public bool UnRegisterGroup(int groupId) { var foundAny = false; var newObjectToKey = PoolDictionary <object, Key> .Spawn(100); foreach (var item in this.objectToKey) { if (item.Value.groupId == groupId) { var keyData = item.Value; var key = MathUtils.GetKey(keyData.groupId, keyData.objId); var foundInside = false; object obj; if (this.keyToObjects.TryGetValue(key, out obj) == true) { var found = this.keyToObjects.Remove(key); if (found == true) { foundInside = true; foundAny = true; } } if (foundInside == false) { newObjectToKey.Add(item.Key, item.Value); } } } PoolDictionary <object, Key> .Recycle(ref this.objectToKey); this.objectToKey = newObjectToKey; return(foundAny); }
void IModuleBase.OnConstruct() { this.localOrderIndex = 0; this.rpcId = 0; this.ping = 0d; this.registry = PoolDictionary <int, System.Reflection.MethodInfo> .Spawn(100); this.objectToKey = PoolDictionary <object, Key> .Spawn(100); this.keyToObjects = PoolDictionary <long, object> .Spawn(100); this.runLocalOnly = PoolHashSet <int> .Spawn(100); this.currentObjectRegistryId = 1000; this.statesHistoryModule = this.world.GetModule <StatesHistory.IStatesHistoryModule <TState> >(); this.statesHistoryModule.SetEventRunner(this); this.world.SetNetworkModule(this); this.RegisterRPC(NetworkModule <TState> .CANCEL_EVENT_RPC_ID, new System.Action <byte[]>(this.CancelEvent_RPC).Method); this.RegisterRPC(NetworkModule <TState> .PING_RPC_ID, new System.Action <double, bool>(this.Ping_RPC).Method); this.RegisterRPC(NetworkModule <TState> .SYNC_RPC_ID, new System.Action <Tick, int>(this.Sync_RPC).Method); this.RegisterObject(this, -1, -1); this.OnInitialize(); }
/*public void Simulate(Tick currentTick, Tick targetTick) { * * TState state; * var historyState = this.GetStateBeforeTick(currentTick); * if (historyState != null) { * * // State found - simulate from this state to current tick * state = historyState; * * } else { * * // Previous state was not found - need to rewind from initial state * state = this.world.GetResetState(); * this.statPlayedEvents = 0; * * } * * this.world.GetState().CopyFrom(state); * this.world.GetState().tick = targetTick; * this.world.Simulate(state.tick, targetTick); * this.world.SetFrameStartTick(targetTick); * * }*/ public void SetSyncHash(int orderId, Tick tick, int hash) { //UnityEngine.Debug.Log("SetSyncHash: " + orderId + " :: " + tick + " :: " + hash); Dictionary <int, int> dic; if (this.syncHashTable.TryGetValue(tick, out dic) == true) { if (dic.ContainsKey(orderId) == true) { dic[orderId] = hash; } else { dic.Add(orderId, hash); } } else { dic = PoolDictionary <int, int> .Spawn(4); this.syncHashTable.Add(tick, dic); } if (dic.ContainsKey(orderId) == true) { dic[orderId] = hash; } else { dic.Add(orderId, hash); } this.CleanUpHashTable(tick - 1000L); }
void IModule <TState> .OnConstruct() { this.states = new CircularQueue <TState>(this.GetTicksPerState(), this.GetQueueCapacity()); this.events = PoolDictionary <ulong, SortedList <long, HistoryEvent> > .Spawn(1000); PoolSortedList <int, HistoryEvent> .Prewarm(1000, 2); this.world.SetStatesHistoryModule(this); }
public override void Initialize(World world, bool freeze, bool restore) { base.Initialize(world, freeze, restore); if (this.playerEntities == null) { this.playerEntities = PoolDictionary <int, Entity> .Spawn(2); } }
public static Meta Create() { return(new Meta() { metaTypeId = 0, meta = PoolDictionary <System.Type, MetaType> .Spawn(8), typeById = PoolDictionary <int, System.Type> .Spawn(8), }); }
void IModuleBase.OnConstruct() { this.statesHistory = new ME.ECS.Network.StatesHistory <TState>(this.world, this.GetQueueCapacity()); //this.states = new StatesCircularQueue<TState>(this.GetTicksPerState(), this.GetQueueCapacity()); this.events = PoolDictionary <Tick, ME.ECS.Collections.SortedList <long, HistoryEvent> > .Spawn(StatesHistoryModule <TState> .POOL_EVENTS_CAPACITY); this.syncHash = PoolDictionary <Tick, int> .Spawn(StatesHistoryModule <TState> .POOL_SYNCHASH_CAPACITY); PoolSortedList <int, HistoryEvent> .Prewarm(StatesHistoryModule <TState> .POOL_HISTORY_SIZE, StatesHistoryModule <TState> .POOL_HISTORY_CAPACITY); this.world.SetStatesHistoryModule(this); }
void IModuleBase.OnConstruct() { this.isRequestsDirty = false; this.list = PoolArray <Views> .Spawn(ViewsModule.VIEWS_CAPACITY); this.rendering = PoolHashSet <ViewInfo> .Spawn(ViewsModule.VIEWS_CAPACITY); this.registryPrefabToId = PoolDictionary <IView, ViewId> .Spawn(ViewsModule.REGISTRY_CAPACITY); this.registryIdToPrefab = PoolDictionary <ViewId, IView> .Spawn(ViewsModule.REGISTRY_CAPACITY); this.registryPrefabToProvider = PoolDictionary <ViewId, IViewsProvider> .Spawn(ViewsModule.REGISTRY_PROVIDERS_CAPACITY); this.registryPrefabToProviderInitializer = PoolDictionary <ViewId, IViewsProviderInitializerBase> .Spawn(ViewsModule.REGISTRY_PROVIDERS_CAPACITY); }
void IModule <TState> .OnConstruct() { this.keyToObjects = PoolDictionary <long, object> .Spawn(100); this.objectToKey = PoolDictionary <object, Key> .Spawn(100); this.registry = PoolDictionary <int, System.Reflection.MethodInfo> .Spawn(100); this.statesHistoryModule = this.world.GetModule <StatesHistory.IStatesHistoryModule <TState> >(); this.statesHistoryModule.SetEventRunner(this); this.world.SetNetworkModule(this); this.OnInitialize(); }
public override void CopyFrom(State other) { base.CopyFrom(other); var _other = (ExampleState)other; if (this.playerEntities != null) { PoolDictionary <int, Entity> .Recycle(ref this.playerEntities); } this.playerEntities = PoolDictionary <int, Entity> .Spawn(_other.playerEntities.Count); foreach (var item in _other.playerEntities) { this.playerEntities.Add(item.Key, item.Value); } }
void IModuleBase.OnConstruct() { this.keyToObjects = PoolDictionary <long, object> .Spawn(100); this.objectToKey = PoolDictionary <object, Key> .Spawn(100); this.registry = PoolDictionary <int, System.Reflection.MethodInfo> .Spawn(100); this.statesHistoryModule = this.world.GetModule <StatesHistory.IStatesHistoryModule <TState> >(); this.statesHistoryModule.SetEventRunner(this); this.world.SetNetworkModule(this); this.RegisterRPC(NetworkModule <TState> .PING_RPC_ID, new System.Action <double, bool>(this.Ping_RPC).Method); this.RegisterRPC(NetworkModule <TState> .SYNC_RPC_ID, new System.Action <Tick, int>(this.Sync_RPC).Method); this.RegisterObject(this, -1, -1); this.OnInitialize(); }
public virtual void OnConstruct() { this.oldestTick = Tick.Invalid; this.lastSavedStateTick = Tick.Invalid; this.pauseStoreStateSinceTick = Tick.Invalid; this.prewarmed = false; this.beginAddEventsCount = 0; this.beginAddEvents = false; this.statEventsAdded = 0; this.statPlayedEvents = 0; this.statesHistory = new ME.ECS.Network.StatesHistory <TState>(this.world, this.GetQueueCapacity()); this.events = PoolDictionary <Tick, ME.ECS.Collections.SortedList <long, HistoryEvent> > .Spawn(StatesHistoryModule <TState> .POOL_EVENTS_CAPACITY); this.syncHashTable = PoolDictionary <Tick, Dictionary <int, int> > .Spawn(StatesHistoryModule <TState> .POOL_SYNCHASH_CAPACITY); this.world.SetStatesHistoryModule(this); }
private void Init(int capacity) { if (this.id == 0) { this.id = ++Serializers.idIncrement; } if (this.serializers == null) { this.serializers = PoolDictionary <System.Type, Item> .Spawn(capacity); } if (this.serializersBaseType == null) { this.serializersBaseType = PoolDictionary <System.Type, Item> .Spawn(capacity); } if (this.serializersByTypeValue == null) { this.serializersByTypeValue = PoolDictionary <byte, Item> .Spawn(capacity); } if (Serializers.initialized.ContainsKey(this.id) == false) { Serializers.initialized.Add(this.id, true); } }
public override void ApplyBeforeConnections(Graph graph) { var navMeshGraph = graph as NavMeshGraph; var graphBounds = new Bounds(navMeshGraph.graphCenter, navMeshGraph.size); var graphHeightMin = navMeshGraph.minHeight; var graphHeightMax = navMeshGraph.maxHeight; var cache = PoolDictionary <int, Item> .Spawn(100); var obstacles = PoolDictionary <int, System.Collections.Generic.List <Bounds> > .Spawn(3); foreach (var item in this.items) { cache.Add(item.requiredTile == null ? 0 : item.requiredTile.GetInstanceID(), item); } foreach (var pos in this.bounds.allPositionsWithin) { var worldPosition = this.tilemap.GetCellCenterWorld(pos) - this.tilemap.layoutGrid.cellGap; if (graphBounds.Contains(worldPosition) == false) { continue; } var tile = this.tilemap.GetTile(pos); var id = tile == null ? 0 : tile.GetInstanceID(); if (cache.TryGetValue(id, out var item) == true) { if (obstacles.TryGetValue(item.tag, out var list) == false) { list = new System.Collections.Generic.List <Bounds>(); obstacles[item.tag] = PoolList <Bounds> .Spawn(100); } list.Add(new Bounds(worldPosition, new Vector3(item.customSize == true ? item.size.x : this.tilemap.layoutGrid.cellSize.x, item.customSize == true ? item.size.y : this.tilemap.layoutGrid.cellSize.y, item.height))); if (item.height < graphHeightMin) { graphHeightMin = item.height; } if (item.height > graphHeightMax) { graphHeightMax = item.height; } } } foreach (var kv in obstacles) { var count = kv.Value.Count; BoundsCompressor.CompressBounds(kv.Value, 0.05f); UnityEngine.Debug.Log($"Obstacles bounds compress from {count} to {kv.Value.Count}"); foreach (var obstacle in kv.Value) { var source = new UnityEngine.AI.NavMeshBuildSource { area = kv.Key, shape = UnityEngine.AI.NavMeshBuildSourceShape.Box, transform = Matrix4x4.TRS(obstacle.center, this.tilemap.transform.rotation, this.tilemap.transform.lossyScale) * this.tilemap.orientationMatrix * this.tilemap.GetTransformMatrix(this.tilemap.WorldToCell(obstacle.center)), size = obstacle.size, }; navMeshGraph.AddBuildSource(source); } PoolList <Bounds> .Recycle(kv.Value); } navMeshGraph.SetMinMaxHeight(graphHeightMin, graphHeightMax); PoolDictionary <int, Item> .Recycle(ref cache); PoolDictionary <int, System.Collections.Generic.List <Bounds> > .Recycle(ref obstacles); }