Пример #1
0
        public WorkManager(int bwidth, int bheight, int bdepth, int offsetX, int offsetY, int offsetZ, GLManager glmanager)
        {
            _glmanager  = glmanager;
            blockOffset = new Tuple <int, int, int>(offsetX, offsetY, offsetZ);
            blockWidth  = bwidth;
            blockHeight = bheight;
            blockDepth  = bdepth;
            blockw      = 1 / (float)blockWidth;
            blockh      = 1 / (float)blockHeight;
            blockd      = 1 / (float)blockDepth;
            nodeCube    = new Node[blockWidth * blockHeight * blockDepth];

            //populate the cube with nodes
            for (int d = 0; d < blockDepth; d++)
            {
                for (int w = 0; w < blockWidth; w++)
                {
                    for (int h = 0; h < blockHeight; h++)
                    {
                        nodeCube[w + blockWidth * (h + blockHeight * d)] = new NormalNode(w, h, d, (w + blockWidth * (h + blockHeight * d)));
                    }
                }
            }

            List <jsonConnection> jsonConnections;
            var serializer = new JsonSerializer();

            using (var re = File.OpenText("nodes.json"))
                using (var reader = new JsonTextReader(re))
                {
                    jsonConnections = serializer.Deserialize <List <jsonConnection> >(reader);
                }

            //cycle through every node in the cube, creating all connections from json for each of them
            for (byte d = 0; d < blockDepth - 1; d++)
            {
                for (byte w = 0; w < blockWidth; w++)
                {
                    for (byte h = 0; h < blockHeight; h++)
                    {
                        Node p = nodeCube[(w) + blockWidth * ((h) + blockHeight * (d))];
                        foreach (jsonConnection conn in jsonConnections)
                        {
                            //check that the child of the connection is inside the cube
                            if (d + conn.z >= 0 && d + conn.z < blockDepth)
                            {
                                if (w + conn.x >= 0 && w + conn.x < blockWidth)
                                {
                                    if (h + conn.y >= 0 && h + conn.y < blockHeight)
                                    {
                                        Connect(p, nodeCube[(w + conn.x) + blockWidth * ((h + conn.y) + blockHeight * (d + conn.z))], conn.weight);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            _workGenerator = new FiringWorkGenerator(ref _fireQueue, ref _renderQueue, blockOffset, nodeCube);
        }
Пример #2
0
        public WorkManager(int bwidth, int bheight, int bdepth, int offsetX, int offsetY, int offsetZ, GLManager glmanager)
        {
            _glmanager = glmanager;
            blockOffset = new Tuple<int, int, int>(offsetX, offsetY, offsetZ);
            blockWidth = bwidth;
            blockHeight = bheight;
            blockDepth = bdepth;
            blockw = 1 / (float)blockWidth;
            blockh = 1 / (float)blockHeight;
            blockd = 1 / (float)blockDepth;
            nodeCube = new Node[blockWidth * blockHeight * blockDepth];

            //populate the cube with nodes
            for (int d = 0; d < blockDepth; d++)
            {
                for (int w = 0; w < blockWidth; w++)
                {
                    for (int h = 0; h < blockHeight; h++)
                    {
                        nodeCube[w + blockWidth * (h + blockHeight * d)] = new NormalNode(w, h, d, (w + blockWidth * (h + blockHeight * d)));
                    }
                }
            }

            List<jsonConnection> jsonConnections;
            var serializer = new JsonSerializer();
            using (var re = File.OpenText("nodes.json"))
            using (var reader = new JsonTextReader(re))
            {
                jsonConnections = serializer.Deserialize<List<jsonConnection>>(reader);
            }

            //cycle through every node in the cube, creating all connections from json for each of them
            for (byte d = 0; d < blockDepth - 1; d++)
            {
                for (byte w = 0; w < blockWidth; w++)
                {
                    for (byte h = 0; h < blockHeight; h++)
                    {
                        Node p = nodeCube[(w) + blockWidth * ((h) + blockHeight * (d))];
                        foreach (jsonConnection conn in jsonConnections)
                        {
                            //check that the child of the connection is inside the cube
                            if(d+conn.z>=0 && d+conn.z<blockDepth){
                                if(w+conn.x>=0 && w+conn.x<blockWidth){
                                    if(h+conn.y>=0 && h+conn.y<blockHeight){
                                        Connect(p, nodeCube[(w+conn.x) + blockWidth * ((h+conn.y) + blockHeight * (d+conn.z))],conn.weight);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            _workGenerator = new FiringWorkGenerator(ref _fireQueue, ref _renderQueue, blockOffset,nodeCube);
        }