コード例 #1
0
        protected void FixedUpdate()
        {
            Frame frame = new Frame();

            for (byte i = 0; i < nbFingers; ++i)
            {
                Vector3 pos = palm.InverseTransformPoint(fingers[i].GetTipPosition());

                switch ((Leap.Finger.FingerType)i)
                {
                case Leap.Finger.FingerType.TYPE_THUMB:
                    frame.thumb = pos;
                    break;

                case Leap.Finger.FingerType.TYPE_INDEX:
                    frame.index = pos;
                    break;

                case Leap.Finger.FingerType.TYPE_MIDDLE:
                    frame.middle = pos;
                    break;

                case Leap.Finger.FingerType.TYPE_RING:
                    frame.ring = pos;
                    break;

                case Leap.Finger.FingerType.TYPE_PINKY:
                    frame.pinky = pos;
                    break;
                }
            }

            lock (window)
            {
                while (window.Count >= GetPredictionWindowSize())
                {
                    window.Dequeue();
                }

                window.Enqueue(frame);
            }

            UpdateCallbacks.Invoke(frame);
        }
コード例 #2
0
ファイル: Native.cs プロジェクト: zachary2234/gamebuilder
 public static Util.Maybe <TResponse> UpdateAgent <TRequest, TResponse>(string brainUid, string agentUid,
                                                                        TRequest input,
                                                                        UpdateCallbacks callbacks)
 {
     return(UpdateAgent <TRequest, TResponse>(brainUid, agentUid, input, DummyByteArray, callbacks));
 }
コード例 #3
0
ファイル: Native.cs プロジェクト: zachary2234/gamebuilder
        public static Util.Maybe <TResponse> UpdateAgent <TRequest, TResponse>(string brainUid, string agentUid,
                                                                               TRequest input, byte[] bytes,
                                                                               UpdateCallbacks callbacks)
        {
            using (new UpdateAgentLock())
                using (InGameProfiler.Section("Native.UpdateAgent"))
                    using (var pinnedBytes = Util.Pin(bytes))
                    {
                        NumUpdateCalls++;
                        bool   ok         = false;
                        string inputJson  = null;
                        string outputJson = null;

                        using (InGameProfiler.Section("ToJson"))
                        {
                            inputJson = JsonUtility.ToJson(input, false);
                        }
                        using (InGameProfiler.Section("UpdateAgentJsonNative"))
                        {
                            UserErrorHandler.Push(callbacks.handleError);
                            UserLogMessageHandler.Push(callbacks.handleLog);

                            userActorStringGetter = callbacks.getActorString;
                            userActorStringSetter = callbacks.setActorString;

                            using (InGameProfiler.Section("setting callbacks"))
                            {
                                // Avoid unnecessary calls to the Set... delegate bind functions,
                                // since those can take ~0.2ms each! Also, any pinning is
                                // unnecessary, since the life time of use is limited to this
                                // function. See:
                                // https://blogs.msdn.microsoft.com/cbrumme/2003/05/06/asynchronous-operations-pinning/

                                if (lastCallServiceFunction != callbacks.callService)
                                {
                                    SetCallServiceFunction(callbacks.callService);
                                    lastCallServiceFunction = callbacks.callService;
                                }

                                // BEGIN_GAME_BUILDER_CODE_GEN ACTOR_ACCESSOR_DELEGATE_MAYBE_SETS
                                if (lastBooleanGetterCallback != callbacks.getActorBoolean) // GENERATED
                                {
                                    SetActorBooleanGetter(callbacks.getActorBoolean);       // GENERATED
                                    lastBooleanGetterCallback = callbacks.getActorBoolean;  // GENERATED
                                }

                                if (lastBooleanSetterCallback != callbacks.setActorBoolean) // GENERATED
                                {
                                    SetActorBooleanSetter(callbacks.setActorBoolean);       // GENERATED
                                    lastBooleanSetterCallback = callbacks.setActorBoolean;  // GENERATED
                                }

                                if (lastVector3GetterCallback != callbacks.getActorVector3) // GENERATED
                                {
                                    SetActorVector3Getter(callbacks.getActorVector3);       // GENERATED
                                    lastVector3GetterCallback = callbacks.getActorVector3;  // GENERATED
                                }

                                if (lastVector3SetterCallback != callbacks.setActorVector3) // GENERATED
                                {
                                    SetActorVector3Setter(callbacks.setActorVector3);       // GENERATED
                                    lastVector3SetterCallback = callbacks.setActorVector3;  // GENERATED
                                }

                                if (lastQuaternionGetterCallback != callbacks.getActorQuaternion) // GENERATED
                                {
                                    SetActorQuaternionGetter(callbacks.getActorQuaternion);       // GENERATED
                                    lastQuaternionGetterCallback = callbacks.getActorQuaternion;  // GENERATED
                                }

                                if (lastQuaternionSetterCallback != callbacks.setActorQuaternion) // GENERATED
                                {
                                    SetActorQuaternionSetter(callbacks.setActorQuaternion);       // GENERATED
                                    lastQuaternionSetterCallback = callbacks.setActorQuaternion;  // GENERATED
                                }

                                if (lastFloatGetterCallback != callbacks.getActorFloat) // GENERATED
                                {
                                    SetActorFloatGetter(callbacks.getActorFloat);       // GENERATED
                                    lastFloatGetterCallback = callbacks.getActorFloat;  // GENERATED
                                }

                                if (lastFloatSetterCallback != callbacks.setActorFloat) // GENERATED
                                {
                                    SetActorFloatSetter(callbacks.setActorFloat);       // GENERATED
                                    lastFloatSetterCallback = callbacks.setActorFloat;  // GENERATED
                                }

                                // END_GAME_BUILDER_CODE_GEN
                            }
                            // Safe callback passing: https://docs.microsoft.com/en-us/dotnet/framework/interop/marshaling-a-delegate-as-a-callback-method
                            StringFunction captureJsonFunction = new StringFunction(json => outputJson = json);
                            ok = UpdateAgentJsonBytes(brainUid, agentUid,
                                                      inputJson, pinnedBytes.GetPointer(), bytes.Length,
                                                      captureJsonFunction);

                            UserErrorHandler.Pop();
                            UserLogMessageHandler.Pop();
                        }

                        if (!ok)
                        {
                            // TODO consider using the JSON return value for communicating the
                            // exception from JS...and throwing an exception!!
                            Debug.LogError("UpdateAgent failed. inputJson: " + inputJson);
                            return(Util.Maybe <TResponse> .CreateEmpty());
                        }
                        else
                        {
                            using (InGameProfiler.Section("FromJson"))
                            {
#if UNITY_EDITOR
                                if (outputJson.Length > 5 * 1024 * 1024)
                                {
                                    Util.LogError($"JSON response from VOOS update is getting dangerously large..exceeding 5MB. Full content: {outputJson}");
                                    Debug.Assert(false, "Editor-only JSON size check. See log for more details.");
                                }
#endif
                                TResponse response = JsonUtility.FromJson <TResponse>(outputJson);
                                return(Util.Maybe <TResponse> .CreateWith(response));
                            }
                        }
                    }
        }