Exemplo n.º 1
0
        public void Store(Chunk chunk, ChunkManager manager)
        {
            int x = chunk.Coords.X & _dimMask;
            int z = chunk.Coords.Z & _dimMask;

            if (Chunks[x, z] != null)
            {
                LoadedChunks.Remove(Chunks[x, z]);
                manager.PrepareChunkForUnload(Chunks[x, z]);
            }

            Chunks[x, z] = chunk;

            LoadedChunks.Add(chunk);
            ChunksAddedSinceSort = true;
        }
Exemplo n.º 2
0
        public Chunk(ChunkManager manager, ref ChunkCoordinate coords, ref Vector3 initialPosition)
        {
            ObjectCount += 1;
            ObjectNumber = ObjectCount;
            Position = initialPosition;
            Coords = coords;
            _heightMap = new int[WIDTH, WIDTH];
            Meshes = new List<ChunkMesh>();

            Xstart = coords.X * Chunk.WIDTH;
            Zstart = coords.Z * Chunk.WIDTH;
            manager.CubeStorage.WrapCoords(ref Xstart, ref Zstart);

            ChangedSinceLoad = false;
            Empty = true;
        }
Exemplo n.º 3
0
        public void UnloadAll(ChunkManager manager)
        {
            for (int i = 0; i < LoadedChunks.Count; i++)
            {
                manager.PrepareChunkForUnload(LoadedChunks[i]);
            }
            LoadedChunks.Clear();

            for (int x = 0; x <= _dimMask; x++)
            {
                for (int z = 0; z <= _dimMask; z++)
                {
                    Chunks[x, z] = null;
                }
            }
        }
Exemplo n.º 4
0
        public void NeighborChangedStateCallback(ChunkManager manager, Chunk chunk, ChunkState state)
        {
            switch (state)
            {
                case ChunkState.Loaded:
                    {
                        LightDependenciesFlag |= Coords.Neighbors(ref chunk.Coords);
                        break;
                    }
                case ChunkState.PendingLight:
                    break;
                case ChunkState.Lighting:
                    break;
                case ChunkState.PendingBuild:
                    {
                        BuildDependenciesFlag |= Coords.Neighbors(ref chunk.Coords);
                        break;
                    }
                case ChunkState.Built:
                    break;
                case ChunkState.PendingRebuild:
                    break;
                case ChunkState.Unloading:
                    {
                        byte val = Coords.Neighbors(ref chunk.Coords);
                        if((NeighborsInMemoryFlag & val) == val) NeighborsInMemoryFlag -= val;
                        if((LightDependenciesFlag & val) == val) LightDependenciesFlag -= val;
                        if((BuildDependenciesFlag & val) == val) BuildDependenciesFlag -= val;

                        StateChanged -= chunk.NeighborChangedStateCallback;
                        chunk.StateChanged -= NeighborChangedStateCallback;

                        break;
                    }
            }
        }
Exemplo n.º 5
0
 public void ChangeState(ChunkManager manager, ChunkState newState)
 {
     //log.Write(newState.ToString(), this.ToString(), "");
     if (StateChanged != null) StateChanged(manager, this, newState);
     _state = newState;
 }
Exemplo n.º 6
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            chunkManager = new ChunkManager(this, new ChunkCoordinate(0,0,8000), new Vector3(0f,Chunk.HEIGHT * 0.9f,0f), true);
            debug.Console.AddObject("chunkManager", chunkManager);
            currentRaster = RasterizerState.CullCounterClockwise;

            // TODO: use this.Content to load your game content here
        }