Skip to content
This repository was archived by the owner on Mar 16, 2023. It is now read-only.

Commit 259d843

Browse files
committed
Fixed POI generation across multiple chunks vertically
1 parent 1bb23d9 commit 259d843

File tree

5 files changed

+53
-37
lines changed

5 files changed

+53
-37
lines changed

Assets/Scripts/Generation/Column.cs

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -96,46 +96,56 @@ public void GeneratePOIBlocks()
9696
for(int z = 0; z < chunkSize; z++)
9797
{
9898

99-
if(walls)
100-
{
101-
if(POIWalls[x,z] == 0) continue;
99+
if(!walls || POIWalls[x,z] == 0) continue;
102100

103-
int ly = LocalY(heightMap[x,z]);
101+
int ly = LocalY(heightMap[x,z]);
104102

105-
if(currentChunk == null)
106-
{
107-
int chunkY = Mathf.FloorToInt(heightMap[x,z] / chunkSize) * chunkSize;
108-
currentChunk = World.chunks[new Vector3(position.x, chunkY, position.z)];
109-
}
103+
// Get starting chunk
104+
int chunkY = Mathf.FloorToInt(heightMap[x,z] / chunkSize) * chunkSize;
105+
currentChunk = World.chunks[new Vector3(position.x, chunkY, position.z)];
110106

111-
Chunk newChunk = null;
112-
if(BlockOwnerChunk(new Vector3(x,ly,z), currentChunk, out newChunk))
107+
// Handle POI with different heights at different points
108+
Chunk newChunk = null;
109+
if(BlockOwnerChunk(new Vector3(x,ly,z), currentChunk, out newChunk))
110+
{
111+
currentChunk = newChunk;
112+
allAlteredChunks.Add(newChunk);
113+
if(currentChunk.composition != Chunk.Composition.MIX) currentChunk.composition = Chunk.Composition.MIX;
114+
}
115+
116+
int iterationReset = 0;
117+
118+
for(int i = 0; i < POIType.wallHeight; i++)
119+
{
120+
int y = (ly + i) - iterationReset;
121+
122+
// Iteration has moved out of current chunk
123+
if(y > 15)
113124
{
114-
currentChunk = newChunk;
115-
allAlteredChunks.Add(newChunk);
125+
bool gotChunk = BlockOwnerChunk(new Vector3(x,y,z), currentChunk, out currentChunk);
126+
if(currentChunk.composition != Chunk.Composition.MIX) currentChunk.composition = Chunk.Composition.MIX;
127+
128+
// Offset i to zero for new chunk
129+
iterationReset = i;
130+
// Local y to zero for new chunk
131+
ly = 0;
132+
// New y value for new chunk
133+
y = (ly + i) - iterationReset;
116134
}
117-
135+
118136
switch(POIWalls[x,z])
119137
{
120138
case 1:
121-
for(int i = 0; i < POIType.wallHeight; i++)
122-
{
123-
int y = ly + i;
124-
if(y > 15) continue; // DEBUG !!!kS
125-
currentChunk.blockTypes[x,y,z] = Blocks.Types.STONE;
126-
if(!hasBlocks) hasBlocks = true;
127-
}
139+
//if(y > 15 || y < 0) continue; // DEBUG !!!kS
140+
currentChunk.blockTypes[x,y,z] = Blocks.Types.STONE;
141+
if(!hasBlocks) hasBlocks = true;
128142
break;
129143

130144
case 2:
131-
for(int i = 0; i < POIType.wallHeight; i++)
132-
{
133-
if(i<3) continue;
134-
int y = ly + i;
135-
if(y > 15) continue; // DEBUG !!!kS
136-
currentChunk.blockTypes[x,y,z] = Blocks.Types.STONE;
137-
if(!hasBlocks) hasBlocks = true;
138-
}
145+
if(i<3) continue;
146+
//if(y > 15 || y < 0) continue; // DEBUG !!!kS
147+
currentChunk.blockTypes[x,y,z] = Blocks.Types.STONE;
148+
if(!hasBlocks) hasBlocks = true;
139149
break;
140150

141151
default:
@@ -231,7 +241,7 @@ bool BlockOwnerColumn(Vector3 pos, out Column column)
231241
if (pos.z < 0) z = -1;
232242
else if (pos.z > World.chunkSize-1) z = 1;
233243

234-
// Voxel is in this chunk
244+
// Voxel is in this column
235245
if(x == 0 && z == 0)
236246
{
237247
column = null;
@@ -269,8 +279,6 @@ bool BlockOwnerChunk(Vector3 pos, Chunk currentChunk, out Chunk chunk)
269279
// The edge
270280
Vector3 edge = new Vector3(x, y, z);
271281

272-
Debug.Log(currentChunk.position + (edge * World.chunkSize));
273-
274282
chunk = World.chunks[currentChunk.position + (edge * World.chunkSize)];
275283
return true;
276284
}

Assets/Scripts/Generation/POI/BuildingGenerator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public BuildingGenerator(Zone zone)
7171
// Randomise seed for debugging
7272
//int seed = Random.Range(0,10000);
7373
//Debug.Log("SEED: "+ seed);
74-
noiseGen.SetSeed(9099);
74+
noiseGen.SetSeed(9770);
7575

7676

7777
// Base noise generated from POI position
@@ -351,7 +351,6 @@ void GenerateRooms(Wing wing, Wing? connectedWing = null, int connectionIndex =
351351
// Split with corridors of decreasing size
352352
for(int i = 0; i < corridorIterations; i++)
353353
{
354-
Debug.Log("iterating");
355354
corridorWidth -= 2;
356355
corridorWidth = corridorWidth < 5 ? 5 : corridorWidth;
357356
roomsCopy = new List<Room>(wing.rooms);
@@ -771,6 +770,9 @@ void SetColumnMaps(POILibrary.POI poi)
771770
column.POIHeightGradient[cx,cz] = zone.heightMatrix[mx,mz];
772771
column.POIDebug[cx,cz] = zone.debugMatrix[mx,mz];
773772
column.POIWalls[cx,cz] = zone.wallMatrix[mx,mz];
773+
774+
//int POIheight = column.heightMap[cx,cz] + poi.wallHeight;
775+
//if(POIheight > column.highestPoint) column.highestPoint = POIheight;
774776
}
775777
}
776778
}

Assets/Scripts/Generation/POI/POILibrary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class POILibrary
88

99
public class POI
1010
{
11-
public int wallHeight = 5;
11+
public int wallHeight = 10;
1212

1313
public void GenerateMatrixes(BuildingGenerator buildingGenerator, Zone zone)
1414
{

Assets/Scripts/Generation/TerrainGenerator.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,24 @@ public void GetTopologyData(Column column)
157157
finalTopology = currentTolopogy;
158158
}
159159

160+
int POIheight = 0;
161+
160162
// Where points of interest exist, flatten terrain
161163
if(column.POIHeightGradient != null && column.POIHeightGradient[x,z] != 0)
162164
{
163165
float interpValue = (float)column.POIHeightGradient[x,z] / chunkSize;
164166
Topology POITopology = new Topology(0.5f, finalTopology.height, 0.5f);
165167
finalTopology = SmoothToPOI(POITopology, finalTopology, interpValue);
168+
169+
// Adjust heighest point
170+
POIheight = column.POIType.wallHeight;
166171
}
167172

168173
// Generate final height value for chunk data
169174
column.heightMap[x,z] = (int)Mathf.Lerp(0, finalTopology.height, finalTopology.baseNoise * finalTopology.noise);
170175

171176
// Update highest and lowest block in chunk column
172-
column.CheckHighest(column.heightMap[x,z]);
177+
column.CheckHighest(column.heightMap[x,z] + POIheight);
173178
column.CheckLowest(column.heightMap[x,z]);
174179
}
175180
}

Assets/Scripts/Generation/World.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ bool GetColumnSize(Vector3 position)
357357
//debug.OutlineChunk(new Vector3(position.x, column.topChunkGenerate, position.z), Color.black, removePrevious: false, sizeDivision: 2f);
358358
//debug.OutlineChunk(new Vector3(position.x, column.bottomChunkGenerate, position.z), Color.blue, removePrevious: false, sizeDivision: 2f);
359359

360-
//debug.OutlineChunk(new Vector3(position.x, column.topChunkDraw, position.z), Color.red, removePrevious: false, sizeDivision: 3f);
360+
//debug.OutlineChunk(new Vector3(position.x, column.topChunkDraw, position.z), Color.white, removePrevious: false, sizeDivision: 3f);
361361
//debug.OutlineChunk(new Vector3(position.x, column.bottomChunkDraw, position.z), Color.red, removePrevious: false, sizeDivision: 3f);
362362

363363
column.sizeCalculated = true;
@@ -426,6 +426,7 @@ void GenerateChunk(Vector3 position)
426426
Chunk chunk = chunks[position];
427427

428428
if(chunk.status == Chunk.Status.GENERATED) return;
429+
//debug.OutlineChunk(new Vector3(position.x, position.y, position.z), Color.white, sizeDivision: 3.5f); // // //
429430

430431
chunk.GenerateBlocks();
431432
}

0 commit comments

Comments
 (0)