internal void AddEntity(WorldEntity entity) { Cell startingCell = FindCell(entity.Position); if (startingCell == null) { entity.Position = map.Settings.DefaultSpawnPoint.position; startingCell = FindCell(entity.Position); } Assert.IsNotNull(startingCell, $"Starting cell is not found for {entity.GetType()} at {entity.Position}"); startingCell.AddWorldEntity(entity); }
internal void DoUpdate(int deltaTime) { gridCellRelocatorTimer.Update(deltaTime); gridCellOutOfRangeTimer.Update(deltaTime); if (gridCellRelocatorTimer.Passed) { for (int i = 0; i < cellCountX; i++) { for (int j = 0; j < cellCountZ; j++) { cells[i, j].Visit(gridCellRelocator); } } foreach (WorldEntity worldEntity in visibilityChangedEntities) { worldEntity.IsVisibilityChanged = false; } foreach (WorldEntity relocatableEntity in relocatableEntities) { Cell currentCell = relocatableEntity.CurrentCell; Cell nextCell = FindCell(relocatableEntity.Position); if (nextCell == null) { relocatableEntity.Position = map.Settings.DefaultSpawnPoint.position; nextCell = FindCell(relocatableEntity.Position); } if (currentCell != nextCell) { currentCell.RemoveWorldEntity(relocatableEntity); nextCell.AddWorldEntity(relocatableEntity); } } visibilityChangedEntities.Clear(); relocatableEntities.Clear(); gridCellRelocatorTimer.Reset(GridRelocatorTime); if (gridCellOutOfRangeTimer.Passed) { gridCellOutOfRangeTimer.Reset(GridRelocatorOutOfRangeTimer); } } }