コード例 #1
0
ファイル: Engine.cs プロジェクト: hach-que/voxeliq
        private static Engine _instance; // the memory instance.

        #endregion Fields

        #region Constructors

        public Engine(Game game, EngineConfig config)
        {
            if (_instance != null)
                throw new Exception("You can not instantiate the Engine more than once.");

            _instance = this;

            this.Game = game;
            this.Configuration = config;

            config.Validate(); // validate the config.
        }
コード例 #2
0
ファイル: ChunkStorageTests.cs プロジェクト: hach-que/voxeliq
        public void Init()
        {
            _game = new SampleGame();
            this._config = new EngineConfig();

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

            this._engine = new Engine(this._game, this._config);
            this._chunkStorage = new ChunkStorage(_game);
            this._chunk = new Chunk(new Vector2Int(0, 0));
        }
コード例 #3
0
ファイル: BlockStorageTests.cs プロジェクト: hach-que/voxeliq
        public void Init()
        {
            _game = new SampleGame();
            this._config = new EngineConfig();
            this._engine = new Engine(this._game, this._config);

            var cacheWidthInBlocks = ((_config.Cache.CacheRange * 2) + 1) * _config.Chunk.WidthInBlocks;
            var cacheLenghtInBlocks = ((_config.Cache.CacheRange*2) + 1) * _config.Chunk.LenghtInBlocks;

            this._cacheXStartIndex = -cacheWidthInBlocks/2;
            this._cacheXEndIndex = cacheWidthInBlocks / 2;

            this._cacheZStartIndex = -cacheLenghtInBlocks / 2;
            this._cacheZEndIndex = cacheLenghtInBlocks / 2;

            this._directlyIndexedValidationDictionary = new Dictionary<int, BlockType>();

            // set the initial values.
            for (var x = this._cacheXStartIndex; x < this._cacheXEndIndex; x++)
            {
                for (var z = this._cacheZStartIndex; z < this._cacheZEndIndex; z++)
                {
                    var offset = BlockStorage.BlockIndexByWorldPosition(x, z);

                    for (var y = 0; y < _config.Chunk.HeightInBlocks; y++)
                    {
                        var index = offset + y;
                        var block = new Block().RandomizeType();

                        this._directlyIndexedValidationDictionary.Add(index, block.Type);

                        BlockStorage.Blocks[index] = block;
                    }
                }
            }

            // check if validationDictionaries item count is equal to CacheRange's volume.
            Assert.AreEqual(this._directlyIndexedValidationDictionary.Values.Count, _config.Cache.CacheRangeVolume);
        }
コード例 #4
0
ファイル: SampleGame.cs プロジェクト: hach-que/voxeliq
        /// <summary>
        /// Initializes the game.
        /// </summary>
        protected override void Initialize()
        {
            Logger.Trace("init()"); // log the init.
            this.Window.Title = string.Format("Voxeliq [{0}/{1}]", PlatformInfo.GameFramework, PlatformInfo.GraphicsApi); // set the window title.

            this.IsMouseVisible = false;

            // read settings.
            var audioSettings = new AudioSettings();
            var graphicsSettings = new GraphicsSettings();

            // create a new engine configuration.
            var config = new EngineConfig
            {
                Chunk =
                {
                    WidthInBlocks = 16,
                    HeightInBlocks = 128,
                    LenghtInBlocks = 16,
                },
                Cache =
                {
                    CacheExtraChunks = true,
                    ViewRange = 8,
                    CacheRange = 12,
                },
                Graphics =
                {
                    Width = graphicsSettings.Width,
                    Height = graphicsSettings.Height,
                    FullScreenEnabled = graphicsSettings.FullScreenEnabled,
                    VerticalSyncEnabled = graphicsSettings.VerticalSyncEnabled,
                    FixedTimeStepsEnabled = graphicsSettings.FixedTimeStepsEnabled,
                },
                World =
                {
                    IsInfinitive = true,
                },
                Debugging =
                {
                    GraphsEnabled = true,
                },
                Bloom =
                {
                    Enabled = false,
                    State = BloomState.Default,
                },
                Audio =
                {
                    Enabled = audioSettings.Enabled,
                }
            };

            var engine = new Engine(this, config);
            this.ScreenManager = new GraphicsManager(this._graphicsDeviceManager, this); // start the screen manager.

            engine.EngineStart += OnEngineStart;

            engine.Run();

            base.Initialize();
        }
コード例 #5
0
        public void TestDefaultValidConfig()
        {
            var game = new SampleGame();
            var config = new EngineConfig();
            var engine = new Engine(game, config);

            Assert.IsTrue(config.Validate()); // expect config validation to succeed.

            Assert.IsNotNull(config.Chunk); // chunk configuration should exist.
            Assert.IsNotNull(config.Cache); // cache configuratio should exists.

            #region validate chunk configuration

            // make sure default dimensions are valid.
            Assert.Greater(config.Chunk.WidthInBlocks, 0);
            Assert.Greater(config.Chunk.HeightInBlocks, 0);
            Assert.Greater(config.Chunk.LenghtInBlocks, 0);

            // calculate expected chunk volume in blocks
            var expectedChunkVolumeInBlocks = config.Chunk.WidthInBlocks*
                                              config.Chunk.HeightInBlocks*
                                              config.Chunk.LenghtInBlocks;
            Assert.AreEqual(config.Chunk.Volume, expectedChunkVolumeInBlocks);

            // make sure max-width-index is valid.
            Assert.AreEqual(config.Chunk.MaxWidthInBlocks,
                            config.Chunk.WidthInBlocks - 1);

            // make sure max-height-index is valid.
            Assert.AreEqual(config.Chunk.MaxHeightInBlocks,
                            config.Chunk.HeightInBlocks - 1);

            // make sure max-lenght-index is valid.
            Assert.AreEqual(config.Chunk.MaxLenghtInBlocks,
                            config.Chunk.LenghtInBlocks - 1);

            #endregion

            #region validate cache configuration

            // make sure default dimensions are valid.
            Assert.Greater(config.Cache.ViewRange, 0);
            Assert.Greater(config.Cache.CacheRange, 0);

            // make sure cache-dimension in blocks are calculated correctly.
            var expectedCacheWidthInBlocks = (config.Cache.CacheRange * 2 + 1) *
                                             config.Chunk.WidthInBlocks;

            var expectedCacheHeightInBlocks = config.Chunk.HeightInBlocks;

            var expectedCacheLenghtInBlocks = (config.Cache.CacheRange * 2 + 1) *
                                              config.Chunk.LenghtInBlocks;

            Assert.AreEqual(config.Cache.CacheRangeWidthInBlocks, expectedCacheWidthInBlocks);
            Assert.AreEqual(config.Cache.CacheRangeHeightInBlocks, expectedCacheHeightInBlocks);
            Assert.AreEqual(config.Cache.CacheRangeLenghtInBlocks, expectedCacheLenghtInBlocks);

            // if by default, cache-extra-chunks option is set to true, make sure that default cache-range > default view-range.
            if (config.Cache.CacheExtraChunks)
                Assert.Greater(config.Cache.CacheRange, config.Cache.ViewRange,
                    "Cache range must be greater view range when CacheExtraChunk option is set to true.");
            else // if by default, cache-extra-chunks option is set to false, make sure that default cache-range = default view-range.
                Assert.AreEqual(config.Cache.ViewRange, config.Cache.CacheRange,
                    "Cache range can not be different than view range when CacheExtraChunk option is set to false.");

            #endregion
        }
コード例 #6
0
ファイル: Engine.cs プロジェクト: hach-que/voxeliq
        private void Dispose(bool disposing)
        {
            if (this.Disposed)
                return; // if already disposed, just return

            if (disposing) // only dispose managed resources if we're called from directly or in-directly from user code.
            {
                _instance = null;
            }

            Disposed = true;
        }