mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-07 14:56:06 +02:00
cleanup code
This commit is contained in:
@@ -156,22 +156,22 @@ namespace VRCX
|
|||||||
|
|
||||||
public void StartVR()
|
public void StartVR()
|
||||||
{
|
{
|
||||||
VRCXVR.SetActive(true);
|
VRCXVR.Instance.SetActive(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StopVR()
|
public void StopVR()
|
||||||
{
|
{
|
||||||
VRCXVR.SetActive(false);
|
VRCXVR.Instance.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RefreshVR()
|
public void RefreshVR()
|
||||||
{
|
{
|
||||||
VRCXVR.Refresh();
|
VRCXVR.Instance.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string[][] GetVRDevices()
|
public string[][] GetVRDevices()
|
||||||
{
|
{
|
||||||
return VRCXVR.GetDevices();
|
return VRCXVR.Instance.GetDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
public float CpuUsage()
|
public float CpuUsage()
|
||||||
|
|||||||
+24
-14
@@ -11,9 +11,9 @@ namespace VRCX
|
|||||||
public class CpuMonitor
|
public class CpuMonitor
|
||||||
{
|
{
|
||||||
public static readonly CpuMonitor Instance;
|
public static readonly CpuMonitor Instance;
|
||||||
public float CpuUsage { get; private set; }
|
public float CpuUsage;
|
||||||
private readonly PerformanceCounter m_Counter;
|
private PerformanceCounter _performanceCounter;
|
||||||
private Thread m_Thread;
|
private Thread _thread;
|
||||||
|
|
||||||
static CpuMonitor()
|
static CpuMonitor()
|
||||||
{
|
{
|
||||||
@@ -24,25 +24,35 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_Counter = new PerformanceCounter("Processor Information", "% Processor Utility", "_Total", true);
|
_performanceCounter = new PerformanceCounter(
|
||||||
|
"Processor Information",
|
||||||
|
"% Processor Utility",
|
||||||
|
"_Total",
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// fallback
|
// fallback
|
||||||
if (m_Counter == null)
|
if (_performanceCounter == null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_Counter = new PerformanceCounter("Processor", "% Processor Time", "_Total", true);
|
_performanceCounter = new PerformanceCounter(
|
||||||
|
"Processor",
|
||||||
|
"% Processor Time",
|
||||||
|
"_Total",
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Thread = new Thread(ThreadLoop)
|
_thread = new Thread(ThreadLoop)
|
||||||
{
|
{
|
||||||
IsBackground = true
|
IsBackground = true
|
||||||
};
|
};
|
||||||
@@ -50,25 +60,25 @@ namespace VRCX
|
|||||||
|
|
||||||
internal void Init()
|
internal void Init()
|
||||||
{
|
{
|
||||||
m_Thread.Start();
|
_thread.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Exit()
|
internal void Exit()
|
||||||
{
|
{
|
||||||
var thread = m_Thread;
|
var thread = _thread;
|
||||||
m_Thread = null;
|
_thread = null;
|
||||||
thread.Interrupt();
|
thread.Interrupt();
|
||||||
thread.Join();
|
thread.Join();
|
||||||
m_Counter?.Dispose();
|
_performanceCounter?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ThreadLoop()
|
private void ThreadLoop()
|
||||||
{
|
{
|
||||||
while (m_Thread != null)
|
while (_thread != null)
|
||||||
{
|
{
|
||||||
if (m_Counter != null)
|
if (_performanceCounter != null)
|
||||||
{
|
{
|
||||||
CpuUsage = m_Counter.NextValue();
|
CpuUsage = _performanceCounter.NextValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|||||||
+10
-5
@@ -26,6 +26,7 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var location = Assembly.GetExecutingAssembly().Location;
|
var location = Assembly.GetExecutingAssembly().Location;
|
||||||
@@ -36,22 +37,26 @@ namespace VRCX
|
|||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
// Program.BaseDirectory + "/html/index.html"
|
|
||||||
Browser = new ChromiumWebBrowser(Path.Combine(Program.BaseDirectory, "html/index.html"))
|
Browser = new ChromiumWebBrowser(
|
||||||
|
Path.Combine(Program.BaseDirectory, "html/index.html")
|
||||||
|
)
|
||||||
{
|
{
|
||||||
DragHandler = new NoopDragHandler(),
|
DragHandler = new NoopDragHandler(),
|
||||||
BrowserSettings =
|
BrowserSettings =
|
||||||
{
|
{
|
||||||
// UniversalAccessFromFileUrls = CefState.Enabled,
|
|
||||||
DefaultEncoding = "UTF-8",
|
DefaultEncoding = "UTF-8",
|
||||||
},
|
},
|
||||||
Dock = DockStyle.Fill,
|
Dock = DockStyle.Fill
|
||||||
};
|
};
|
||||||
Util.ApplyJavascriptBindings(Browser.JavascriptObjectRepository);
|
|
||||||
Browser.IsBrowserInitializedChanged += (A, B) =>
|
Browser.IsBrowserInitializedChanged += (A, B) =>
|
||||||
{
|
{
|
||||||
// Browser.ShowDevTools();
|
// Browser.ShowDevTools();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Util.ApplyJavascriptBindings(Browser.JavascriptObjectRepository);
|
||||||
|
|
||||||
Controls.Add(Browser);
|
Controls.Add(Browser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+106
-30
@@ -9,22 +9,32 @@ using CefSharp.OffScreen;
|
|||||||
using CefSharp.Structs;
|
using CefSharp.Structs;
|
||||||
using SharpDX.Direct3D11;
|
using SharpDX.Direct3D11;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace VRCX
|
namespace VRCX
|
||||||
{
|
{
|
||||||
public class OffScreenBrowser : ChromiumWebBrowser, IRenderHandler
|
public class OffScreenBrowser : ChromiumWebBrowser, IRenderHandler
|
||||||
{
|
{
|
||||||
private Texture2D _texture;
|
private ReaderWriterLockSlim _paintBufferLock;
|
||||||
|
private GCHandle _paintBuffer;
|
||||||
|
private int _width;
|
||||||
|
private int _height;
|
||||||
|
|
||||||
public OffScreenBrowser(Texture2D texture, string address)
|
public OffScreenBrowser(string address, int width, int height)
|
||||||
: base(address, new BrowserSettings()
|
: base(
|
||||||
|
address,
|
||||||
|
new BrowserSettings()
|
||||||
{
|
{
|
||||||
DefaultEncoding = "UTF-8"
|
DefaultEncoding = "UTF-8"
|
||||||
})
|
}
|
||||||
|
)
|
||||||
{
|
{
|
||||||
_texture = texture;
|
_paintBufferLock = new ReaderWriterLockSlim();
|
||||||
Size = new System.Drawing.Size(texture.Description.Width, texture.Description.Height);
|
|
||||||
|
Size = new System.Drawing.Size(width, height);
|
||||||
RenderHandler = this;
|
RenderHandler = this;
|
||||||
|
|
||||||
Util.ApplyJavascriptBindings(JavascriptObjectRepository);
|
Util.ApplyJavascriptBindings(JavascriptObjectRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,17 +42,78 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
RenderHandler = null;
|
RenderHandler = null;
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
_texture = null;
|
|
||||||
|
_paintBufferLock.EnterWriteLock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_paintBuffer.IsAllocated == true)
|
||||||
|
{
|
||||||
|
_paintBuffer.Free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_paintBufferLock.ExitWriteLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
_paintBufferLock.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RenderToTexture(Texture2D texture)
|
||||||
|
{
|
||||||
|
_paintBufferLock.EnterReadLock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_width > 0 &&
|
||||||
|
_height > 0)
|
||||||
|
{
|
||||||
|
var context = texture.Device.ImmediateContext;
|
||||||
|
var dataBox = context.MapSubresource(
|
||||||
|
texture,
|
||||||
|
0,
|
||||||
|
MapMode.WriteDiscard,
|
||||||
|
MapFlags.None
|
||||||
|
);
|
||||||
|
if (dataBox.IsEmpty == false)
|
||||||
|
{
|
||||||
|
var sourcePtr = _paintBuffer.AddrOfPinnedObject();
|
||||||
|
var destinationPtr = dataBox.DataPointer;
|
||||||
|
var pitch = _width * 4;
|
||||||
|
var rowPitch = dataBox.RowPitch;
|
||||||
|
if (pitch == rowPitch)
|
||||||
|
{
|
||||||
|
WinApi.CopyMemory(
|
||||||
|
destinationPtr,
|
||||||
|
sourcePtr,
|
||||||
|
(uint)(_width * _height * 4)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (var y = _height; y > 0; --y)
|
||||||
|
{
|
||||||
|
WinApi.CopyMemory(
|
||||||
|
destinationPtr,
|
||||||
|
sourcePtr,
|
||||||
|
(uint)pitch
|
||||||
|
);
|
||||||
|
sourcePtr += pitch;
|
||||||
|
destinationPtr += rowPitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
context.UnmapSubresource(texture, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_paintBufferLock.ExitReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ScreenInfo? IRenderHandler.GetScreenInfo()
|
ScreenInfo? IRenderHandler.GetScreenInfo()
|
||||||
{
|
{
|
||||||
return new ScreenInfo
|
return null;
|
||||||
{
|
|
||||||
DeviceScaleFactor = 1f
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRenderHandler.GetScreenPoint(int viewX, int viewY, out int screenX, out int screenY)
|
bool IRenderHandler.GetScreenPoint(int viewX, int viewY, out int screenX, out int screenY)
|
||||||
@@ -74,31 +145,36 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
if (type == PaintElementType.View)
|
if (type == PaintElementType.View)
|
||||||
{
|
{
|
||||||
var context = _texture.Device.ImmediateContext;
|
_paintBufferLock.EnterWriteLock();
|
||||||
var dataBox = context.MapSubresource(_texture, 0, MapMode.WriteDiscard, MapFlags.None);
|
try
|
||||||
if (dataBox.IsEmpty == false)
|
|
||||||
{
|
{
|
||||||
var sourcePtr = buffer;
|
if (_width != width ||
|
||||||
var destinationPtr = dataBox.DataPointer;
|
_height != height)
|
||||||
var rowPitch = dataBox.RowPitch;
|
|
||||||
var pitch = width * 4;
|
|
||||||
if (rowPitch == pitch)
|
|
||||||
{
|
{
|
||||||
WinApi.CopyMemory(destinationPtr, sourcePtr, (uint)(width * height * 4));
|
_width = width;
|
||||||
}
|
_height = height;
|
||||||
else
|
if (_paintBuffer.IsAllocated == true)
|
||||||
{
|
{
|
||||||
for (var i = height; i > 0; --i)
|
_paintBuffer.Free();
|
||||||
|
}
|
||||||
|
_paintBuffer = GCHandle.Alloc(
|
||||||
|
new byte[_width * _height * 4],
|
||||||
|
GCHandleType.Pinned
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
WinApi.CopyMemory(
|
||||||
|
_paintBuffer.AddrOfPinnedObject(),
|
||||||
|
buffer,
|
||||||
|
(uint)(width * height * 4)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
finally
|
||||||
{
|
{
|
||||||
WinApi.CopyMemory(destinationPtr, sourcePtr, (uint)pitch);
|
_paintBufferLock.ExitWriteLock();
|
||||||
sourcePtr += pitch;
|
|
||||||
destinationPtr += rowPitch;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
context.UnmapSubresource(_texture, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void IRenderHandler.OnPopupShow(bool show)
|
void IRenderHandler.OnPopupShow(bool show)
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -45,9 +45,9 @@ namespace VRCX
|
|||||||
LogWatcher.Instance.Init();
|
LogWatcher.Instance.Init();
|
||||||
|
|
||||||
CefService.Instance.Init();
|
CefService.Instance.Init();
|
||||||
VRCXVR.Init();
|
VRCXVR.Instance.Init();
|
||||||
Application.Run(new MainForm());
|
Application.Run(new MainForm());
|
||||||
VRCXVR.Exit();
|
VRCXVR.Instance.Exit();
|
||||||
CefService.Instance.Exit();
|
CefService.Instance.Exit();
|
||||||
|
|
||||||
LogWatcher.Instance.Exit();
|
LogWatcher.Instance.Exit();
|
||||||
|
|||||||
@@ -19,59 +19,56 @@ using Device = SharpDX.Direct3D11.Device;
|
|||||||
|
|
||||||
namespace VRCX
|
namespace VRCX
|
||||||
{
|
{
|
||||||
public static class VRCXVR
|
public class VRCXVR
|
||||||
{
|
{
|
||||||
private static readonly ReaderWriterLockSlim m_Lock = new ReaderWriterLockSlim();
|
public static readonly VRCXVR Instance;
|
||||||
private static List<string[]> m_Devices = new List<string[]>();
|
private static readonly float[] _rotation = { 0f, 0f, 0f };
|
||||||
private static Thread m_Thread;
|
private static readonly float[] _translation = { 0f, 0f, 0f };
|
||||||
private static Device m_Device;
|
private static readonly float[] _translationLeft = { -7f / 100f, -5f / 100f, 6f / 100f };
|
||||||
private static Texture2D m_Texture1;
|
private static readonly float[] _translationRight = { 7f / 100f, -5f / 100f, 6f / 100f };
|
||||||
private static Texture2D m_Texture2;
|
private static readonly float[] _rotationLeft = { 90f * (float)(Math.PI / 180f), 90f * (float)(Math.PI / 180f), -90f * (float)(Math.PI / 180f) };
|
||||||
private static OffScreenBrowser m_Browser1;
|
private static readonly float[] _rotationRight = { -90f * (float)(Math.PI / 180f), -90f * (float)(Math.PI / 180f), -90f * (float)(Math.PI / 180f) };
|
||||||
private static OffScreenBrowser m_Browser2;
|
private readonly ReaderWriterLockSlim _deviceListLock;
|
||||||
private static bool m_Active;
|
private List<string[]> _deviceList;
|
||||||
private static float[] m_Rotation = { 0f, 0f, 0f };
|
private Thread _thread;
|
||||||
private static float[] m_Translation = { 0f, 0f, 0f };
|
private Device _device;
|
||||||
private static float[] m_L_Translation = { -7f / 100f, -5f / 100f, 6f / 100f };
|
private Texture2D _texture1;
|
||||||
private static float[] m_R_Translation = { 7f / 100f, -5f / 100f, 6f / 100f };
|
private Texture2D _texture2;
|
||||||
private static float[] m_L_Rotation = { 90f * (float)(Math.PI / 180f), 90f * (float)(Math.PI / 180f), -90f * (float)(Math.PI / 180f) };
|
private OffScreenBrowser _browser1;
|
||||||
private static float[] m_R_Rotation = { -90f * (float)(Math.PI / 180f), -90f * (float)(Math.PI / 180f), -90f * (float)(Math.PI / 180f) };
|
private OffScreenBrowser _browser2;
|
||||||
|
private bool _active;
|
||||||
|
|
||||||
|
static VRCXVR()
|
||||||
|
{
|
||||||
|
Instance = new VRCXVR();
|
||||||
|
}
|
||||||
|
|
||||||
|
public VRCXVR()
|
||||||
|
{
|
||||||
|
_deviceListLock = new ReaderWriterLockSlim();
|
||||||
|
_deviceList = new List<string[]>();
|
||||||
|
_thread = new Thread(ThreadLoop)
|
||||||
|
{
|
||||||
|
IsBackground = true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE
|
// NOTE
|
||||||
// 메모리 릭 때문에 미리 생성해놓고 계속 사용함
|
// 메모리 릭 때문에 미리 생성해놓고 계속 사용함
|
||||||
public static void Init()
|
internal void Init()
|
||||||
{
|
{
|
||||||
m_Device = new Device(
|
_thread.Start();
|
||||||
DriverType.Hardware,
|
}
|
||||||
DeviceCreationFlags.BgraSupport
|
|
||||||
);
|
internal void Exit()
|
||||||
m_Texture1 = new Texture2D(m_Device, new Texture2DDescription()
|
|
||||||
{
|
{
|
||||||
Width = 512,
|
var thread = _thread;
|
||||||
Height = 512,
|
_thread = null;
|
||||||
MipLevels = 1,
|
thread.Interrupt();
|
||||||
ArraySize = 1,
|
thread.Join();
|
||||||
Format = Format.B8G8R8A8_UNorm,
|
}
|
||||||
SampleDescription = new SampleDescription(1, 0),
|
|
||||||
Usage = ResourceUsage.Dynamic,
|
private void ThreadLoop()
|
||||||
BindFlags = BindFlags.ShaderResource,
|
|
||||||
CpuAccessFlags = CpuAccessFlags.Write
|
|
||||||
});
|
|
||||||
m_Texture2 = new Texture2D(m_Device, new Texture2DDescription()
|
|
||||||
{
|
|
||||||
Width = 512,
|
|
||||||
Height = 512,
|
|
||||||
MipLevels = 1,
|
|
||||||
ArraySize = 1,
|
|
||||||
Format = Format.B8G8R8A8_UNorm,
|
|
||||||
SampleDescription = new SampleDescription(1, 0),
|
|
||||||
Usage = ResourceUsage.Dynamic,
|
|
||||||
BindFlags = BindFlags.ShaderResource,
|
|
||||||
CpuAccessFlags = CpuAccessFlags.Write
|
|
||||||
});
|
|
||||||
m_Browser1 = new OffScreenBrowser(m_Texture1, Path.Combine(Program.BaseDirectory, "html/vr.html?1"));
|
|
||||||
m_Browser2 = new OffScreenBrowser(m_Texture2, Path.Combine(Program.BaseDirectory, "html/vr.html?2"));
|
|
||||||
m_Thread = new Thread(() =>
|
|
||||||
{
|
{
|
||||||
var active = false;
|
var active = false;
|
||||||
var e = new VREvent_t();
|
var e = new VREvent_t();
|
||||||
@@ -84,8 +81,64 @@ namespace VRCX
|
|||||||
var dashboardHandle = 0UL;
|
var dashboardHandle = 0UL;
|
||||||
var overlayHandle1 = 0UL;
|
var overlayHandle1 = 0UL;
|
||||||
var overlayHandle2 = 0UL;
|
var overlayHandle2 = 0UL;
|
||||||
while (m_Thread != null)
|
|
||||||
|
// REMOVE THIS
|
||||||
|
nextOverlay = DateTime.MaxValue;
|
||||||
|
|
||||||
|
_device = new Device(
|
||||||
|
DriverType.Hardware,
|
||||||
|
DeviceCreationFlags.SingleThreaded | DeviceCreationFlags.BgraSupport
|
||||||
|
);
|
||||||
|
|
||||||
|
_texture1 = new Texture2D(
|
||||||
|
_device,
|
||||||
|
new Texture2DDescription()
|
||||||
{
|
{
|
||||||
|
Width = 512,
|
||||||
|
Height = 512,
|
||||||
|
MipLevels = 1,
|
||||||
|
ArraySize = 1,
|
||||||
|
Format = Format.B8G8R8A8_UNorm,
|
||||||
|
SampleDescription = new SampleDescription(1, 0),
|
||||||
|
Usage = ResourceUsage.Dynamic,
|
||||||
|
BindFlags = BindFlags.ShaderResource,
|
||||||
|
CpuAccessFlags = CpuAccessFlags.Write
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
_texture2 = new Texture2D(
|
||||||
|
_device,
|
||||||
|
new Texture2DDescription()
|
||||||
|
{
|
||||||
|
Width = 512,
|
||||||
|
Height = 512,
|
||||||
|
MipLevels = 1,
|
||||||
|
ArraySize = 1,
|
||||||
|
Format = Format.B8G8R8A8_UNorm,
|
||||||
|
SampleDescription = new SampleDescription(1, 0),
|
||||||
|
Usage = ResourceUsage.Dynamic,
|
||||||
|
BindFlags = BindFlags.ShaderResource,
|
||||||
|
CpuAccessFlags = CpuAccessFlags.Write
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
_browser1 = new OffScreenBrowser(
|
||||||
|
Path.Combine(Program.BaseDirectory, "html/vr.html?1"),
|
||||||
|
512,
|
||||||
|
512
|
||||||
|
);
|
||||||
|
|
||||||
|
_browser2 = new OffScreenBrowser(
|
||||||
|
Path.Combine(Program.BaseDirectory, "html/vr.html?2"),
|
||||||
|
512,
|
||||||
|
512
|
||||||
|
);
|
||||||
|
|
||||||
|
while (_thread != null)
|
||||||
|
{
|
||||||
|
_browser1.RenderToTexture(_texture1);
|
||||||
|
_browser2.RenderToTexture(_texture2);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Thread.Sleep(10);
|
Thread.Sleep(10);
|
||||||
@@ -94,10 +147,9 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
// ThreadInterruptedException
|
// ThreadInterruptedException
|
||||||
}
|
}
|
||||||
if (m_Active)
|
|
||||||
|
if (_active)
|
||||||
{
|
{
|
||||||
m_Browser1.Render();
|
|
||||||
m_Browser2.Render();
|
|
||||||
var system = OpenVR.System;
|
var system = OpenVR.System;
|
||||||
if (system == null)
|
if (system == null)
|
||||||
{
|
{
|
||||||
@@ -170,71 +222,60 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
active = false;
|
active = false;
|
||||||
OpenVR.Shutdown();
|
OpenVR.Shutdown();
|
||||||
m_Lock.EnterWriteLock();
|
_deviceListLock.EnterWriteLock();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_Devices.Clear();
|
_deviceList.Clear();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
m_Lock.ExitWriteLock();
|
_deviceListLock.ExitWriteLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
{
|
|
||||||
IsBackground = true
|
|
||||||
};
|
|
||||||
m_Thread.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Exit()
|
_browser2.Dispose();
|
||||||
{
|
_browser1.Dispose();
|
||||||
var T = m_Thread;
|
_texture2.Dispose();
|
||||||
m_Thread = null;
|
_texture1.Dispose();
|
||||||
T.Interrupt();
|
_device.Dispose();
|
||||||
T.Join();
|
|
||||||
m_Browser2.Dispose();
|
|
||||||
m_Browser1.Dispose();
|
|
||||||
m_Texture2.Dispose();
|
|
||||||
m_Texture1.Dispose();
|
|
||||||
m_Device.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetActive(bool active)
|
public void SetActive(bool active)
|
||||||
{
|
{
|
||||||
m_Active = active;
|
_active = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Refresh()
|
public void Refresh()
|
||||||
{
|
{
|
||||||
m_Browser1.ExecuteScriptAsync("location.reload()");
|
_browser1.ExecuteScriptAsync("location.reload()");
|
||||||
m_Browser2.ExecuteScriptAsync("location.reload()");
|
_browser2.ExecuteScriptAsync("location.reload()");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string[][] GetDevices()
|
public string[][] GetDevices()
|
||||||
{
|
{
|
||||||
m_Lock.EnterReadLock();
|
_deviceListLock.EnterReadLock();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return m_Devices.ToArray();
|
return _deviceList.ToArray();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
m_Lock.ExitReadLock();
|
_deviceListLock.ExitReadLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UpdateDevices(CVRSystem system, ref uint overlayIndex)
|
internal void UpdateDevices(CVRSystem system, ref uint overlayIndex)
|
||||||
{
|
{
|
||||||
m_Lock.EnterWriteLock();
|
_deviceListLock.EnterWriteLock();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_Devices.Clear();
|
_deviceList.Clear();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
m_Lock.ExitWriteLock();
|
_deviceListLock.ExitWriteLock();
|
||||||
}
|
}
|
||||||
var sb = new StringBuilder(256);
|
var sb = new StringBuilder(256);
|
||||||
var state = new VRControllerState_t();
|
var state = new VRControllerState_t();
|
||||||
@@ -267,13 +308,13 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
if (role == ETrackedControllerRole.LeftHand)
|
if (role == ETrackedControllerRole.LeftHand)
|
||||||
{
|
{
|
||||||
Array.Copy(m_L_Translation, m_Translation, 3);
|
Array.Copy(_translationLeft, _translation, 3);
|
||||||
Array.Copy(m_L_Rotation, m_Rotation, 3);
|
Array.Copy(_rotationLeft, _rotation, 3);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Array.Copy(m_R_Translation, m_Translation, 3);
|
Array.Copy(_translationRight, _translation, 3);
|
||||||
Array.Copy(m_R_Rotation, m_Rotation, 3);
|
Array.Copy(_rotationRight, _rotation, 3);
|
||||||
}
|
}
|
||||||
overlayIndex = i;
|
overlayIndex = i;
|
||||||
}
|
}
|
||||||
@@ -310,20 +351,20 @@ namespace VRCX
|
|||||||
: "disconnected",
|
: "disconnected",
|
||||||
(batteryPercentage * 100).ToString()
|
(batteryPercentage * 100).ToString()
|
||||||
};
|
};
|
||||||
m_Lock.EnterWriteLock();
|
_deviceListLock.EnterWriteLock();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_Devices.Add(item);
|
_deviceList.Add(item);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
m_Lock.ExitWriteLock();
|
_deviceListLock.ExitWriteLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static EVROverlayError ProcessDashboard(CVROverlay overlay, ref ulong dashboardHandle, bool dashboardVisible)
|
internal EVROverlayError ProcessDashboard(CVROverlay overlay, ref ulong dashboardHandle, bool dashboardVisible)
|
||||||
{
|
{
|
||||||
var err = EVROverlayError.None;
|
var err = EVROverlayError.None;
|
||||||
|
|
||||||
@@ -363,20 +404,20 @@ namespace VRCX
|
|||||||
if (type == EVREventType.VREvent_MouseMove)
|
if (type == EVREventType.VREvent_MouseMove)
|
||||||
{
|
{
|
||||||
var m = e.data.mouse;
|
var m = e.data.mouse;
|
||||||
var s = m_Browser1.Size;
|
var s = _browser1.Size;
|
||||||
m_Browser1.GetBrowserHost().SendMouseMoveEvent((int)(m.x * s.Width), s.Height - (int)(m.y * s.Height), false, CefEventFlags.None);
|
_browser1.GetBrowserHost().SendMouseMoveEvent((int)(m.x * s.Width), s.Height - (int)(m.y * s.Height), false, CefEventFlags.None);
|
||||||
}
|
}
|
||||||
else if (type == EVREventType.VREvent_MouseButtonDown)
|
else if (type == EVREventType.VREvent_MouseButtonDown)
|
||||||
{
|
{
|
||||||
var m = e.data.mouse;
|
var m = e.data.mouse;
|
||||||
var s = m_Browser1.Size;
|
var s = _browser1.Size;
|
||||||
m_Browser1.GetBrowserHost().SendMouseClickEvent((int)(m.x * s.Width), s.Height - (int)(m.y * s.Height), MouseButtonType.Left, false, 1, CefEventFlags.LeftMouseButton);
|
_browser1.GetBrowserHost().SendMouseClickEvent((int)(m.x * s.Width), s.Height - (int)(m.y * s.Height), MouseButtonType.Left, false, 1, CefEventFlags.LeftMouseButton);
|
||||||
}
|
}
|
||||||
else if (type == EVREventType.VREvent_MouseButtonUp)
|
else if (type == EVREventType.VREvent_MouseButtonUp)
|
||||||
{
|
{
|
||||||
var m = e.data.mouse;
|
var m = e.data.mouse;
|
||||||
var s = m_Browser1.Size;
|
var s = _browser1.Size;
|
||||||
m_Browser1.GetBrowserHost().SendMouseClickEvent((int)(m.x * s.Width), s.Height - (int)(m.y * s.Height), MouseButtonType.Left, true, 1, CefEventFlags.None);
|
_browser1.GetBrowserHost().SendMouseClickEvent((int)(m.x * s.Width), s.Height - (int)(m.y * s.Height), MouseButtonType.Left, true, 1, CefEventFlags.None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,7 +425,7 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
var texture = new Texture_t
|
var texture = new Texture_t
|
||||||
{
|
{
|
||||||
handle = m_Texture1.NativePointer
|
handle = _texture1.NativePointer
|
||||||
};
|
};
|
||||||
err = overlay.SetOverlayTexture(dashboardHandle, ref texture);
|
err = overlay.SetOverlayTexture(dashboardHandle, ref texture);
|
||||||
if (err != EVROverlayError.None)
|
if (err != EVROverlayError.None)
|
||||||
@@ -396,7 +437,7 @@ namespace VRCX
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static EVROverlayError ProcessOverlay1(CVROverlay overlay, ref ulong overlayHandle, ref bool overlayVisible, bool dashboardVisible, uint overlayIndex, DateTime nextOverlay)
|
internal EVROverlayError ProcessOverlay1(CVROverlay overlay, ref ulong overlayHandle, ref bool overlayVisible, bool dashboardVisible, uint overlayIndex, DateTime nextOverlay)
|
||||||
{
|
{
|
||||||
var err = EVROverlayError.None;
|
var err = EVROverlayError.None;
|
||||||
|
|
||||||
@@ -438,10 +479,10 @@ namespace VRCX
|
|||||||
// http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices
|
// http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices
|
||||||
// Scaling-Rotation-Translation
|
// Scaling-Rotation-Translation
|
||||||
var m = Matrix.Scaling(0.25f);
|
var m = Matrix.Scaling(0.25f);
|
||||||
m *= Matrix.RotationX(m_Rotation[0]);
|
m *= Matrix.RotationX(_rotation[0]);
|
||||||
m *= Matrix.RotationY(m_Rotation[1]);
|
m *= Matrix.RotationY(_rotation[1]);
|
||||||
m *= Matrix.RotationZ(m_Rotation[2]);
|
m *= Matrix.RotationZ(_rotation[2]);
|
||||||
m *= Matrix.Translation(m_Translation[0], m_Translation[1], m_Translation[2]);
|
m *= Matrix.Translation(_translation[0], _translation[1], _translation[2]);
|
||||||
var hm34 = new HmdMatrix34_t
|
var hm34 = new HmdMatrix34_t
|
||||||
{
|
{
|
||||||
m0 = m.M11,
|
m0 = m.M11,
|
||||||
@@ -469,7 +510,7 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
var texture = new Texture_t
|
var texture = new Texture_t
|
||||||
{
|
{
|
||||||
handle = m_Texture1.NativePointer
|
handle = _texture1.NativePointer
|
||||||
};
|
};
|
||||||
err = overlay.SetOverlayTexture(overlayHandle, ref texture);
|
err = overlay.SetOverlayTexture(overlayHandle, ref texture);
|
||||||
if (err != EVROverlayError.None)
|
if (err != EVROverlayError.None)
|
||||||
@@ -499,7 +540,7 @@ namespace VRCX
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static EVROverlayError ProcessOverlay2(CVROverlay overlay, ref ulong overlayHandle, ref bool overlayVisible, bool dashboardVisible)
|
internal EVROverlayError ProcessOverlay2(CVROverlay overlay, ref ulong overlayHandle, ref bool overlayVisible, bool dashboardVisible)
|
||||||
{
|
{
|
||||||
var err = EVROverlayError.None;
|
var err = EVROverlayError.None;
|
||||||
|
|
||||||
@@ -562,7 +603,7 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
var texture = new Texture_t
|
var texture = new Texture_t
|
||||||
{
|
{
|
||||||
handle = m_Texture2.NativePointer
|
handle = _texture2.NativePointer
|
||||||
};
|
};
|
||||||
err = overlay.SetOverlayTexture(overlayHandle, ref texture);
|
err = overlay.SetOverlayTexture(overlayHandle, ref texture);
|
||||||
if (err != EVROverlayError.None)
|
if (err != EVROverlayError.None)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// This work is licensed under the terms of the MIT license.
|
// This work is licensed under the terms of the MIT license.
|
||||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using CefSharp;
|
using CefSharp;
|
||||||
@@ -14,51 +13,56 @@ namespace VRCX
|
|||||||
public partial class VRForm : Form
|
public partial class VRForm : Form
|
||||||
{
|
{
|
||||||
public static VRForm Instance;
|
public static VRForm Instance;
|
||||||
private ChromiumWebBrowser Browser1;
|
private ChromiumWebBrowser _browser1;
|
||||||
private ChromiumWebBrowser Browser2;
|
private ChromiumWebBrowser _browser2;
|
||||||
|
|
||||||
public VRForm()
|
public VRForm()
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
//
|
|
||||||
Browser1 = new ChromiumWebBrowser(Path.Combine(Program.BaseDirectory, "html/vr.html?1"))
|
_browser1 = new ChromiumWebBrowser(
|
||||||
|
Path.Combine(Program.BaseDirectory, "html/vr.html?1")
|
||||||
|
)
|
||||||
{
|
{
|
||||||
DragHandler = new NoopDragHandler(),
|
DragHandler = new NoopDragHandler(),
|
||||||
BrowserSettings =
|
BrowserSettings =
|
||||||
{
|
{
|
||||||
// UniversalAccessFromFileUrls = CefState.Enabled,
|
|
||||||
DefaultEncoding = "UTF-8",
|
DefaultEncoding = "UTF-8",
|
||||||
},
|
},
|
||||||
Dock = DockStyle.Fill,
|
Dock = DockStyle.Fill
|
||||||
};
|
};
|
||||||
Browser2 = new ChromiumWebBrowser(Path.Combine(Program.BaseDirectory, "html/vr.html?2"))
|
|
||||||
|
_browser2 = new ChromiumWebBrowser(
|
||||||
|
Path.Combine(Program.BaseDirectory, "html/vr.html?2")
|
||||||
|
)
|
||||||
{
|
{
|
||||||
DragHandler = new NoopDragHandler(),
|
DragHandler = new NoopDragHandler(),
|
||||||
BrowserSettings =
|
BrowserSettings =
|
||||||
{
|
{
|
||||||
// UniversalAccessFromFileUrls = CefState.Enabled,
|
|
||||||
DefaultEncoding = "UTF-8",
|
DefaultEncoding = "UTF-8",
|
||||||
},
|
},
|
||||||
Dock = DockStyle.Fill,
|
Dock = DockStyle.Fill
|
||||||
};
|
};
|
||||||
Util.ApplyJavascriptBindings(Browser1.JavascriptObjectRepository);
|
|
||||||
Util.ApplyJavascriptBindings(Browser2.JavascriptObjectRepository);
|
Util.ApplyJavascriptBindings(_browser1.JavascriptObjectRepository);
|
||||||
panel1.Controls.Add(Browser1);
|
Util.ApplyJavascriptBindings(_browser2.JavascriptObjectRepository);
|
||||||
panel2.Controls.Add(Browser2);
|
|
||||||
|
panel1.Controls.Add(_browser1);
|
||||||
|
panel2.Controls.Add(_browser2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button_refresh_Click(object sender, System.EventArgs e)
|
private void button_refresh_Click(object sender, System.EventArgs e)
|
||||||
{
|
{
|
||||||
Browser1.ExecuteScriptAsync("location.reload()");
|
_browser1.ExecuteScriptAsync("location.reload()");
|
||||||
Browser2.ExecuteScriptAsync("location.reload()");
|
_browser2.ExecuteScriptAsync("location.reload()");
|
||||||
VRCXVR.Refresh();
|
VRCXVR.Instance.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button_devtools_Click(object sender, System.EventArgs e)
|
private void button_devtools_Click(object sender, System.EventArgs e)
|
||||||
{
|
{
|
||||||
Browser1.ShowDevTools();
|
_browser1.ShowDevTools();
|
||||||
Browser2.ShowDevTools();
|
_browser2.ShowDevTools();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user