Exemple #1
0
 internal void AddHash(int x)
 {
     numPaths++;
     rand = new JavaRandom(x);
     // XXX: fp.set(x % size); would work just as well but would encode a
     //      different bit
     fp.Set(rand.Next(fpsize), true);
 }
Exemple #2
0
        void PlantTrees(int chunkX, int chunkZ, OctaveNoise n1)
        {
            int numTrees = (int)Math.Round(n1.Compute(chunkX * 8, chunkZ * 8), MidpointRounding.AwayFromZero);

            for (int i = 0; i < numTrees; i++)
            {
                int patchX = (decX + 8), patchZ = (decZ + 8);

                //for (int j = 0; j < 20; j++) {
                int treeX = patchX, treeZ = patchZ;
                for (int k = 0; k < 20; k++)
                {
                    treeX += rnd2.Next(15);
                    treeZ += rnd2.Next(15);
                    if (treeX < patchX || treeZ < patchZ || treeX >= (patchX + 16) ||
                        treeZ >= (patchZ + 16) || rnd2.NextFloat() >= 0.25)
                    {
                        continue;
                    }

                    //int treeY = heightmap[treeZ * Width + treeX] + 1;
                    int treeY = GetMaxBlock(treeX, treeZ) + 1;
                    if (treeY >= Height)
                    {
                        continue;
                    }
                    int treeHeight = 5 + rnd.Next(3);

                    //int index = (treeY * Length + treeZ) * Width + treeX;
                    BlockRaw blockUnder = treeY > 0 ? ChunkHandler.GetBlockAdjSafe(treeX, treeY - 1, treeZ) : Block.Air;

                    if (blockUnder == Block.Grass && CanGrowTree(treeX, treeY, treeZ, treeHeight))
                    {
                        GrowTree(treeX, treeY, treeZ, treeHeight);
                    }
                }
                //}
            }
        }
Exemple #3
0
        protected virtual void DrawSprite(int count)
        {
            int   texId   = BlockInfo.textures[curBlock * Side.Sides + Side.Right];
            int   i       = texId / elementsPerAtlas1D;
            float vOrigin = (texId % elementsPerAtlas1D) * invVerElementSize;

            float       x1 = X + 2.50f / 16, y1 = Y, z1 = Z + 2.50f / 16;
            float       x2 = X + 13.5f / 16, y2 = Y + 1, z2 = Z + 13.5f / 16;
            const float u1 = 0, u2 = 15.99f / 16f;
            float       v1 = vOrigin, v2 = vOrigin + invVerElementSize * 15.99f / 16f;

            byte offsetType = BlockInfo.SpriteOffset[curBlock];

            if (offsetType >= 6 && offsetType <= 7)
            {
                spriteRng.SetSeed((X + 1217 * Z) & 0x7fffffff);
                float valX = spriteRng.Next(-3, 3 + 1) / 16.0f;
                float valY = spriteRng.Next(0, 3 + 1) / 16.0f;
                float valZ = spriteRng.Next(-3, 3 + 1) / 16.0f;

                const float stretch = 1.7f / 16.0f;
                x1 += valX - stretch; x2 += valX + stretch;
                z1 += valZ - stretch; z2 += valZ + stretch;
                if (offsetType == 7)
                {
                    y1 -= valY; y2 -= valY;
                }
            }

            DrawInfo part = normalParts[i];
            int      col  = fullBright ? FastColour.WhitePacked : light.LightCol_Sprite_Fast(X, Y, Z);

            if (tinted)
            {
                col = TintBlock(curBlock, col);
            }
            VertexP3fT2fC4b v; v.Colour = col;

            // Draw Z axis
            int index = part.sIndex;

            v.X = x1; v.Y = y1; v.Z = z1; v.U = u2; v.V = v2; part.vertices[index + 0] = v;
            v.Y = y2;                     v.V = v1; part.vertices[index + 1] = v;
            v.X = x2;           v.Z = z2; v.U = u1;           part.vertices[index + 2] = v;
            v.Y = y1;                     v.V = v2; part.vertices[index + 3] = v;

            // Draw Z axis mirrored
            index += part.sAdvance;
            v.X    = x2; v.Y = y1; v.Z = z2; v.U = u2;           part.vertices[index + 0] = v;
            v.Y    = y2;                     v.V = v1; part.vertices[index + 1] = v;
            v.X    = x1;           v.Z = z1; v.U = u1;           part.vertices[index + 2] = v;
            v.Y    = y1;                     v.V = v2; part.vertices[index + 3] = v;

            // Draw X axis
            index += part.sAdvance;
            v.X    = x1; v.Y = y1; v.Z = z2; v.U = u2;           part.vertices[index + 0] = v;
            v.Y    = y2;                     v.V = v1; part.vertices[index + 1] = v;
            v.X    = x2;           v.Z = z1; v.U = u1;           part.vertices[index + 2] = v;
            v.Y    = y1;                     v.V = v2; part.vertices[index + 3] = v;

            // Draw X axis mirrored
            index += part.sAdvance;
            v.X    = x2; v.Y = y1; v.Z = z1; v.U = u2;           part.vertices[index + 0] = v;
            v.Y    = y2;                     v.V = v1; part.vertices[index + 1] = v;
            v.X    = x1;           v.Z = z2; v.U = u1;           part.vertices[index + 2] = v;
            v.Y    = y1;                     v.V = v2; part.vertices[index + 3] = v;

            part.sIndex += 4;
        }
Exemple #4
0
        void DumpVertices()
        {
            w.WriteLine("#vertices");
            int     i = -1, mask = BlockInfo.IDMask;
            Vector3 min, max;

            for (int y = 0; y < map.Height; y++)
            {
                for (int z = 0; z < map.Length; z++)
                {
                    for (int x = 0; x < map.Width; x++)
                    {
                        ++i; int b = (blocks[i] | (blocks2[i] << 8)) & mask;
                        if (!include[b])
                        {
                            continue;
                        }
                        min.X = x; min.Y = y; min.Z = z;
                        max.X = x; max.Y = y; max.Z = z;

                        if (BlockInfo.Draw[b] == DrawType.Sprite)
                        {
                            min.X += 2.50f / 16f; min.Z += 2.50f / 16f;
                            max.X += 13.5f / 16f; max.Z += 13.5f / 16f; max.Y += 1.0f;

                            byte offsetType = BlockInfo.SpriteOffset[b];
                            if (offsetType >= 6 && offsetType <= 7)
                            {
                                spriteRng.SetSeed((x + 1217 * z) & 0x7fffffff);
                                float valX = spriteRng.Next(-3, 3 + 1) / 16.0f;
                                float valY = spriteRng.Next(0, 3 + 1) / 16.0f;
                                float valZ = spriteRng.Next(-3, 3 + 1) / 16.0f;

                                const float stretch = 1.7f / 16.0f;
                                min.X += valX - stretch; max.X += valX + stretch;
                                min.Z += valZ - stretch; max.Z += valZ + stretch;
                                if (offsetType == 7)
                                {
                                    min.Y -= valY; max.Y -= valY;
                                }
                            }

                            // Draw Z axis
                            w.WriteLine("v " + min.X + " " + min.Y + " " + min.Z);
                            w.WriteLine("v " + min.X + " " + max.Y + " " + min.Z);
                            w.WriteLine("v " + max.X + " " + max.Y + " " + max.Z);
                            w.WriteLine("v " + max.X + " " + min.Y + " " + max.Z);

                            // Draw Z axis mirrored
                            if (mirror)
                            {
                                w.WriteLine("v " + max.X + " " + min.Y + " " + max.Z);
                                w.WriteLine("v " + max.X + " " + max.Y + " " + max.Z);
                                w.WriteLine("v " + min.X + " " + max.Y + " " + min.Z);
                                w.WriteLine("v " + min.X + " " + min.Y + " " + min.Z);
                            }

                            // Draw X axis
                            w.WriteLine("v " + min.X + " " + min.Y + " " + max.Z);
                            w.WriteLine("v " + min.X + " " + max.Y + " " + max.Z);
                            w.WriteLine("v " + max.X + " " + max.Y + " " + min.Z);
                            w.WriteLine("v " + max.X + " " + min.Y + " " + min.Z);

                            // Draw X axis mirrored
                            if (mirror)
                            {
                                w.WriteLine("v " + max.X + " " + min.Y + " " + min.Z);
                                w.WriteLine("v " + max.X + " " + max.Y + " " + min.Z);
                                w.WriteLine("v " + min.X + " " + max.Y + " " + max.Z);
                                w.WriteLine("v " + min.X + " " + min.Y + " " + max.Z);
                            }
                            continue;
                        }

                        min += BlockInfo.RenderMinBB[b];
                        max += BlockInfo.RenderMaxBB[b];

                        // minx
                        if (x == 0 || all || !IsFaceHidden(b, (blocks[i - oneX] | (blocks2[i - oneX] << 8)) & mask, Side.Left))
                        {
                            w.WriteLine("v " + min.X + " " + min.Y + " " + min.Z);
                            w.WriteLine("v " + min.X + " " + max.Y + " " + min.Z);
                            w.WriteLine("v " + min.X + " " + max.Y + " " + max.Z);
                            w.WriteLine("v " + min.X + " " + min.Y + " " + max.Z);
                        }

                        // maxx
                        if (x == maxX || all || !IsFaceHidden(b, (blocks[i + oneX] | (blocks2[i + oneX] << 8)) & mask, Side.Right))
                        {
                            w.WriteLine("v " + max.X + " " + min.Y + " " + min.Z);
                            w.WriteLine("v " + max.X + " " + max.Y + " " + min.Z);
                            w.WriteLine("v " + max.X + " " + max.Y + " " + max.Z);
                            w.WriteLine("v " + max.X + " " + min.Y + " " + max.Z);
                        }

                        // minz
                        if (z == 0 || all || !IsFaceHidden(b, (blocks[i - oneZ] | (blocks2[i - oneZ] << 8)) & mask, Side.Front))
                        {
                            w.WriteLine("v " + min.X + " " + min.Y + " " + min.Z);
                            w.WriteLine("v " + min.X + " " + max.Y + " " + min.Z);
                            w.WriteLine("v " + max.X + " " + max.Y + " " + min.Z);
                            w.WriteLine("v " + max.X + " " + min.Y + " " + min.Z);
                        }

                        // maxz
                        if (z == maxZ || all || !IsFaceHidden(b, (blocks[i + oneZ] | (blocks2[i + oneZ] << 8)) & mask, Side.Back))
                        {
                            w.WriteLine("v " + min.X + " " + min.Y + " " + max.Z);
                            w.WriteLine("v " + min.X + " " + max.Y + " " + max.Z);
                            w.WriteLine("v " + max.X + " " + max.Y + " " + max.Z);
                            w.WriteLine("v " + max.X + " " + min.Y + " " + max.Z);
                        }

                        // miny
                        if (y == 0 || all || !IsFaceHidden(b, (blocks[i - oneY] | (blocks2[i - oneY] << 8)) & mask, Side.Bottom))
                        {
                            w.WriteLine("v " + min.X + " " + min.Y + " " + min.Z);
                            w.WriteLine("v " + min.X + " " + min.Y + " " + max.Z);
                            w.WriteLine("v " + max.X + " " + min.Y + " " + max.Z);
                            w.WriteLine("v " + max.X + " " + min.Y + " " + min.Z);
                        }

                        // maxy
                        if (y == maxY || all || !IsFaceHidden(b, (blocks[i + oneY] | (blocks2[i + oneY] << 8)) & mask, Side.Top))
                        {
                            w.WriteLine("v " + min.X + " " + max.Y + " " + min.Z);
                            w.WriteLine("v " + min.X + " " + max.Y + " " + max.Z);
                            w.WriteLine("v " + max.X + " " + max.Y + " " + max.Z);
                            w.WriteLine("v " + max.X + " " + max.Y + " " + min.Z);
                        }
                    }
                }
            }
        }