public void Initialize(World world, int chunkSize, Vector3Int position) { _commandList = Game.GraphicsContext.CommandList; this._chunkSize = chunkSize; this.Position = position; _isolevel = World.Isolevel; _seed = World.Seed; _densityGenerator = world.DensityGenerator; points = new Point[chunkSize + 1, chunkSize + 1, chunkSize + 1]; _marchingCubes = new MarchingCubes(points, _isolevel, _seed); for (int x = 0; x < points.GetLength(0); x++) { for (int y = 0; y < points.GetLength(1); y++) { for (int z = 0; z < points.GetLength(2); z++) { points[x, y, z] = new Point( new Vector3(x, y, z), //_densityGenerator.CalculateDensity(x + worldPosX, y + worldPosY, z + worldPosZ) _densityGenerator.SphereDensity(x + position.X, y + position.Y, z + position.Z, 32) ); } } } Generate(); }
public override async Task Execute() { // TODO This should be moved into a settings script (Game).Window.AllowUserResizing = true; // Preload a few chunks for (int i = 0; i < 10; i++) { var chunkEntity = new Entity(); chunkEntity.GetOrCreate <Chunk>(); Entity.AddChild(chunkEntity); chunkEntity.EnableAll(false, true); _chunkPoolInactive.Push(chunkEntity); } // Make the player and spawn it List <Entity> player = PlayerPrefab.Instantiate(); player[0].Transform.Position = new Vector3(0f, 0f, 64f); player[0].Get <BasicCameraController>().world = this; var terrainEditorScript = player[0].GetOrCreate <EditTerrain>(); terrainEditorScript.World = this; terrainEditorScript.CamComp = player[0].Get <CameraComponent>(); SceneSystem.SceneInstance.RootScene.Entities.AddRange(player); _chunkMaterial = Content.Load <Material>("Ground Material"); DensityGenerator = new DensityGenerator(Seed); Chunks = new Dictionary <Vector3, Chunk>(WorldWidth * WorldHeight * WorldDepth); CreateChunks(); while (Game.IsRunning) { foreach (Chunk chunk in _chunksToUpdate) { chunk.Generate(); } _chunksToUpdate.Clear(); await Script.NextFrame(); } }