Exemple #1
0
        /// <summary>
        ///Add a chunk to the chunkset
        /// </summary>
        /// <param name="chunk">
        ///The chunk you wish to add
        /// </param>
        /// <param name="depth">
        ///The depth at which you are adding the chunk
        /// </param>
        public void AddChunkAt(MapChunk chunk, int depth)
        {
            if(chunkSet == null || chunkSet.Length == 0){
                chunkSet = new MapChunkEntry[1];
                chunkSet[0] = new ChunkSet.MapChunkEntry(chunk,depth);
                return;
            }

            if(ContainsDepth(depth)){

                Debug.LogWarning("Attemping to add a chunk at depth: " + depth + " to set at " + x + "," + y);

                return;
            }

            int newLength = chunkSet.Length + 1;

            MapChunkEntry[] newSet = new MapChunkEntry[newLength];

            for(int i = 0; i < chunkSet.Length; i++){

                newSet[i] = chunkSet[i];

            }

            newSet[newLength-1] =  new ChunkSet.MapChunkEntry(chunk,depth);

            chunkSet = newSet;
        }
    int updateTimer = 0, updateMax = (int)(1f / 0.02f); //Timer for texture animation. Unchangd overlays are not animated

    #endregion Fields

    #region Constructors

    public MapChunkVisibilityOverlay(MapChunk t)
    {
        chunk = t;
        updateTimer = updateMax;

        if (csUpdate_functionIndex == -1)
            csUpdate_functionIndex = csUpdate.FindKernel("CSMain");
    }
    public static MapChunk CreateChunk(int x, int y)
    {
        MapChunk chunk = new MapChunk(x, y);

        chunks.Add(chunk.pos, chunk);
        chunk.gameobject.transform.parent   = MapChunks.transform;
        chunk.gameobject.transform.position = new Vector3(x * MapChunk.chunkSize, y * MapChunk.chunkSize, 0);
        return(chunk);
    }
Exemple #4
0
        public void TrySetFloorFailsOnInvalidPositionTest()
        {
            var chunk     = new MapChunk();
            var parquetID = TestEntities.TestFloor.ID;

            var result = chunk.TrySetFloorDefinition(parquetID, invalidPosition);

            Assert.False(result);
        }
    //Create a map chunk at a specific position
    MapChunk buildChunkScript(GameObject chunkObject, int chunkSize, IntVector2 offset, MapChunkPosition position, List <WavesAndWeights> wavesAndWeights, Transform mapTransform)
    {
        MapChunk chunk = chunkObject.AddComponent <MapChunk>();

        chunk.build(chunkSize, offset, wavesAndWeights, mapTransform);
        chunk.setPosition(position);

        return(chunk);
    }
Exemple #6
0
        public void TrySetBlockSucceedsOnDefaultParquetAndPositionTest()
        {
            var chunk     = new MapChunk();
            var parquetID = TestParquets.TestBlock.ID;

            var result = chunk.TrySetBlock(parquetID, Vector2Int.ZeroVector);

            Assert.True(result);
        }
Exemple #7
0
        public void TrySetBlockFailsOnInvalidPositionTest()
        {
            var chunk     = new MapChunk();
            var parquetID = TestParquets.TestBlock.ID;

            var result = chunk.TrySetBlock(parquetID, invalidPosition);

            Assert.False(result);
        }
Exemple #8
0
        public void TryRemoveExitPointFailsOnInvalidPositionTest()
        {
            var chunk = new MapChunk();
            var point = new ExitPoint(invalidPosition, new Guid());

            var result = chunk.TryRemoveExitPoint(point);

            Assert.False(result);
        }
Exemple #9
0
        public void TrySetFloorSucceedsOnDefaultParquetAndPositionTest()
        {
            var chunk     = new MapChunk();
            var parquetID = TestEntities.TestFloor.ID;

            var result = chunk.TrySetFloorDefinition(parquetID, Vector2Int.ZeroVector);

            Assert.True(result);
        }
Exemple #10
0
        public void TryRemoveSpawnPointFailsOnInvalidPositionTest()
        {
            var chunk = new MapChunk();
            var point = new SpawnPoint(invalidPosition, SpawnType.Player);

            var result = chunk.TryRemoveSpawnPoint(point);

            Assert.False(result);
        }
Exemple #11
0
        public void TrySetSpawnPointSucceedsOnValidPositionTest()
        {
            var chunk = new MapChunk();
            var point = new SpawnPoint(Vector2Int.ZeroVector, SpawnType.Player);

            var result = chunk.TrySetSpawnPoint(point);

            Assert.True(result);
        }
Exemple #12
0
        public void TrySetExitPointSucceedsOnValidPositionTest()
        {
            var chunk = new MapChunk();
            var point = new ExitPoint(Vector2Int.ZeroVector, new Guid());

            var result = chunk.TrySetExitPoint(point);

            Assert.True(result);
        }
    public void PanCameraToChunk()
    {
        MapChunk currentChunk = mapGenerator.GetChunkAt(skeleton.transform.position);

        if (currentChunk != null)
        {
            cameraManager.MoveTo(currentChunk.transform.position);
        }
    }
Exemple #14
0
        public void TryRemoveExitPointSucceedsOnExitPointMissingTest()
        {
            var chunk = new MapChunk();
            var point = new ExitPoint(Vector2Int.ZeroVector, new Guid());

            var result = chunk.TryRemoveExitPoint(point);

            Assert.True(result);
        }
        static void ChunkGetCoordForMiddlePoint(MapChunk c, int row, int col,
                                                out float x, out float y, out float z)
        {
            int off = (9 + (row * 17 + col)) * 3;

            x = ChunkReader.ZEROPOINT - c.vertices[off + 2];
            y = ChunkReader.ZEROPOINT - c.vertices[off];
            z = c.vertices[off + 1];
        }
Exemple #16
0
        public MCAL(MapChunk chunk, WDT wdt, Chunk c) : base(c, false)
        {
            Debug.Assert(wdt != null, "WDT Cannot be null in order to read MCAL!");

            _mapChunk = chunk;
            _wdt      = wdt;

            Read();
        }
Exemple #17
0
        public void TryRemoveSpawnPointSucceedsOnSpawnPointMissingTest()
        {
            var chunk = new MapChunk();
            var point = new SpawnPoint(Vector2Int.ZeroVector, SpawnType.Player);

            var result = chunk.TryRemoveSpawnPoint(point);

            Assert.True(result);
        }
Exemple #18
0
    public Vector2 GetChunkIndex(MapChunk chunk)
    {
        int   chunkCols = (int)Mathf.Ceil((MapWidth / HorizontalSpacing) / (ChunkWidth));
        int   chunkRows = (int)Mathf.Ceil((MapHeight / VerticalSpacing) / ChunkHeight);
        int   index     = honeycombChunks.IndexOf(chunk);
        float x         = index % (chunkCols);
        float y         = index / (chunkCols);

        return(new Vector2(x, y));
    }
    public static void Dirty(MapChunk chunk)
    {
        if (dirtyList.Contains(chunk))
        {
            return;
        }

        dirtyList.Add(chunk);
        dirtyChunks = true;
    }
Exemple #20
0
 public static void AnnounceMapChunkLoaded(MapChunk chunk)
 {
     for (int i = 0; i < s_RegisteredMultis.Count; i++)
     {
         if (!s_RegisteredMultis[i].IsDisposed)
         {
             s_RegisteredMultis[i].PlaceTilesIntoNewlyLoadedChunk(chunk);
         }
     }
 }
 public void SetMapChunk(MapChunk mapChunk)
 {
     x               = mapChunk._x;
     y               = mapChunk._y;
     tier            = mapChunk._tier;
     _mapWealth      = mapChunk._mapWealth;
     _mapBiodome     = mapChunk._mapBiodome;
     _mapSize        = mapChunk._mapSize;
     _mapOrientation = mapChunk._mapOrientation;
 }
Exemple #22
0
    public MapChunk CreateChunk(int x, int y)
    {
        MapChunk chunk = new MapChunk(x, y, map);

        chunkPointers.Add(chunk.pos);
        mapChunks.Add(chunk);

        chunk.gameobject.transform.parent        = mapChunksGameObject.transform;
        chunk.gameobject.transform.localPosition = new Vector3(x * map.chunkSize, y * map.chunkSize, 0);
        return(chunk);
    }
Exemple #23
0
        public void GetAllParquetsReturnsNullsOnEmptyMapTest()
        {
            var chunk = new MapChunk();

            var parquetStack = chunk.GetAllParquetsAtPosition(Vector2Int.ZeroVector);

            Assert.Null(parquetStack.Floor);
            Assert.Null(parquetStack.Block);
            Assert.Null(parquetStack.Furnishing);
            Assert.Null(parquetStack.Collectible);
        }
Exemple #24
0
    public MapHoneycomb GetHoneycomb(int col, int row)
    {
        int      xChunk = col / ChunkWidth;
        int      yChunk = row / (ChunkHeight / 2);
        MapChunk chunk  = GetChunk(xChunk, yChunk);

        col = col % ChunkWidth;
        row = row % (ChunkHeight / 2);

        return(chunk.GetMapHoneycomb(col, row));
    }
Exemple #25
0
    // internal
    private void TerrainUpdate(Vector3Int centerCell)
    {
        // remove far objects
        List <Vector3Int> removed = new List <Vector3Int>();

        foreach (KeyValuePair <Vector3Int, MapModifier.TileGameObject> entry in modifier.tileObjects)
        {
            if (Mathf.Abs(centerCell.x - entry.Key.x) > streamingCellRadius || Mathf.Abs(centerCell.y - entry.Key.y) > streamingCellRadius)
            {
                removed.Add(entry.Key);
            }
        }
        foreach (Vector3Int cell in removed)
        {
            MapModifier.JobModifier job = new MapModifier.JobModifier();
            job.jobType      = MapModifier.JobType.RemoveTile;
            job.cellPosition = cell;
            modifier.jobs.Enqueue(job);
        }

        // create new tiles
        for (int x = centerCell.x - streamingCellRadius; x < centerCell.x + streamingCellRadius; x++)
        {
            for (int z = centerCell.y - streamingCellRadius; z < centerCell.y + streamingCellRadius; z++)
            {
                Vector3Int cellPosition = new Vector3Int(x, z, (int)modifier.tilemap.transform.position.y);
                if (modifier.tilemap.HasTile(cellPosition) && !modifier.tileObjects.ContainsKey(cellPosition))
                {
                    MapModifier.JobModifier job = new MapModifier.JobModifier();
                    job.jobType      = MapModifier.JobType.PlaceTile;
                    job.cellPosition = cellPosition;
                    job.tile         = modifier.tilemap.GetTile <ScriptableTile>(cellPosition);
                    modifier.jobs.Enqueue(job);
                }
            }
        }

        // update grid chunks visibility
        int radius = (int)(streamingCellRadius + MapChunk.chunkSize / modifier.tilemap.layoutGrid.cellSize.x);

        foreach (KeyValuePair <Vector2Int, MapChunk> entry in modifier.grid.grid)
        {
            Vector3Int chunkCellPos = modifier.tilemap.WorldToCell(MapChunk.CellToWorld(entry.Key));

            if (Mathf.Abs(centerCell.x - chunkCellPos.x) > radius || Mathf.Abs(centerCell.y - chunkCellPos.y) > radius)
            {
                entry.Value.gameObject.SetActive(false);
            }
            else
            {
                entry.Value.gameObject.SetActive(true);
            }
        }
    }
Exemple #26
0
 public void MakeObjectInteractable(GameObject obj)
 {
     if (obj)
     {
         Vector2Int cell = MapChunk.WorldToCell(obj.transform.position);
         if (grid.ContainsKey(cell))
         {
             grid[cell].RemoveFromBatching(obj);
         }
     }
 }
Exemple #27
0
 //public HoneycombCell honeyGrid;
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.CompareTag("Player"))
     {
         Insect   insect = Instantiate(transform.parent.GetComponent <HoneycombCell>().honeyGrid.GetEnemyPrefab(), transform.position, Quaternion.identity).GetComponent <Insect>();
         MapChunk chunk  = Utility.GetMapChunk(insect.transform.position);
         chunk.AddEnemyToChunk(insect);
         insect.InsectPrefab = transform.parent.GetComponent <HoneycombCell>().honeyGrid.GetEnemyPrefab();
         transform.parent.GetComponent <HoneycombCell>().honeyGrid.DestroyHoneycomb();
     }
 }
Exemple #28
0
        public void GetDefinitionReturnsNoneOnInvalidPositionTest()
        {
            var chunk = new MapChunk().FillTestPattern();

            var result = chunk.GetDefinitionAtPosition(invalidPosition);

            Assert.Equal(EntityID.None, result.Floor);
            Assert.Equal(EntityID.None, result.Block);
            Assert.Equal(EntityID.None, result.Furnishing);
            Assert.Equal(EntityID.None, result.Collectible);
        }
Exemple #29
0
        public void GetDefinitionReturnsNoneOnEmptyMapTest()
        {
            var chunk = new MapChunk();

            var result = chunk.GetDefinitionAtPosition(Vector2Int.ZeroVector);

            Assert.Equal(EntityID.None, result.Floor);
            Assert.Equal(EntityID.None, result.Block);
            Assert.Equal(EntityID.None, result.Furnishing);
            Assert.Equal(EntityID.None, result.Collectible);
        }
Exemple #30
0
        public void GetAllParquetsReturnsNullsOnInvalidPositionTest()
        {
            var chunk = new MapChunk().FillTestPattern();

            var parquetStack = chunk.GetAllParquetsAtPosition(invalidPosition);

            Assert.Null(parquetStack.Floor);
            Assert.Null(parquetStack.Block);
            Assert.Null(parquetStack.Furnishing);
            Assert.Null(parquetStack.Collectible);
        }
    private MapChunk getRandomChunkWithTrap(MapChunk[] mapChunks)
    {
        MapChunk current = null;

        while (current == null || !current.isTrap)
        {
            int idx = UnityEngine.Random.Range(0, mapChunks.Length);
            current = mapChunks[idx];
        }

        return(current);
    }
Exemple #32
0
    // Use this for initialization
    void Start()
    {
        //TODO: eventually we probably want to not pull in entire map...or maybe we do if its only ints...
        //depends a lot on whether we end up making each tile a full object...if so than loading could be
        //costly in terms of time and/or memory
        //tiles go from left to right horizontally and from the bottom up vertically (0,0) is lower left corner
        gamemap = new HexMap(mapsize_x, mapsize_y);
        ////just setting some tiles for testing
        //gamemap.SetTile(0, 0, 1);
        //gamemap.SetTile(1, 0, 1);
        //gamemap.SetTile(0, 1, 1);
        //gamemap.SetTile(1, 1, 1);
        //gamemap.SetTile(1, 2, 1);
        //gamemap.SetTile(2, 0, 1);
        ////gamemap.SetTile(0, 1, 2);
        ////gamemap.SetTile(1, 1, 3);
        //gamemap.SetTile(5, 5, 3);
        //gamemap.SetTile(5, 10, 2);
        //gamemap.SetTile(16, 8, 2);
        int[,] maptiles = GameController.instance.mapLoader.GetMapTiles();
        gamemap.SetTiles(maptiles);

        //build and fill the tileUV data structure for our texture atlas
        tileuvs = buildTileUVs();

        //meshes can be a max size of 65535 verts
        //so doing a little math 65535/7 ~ 9362 which means chunksize_x * chunksize_y cant be greater than 9362
        //check and throw an error if so
        if (chunksize_x * chunksize_y > 9362)
        {
            throw new System.Exception("chunksize too big");
        }
        //TODO: eventually we probably will want to build out chunks just around where player is viewing
        //dynamically adding and removing meshes as we scroll around...but for now this is sufficient
        //next we need to build out meshes based on the chunk size...so iterate through
        //chunks building meshes for each as we go first get number of chunks
        int numchunks_x = mapsize_x / chunksize_x;
        int numchunks_y = mapsize_y / chunksize_y;

        //allocate array of mapchunks
        gamemapchunks = new MapChunk[numchunks_x, numchunks_y];
        for (int y = 0; y < numchunks_y; y++)
        {
            for (int x = 0; x < numchunks_x; x++)
            {
                MapChunk chunk = Instantiate(chunkprefab);
                chunk.name = "GameMapChunk[" + x + ", " + y + "]";
                chunk.BuildMesh(x, y, chunksize_x, chunksize_y, this);
                gamemapchunks[x, y] = chunk;
                chunk.transform.SetParent(this.transform);
            }
        }
    }
Exemple #33
0
        public void ProcessMapChunk(MapChunk chunk)
        {
            if (!Source.HasObjectData)
                return;

            // f**k it blizzard, why is this crap necessary?
            var firstIndex = Source.ObjectData.GetFirstIndex("MCNK");
            if (firstIndex == -1)
                return;
            if (firstIndex + chunk.Index > Source.ObjectData.Chunks.Count)
                return;
            var ourChunk = Source.ObjectData.Chunks[firstIndex + chunk.Index];
            if (ourChunk.Length == 0)
                return;
            var subChunks = new ChunkedData(ourChunk.GetStream(), (int)ourChunk.Length, 2);
            ProcessInternal(subChunks);
        }
Exemple #34
0
 static void ChunkGetCoordForPoint(MapChunk c, int row, int col,
     out float x, out float y, out float z)
 {
     int off = (row * 17 + col) * 3;
     x = ChunkReader.ZEROPOINT - c.vertices[off + 2];
     y = ChunkReader.ZEROPOINT - c.vertices[off];
     z = c.vertices[off + 1];
 }
	/// <summary>
	///Creates a new map, and adds the first chunk. 
	/// </summary>
	/// <param name="mapName">
	/// The name of this map
	/// </param>
	/// <param name="chunkPrefab">
	/// The prefab from which to create a 'chunk'
	/// </param>
	public void Editor_InitializeMap(string mapName, MapChunk chunkPrefab){
		
		this.name = mapName;	
				
		Editor_AddChunkAt(0,0,0,chunkPrefab,false);
				
	}
	/// <summary>
	///Initializes the chunk at the specified coordinates - populating it with blocks and adding chunks surrounding it 
	/// </summary>
	/// <param name="x">
	/// The x coordinate of the target chunk
	/// </param>
	/// <param name="y">
	/// The y coordinate of the target chunk
	/// </param>
	/// <param name="blocks">
	/// An array of instantiated blocks with which to populate the chunk
	/// </param>
	/// <param name="chunkPrefab">
	/// The prefab from which to spawn surrounding chunks
	/// </param>
	public void Editor_InitializeChunkAt(int x, int y, int depth, Block[] blocks, MapChunk chunkPrefab){
			
		if(HasChunkAt(x,y,depth)){
						
			MapChunk chunk = GetChunkAt(x,y,depth,false);
			
			chunk.Editor_InitializeChunk(blocks);
			
			chunk.BindAllBlocksToMap();
			
			for(int x1 = -1; x1 <= 1; x1++){
				for(int y1 = -1; y1 <= 1; y1++){
									
					int x_coord = chunk.x + x1;
					int y_coord = chunk.y + y1;
					
					if(!HasChunkAt(x_coord,y_coord,depth)){
						
						Editor_AddChunkAt(x_coord,y_coord,depth,chunkPrefab,false);
						
						//look around this chunk
						//if it is above or below an already-initialized chunk
						//initialize it and bind the transforms to that chunk
						
					}
				}	
			}
		}
		
	}
	public void Editor_AddChunkAt(int x, int y, int depth, MapChunk chunkPrefab, bool placeAbsolute){
						
		ChunkSet cs = GetNodeAt(x,y);
				
		if(depth > mapUpperDepth){
			mapUpperDepth = depth;
		}
		
		if(depth < mapLowerDepth){
			mapLowerDepth = depth;
		}
		
		MapChunk mc = null;
		
		if(cs == null){
			cs = new ChunkSet();
			
			cs.InitializeChunkSet(this,x,y);
			
			AddNodeAt(cs,x,y);
			
			mc = GameObject.Instantiate(chunkPrefab) as MapChunk;
			
			mc.name = "MapChunk_"+x+"_"+y;
						
			cs.AddChunkAt(mc,depth);
			
			mc.Editor_Activate(chunkWidth,chunkHeight,cs.x,cs.y,depth,this,placeAbsolute);
						
			return;
		}
		else{
			
			if(cs.x != x){
				cs.x = x;
			}
			
			if(cs.y != y){
				cs.y = y;
			}
			
		}
				
		if(cs.GetChunkAt(depth,false) != null){
									
			return;
		}
		
		mc = GameObject.Instantiate(chunkPrefab) as MapChunk;
			
		mc.name = "MapChunk_"+x+"_"+y;
			
		//at this point we want to do a different activation, as the chunkset already exists
		//and this is therefore at a different depth
		cs.AddChunkAt(mc,depth);
		
		int upper = depth+1;
		int lower = depth-1;
		
		MapChunk u = cs.GetChunkAt(upper,false);
		MapChunk l = cs.GetChunkAt(lower,false);
				
		if(u != null){
			
			mc.Editor_ActivateBound(chunkWidth,chunkHeight,cs.x,cs.y,depth,this,u);
			
		}
		else if(l != null){
			
			mc.Editor_ActivateBound(chunkWidth,chunkHeight,cs.x,cs.y,depth,this,l);
			
		}
		else{
			
			mc.Editor_Activate(chunkWidth,chunkHeight,cs.x,cs.y,depth,this,placeAbsolute);
		}
				
	}
        static void InitializeToolkitPrefabs()
        {
            GameObject chunkObject = AssetDatabase.LoadAssetAtPath("Assets/"+prefabPath+"/"+mapChunkPrefabName,typeof(GameObject)) as GameObject;
            if(chunkObject == null){

                Debug.LogWarning("No MapChunk prefab found. You will not be able to create maps.");

            }
            else{

                mapChunkPrefab = chunkObject.GetComponent<MapChunk>();

                if(mapChunkPrefab == null){

                    Debug.LogWarning("No MapChunk component found on MapChunk prefab. You will not be able to create maps.");

                }
            }

            //First, add the null block
            GameObject nullBlockObject = AssetDatabase.LoadAssetAtPath("Assets/"+coreBlockPath+"/"+nullBlockName+".prefab",typeof(GameObject)) as GameObject;

            if(nullBlockObject == null){
                Debug.LogWarning("No empty block found at: " +"Assets/"+coreBlockPath+"/"+nullBlockName+".prefab - This is mandatory for a healthy, happy Tidy TileMapper!");
            }
            else{
                nullBlockPrefab = nullBlockObject.GetComponent<Block>();

                if(nullBlockPrefab == null){
                    Debug.LogWarning("No Block script found on empty block. This is required!");
                }

            }
        }
Exemple #39
0
        private void InitChunks()
        {
            var minPos = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            var maxPos = new Vector3(float.MinValue, float.MinValue, float.MinValue);

            var modelMin = new Vector3(float.MaxValue);
            var modelMax = new Vector3(float.MinValue);

            for (var i = 0; i < 256; ++i)
            {
                var chunk = new MapChunk(mMainChunks[i], mTexChunks[i], mObjChunks[i], i % 16, i / 16, this);
                chunk.AsyncLoad();
                var bbmin = chunk.BoundingBox.Minimum;
                var bbmax = chunk.BoundingBox.Maximum;
                if (bbmin.X < minPos.X)
                    minPos.X = bbmin.X;
                if (bbmax.X > maxPos.X)
                    maxPos.X = bbmax.X;
                if (bbmin.Y < minPos.Y)
                    minPos.Y = bbmin.Y;
                if (bbmax.Y > maxPos.Y)
                    maxPos.Y = bbmax.Y;
                if (bbmin.Z < minPos.Z)
                    minPos.Z = bbmin.Z;
                if (bbmax.Z > maxPos.Z)
                    maxPos.Z = bbmax.Z;

                bbmin = chunk.ModelBox.Minimum;
                bbmax = chunk.ModelBox.Maximum;
                if (bbmin.X < modelMin.X)
                    modelMin.X = bbmin.X;
                if (bbmax.X > modelMax.X)
                    modelMax.X = bbmax.X;
                if (bbmin.Y < modelMin.Y)
                    modelMin.Y = bbmin.Y;
                if (bbmax.Y > modelMax.Y)
                    modelMax.Y = bbmax.Y;
                if (bbmin.Z < modelMin.Z)
                    modelMin.Z = bbmin.Z;
                if (bbmax.Z > modelMax.Z)
                    modelMax.Z = bbmax.Z;

                mChunks.Add(chunk);
                Array.Copy(chunk.Vertices, 0, FullVertices, i * 145, 145);
            }

            BoundingBox = new BoundingBox(minPos, maxPos);
            ModelBox = new BoundingBox(modelMin, modelMax);
        }
Exemple #40
0
        public void UpdateVertices(MapChunk chunk)
        {
            if (chunk == null)
                return;

            var ix = chunk.IndexX;
            var iy = chunk.IndexY;

            var index = (ix + iy * 16) * 145;
            for (var i = 0; i < 145; ++i)
                FullVertices[i + index] = chunk.Vertices[i];
        }
			public MapChunkEntry(MapChunk chunk, int depth){
				this.chunk = chunk;
				this.depth = depth;
			}
		void CheckMouseOver(){
			
			Ray worldRay = HandleUtility.GUIPointToWorldRay (Event.current.mousePosition);
			
			mouseoverBlock = null;
			mouseoverChunk = null;
			
			//Note to the viewer: I don't like doing this, I would prefer to use layers
			//But in the absence of an API method for adding layers programmatically, this (to me)
			//is a preferable choice to adding a setup step:
			//Step One) add a layer named y
			RaycastHit[] hits = Physics.RaycastAll(worldRay);
			
			if(hits != null){
					
				float dist = float.MaxValue;
				
				MapChunk closest_mc = null;
				Block closest_b = null;
				
				for(int i = 0; i < hits.Length; i++){
					
					MapChunk mc = hits[i].collider.gameObject.GetComponent<MapChunk>();
					
					
					if(mc != null){
						
						if(!IsLayerUnlocked(mc)){
							continue;
						}
						
						if(hits[i].distance < dist){
							closest_mc = mc;
							closest_b = null;
							dist = hits[i].distance;
						}
						
						continue;
					}
						
					Block b = hits[i].collider.gameObject.GetComponent<Block>();
						
					if(b != null){
									
						if(!IsLayerUnlocked(b)){
							continue;
						}
						
						if(hits[i].distance < dist){
							closest_b = b;
							closest_mc = null;
							dist = hits[i].distance;
						}
					}
				}
				
				if(closest_mc != null){
					
					mouseoverChunk = closest_mc;
					
				}
				else
				if(closest_b != null){
					
					mouseoverBlock = closest_b;
					
				}
				
			}
						
		}
		void AddLayerChunk(MapChunk chunk, int direction){
			
			if(!canAct){
				return;
			}
			
			HasActed();
			
			//Debug.Log(chunk);
			
			int depth = chunk.depth + direction;
			
			//Debug.Log("Adding chunk at: " + depth);
			
			chunk.parentMap.Editor_AddChunkAt(chunk.x,chunk.y,depth,TidyEditorUtility.GetMapChunkPrefab(),false);
			
			MapChunk c = chunk.parentMap.GetChunkAt(chunk.x,chunk.y,depth,false);
			
			EditorUtility.SetDirty(c);
			EditorUtility.SetDirty(chunk.parentMap);
			
			RefreshExistentBlockMaps();
			
		}
		void DeleteChunk(MapChunk targetChunk){
			
			if(!targetChunk.Editor_IsInitialized()){
				
				targetChunk.parentMap.RemoveChunkAt(targetChunk.x,targetChunk.y, targetChunk.depth);
				
				SetEntireMapDirty(targetChunk.parentMap);
				
				Editor.DestroyImmediate(targetChunk.gameObject);
			}
			
		}
Exemple #45
0
    public void Editor_ActivateBound(int width, int height, int x, int y, int depth, BlockMap parentMap, MapChunk boundChunk)
    {
        this.parentMap = parentMap;
        this.width = width;
        this.height = height;

        this.x = x;
        this.y = y;
        this.depth = depth;

        int chunkDiff = depth - boundChunk.depth;

        float heightOffset = 0.0f;

        if(chunkDiff == 1){
            //above
            heightOffset = parentMap.tileScale.z;

        }
        else if(chunkDiff == -1){
            //below
            heightOffset = -parentMap.tileScale.z;
        }
        else{
            Debug.LogWarning("Chunk depth difference inconsistent! Aneurysm imminent!");
        }

        transform.parent = parentMap.transform;

        Vector3 pos = Vector3.zero;

        if(parentMap.growthAxis == BlockMap.GrowthAxis.Up){

            pos = new Vector3(
                                      boundChunk.transform.localPosition.x,
                                      boundChunk.transform.localPosition.y,
                                      boundChunk.transform.localPosition.z + heightOffset
                                      );

            transform.localRotation = Quaternion.identity;

        }
        else if(parentMap.growthAxis == BlockMap.GrowthAxis.Forward ){

            pos = new Vector3(
                                      boundChunk.transform.localPosition.x,
                              		  boundChunk.transform.localPosition.y + heightOffset,
                                      boundChunk.transform.localPosition.z
                                      );

            transform.localRotation = Quaternion.Euler(
                                                       new Vector3(
                                                                   90.0f,
                                                                   0.0f,
                                                                   0.0f
                                                                   ));

        }

        transform.localPosition = pos;

        transform.localScale = new Vector3(
                                                       parentMap.tileScale.x * width,
                                                       parentMap.tileScale.y * height,
                                                       parentMap.tileScale.z
                                                       );
    }
        private static void DoSerialize(BigMap map, TileSet tileset, bool IncludeTileset, Stream destination)
        {
            SerializedMap result = new SerializedMap();
            Dictionary<Tile, int> tileLookup = new Dictionary<Tile, int>();
            if (tileset != null)
            {
                result.TileHeight = tileset.TileHeight;
                result.TileWidth = tileset.TileWidth;

                foreach (Tile tile in tileset.Tiles)
                {
                    if (IncludeTileset)
                    {
                        result.Tiles.Add(SaveImage(tile.FullImage));
                    }
                    tileLookup.Add(tile, tileLookup.Count);
                }
            }
            else
            { result.Tiles = null; }
            foreach (var layer in map.Layers)
            {
                Rectangle r = layer.ImageBounds;
                MapChunk chunk = new MapChunk();
                chunk.X = r.Left;
                chunk.Y = r.Top; ;
                chunk.Width = r.Width;
                chunk.Height = r.Height;
                for (int x = r.Left; x < r.Right; x++)
                {
                    for (int y = r.Top; y < r.Bottom; y++)
                    {
                        Tile tile = layer[x, y];
                        int index = -1;
                        if (tile != null)
                        {
                            if (!tileLookup.TryGetValue(tile, out index))
                            {
                                index = tileLookup.Count;
                                tileLookup.Add(tile, index);
                            }
                        }
                        chunk.Data.Add(index);
                    }
                }
                MapLayer serializedLayer = new MapLayer();
                serializedLayer.Visible = layer.Visible;
                serializedLayer.IsWall = layer.IsWall;
                serializedLayer.Chunks.Add(chunk);
                result.Layers.Add(serializedLayer);
            }
            Serializer.Serialize(destination, result);
        }
		bool IsLayerUnlocked(MapChunk chunk){
				
			if(!mapUnlockAll.ContainsKey(chunk.parentMap.name)){
				mapUnlockAll.Add(chunk.parentMap.name,true);
			}
			
			if(mapUnlockAll[chunk.parentMap.name]){
				return true;
			}
			
			if(mapLayerLock.ContainsKey(chunk.parentMap.name + "_" + chunk.depth)){
				return mapLayerLock[chunk.parentMap.name + "_" + chunk.depth];
			}
			
			return false;
		}
Exemple #48
0
        void AddTriangles(TriangleCollection s, MapChunk c)
        {
            int[,] vertices = new int[9, 9];
            int[,] verticesMid = new int[8, 8];

            for (int row = 0; row < 9; row++)
                for (int col = 0; col < 9; col++)
                {
                    float x, y, z;
                    ChunkGetCoordForPoint(c, row, col, out x, out y, out z);
                    int index = s.AddVertex(x, y, z);
                    vertices[row, col] = index;
                }

            for (int row = 0; row < 8; row++)
                for (int col = 0; col < 8; col++)
                {
                    float x, y, z;
                    ChunkGetCoordForMiddlePoint(c, row, col, out x, out y, out z);
                    int index = s.AddVertex(x, y, z);
                    verticesMid[row, col] = index;
                }
            for (int row = 0; row < 8; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    if (!c.isHole(col, row))
                    {
                        int v0 = vertices[row, col];
                        int v1 = vertices[row + 1, col];
                        int v2 = vertices[row + 1, col + 1];
                        int v3 = vertices[row, col + 1];
                        int vMid = verticesMid[row, col];

                        s.AddTriangle(v0, v1, vMid);
                        s.AddTriangle(v1, v2, vMid);
                        s.AddTriangle(v2, v3, vMid);
                        s.AddTriangle(v3, v0, vMid);

                    }
                }
            }

            if (c.haswater)
            {
                // paint the water
                for (int row = 0; row < 9; row++)
                    for (int col = 0; col < 9; col++)
                    {
                        float x, y, z;
                        ChunkGetCoordForPoint(c, row, col, out x, out y, out z);
                        float height = c.water_height[row, col] - 1.5f;
                        int index = s.AddVertex(x, y, height);
                        vertices[row, col] = index;
                    }
                for (int row = 0; row < 8; row++)
                {
                    for (int col = 0; col < 8; col++)
                    {
                        if (c.water_flags[row, col] != 0xf)
                        {
                            int v0 = vertices[row, col];
                            int v1 = vertices[row + 1, col];
                            int v2 = vertices[row + 1, col + 1];
                            int v3 = vertices[row, col + 1];

                            s.AddTriangle(v0, v1, v3, ChunkedTriangleCollection.TriangleFlagDeepWater);
                            s.AddTriangle(v1, v2, v3, ChunkedTriangleCollection.TriangleFlagDeepWater);
                        }
                    }
                }
            }
        }