public override void Initialize(Simulation simulation) { base.Initialize(simulation); simulationConfiguration = SimulationConfiguration.LoadConfigOrDefault(); tileMap = TileMap.DeserializeFromFile("tilemap.dat", this); if (tileMap == null) { tileMap = new TileMap(100, 100, 100.0f); tileMap.Initialize(this); ValueNoise2D vn = new ValueNoise2D(tileMap.Width, tileMap.Height); vn.startFrequencyX = 10; vn.startFrequencyY = 10; vn.calculate(); float[,] heightMap = vn.getHeightMap(); for (int x = 0; x < tileMap.Width; x++) { for (int y = 0; y < tileMap.Height; y++) { tileMap.SetTileType(x, y, heightMap[x, y] > 0.5 ? TileType.Land : TileType.Water); } } tileMap.SerializeToFile("tilemap.dat"); } creatureManager.Initialize(this); creatureManager.Deserialize("creatures.dat"); }
public override void Initialize(Simulation simulation) { base.Initialize(simulation); simulationConfiguration = SimulationConfiguration.LoadConfigOrDefault(); int poolSize = simulationConfiguration.NumThreads; if (poolSize == 0) { poolSize = Environment.ProcessorCount; } poolSize = Math.Max(1, poolSize); //ThreadPool.SetMaxThreads(poolSize, poolSize); taskManager = new TaskManager(); tileMap = TileMap.DeserializeFromFile("tilemap.dat", this); bool validTileMap = tileMap != null && tileMap.Width == simulationConfiguration.TileMapSizeX && tileMap.Height == simulationConfiguration.TileMapSizeY; if (!validTileMap) { tileMap = new TileMap( simulation.SimulationConfiguration.TileMapSizeX, simulation.simulationConfiguration.TileMapSizeY, 100.0f ); ValueNoise2D vn = new ValueNoise2D(tileMap.Width, tileMap.Height); vn.startFrequencyX = 10; vn.startFrequencyY = 10; vn.calculate(); float[,] heightMap = vn.getHeightMap(); for (int x = 0; x < tileMap.Width; x++) { for (int y = 0; y < tileMap.Height; y++) { tileMap.SetTileType(x, y, heightMap[x, y] > SimulationConfiguration.WaterPercentage ? TileType.Land : TileType.Water); } } tileMap.SerializeToFile("tilemap.dat"); } tileMap.Initialize(this); CreatureManager deserialized = CreatureManager.Deserialize("creatures/creatures.dat", this); if (deserialized != null) { creatureManager = deserialized; } else { creatureManager.Initialize(this); } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); WhiteCircleTexture = Content.Load <Texture2D>("Map/WhiteCircle512"); RenderHelper.Ini(WhiteTexture, WhiteCircleTexture); tileMap = TileMap.DeserializeFromFile("tilemap.dat", this); if (tileMap == null) { tileMap = new TileMap(100, 100, 100.0f); tileMap.Initialize(this); ValueNoise2D vn = new ValueNoise2D(tileMap.Width, tileMap.Height); vn.startFrequencyX = 10; vn.startFrequencyY = 10; vn.calculate(); float[,] heightMap = vn.getHeightMap(); for (int x = 0; x < tileMap.Width; x++) { for (int y = 0; y < tileMap.Height; y++) { tileMap.SetTileType(x, y, heightMap[x, y] > 0.5 ? TileType.Land : TileType.Water); } } tileMap.SerializeToFile("tilemap.dat"); } creatureManager.Initialize(this); creatureManager.Deserialize("creatures.dat"); modules.Add(tileMap); modules.Add(creatureManager); Creature.Initialize(); // TODO: use this.Content to load your game content here }