public void SingleComponentValueRollbackTest() { ResourcesConfigManager.Initialize(); WorldManager.IntervalTime = 100; LockStepEntityTestWorld world = (LockStepEntityTestWorld)WorldManager.CreateWorld <LockStepEntityTestWorld>(); world.IsClient = true; world.IsStart = true; world.IsLocal = true; ConnectStatusComponent csc = world.GetSingletonComp <ConnectStatusComponent>(); csc.confirmFrame = 0; //从目标帧之后开始计算 SelfComponent sc = new SelfComponent(); /*EntityBase c1 =*/ world.CreateEntityImmediately("1", sc); world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); TestSingleComponent tc = world.GetSingletonComp <TestSingleComponent>(); Assert.AreEqual(0, tc.testValue); TestCommandComponent cmd = new TestCommandComponent(); cmd.frame = 1; cmd.id = 1; cmd.isFire = true; GlobalEvent.DispatchTypeEvent(cmd); world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); tc = world.GetSingletonComp <TestSingleComponent>(); Assert.AreEqual(1, tc.testValue); world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); tc = world.GetSingletonComp <TestSingleComponent>(); Assert.AreEqual(1, tc.testValue); cmd = new TestCommandComponent(); cmd.frame = 2; cmd.id = 1; cmd.isFire = true; GlobalEvent.DispatchTypeEvent(cmd); world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); tc = world.GetSingletonComp <TestSingleComponent>(); Assert.AreEqual(2, tc.testValue); }
public void ValueRollbackTest() { ResourcesConfigManager.Initialize(); WorldManager.IntervalTime = 100; LockStepEntityTestWorld world = (LockStepEntityTestWorld)WorldManager.CreateWorld <LockStepEntityTestWorld>(); world.IsClient = true; world.IsStart = true; world.IsLocal = true; ConnectStatusComponent csc = world.GetSingletonComp <ConnectStatusComponent>(); csc.confirmFrame = 0; //从目标帧之后开始计算 SelfComponent sc = new SelfComponent(); EntityBase c1 = world.CreateEntityImmediately("1", sc); LockStepInputSystem.commandCache.moveDir.x = 1000; world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); LockStepInputSystem.commandCache.moveDir.x = 0000; TestMoveComponent mc = c1.GetComp <TestMoveComponent>(); //Debug.Log("mc.pos.x " + mc.pos.x + " frame " + world.FrameCount); Assert.AreEqual(400, mc.pos.x); TestCommandComponent cmd = new TestCommandComponent(); cmd.frame = 1; cmd.id = 1; GlobalEvent.DispatchTypeEvent(cmd); world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); mc = c1.GetComp <TestMoveComponent>(); //Debug.Log("mc.pos.x " + mc.pos.x + " frame " + world.FrameCount); for (int i = 0; i < 10; i++) { world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); mc = c1.GetComp <TestMoveComponent>(); //Debug.Log("mc.pos.x " + mc.pos.x + " frame " + world.FrameCount); } Assert.AreEqual(0, mc.pos.x); }
public override void OnPlayerJoin(EntityBase entity) { if (!entity.GetExistComp <TestMoveComponent>()) { TestMoveComponent c = new TestMoveComponent(); entity.AddComp(c); } if (!entity.GetExistComp <TestCommandComponent>()) { TestCommandComponent c = new TestCommandComponent(); entity.AddComp(c); } }
public override PlayerCommandBase DeepCopy() { TestCommandComponent cc = new TestCommandComponent(); //cc.id = id; //cc.frame = frame; //cc.isFire = isFire; //cc.moveDir = moveDir.DeepCopy(); //cc.skillDir = skillDir.DeepCopy(); //cc.element1 = element1; //cc.element2 = element2; return(cc); }
public override bool EqualsCmd(PlayerCommandBase cmd) { if (!(cmd is TestCommandComponent)) { return(false); } TestCommandComponent cc = cmd as TestCommandComponent; if (id != cc.id) { return(false); } if (frame != cc.frame) { return(false); } if (isFire != cc.isFire) { return(false); } if (element1 != cc.element1) { return(false); } if (element2 != cc.element2) { return(false); } if (!moveDir.Equals(cc.moveDir)) { return(false); } if (!skillDir.Equals(cc.skillDir)) { return(false); } return(true); }
public override void FixedUpdate(int deltaTime) { List <EntityBase> list = GetEntityList(); for (int i = 0; i < list.Count; i++) { TestCommandComponent cc = list[i].GetComp <TestCommandComponent>(); if (cc.isFire) { //Debug.Log("Fire " + m_world.FrameCount); TestLifeSpanComponent lsc = new TestLifeSpanComponent(); lsc.lifeTime = 500; m_world.CreateEntity("FireObject" + cc.Entity.ID, lsc); } } }
void UpdateMove(EntityBase entity, int deltaTime) { TestMoveComponent mc = (TestMoveComponent)entity.GetComp("TestMoveComponent"); TestCommandComponent cc = (TestCommandComponent)entity.GetComp("TestCommandComponent"); mc.dir = cc.moveDir; mc.m_velocity = 4000; //Debug.Log("LockStepTestMoveSystem " + mc.dir); 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; //Debug.Log("mc.pos "+ mc.pos + " newPos " + newPos + " mc.dir.x " + mc.dir.x + " mc.m_velocity " + mc.m_velocity); mc.pos = newPos; //Debug.DrawRay(newPos.ToVector(), Vector3.up, Color.yellow, 10); }
public void SameMsgTest_1() { ResourcesConfigManager.Initialize(); WorldManager.IntervalTime = 100; LockStepEntityTestWorld world = (LockStepEntityTestWorld)WorldManager.CreateWorld <LockStepEntityTestWorld>(); world.IsClient = true; world.IsStart = true; world.IsLocal = true; ConnectStatusComponent csc = world.GetSingletonComp <ConnectStatusComponent>(); csc.confirmFrame = 0; //从目标帧之后开始计算 SelfComponent sc = new SelfComponent(); EntityBase c1 = world.CreateEntityImmediately("1", sc); LockStepInputSystem.commandCache.moveDir.x = 0; world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); TestMoveComponent mc = c1.GetComp <TestMoveComponent>(); Assert.AreEqual(0, mc.pos.x); LockStepInputSystem.commandCache.moveDir.x = 1000; world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); mc = c1.GetComp <TestMoveComponent>(); Assert.AreEqual(1000, mc.pos.x); TestCommandComponent cmd = new TestCommandComponent(); cmd.frame = 1; cmd.id = 1; cmd.moveDir.x = 1000; GlobalEvent.DispatchTypeEvent(cmd); world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); mc = c1.GetComp <TestMoveComponent>(); Assert.AreEqual(1000, mc.pos.x); SameCommand sameMsg = new SameCommand(); sameMsg.id = 1; sameMsg.frame = 2; GlobalEvent.DispatchTypeEvent(sameMsg); mc = c1.GetComp <TestMoveComponent>(); world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); mc = c1.GetComp <TestMoveComponent>(); Assert.AreEqual(0, mc.pos.x); }
public void EnityRollBackTest_4() { WorldManager.IntervalTime = 100; ResourcesConfigManager.Initialize(); LockStepEntityTestWorld world = (LockStepEntityTestWorld)WorldManager.CreateWorld <LockStepEntityTestWorld>(); world.IsClient = true; world.IsStart = true; world.IsLocal = true; ConnectStatusComponent csc = world.GetSingletonComp <ConnectStatusComponent>(); csc.confirmFrame = 0; //从目标帧之后开始计算 PlayerComponent pc = new PlayerComponent(); SelfComponent sc = new SelfComponent(); /*EntityBase c1 = */ world.CreateEntityImmediately("1", pc, sc); int createFrame = -1; int destroyFrame = -1; string tmp = (1 + "FireObject" + 1); int id = tmp.ToHash(); string tmp2 = (2 + "FireObject" + 1); int id2 = tmp2.ToHash(); world.OnEntityOptimizeCreated += (entity) => { //Debug.Log("OnEntityCreate " + entity.ID + " frame " + world.FrameCount); if (entity.ID == id2) { createFrame = world.FrameCount; } }; world.OnEntityOptimizeDestroyed += (entity) => { if (entity.ID == id2) { destroyFrame = world.FrameCount; } }; Assert.AreEqual(false, world.GetEntityIsExist(id)); //没执行前不存在这个对象 Assert.AreEqual(false, world.GetEntityIsExist(id2)); //没执行前不存在这个对象 LockStepInputSystem.commandCache.isFire = true; world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); //id1 存在 id2 不存在 Assert.AreEqual(true, world.GetEntityIsExist(id)); Assert.AreEqual(false, world.GetEntityIsExist(id2)); LockStepInputSystem.commandCache.isFire = false; for (int i = 0; i < 10; i++) { world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); } TestCommandComponent cmd = new TestCommandComponent(); cmd.frame = 1; cmd.id = 1; cmd.isFire = false; GlobalEvent.DispatchTypeEvent(cmd); cmd = new TestCommandComponent(); cmd.frame = 2; cmd.id = 1; cmd.isFire = true; GlobalEvent.DispatchTypeEvent(cmd); world.CallRecalc(); //id2 不存在 id1 不存在 Assert.AreEqual(false, world.GetEntityIsExist(id2)); Assert.AreEqual(false, world.GetEntityIsExist(id)); Assert.AreEqual(-1, createFrame); //应该不派发 Assert.AreEqual(-1, destroyFrame); //不派发 }
public void EnityRollBackTest_2() { WorldManager.IntervalTime = 100; LockStepEntityTestWorld world = (LockStepEntityTestWorld)WorldManager.CreateWorld <LockStepEntityTestWorld>(); world.IsClient = true; world.IsStart = true; world.IsLocal = true; ConnectStatusComponent csc = world.GetSingletonComp <ConnectStatusComponent>(); csc.confirmFrame = 0; //从目标帧之后开始计算 PlayerComponent pc = new PlayerComponent(); SelfComponent sc = new SelfComponent(); /*EntityBase c1 =*/ world.CreateEntityImmediately("1", pc, sc); int createFrame = -1; int destroyFrame = -1; world.OnEntityOptimizeCreated += (entity) => { //Debug.Log("OnEntityCreate " + entity.ID + " frame " + world.FrameCount); createFrame = world.FrameCount; }; world.OnEntityOptimizeDestroyed += (entity) => { //Debug.Log("OnEntityDestroyed " + entity.ID + " frame " + world.FrameCount); destroyFrame = world.FrameCount; }; string tmp = (1 + "FireObject" + 1); int id = tmp.ToHash(); Assert.AreEqual(false, world.GetEntityIsExist(id)); //没执行前不存在这个对象 LockStepInputSystem.commandCache.isFire = false; world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); Assert.AreEqual(false, world.GetEntityIsExist(id)); //执行完也不存在这个对象 TestCommandComponent cmd = new TestCommandComponent(); cmd.frame = 1; cmd.id = 1; cmd.isFire = true; GlobalEvent.DispatchTypeEvent(cmd); world.CallRecalc(); world.FixedLoop(WorldManager.IntervalTime); Assert.AreEqual(true, world.GetEntityIsExist(id)); //重计算后对象出现 Assert.AreEqual(1, createFrame); //应该立即创建处这个对象 Assert.AreEqual(-1, destroyFrame); //这个对象不销毁 }