Exemple #1
0
        public ChunkManager(ContentManager content,
                            WorldManager world,
                            Camera camera, GraphicsDevice graphics,
                            ChunkGenerator chunkGen, int maxChunksX, int maxChunksY, int maxChunksZ)
        {
            WorldSize = new Point3(maxChunksX, maxChunksY, maxChunksZ);

            World       = world;
            ExitThreads = false;
            drawDistSq  = DrawDistance * DrawDistance;
            Content     = content;

            var originCoord = new GlobalVoxelCoordinate(
                (int)(world.WorldOrigin.X * world.WorldScale),
                0,
                (int)(world.WorldOrigin.Y * world.WorldScale))
                              .GetGlobalChunkCoordinate();

            chunkData = new ChunkData(this, maxChunksX - 1, maxChunksZ - 1, (int)(originCoord.X - WorldSize.X / 2 + 1), (int)(originCoord.Z - WorldSize.Z / 2 + 1));

            ChunkGen = chunkGen;

            GeneratorThread      = new Thread(GenerateThread);
            GeneratorThread.Name = "Generate";

            RebuildThread      = new Thread(RebuildVoxelsThread);
            RebuildThread.Name = "RebuildVoxels";

            WaterUpdateThread = new AutoScaleThread(this, GamePerformance.ThreadIdentifier.UpdateWater,
                                                    (f) => Water.UpdateWater());

            ToGenerate = new List <GlobalChunkCoordinate>();
            Graphics   = graphics;

            chunkGen.Manager = this;

            GameSettings.Default.ChunkGenerateTime = 0.5f;
            generateChunksTimer = new Timer(GameSettings.Default.ChunkGenerateTime, false, Timer.TimerMode.Real);
            GameSettings.Default.ChunkRebuildTime = 0.1f;
            Timer rebuildChunksTimer = new Timer(GameSettings.Default.ChunkRebuildTime, false, Timer.TimerMode.Real);

            GameSettings.Default.VisibilityUpdateTime = 0.05f;
            generateChunksTimer.HasTriggered          = true;
            rebuildChunksTimer.HasTriggered           = true;
            this.camera = camera;

            Water = new WaterManager(this);

            PauseThreads = false;

            Vector3 maxBounds = new Vector3(
                maxChunksX * VoxelConstants.ChunkSizeX / 2.0f,
                maxChunksY * VoxelConstants.ChunkSizeY / 2.0f,
                maxChunksZ * VoxelConstants.ChunkSizeZ / 2.0f);
            Vector3 minBounds = -maxBounds;

            Bounds = new BoundingBox(minBounds, maxBounds);

            Splasher = new Splasher(this);
        }
Exemple #2
0
        public ChunkManager(ContentManager Content, WorldManager World)
        {
            this.Content = Content;
            this.World   = World;

            ExitThreads = false;

            InitializeChunkMap(Point3.Zero, World.WorldSizeInChunks);

            RebuildThread = new Thread(RebuildVoxelsThread)
            {
                IsBackground = true
            };
            RebuildThread.Name = "RebuildVoxels";

            WaterUpdateThread      = new AutoScaleThread(this, (f) => Water.UpdateWater());
            this.ChunkUpdateThread = new Thread(UpdateChunks)
            {
                IsBackground = true, Name = "Update Chunks"
            };

            GameSettings.Current.VisibilityUpdateTime = 0.05f;

            Water = new WaterManager(this);

            PauseThreads = false;

            Vector3 maxBounds = new Vector3(
                World.WorldSizeInChunks.X * VoxelConstants.ChunkSizeX / 2.0f,
                World.WorldSizeInChunks.Y * VoxelConstants.ChunkSizeY / 2.0f,
                World.WorldSizeInChunks.Z * VoxelConstants.ChunkSizeZ / 2.0f);
            Vector3 minBounds = -maxBounds; // Todo: Can this just be 0,0,0?

            Bounds = new BoundingBox(minBounds, maxBounds);
        }
Exemple #3
0
        public ChunkManager(ContentManager content, 
            uint chunkSizeX, uint chunkSizeY, uint chunkSizeZ, 
            Camera camera, GraphicsDevice graphics,
            ChunkGenerator chunkGen, int maxChunksX, int maxChunksY, int maxChunksZ)
        {
            KilledVoxels = new List<Voxel>();
            ExitThreads = false;
            drawDistSq = DrawDistance * DrawDistance;
            Content = content;

            chunkData = new ChunkData(chunkSizeX, chunkSizeY, chunkSizeZ, 1.0f / chunkSizeX, 1.0f / chunkSizeY, 1.0f / chunkSizeZ, this);
            ChunkData.ChunkMap = new ConcurrentDictionary<Point3, VoxelChunk>();
            RenderList = new ConcurrentQueue<VoxelChunk>();
            RebuildList = new ConcurrentQueue<VoxelChunk>();
            RebuildLiquidsList = new ConcurrentQueue<VoxelChunk>();
            ChunkGen = chunkGen;


            GeneratedChunks = new ConcurrentQueue<VoxelChunk>();
            GeneratorThread = new Thread(GenerateThread);

            RebuildThread = new Thread(RebuildVoxelsThread);
            RebuildLiquidThread = new Thread(RebuildLiquidsThread);

            WaterThread = new Thread(UpdateWaterThread);

            ToGenerate = new List<Point3>();
            Graphics = graphics;

            chunkGen.Manager = this;

            ChunkData.MaxViewingLevel = chunkSizeY;

            GameSettings.Default.ChunkGenerateTime = 0.5f;
            generateChunksTimer = new Timer(GameSettings.Default.ChunkGenerateTime, false, Timer.TimerMode.Real);
            GameSettings.Default.ChunkRebuildTime = 0.1f;
            Timer rebuildChunksTimer = new Timer(GameSettings.Default.ChunkRebuildTime, false, Timer.TimerMode.Real);
            GameSettings.Default.VisibilityUpdateTime = 0.05f;
            visibilityChunksTimer = new Timer(GameSettings.Default.VisibilityUpdateTime, false, Timer.TimerMode.Real);
            generateChunksTimer.HasTriggered = true;
            rebuildChunksTimer.HasTriggered = true;
            visibilityChunksTimer.HasTriggered = true;
            this.camera = camera;

            Water = new WaterManager(this);

            DynamicLights = new List<DynamicLight>();

            ChunkData.Slice = SliceMode.Y;
            PauseThreads = false;

            WorldSize = new Point3(maxChunksX, maxChunksY, maxChunksZ);

            Vector3 maxBounds = new Vector3(maxChunksX * chunkSizeX * 0.5f, maxChunksY * chunkSizeY * 0.5f, maxChunksZ * chunkSizeZ * 0.5f);
            Vector3 minBounds = -maxBounds;
            Bounds = new BoundingBox(minBounds, maxBounds);
        }
Exemple #4
0
        public ChunkManager(ContentManager content,
                            WorldManager world,
                            ChunkGenerator chunkGen, int maxChunksX, int maxChunksY, int maxChunksZ)
        {
            WorldSize = new Point3(maxChunksX, maxChunksY, maxChunksZ);

            World       = world;
            ExitThreads = false;
            Content     = content;

            chunkData = new ChunkData(maxChunksX, maxChunksZ, 0, 0);

            ChunkGen = chunkGen;

            RebuildThread = new Thread(RebuildVoxelsThread)
            {
                IsBackground = true
            };
            RebuildThread.Name = "RebuildVoxels";

            WaterUpdateThread      = new AutoScaleThread(this, (f) => Water.UpdateWater());
            this.ChunkUpdateThread = new Thread(UpdateChunks)
            {
                IsBackground = true, Name = "Update Chunks"
            };

            chunkGen.Manager = this;

            GameSettings.Default.ChunkGenerateTime = 0.5f;
            GameSettings.Default.ChunkRebuildTime  = 0.1f;
            Timer rebuildChunksTimer = new Timer(GameSettings.Default.ChunkRebuildTime, false, Timer.TimerMode.Real);

            GameSettings.Default.VisibilityUpdateTime = 0.05f;
            rebuildChunksTimer.HasTriggered           = true;

            Water = new WaterManager(this);

            PauseThreads = false;

            Vector3 maxBounds = new Vector3(
                maxChunksX * VoxelConstants.ChunkSizeX / 2.0f,
                maxChunksY * VoxelConstants.ChunkSizeY / 2.0f,
                maxChunksZ * VoxelConstants.ChunkSizeZ / 2.0f);
            Vector3 minBounds = -maxBounds;

            Bounds = new BoundingBox(minBounds, maxBounds);
        }
Exemple #5
0
        public ChunkManager(ContentManager content, 
            uint chunkSizeX, uint chunkSizeY, uint chunkSizeZ,
            Camera camera, GraphicsDevice graphics, Texture2D tilemap,
            Texture2D illumMap, Texture2D sunMap, Texture2D ambientMap,
            Texture2D torchMap, ChunkGenerator chunkGen, int maxChunksX, int maxChunksY, int maxChunksZ)
        {
            KilledVoxels = new List<Voxel>();
            ExitThreads = false;
            drawDistSq = DrawDistance * DrawDistance;
            Content = content;

            chunkData = new ChunkData(chunkSizeX, chunkSizeY, chunkSizeZ, 1.0f / chunkSizeX, 1.0f / chunkSizeY, 1.0f / chunkSizeZ, tilemap, illumMap, this);
            ChunkData.ChunkMap = new ConcurrentDictionary<Point3, VoxelChunk>();
            RenderList = new ConcurrentQueue<VoxelChunk>();
            RebuildList = new ConcurrentQueue<VoxelChunk>();
            RebuildLiquidsList = new ConcurrentQueue<VoxelChunk>();
            ChunkGen = chunkGen;

            GeneratedChunks = new ConcurrentQueue<VoxelChunk>();
            GeneratorThread = new Thread(GenerateThread);

            RebuildThread = new Thread(RebuildVoxelsThread);
            RebuildLiquidThread = new Thread(RebuildLiquidsThread);

            WaterThread = new Thread(UpdateWaterThread);

            ToGenerate = new List<Point3>();
            Graphics = graphics;

            chunkGen.Manager = this;

            ChunkData.MaxViewingLevel = chunkSizeY;

            GameSettings.Default.ChunkGenerateTime = 0.5f;
            generateChunksTimer = new Timer(GameSettings.Default.ChunkGenerateTime, false, Timer.TimerMode.Real);
            GameSettings.Default.ChunkRebuildTime = 0.1f;
            Timer rebuildChunksTimer = new Timer(GameSettings.Default.ChunkRebuildTime, false, Timer.TimerMode.Real);
            GameSettings.Default.VisibilityUpdateTime = 0.05f;
            visibilityChunksTimer = new Timer(GameSettings.Default.VisibilityUpdateTime, false, Timer.TimerMode.Real);
            generateChunksTimer.HasTriggered = true;
            rebuildChunksTimer.HasTriggered = true;
            visibilityChunksTimer.HasTriggered = true;
            this.camera = camera;

            Water = new WaterManager(this);

            ChunkData.SunMap = sunMap;
            ChunkData.AmbientMap = ambientMap;
            ChunkData.TorchMap = torchMap;

            DynamicLights = new List<DynamicLight>();

            ChunkData.Slice = SliceMode.Y;
            PauseThreads = false;

            WorldSize = new Point3(maxChunksX, maxChunksY, maxChunksZ);

            Vector3 maxBounds = new Vector3(maxChunksX * chunkSizeX * 0.5f, maxChunksY * chunkSizeY * 0.5f, maxChunksZ * chunkSizeZ * 0.5f);
            Vector3 minBounds = -maxBounds;
            Bounds = new BoundingBox(minBounds, maxBounds);
        }