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)); }
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); }
/// <summary> /// The main entry point for the application. /// </summary> private static void Main(string[] args) { #if !DEBUG AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; // Watch for any unhandled exceptions. #endif Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; // Use invariant culture - we have to set it explicitly for every thread we create to prevent any mpq-reading problems (mostly because of number formats). Console.ForegroundColor = ConsoleColor.Yellow; PrintBanner(); PrintLicense(); PrintDebugKeys(); Console.ResetColor(); InitLoggers(); // init logging facility. Logger.Info("voxeliq v{0} warming-up..", Assembly.GetAssembly(typeof (Player)).GetName().Version); Logger.Info(string.Format("Running over {0} {1}.", PlatformInfo.DotNetFramework, PlatformInfo.DotNetFrameworkVersion)); Logger.Info(string.Format("Using game framework {0} {1}, over {2}.", PlatformInfo.GameFramework, PlatformInfo.GameFrameworkVersion, PlatformInfo.GraphicsApi)); using (var game = new SampleGame()) // startup the game. { Logger.Trace("Starting game loop.."); game.Run(); } }
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 }