Exemplo n.º 1
0
        public ClientChunkStateManager(
            IChunkOctreeFactory chunkOctreeFactory,
            IPositionScaleTranslation positionScaleTranslation,
            IPredeterminedChunkPositions predeterminedChunkPositions,
            MxClient client)
        {
            this.m_PositionScaleTranslation = positionScaleTranslation;
            this.m_PredeterminedChunkPositions = predeterminedChunkPositions;

            this.m_ClientHasChunkOctree = chunkOctreeFactory.CreateChunkOctree<ServerChunk>();
        }
Exemplo n.º 2
0
        public ServerChunkManager(
            TychaiaServer server, 
            IChunkOctreeFactory chunkOctreeFactory, 
            IChunkGenerator chunkGenerator,
            IChunkSizePolicy chunkSizePolicy)
        {
            this.m_Server = server;
            this.m_ChunkOctreeFactory = chunkOctreeFactory;
            this.m_ChunkGenerator = chunkGenerator;
            this.m_ChunkSizePolicy = chunkSizePolicy;
            this.m_RequestedChunks = new ConcurrentQueue<ChunkRequest>();

            this.m_ChunkGenerator.InputDisconnect();
        }
Exemplo n.º 3
0
        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);
                });
        }