Esempio n. 1
0
        static void SetSnapshot(DynamicObjectSnapshot snap, StringBuilder builder)
        {
            builder.Append('{');

            JsonUtil.SetString("id", snap.Id, builder);
            builder.Append(',');
            JsonUtil.SetDouble("time", snap.Timestamp, builder);
            builder.Append(',');
            JsonUtil.SetVectorRaw("p", snap.posX, snap.posY, snap.posZ, builder);
            builder.Append(',');
            JsonUtil.SetQuatRaw("r", snap.rotX, snap.rotY, snap.rotZ, snap.rotW, builder);
            if (snap.DirtyScale)
            {
                builder.Append(',');
                JsonUtil.SetVectorRaw("s", snap.scaleX, snap.scaleY, snap.scaleZ, builder);
            }

            //properties should already be formatted, just need to append them here
            if (!string.IsNullOrEmpty(snap.Properties))
            {
                //properties are an array of a single object? weird
                builder.Append(",\"properties\":[{");
                builder.Append(snap.Properties);
                builder.Append("}]");
            }

            if (!string.IsNullOrEmpty(snap.Buttons))
            {
                builder.Append(",\"buttons\":{");
                builder.Append(snap.Buttons);
                builder.Append("}");
            }

            builder.Append("}"); //close object snapshot
        }
Esempio n. 2
0
        //button properties are formated as   ,"buttons":{"input":value,"input":value}
        internal static void WriteDynamicController(DynamicData data, string props, bool writeScale, string jbuttonstates)
        {
            var s = DynamicObjectSnapshot.GetSnapshot();

            s.Id   = data.Id;
            s.posX = data.LastPosition.x;
            s.posY = data.LastPosition.y;
            s.posZ = data.LastPosition.z;
            s.rotX = data.LastRotation.x;
            s.rotY = data.LastRotation.y;
            s.rotZ = data.LastRotation.z;
            s.rotW = data.LastRotation.w;

            if (writeScale)
            {
                s.DirtyScale = true;
                s.scaleX     = data.LastScale.x;
                s.scaleY     = data.LastScale.y;
                s.scaleZ     = data.LastScale.z;
            }
            s.Properties = props;
            props        = null;
            s.Buttons    = jbuttonstates;

            s.Timestamp = Util.Timestamp(FrameCount);

            queuedSnapshots.Enqueue(s);
            tempsnapshots++;
            if (tempsnapshots > CognitiveVR_Preferences.S_DynamicSnapshotCount)
            {
                tempsnapshots    = 0;
                ReadyToWriteJson = true; //mark the coroutine as ready to pull from the queue
            }
        }
Esempio n. 3
0
 internal static DynamicObjectSnapshot GetSnapshot()
 {
     if (SnapshotPool.Count > 0)
     {
         DynamicObjectSnapshot dos = SnapshotPool.Dequeue();
         return(dos);
     }
     else
     {
         var dos = new DynamicObjectSnapshot();
         return(dos);
     }
 }
Esempio n. 4
0
        internal static void WriteDynamic(DynamicData data, string props, bool writeScale)
        {
            var s = DynamicObjectSnapshot.GetSnapshot();

            s.Id   = data.Id;
            s.posX = data.LastPosition.x;
            s.posY = data.LastPosition.y;
            s.posZ = data.LastPosition.z;
            s.rotX = data.LastRotation.x;
            s.rotY = data.LastRotation.y;
            s.rotZ = data.LastRotation.z;
            s.rotW = data.LastRotation.w;

            if (writeScale)
            {
                s.DirtyScale = true;
                s.scaleX     = data.LastScale.x;
                s.scaleY     = data.LastScale.y;
                s.scaleZ     = data.LastScale.z;
            }
            s.Properties = props;
            s.Timestamp  = Util.Timestamp(FrameCount);

            queuedSnapshots.Enqueue(s);
            tempsnapshots++;
            if (tempsnapshots > CognitiveVR_Preferences.S_DynamicSnapshotCount)
            {
                if (Time.time > NextMinSendTime || tempsnapshots > CognitiveVR_Preferences.S_DynamicExtremeSnapshotCount)
                {
                    NextMinSendTime = Time.time + CognitiveVR_Preferences.S_DynamicSnapshotMinTimer;
                    //check lastSendTimer and extreme batch size
                    tempsnapshots    = 0;
                    ReadyToWriteJson = true; //mark the coroutine as ready to pull from the queue
                }
            }
        }
        //writes manifest entry and object snapshot to string then send http request
        public IEnumerator Thread_StringThenSend(Queue <DynamicObjectManifestEntry> SendObjectManifest, Queue <DynamicObjectSnapshot> SendObjectSnapshots, CognitiveVR_Preferences.SceneSettings trackingSettings, string uniqueid, double sessiontimestamp, string sessionid)
        {
            //save and clear snapshots and manifest entries
            DynamicObjectManifestEntry[] tempObjectManifest = new DynamicObjectManifestEntry[SendObjectManifest.Count];
            SendObjectManifest.CopyTo(tempObjectManifest, 0);
            SendObjectManifest.Clear();


            DynamicObjectSnapshot[] tempSnapshots = new DynamicObjectSnapshot[SendObjectSnapshots.Count];
            SendObjectSnapshots.CopyTo(tempSnapshots, 0);

            //for (int i = 0; i<tempSnapshots.Length; i++)
            //{
            //    var s = DynamicObject.SetSnapshot(tempSnapshots[i]);
            //    Debug.Log(">>>>>>>>>>>>>queue snapshot  " + s);
            //}


            //write manifest entries to thread
            List <string> manifestEntries = new List <string>();
            bool          done            = true;

            if (tempObjectManifest.Length > 0)
            {
                done = false;
                new System.Threading.Thread(() =>
                {
                    for (int i = 0; i < tempObjectManifest.Length; i++)
                    {
                        manifestEntries.Add(DynamicObject.SetManifestEntry(tempObjectManifest[i]));
                    }
                    done = true;
                }).Start();

                while (!done)
                {
                    yield return(null);
                }
            }



            List <string> snapshots = new List <string>();

            if (tempSnapshots.Length > 0)
            {
                done = false;
                new System.Threading.Thread(() =>
                {
                    for (int i = 0; i < tempSnapshots.Length; i++)
                    {
                        snapshots.Add(DynamicObject.SetSnapshot(tempSnapshots[i]));
                    }
                    //System.GC.Collect();
                    done = true;
                }).Start();

                while (!done)
                {
                    yield return(null);
                }
            }

            while (SendObjectSnapshots.Count > 0)
            {
                SendObjectSnapshots.Dequeue().ReturnToPool();
            }

            DynamicObject.SendSavedSnapshots(manifestEntries, snapshots, trackingSettings, uniqueid, sessiontimestamp, sessionid);
        }