Exemplo n.º 1
0
        public LoadWorld(
            I2DRenderUtilities twodRenderUtilities,
            IAssetManagerProvider assetManagerProvider,
            IBackgroundCubeEntityFactory backgroundCubeEntityFactory,
            ILevelAPI levelAPI,
            ISkin skin)
            : base(twodRenderUtilities, assetManagerProvider, backgroundCubeEntityFactory, skin)
        {
            var assetManager = assetManagerProvider.GetAssetManager();
            var returnText = assetManager.Get<LanguageAsset>("language.RETURN");

            this.AddMenuItem(returnText, () => { this.TargetWorld = this.GameContext.CreateWorld<TitleWorld>(); });

            // Get all available levels.
            foreach (var levelRef in levelAPI.GetAvailableLevels())
            {
                this.AddMenuItem(
                    new LanguageAsset(levelRef, levelRef),
                    () => { this.TargetWorld = this.GameContext.CreateWorld<TychaiaGameWorld>(); });
            }
        }
Exemplo n.º 2
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);
                });
        }