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. }
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)); }
public void Init() { _game = new GameClient(); this._config = new EngineConfig(); this._engine = new Engine.Core.Engine(this._game, this._config); var cacheWidthInBlocks = ((_config.Cache.CacheRange * 2) + 1) * _config.Chunk.WidthInBlocks; var cacheLenghtInBlocks = ((_config.Cache.CacheRange*2) + 1) * _config.Chunk.LengthInBlocks; 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); }
/// <summary> /// Initializes the game. /// </summary> protected override void Initialize() { Logger.Trace("init()"); // log the init. this.Window.Title = string.Format("Voxeliq [{0}/{1}]", PlatformManager.GameFramework, PlatformManager.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, LengthInBlocks = 16, }, Cache = { CacheExtraChunks = true, ViewRange = 12, CacheRange = 16, }, 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.Saturated, }, Audio = { Enabled = audioSettings.Enabled, } }; var engine = new Engine.Core.Engine(this, config); this.ScreenManager = new GraphicsManager(this._graphicsDeviceManager, this); // start the screen manager. engine.EngineStart += OnEngineStart; engine.Run(); base.Initialize(); }
public void TestInvalidWidthInBlocksValue() { var config = new EngineConfig {Chunk = {WidthInBlocks = 0}}; config.Validate(); }
public void TestDefaultValidConfig() { var game = new GameClient(); var config = new EngineConfig(); var engine = new Engine.Core.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.LengthInBlocks, 0); // calculate expected chunk volume in blocks var expectedChunkVolumeInBlocks = config.Chunk.WidthInBlocks* config.Chunk.HeightInBlocks* config.Chunk.LengthInBlocks; 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.MaxLengthInBlocks, config.Chunk.LengthInBlocks - 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.LengthInBlocks; 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 }
public void TestInvalidCacheRangeNotGreaterThanViewRangeWhenCacheExtraChunksIsOn() { var config = new EngineConfig { Cache = { CacheExtraChunks = true, ViewRange = 2, CacheRange = 2 } }; config.Validate(); }
public void TestInvalidViewRangeNotEqualToCacheRangeWhenCacheExtraChunksIsOff() { var config = new EngineConfig { Cache = { CacheExtraChunks = false, ViewRange = 1, CacheRange = 2 } }; config.Validate(); }
public void TestInvalidViewRangeGreaterThanCacheRange() { var config = new EngineConfig { Cache = { ViewRange = 2, CacheRange = 1 } }; config.Validate(); }
public void TestInvalidCacheRangeValue() { var config = new EngineConfig { Cache = { CacheRange = 0 } }; config.Validate(); }