コード例 #1
0
        public override int GetHashCode()
        {
            int hash = 13;

            hash = (hash + 7) * PolSeq.GetHashCode();
            hash = (hash + 7) * ScenSeq.GetHashCode();
            hash = (hash + 7) * Mth.GetHashCode();
            return(hash);
        }
コード例 #2
0
ファイル: FSvc.asmx.cs プロジェクト: samuelchl/FiboSvc
        public string FibonacciJSON(int n)
        {
            log.Info(string.Format("Appel FibonacciJSON - param n = {0}", n));

            try
            {
                var res = JsonConvert.SerializeObject(Mth.CalculateFibonacci(n));

                log.Info(string.Format("Retour FibonacciJSON - resultat = {0}", res));

                return(res);
            }
            catch (Exception e)
            {
                log.Error(string.Format(e.Message));
                return("-1");
            }
        }
コード例 #3
0
ファイル: FSvc.asmx.cs プロジェクト: samuelchl/FiboSvc
        public int Fibonacci(int n)
        {
            log.Info(string.Format("Appel Fibonnacci - param n = {0}", n));

            try
            {
                var res = Mth.CalculateFibonacci(n);

                log.Info(string.Format("Retour Fibonnacci - resultat = {0}", res));

                return(res);
            }
            catch (Exception e)
            {
                log.Error(e.Message);
                return(-1);
            }
        }
コード例 #4
0
    // called only once all neighbors are generated
    public static void BuildStructures(Vector3i chunkBlockPos, int seed, ref NativeArray3x3 <Block> blocks)
    {
        // not sure here lol
        Random urand = new Random((uint)(chunkBlockPos.GetHashCode() + seed));

        for (int y = 0; y < Chunk.SIZE; ++y)
        {
            for (int z = 0; z < Chunk.SIZE; ++z)
            {
                for (int x = 0; x < Chunk.SIZE; ++x)
                {
                    //if (blocks.Get(x, y, z) == Blocks.AIR && blocks.Get(x, y - 1, z) == Blocks.STONE) {
                    //    blocks.Set(x, y, z, Blocks.GRASS);
                    //    blocks.Set(x, y - 1, z, Blocks.GRASS);
                    //}

                    // random chance to try to spawn tree
                    if (urand.NextFloat() < 0.01f)
                    {
                        TrySpawnGoodTree(ref blocks, urand, x, y, z);
                    }

                    // try to spawn gems
                    if (blocks.Get(x, y, z) == Blocks.AIR)
                    {
                        float gemChance = Mth.Blend(0.02f, 0.0f, y + chunkBlockPos.y, -400, -100);

                        if (urand.NextFloat() < gemChance)
                        {
                            TrySpawnGemstone(ref blocks, urand, x, y, z);
                        }
                    }
                }
            }
        }
    }
コード例 #5
0
 public int Fibonacci(int n)
 {
     return(Mth.CalculateFibonacci(n));
 }
コード例 #6
0
    // this is a pine tree routine
    static void TrySpawnGoodTree(ref NativeArray3x3 <Block> blocks, Random urand, int x, int y, int z)
    {
        float width = urand.NextFloat(0.5f, 2f);

        int height = 0;

        height = (int)(28 * width / 2.0f) + urand.NextInt(-3, 3);
        math.clamp(height, 5, 29);

        // make sure space is kinda clear for tree height at least
        int wi = (int)width + 1;

        for (int u = -wi; u <= wi; ++u)
        {
            for (int v = -wi; v <= wi; ++v)
            {
                if (math.lengthsq(new float2(u, v)) < wi * wi)
                {
                    if (blocks.Get(x + u, y, z + v) != Blocks.GRASS)
                    {
                        return;
                    }
                }
            }
        }
        for (int i = 1; i <= height; ++i)
        {
            if (blocks.Get(x, y + i, z) != Blocks.AIR)
            {
                return;
            }
        }

        int nextLeafLevel = urand.NextInt(3, 5);

        for (int i = 1; i <= height; ++i)
        {
            float hp       = (float)i / height;
            float curWidth = math.lerp(width, width / 2.0f, hp);
            float leafEdge = 0.0f;

            //bool leafLayer = (i >= 3 && i % 2 == 0) || i >= height;
            bool leafLayer = i == nextLeafLevel || i == height;
            if (leafLayer)
            {
                leafEdge = math.lerp(width * 4.0f, 1.5f, Mth.QuadraticEaseOut(hp));
                float r = urand.NextFloat();
                if (r < 0.1f)
                {
                    nextLeafLevel += 1;
                }
                else if (r < 0.75f || height < 20)
                {
                    nextLeafLevel += 2;
                }
                else     // taller trees have small chance of large gaps in leaves
                {
                    nextLeafLevel += 3;
                }
                if (i == height)
                {
                    leafEdge = 1.0f;
                }
                else if (urand.NextFloat() < .2f)
                {
                    leafEdge++;
                }
            }
            int cwi = (int)(curWidth + leafEdge) + 1;

            for (int u = -cwi; u <= cwi; ++u)
            {
                for (int v = -cwi; v <= cwi; ++v)
                {
                    float len = math.lengthsq(new float2(u, v));
                    if (len < curWidth * curWidth)
                    {
                        blocks.Set(x + u, y + i, z + v, Blocks.PINE);
                    }
                    else if (leafLayer && len < (curWidth + leafEdge) * (curWidth + leafEdge))
                    {
                        if (blocks.Get(x + u, y + i, z + v) == Blocks.AIR)
                        {
                            blocks.Set(x + u, y + i, z + v, Blocks.PINELEAF);
                        }
                    }
                }
            }
        }

        // add leaves to the top
        int topper = height > 20 ? 2 : 1;

        for (int i = height + 1; i < height + 1 + topper; ++i)
        {
            if (blocks.Get(x, y + i, z) == Blocks.AIR)
            {
                blocks.Set(x, y + i, z, Blocks.PINELEAF);
            }
        }
    }
コード例 #7
0
 // returns lookup byte position to sector table
 public static int GetTablePos(Vector3i cp)
 {
     return(4 * (Mth.Mod16(cp.x) + Mth.Mod16(cp.z) * 16 + Mth.Mod16(cp.y) * 256));
 }
コード例 #8
0
    void Update()
    {
        // scroll to select blocks (create mesh as you switch)
        float scroll  = Input.GetAxis("Mouse ScrollWheel");
        bool  changed = true;

        if (scroll > 0.0f)
        {
            blockIndex--;
        }
        else if (scroll < 0.0f)     // scroll down will progress list forward
        {
            blockIndex++;
        }
        else
        {
            changed = false;
        }
        blockIndex = Mth.Mod(blockIndex, blocks.Length);
        if (changed)
        {
            MeshBuilder.GetBlockMesh(blocks[blockIndex], blockMeshFilter);
        }

        // show square around block aiming at
        // todo: have option to show 2x2 for hammering!
        //bool mainRaycast = Physics.Raycast(transform.position, transform.forward, out hit, 1000);
        drawer.Clear();

        RaycastVoxelHit vhit;
        bool            success = BlonkPhysics.RaycastVoxel(world, transform.position, transform.forward, out vhit);

        if (success)
        {
            // move cube towards camera direction a little so it looks better when intersecting with other blocks
            Vector3 center = (vhit.bpos.ToVector3() + Vector3.one * placementSize * 0.5f) / Chunk.BPU;
            drawer.AddBounds(new Bounds(center - transform.forward * 0.01f, Vector3.one * placementSize / Chunk.BPU), Color.white);
        }

        // left click delete
        if (Input.GetMouseButtonDown(0) && success)
        {
            lastPos = transform.position;
            lastHit = vhit;

            //todo: add some better directional intuitions on where to place edit shape
            for (int y = 0; y < placementSize; ++y)
            {
                for (int z = 0; z < placementSize; ++z)
                {
                    for (int x = 0; x < placementSize; ++x)
                    {
                        world.SetBlock(vhit.bpos + new Vector3i(x, y, z), Blocks.AIR);
                    }
                }
            }
        }

        // right click place
        if (Input.GetMouseButtonDown(1) && success)
        {
            lastPos = transform.position;
            lastHit = vhit;

            for (int y = 0; y < placementSize; ++y)
            {
                for (int z = 0; z < placementSize; ++z)
                {
                    for (int x = 0; x < placementSize; ++x)
                    {
                        world.SetBlock(vhit.bpos + Dirs.GetNormal(vhit.dir) + new Vector3i(x, y, z), blocks[blockIndex]);
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            placementSize++;
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            placementSize--;
        }
        if (placementSize < 1)
        {
            placementSize = 1;
        }

        if (Input.GetKeyDown(KeyCode.F1))
        {
            flyCam.ToggleFlyMode();
        }
        if (Input.GetKeyDown(KeyCode.F2))
        {
            drawChunkBorders = !drawChunkBorders;
        }
        if (Input.GetKeyDown(KeyCode.F3))
        {
            ToggleDebugDay();
        }
        if (Input.GetKeyDown(KeyCode.F4))
        {
            LoadChunks.drawDebug = !LoadChunks.drawDebug;
        }
        if (Input.GetKeyDown(KeyCode.F5))
        {
            LoadChunks.updateChunks = !LoadChunks.updateChunks;
        }
        if (drawChunkBorders)
        {
            DrawChunkBorders();
        }
    }
コード例 #9
0
ファイル: Tests.cs プロジェクト: buckslice/shardcraft
    public static void Run()
    {
        passes   = 0;
        failures = 0;

        {
            TestEqual(Dirs.Opp(Dir.west), Dir.east, "DirTest1");
            TestEqual(Dirs.Opp(Dir.down), Dir.up, "DirTest2");
            TestEqual(Dirs.Opp(Dir.south), Dir.north, "DirTest3");
            TestEqual(Dirs.Opp(Dir.east), Dir.west, "DirTest4");
            TestEqual(Dirs.Opp(Dir.up), Dir.down, "DirTest5");
            TestEqual(Dirs.Opp(Dir.north), Dir.south, "DirTest6");
        }

        {
            TestEqual(WorldUtils.GetRegionCoord(new Vector3i(0, 0, 0)), new Vector3i(0, 0, 0), "RegionCoordTest1");
            TestEqual(WorldUtils.GetRegionCoord(new Vector3i(1, 0, 0)), new Vector3i(0, 0, 0), "RegionCoordTest2");
            TestEqual(WorldUtils.GetRegionCoord(new Vector3i(5, 5, 5)), new Vector3i(0, 0, 0), "RegionCoordTest3");
            TestEqual(WorldUtils.GetRegionCoord(new Vector3i(15, 15, 15)), new Vector3i(0, 0, 0), "RegionCoordTest4");
            TestEqual(WorldUtils.GetRegionCoord(new Vector3i(16, 16, 16)), new Vector3i(1, 1, 1), "RegionCoordTest5");
            TestEqual(WorldUtils.GetRegionCoord(new Vector3i(18, 5, 5)), new Vector3i(1, 0, 0), "RegionCoordTest6");
            TestEqual(WorldUtils.GetRegionCoord(new Vector3i(-1, 0, 0)), new Vector3i(-1, 0, 0), "RegionCoordTest7");
            TestEqual(WorldUtils.GetRegionCoord(new Vector3i(0, -1, 0)), new Vector3i(0, -1, 0), "RegionCoordTest8");
            TestEqual(WorldUtils.GetRegionCoord(new Vector3i(0, 0, -1)), new Vector3i(0, 0, -1), "RegionCoordTest9");
            TestEqual(WorldUtils.GetRegionCoord(new Vector3i(0, 0, -1)), new Vector3i(0, 0, -1), "RegionCoordTest10");
            TestEqual(WorldUtils.GetRegionCoord(new Vector3i(14, 15, 15)), new Vector3i(0, 0, 0), "RegionCoordTest11");
            TestEqual(WorldUtils.GetRegionCoord(new Vector3i(17, 15, 15)), new Vector3i(1, 0, 0), "RegionCoordTest12");
        }

        {   // written assuming 2 blocks per unit
            TestEqual(WorldUtils.GetChunkPosFromWorldPos(new Vector3(0, 0, 0)), new Vector3i(0, 0, 0), "ChunkPos1");
            TestEqual(WorldUtils.GetChunkPosFromWorldPos(new Vector3(-1.0f, 0, 0)), new Vector3i(-1, 0, 0), "ChunkPos2");
            TestEqual(WorldUtils.GetChunkPosFromWorldPos(new Vector3(-16.01f, 0, 0)), new Vector3i(-2, 0, 0), "ChunkPos3");
            TestEqual(WorldUtils.GetChunkPosFromWorldPos(new Vector3(25, 35, -5)), new Vector3i(1, 2, -1), "ChunkPos4");
        }

        {
            TestEqual(WorldUtils.GetChunkPosFromBlockPos(0, 13, 0), new Vector3i(0, 0, 0), "GCPFBP1");
            TestEqual(WorldUtils.GetChunkPosFromBlockPos(32, 34, 0), new Vector3i(1, 1, 0), "GCPFBP2");
            TestEqual(WorldUtils.GetChunkPosFromBlockPos(0, -1, 0), new Vector3i(0, -1, 0), "GCPFBP3");
            TestEqual(WorldUtils.GetChunkPosFromBlockPos(-15, 0, 0), new Vector3i(-1, 0, 0), "GCPFBP4");
            TestEqual(WorldUtils.GetChunkPosFromBlockPos(-16, 0, 0), new Vector3i(-1, 0, 0), "GCPFBP5");
            TestEqual(WorldUtils.GetChunkPosFromBlockPos(-31, 0, 0), new Vector3i(-1, 0, 0), "GCPFBP6");
            TestEqual(WorldUtils.GetChunkPosFromBlockPos(-32, 0, 0), new Vector3i(-1, 0, 0), "GCPFBP7");
            TestEqual(WorldUtils.GetChunkPosFromBlockPos(-33, 0, 0), new Vector3i(-2, 0, 0), "GCPFBP8");
            TestEqual(WorldUtils.GetChunkPosFromBlockPos(-33, 0, 40), new Vector3i(-2, 0, 1), "GCPFBP9");
        }

        {
            TestEqual(Serialization.GetTablePos(new Vector3i(0, 0, 0)), 0, "LookUpPos1");
            TestEqual(Serialization.GetTablePos(new Vector3i(1, 0, 0)), 4, "LookUpPos2");
            TestEqual(Serialization.GetTablePos(new Vector3i(0, 1, 0)), 1024, "LookUpPos3");
            TestEqual(Serialization.GetTablePos(new Vector3i(-1, 0, 0)), 60, "LookUpPos4");
        }
        {
            TestEqual(Mth.Mod16(0), 0, "Mod16_1");
            TestEqual(Mth.Mod16(15), 15, "Mod16_2");
            TestEqual(Mth.Mod16(16), 0, "Mod16_3");
            TestEqual(Mth.Mod16(35), 3, "Mod16_4");
            TestEqual(Mth.Mod16(-1), 15, "Mod16_5");
            TestEqual(Mth.Mod16(-16), 0, "Mod16_6");
            TestEqual(Mth.Mod16(-5), 11, "Mod16_7");
        }

        {
            int b = 0;

            b |= 0x1;

            TestEqual(b & 0x1, 1, "bit1");

            TestEqual(0x1, 1, "hex0");
            TestEqual(0x2, 2, "hex1");
            TestEqual(0x4, 4, "hex2");
            TestEqual(0x8, 8, "hex3");
            TestEqual(0x10, 16, "hex4");
            TestEqual(0x20, 32, "hex5");
            TestEqual(0x40, 64, "hex6");
            TestEqual(0x80, 128, "hex7");
            TestEqual(0x100, 256, "hex8");
            TestEqual(0x200, 512, "hex9");
            TestEqual(0x400, 1024, "hex10");
            TestEqual(0x800, 2048, "hex11");
            TestEqual(0x1000, 4096, "hex12");
        }

        {
            // U RRRRR GGGGG BBBBB
            ushort torch = 0b0_00010_00110_10011;
            TestEqual(LightCalculator.GetRed(torch), 2, "torch1");
            TestEqual(LightCalculator.GetGreen(torch), 6, "torch2");
            TestEqual(LightCalculator.GetBlue(torch), 19, "torch3");

            TestEqual(LightCalculator.GetIsLight(torch), false, "torchb1");

            torch = 0b0_11111_00000_11111;

            TestEqual(LightCalculator.GetRed(torch), 31, "torch4");
            TestEqual(LightCalculator.GetGreen(torch), 0, "torch5");
            TestEqual(LightCalculator.GetBlue(torch), 31, "torch6");

            torch = LightCalculator.SetIsLight(torch, true);
            TestEqual(LightCalculator.GetIsLight(torch), true, "torchb1");

            torch = 0b0_10000_00100_01010;

            TestEqual(LightCalculator.GetRed(torch), 16, "torch7");
            TestEqual(LightCalculator.GetGreen(torch), 4, "torch8");
            TestEqual(LightCalculator.GetBlue(torch), 10, "torch9");

            torch = LightCalculator.SetRed(torch, 8);
            TestEqual(torch, (ushort)0b0_01000_00100_01010, "torch10");
            torch = LightCalculator.SetBlue(torch, 23);
            TestEqual(torch, (ushort)0b0_01000_00100_10111, "torch11");
            torch = LightCalculator.SetGreen(torch, 0);
            TestEqual(torch, (ushort)0b0_01000_00000_10111, "torch12");

            torch = LightCalculator.SetIsLight(torch, true);
            TestEqual(LightCalculator.GetIsLight(torch), true, "torchb1");
            torch = LightCalculator.SetIsLight(torch, false);
            TestEqual(LightCalculator.GetIsLight(torch), false, "torchb1");

            int c = LightCalculator.GetColor(31, 31, 31);
            TestEqual(LightCalculator.GetRed(c), 31, "torch13");
            TestEqual(LightCalculator.GetGreen(c), 31, "torch14");
            TestEqual(LightCalculator.GetBlue(c), 31, "torch15");

            c = LightCalculator.GetColor(1, 7, 30);
            TestEqual(LightCalculator.GetRed(c), 1, "torch16");
            TestEqual(LightCalculator.GetGreen(c), 7, "torch17");
            TestEqual(LightCalculator.GetBlue(c), 30, "torch18");

            c = LightCalculator.GetColor(0, 0, 0);
            TestEqual(LightCalculator.GetRed(c), 0, "torch19");
            TestEqual(LightCalculator.GetGreen(c), 0, "torch20");
            TestEqual(LightCalculator.GetBlue(c), 0, "torch21");


            torch = 0b0_00010_00110_10011;
            TestEqual(LightCalculator.GetChannel(torch, 2), 2, "torch1");
            TestEqual(LightCalculator.GetChannel(torch, 1), 6, "torch2");
            TestEqual(LightCalculator.GetChannel(torch, 0), 19, "torch3");

            TestEqual(LightCalculator.GetIsLight(torch), false, "torchb1");

            torch = 0b1_11111_00000_11111;

            TestEqual(LightCalculator.GetIsLight(torch), true, "torchb1");

            TestEqual(LightCalculator.GetChannel(torch, 2), 31, "torch4");
            TestEqual(LightCalculator.GetChannel(torch, 1), 0, "torch5");
            TestEqual(LightCalculator.GetChannel(torch, 0), 31, "torch6");

            TestEqual(LightCalculator.GetIsLight(torch), true, "torchb1");

            torch = 0b1_10000_00100_01010;

            TestEqual(LightCalculator.GetChannel(torch, 2), 16, "torch7");
            TestEqual(LightCalculator.GetChannel(torch, 1), 4, "torch8");
            TestEqual(LightCalculator.GetChannel(torch, 0), 10, "torch9");

            torch = LightCalculator.SetChannel(torch, 2, 8);
            TestEqual(torch, (ushort)0b1_01000_00100_01010, "torch10");
            torch = LightCalculator.SetChannel(torch, 0, 23);
            TestEqual(torch, (ushort)0b1_01000_00100_10111, "torch11");
            torch = LightCalculator.SetChannel(torch, 1, 0);
            TestEqual(torch, (ushort)0b1_01000_00000_10111, "torch12");

            TestEqual(LightCalculator.GetIsLight(torch), true, "torchb1");

            c = LightCalculator.GetColor(31, 31, 31);
            TestEqual(LightCalculator.GetChannel(c, 2), 31, "torch13");
            TestEqual(LightCalculator.GetChannel(c, 1), 31, "torch14");
            TestEqual(LightCalculator.GetChannel(c, 0), 31, "torch15");

            c = LightCalculator.GetColor(1, 7, 30);
            TestEqual(LightCalculator.GetChannel(c, 2), 1, "torch16");
            TestEqual(LightCalculator.GetChannel(c, 1), 7, "torch17");
            TestEqual(LightCalculator.GetChannel(c, 0), 30, "torch18");

            c = LightCalculator.GetColor(0, 0, 0);
            TestEqual(LightCalculator.GetChannel(c, 2), 0, "torch19");
            TestEqual(LightCalculator.GetChannel(c, 1), 0, "torch20");
            TestEqual(LightCalculator.GetChannel(c, 0), 0, "torch21");

            TestEqual(LightCalculator.GetIsLight(torch), true, "torchb1");
        }

        {
            BlockData test = new BlockData(0)
            {
                colliderSolid = 0,
            };
            TestEqual(test.texture, 0, "bd1");
            TestEqual(test.light, (ushort)0, "bd2");
            TestEqual(test.renderType, (byte)1, "bd3");
            TestEqual(test.colliderSolid, (byte)0, "bd4");
            TestEqual(test.renderSolid, (byte)1, "bd5");
        }

        {
            TestStruct t;
            t.member = 0;
            TestEqual(t.member, 0, "struct1");
            t.IncMember();
            TestEqual(t.member, 1, "struct2");
        }


        string msg = string.Format("{0}/{1} tests passed", passes, passes + failures);

        if (failures == 0)
        {
            Debug.Log(string.Format("<color=#00FF00><b>{0}</b></color>", msg));
        }
        else
        {
            Debug.Log(msg);
        }
    }
コード例 #10
0
ファイル: VoteMembers.cs プロジェクト: HeleusCore/Heleus.Node
 public bool IsVotingValid(int count)
 {
     return(Mth.Percentage(count, _voteKeys.Count) > 50f);
 }
コード例 #11
0
    public static void Generate(Vector3 chunkWorldPos, NativeArray <Block> blocks, NativeArray <Light> lights)
    {
        // make this single loop instead and calculate x,y,z from index i
        for (int y = 0; y < Chunk.SIZE; ++y)
        {
            for (int z = 0; z < Chunk.SIZE; ++z)
            {
                for (int x = 0; x < Chunk.SIZE; ++x)
                {
                    Vector3 wp = new Vector3(x, y, z) / Chunk.BPU + chunkWorldPos + new Vector3(55.0f, 12.4f, 87.5f);
                    float   n  = 0.0f;

                    // experiment with catlike coding noise some more
                    //NoiseSample samp = Noise.Sum(Noise.Simplex3D, wp, 0.015f, 5, 2.0f, 0.5f);
                    //float n = samp.value * 3.0f;

                    // TODO: convert shapes.cginc into c# equiv, and or get gen going on multiple thread (try job system!!!)
                    // this is adding a flat ground plane density at low strength, so as you go lower will slowly become solid
                    n -= Vector3.Dot(wp, Vector3.up) * 0.03f;

                    //n += Fractal(wp, 5, 0.01f);
                    float4 ng = Mth.FractalGrad(wp, 5, 0.01f);
                    n += ng.x;

                    Block b = Blocks.AIR;

                    if (n > 0.25f)
                    {
                        b = Blocks.STONE;
                    }
                    else if (n > 0.15f)
                    {
                        b = Blocks.STONE;

                        // todo switch to using math.dot
                        if (Vector3.Dot(Vector3.up, new Vector3(ng.y, ng.z, ng.w).normalized) < .7f)
                        {
                            b = Blocks.GRASS;
                        }

                        // trying to make grass not spawn on cliff edge...
                        //if (Mathf.Abs(samp.derivative.normalized.y) < 0.4f) {
                        //    chunk.SetBlock(x, y, z, new BlockGrass());
                        //} else {
                        //    chunk.SetBlock(x, y, z, new Block());
                        //}
                    }

                    if (b == Blocks.STONE)
                    {
                        float coal = Mth.Billow(wp + new Vector3(1000, 722, 255), 2, 0.04f, 1, 0.6f);

                        if (coal > 0.0f)
                        {
                            b = Blocks.COAL;
                        }
                    }

                    // add caves
                    if (b != Blocks.AIR)
                    {
                        // octaves of 5 and 0.015 was pretty good too
                        n = Mth.Ridged(wp + new Vector3(500, -5000, 1000), 4, 0.01f);
                        if (n > 0.75f - math.abs(wp.y) * 0.001f)   // as you go deeper caves open up is the idea here
                        {
                            b = Blocks.AIR;
                        }
                    }

                    // for testing singular blocks
                    //if (b != Blocks.COAL) {
                    //    b = Blocks.AIR;
                    //}

                    blocks[x + z * Chunk.SIZE + y * Chunk.SIZE * Chunk.SIZE] = b;
                }
            }
        }

        LightCalculator.InitializeLights(lights, chunkWorldPos);
    }
コード例 #12
0
ファイル: frmExecViewRep.cs プロジェクト: radtek/Tradelink
        private void crystalReportViewer1_Load(object sender, EventArgs e)
        {
            if (_RepNo == 1)
            {
                DataSet ds = new DataSet();
                DataSet1.DataTable1DataTable dataTable1 = new DataSet1.DataTable1DataTable();
                DataSet1.DataTable2DataTable dataTable2 = new DataSet1.DataTable2DataTable();

                ExecRepository      repo       = new ExecRepository();
                ExecQueryParameters QueryParms = new ExecQueryParameters();

                core = new Util();
                //================================================================
                System.Data.DataTable dt = new System.Data.DataTable();
                dt.Columns.Add("Description", typeof(string)); // 0
                //===============================================================================
                dt.Columns.Add("01", typeof(decimal));         // 1
                dt.Columns[1].DefaultValue = 0.0;
                dt.Columns.Add("02", typeof(decimal));         // 2
                dt.Columns[2].DefaultValue = 0.0;
                dt.Columns.Add("03", typeof(decimal));         // 3
                dt.Columns[3].DefaultValue = 0.0;
                dt.Columns.Add("04", typeof(decimal));         // 4
                dt.Columns[4].DefaultValue = 0.0;
                dt.Columns.Add("05", typeof(decimal));         // 5
                dt.Columns[5].DefaultValue = 0.0;
                dt.Columns.Add("06", typeof(decimal));         // 6
                dt.Columns[6].DefaultValue = 0.0;
                dt.Columns.Add("07", typeof(decimal));         // 7
                dt.Columns[7].DefaultValue = 0.0;
                dt.Columns.Add("08", typeof(decimal));         // 8
                dt.Columns[8].DefaultValue = 0.0;
                dt.Columns.Add("09", typeof(decimal));         // 9
                dt.Columns[9].DefaultValue = 0.0;
                dt.Columns.Add("10", typeof(decimal));         // 10
                dt.Columns[10].DefaultValue = 0.0;
                dt.Columns.Add("11", typeof(decimal));         // 11
                dt.Columns[11].DefaultValue = 0.0;
                dt.Columns.Add("12", typeof(decimal));         // 12
                dt.Columns[12].DefaultValue = 0.0;
                dt.Columns.Add("13", typeof(int));             // 13
                dt.Columns[13].DefaultValue = 0;

                using (var context = new TTI2Entities())
                {
                    QueryParms.ToDate   = DateTime.Now;
                    QueryParms.FromDate = QueryParms.ToDate.AddDays(-1 * QueryParms.ToDate.DayOfYear + 1);

                    var YarnProd = repo.ExecYarnProduction(QueryParms).GroupBy(x => x.YarnOP_DatePacked.Value.Month);
                    if (YarnProd.Count() != 0)
                    {
                        DataRow Row = dt.NewRow();
                        Row[0] = "Spinning - Yarn Production";

                        foreach (var Mth in YarnProd)
                        {
                            var MthKey   = Mth.FirstOrDefault().YarnOP_DatePacked.Value.Month.ToString().PadLeft(2, '0');
                            var ColIndex = dt.Columns.IndexOf(MthKey);
                            if (ColIndex != 0)
                            {
                                Row[ColIndex] = Row.Field <decimal>(ColIndex) + Mth.Sum(x => (decimal?)x.YarnOP_NettWeight) ?? 0.0M;
                            }
                        }
                        Row[13] = 1;
                        dt.Rows.Add(Row);
                    }

                    var GreigeProd = repo.ExecGreigeProduction(QueryParms).GroupBy(x => x.GreigeP_PDate.Value.Month);
                    if (GreigeProd.Count() != 0)
                    {
                        DataRow Row = dt.NewRow();
                        Row[0] = "Knitting - Greige Production";

                        foreach (var Mth in GreigeProd)
                        {
                            var MthKey   = Mth.FirstOrDefault().GreigeP_PDate.Value.Month.ToString().PadLeft(2, '0');
                            var ColIndex = dt.Columns.IndexOf(MthKey);
                            if (ColIndex != 0)
                            {
                                Row[ColIndex] = Row.Field <decimal>(ColIndex) + Mth.Sum(x => (decimal?)x.GreigeP_weight) ?? 0.0M;
                            }
                        }
                        Row[13] = 2;
                        dt.Rows.Add(Row);
                    }

                    var DyedNotComplete = repo.ExecDyeNotFinshed(QueryParms).GroupBy(x => x.TLDYET_Date.Month);
                    if (DyedNotComplete.Count() != 0)
                    {
                        DataRow Row = dt.NewRow();
                        Row[0] = "Dyeing - Fabric Dyed";

                        foreach (var Mth in DyedNotComplete)
                        {
                            var MthKey   = Mth.FirstOrDefault().TLDYET_Date.Month.ToString().PadLeft(2, '0');
                            var ColIndex = dt.Columns.IndexOf(MthKey);
                            if (ColIndex != 0)
                            {
                                Row[ColIndex] = Row.Field <decimal>(ColIndex) + Mth.Sum(x => (decimal?)x.TLDYET_BatchWeight) ?? 0.0M;
                            }
                        }
                        Row[13] = 3;
                        dt.Rows.Add(Row);
                    }

                    var DyedIntoQuarantine = repo.ExecDyeIntoQuarantine(QueryParms).GroupBy(x => x.DYEBO_ApprovalDate.Value.Month);
                    if (DyedIntoQuarantine.Count() != 0)
                    {
                        DataRow Row = dt.NewRow();
                        Row[0] = "Dyeing - Fabric Into Quarantine";

                        foreach (var Mth in DyedIntoQuarantine)
                        {
                            var MthKey   = Mth.FirstOrDefault().DYEBO_ApprovalDate.Value.Month.ToString().PadLeft(2, '0');
                            var ColIndex = dt.Columns.IndexOf(MthKey);
                            if (ColIndex != 0)
                            {
                                Row[ColIndex] = Row.Field <decimal>(ColIndex) + Mth.Sum(x => (decimal?)x.DYEBO_Nett) ?? 0.0M;
                            }
                        }
                        Row[13] = 4;
                        dt.Rows.Add(Row);
                    }
                    var CutProd = repo.ExecIntoPanelStore(QueryParms).GroupBy(x => x.TLCUTSHRD_PanelDate.Value.Month);
                    if (CutProd.Count() != 0)
                    {
                        DataRow Row = dt.NewRow();
                        Row[0] = "Cutting - Panels into Store";

                        foreach (var Mth in CutProd)
                        {
                            var MthKey   = Mth.FirstOrDefault().TLCUTSHRD_PanelDate.Value.Month.ToString().PadLeft(2, '0');
                            var ColIndex = dt.Columns.IndexOf(MthKey);
                            if (ColIndex != 0)
                            {
                                Row[ColIndex] = Row.Field <decimal>(ColIndex) + Mth.Sum(x => (decimal?)x.TLCUTSHRD_BoxUnits) ?? 0.0M;
                            }
                        }
                        Row[13] = 5;
                        dt.Rows.Add(Row);
                    }

                    var WorkComplete = repo.ExecWorkCompleted(QueryParms);
                    if (WorkComplete.Count() != 0)
                    {
                        DataRow Row = dt.NewRow();
                        Row[0] = "CMT - Work Completed";

                        var Records = (from LI in context.TLCMT_LineIssue
                                       join WC in context.TLCMT_CompletedWork on LI.TLCMTLI_Pk equals WC.TLCMTWC_LineIssue_FK
                                       where LI.TLCMTLI_WorkCompleted && LI.TLCMTLI_WorkCompletedDate >= QueryParms.FromDate && LI.TLCMTLI_WorkCompletedDate <= QueryParms.ToDate
                                       select new { LI.TLCMTLI_WorkCompletedDate, WC.TLCMTWC_Qty }).GroupBy(x => x.TLCMTLI_WorkCompletedDate.Value.Month);

                        foreach (var Group in Records)
                        {
                            var MthKey   = Group.FirstOrDefault().TLCMTLI_WorkCompletedDate.Value.Month.ToString().PadLeft(2, '0');
                            var ColIndex = dt.Columns.IndexOf(MthKey);
                            if (ColIndex != 0)
                            {
                                Row[ColIndex] = Row.Field <decimal>(ColIndex) + Group.Sum(x => (decimal?)x.TLCMTWC_Qty) ?? 0.0M;
                            }
                        }
                        Row[13] = 6;
                        dt.Rows.Add(Row);

                        foreach (DataRow DRow in dt.Rows)
                        {
                            DataSet1.DataTable1Row nr = dataTable1.NewDataTable1Row();
                            nr.Description = DRow.Field <String>(0);
                            nr.Jan         = DRow.Field <decimal>(1);
                            nr.Feb         = DRow.Field <decimal>(2);
                            nr.Mar         = DRow.Field <decimal>(3);
                            nr.Apr         = DRow.Field <decimal>(4);
                            nr.May         = DRow.Field <decimal>(5);
                            nr.Jun         = DRow.Field <decimal>(6);
                            nr.Jul         = DRow.Field <decimal>(7);
                            nr.Aug         = DRow.Field <decimal>(8);
                            nr.Sep         = DRow.Field <decimal>(9);
                            nr.Oct         = DRow.Field <decimal>(10);
                            nr.Nov         = DRow.Field <decimal>(11);
                            nr.Dec         = DRow.Field <decimal>(12);
                            nr.SortOrder   = DRow.Field <int>(13);
                            nr.Pk          = 1;
                            dataTable1.AddDataTable1Row(nr);
                        }
                        dt.Rows.Clear();
                    }
                }

                DataSet1.DataTable2Row hnr = dataTable2.NewDataTable2Row();
                hnr.Pk       = 1;
                hnr.FromDate = QueryParms.FromDate;
                hnr.ToDate   = QueryParms.ToDate;
                hnr.Title    = "Company Production By Department";
                dataTable2.AddDataTable2Row(hnr);

                if (dataTable1.Rows.Count == 0)
                {
                    DataSet1.DataTable1Row nr = dataTable1.NewDataTable1Row();
                    nr.ErrorLog = "No record found peratining to selection made";
                    dataTable1.AddDataTable1Row(nr);
                }

                ds.Tables.Add(dataTable1);
                ds.Tables.Add(dataTable2);

                Production Prod = new Production();
                Prod.SetDataSource(ds);
                crystalReportViewer1.ReportSource = Prod;
            }

            crystalReportViewer1.Refresh();
        }