public ClientChunk[] Process( TychaiaGameWorld world, ChunkManagerEntity manager, IGameContext gameContext, IRenderContext renderContext) { foreach ( var position in this.m_PredeterminedChunkPositions.GetPurgableAbsolutePositions( new Vector3( world.IsometricCamera.Chunk.X, world.IsometricCamera.Chunk.Y, world.IsometricCamera.Chunk.Z))) { var chunk = world.ChunkOctree.Get((long)position.X, (long)position.Y, (long)position.Z); if (chunk != null) { Console.WriteLine("FIXME: PURGING CHUNK"); // chunk.Purge(); } } return null; }
public ClientChunk[] Process( TychaiaGameWorld world, ChunkManagerEntity manager, IGameContext gameContext, IRenderContext renderContext) { if (this.ShowDebugInfo.ToLower() == "true") { foreach (var position in this.m_PredeterminedChunkPositions.GetAbsolutePositions( new Vector3( world.IsometricCamera.Chunk.X, world.IsometricCamera.Chunk.Y, world.IsometricCamera.Chunk.Z))) { Action<Color> box = color => this.m_DebugCubeRenderer.RenderWireframeCube( renderContext, new Protogame.BoundingBox { X = position.X, Y = position.Y, Z = position.Z, Width = this.m_ChunkSizePolicy.CellVoxelWidth * this.m_ChunkSizePolicy.ChunkCellWidth, Height = this.m_ChunkSizePolicy.CellVoxelHeight * this.m_ChunkSizePolicy.ChunkCellHeight, Depth = this.m_ChunkSizePolicy.CellVoxelDepth * this.m_ChunkSizePolicy.ChunkCellDepth }, color); var chunk = this.GetChunkOrGenerate( world.ChunkOctree, world.Level, (long)position.X, (long)position.Y, (long)position.Z); if (!chunk.Generated) box(Color.Yellow); else if (chunk.GraphicsEmpty) box(Color.Red); else box(Color.Green); } } else { foreach (var position in this.m_PredeterminedChunkPositions.GetAbsolutePositions( new Vector3( world.IsometricCamera.Chunk.X, world.IsometricCamera.Chunk.Y, world.IsometricCamera.Chunk.Z))) { this.GetChunkOrGenerate( world.ChunkOctree, world.Level, (long)position.X, (long)position.Y, (long)position.Z); } } return null; }
public ClientChunk[] Process( TychaiaGameWorld world, ChunkManagerEntity manager, IGameContext gameContext, IRenderContext renderContext) { // If the currently focused chunk hasn't changed, then just use // the previous list of chunks. if (world.IsometricCamera.CurrentFocus == this.m_PreviousFocusChunk && !this.m_FirstProcess) { return null; } this.m_FirstProcess = false; this.m_PreviousFocusChunk = world.IsometricCamera.CurrentFocus; return this.m_PredeterminedChunkPositions.GetChunks( world.ChunkOctree, new Vector3( world.IsometricCamera.Chunk.X, world.IsometricCamera.Chunk.Y, world.IsometricCamera.Chunk.Z)).ToArray(); }
public TychaiaGameWorld( IAssetManagerProvider assetManagerProvider, I3DRenderUtilities threedRenderUtilities, IFilteredFeatures filteredFeatures, IChunkOctreeFactory chunkOctreeFactory, IIsometricCameraFactory isometricCameraFactory, IChunkSizePolicy chunkSizePolicy, IChunkManagerEntityFactory chunkManagerEntityFactory, IProfiler profiler, IConsole console, ILevelAPI levelAPI /* temporary */, IGameUIFactory gameUIFactory, I2DRenderUtilities twodRenderUtilities, IClientNetworkAPI networkAPI, IEntityFactory entityFactory, IChunkConverter chunkConverter, IChunkCompressor chunkCompressor, IChunkGenerator chunkGenerator, ITerrainSurfaceCalculator terrainSurfaceCalculator, int uniqueClientIdentifier, Action cleanup, IViewportMode viewportMode) { this.m_3DRenderUtilities = threedRenderUtilities; this.m_FilteredFeatures = filteredFeatures; this.m_ChunkSizePolicy = chunkSizePolicy; this.m_Profiler = profiler; this.m_Console = console; this.m_2DRenderUtilities = twodRenderUtilities; this.m_NetworkAPI = networkAPI; this.m_EntityFactory = entityFactory; this.m_ChunkConverter = chunkConverter; this.m_ChunkCompressor = chunkCompressor; this.m_ChunkGenerator = chunkGenerator; this.m_TerrainSurfaceCalculator = terrainSurfaceCalculator; this.m_UniqueClientIdentifier = uniqueClientIdentifier; this.m_AssetManagerProvider = assetManagerProvider; this.m_Cleanup = cleanup; this.Level = levelAPI.NewLevel("test"); this.m_ViewportMode = viewportMode; this.m_DefaultFontAsset = this.m_AssetManagerProvider.GetAssetManager().Get<FontAsset>("font.Default"); this.ChunkOctree = chunkOctreeFactory.CreateChunkOctree<ClientChunk>(); var chunk = new ClientChunk(0, 0, 0); this.IsometricCamera = isometricCameraFactory.CreateIsometricCamera(this.ChunkOctree, chunk); this.m_ChunkManagerEntity = chunkManagerEntityFactory.CreateChunkManagerEntity(this); this.m_InventoryUIEntity = gameUIFactory.CreateInventoryUIEntity(); this.Entities = new List<IEntity> { this.m_ChunkManagerEntity, this.m_InventoryUIEntity }; // TODO: Move this somewhere better. this.m_NetworkAPI.ListenForMessage( "player update", (client, data) => { var playerState = InMemorySerializer.Deserialize<PlayerServerEntity.PlayerServerState>(data); // Lookup the player entity for this unique client ID if we have one. var player = this.Entities.OfType<PlayerEntity>() .FirstOrDefault(x => x.RuntimeData.UniqueClientIdentifier == playerState.UniqueClientID); if (player == null) { // Need to create a new player entity. player = this.m_EntityFactory.CreatePlayerEntity( new Player { UniqueClientIdentifier = playerState.UniqueClientID }); this.Entities.Add(player); } player.X = playerState.X; player.Y = playerState.Y; player.Z = playerState.Z; }); // TODO: Move this somewhere better. this.m_NetworkAPI.ListenForMessage( "player leave", (client, data) => { var playerState = InMemorySerializer.Deserialize<PlayerServerEntity.PlayerServerState>(data); // Lookup the player entity for this unique client ID if we have one. var player = this.Entities.OfType<PlayerEntity>() .FirstOrDefault(x => x.RuntimeData.UniqueClientIdentifier == playerState.UniqueClientID); // If we have a player entity, remove it from the world. if (player != null) { this.Entities.Remove(player); } }); // TODO: Move this somewhere better. this.m_NetworkAPI.ListenForMessage( "chunk available", (client, data) => { var dataChunk = this.m_ChunkCompressor.Decompress(data); var clientChunk = this.ChunkOctree.Get(dataChunk.X, dataChunk.Y, dataChunk.Z); if (clientChunk == null) { clientChunk = new ClientChunk(dataChunk.X, dataChunk.Y, dataChunk.Z); this.ChunkOctree.Set(clientChunk); } else if (clientChunk.Generated) { // TODO: We already have this chunk. The server shouldn't announce it to // us because we've already had it sent before, but at the moment the server // doesn't track this. We just ignore it for now (so we don't recompute // graphics data). Console.WriteLine("Chunk is marked as generated, will not reload from server"); return; } this.m_ChunkConverter.FromChunk(dataChunk, clientChunk); this.m_ChunkGenerator.Generate(clientChunk); }); }