diff --git a/ProjectObsidian.SourceGenerators/BindingGenerator.cs b/ProjectObsidian.SourceGenerators/BindingGenerator.cs index fe1b860..6c591f4 100644 --- a/ProjectObsidian.SourceGenerators/BindingGenerator.cs +++ b/ProjectObsidian.SourceGenerators/BindingGenerator.cs @@ -46,7 +46,7 @@ private class OrderedCount private readonly string MethodReturnType; public string CountOverride => VariableNames.Count == 0 ? "" - : $" public override int {CountVariableName} => base.{CountVariableName} + {VariableNames.Count};"; + : $" public override int {CountVariableName} => base.{CountVariableName} + {VariableNames.Count};\n"; public void Add(string value) => VariableNames.Add(value); @@ -117,7 +117,7 @@ public OrderedCount(string countVariableName, string methodName, string methodRe private readonly OrderedCount _inputCount = new("NodeInputCount", "GetInputInternal", "ISyncRef"); private readonly OrderedCount _outputCount = new("NodeOutputCount", "GetOutputInternal", "INodeOutput"); private readonly OrderedCount _impulseCount = new("NodeImpulseCount", "GetImpulseInternal", "ISyncRef"); - private readonly OrderedCount _operationCount = new("NodeImpulseCount", "GetImpulseInternal", "INodeOperation"); + private readonly OrderedCount _operationCount = new("NodeOperationCount", "GetOperationInternal", "INodeOperation"); private readonly OrderedCount _inputListCount = new("NodeInputListCount", "GetInputListInternal", "ISyncList"); private readonly OrderedCount _outputListCount = new("NodeOutputListCount", "GetOutputListInternal", "ISyncList"); @@ -147,7 +147,7 @@ public string Result namespace {BindingPrefix}{_currentNameSpace}; [Category(new string[] {{""ProtoFlux/Runtimes/Execution/Nodes/{_category}""}})] -public partial class {_fullName} : {_baseType} +public partial class {_fullName} : global::FrooxEngine.ProtoFlux.Runtimes.Execution.{_baseType} {{ {Declarations} {_nodeNameOverride} @@ -203,37 +203,37 @@ public override void VisitFieldDeclaration(FieldDeclarationSyntax node) var name = node.Declaration.Variables.First().ToString(); //inputs - TypedFieldDetection(type, name, "ObjectInput", "SyncRef>", _inputCount); - TypedFieldDetection(type, name, "ObjectArgument", "SyncRef>", _inputCount); - TypedFieldDetection(type, name, "ValueInput", "SyncRef>", _inputCount); - TypedFieldDetection(type, name, "ValueArgument", "SyncRef>", _inputCount); + TypedFieldDetection(type, name, "ObjectInput", "global::FrooxEngine.SyncRef>", _inputCount); + TypedFieldDetection(type, name, "ObjectArgument", "global::FrooxEngine.SyncRef>", _inputCount); + TypedFieldDetection(type, name, "ValueInput", "global::FrooxEngine.SyncRef>", _inputCount); + TypedFieldDetection(type, name, "ValueArgument", "global::FrooxEngine.SyncRef>", _inputCount); //outputs - TypedFieldDetection(type, name, "ObjectOutput", "NodeObjectOutput<{1}>", _outputCount); - TypedFieldDetection(type, name, "ValueOutput", "NodeValueOutput<{1}>", _outputCount); + TypedFieldDetection(type, name, "ObjectOutput", "global::FrooxEngine.ProtoFlux.NodeObjectOutput<{1}>", _outputCount); + TypedFieldDetection(type, name, "ValueOutput", "global::FrooxEngine.ProtoFlux.NodeValueOutput<{1}>", _outputCount); //impulses - if (!UntypedFieldDetection(type, name, "AsyncCall", "SyncRef", _impulseCount)) - UntypedFieldDetection(type, name, "Call", "SyncRef", _impulseCount); - UntypedFieldDetection(type, name, "Continuation", "SyncRef", _impulseCount); - UntypedFieldDetection(type, name, "AsyncResumption", "SyncRef", _impulseCount); + if (!UntypedFieldDetection(type, name, "AsyncCall", "global::FrooxEngine.SyncRef", _impulseCount)) + UntypedFieldDetection(type, name, "Call", "global::FrooxEngine.SyncRef", _impulseCount); + UntypedFieldDetection(type, name, "Continuation", "global::FrooxEngine.SyncRef", _impulseCount); + UntypedFieldDetection(type, name, "AsyncResumption", "global::FrooxEngine.SyncRef", _impulseCount); //operations - UntypedFieldDetection(type, name, "Operation", "SyncNodeOperation", _operationCount); + UntypedFieldDetection(type, name, "Operation", "global::FrooxEngine.ProtoFlux.SyncNodeOperation", _operationCount); //lists //input lists - TypedFieldDetection(type, name, "ValueInputList", "SyncRefList>", _inputListCount); + TypedFieldDetection(type, name, "ValueInputList", "global::FrooxEngine.SyncRefList>", _inputListCount); //output lists - TypedFieldDetection(type, name, "ObjectInputList", "SyncRefList>", _outputListCount); + TypedFieldDetection(type, name, "ObjectInputList", "global::FrooxEngine.SyncRefList>", _outputListCount); //impulse lists - UntypedFieldDetection(type, name, "ContinuationList", "SyncRefList", _impulseListCount); + UntypedFieldDetection(type, name, "ContinuationList", "global::FrooxEngine.SyncRefList", _impulseListCount); //operation lists - UntypedFieldDetection(type, name, "SyncOperationList", "SyncList", _operationListCount); + UntypedFieldDetection(type, name, "SyncOperationList", "global::FrooxEngine.SyncList", _operationListCount); base.VisitFieldDeclaration(node); } diff --git a/ProjectObsidian/Components/Users/ImuInfo.cs b/ProjectObsidian/Components/Users/ImuInfo.cs new file mode 100644 index 0000000..306f084 --- /dev/null +++ b/ProjectObsidian/Components/Users/ImuInfo.cs @@ -0,0 +1,93 @@ +using System; +using System.Runtime.InteropServices; +using Elements.Core; +using Valve.VR; + +namespace FrooxEngine; + +[Category("Obsidian/Devices")] +public class ImuInfo : Component +{ + public readonly Sync Simulate; + public readonly SyncRef SimulatingUser; + public readonly Sync Path; + public readonly Sync Connected; + public readonly Sync SampleTime; + public readonly Sync VAccel; + public readonly Sync VGyro; + public readonly Sync OffScaleFlags; + private ulong _buffer; + private string _previousPath; + private bool _previousSimulating; + + ~ImuInfo() + { + CloseBuffer(); + } + + private void CloseBuffer() + { + if (_buffer == 0) return; + OpenVR.IOBuffer.Close(_buffer); + _previousPath = null; + _buffer = 0; + Connected.Value = false; + } + protected override void OnCommonUpdate() + { + base.OnCommonUpdate(); + + if (Simulate.Value && LocalUser == SimulatingUser.Target) + { + if (!LocalUser.VR_Active || OpenVR.IOBuffer is null || string.IsNullOrEmpty(Path.Value)) CloseBuffer(); + else if (_buffer == 0 || _previousPath != Path.Value) + { + CloseBuffer(); + unsafe + { + ulong buffer = default; + //TODO: make this not run every frame if it fails + var errorCode = OpenVR.IOBuffer.Open(Path.Value, EIOBufferMode.Read, (uint)sizeof(ImuSample_t), 0u, ref buffer); + UniLog.Log($"{buffer}, {errorCode.ToString()}"); + if (errorCode == EIOBufferError.IOBuffer_Success) + { + _buffer = buffer; + _previousPath = Path.Value; + } + } + } + if (_buffer != 0) + { + unsafe + { + var punRead = 0u; + var imuSample_t = default(ImuSample_t); + + var error = OpenVR.IOBuffer.Read(_buffer, (IntPtr)(&imuSample_t), (uint)sizeof(ImuSample_t), ref punRead); + + if (error == EIOBufferError.IOBuffer_Success && punRead == sizeof(ImuSample_t)) + { + var fSampleTime = imuSample_t.fSampleTime; + var vAccel = new double3(imuSample_t.vAccel.v0, imuSample_t.vAccel.v1, imuSample_t.vAccel.v2); + var vGyro = new double3(imuSample_t.vGyro.v0, imuSample_t.vGyro.v1, imuSample_t.vGyro.v2); + var flags = (Imu_OffScaleFlags)imuSample_t.unOffScaleFlags; + + SampleTime.Value = fSampleTime; + VAccel.Value = vAccel; + VGyro.Value = vGyro; + OffScaleFlags.Value = flags; + } + } + } + } + else + { + CloseBuffer(); + } + + if (LocalUser != SimulatingUser.Target) return; + + var connectedValue = _buffer != 0; + if (connectedValue != Connected.Value) Connected.Value = connectedValue; + } +} \ No newline at end of file