Skip to content

Commit

Permalink
Add CLog. Deprecate old Log Tag system.
Browse files Browse the repository at this point in the history
  • Loading branch information
Soapwood committed May 9, 2024
1 parent acb894f commit 9eb87ba
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 111 deletions.
141 changes: 31 additions & 110 deletions VXMusicOverlay/Assets/Plugins/VXMusicOverlay.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using AiUnity.CLog.Core;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
using Valve.VR;
//using NLog;
//using Logger = NLog.Logger;

namespace Plugins
{
public class VXMusicOverlay : MonoBehaviour
{
//private static Logger _logger = LogManager.GetCurrentClassLogger();
private CLogger _logger;

#region Script Fields
[Header("Debug")]
Expand Down Expand Up @@ -186,21 +184,16 @@ private void HandleRecognitionStateEnd()
#region Overlay Initialisation
private void Start()
{
#pragma warning disable 0219 // TODO Deprecate this wank - use an actual logger please.
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); // Automatically obtain class name and method name
#pragma warning restore 0219

Debug.Log(Tag + "VXMusic Overlay is Booting");
_logger.Info("VXMusic Overlay is Booting");
OverlayInitialisationError = false;

// Subscribe to VX Event triggers
Debug.Log("Subscribing to inter-process Events");
_logger.Debug("Subscribing to inter-process Events");
OnRecognitionStateBegin += HandleRecognitionStateBegin;
OnRecognitionStateEnded += HandleRecognitionStateEnd;

// Instanciate MainThreadDispatcher
Debug.Log("Instanciating MainThreadDispatcher");
_logger.Debug("Instanciating MainThreadDispatcher");
MainThreadDispatcher.Initialize();

// Create Debug Overlay Markers
Expand All @@ -210,13 +203,13 @@ private void Start()
RightDebugSphere = Instantiate(DebugSpherePrefab, Vector3.zero, Quaternion.identity);
RightDebugSphere.GetComponent<Renderer>().material.color = Color.green;

Debug.Log(Tag + $"Setting Overlay Target Framerate to {ApplicationTargetFramerate}hz.");
_logger.Debug($"Setting Overlay Target Framerate to {ApplicationTargetFramerate}hz.");
Application.targetFrameRate = ApplicationTargetFramerate;

InitialiseOpenVrSubsystemInstances();
InitialiseOverlayTextureBounds();

Debug.Log(Tag + "Initialising overlay");
_logger.Debug("Initialising overlay");

_VXMusicInterfaceObject = GameObject.Find("VXMusicInterfacePipe");
_VXMusicInterface = _VXMusicInterfaceObject.GetComponent<VXMusicInterface>();
Expand Down Expand Up @@ -281,11 +274,6 @@ private void InitialiseOverlayTextureBounds()
#region Main Overlay Tick Logic
private void Update()
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); // Automatically obtain class name and method name
#pragma warning restore 0219

// Do not execute if an error occurs or the handle is invalid
if (IsError())
return;
Expand All @@ -312,7 +300,7 @@ private void Update()
// Handle termination event
if (IsQuitEventPresentInOpenVrSubsystem())
{
Debug.Log(Tag + "VR system has been terminated");
_logger.Debug("VR system has been terminated");
ApplicationQuit();
}

Expand Down Expand Up @@ -343,15 +331,10 @@ private void Update()
// Update location information
private void UpdateOverlayPosition()
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); // Automatically obtain class name and method name
#pragma warning restore 0219

// Check if Render Texture is generated
if (!RenderTexture.IsCreated())
{
Debug.Log(Tag + "Render Texture has not been generated yet");
_logger.Debug("Render Texture has not been generated yet");
return;
}

Expand Down Expand Up @@ -402,7 +385,7 @@ private void UpdateOverlayPosition()
// If there is a change in device information, it will be reflected in the Inspector
if (DeviceIndexOld != (int)idx)
{
Debug.Log(Tag + "Device Updated");
_logger.Debug("Device Updated");
UpdateDeviceInfo(idx);
DeviceIndexOld = (int)idx;
}
Expand Down Expand Up @@ -449,7 +432,7 @@ private void UpdateOverlayPosition()
}
catch (UnassignedReferenceException e)
{
Debug.LogError(Tag + "RenderTexture is not set " + e.ToString());
_logger.Error("RenderTexture is not set " + e.ToString());
ProcessError();
return;
}
Expand All @@ -458,17 +441,12 @@ private void UpdateOverlayPosition()
// Update display information
private void UpdateOverlayTexture()
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod();
#pragma warning restore 0219

_openVROverlayInstance.SetOverlayFlag(_LowLevelOverlayHandle, VROverlayFlags.SideBySide_Parallel, SideBySide);

// Check if RenderTexture is generated
if (!RenderTexture.IsCreated())
{
Debug.Log(Tag + "RenderTexture has not been generated yet.");
_logger.Debug("RenderTexture has not been generated yet.");
return;
}

Expand All @@ -479,7 +457,7 @@ private void UpdateOverlayTexture()
}
catch (UnassignedReferenceException e)
{
Debug.LogError(Tag + "RenderTexture is not set " + e.ToString());
_logger.Debug("RenderTexture is not set " + e.ToString());
ProcessError();
return;
}
Expand All @@ -489,7 +467,7 @@ private void UpdateOverlayTexture()
overlayError = _openVROverlayInstance.SetOverlayTexture(_LowLevelOverlayHandle, ref _overlayTexture);
if (overlayError != EVROverlayError.None)
{
Debug.LogError(Tag + "Overlay could not set texture." + overlayError.ToString());
_logger.Debug("Overlay could not set texture." + overlayError.ToString());
// Do not treat it as a fatal error
return;
}
Expand Down Expand Up @@ -559,14 +537,15 @@ public void TriggerOnRecognitionStateEnded()

#region Logging

// Output all device information to log
private void LogDeviceInfo()
public void Awake()
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); //クラス名とメソッド名を自動取得
#pragma warning restore 0219
_logger = CLogManager.Instance.GetLogger(this);
_logger.Info("Logger Instantiated for VXMusicOverlay.");
}

// Output all device information to log
private void LogDeviceInfo()
{
// Get connection status of all devices
TrackedDevicePose_t[] allDevicePose = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount];
_openVrSystemApiInstance.GetDeviceToAbsoluteTrackingPose(ETrackingUniverseOrigin.TrackingUniverseStanding, 0f, allDevicePose);
Expand Down Expand Up @@ -602,11 +581,6 @@ private void LogDeviceInfo()
// Output device information to log (1 item)
private bool GetPropertyAndPutLog(uint idx, TrackedDevicePose_t[] allDevicePose)
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); // Automatically obtain class name and method name
#pragma warning restore 0219

// Check if connected
if (allDevicePose[idx].bDeviceIsConnected)
{
Expand All @@ -617,21 +591,20 @@ private bool GetPropertyAndPutLog(uint idx, TrackedDevicePose_t[] allDevicePose)
string s2 = GetProperty(idx, ETrackedDeviceProperty.Prop_RenderModelName_String);
if (s1 != null && s2 != null)
{
// Show in log
Debug.Log(Tag + "Device " + idx + ":" + s1 + " : " + s2);
_logger.Debug("Device " + idx + ":" + s1 + " : " + s2);
}
else
{
// Acquisition failed for some reason
Debug.Log(Tag + "Device " + idx + ": Error");
_logger.Debug("Device " + idx + ": Error");
}

return true;
}
else
{
// unconnected device
Debug.Log(Tag + "Device " + idx + ": Not connected");
_logger.Debug("Device " + idx + ": Not connected");
return false;
}
}
Expand Down Expand Up @@ -659,11 +632,6 @@ private bool IsInputLockButtonPressed()

private void VrInputTick()
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); // Automatically obtain class name and method name
#pragma warning restore 0219

// Get information for all VR connected devices
TrackedDevicePose_t[] allDevicePose = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount];
_openVrSystemApiInstance.GetDeviceToAbsoluteTrackingPose(ETrackingUniverseOrigin.TrackingUniverseStanding, 0f, allDevicePose);
Expand Down Expand Up @@ -781,11 +749,6 @@ private bool IsRaycastIntersectingWithOverlayCanvas(uint idx, Vector3 pos, Vecto
*/
private bool IsRaycastIntersectingWithOverlayCanvas(uint idx, TrackedDevicePose_t[] allDevicePose, ref VROverlayIntersectionResults_t results)
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); // Automatically obtain class name and method name
#pragma warning restore 0219

//device index enabled
if (idx != OpenVR.k_unTrackedDeviceIndexInvalid)
{
Expand All @@ -810,11 +773,6 @@ private bool IsRaycastIntersectingWithOverlayCanvas(uint idx, TrackedDevicePose_
// Check if it has an intersection with the overlay
private bool ComputeOverlayIntersection(Vector3 pos, Vector3 rotvect, ref VROverlayIntersectionResults_t results)
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); // Automatically obtain class name and method name
#pragma warning restore 0219

// Ray irradiation information
VROverlayIntersectionParams_t param = new VROverlayIntersectionParams_t();
// Ray launcher position
Expand All @@ -840,11 +798,6 @@ private bool ComputeOverlayIntersection(Vector3 pos, Vector3 rotvect, ref VROver

private void IsRaycastInClickingRange(VROverlayIntersectionResults_t results, LeftOrRight lr, ref bool tapped)
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); // Automatically obtain class name and method name
#pragma warning restore 0219

// If the distance between the controller and the overlay is below a certain level
if (results.fDistance < TapOnDistance && !tapped)
{
Expand Down Expand Up @@ -872,11 +825,6 @@ private void IsRaycastInClickingRange(VROverlayIntersectionResults_t results, Le
// Identify and click an element on Canvas
private void ProcessOverlayClick(VROverlayIntersectionResults_t results)
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); // Automatically obtain class name and method name
#pragma warning restore 0219

// Calculate uv coordinates for click
float u = results.vUVs.v0 * RenderTexture.width;
float v = RenderTexture.height - results.vUVs.v1 * RenderTexture.height;
Expand All @@ -897,7 +845,7 @@ private void ProcessOverlayClick(VROverlayIntersectionResults_t results)

// Number and coordinates of detected elements

Debug.Log(Tag + "count:" + result.Count + " u:" + u + " / v:" + v);
_logger.Debug("count:" + result.Count + " u:" + u + " / v:" + v);

// Perform click processing on the first element found
for (int i = 0; i < result.Count; i++)
Expand All @@ -907,7 +855,7 @@ private void ProcessOverlayClick(VROverlayIntersectionResults_t results)
// Hit the first thing you hooked (uncheck everything other than target)
if (res.isValid)
{
Debug.Log(Tag + res.gameObject.name + " at " + res.gameObject.transform.root.name);
_logger.Debug(res.gameObject.name + " at " + res.gameObject.transform.root.name);
// Check if it is a child of the root object you want to target
if (res.gameObject.transform.root.name == RaycastRootObject.name)
{
Expand All @@ -925,11 +873,6 @@ private void ProcessOverlayClick(VROverlayIntersectionResults_t results)
// Get device information
private string GetProperty(uint idx, ETrackedDeviceProperty prop)
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); // Automatically obtain class name and method name
#pragma warning restore 0219

ETrackedPropertyError error = new ETrackedPropertyError();
// Get the number of characters required to get device information
uint size = _openVrSystemApiInstance.GetStringTrackedDeviceProperty(idx, prop, null, 0, ref error);
Expand Down Expand Up @@ -985,11 +928,6 @@ private void UpdateDeviceInfo(uint idx)
// Perform vibration feedback
private void PerformHapticFeedback(LeftOrRight lr)
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); // Automatically obtain class name and method name
#pragma warning restore 0219

// Check if left hand controller is enabled
uint Leftidx = _openVrSystemApiInstance.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.LeftHand);
//OverlayTrackedDevice
Expand Down Expand Up @@ -1018,11 +956,6 @@ public bool IsError()
// Return when the end event is caught
private bool IsQuitEventPresentInOpenVrSubsystem()
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod();
#pragma warning restore 0219

// Get the size of the event structure
uint uncbVREvent = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t));

Expand All @@ -1034,14 +967,14 @@ private bool IsQuitEventPresentInOpenVrSubsystem()
// View event log
if (EventLog)
{
Debug.Log(Tag + "Event:" + ((EVREventType)Event.eventType).ToString());
_logger.Debug("Event:" + ((EVREventType)Event.eventType).ToString());
}

// Branch by event information
switch ((EVREventType)Event.eventType)
{
case EVREventType.VREvent_Quit:
Debug.Log(Tag + "Quit");
_logger.Debug("Quit");
return true;
}
}
Expand All @@ -1058,11 +991,7 @@ public bool IsVisible()
// Error processing (release processing)
private void ProcessError()
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); // Automatically obtain class name and method name
#pragma warning restore 0219
Debug.Log(Tag + "Begin");
_logger.Debug("Begin");

// release the handle
if (_LowLevelOverlayHandle != INVALID_HANDLE && _openVROverlayInstance != null)
Expand All @@ -1079,11 +1008,7 @@ private void ProcessError()
// When destroying an object
private void OnDestroy()
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); // automatically obtain class name and method name
#pragma warning restore 0219
Debug.Log(Tag + "Begin");
_logger.Debug("OnDestroy");

// Fully open handles
ProcessError();
Expand All @@ -1092,11 +1017,7 @@ private void OnDestroy()
// When application termination is detected
private void OnApplicationQuit()
{
#pragma warning disable 0219
string Tag = "[" + this.GetType().Name + ":" +
System.Reflection.MethodBase.GetCurrentMethod(); // Automatically obtain class name and method name
#pragma warning restore 0219
Debug.Log(Tag + "Begin");
_logger.Debug("OnApplicationQuit");

// Fully open handles
ProcessError();
Expand Down
1 change: 0 additions & 1 deletion VXMusicOverlay/Assets/Plugins/VXMusicOverlayTcpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Net.Sockets;
using System.Text;
using System.Threading;
using Plugins.Messaging;
using UnityEngine;

namespace Plugins
Expand Down
Loading

0 comments on commit 9eb87ba

Please sign in to comment.