예제 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public bool ProcessMessage(NetMessage message)
 {
     return(message.Match()
            .With <PhysicsWorldDataMessage>((physics) =>
     {
         MapInstance.Instance.Initialize(
             physics.PtmRatio,
             physics.GravityX,
             physics.GravityY,
             physics.VelocityIte,
             physics.PositionIte);
         Logger.Debug("Physics data received");
     })
            .With <ClientControlledObjectMessage>((m) =>
     {
         WorldManager.Instance.ControlledObjectId = m.ObjectId;
     })
            .With <EntitySpawMessage>((entitySpawn) =>
     {
         var entity = EntityFactory.Instance.CreateFromNetwork(entitySpawn.Type, entitySpawn.SubType, entitySpawn.EntityData);
         if (entity != null)
         {
             AddGameObject(entity);
             Logger.Debug("[entity]");
             Logger.Debug("id=" + entity.Id);
             Logger.Debug("position=" + entity.InitialPosition);
             var animated = entity as AnimatedEntity;
             if (animated != null)
             {
                 Logger.Debug("Animation stand for entity : " + entity.Id);
                 animated.StartAnimation(Animation.STAND);
             }
         }
     })
            .With <EntityDestroyMessage>(entityDestroyed =>
     {
         MapInstance.Instance.RemoveGameObject(entityDestroyed.ObjectId);
     })
            .With <WorldStateSnapshotMessage>((m) =>
     {
         var snapshot = new WorldStateSnapshot();
         using (var stream = new MemoryStream(m.WorldStateData))
         {
             using (var reader = new BinaryReader(stream))
             {
                 snapshot.FromNetwork(reader);
             }
         }
         WorldManager.Instance.AddWorldStateSnapshot(snapshot);
     })
            .Matched);
 }
예제 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="snapShot"></param>
 public void AddWorldStateSnapshot(WorldStateSnapshot snapShot)
 {
     if (snapShot.PhysicUpdateSequence >= m_serverPhysicUpdateSequence)
     {
         m_serverPhysicUpdateSequence = snapShot.PhysicUpdateSequence;
         m_stateSnapshots.Enqueue(snapShot);
     }
     if (m_stateSnapshots.Count == 1)
     {
         m_initialServerPhysicUpdateSequence = snapShot.PhysicUpdateSequence;
     }
     AddLocalStateSnapshot(MapInstance.Instance.ClientPhysicUpdateSequence);
 }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 public void UpdateEntitiesFromNet(WorldStateSnapshot snapShot)
 {
     foreach (var state in snapShot.States)
     {
         switch (state.Type)
         {
         case StateTypeEnum.GAME_OBJECT:
             var objState = (GameObjectState)state;
             var obj      = GetGameObject(objState.Id);
             if (obj != null)
             {
                 obj.UpdatePart(objState.Parts);
             }
             break;
         }
     }
 }
예제 #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public bool ProcessMessage(NetMessage message)
 {
     return message.Match()
         .With<PhysicsWorldDataMessage>((physics) =>
         {
             MapInstance.Instance.Initialize(
                 physics.PtmRatio,
                 physics.GravityX,
                 physics.GravityY,
                 physics.VelocityIte,
                 physics.PositionIte);
             Logger.Debug("Physics data received");
         })
         .With<ClientControlledObjectMessage>((m) =>
         {
             WorldManager.Instance.ControlledObjectId = m.ObjectId;
         })
         .With<EntitySpawMessage>((entitySpawn) =>
         {
             var entity = EntityFactory.Instance.CreateFromNetwork(entitySpawn.Type, entitySpawn.SubType, entitySpawn.EntityData);
             if (entity != null)
             {
                 AddGameObject(entity);
                 Logger.Debug("[entity]");
                 Logger.Debug("id=" + entity.Id);
                 Logger.Debug("position=" + entity.InitialPosition);
                 var animated = entity as AnimatedEntity;
                 if (animated != null)
                 {
                     Logger.Debug("Animation stand for entity : " + entity.Id);
                     animated.StartAnimation(Animation.STAND);
                 }
             }
         })
         .With<EntityDestroyMessage>(entityDestroyed =>
         {
             MapInstance.Instance.RemoveGameObject(entityDestroyed.ObjectId);
         })
         .With<WorldStateSnapshotMessage>((m) =>
         {
             var snapshot = new WorldStateSnapshot();
             using (var stream = new MemoryStream(m.WorldStateData))
             {
                 using (var reader = new BinaryReader(stream))
                 {
                     snapshot.FromNetwork(reader);
                 }
             }
             WorldManager.Instance.AddWorldStateSnapshot(snapshot);
         })
         .Matched;
 }