Example #1
0
        public MiloFile(string name, string type, bool bigEndian = true) : base(name, type, bigEndian)
        {
            _structure = BlockStructure.MILO_A;
            _offset    = 2064;

            Entries = new List <AbstractEntry>();
        }
 public void Reset()
 {
     ControllerState = ControllerStateEnum.Control;
     Clock.Reset();
     SignalGroups.ForEach(x => x.Reset());
     BlockStructure.Reset();
     Extras.Reset();
 }
Example #3
0
        /// <summary>
        /// Get particle mesh by BlockType
        /// </summary>
        /// <param name="type">type of block</param>
        private static Mesh CreateBlockParticleMeh(BlockType type)
        {
            Mesh           particleMesh;
            BlockStructure block = WorldData.GetBlockData(type);

            float offsetX = UnityEngine.Random.Range(0f, 1 - blockDestroyParticleUvSize) / BlockTextureSize;
            float offsetY = UnityEngine.Random.Range(0f, blockDestroyParticleUvSize) / BlockTextureSize;
            float size    = blockDestroyParticleUvSize / BlockTextureSize;

            // if mesh is in cache
            if (particleMeshes.ContainsKey(type))
            {
                particleMesh = particleMeshes[type];

                particleMesh.uv = new Vector2[]
                {
                    block.sideUVs.uv0 + new float2(offsetX, offsetY),
                    block.sideUVs.uv0 + new float2(offsetX, offsetY + size),
                    block.sideUVs.uv0 + new float2(offsetX + size, offsetY + size),
                    block.sideUVs.uv0 + new float2(offsetX + size, offsetY)
                };

                particleMesh.RecalculateNormals();

                return(particleMeshes[type]);
            }

            particleMesh = new Mesh();

            particleMesh.vertices = new Vector3[]
            {
                new Vector3(0, 0, 0),
                new Vector3(0, 1, 0),
                new Vector3(1, 1, 0),
                new Vector3(1, 0, 0)
            };
            particleMesh.uv = new Vector2[]
            {
                block.sideUVs.uv0 + new float2(offsetX, offsetY),
                block.sideUVs.uv0 + new float2(offsetX, offsetY + size),
                block.sideUVs.uv0 + new float2(offsetX + size, offsetY + size),
                block.sideUVs.uv0 + new float2(offsetX + size, offsetY)
            };
            particleMesh.triangles = new int[]
            {
                0,
                1,
                2,
                0,
                2,
                3
            };

            particleMesh.RecalculateNormals();

            particleMeshes.Add(type, particleMesh);
            return(particleMesh);
        }
        protected virtual void DoOnChange(BlockStructure blockStructure)
        {
            ChangedEventHandler handler = OnChange;

            if (handler != null)
            {
                handler(blockStructure);
            }
        }
        public BlockStructureSupervisor(Project project)
        {
            // Save the members we need for later referencing.
            Project = project;

            // Set up the default structure which is just one or more paragraphs
            // and no structural elements.
            rootBlockStructure = new BlockStructure
            {
                BlockType = project.BlockTypes.Paragraph
            };
        }
        public BlockStructureSupervisor(Project project)
        {
            // Save the members we need for later referencing.
            Project = project;

            // Set up the default structure which is just one or more paragraphs
            // and no structural elements.
            rootBlockStructure = new BlockStructure
            {
                BlockType = project.BlockTypes.Paragraph
            };
        }
Example #7
0
        private static FoldingRange[] GetFoldingRanges(
            BlockStructure blockStructure,
            SourceText text
            )
        {
            if (blockStructure.Spans.IsEmpty)
            {
                return(Array.Empty <FoldingRange>());
            }

            using var _ = ArrayBuilder <FoldingRange> .GetInstance(out var foldingRanges);

            foreach (var span in blockStructure.Spans)
            {
                if (!span.IsCollapsible)
                {
                    continue;
                }

                var linePositionSpan = text.Lines.GetLinePositionSpan(span.TextSpan);

                // Filter out single line spans.
                if (linePositionSpan.Start.Line == linePositionSpan.End.Line)
                {
                    continue;
                }

                // TODO - Figure out which blocks should be returned as a folding range (and what kind).
                // https://github.com/dotnet/roslyn/projects/45#card-20049168
                FoldingRangeKind?foldingRangeKind = span.Type switch
                {
                    BlockTypes.Comment => FoldingRangeKind.Comment,
                    BlockTypes.Imports => FoldingRangeKind.Imports,
                    BlockTypes.PreprocessorRegion => FoldingRangeKind.Region,
                    _ => null,
                };

                foldingRanges.Add(
                    new FoldingRange()
                {
                    StartLine      = linePositionSpan.Start.Line,
                    StartCharacter = linePositionSpan.Start.Character,
                    EndLine        = linePositionSpan.End.Line,
                    EndCharacter   = linePositionSpan.End.Character,
                    Kind           = foldingRangeKind
                }
                    );
            }

            return(foldingRanges.ToArray());
        }
Example #8
0
        public static void TestReading(Header header)
        {
            var readQueue = new Queue <BlockStructure>();

            readQueue.Enqueue(header);

            while (readQueue.Count > 0)
            {
                BlockStructure block = readQueue.Dequeue();
                block.Load();

                foreach (BlockStructure b in block.ReferencedBlocks)
                {
                    readQueue.Enqueue(b);
                }

                block.Unload();
            }
        }
Example #9
0
 public Up45Block(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.Up45;
 }
Example #10
0
 public Up26HighBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.Up26High;
 }
 public DiagonalFacingDownRightBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.DiagonalFacingDownRight;
 }
Example #12
0
	public void AddBlockStructureToTerrain(Chunk chunk, BlockStructure MyTownHall, Vector3 TownHallSize, Vector3 TownHallPosition) {
		AddBlockStructureToTerrain(chunk, MyTownHall, TownHallSize, TownHallPosition, new Vector3());
	}
Example #13
0
        public static void CreateBlockCube(Mesh mesh, BlockType blockType, float cubeSize = 1, float pivotX = 0.5f, float pivotY = 0.5f, float pivotZ = 0.5f)
        {
            BlockStructure block = WorldData.GetBlockData(blockType);

            Vector3[] verts = new Vector3[24];
            Vector2[] uv    = new Vector2[24];

            float startPosX = -pivotX * cubeSize;
            float startPosY = -pivotY * cubeSize;
            float startPosZ = -pivotZ * cubeSize;

            verts[0] = new Vector3(startPosX, startPosY + cubeSize, startPosZ);
            verts[1] = new Vector3(startPosX, startPosY + cubeSize, startPosZ + cubeSize);
            verts[2] = new Vector3(startPosX + cubeSize, startPosY + cubeSize, startPosZ + cubeSize);
            verts[3] = new Vector3(startPosX + cubeSize, startPosY + cubeSize, startPosZ);

            uv[0] = block.topUVs.uv0;
            uv[1] = block.topUVs.uv1;
            uv[2] = block.topUVs.uv2;
            uv[3] = block.topUVs.uv3;

            verts[4] = new Vector3(startPosX, startPosY, startPosZ);
            verts[5] = new Vector3(startPosX + cubeSize, startPosY, startPosZ);
            verts[6] = new Vector3(startPosX + cubeSize, startPosY, startPosZ + cubeSize);
            verts[7] = new Vector3(startPosX, startPosY, startPosZ + cubeSize);

            uv[4] = block.botUvs.uv0;
            uv[5] = block.botUvs.uv1;
            uv[6] = block.botUvs.uv2;
            uv[7] = block.botUvs.uv3;

            verts[8]  = new Vector3(startPosX, startPosY, startPosZ);
            verts[9]  = new Vector3(startPosX, startPosY + cubeSize, startPosZ);
            verts[10] = new Vector3(startPosX + cubeSize, startPosY + cubeSize, startPosZ);
            verts[11] = new Vector3(startPosX + cubeSize, startPosY, startPosZ);

            uv[8]  = block.sideUVs.uv0;
            uv[9]  = block.sideUVs.uv1;
            uv[10] = block.sideUVs.uv2;
            uv[11] = block.sideUVs.uv3;

            verts[12] = new Vector3(startPosX + cubeSize, startPosY, startPosZ + cubeSize);
            verts[13] = new Vector3(startPosX + cubeSize, startPosY + cubeSize, startPosZ + cubeSize);
            verts[14] = new Vector3(startPosX, startPosY + cubeSize, startPosZ + cubeSize);
            verts[15] = new Vector3(startPosX, startPosY, startPosZ + cubeSize);

            uv[12] = block.sideUVs.uv0;
            uv[13] = block.sideUVs.uv1;
            uv[14] = block.sideUVs.uv2;
            uv[15] = block.sideUVs.uv3;

            verts[16] = new Vector3(startPosX + cubeSize, startPosY, startPosZ);
            verts[17] = new Vector3(startPosX + cubeSize, startPosY + cubeSize, startPosZ);
            verts[18] = new Vector3(startPosX + cubeSize, startPosY + cubeSize, startPosZ + cubeSize);
            verts[19] = new Vector3(startPosX + cubeSize, startPosY, startPosZ + cubeSize);

            uv[16] = block.sideUVs.uv0;
            uv[17] = block.sideUVs.uv1;
            uv[18] = block.sideUVs.uv2;
            uv[19] = block.sideUVs.uv3;

            verts[20] = new Vector3(startPosX, startPosY, startPosZ + cubeSize);
            verts[21] = new Vector3(startPosX, startPosY + cubeSize, startPosZ + cubeSize);
            verts[22] = new Vector3(startPosX, startPosY + cubeSize, startPosZ);
            verts[23] = new Vector3(startPosX, startPosY, startPosZ);

            uv[20] = block.sideUVs.uv0;
            uv[21] = block.sideUVs.uv1;
            uv[22] = block.sideUVs.uv2;
            uv[23] = block.sideUVs.uv3;

            int[] triangles = new int[36];
            int   counter   = 0;

            for (int i = 0; i < 6; i++)
            {
                triangles[counter + 0] = i * 4;
                triangles[counter + 1] = i * 4 + 1;
                triangles[counter + 2] = i * 4 + 2;
                triangles[counter + 3] = i * 4;
                triangles[counter + 4] = i * 4 + 2;
                triangles[counter + 5] = i * 4 + 3;
                counter += 6;
            }

            mesh.Clear();
            mesh.vertices  = verts;
            mesh.triangles = triangles;
            mesh.uv        = uv;
            mesh.RecalculateNormals();
        }
Example #14
0
 public Down26LowBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.Down26Low;
 }
Example #15
0
	// once the models finished generating itll be loaded
	public void LoadModelFromDataBase() {
		if (!HasLoaded && GetManager.GetDataManager ().IsModel (MyVoxelModelName)) {
			MyBlockStructure = GetManager.GetDataManager ().GetBlockStructure(MyBlockStructureName);
			gameObject.GetComponent<MeshFilter> ().mesh = GetManager.GetDataManager ().GetModel (MyVoxelModelName);
			if (gameObject.GetComponent<MeshCollider> () != null) {
				gameObject.GetComponent<MeshCollider> ().sharedMesh = null;
				gameObject.GetComponent<MeshCollider> ().sharedMesh = gameObject.GetComponent<MeshFilter> ().mesh;
			}
			HasLoaded = true;
		}
	}
Example #16
0
 public Right7LowBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.Right7Low;
 }
        /// <summary>
        /// Updates the blocks in the project and assign them to block types that fit
        /// the document structure. This will attempt to keep the current block type
        /// of a given block if it can fit into the structure.
        /// </summary>
        public void Update()
        {
            // If we are inside interactive processing, we need to skip updates
            // since this can be an expensive operation.
            if (Project.ProcessingState == ProjectProcessingState.Batch)
            {
                return;
            }

            // We need to get a write lock on the block since we'll be making changes
            // to all the blocks and their relationships. This will, in effect, also
            // ensure no block is being modified.
            using (Project.Blocks.AcquireLock(RequestLock.Write))
            {
                // Go through all the blocks in the list.
                ProjectBlockCollection blocks = Project.Blocks;

                for (int blockIndex = 0;
                     blockIndex < Project.Blocks.Count;
                     blockIndex++)
                {
                    // Grab the block we're currently looking at.
                    Block     block     = blocks[blockIndex];
                    BlockType blockType = block.BlockType;

                    // To figure out the block type, we go backwards until we find the
                    // first block's structure that contains this block type. If we
                    // can't find one, we will just use the first block in the list
                    // regardless of type.
                    BlockStructure newBlockStructure = null;
                    Block          newParentBlock    = null;

                    for (int searchIndex = blockIndex - 1;
                         searchIndex >= 0;
                         searchIndex--)
                    {
                        // Grab this block and structure.
                        Block          searchBlock     = blocks[searchIndex];
                        BlockStructure searchStructure = searchBlock.BlockStructure;

                        // If the search structure includes the current block type,
                        // then we'll use that and stop looking through the rest of the list.
                        if (searchStructure.ContainsChildStructure(blockType))
                        {
                            newBlockStructure = searchStructure.GetChildStructure(blockType);
                            newParentBlock    = searchBlock;
                            break;
                        }
                    }

                    // Look to see if we assigned the parent block and structure. If we
                    // haven't, then assign the parent to the first one (obvious not if
                    // we are modifying the first one).
                    if (newParentBlock == null &&
                        blockIndex > 0)
                    {
                        newParentBlock = Project.Blocks[0];
                    }

                    if (newBlockStructure == null)
                    {
                        newBlockStructure = RootBlockStructure;
                    }

                    // Assign the new block structure and parent.
                    block.SetParentBlock(newParentBlock);
                    //block.SetBlockStructure(newBlockStructure);
                }
            }
        }
Example #18
0
    public static Chunk[] SetStructure(ref WorldResources worldRes, BlockStructure structure)
    {
        List <Chunk> modifiedChunks = new List <Chunk>();
        int          x      = ((int)Mathf.Ceil(16 * ((structure.BuildPointer.x / 16) - ((int)(structure.BuildPointer.x / 16))) + 0.5f) - 1);
        int          Height = (int)Mathf.Ceil(255 * ((structure.BuildPointer.y / 255) - ((int)(structure.BuildPointer.y / 255))) + 0.5f) - 1;
        int          z      = (int)Mathf.Ceil(16 * ((structure.BuildPointer.z / 16) - ((int)(structure.BuildPointer.z / 16))) + 0.5f) - 1;
        int          chunkX = (int)(structure.BuildPointer.x / 16f);
        int          chunkZ = (int)(structure.BuildPointer.z / 16f);

        Chunk selectedChunk;

        Vector3 spawnPointer;

        for (int i = 0; i < structure.Structure.Length; i++)
        {
            int chunkMx = 0;
            int chunkMz = 0;
            spawnPointer = new Vector3((structure.Structure[i].WorldPos.x + x), (structure.Structure[i].WorldPos.y + Height), (structure.Structure[i].WorldPos.z + z));
            if (spawnPointer.x >= 16)
            {
                chunkMx += (int)(spawnPointer.x / 16f);

                spawnPointer.x = spawnPointer.x - 16;
            }
            if (spawnPointer.z >= 16)
            {
                spawnPointer.z = spawnPointer.z - 16;
                chunkMz       += (int)(spawnPointer.z / 16f);
            }

            if (spawnPointer.x < 0)
            {
                spawnPointer.x = -(spawnPointer.x - 16);
                chunkMx       -= (int)(Mathf.Abs(spawnPointer.x) / 16f);


                //Debug.Log($"{Mathf.Abs(spawnPointer.x)} / 16 = {chunkX + chunkMx} ; {spawnPointer.x}");
            }
            if (spawnPointer.z < 0)
            {
                spawnPointer.z = -(spawnPointer.z - 16);
                chunkMz       -= (int)(Mathf.Abs(spawnPointer.z) / 16f);
            }
            if ((chunkZ + chunkMz) < 0 || (chunkZ + chunkMz) >= worldRes.VMG.ChunksRenderDistance || (chunkX + chunkMx) < 0 || (chunkX + chunkMx) >= worldRes.VMG.ChunksRenderDistance)
            {
                continue;
            }

            selectedChunk = worldRes.WorldMap[chunkZ + chunkMz, chunkX + chunkMx];

            try
            {
                selectedChunk.ChunkMap[(int)spawnPointer.y, (int)spawnPointer.z, (int)spawnPointer.x] = structure.Structure[i].ID;
            }
            catch
            {
                Debug.Log($"{spawnPointer.ToString()}");
            }
            if (!IsChunkInList(ref modifiedChunks, ref selectedChunk) == true)
            {
                modifiedChunks.Add(selectedChunk);
            }
        }
        return(modifiedChunks.ToArray());
    }
Example #19
0
 public Right26LowBlock(BlockStructure blockStructure, Vector3 pos)
     : base(blockStructure, pos)
 {
     SlopeType = SlopeType.Right26Low;
 }
Example #20
0
 public Up7LowBlock(BlockStructure blockStructure, Vector3 pos)
     : base(blockStructure, pos)
 {
     SlopeType = SlopeType.Up7Low;
 }
Example #21
0
 public PartialCenterBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos) 
 {
     SlopeType = SlopeType.PartialCentreBlock;
 }
Example #22
0
 public MiloFile()
 {
     _structure = BlockStructure.MILO_B;
     _offset    = 2064;
 }
Example #23
0
 public Down26LowBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.Down26Low;
 }
Example #24
0
	public bool IsInsideBlockStructure(Chunk chunk, BlockStructure MyBlockStructure, Vector3 TownHallPosition, Vector3 TownHallSize) {
		//Vector3 LowerBounds = new Vector3(TownHallPosition.x-TownHallSize.x/2f,TownHallPosition.y-TownHallSize.y/2f,TownHallPosition.z-TownHallSize.z/2f);
		//Vector3 UpperBounds = new Vector3(TownHallPosition.x+TownHallSize.x/2f,TownHallPosition.y+TownHallSize.y/2f,TownHallPosition.z+TownHallSize.z/2f);
		Vector3 LowerBounds = new Vector3(0,0,0);
		Vector3 UpperBounds = new Vector3(TownHallPosition.x+TownHallSize.x,TownHallPosition.y+TownHallSize.y,TownHallPosition.z+TownHallSize.z);
		//Debug.LogError ("Before Rounding - Lower: " + LowerBounds.ToString() + " : Upper: " + UpperBounds.ToString());
		LowerBounds.x = 16f*(Mathf.FloorToInt(LowerBounds.x/16f));
		LowerBounds.y = 16f*(Mathf.FloorToInt(LowerBounds.y/16f));
		LowerBounds.z = 16f*(Mathf.FloorToInt(LowerBounds.z/16f));
		UpperBounds.x = 16f*(Mathf.CeilToInt(UpperBounds.x/16f));
		UpperBounds.y = 16f*(Mathf.CeilToInt(UpperBounds.y/16f));
		UpperBounds.z = 16f*(Mathf.CeilToInt(UpperBounds.z/16f));
		//Debug.LogError ("LowerBounds: " + LowerBounds.ToString() + " : Upper: " + UpperBounds.ToString());
		if (chunk.pos.x >= LowerBounds.x && chunk.pos.x <= UpperBounds.x
			&& chunk.pos.y >= LowerBounds.y && chunk.pos.y <= UpperBounds.y
			&& chunk.pos.z >= LowerBounds.z && chunk.pos.z <= UpperBounds.z) // if town hall position+size is inside chunk!
			return true;
		else
			return false;
	}
Example #25
0
 internal void AddToBlockStructureCache(Tuple <int, uint> address, BlockStructure blockStructure)
 {
     _blockStructureCache[address] = new WeakReference(blockStructure);
 }
Example #26
0
 public Down7High4Block(BlockStructure blockStructure, Vector3 pos)
     : base(blockStructure, pos)
 {
     SlopeType = SlopeType.Down7High4;
 }
Example #27
0
 public PartialTopLeftBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.PartialBlockTopLeft;
 }
 public DiagonalSlopeFacingUpLeftBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.DiagonalSlopeFacingUpLeft;
 }
        public void Execute()
        {
            NativeArray <float3> verts     = new NativeArray <float3>(4, Allocator.Temp);
            NativeArray <float2> uv        = new NativeArray <float2>(4, Allocator.Temp);
            NativeArray <int>    triangles = new NativeArray <int>(6, Allocator.Temp);

            NativeArray <bool> drawFace = new NativeArray <bool>(6, Allocator.Temp);
            NativeArray <bool> flipFace = new NativeArray <bool>(6, Allocator.Temp);

            NativeArray <short> nearbyLiquidSourceDistance = new NativeArray <short>(4, Allocator.Temp);

            for (int x = 1; x < WorldSettings.ChunkSizeXZ + 1; x++)
            {
                for (int z = 1; z < WorldSettings.ChunkSizeXZ + 1; z++)
                {
                    for (int y = 0; y < WorldSettings.ChunkSizeY; y++)
                    {
                        int       index     = Utils.BlockPosition3DtoIndex(x, y, z);
                        BlockType blockType = blocks[index];

                        if (blockType == BlockType.AIR)
                        {
                            continue;
                        }

                        int3 blockPos = new int3(x - 1, y, z - 1);
                        int  numFaces = 0;

                        BlockStructure block = WorldData.GetBlockData(blockType);

                        short param = 0;

                        // assign default values
                        ref var verticles = ref blockVerticles;
                        ref var uvs       = ref blockUVs;
                        ref var tris      = ref blockTriangles;

                        // check for visible faces
                        switch (block.shape)
                        {
                        case BlockShape.LIQUID:
                            verticles = ref liquidVerticles;
                            uvs       = ref liquidUVs;
                            tris      = ref liquidTriangles;

                            // set to full by default to not save full blocks in game saves
                            if (!blockParameters.TryGetValue(new BlockParameter(new int3(x, y, z), ParameterType.WATER_SOURCE_DISTANCE), out param))
                            {
                                param = 8;
                            }

                            BlockstateLiquid(drawFace, index, x, y, z);
                            break;

                        case BlockShape.HALF_BLOCK:
                            blockParameters.TryGetValue(new BlockParameter(new int3(x, y, z), ParameterType.ROTATION), out param);

                            BlockstateSolidHalf(drawFace, index, x, y, z, param);
                            break;

                        case BlockShape.GRASS:
                            verticles = ref plantsVerticles;
                            uvs       = ref plantsUVs;
                            tris      = ref plantsTriangles;

                            blockParameters.TryGetValue(new BlockParameter(new int3(x, y, z), ParameterType.BLOCK_TYPE), out param);

                            BlockstateGrass(drawFace, index, x, y, z);
                            break;

                        default:
                            BlockstateSolid(drawFace, index, x, y, z);
                            break;
                        }

                        // draw faces
                        if (block.shape == BlockShape.LIQUID)
                        {
                            short value;
                            for (int i = 0; i < 6; i++)
                            {
                                if (!drawFace[i])
                                {
                                    continue;
                                }

                                // R L F B
                                nearbyLiquidSourceDistance[0] = blockParameters.TryGetValue(new BlockParameter(new int3(x + 1, y, z), ParameterType.WATER_SOURCE_DISTANCE), out value) ? value : (short)0;
                                nearbyLiquidSourceDistance[1] = blockParameters.TryGetValue(new BlockParameter(new int3(x - 1, y, z), ParameterType.WATER_SOURCE_DISTANCE), out value) ? value : (short)0;
                                nearbyLiquidSourceDistance[2] = blockParameters.TryGetValue(new BlockParameter(new int3(x, y, z + 1), ParameterType.WATER_SOURCE_DISTANCE), out value) ? value : (short)0;
                                nearbyLiquidSourceDistance[3] = blockParameters.TryGetValue(new BlockParameter(new int3(x, y, z - 1), ParameterType.WATER_SOURCE_DISTANCE), out value) ? value : (short)0;

                                bool reverse = block.GetWaterShape((BlockFace)i, blockPos, verts, uv, param, nearbyLiquidSourceDistance);
                                verticles.AddRange(verts);
                                uvs.AddRange(uv);

                                flipFace[numFaces] = reverse;
                                numFaces++;
                            }
                        }
                        else
                        {
                            for (int i = 0; i < 6; i++)
                            {
                                if (!drawFace[i])
                                {
                                    continue;
                                }
                                bool reverse = block.GetBlockShape((BlockFace)i, blockPos, verts, uv, param);
                                verticles.AddRange(verts);
                                uvs.AddRange(uv);

                                flipFace[numFaces] = reverse;
                                numFaces++;
                            }
                        }

                        // triangles
                        int tl = verticles.Length - 4 * numFaces;
                        for (int i = 0; i < numFaces; i++)
                        {
                            if (flipFace[i])
                            {
                                triangles[5] = tl + i * 4;
                                triangles[4] = tl + i * 4 + 1;
                                triangles[3] = tl + i * 4 + 2;
                                triangles[2] = tl + i * 4;
                                triangles[1] = tl + i * 4 + 2;
                                triangles[0] = tl + i * 4 + 3;
                            }
                            else
                            {
                                triangles[0] = tl + i * 4;
                                triangles[1] = tl + i * 4 + 1;
                                triangles[2] = tl + i * 4 + 2;
                                triangles[3] = tl + i * 4;
                                triangles[4] = tl + i * 4 + 2;
                                triangles[5] = tl + i * 4 + 3;
                            }

                            tris.AddRange(triangles);
                        }
                    }
Example #30
0
 public Down7High2Block(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.Down7High2;
 }
Example #31
0
	public void AddBlockStructureToTerrain(Chunk chunk, BlockStructure MyTownHall, Vector3 TownHallSize, Vector3 TownHallPosition, Vector3 Buffer) {
		for (int i = 0; i < TownHallSize.x; i++)
			for (int j = 0; j < TownHallSize.y; j++)
			for (int k = 0; k < TownHallSize.z; k++) {
				Vector3 MyBlockStructurePosition = new Vector3 (i, j, k);
				MyBlockStructurePosition += TownHallPosition;
				MyBlockStructurePosition.x -= chunk.pos.x;
				MyBlockStructurePosition.y -= chunk.pos.y;
				MyBlockStructurePosition.z -= chunk.pos.z;
				{
					int BlockType = MyTownHall.MyBlocks.GetBlockType (MyBlockStructurePosition + new Vector3(chunk.pos.x, chunk.pos.y, chunk.pos.z));
						// spawn town hall here
					MyBlockStructurePosition += Buffer;
					int x = Mathf.FloorToInt (MyBlockStructurePosition.x);
					int y = Mathf.FloorToInt (MyBlockStructurePosition.y);
					int z = Mathf.FloorToInt (MyBlockStructurePosition.z);
					if (Chunk.InRange(x) && Chunk.InRange(y) && Chunk.InRange(z)) {
						if (BlockType != 0)
							chunk.SetBlock (x,y,z,
							                new Block (BlockType));	// cobble stone
						else
						    chunk.SetBlock (x,y,z,
							                new BlockAir ());
						}
				}
				}
	}
Example #32
0
 public PartialCenterBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.PartialCentreBlock;
 }
Example #33
0
 public EmptyBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.None;
 }
Example #34
0
	public BlockStructure LoadModelFromFile2(string FileName) {
		BlockStructure MyBlockStructure = new BlockStructure();
		FileName = FileLocator.SaveLocation (GetManager.GetGameManager ().GameName, FileName, "Models/", ".vmd");
		Debug.Log (".... Loading Model from: " + FileName + " At time: " + Time.time);
		if (File.Exists (FileName)) {
			IFormatter BinaryFile = new BinaryFormatter ();
			FileStream MyFile = new FileStream (FileName, FileMode.Open);
			
			BlocksSerial MyBlocksSerial = (BlocksSerial)BinaryFile.Deserialize (MyFile);
			
			MyBlockStructure.MyBlocks.SetData(MyBlocksSerial.GetData());
			MyBlockStructure.MyBlocks.Size = MyBlocksSerial.GetSize();
			MyBlockStructure.MyBlocks.ReCreateBlocks();
			MyBlockStructure.MyBlocks.HasUpdated = true;
		}
		return MyBlockStructure;
	}
Example #35
0
        private static byte[] ADDE_PADDING = { 0xAD, 0xDE, 0xAD, 0xDE }; // Used to pad files

        private static MiloFile ParseDirectory(AwesomeReader ar, BlockStructure structure, uint offset)
        {
            bool        origBigEndian = ar.BigEndian; // Used to preserve orig stream
            MiloFile    milo;
            MiloVersion version;
            bool        valid;
            string      dirName, dirType;

            string[] entryNames, entryTypes;

            // Guesses endianess
            ar.BigEndian = DetermineEndianess(ar.ReadBytes(4), out version, out valid);
            if (!valid)
            {
                return(null);        // Maybe do something else later
            }
            ParseEntryNames(ar, version, out dirName, out dirType, out entryNames, out entryTypes);
            milo            = new MiloFile(dirName, dirType, ar.BigEndian);
            milo._structure = structure;
            milo._offset    = offset;
            milo._version   = version;

            // TODO: Add component parser (Difficult)
            if (version == MiloVersion.V10)
            {
                milo._externalResources = new List <string>(GetExternalResources(ar));
            }
            else if (version == MiloVersion.V24)
            {
                /*
                 * if (dirName == "alterna1") // Hacky fix, please remove!
                 * {
                 *  ar.BaseStream.Position += 117;
                 *  Trans tran = new Trans(dirName);
                 *
                 *  // Reads view matrices
                 *  tran.Mat1 = Matrix.FromStream(ar);
                 *  ar.BaseStream.Position += 4;
                 *  tran.Mat2 = Matrix.FromStream(ar);
                 *  ar.BaseStream.Position += 4;
                 *
                 *  milo.Entries.Add(tran);
                 * }
                 * else if (dirName == "dancer1") // Hacky fix, please remove!
                 * {
                 *  ar.BaseStream.Position += 31;
                 *  Trans tran = new Trans(dirName);
                 *
                 *  // Reads view matrices
                 *  tran.Mat1 = Matrix.FromStream(ar);
                 *  ar.BaseStream.Position += 4;
                 *  tran.Mat2 = Matrix.FromStream(ar);
                 *  ar.BaseStream.Position += 4;
                 *
                 *  milo.Entries.Add(tran);
                 * }*/

                // Skips unknown stuff for now
                ar.FindNext(ADDE_PADDING);
                ar.BaseStream.Position += 4;
            }

            // Reads each file
            for (int i = 0; i < entryNames.Length; i++)
            {
                long   start = ar.BaseStream.Position;
                int    size  = (int)(ar.FindNext(ADDE_PADDING));
                byte[] bytes;

                // Reads raw file bytes
                ar.BaseStream.Position = start;
                bytes = ar.ReadBytes(size);
                ar.BaseStream.Position += 4; // Jumps ADDE padding

                switch (entryTypes[i])
                {
                case "Tex":
                    using (MemoryStream ms = new MemoryStream(bytes))
                    {
                        AbstractEntry entry = Tex.FromStream(ms);
                        if (entry == null)
                        {
                            goto defaultCase;
                        }

                        entry.Name = entryNames[i];
                        milo.Entries.Add(entry);
                    }
                    break;

                case "Mesh":
                    using (MemoryStream ms = new MemoryStream(bytes))
                    {
                        AbstractEntry entry = Mesh.FromStream(ms);
                        if (entry == null)
                        {
                            goto defaultCase;
                        }

                        entry.Name = entryNames[i];
                        milo.Entries.Add(entry);
                    }
                    break;

                case "View":
                    using (MemoryStream ms = new MemoryStream(bytes))
                    {
                        AbstractEntry entry = View.FromStream(ms);
                        if (entry == null)
                        {
                            goto defaultCase;
                        }

                        entry.Name = entryNames[i];
                        milo.Entries.Add(entry);
                    }
                    break;

                case "Group":
                    using (MemoryStream ms = new MemoryStream(bytes))
                    {
                        AbstractEntry entry = View.FromStreamAsGroup(ms);
                        if (entry == null)
                        {
                            goto defaultCase;
                        }

                        entry.Name = entryNames[i];
                        milo.Entries.Add(entry);
                    }
                    break;

                case "Mat":
                    using (MemoryStream ms = new MemoryStream(bytes))
                    {
                        AbstractEntry entry = Mat.FromStream(ms);
                        if (entry == null)
                        {
                            goto defaultCase;
                        }

                        entry.Name = entryNames[i];
                        milo.Entries.Add(entry);
                    }
                    break;

                case "Trans":
                    using (MemoryStream ms = new MemoryStream(bytes))
                    {
                        AbstractEntry entry = Trans.FromStream(ms);
                        if (entry == null)
                        {
                            goto defaultCase;
                        }

                        entry.Name = entryNames[i];
                        milo.Entries.Add(entry);
                    }
                    break;

                default:
defaultCase:
                    milo.Entries.Add(new MiloEntry(entryNames[i], entryTypes[i], bytes, milo.BigEndian));
                    break;
                }



                /* TODO: Implement milo files as entries
                 * if (type[i] == "ObjectDir" || type[i] == "MoveDir")
                 * {
                 *  // Directory embedded as an entry
                 *  // Skips over redundant directory info
                 *  ar.BaseStream.Position += 4;
                 *  dir.Entries.Add(MiloFile.FromStream(ar));
                 * }
                 * else
                 * {
                 *  // Regular entry
                 *  ar.BaseStream.Position = start;
                 *  dir.Entries.Add(new MEntry(name[i], type[i], ar.ReadBytes(size)));
                 *  ar.BaseStream.Position += 4;
                 * } */
            }

            ar.BigEndian = origBigEndian;
            return(milo);
        }
Example #36
0
 public Left7High0Block(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.Left7High0;
 }
Example #37
0
 public CubeBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.None;
 }
Example #38
0
 public PartialRightBlock(BlockStructure blockStructure, Vector3 pos)
     : base(blockStructure, pos)
 {
     SlopeType = SlopeType.PartialBlockRight;
 }
 public DiagonalFacingDownLeftBlock(BlockStructure blockStructure, Vector3 pos)
     : base(blockStructure, pos)
 {
     SlopeType = SlopeType.DiagonalFacingDownLeft;
 }
Example #40
0
 public PartialBottomBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.PartialBlockBottom;
 }
 public PartialBottomRightBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.PartialBlockBottomRight;
 }
Example #42
0
 public Right26HighBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.Right26High;
 }
 public DiagonalSlopeFacingUpRightBlock(BlockStructure blockStructure, Vector3 pos)
     : base(blockStructure, pos)
 {
     SlopeType = SlopeType.DiagonalSlopeFacingUpRight;
 }
Example #44
0
 public PartialTopBlock(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos) 
 {
     SlopeType = SlopeType.PartialBlockTop;
 }
Example #45
0
 public Left7High5Block(BlockStructure blockStructure, Vector3 pos)
     : base(blockStructure, pos)
 {
     SlopeType = SlopeType.Left7High5;
 }
Example #46
0
 public Up7High1Block(BlockStructure blockStructure, Vector3 pos) : base(blockStructure, pos)
 {
     SlopeType = SlopeType.Up7High1;
 }
Example #47
0
 public Right7High1Block(BlockStructure blockStructure, Vector3 pos)
     : base(blockStructure, pos)
 {
     SlopeType = SlopeType.Right7High1;
 }
Example #48
0
        internal void BindBlock(BlockStructure blockStructure)
        {
            if (blockStructure.Address != null)
            {
                throw new ArgumentException("blockStructure.Address already set!");
            }

            {
                var uniqueBlockStructure = blockStructure as UniqueBlockStructure;
                if (uniqueBlockStructure != null)
                {
                    if (uniqueBlockStructure.TryBindToExistingAddress())
                    {
                        return;
                    }
                }
            }

            int blockLength = blockStructure.Length;

            Tuple <int, Tuple <int, int> > bestMatch = null;

            for (int fileIndex = 0; fileIndex < _freeSpace.Length; fileIndex++)
            {
                foreach (var freeArea in _freeSpace[fileIndex].Items)
                {
                    int freeAreaLength = freeArea.Item2 - freeArea.Item1;

                    if (freeAreaLength < blockLength)
                    {
                        continue;
                    }

                    if (bestMatch != null && bestMatch.Item2.Item2 - bestMatch.Item2.Item1 < freeAreaLength)
                    {
                        continue;
                    }

                    bestMatch = new Tuple <int, Tuple <int, int> >(fileIndex, freeArea);
                }
            }
            if (bestMatch != null)
            {
                //Resize to fit block
                bestMatch = new Tuple <int, Tuple <int, int> >(bestMatch.Item1,
                                                               new Tuple <int, int>(bestMatch.Item2.Item1,
                                                                                    bestMatch.Item2.Item1 + blockLength));
            }

            if (bestMatch == null)
            {
                for (int fileIndex = 0; fileIndex < _blobFiles.Length; fileIndex++)
                {
                    if (_blobFiles[fileIndex].Length < MaximumBlockStartAddress)
                    {
                        bestMatch = new Tuple <int, Tuple <int, int> >(
                            fileIndex,
                            new Tuple <int, int>(
                                (int)_blobFiles[fileIndex].Length,
                                (int)_blobFiles[fileIndex].Length + blockLength));

                        _blobFiles[fileIndex].SetLength(_blobFiles[fileIndex].Length + blockLength);

                        break;
                    }
                }
            }

            if (bestMatch == null)
            {
                int newBlobIndex = AddNewBlob();

                bestMatch = new Tuple <int, Tuple <int, int> >(newBlobIndex,
                                                               new Tuple <int, int>(
                                                                   (int)_blobFiles[newBlobIndex].Length,
                                                                   (int)_blobFiles[newBlobIndex].Length + blockLength));
            }

            if (bestMatch.Item2.Item2 - bestMatch.Item2.Item1 != blockLength)
            {
                throw new Exception("Area mismatch! Wanted" + blockLength + "bytes, but got " +
                                    (bestMatch.Item2.Item2 - bestMatch.Item2.Item1) + " bytes.");
            }

            AllocateSpace(bestMatch.Item1, bestMatch.Item2);

            blockStructure.Address = new Tuple <int, uint>(bestMatch.Item1, (uint)bestMatch.Item2.Item1);

            {
                var uniqueBlockStructure = blockStructure as UniqueBlockStructure;
                if (uniqueBlockStructure != null)
                {
                    uniqueBlockStructure.UniqueBlockStructureBound();
                }
            }
        }