Skip to content
Permalink
Browse files

Tidy up Builder.c a bit

  • Loading branch information
UnknownShadow200 committed Feb 9, 2020
1 parent fc5c746 commit 881e28d844eb0f2b29ae16611c41f0dde1afda90
Showing with 31 additions and 32 deletions.
  1. +31 −32 src/Builder.c
@@ -37,8 +37,8 @@ static int (*Builder_StretchXLiquid)(int countIndex, int x, int y, int z, int ch
static int (*Builder_StretchX)(int countIndex, int x, int y, int z, int chunkIndex, BlockID block, Face face);
static int (*Builder_StretchZ)(int countIndex, int x, int y, int z, int chunkIndex, BlockID block, Face face);
static void (*Builder_RenderBlock)(int countsIndex);
static void (*Builder_PreStretchTiles)(int x1, int y1, int z1);
static void (*Builder_PostStretchTiles)(int x1, int y1, int z1);
static void (*Builder_PreStretchTiles)(void);
static void (*Builder_PostStretchTiles)(void);

/* Contains state for vertices for a portion of a chunk mesh (vertices that are in a 1D atlas) */
struct Builder1DPart {
@@ -84,13 +84,13 @@ static int Builder_TotalVerticesCount(void) {
/*########################################################################################################################*
*----------------------------------------------------Base mesh builder----------------------------------------------------*
*#########################################################################################################################*/
static void Builder_AddSpriteVertices(BlockID block) {
static void AddSpriteVertices(BlockID block) {
int i = Atlas1D_Index(Block_Tex(block, FACE_XMAX));
struct Builder1DPart* part = &Builder_Parts[i];
part->sCount += 4 * 4;
}

static void Builder_AddVertices(BlockID block, Face face) {
static void AddVertices(BlockID block, Face face) {
int baseOffset = (Blocks.Draw[block] == DRAW_TRANSLUCENT) * ATLAS1D_MAX_ATLASES;
int i = Atlas1D_Index(Block_Tex(block, face));
struct Builder1DPart* part = &Builder_Parts[baseOffset + i];
@@ -122,7 +122,7 @@ static void BuildPartVbs(struct ChunkPartInfo* info) {
}
#endif

static void Builder_SetPartInfo(struct Builder1DPart* part, int* offset, struct ChunkPartInfo* info, cc_bool* hasParts) {
static void SetPartInfo(struct Builder1DPart* part, int* offset, struct ChunkPartInfo* info, cc_bool* hasParts) {
int vCount = Builder1DPart_VerticesCount(part);
info->Offset = -1;
if (!vCount) return;
@@ -180,7 +180,7 @@ static void Builder_Stretch(int x1, int y1, int z1) {
/* Sprites can't be stretched, nor can then be they hidden by other blocks. */
/* Note sprites are drawn using DrawSprite and not with any of the DrawXFace. */
if (Blocks.Draw[b] == DRAW_SPRITE) {
Builder_AddSpriteVertices(b);
AddSpriteVertices(b);
continue;
}

@@ -195,7 +195,7 @@ static void Builder_Stretch(int x1, int y1, int z1) {
Builder_Counts[index] = 0;
} else {
count = Builder_StretchZ(index, x, y, z, cIndex, b, FACE_XMIN);
Builder_AddVertices(b, FACE_XMIN);
AddVertices(b, FACE_XMIN);
Builder_Counts[index] = count;
}

@@ -206,7 +206,7 @@ static void Builder_Stretch(int x1, int y1, int z1) {
Builder_Counts[index] = 0;
} else {
count = Builder_StretchZ(index, x, y, z, cIndex, b, FACE_XMAX);
Builder_AddVertices(b, FACE_XMAX);
AddVertices(b, FACE_XMAX);
Builder_Counts[index] = count;
}

@@ -217,7 +217,7 @@ static void Builder_Stretch(int x1, int y1, int z1) {
Builder_Counts[index] = 0;
} else {
count = Builder_StretchX(index, Builder_X, Builder_Y, Builder_Z, cIndex, b, FACE_ZMIN);
Builder_AddVertices(b, FACE_ZMIN);
AddVertices(b, FACE_ZMIN);
Builder_Counts[index] = count;
}

@@ -228,7 +228,7 @@ static void Builder_Stretch(int x1, int y1, int z1) {
Builder_Counts[index] = 0;
} else {
count = Builder_StretchX(index, x, y, z, cIndex, b, FACE_ZMAX);
Builder_AddVertices(b, FACE_ZMAX);
AddVertices(b, FACE_ZMAX);
Builder_Counts[index] = count;
}

@@ -238,7 +238,7 @@ static void Builder_Stretch(int x1, int y1, int z1) {
Builder_Counts[index] = 0;
} else {
count = Builder_StretchX(index, x, y, z, cIndex, b, FACE_YMIN);
Builder_AddVertices(b, FACE_YMIN);
AddVertices(b, FACE_YMIN);
Builder_Counts[index] = count;
}

@@ -248,11 +248,11 @@ static void Builder_Stretch(int x1, int y1, int z1) {
Builder_Counts[index] = 0;
} else if (b < BLOCK_WATER || b > BLOCK_STILL_LAVA) {
count = Builder_StretchX(index, x, y, z, cIndex, b, FACE_YMAX);
Builder_AddVertices(b, FACE_YMAX);
AddVertices(b, FACE_YMAX);
Builder_Counts[index] = count;
} else {
count = Builder_StretchXLiquid(index, x, y, z, cIndex, b);
if (count > 0) Builder_AddVertices(b, FACE_YMAX);
if (count > 0) AddVertices(b, FACE_YMAX);
Builder_Counts[index] = count;
}
}
@@ -349,20 +349,20 @@ static cc_bool ReadBorderChunkData(int x1, int y1, int z1, cc_bool* outAllAir) {
return false;
}

static cc_bool Builder_BuildChunk(int x1, int y1, int z1, cc_bool* allAir) {
static cc_bool BuildChunk(int x1, int y1, int z1, struct ChunkInfo* info) {
BlockID chunk[EXTCHUNK_SIZE_3];
cc_uint8 counts[CHUNK_SIZE_3 * FACE_COUNT];
int bitFlags[EXTCHUNK_SIZE_3];

cc_bool allSolid, onBorder;
cc_bool allAir, allSolid, onBorder;
int xMax, yMax, zMax;
int cIndex, index;
int x, y, z, xx, yy, zz;

Builder_Chunk = chunk;
Builder_Counts = counts;
Builder_BitFlags = bitFlags;
Builder_PreStretchTiles(x1, y1, z1);
Builder_PreStretchTiles();

onBorder =
x1 == 0 || y1 == 0 || z1 == 0 || x1 + CHUNK_SIZE >= World.Width ||
@@ -371,12 +371,13 @@ static cc_bool Builder_BuildChunk(int x1, int y1, int z1, cc_bool* allAir) {
if (onBorder) {
/* less optimal case here */
Mem_Set(chunk, BLOCK_AIR, EXTCHUNK_SIZE_3 * sizeof(BlockID));
allSolid = ReadBorderChunkData(x1, y1, z1, allAir);
allSolid = ReadBorderChunkData(x1, y1, z1, &allAir);
} else {
allSolid = ReadChunkData(x1, y1, z1, allAir);
allSolid = ReadChunkData(x1, y1, z1, &allAir);
}

if (*allAir || allSolid) return false;
info->AllAir = allAir;
if (allAir || allSolid) return false;
Lighting_LightHint(x1 - 1, z1 - 1);

Mem_Set(counts, 1, CHUNK_SIZE_3 * FACE_COUNT);
@@ -386,7 +387,7 @@ static cc_bool Builder_BuildChunk(int x1, int y1, int z1, cc_bool* allAir) {

Builder_ChunkEndX = xMax; Builder_ChunkEndZ = zMax;
Builder_Stretch(x1, y1, z1);
Builder_PostStretchTiles(x1, y1, z1);
Builder_PostStretchTiles();

for (y = y1, yy = 0; y < yMax; y++, yy++) {
for (z = z1, zz = 0; z < zMax; z++, zz++) {
@@ -408,13 +409,11 @@ static cc_bool Builder_BuildChunk(int x1, int y1, int z1, cc_bool* allAir) {

void Builder_MakeChunk(struct ChunkInfo* info) {
int x = info->CentreX - 8, y = info->CentreY - 8, z = info->CentreZ - 8;
cc_bool allAir, hasMesh, hasNorm, hasTran;
cc_bool hasMesh, hasNorm, hasTran;
int totalVerts, partsIndex;
int i, j, curIdx, offset;

allAir = false;
hasMesh = Builder_BuildChunk(x, y, z, &allAir);
info->AllAir = allAir;
hasMesh = BuildChunk(x, y, z, info);
if (!hasMesh) return;

totalVerts = Builder_TotalVerticesCount();
@@ -433,8 +432,8 @@ void Builder_MakeChunk(struct ChunkInfo* info) {
j = i + ATLAS1D_MAX_ATLASES;
curIdx = partsIndex + i * MapRenderer_ChunksCount;

Builder_SetPartInfo(&Builder_Parts[i], &offset, &MapRenderer_PartsNormal[curIdx], &hasNorm);
Builder_SetPartInfo(&Builder_Parts[j], &offset, &MapRenderer_PartsTranslucent[curIdx], &hasTran);
SetPartInfo(&Builder_Parts[i], &offset, &MapRenderer_PartsNormal[curIdx], &hasNorm);
SetPartInfo(&Builder_Parts[j], &offset, &MapRenderer_PartsTranslucent[curIdx], &hasTran);
}

if (hasNorm) {
@@ -460,11 +459,11 @@ static cc_bool Builder_OccludedLiquid(int chunkIndex) {
&& Blocks.Draw[Builder_Chunk[chunkIndex + EXTCHUNK_SIZE]] != DRAW_GAS;
}

static void Builder_DefaultPreStretchTiles(int x1, int y1, int z1) {
static void DefaultPreStretchTiles(void) {
Mem_Set(Builder_Parts, 0, sizeof(Builder_Parts));
}

static void Builder_DefaultPostStretchTiles(int x1, int y1, int z1) {
static void DefaultPostStretchTiles(void) {
int i, j, offset, count;

count = Builder_TotalVerticesCount();
@@ -756,8 +755,8 @@ static void Builder_SetDefault(void) {
Builder_RenderBlock = NULL;

Builder_UseBitFlags = false;
Builder_PreStretchTiles = Builder_DefaultPreStretchTiles;
Builder_PostStretchTiles = Builder_DefaultPostStretchTiles;
Builder_PreStretchTiles = DefaultPreStretchTiles;
Builder_PostStretchTiles = DefaultPostStretchTiles;
}

static void NormalBuilder_SetActive(void) {
@@ -1238,9 +1237,9 @@ static void Adv_RenderBlock(int index) {
if (count_YMax) Adv_DrawYMax(count_YMax);
}

static void Adv_PreStretchTiles(int x1, int y1, int z1) {
static void Adv_PreStretchTiles(void) {
int i;
Builder_DefaultPreStretchTiles(x1, y1, z1);
DefaultPreStretchTiles();
adv_bitFlags = Builder_BitFlags;

for (i = 0; i <= 4; i++) {

0 comments on commit 881e28d

Please sign in to comment.
You can’t perform that action at this time.