void UpdateMove(EntityBase entity, int deltaTime) { MoveComponent mc = (MoveComponent)entity.GetComp("MoveComponent"); SyncVector3 newPos = mc.pos.DeepCopy(); newPos.x += (mc.dir.x * deltaTime / 1000) * mc.m_velocity / 1000; newPos.y += (mc.dir.y * deltaTime / 1000) * mc.m_velocity / 1000; newPos.z += (mc.dir.z * deltaTime / 1000) * mc.m_velocity / 1000; if (!entity.GetExistComp("FlyObjectComponent") && entity.GetExistComp("CollisionComponent")) { CollisionComponent cc = (CollisionComponent)entity.GetComp("CollisionComponent"); cc.area.position = newPos.ToVector(); if (!IsCollisionBlock(cc.area)) { mc.pos = newPos; } } else { mc.pos = newPos; } if (SyncDebugSystem.isDebug && SyncDebugSystem.IsFilter("MoveSystem")) { string content = "id: " + mc.Entity.ID + " m_pos " + mc.pos.ToVector() + " deltaTime " + deltaTime + " m_velocity " + mc.m_velocity + " m_dir " + mc.dir.ToVector(); //Debug.Log(content); //SyncDebugSystem.syncLog += content + "\n"; } }
void ReceviceCommandMsg(T cmd, params object[] objs) { //Debug.Log("ReceviceCommandMsg frame " + cmd.frame + " frame " + Serializer.Serialize(cmd)); if (SyncDebugSystem.isDebug) { SyncDebugSystem.RecordMsg("cmd_commandComponent", cmd.frame, Serializer.Serialize(cmd)); } //立即返回确认消息 AffirmMsg amsg = new AffirmMsg(); amsg.index = cmd.frame; amsg.time = cmd.time; ProtocolAnalysisService.SendCommand(amsg); if (m_world.IsStart) { EntityBase entity = m_world.GetEntity(cmd.id); AddComp(entity); //自动添加记录组件 PlayerCommandRecordComponent pcrc = entity.GetComp <PlayerCommandRecordComponent>(ComponentType.PlayerCommandRecordComponent); PlayerCommandBase record = pcrc.GetInputCahae(cmd.frame); //判断和本地的预测有没有冲突 if (record == null || !record.EqualsCmd(cmd)) { pcrc.SetConflict(cmd.frame, true); } else { pcrc.SetConflict(cmd.frame, false); } if (pcrc.lastInputFrame < cmd.frame) { pcrc.lastInputFrame = cmd.frame; } pcrc.RecordCommand(cmd); //数据完整校验 if (cmd.frame != 0 && pcrc.GetAllMessage(cmd.frame) && !pcrc.GetAllMessage(cmd.frame - 1)) { ReSendMessage(cmd.frame - 1, cmd.id); } //Recalc(); } else { GameDataCacheComponent gdcc = m_world.GetSingletonComp <GameDataCacheComponent>(); gdcc.m_noExecuteCommandList.Add(cmd); } }
public int GetRandom() { m_RandomSeed = Math.Abs((m_RandomSeed * m_randomA + m_randomB) % m_randomC); if (SyncDebugSystem.isDebug) { SyncDebugSystem.RecordRandomChange(FrameCount, m_RandomSeed, ""); } return(m_RandomSeed); }
/// <summary> /// 使用指定的实体ID创建实体,不建议直接使用 /// </summary> /// <param name="ID"></param> /// <returns></returns> public EntityBase CreateEntity(string name, int ID, params ComponentBase[] compList) { if (m_entityDict.ContainsKey(ID)) { throw new Exception("CreateEntity Entity ID has exist ! ->" + ID + "<-"); } SyncDebugSystem.AddDebugMsg("Create " + ID + " " + name); EntityBase entity = NewEntity(name, ID, compList); AddEntity(entity); return(entity); }
public void ClearBefore(int frame) { for (int i = 0; i < m_record.Count; i++) { if (m_record[i].Frame < frame) { if (SyncDebugSystem.isDebug && SyncDebugSystem.IsFilter(typeof(T).Name)) { //Debug.Log(" ClearBefore Frame:" + m_record[i].Frame + " id: " + m_record[i].ID); } m_record.RemoveAt(i); i--; } } }
public override void RevertToFrame(int frame) { RecordComponent <T> rc = m_world.GetSingletonComp <RecordComponent <T> >(); List <T> list = rc.GetRecordList(frame); if (SyncDebugSystem.IsFilter(typeof(T).Name)) { Debug.Log("数据回滚 frame:" + frame + " Count:" + list.Count); } for (int i = 0; i < list.Count; i++) { if (m_world.GetEntityIsExist(list[i].ID)) { EntityBase entity = m_world.GetEntity(list[i].ID); entity.ChangeComp((T)list[i].DeepCopy()); } else if (m_world.GetIsExistCreateRollbackCache(list[i].ID)) { Debug.Log("GetIsExistCreateRollbackCache " + list[i].ID); EntityBase entity = m_world.GetCreateRollbackCache(list[i].ID); entity.ChangeComp((T)list[i].DeepCopy()); } else if (m_world.GetIsExistDestroyRollbackCache(list[i].ID)) { Debug.Log("GetIsExistDestroyRollbackCache " + list[i].ID); EntityBase entity = m_world.GetDestroyRollbackCache(list[i].ID); entity.ChangeComp((T)list[i].DeepCopy()); } else { Debug.Log("没有找到回滚对象 " + list[i].ID + " frame " + frame); } if (SyncDebugSystem.IsFilter(typeof(T).Name)) { Debug.Log("数据回滚 ID:" + list[i].ID + " frame:" + list[i].Frame + " conent:" + Serializer.Serialize(list[i])); } } }
public override void Record(int frame) { RecordComponent <T> rc = m_world.GetSingletonComp <RecordComponent <T> > (); List <EntityBase> list = GetEntityList(); for (int i = 0; i < list.Count; i++) { T record = (T)list[i].GetComp <T>().DeepCopy(); record.Frame = frame; record.ID = list[i].ID; rc.m_record.Add(record); if (SyncDebugSystem.IsFilter(typeof(T).Name)) { Debug.Log("数据记录 ID:" + list[i].ID + " frame:" + frame + " conent:" + Serializer.Serialize(record)); } } }
void ReceviceChangeSingletonCompMsg(ChangeSingletonComponentMsg msg, params object[] objs) { SyncDebugSystem.LogAndDebug("ChangeSingletonCompMsg"); if (m_world.IsStart) { ServerCacheComponent rc = m_world.GetSingletonComp <ServerCacheComponent>(); ServiceMessageInfo info = new ServiceMessageInfo(); info.m_frame = msg.frame; info.m_type = MessageType.ChangeSingletonComponent; info.m_msg = msg; rc.m_messageList.Add(info); Recalc(msg.frame); clearReson = "ReceviceChangeSingletonCompMsg"; } else { ExecuteChangeSingletonCompMsg(msg); } }