コード例 #1
0
ファイル: VoxelMap.cs プロジェクト: tomba/dwarrowdelf
 public void SetVoxel(IntVector3 p, Voxel voxel)
 {
     this.Grid[p.Z, p.Y, p.X] = voxel;
 }
コード例 #2
0
ファイル: Chunk.cs プロジェクト: tomba/dwarrowdelf
        void HandleVoxel(IntVector3 p, ref Voxel vox, ref IntGrid3 viewGrid, Direction visibleChunkFaces,
			VertexList<TerrainVertex> vertexList)
        {
            // Faces that are visible due to viewgrid
            Direction sliceFaces = GetVoxelSliceDirections(p, ref viewGrid) & visibleChunkFaces;

            // Faces that are drawn (if there's something to draw)
            Direction visibleFaces = (vox.VisibleFaces | sliceFaces) & visibleChunkFaces;

            if (visibleFaces == 0)
                return;

            FaceTexture baseTexture, topTexture;

            GetTextures(p, ref vox, out baseTexture, out topTexture, sliceFaces);

            CreateCube(p, visibleFaces, ref baseTexture, ref topTexture, vertexList,
                sliceFaces);
        }
コード例 #3
0
ファイル: Chunk.cs プロジェクト: tomba/dwarrowdelf
        void FillVoxelMap()
        {
            m_voxelMap = new VoxelMap(ChunkSize);

            foreach (var p in m_voxelMap.Size.Range())
            {
                var mp = this.ChunkOffset + p;

                var td = m_map.GetTileData(mp);

                // we don't use VisibleFaces for Empty, and Undefined is always hidden
                if (td.IsEmptyNoWater || td.IsUndefined)
                    continue;

                Voxel v = new Voxel();

                v.VisibleFaces = GetVisibleFaces(mp);

                m_voxelMap.SetVoxel(mp - this.ChunkOffset, v);
            }
        }
コード例 #4
0
ファイル: Chunk.cs プロジェクト: tomba/dwarrowdelf
        void GetTextures(IntVector3 p, ref Voxel vox, out FaceTexture baseTexture, out FaceTexture topTexture,
			Direction sliceFaces)
        {
            var td = m_map.GetTileData(p);

            baseTexture = new FaceTexture();
            topTexture = new FaceTexture();

            if (td.IsUndefined)
            {
                baseTexture = Chunk.UndefinedFaceTexture;
                topTexture = baseTexture;
                return;
            }

            if (td.WaterLevel > 0)
            {
                baseTexture.Symbol1 = SymbolID.Water;
                baseTexture.Color0 = GameColor.MediumBlue;
                baseTexture.Color1 = GameColor.SeaGreen;
                topTexture = baseTexture;
                return;
            }

            switch (td.ID)
            {
                case TileID.NaturalWall:
                    var matInfo = Materials.GetMaterial(td.MaterialID);
                    var color = matInfo.Color;

                    baseTexture.Color0 = GameColor.None;
                    baseTexture.Symbol1 = SymbolID.Wall;
                    baseTexture.Color1 = color;

                    var secondaryMatInfo = Materials.GetMaterial(td.SecondaryMaterialID);

                    switch (secondaryMatInfo.Category)
                    {
                        case MaterialCategory.Gem:
                            baseTexture.Symbol2 = SymbolID.GemOre;
                            baseTexture.Color2 = secondaryMatInfo.Color;
                            break;

                        case MaterialCategory.Mineral:
                            baseTexture.Symbol2 = SymbolID.ValuableOre;
                            baseTexture.Color2 = secondaryMatInfo.Color;
                            break;

                        default:
                            break;
                    }

                    // If the top face of the tile is visible, and it's not the slice level, we have a "floor"
                    if ((sliceFaces & Direction.Up) == 0 && (vox.VisibleFaces & Direction.PositiveZ) != 0)
                    {
                        if (m_map.Contains(p.Up) && m_map.GetTileData(p.Up).IsGreen)
                        {
                            var tdUp = m_map.GetTileData(p.Up);
                            var matInfoUp = Materials.GetMaterial(tdUp.MaterialID);

                            SymbolID symbol;

                            switch (matInfoUp.ID)
                            {
                                case MaterialID.ReedGrass:
                                    symbol = SymbolID.Grass4;
                                    break;

                                case MaterialID.RyeGrass:
                                    symbol = SymbolID.Grass2;
                                    break;

                                case MaterialID.MeadowGrass:
                                    symbol = SymbolID.Grass3;
                                    break;

                                case MaterialID.HairGrass:
                                    symbol = SymbolID.Grass;
                                    break;

                                default:
                                    symbol = SymbolID.Undefined;
                                    break;
                            }

                            topTexture.Color0 = GameColor.Green;
                            topTexture.Symbol1 = symbol;
                            topTexture.Color1 = GameColor.Green;
                        }
                        else if (matInfo.Category == MaterialCategory.Soil)
                        {
                            topTexture.Color0 = color;
                            topTexture.Symbol1 = SymbolID.Sand;
                            topTexture.Color1 = color;
                        }
                        else
                        {
                            topTexture.Color0 = color;
                            topTexture.Symbol1 = SymbolID.Floor;
                            topTexture.Color1 = color;
                        }
                        //floorTile.BgColor = GetTerrainBackgroundColor(matInfoDown);
                    }
                    else
                    {
                        topTexture = baseTexture;
                    }
                    return;

                case TileID.Stairs:
                    baseTexture.Symbol1 = SymbolID.StairsDown;
                    baseTexture.Color1 = GameColor.Red;
                    topTexture = baseTexture;
                    return;

                default:
                    throw new Exception();
            }
        }
コード例 #5
0
ファイル: Chunk.cs プロジェクト: tomba/dwarrowdelf
        public void UpdateVoxel(IntVector3 mp)
        {
            if (this.IsAllEmpty || this.IsAllUndefined)
            {
                // presume the chunk is no longer empty or undefined
                this.IsAllEmpty = this.IsAllUndefined = false;
                return;
            }

            if (m_voxelMap == null)
                return;

            var td = m_map.GetTileData(mp);

            Voxel v = new Voxel();

            // we don't use VisibleFaces for Empty, and Undefined is always hidden
            if (!td.IsEmptyNoWater && !td.IsUndefined)
                v.VisibleFaces = GetVisibleFaces(mp);

            m_voxelMap.SetVoxel(mp - this.ChunkOffset, v);
        }