public override void BeforeFixedUpdate(int deltaTime) { List <EntityBase> list = GetEntityList(); if (list.Count > 1) { Debug.LogError("CommandSyncSystem Error exist two selfComponet!"); return; } if (list.Count > 0) { EntityBase entity = list[0]; FrameCountComponent fc = m_world.GetSingletonComp <FrameCountComponent>(); T comp = new T(); BuildCommand(comp); entity.ChangeComp(comp); //缓存起来 RecordComponent rc = m_world.GetSingletonComp <RecordComponent>(); rc.m_inputCache = comp; ChangeComponentMsg msg = new ChangeComponentMsg(); msg.frame = fc.count; msg.id = entity.ID; msg.info = new ComponentInfo(); msg.info.m_compName = comp.GetType().Name; msg.info.content = Serializer.Serialize(comp); ProtocolAnalysisService.SendCommand(msg); } }
public override void BeforeFixedUpdate(int deltaTime) { FrameCountComponent fc = m_world.GetSingletonComp <FrameCountComponent>(); fc.count++; Debug.Log("-------------------- Frame:" + fc.count + "------------------------------"); }
void PushDestroyEntity(SyncSession session, int entityID) { FrameCountComponent fc = m_world.GetSingletonComp <FrameCountComponent>(); DestroyEntityMsg msg = new DestroyEntityMsg(); msg.id = entityID; msg.frame = fc.count; session.SendMsg(msg); Debug.Log("PushDestroyEntity 3"); }
public void PushSingletonComp(SyncSession session, string compName) { FrameCountComponent fc = m_world.GetSingletonComp <FrameCountComponent>(); SingletonComponent comp = m_world.GetSingletonComp(compName); ChangeSingletonComponentMsg msg = new ChangeSingletonComponentMsg(); msg.info.m_compName = compName; msg.info.content = Serializer.Serialize(comp); msg.frame = fc.count; session.SendMsg(msg); }
public void PushSyncEnity(SyncSession session, EntityBase entity) { if (!session.Connected) { return; } FrameCountComponent fc = m_world.GetSingletonComp <FrameCountComponent>(); SyncEntityMsg msg = new SyncEntityMsg(); msg.frame = fc.count; msg.id = entity.ID; msg.infos = new List <ComponentInfo>(); foreach (var c in entity.m_compDict) { Type type = c.Value.GetType(); if (!type.IsSubclassOf(typeof(ServiceComponent))) { ComponentInfo info = new ComponentInfo(); info.m_compName = type.Name; info.content = Serializer.Serialize(c.Value); msg.infos.Add(info); } } //给有连接组件的增加Self组件 if (entity.GetExistComp <ConnectionComponent>()) { ConnectionComponent comp = entity.GetComp <ConnectionComponent>(); if (comp.m_session == session) { ComponentInfo info = new ComponentInfo(); info.m_compName = "SelfComponent"; info.content = "{}"; msg.infos.Add(info); } else { ComponentInfo info = new ComponentInfo(); info.m_compName = "TheirComponent"; info.content = "{}"; msg.infos.Add(info); } } session.SendMsg(msg); }
public override void LateFixedUpdate(int deltaTime) { RecordComponent rc = m_world.GetSingletonComp <RecordComponent>(); FrameCountComponent fc = m_world.GetSingletonComp <FrameCountComponent>(); RecordInfo info = new RecordInfo(); info.frame = fc.count; info.m_inputCmd = rc.m_inputCache; info.m_changeData = rc.m_changeCache; rc.m_recordList.Add(info); //清空缓存 rc.ClearCache(); }
/// <summary> /// 从目标帧开始重新演算 /// </summary> /// <param name="frameCount"></param> public void Recalc(int frameCount) { FrameCountComponent fc = m_world.GetSingletonComp <FrameCountComponent>(); //回退到目标帧 RevertToFrame(frameCount); for (int i = frameCount; i < fc.count; i++) { //重新读取操作 LoadPlayerInput(i); //服务器输入其他人操作 ExecuteServiceMessage(i); //重新演算 m_world.FixedLoop(1000); } ClearRecordInfo(fc.count - 1); }
public override void BeforeFixedUpdate(int deltaTime) { FrameCountComponent fc = m_world.GetSingletonComp <FrameCountComponent>(); fc.count++; }