Ejemplo n.º 1
0
        public object GetSynchInfo(string syncInfoName)
        {
            StateUpdateObject syncInfoObject = null;
            int i = 0;

            while (syncInfoObject == null && i < Data.Count)
            {
                StateUpdateObject updateObject = Data[i];
                if (updateObject.Type == syncInfoName)
                {
                    syncInfoObject = updateObject;
                }
                i++;
            }

            if (syncInfoObject != null)
            {
                return(syncInfoObject.Information);
            }
            else
            {
                Debugger.Log("ERREUR : " + syncInfoName + " n'est pas présent dans ce ComponentSynchInfoDataObject !", UnityEngine.Color.red);
                return(null);
            }
        }
Ejemplo n.º 2
0
        private bool CompareStateUpdates(StateUpdate desObj, StateUpdateObject sup)
        {
            var passed = true;

            passed &= desObj.SiteDrive == sup.siteDrive;
            passed &= desObj.Delete(0) == sup.delete[0];
            passed &= desObj.Poi.Value.Id == sup.poiPlacementObject.id && desObj.Poi.Value.Name == sup.poiPlacementObject.name &&
                      new Vector3(desObj.Poi.Value.Position.Value.X, desObj.Poi.Value.Position.Value.Y,
                                  desObj.Poi.Value.Position.Value.Z) ==
                      sup.poiPlacementObject.position;
            passed &= desObj.Create(0).Value.Id == sup.create[0].id && desObj.Create(0).Value.Owner == sup.create[0].owner &&
                      new Vector3(desObj.Create(0).Value.Position.Value.X, desObj.Create(0).Value.Position.Value.Y,
                                  desObj.Create(0).Value.Position.Value.Z) ==
                      sup.create[0].position && new Vector3(desObj.Create(0).Value.LookDirection.Value.X,
                                                            desObj.Create(0).Value.LookDirection.Value.Y,
                                                            desObj.Create(0).Value.LookDirection.Value.Z) ==
                      sup.create[0].lookDirection;

            passed &= desObj.Update(0).Value.Id == sup.update[0].id && desObj.Update(0).Value.Owner == sup.update[0].owner &&
                      new Vector3(desObj.Update(0).Value.Position.Value.X, desObj.Update(0).Value.Position.Value.Y,
                                  desObj.Update(0).Value.Position.Value.Z) ==
                      sup.update[0].position && new Vector3(desObj.Update(0).Value.LookDirection.Value.X,
                                                            desObj.Update(0).Value.LookDirection.Value.Y,
                                                            desObj.Update(0).Value.LookDirection.Value.Z) ==
                      sup.update[0].lookDirection;

            passed &= desObj.Annotations(0).Value.LineId == sup.annotationObjects[0].lineId && desObj.Annotations(0).Value.UserId == sup.annotationObjects[0].userId &&
                      new Vector3(desObj.Annotations(0).Value.Positions(0).Value.X, desObj.Annotations(0).Value.Positions(0).Value.Y, desObj.Annotations(0).Value.Positions(0).Value.Z) ==
                      sup.annotationObjects[0].positions[0];

            return(passed);
        }
Ejemplo n.º 3
0
        public void SetSynchInfo(string syncInfoName, object info)
        {
            StateUpdateObject syncInfoObject = null;
            int i = 0;

            while (syncInfoObject == null && i < Data.Count)
            {
                StateUpdateObject updateObject = Data[i];
                if (updateObject.Type == syncInfoName)
                {
                    syncInfoObject = updateObject;
                }
                i++;
            }

            if (syncInfoObject == null)
            {
                syncInfoObject = new StateUpdateObject(syncInfoName, info);
                Data.Add(syncInfoObject);
            }
            else
            {
                syncInfoObject.Information = info;
            }
        }
Ejemplo n.º 4
0
        public StateUpdateObject[] GetSynchInfo()
        {
            StateUpdateObject baseSpeedObject    = new StateUpdateObject("BaseSpeed", BaseSpeed);
            StateUpdateObject currentSpeedObject = new StateUpdateObject("CurrentSpeed", CurrentSpeed);
            StateUpdateObject rootedTimeObject   = new StateUpdateObject("RootedTime", RootTime);

            return(new StateUpdateObject[] { baseSpeedObject, currentSpeedObject, rootedTimeObject });
        }
Ejemplo n.º 5
0
    public StateUpdateObject[] GetConstructionStateInformation()
    {
        // Ajout des informations relative à la map.
        StateUpdateObject mapID;
        int id = CurrentWorldState.GetData <BloodAndBileEngine.WorldState.Map>().ID;

        mapID = new StateUpdateObject("MAP_ID", id);

        return(new StateUpdateObject[] { mapID });
    }
Ejemplo n.º 6
0
        private bool TestStateUpdateMessage()
        {
            var sup     = new StateUpdateObject();
            var created = new RoomObjectObj
            {
                disposable    = true,
                id            = 27,
                isHidden      = false,
                lookDirection = Vector3.forward,
                owner         = "test",
                position      = Vector3.one,
                prefab        = "a test thing"
            };
            var updated = new RoomObjectObj
            {
                disposable    = false,
                id            = 23,
                isHidden      = true,
                lookDirection = Vector3.back,
                owner         = "test",
                position      = Vector3.down,
                prefab        = ""
            };
            var deleted = 0;



            var TestSUP = new StateUpdateObject
            {
                create = new List <RoomObjectObj>()
                {
                    created
                },
                update = new List <RoomObjectObj>()
                {
                    updated
                },
                delete = new List <int>()
                {
                    deleted
                },
            };

            var buf    = ServerMessageFactory.BuildMessage(TestSUP);
            var bb     = new ByteBuffer(buf);
            var desMsg = ServerMessage.GetRootAsServerMessage(bb);
            var passed = true;

            passed &= desMsg.DataType == msg.StateUpdate;
            if (passed)
            {
                passed &= CompareStateUpdates(desMsg.Data <StateUpdate>().Value, TestSUP);
            }
            return(passed);
        }
Ejemplo n.º 7
0
        public void TestStateUpdate()
        {
            var sup     = new StateUpdateObject();
            var created = new RoomObjectObj
            {
                disposable    = true,
                id            = 27,
                isHidden      = false,
                lookDirection = Vector3.forward,
                owner         = "test",
                position      = Vector3.one,
                prefab        = "a test thing"
            };
            var updated = new RoomObjectObj
            {
                disposable    = false,
                id            = 23,
                isHidden      = true,
                lookDirection = Vector3.back,
                owner         = "test",
                position      = Vector3.down,
                prefab        = ""
            };
            var deleted = 0;



            var TestSUP = new StateUpdateObject
            {
                create = new List <RoomObjectObj>()
                {
                    created
                },
                update = new List <RoomObjectObj>()
                {
                    updated
                },
                delete = new List <int>()
                {
                    deleted
                },
            };

            var fbb    = new FlatBufferBuilder(1024);
            var offset = TestSUP.ToBuffer(fbb);

            fbb.Finish(offset.Value);
            var bArray = fbb.SizedByteArray();
            var bb     = new ByteBuffer(bArray);
            var desObj = StateUpdate.GetRootAsStateUpdate(bb);
            var passed = CompareStateUpdates(desObj, TestSUP);

            print("State Update : " + (passed ? "Passed" : "Failed"));
        }
Ejemplo n.º 8
0
    // Lance une mise à jour de chaque EntitySynchroniserComponent et regroupe leurs
    // EntitySynchronizationDataObjects dans un objet StateUpdateObject portant le nom "EntitySynchronization".
    // Renvoi également un StateUpdateObject "CreatedEntities" et un StateUpdateObject "DestroyedEntities".
    public StateUpdateObject[] GetStateUpdateInformation()
    {
        StateUpdateObject EntitySyncObject = new StateUpdateObject("EntitySynchronization", null);
        List <BloodAndBileEngine.EntitySynchronizationDataObject> SyncDataObjectList = new List <BloodAndBileEngine.EntitySynchronizationDataObject>();

        foreach (BloodAndBileEngine.Entity entity in LivingEntities)
        {
            BloodAndBileEngine.EntitySynchroniserComponent syncComponent = (BloodAndBileEngine.EntitySynchroniserComponent)entity.GetComponent(typeof(BloodAndBileEngine.EntitySynchroniserComponent));
            if (syncComponent != null)
            {
                syncComponent.Update(0f);
                SyncDataObjectList.Add(syncComponent.GetSynchronizationData());
            }
        }

        EntitySyncObject.Information = SyncDataObjectList.ToArray();
        return(new StateUpdateObject[] { EntitySyncObject });
    }
Ejemplo n.º 9
0
        private bool CompareStateUpdates(StateUpdate desObj, StateUpdateObject sup)
        {
            var passed = true;

            passed &= desObj.Delete(0) == sup.delete[0];
            passed &= desObj.Create(0).Value.Id == sup.create[0].id && desObj.Create(0).Value.Owner == sup.create[0].owner &&
                      new Vector3(desObj.Create(0).Value.Position.Value.X, desObj.Create(0).Value.Position.Value.Y,
                                  desObj.Create(0).Value.Position.Value.Z) ==
                      sup.create[0].position && new Vector3(desObj.Create(0).Value.LookDirection.Value.X,
                                                            desObj.Create(0).Value.LookDirection.Value.Y,
                                                            desObj.Create(0).Value.LookDirection.Value.Z) ==
                      sup.create[0].lookDirection;

            passed &= desObj.Update(0).Value.Id == sup.update[0].id && desObj.Update(0).Value.Owner == sup.update[0].owner &&
                      new Vector3(desObj.Update(0).Value.Position.Value.X, desObj.Update(0).Value.Position.Value.Y,
                                  desObj.Update(0).Value.Position.Value.Z) ==
                      sup.update[0].position && new Vector3(desObj.Update(0).Value.LookDirection.Value.X,
                                                            desObj.Update(0).Value.LookDirection.Value.Y,
                                                            desObj.Update(0).Value.LookDirection.Value.Z) ==
                      sup.update[0].lookDirection;


            return(passed);
        }
Ejemplo n.º 10
0
        public void TestStateUpdate()
        {
            var sup     = new StateUpdateObject();
            var created = new RoomObjectObj
            {
                disposable    = true,
                id            = 27,
                isHidden      = false,
                lookDirection = Vector3.forward,
                owner         = "test",
                position      = Vector3.one,
                prefab        = "a test thing"
            };
            var updated = new RoomObjectObj
            {
                disposable    = false,
                id            = 23,
                isHidden      = true,
                lookDirection = Vector3.back,
                owner         = "test",
                position      = Vector3.down,
                prefab        = ""
            };
            var deleted = 0;

            var TestAnnotation = new AnnotationObject
            {
                isValid   = true,
                lineId    = "testLine",
                positions = new[] { Vector3.one },
                userId    = "testUser"
            };

            TargetPlacementObject poi = new TargetPlacementObject
            {
                id       = 0,
                isValid  = true,
                name     = "testPoi",
                position = Vector3.one
            };

            var sitedrive = "SomeSiteDrive";

            var TestSUP = new StateUpdateObject
            {
                poiPlacementObject = poi,
                annotationObjects  = new List <AnnotationObject>()
                {
                    TestAnnotation
                },
                create = new List <RoomObjectObj>()
                {
                    created
                },
                update = new List <RoomObjectObj>()
                {
                    updated
                },
                delete = new List <int>()
                {
                    deleted
                },
                siteDrive = sitedrive
            };

            var fbb    = new FlatBufferBuilder(1024);
            var offset = TestSUP.ToBuffer(fbb);

            fbb.Finish(offset.Value);
            var bArray = fbb.SizedByteArray();
            var bb     = new ByteBuffer(bArray);
            var desObj = StateUpdate.GetRootAsStateUpdate(bb);
            var passed = CompareStateUpdates(desObj, TestSUP);

            print("State Update : " + (passed ? "Passed" : "Failed"));
        }
Ejemplo n.º 11
0
        private bool TestStateUpdateMessage()
        {
            var sup     = new StateUpdateObject();
            var created = new RoomObjectObj
            {
                disposable    = true,
                id            = 27,
                isHidden      = false,
                lookDirection = Vector3.forward,
                owner         = "test",
                position      = Vector3.one,
                prefab        = "a test thing"
            };
            var updated = new RoomObjectObj
            {
                disposable    = false,
                id            = 23,
                isHidden      = true,
                lookDirection = Vector3.back,
                owner         = "test",
                position      = Vector3.down,
                prefab        = ""
            };
            var deleted = 0;

            var TestAnnotation = new AnnotationObject
            {
                isValid   = true,
                lineId    = "testLine",
                positions = new[] { Vector3.one },
                userId    = "testUser"
            };

            TargetPlacementObject poi = new TargetPlacementObject
            {
                id       = 0,
                isValid  = true,
                name     = "testPoi",
                position = Vector3.one
            };

            var sitedrive = "SomeSiteDrive";

            var TestSUP = new StateUpdateObject
            {
                poiPlacementObject = poi,
                annotationObjects  = new List <AnnotationObject>()
                {
                    TestAnnotation
                },
                create = new List <RoomObjectObj>()
                {
                    created
                },
                update = new List <RoomObjectObj>()
                {
                    updated
                },
                delete = new List <int>()
                {
                    deleted
                },
                siteDrive = sitedrive
            };

            var buf    = ServerMessageFactory.BuildMessage(TestSUP);
            var bb     = new ByteBuffer(buf);
            var desMsg = ServerMessage.GetRootAsServerMessage(bb);
            var passed = true;

            passed &= desMsg.DataType == msg.StateUpdate;
            if (passed)
            {
                passed &= CompareStateUpdates(desMsg.Data <StateUpdate>().Value, TestSUP);
            }
            return(passed);
        }
Ejemplo n.º 12
0
        public StateUpdateObject[] GetSynchInfo()
        {
            StateUpdateObject spellKeys = new StateUpdateObject("SpellKeyCodes", SpellKeyCodes);

            return(new StateUpdateObject[] { spellKeys });
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Upload any changes in objects owned by the local player, in scene properties, or scene objects
        /// </summary>
        private void UploadGlobalState()
        {
            lastUpdate = Time.realtimeSinceStartup;
            if (!inRoom)
            {
                return;
            }

            List <RoomObjectObj> localObjectsUpdate = new List <RoomObjectObj>();

            StateUpdateObject diffState = null;

            #region Object Updates

            if (globalState.objects != null)
            {
                foreach (RoomObjectObj obj in globalState.objects)
                {
                    if (!trackers[obj.id].isLocal)
                    {
                        continue;
                    }
                    if (!CompareObjects(obj, trackers[obj.id].ToRoomObject()))
                    {
                        localObjectsUpdate.Add(trackers[obj.id].ToRoomObject());
                    }
                }

                //update the local copy of the global state with the new values for player controlled and scene objects
                for (int i = 0; i < localObjectsUpdate.Count; i++)
                {
                    globalState.objects[globalState.objects.IndexOf(localObjectsUpdate[i])] = localObjectsUpdate[i];
                }

                if (localObjectsUpdate.Count != 0 || newRoomObjects.Count != 0)
                {
                    diffState = new StateUpdateObject {
                        update = localObjectsUpdate
                    };
                    if (newRoomObjects.Count > 0)
                    {
                        diffState.create = newRoomObjects;
                    }


                    newRoomObjects = new List <RoomObjectObj>();
                }
            }
            else
            {
                print("globalState has no objects");
            }


            #endregion

            #region Property Updates

            if (!string.IsNullOrEmpty(requestedSiteDrive)) //update scene
            {
                print("site drive changed in global");
                var mutState = diffState ?? (diffState = new StateUpdateObject());
                mutState.siteDrive = requestedSiteDrive;
                requestedSiteDrive = "";
                oldSiteDrive       = "";
            }

            if (requestedPoi.isValid)
            {
                print("Setting requested poi");
                var mutState = diffState ?? (diffState = new StateUpdateObject());
                mutState.PlacePoi(requestedPoi);
                requestedPoi.isValid = false;
            }

            if (requestedAnnotation.isValid)
            {
                print("Adding requested annotation");
                var mutState = diffState ?? (diffState = new StateUpdateObject());
                mutState.AddAnnotation(requestedAnnotation);
                requestedAnnotation.isValid = false;
            }
            if (requestedAnnotationDeletions != null)
            {
                var mutState = diffState ?? (diffState = new StateUpdateObject());
                for (int i = 0; i < requestedAnnotationDeletions.Count; i++)
                {
                    var del = requestedAnnotationDeletions[i];
                    del.positions = new UnityEngine.Vector3[0];
                    del.isValid   = true;
                    mutState.AddAnnotation(del);
                }
                requestedAnnotationDeletions = null;
            }

            #endregion

            if (diffState != null
                ) //Serialize the updates to json and pass them to the NeuraCore to be sent to the server
            {
                NeuraCore.Instance.SetUpdate(ServerMessageFactory.BuildMessage(diffState));
            }
            //Find all local owned and scene objects that have changed since the last tick
            oldStateGen = new RoomStateGen(globalState);
        }
Ejemplo n.º 14
0
        public StateUpdateObject[] GetSynchInfo()
        {
            StateUpdateObject valueObject = new StateUpdateObject("Value", value);

            return(new StateUpdateObject[] { valueObject });
        }
Ejemplo n.º 15
0
        public StateUpdateObject[] GetSynchInfo()
        {
            StateUpdateObject humors = new StateUpdateObject("Humors", new int[] { Blood, Phlegm, YellowBile, BlackBile });

            return(new StateUpdateObject[] { humors });
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Upload any changes in objects owned by the local player, in scene properties, or scene objects
        /// </summary>
        private void UploadGlobalState()
        {
            lastUpdate = Time.realtimeSinceStartup;
            if (!inRoom)
            {
                return;
            }

            List <RoomObjectObj> localObjectsUpdate = new List <RoomObjectObj>();

            StateUpdateObject diffState = null;

            #region Object Updates

            if (globalState.objects != null)
            {
                foreach (RoomObjectObj obj in globalState.objects)
                {
                    if (!trackers[obj.id].isLocal)
                    {
                        continue;
                    }
                    if (!CompareObjects(obj, trackers[obj.id].ToRoomObject()))
                    {
                        localObjectsUpdate.Add(trackers[obj.id].ToRoomObject());
                    }
                }

                //update the local copy of the global state with the new values for player controlled and scene objects
                for (int i = 0; i < localObjectsUpdate.Count; i++)
                {
                    globalState.objects[globalState.objects.IndexOf(localObjectsUpdate[i])] = localObjectsUpdate[i];
                }

                if (localObjectsUpdate.Count != 0 || newRoomObjects.Count != 0)
                {
                    diffState = new StateUpdateObject {
                        update = localObjectsUpdate
                    };
                    if (newRoomObjects.Count > 0)
                    {
                        diffState.create = newRoomObjects;
                    }


                    newRoomObjects = new List <RoomObjectObj>();
                }
            }
            else
            {
                print("globalState has no objects");
            }


            #endregion

            #region Property Updates

            #endregion

            if (diffState != null
                ) //Serialize the updates to json and pass them to the NeuraCore to be sent to the server
            {
                NeuraCore.Instance.SetUpdate(ServerMessageFactory.BuildMessage(diffState));
            }
            //Find all local owned and scene objects that have changed since the last tick
            oldStateGen = new RoomStateGen(globalState);
        }