Example #1
0
        void Start()
        {
            cg.blocksRaycasts = initialCGBlocksRaycasts;

            Globals.Reset();
            Program program = Globals.program;

            // Create code block for each instruction in program
            instructionBlockTransforms = new Transform[program.instructions.Count];
            int lineNumber     = 0;
            int nextLabelIndex = 0;

            foreach (Instruction instruction in program.instructions)
            {
                // Create any labels for the current line
                while (nextLabelIndex < program.branchLabelList.Count && program.branchLabelList[nextLabelIndex].val == lineNumber)
                {
                    CreateLabel(ref nextLabelIndex);
                }

                // Create divider
                Divider divider = Instantiate(dividerPrefab, transform, false).GetComponent <Divider>();
                divider.Init(lineNumber);
                Globals.dividers.Add(divider);

                // Create code block
                GameObject instructionBlock = Instantiate(instructionBlockPrefab, transform, false);
                instructionBlock.GetComponent <InstructionBlock>().Init(lineNumber, instruction, divider);

                instructionBlockTransforms[lineNumber] = instructionBlock.transform;
                ++lineNumber;
            }

            // Create any remaining labels
            while (nextLabelIndex < program.branchLabelList.Count)
            {
                CreateLabel(ref nextLabelIndex);
            }

            // Create end divider
            Divider endDivider = Instantiate(dividerPrefab, transform, false).GetComponent <Divider>();

            endDivider.Init(lineNumber);
            Globals.dividers.Add(endDivider);

            OnRectTransformDimensionsChange();
            HandleTick();
        }
Example #2
0
        private void CreateLabel(ref int nextLabelIndex)
        {
            Label label = Program.branchLabelList[nextLabelIndex];

            Divider labelDivider = Instantiate(dividerPrefab, transform, false).GetComponent <Divider>();

            labelDivider.Init(label.val, label);
            Dividers.Add(labelDivider);

            // TODO: Need to test on bad devices to see if there's a performance hit when the code list is reset
            // NOTE: Maybe if there is, we can use pooling and continue to do a full reset
            GameObject labelBlock = Instantiate(labelBlockPrefab, transform, false);

            labelBlock.GetComponent <LabelBlock>().Init(label, labelDivider, this);
            ++nextLabelIndex;
        }
Example #3
0
        private void Generate()
        {
            cg.blocksRaycasts = initialCGBlocksRaycasts;

            Dividers.Clear();
            SlotFields.Clear();

            // Create code block for each instruction in program
            instructionBlockTransforms = new Transform[Program.instructions.Count];
            int lineNumber     = 0;
            int nextLabelIndex = 0;

            foreach (Instruction instruction in Program.instructions)
            {
                // Create any labels for the current line
                while (nextLabelIndex < Program.branchLabelList.Count && Program.branchLabelList[nextLabelIndex].val == lineNumber)
                {
                    CreateLabel(ref nextLabelIndex);
                }

                // Create divider
                Divider divider = Instantiate(dividerPrefab, transform, false).GetComponent <Divider>();
                divider.Init(lineNumber);
                Dividers.Add(divider);

                // Create code block
                GameObject instructionBlock = Instantiate(instructionBlockPrefab, transform, false);
                instructionBlock.GetComponent <InstructionBlock>().Init(lineNumber, instruction, divider, this);

                instructionBlockTransforms[lineNumber] = instructionBlock.transform;
                ++lineNumber;
            }

            // Create any remaining labels
            while (nextLabelIndex < Program.branchLabelList.Count)
            {
                CreateLabel(ref nextLabelIndex);
            }

            // Create end divider
            Divider endDivider = Instantiate(dividerPrefab, transform, false).GetComponent <Divider>();

            endDivider.Init(lineNumber);
            Dividers.Add(endDivider);

            OnRectTransformDimensionsChange();
        }