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 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(); }