public void Update() { if (this.world == null) { // Initialize world with 0.033 time step WorldUtilities.CreateWorld <TState>(ref this.world, 0.033f); { #if FPS_MODULE_SUPPORT this.world.AddModule <FPSModule>(); #endif this.world.AddModule <StatesHistoryModule>(); this.world.AddModule <NetworkModule>(); // Add your custom modules here // Create new state this.world.SetState <TState>(WorldUtilities.CreateState <TState>()); ComponentsInitializer.DoInit(); this.Initialize(this.world); // Add your custom systems here } // Save initialization state this.world.SaveResetState <TState>(); } if (this.world != null) { var dt = Time.deltaTime; this.world.PreUpdate(dt); this.world.Update(dt); } }
public static void Do( System.Action <World> setupWorld = null, System.Action <World> initSystems = null, System.Action <World> beforeUpdate = null, System.Action <World> afterUpdate = null, int from = 0, int to = 2) { WorldUtilities.ResetTypeIds(); ME.ECS.Pools.current = new ME.ECS.PoolImplementation(isNull: false); World world = null; WorldUtilities.CreateWorld <EmptyState>(ref world, 0.033f); { world.AddModule <EmptyStatesHistoryModule>(); world.AddModule <EmptyNetworkModule>(); world.SetState <EmptyState>(WorldUtilities.CreateState <EmptyState>()); world.SetSeed(1u); { ref var str = ref world.GetStructComponents(); CoreComponentsInitializer.InitTypeId(); CoreComponentsInitializer.Init(ref str); setupWorld?.Invoke(world); } initSystems?.Invoke(world); }
public static World PrepareWorld() { World world = null; WorldUtilities.CreateWorld <TestState>(ref world, 0.033f); { world.SetState <TestState>(WorldUtilities.CreateState <TestState>()); world.SetSeed(1u); { WorldUtilities.InitComponentTypeId <ME.ECS.Views.ViewComponent>(false); WorldUtilities.InitComponentTypeId <ME.ECS.Name.Name>(false); WorldUtilities.InitComponentTypeId <ME.ECS.Transform.Childs>(false); WorldUtilities.InitComponentTypeId <ME.ECS.Collections.IntrusiveListNode>(false); WorldUtilities.InitComponentTypeId <ME.ECS.Collections.IntrusiveHashSetBucket>(false); world.GetStructComponents().Validate <ME.ECS.Views.ViewComponent>(); world.GetStructComponents().Validate <ME.ECS.Name.Name>(); world.GetStructComponents().Validate <ME.ECS.Transform.Childs>(); world.GetStructComponents().Validate <ME.ECS.Collections.IntrusiveListNode>(); world.GetStructComponents().Validate <ME.ECS.Collections.IntrusiveHashSetBucket>(); ComponentsInitializerWorld.Setup((e) => { e.ValidateData <ME.ECS.Views.ViewComponent>(); e.ValidateData <ME.ECS.Name.Name>(); e.ValidateData <ME.ECS.Transform.Childs>(); e.ValidateData <ME.ECS.Collections.IntrusiveListNode>(); e.ValidateData <ME.ECS.Collections.IntrusiveHashSetBucket>(); }); //world.SetEntitiesCapacity(1000); } } WorldUtilities.SetWorld(world); return(world); }
private void Initialize() { WorldUtilities.CreateWorld <TestState>(ref this.world, 0.033f); this.world.SetState <TestState>(WorldUtilities.CreateState <TestState>()); this.world.AddModule <TestStatesHistoryModule>(); this.world.SetSeed(1u); this.world.SaveResetState <TestState>(); }
public static World <State> CreateWorld(float tickTime = 0.05f) { World <State> world = null; WorldUtilities.CreateWorld(ref world, tickTime); world.SetState(WorldUtilities.CreateState <State>()); return(world); }
public static World <State> CreateWorld() { World <State> world = null; WorldUtilities.CreateWorld(ref world, 0.05f); world.SetState(world.CreateState()); return(world); }
public void WorldSerialization() { World CreateWorld() { World world = null; WorldUtilities.CreateWorld <TestState>(ref world, 0.033f); { world.AddModule <TestStatesHistoryModule>(); world.AddModule <FakeNetworkModule>(); world.SetState <TestState>(WorldUtilities.CreateState <TestState>()); //components { ref var sc = ref world.GetStructComponents(); ComponentsInitializerWorld.Setup(e => e.ValidateData <TestStructComponent>()); CoreComponentsInitializer.Init(ref sc); sc.Validate <TestStructComponent>(); } //settings { world.SetSettings(new WorldSettings { useJobsForSystems = false, useJobsForViews = false, turnOffViews = false, viewsSettings = new WorldViewsSettings() }); world.SetDebugSettings(WorldDebugSettings.Default); } var group = new SystemGroup(world, "GroupName"); group.AddSystem <TestSystem>(); } var ent = new Entity("Test Entity"); ent.SetPosition(UnityEngine.Vector3.zero); ent.SetData(new TestStructComponent()); world.SaveResetState <TestState>(); return(world); }
private void CreateWorld() { // Initialize world with 0.033 time step WorldUtilities.CreateWorld <TState>(ref _world, 0.033f); { #if FPS_MODULE_SUPPORT this.world.AddModule <FPSModule>(); #endif _world.AddModule <StatesHistoryModule>(); _world.AddModule <NetworkModule>(); // Add your custom modules here // Create new state _world.SetState <TState>(WorldUtilities.CreateState <TState>()); ComponentsInitializer.DoInit(); Initialize(_world); _world.SetSeed((uint)1); // Add your custom systems here } // Save initialization state _world.SaveResetState <TState>(); }
public void Update() { if (this.world == null) { // Loading level WorldUtilities.CreateWorld(ref this.world, 0.133f, this.worldId); this.world.AddModule <FPSModule>(); this.world.AddModule <StatesHistoryModule>(); this.world.AddModule <NetworkModule>(); if (this.worldConnectionId > 0) { var network = this.world.GetModule <NetworkModule>(); network.SetWorldConnection(this.worldConnectionId); network.SetDropPercent(this.dropPercent); } this.world.SetState(WorldUtilities.CreateState <State>()); this.world.GetState().worldPosition = this.transform.position; this.RegisterViewSources(); this.pointsFeatureInitParameters.pointViewSourceId = this.pointViewSourceId; this.world.AddFeature <PointsFeature, PointsFeatureInitParameters>(ref this.pointsFeatureInitParameters); this.world.AddFeature <UnitsFeature>(); this.world.AddFeature <InputFeature, ConstructParameters <Entity, Entity> >(new ConstructParameters <Entity, Entity>(this.pointsFeatureInitParameters.p1, this.pointsFeatureInitParameters.p2)); this.world.SaveResetState(); } if (this.world != null) { var dt = Time.deltaTime * this.deltaTimeMultiplier; this.world.Update(dt); } }
public void Update() { if (Input.GetKeyDown(KeyCode.A) == true) { WorldUtilities.CreateWorld(ref this.world, 0.033f); this.world.AddModule <StatesHistoryModule>(); this.world.AddModule <NetworkModule>(); var network = this.world.GetModule <NetworkModule>(); this.testCallId = network.RegisterRPC(new System.Action <int, Vector3>(this.TestCall_RPC).Method); network.RegisterObject(this, 1); this.world.SetState(this.world.CreateState()); this.world.AddEntity(new Point() { position = Vector3.one, unitsCount = 99f, increaseRate = 1f }); this.world.AddEntity(new Point() { position = Vector3.one, unitsCount = 1f, increaseRate = 1f }); this.world.AddSystem <InputSystem>(); this.world.AddSystem <PointsSystem>(); this.world.SaveResetState(); } if (Input.GetKeyDown(KeyCode.Z) == true) { WorldUtilities.CreateWorld(ref this.world, 1f); this.world.AddModule <StatesHistoryModule>(); this.world.AddModule <NetworkModule>(); var network = this.world.GetModule <NetworkModule>(); this.testCallId = network.RegisterRPC(new System.Action <int, Vector3>(this.TestCall_RPC).Method); network.RegisterObject(this, 1); this.world.SetState(this.world.CreateState()); this.world.SetCapacity <Point>(100000); for (int i = 0; i < 100000; ++i) { this.world.AddEntity(new Point() { position = Vector3.one, unitsCount = 99f, increaseRate = 1f }, updateFilters: false); } this.world.UpdateFilters <Point>(); this.world.AddSystem <InputSystem>(); this.world.AddSystem <PointsSystem>(); this.world.SaveResetState(); } if (Input.GetKeyDown(KeyCode.R) == true) { var newState = (IState <State>) this.world.CreateState(); newState.Initialize(this.world, freeze: true, restore: false); newState.CopyFrom((State)this.savedState); this.world.SetState((State)newState); ((IWorldBase)this.world).Simulate(newState.tick); } if (Input.GetKeyDown(KeyCode.P) == true) { var historyModule = this.world.GetModule <StatesHistoryModule>(); var state = historyModule.GetStateBeforeTick(this.world.GetTick()); Debug.Log("Tick: " + this.world.GetTick() + ", State Tick: " + state.tick); } if (Input.GetKey(KeyCode.F) == true) { var networkModule = this.world.GetModule <NetworkModule>(); networkModule.RPC(this, this.testCallId, 1, Vector3.one); /* * var historyModule = this.world.GetModule<StatesHistoryModule>(); * * var evt = new ME.ECS.StatesHistory.HistoryEvent() { * tick = (ulong)Random.Range(0, this.world.GetTick()), * order = 0, * id = 123, * }; * historyModule.AddEvent(evt); * Debug.Log("Add Event for tick: " + evt.tick + ", order: " + evt.order + ", method: " + evt.id); */ } if (Input.GetKeyDown(KeyCode.T) == true) { /*var historyModule = this.world.GetModule<StatesHistoryModule>(); * var evt = new ME.ECS.StatesHistory.HistoryEvent() { * tick = 0UL, * order = 0, * }; * historyModule.AddEvent(evt); * Debug.Log("Add Event for tick: " + evt.tick + ", order: " + evt.order + ", method: " + evt.id); */ } if (Input.GetKeyDown(KeyCode.S) == true) { var state = this.world.GetState(); this.savedState = this.world.CreateState(); this.savedState.Initialize(this.world, freeze: true, restore: false); this.savedState.CopyFrom(state); } if (this.world != null) { var dt = Time.deltaTime; this.world.Update(dt); } }