Esempio n. 1
0
        public ChunkStorage Save()
        {
            ChunkStorage           store    = new ChunkStorage();
            Dictionary <Tile, int> tileToId = TILES.GetTileToID();

            store.X     = X;
            store.Y     = Y;
            store.Level = Level.Id;

            store.Registry = TILES.GetIDToName();

            // Saving tile
            for (int x = 0; x < CHUNK_SIZE; x++)
            {
                for (int y = 0; y < CHUNK_SIZE; y++)
                {
                    store.Tiles[y * CHUNK_SIZE + x] = tileToId[Tiles[x, y]];
                    store.Data[y * CHUNK_SIZE + x]  = Data[x, y];
                }
            }

            // Saving entities
            foreach (var e in Entities)
            {
                if (!e.IsMemberOf(ENTITIES.GROUPE_SAVE_EXCUDED))
                {
                    store.Entities.Add(e.Save());
                }
            }

            return(store);
        }
Esempio n. 2
0
        public ChunkStorage Save()
        {
            var storage  = new ChunkStorage();
            var tileToId = TILES.GetTileToID();

            storage.X     = X;
            storage.Y     = Y;
            storage.Level = Level.Id;

            storage.Registry = TILES.GetIDToName();

            // Saving tile
            for (var x = 0; x < SIZE; x++)
            {
                for (var y = 0; y < SIZE; y++)
                {
                    storage.Tiles[y * SIZE + x] = tileToId[Tiles[x, y]];
                    storage.Data[y * SIZE + x]  = Data[x, y];
                }
            }

            // Saving entities
            lock (Entities)
            {
                foreach (var entity in Entities.Where(e => !e.MemberOf(ENTITIES.GROUPE_SAVE_EXCUDED)))
                {
                    storage.Entities.Add(entity.Save());
                }
            }

            return(storage);
        }
Esempio n. 3
0
 void Awake()
 {
     _manager     = CreateManager();
     _source      = GetSource();
     CurrentPos   = Root.position;
     CurrentChunk = null;
     _storage     = new ChunkStorage();
     _storage.AddChunk(new ChunkOffset(0, 0), null);
 }
Esempio n. 4
0
        /// <summary>
        /// Adds game-components.
        /// </summary>
        private void AddComponents()
        {
            this.Rasterizer = new Rasterizer();

            this.Game.Components.Add(new InputManager(this.Game));

            this.Game.Components.Add(new AssetManager(this.Game));

#if XNA
            //this.Game.Components.Add(new Sky(this.Game));
#endif

            this.Game.Components.Add(new NewSky(this.Game));

            this.Game.Components.Add(new Fogger(this.Game));

            var chunkStorage = new ChunkStorage(this.Game);
            this.Game.Components.Add(chunkStorage);

            var vertexBuilder = new VertexBuilder(this.Game);
            this.Game.Components.Add(vertexBuilder);

            var chunkCache = new ChunkCache(this.Game);
            this.Game.Components.Add(chunkCache);

            var blockStorage = new BlockStorage(this.Game);
            this.Game.Components.Add(blockStorage);

            var world = new World(this.Game, chunkStorage, chunkCache);
            this.Game.Components.Add(world);

            this.Game.Components.Add(new Player(this.Game, world));

            this.Game.Components.Add(new Camera(this.Game));
            this.Game.Components.Add(new UserInterface(this.Game));

            this.Game.Components.Add(new InGameDebugger(this.Game));
            this.Game.Components.Add(new DebugBar(this.Game));
            this.Game.Components.Add(new GraphManager(this.Game));

#if XNA
            this.Game.Components.Add(new AudioManager(this.Game));
#endif

            var spriteBatch = new SpriteBatch(this.Game.GraphicsDevice);
            Console = new GameConsole(this.Game, spriteBatch, new GameConsoleOptions
            {
                Font                   = Game.Content.Load <SpriteFont>(@"Fonts/Verdana"),
                FontColor              = Color.LawnGreen,
                Prompt                 = ">",
                PromptColor            = Color.Crimson,
                CursorColor            = Color.OrangeRed,
                BackgroundColor        = Color.Black * 0.8f,
                PastCommandOutputColor = Color.Aqua,
                BufferColor            = Color.Gold
            });
        }
Esempio n. 5
0
        private static readonly Logger Logger = LogManager.CreateLogger(); // logging-facility.

        /// <summary>
        /// Creates a new world.
        /// </summary>
        /// <param name="game"> </param>
        /// <param name="chunkStorage"> </param>
        /// <param name="chunkCache"> </param>
        public World(Game game, ChunkStorage chunkStorage, ChunkCache chunkCache)
            : base(game)
        {
            this.Chunks      = chunkStorage;
            this._chunkCache = chunkCache;

            // export services.
            this.Game.Services.AddService(typeof(IWorld), this);
        }
Esempio n. 6
0
 internal void Initialize(WorldConfiguration config)
 {
     chunkCache          = new ChunkCache();
     storage             = new ChunkStorage();
     generator           = config.Generator;
     Player              = new Player();
     Player.PrevPosition = World.Instance.Player.Position = new Vector3(0, 100, -20);
     entityToControl     = Player;
     globalEntities.Add(new Sun());
     globalEntities.Add(new Moon());
     globalEntities.Add(Player);
 }
Esempio n. 7
0
        public void HandleCHUNK(Socket socket, byte[] data)
        {
            new BufferReader(data)
            .Ignore(sizeof(int))
            .ReadStringUTF8(out var chunkJson);

            ChunkStorage chunkStorage = chunkJson.FromJson <ChunkStorage>();

            Logger.Log <GameState>($"Loading chunk: {chunkStorage.Level}:{chunkStorage.X}-{chunkStorage.Y} ...");
            Chunk chunk = Chunk.Load(chunkStorage);

            World.GetLevel(chunkStorage.Level).Chunks[chunkStorage.X, chunkStorage.Y] = chunk;
        }
Esempio n. 8
0
        public void Init()
        {
            _game        = new GameClient();
            this._config = new EngineConfig();

            if (Engine.Core.Engine.Instance != null) // if there exists already an engine instance, dispose it first.
            {
                Engine.Core.Engine.Instance.Dispose();
            }

            this._engine       = new Engine.Core.Engine(this._game, this._config);
            this._chunkStorage = new ChunkStorage(_game);
            this._chunk        = new Chunk(new Vector2Int(0, 0));
        }
Esempio n. 9
0
        /// <summary>
        /// Adds game-components.
        /// </summary>
        private void AddComponents()
        {
            this.Components.Add(new InputManager(this));

            this.Components.Add(new AssetManager(this));

            #if XNA
            this.Components.Add(new Sky(this));
            #endif

            this.Components.Add(new Fogger(this));

            var chunkStorage = new ChunkStorage(this);
            this.Components.Add(chunkStorage);

            var vertexBuilder = new VertexBuilder(this);
            this.Components.Add(vertexBuilder);

            var chunkCache = new ChunkCache(this);
            this.Components.Add(chunkCache);

            var world = new World(this, chunkStorage, chunkCache);
            this.Components.Add(world);

            this.Components.Add(new Player(this, world));

            #if XNA
            bloom = new BloomComponent(this);
            this.Components.Add(bloom);
            #endif

            this.Components.Add(new Camera(this));
            this.Components.Add(new UserInterface(this));

            this.Components.Add(new InGameDebugger(this));
            this.Components.Add(new Statistics(this));
            this.Components.Add(new GraphManager(this));

            #if XNA
            this.Components.Add(new AudioManager(this));
            #endif

            this._timeRuler         = new TimeRuler(this);
            this._timeRuler.Visible = true;
            this._timeRuler.ShowLog = true;
            this.Components.Add(this._timeRuler);
        }
Esempio n. 10
0
        public static Chunk Load(ChunkStorage store)
        {
            Chunk chunk = new Chunk(store.X, store.Y);

            // Loading tile
            for (int x = 0; x < CHUNK_SIZE; x++)
            {
                for (int y = 0; y < CHUNK_SIZE; y++)
                {
                    chunk.Tiles[x, y] = TILES.GetTile(store.Registry[store.Tiles[y * CHUNK_SIZE + x].ToString()]);
                    chunk.Data[x, y]  = store.Data[y * CHUNK_SIZE + x];
                }
            }

            // Loading entities
            foreach (EntityStorage entityData in store.Entities)
            {
                Entity entity = entityData.ConstructEntity();
                chunk.AddEntity(entity);
            }

            return(chunk);
        }
Esempio n. 11
0
 /// <summary>
 /// Retrieves the specified chunkdata from the
 /// file system if its there otherwise from the repository
 /// </summary>
 /// <param name="chunkHash"></param>
 /// <returns></returns>
 public virtual ChunkData GetChunkData(string chunkHash)
 {
     return(ChunkData.FromChunk(ChunkStorage.GetChunk(chunkHash)));
 }
Esempio n. 12
0
 /// <summary>
 /// Save the ChunkData
 /// </summary>
 /// <param name="chunk"></param>
 /// <returns></returns>
 public virtual void SaveChunkData(ChunkData chunk)
 {
     Args.ThrowIf(!chunk.ChunkHash.Equals(chunk.Data.FromBase64().Sha256()), "Hash validation failed");
     ChunkStorage.SetChunk(chunk.ToChunk());
 }