Example #1
0
 public void EnsureFullyGenerated()
 {
     if (blockTypes == null)
     {
         blockTypes = ScriptableObject.CreateInstance <BlockTypeList>();
     }
 }
Example #2
0
        /// <summary>
        /// Called when the BlockWorld behaviour is enabled.
        /// </summary>
        private void OnEnable()
        {
            if (m_WorldContainer != null)
            {
                return; // Already enabled
            }
            var chunkSize = new GridSize(4);

            var world     = new World(chunkSize);
            var blockList = new BlockTypeList();
            var remesh    = new RemeshHandler();
            var database  = new WorldDatabase("/home/thedudefromci/Bones3/TestWorld");

            remesh.AddDistributor(new StandardDistributor());

            m_WorldContainer = new WorldContainer(world, remesh, blockList, database);
            m_WorldContainer.BlockContainerProvider.OnBlockContainerCreated   += OnChunkCreated;
            m_WorldContainer.BlockContainerProvider.OnBlockContainerDestroyed += OnChunkDestroyed;
            m_WorldContainer.RemeshHandler.OnRemeshFinish += OnRemeshFinished;

#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                UnityEditor.EditorApplication.update += Update;
            }
#endif
        }
Example #3
0
        private void AddToCumulative(TargetType type, BlockTypeList blocks)
        {
            if (blocks == null)
            {
                return;
            }
            Log.DebugLog("adding to type: " + type + ", count: " + blocks.BlockNamesContain.Length);

            if (type == TargetType.AllGrid)
            {
                AddToCumulative(TargetType.SmallGrid, blocks);
                AddToCumulative(TargetType.LargeGrid, blocks);
                AddToCumulative(TargetType.Station, blocks);
                return;
            }

            BlockTypeList targetBlocks;

            if (m_cumulative_targeting.TryGetValue(type, out targetBlocks))
            {
                m_cumulative_targeting[type] = BlockTypeList.Union(targetBlocks, blocks);
            }
            else
            {
                m_cumulative_targeting[type] = blocks;
            }
        }
Example #4
0
        public void AddBlock_WrongID_Error()
        {
            var list = new BlockTypeList();

            Assert.Throws <ArgumentException>(() =>
                                              list.AddBlockType(new BlockBuilder(5).Build()));
        }
Example #5
0
        /// <summary>
        /// Creates a new block type preview object.
        /// </summary>
        /// <param name="blockTypes">The block type list to reference when rendering.</param>
        public BlockTypesPreview(BlockTypeList blockTypes)
        {
            this.blockTypes = blockTypes;

            EditorUtility.SetCameraAnimateMaterials(previewUtility.camera, true);

            remeshHandler = new RemeshHandler();
            remeshHandler.AddDistributor(new StandardDistributor());
            remeshHandler.OnRemeshFinish += OnRemeshFinish;
        }
Example #6
0
        public void RemoveProtectedBlockType_Error()
        {
            var list = new BlockTypeList();

            Assert.Throws <AccessViolationException>(() =>
                                                     list.RemoveBlockType(list.GetBlockType(0)));

            Assert.Throws <AccessViolationException>(() =>
                                                     list.RemoveBlockType(list.GetBlockType(1)));
        }
Example #7
0
        public void RemoveBlock()
        {
            var list  = new BlockTypeList();
            var block = new BlockBuilder(list.NextBlockID)
                        .Build();

            list.AddBlockType(block);

            list.RemoveBlockType(block);

            Assert.AreEqual(2, list.Count);
        }
Example #8
0
        public void RemoveBlock_Null()
        {
            var list  = new BlockTypeList();
            var block = new BlockBuilder(list.NextBlockID)
                        .Name("Iron")
                        .Build();

            list.AddBlockType(block);

            list.RemoveBlockType(null);

            Assert.AreEqual(3, list.Count);
        }
Example #9
0
        public void AddBlock()
        {
            var list  = new BlockTypeList();
            var block = new BlockBuilder(list.NextBlockID)
                        .Name("Coal")
                        .Build();

            list.AddBlockType(block);

            Assert.AreEqual(3, list.Count);
            Assert.AreEqual(2, block.ID);
            Assert.AreEqual(block, list.GetBlockType(2));
        }
Example #10
0
        /// <summary>
        /// Called when the BlockWorld behaviour is enabled.
        /// </summary>
        private void OnEnable()
        {
            var chunkSize = new GridSize(4);

            var world     = new World(chunkSize);
            var blockList = new BlockTypeList();
            var remesh    = new RemeshHandler();
            var database  = new WorldDatabase("/home/thedudefromci/Bones3/TestWorld");

            remesh.AddDistributor(new StandardDistributor());

            WorldContainer = new WorldContainer(world, remesh, blockList, database);
            WorldContainer.BlockContainerProvider.OnBlockContainerCreated   += OnChunkCreated;
            WorldContainer.BlockContainerProvider.OnBlockContainerDestroyed += OnChunkDestroyed;
            WorldContainer.RemeshHandler.OnRemeshFinish += OnRemeshFinished;
        }
Example #11
0
        public ProgrammableBlock(IMyCubeBlock block)
            : base(block)
        {
            m_logger = new Logger(GetType().Name, block);
            m_progBlock = block as Ingame.IMyProgrammableBlock;
            m_networkClient = new RelayClient(block, HandleMessage);

            byte index = 0;
            m_handleDetectedTerminal_ev = new EntityValue<bool>(block, index++, UpdateVisual);
            m_blockCountList_ev = new EntityStringBuilder(block, index++, () => {
                UpdateVisual();
                m_blockCountList_btl = new BlockTypeList(m_blockCountList_sb.ToString().LowerRemoveWhitespace().Split(','));
            });

            Registrar.Add(block, this);
        }
Example #12
0
        public void DefaultBlockTypes()
        {
            var list = new BlockTypeList();

            Assert.AreEqual(2, list.Count);

            Assert.AreEqual("Ungenerated", list.GetBlockType(0).Name);
            Assert.AreEqual(0, list.GetBlockType(0).ID);
            Assert.IsFalse(list.GetBlockType(0).IsSolid);
            Assert.IsFalse(list.GetBlockType(0).IsVisible);

            Assert.AreEqual("Air", list.GetBlockType(1).Name);
            Assert.AreEqual(1, list.GetBlockType(1).ID);
            Assert.IsFalse(list.GetBlockType(1).IsSolid);
            Assert.IsFalse(list.GetBlockType(1).IsVisible);
        }
Example #13
0
        public void CleanupRemesh()
        {
            // Clear references to avoid memory leaks
            chunk         = null;
            filter        = null;
            render        = null;
            collider      = null;
            materialArray = null;
            blockTypes    = null;

            // Clear lists to prepare for next pool use
            materialsUsed.Clear();
            toSort.Clear();

            // Mark object as unused in pool
            activeInPool = false;
        }
Example #14
0
        public void Initalize(Transform player, Chunk chunk)
        {
            this.chunk = chunk;
            render     = chunk.GetComponent <Renderer>();
            collider   = chunk.GetComponent <MeshCollider>();
            filter     = chunk.GetComponent <MeshFilter>();
            blockTypes = chunk.BlockTypes;

            Array.Copy(chunk.GetBlocksRaw(), blocks, blocks.Length);
            Array.Copy(chunk.GetBlockStatesRaw(), blockStates, blockStates.Length);

            Chunk side;

            for (int i = 0; i < 6; i++)
            {
                side = chunk.GetNearbyChunk(i);
                if (side == null)
                {
                    for (int j = 0; j < 4096; j++)
                    {
                        nearbyBlocks[i * 4096 + j]      = 0;
                        nearbyBlockStates[i * 4096 + j] = 0;
                    }
                }
                else
                {
                    Array.Copy(side.GetBlocksRaw(), 0, nearbyBlocks, i * 4096, 4096);
                    Array.Copy(side.GetBlockStatesRaw(), 0, nearbyBlockStates, i * 4096, 4096);
                }
            }

            chunkX     = chunk.chunkX;
            chunkY     = chunk.chunkY;
            chunkZ     = chunk.chunkZ;
            emptyChunk = chunk.EmptyChunk;
        }
Example #15
0
        private void AddToCumulative(TargetType type, BlockTypeList blocks)
        {
            m_logger.debugLog("adding to type: " + type + ", count: " + blocks.BlockNamesContain.Length);

            if (type == TargetType.AllGrid)
            {
                AddToCumulative(TargetType.SmallGrid, blocks);
                AddToCumulative(TargetType.LargeGrid, blocks);
                AddToCumulative(TargetType.Station, blocks);
                return;
            }

            BlockTypeList targetBlocks;
            if (m_cumulative_targeting.TryGetValue(type, out targetBlocks))
                m_cumulative_targeting[type] = BlockTypeList.Union(targetBlocks, blocks);
            else
                m_cumulative_targeting[type] = blocks;
        }
Example #16
0
 public void OnObjectCloned()
 {
     // Clone block types
     blockTypes = BlockTypes.Copy();
 }