mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-10-01 09:49:23 -04:00
Fix memory leak and get rid of redundant Lighting.Color_YMax_Fast function
This commit is contained in:
parent
671f1a36cc
commit
c6c0f525c6
@ -357,7 +357,7 @@ static cc_bool BuildChunk(int x1, int y1, int z1, struct ChunkInfo* info) {
|
|||||||
|
|
||||||
info->AllAir = allAir;
|
info->AllAir = allAir;
|
||||||
if (allAir || allSolid) return false;
|
if (allAir || allSolid) return false;
|
||||||
Lighting.LightHint(x1 - 1, z1 - 1);
|
Lighting.LightHint(x1 - 1, y1 - 1, z1 - 1);
|
||||||
|
|
||||||
Mem_Set(counts, 1, CHUNK_SIZE_3 * FACE_COUNT);
|
Mem_Set(counts, 1, CHUNK_SIZE_3 * FACE_COUNT);
|
||||||
xMax = min(World.Width, x1 + CHUNK_SIZE);
|
xMax = min(World.Width, x1 + CHUNK_SIZE);
|
||||||
@ -555,7 +555,7 @@ static PackedCol Normal_LightColor(int x, int y, int z, Face face, BlockID block
|
|||||||
case FACE_YMIN:
|
case FACE_YMIN:
|
||||||
return Lighting.Color_YMin_Fast(x, y - offset, z);
|
return Lighting.Color_YMin_Fast(x, y - offset, z);
|
||||||
case FACE_YMAX:
|
case FACE_YMAX:
|
||||||
return Lighting.Color_YMax_Fast(x, y + offset, z);
|
return Lighting.Color_Fast(x, y + offset, z);
|
||||||
}
|
}
|
||||||
return 0; /* should never happen */
|
return 0; /* should never happen */
|
||||||
}
|
}
|
||||||
@ -723,7 +723,7 @@ static void NormalBuilder_RenderBlock(int index, int x, int y, int z) {
|
|||||||
offset = (lightFlags >> FACE_YMAX) & 1;
|
offset = (lightFlags >> FACE_YMAX) & 1;
|
||||||
part = &Builder_Parts[baseOffset + Atlas1D_Index(loc)];
|
part = &Builder_Parts[baseOffset + Atlas1D_Index(loc)];
|
||||||
|
|
||||||
col = fullBright ? PACKEDCOL_WHITE : Lighting.Color_YMax_Fast(x, y + offset, z);
|
col = fullBright ? PACKEDCOL_WHITE : Lighting.Color_Fast(x, y + offset, z);
|
||||||
Drawer_YMax(count_YMax, col, loc, &part->fVertices[FACE_YMAX]);
|
Drawer_YMax(count_YMax, col, loc, &part->fVertices[FACE_YMAX]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,6 @@ static void Heightmap_Allocate(void) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*----------------------------------------------------Classic lighting-----------------------------------------------------*
|
*----------------------------------------------------Classic lighting-----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
|
||||||
/* Outside color is same as sunlight color, so we reuse when possible */
|
/* Outside color is same as sunlight color, so we reuse when possible */
|
||||||
static cc_bool ClassicLighting_IsLit(int x, int y, int z) {
|
static cc_bool ClassicLighting_IsLit(int x, int y, int z) {
|
||||||
return y > Heightmap_GetLightHeight(x, z);
|
return y > Heightmap_GetLightHeight(x, z);
|
||||||
@ -219,10 +218,6 @@ static PackedCol ClassicLighting_Color_Fast(int x, int y, int z) {
|
|||||||
return y > heightmap[Heightmap_Pack(x, z)] ? Env.SunCol : Env.ShadowCol;
|
return y > heightmap[Heightmap_Pack(x, z)] ? Env.SunCol : Env.ShadowCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PackedCol ClassicLighting_Color_YMax_Fast(int x, int y, int z) {
|
|
||||||
return y > heightmap[Heightmap_Pack(x, z)] ? Env.SunCol : Env.ShadowCol;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PackedCol ClassicLighting_Color_YMin_Fast(int x, int y, int z) {
|
static PackedCol ClassicLighting_Color_YMin_Fast(int x, int y, int z) {
|
||||||
return y > heightmap[Heightmap_Pack(x, z)] ? Env.SunYMin : Env.ShadowYMin;
|
return y > heightmap[Heightmap_Pack(x, z)] ? Env.SunYMin : Env.ShadowYMin;
|
||||||
}
|
}
|
||||||
@ -235,6 +230,11 @@ static PackedCol ClassicLighting_Color_ZSide_Fast(int x, int y, int z) {
|
|||||||
return y > heightmap[Heightmap_Pack(x, z)] ? Env.SunZSide : Env.ShadowZSide;
|
return y > heightmap[Heightmap_Pack(x, z)] ? Env.SunZSide : Env.ShadowZSide;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ClassicLighting_LightHint(int startX, int startY, int startZ) {
|
||||||
|
Heightmap_PreCalcColumns(startX, startZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void ClassicLighting_UpdateLighting(int x, int y, int z, BlockID oldBlock, BlockID newBlock, int index, int lightH) {
|
static void ClassicLighting_UpdateLighting(int x, int y, int z, BlockID oldBlock, BlockID newBlock, int index, int lightH) {
|
||||||
cc_bool didBlock = Blocks.BlocksLight[oldBlock];
|
cc_bool didBlock = Blocks.BlocksLight[oldBlock];
|
||||||
cc_bool nowBlocks = Blocks.BlocksLight[newBlock];
|
cc_bool nowBlocks = Blocks.BlocksLight[newBlock];
|
||||||
@ -385,14 +385,13 @@ static void ClassicLighting_SetActive(void) {
|
|||||||
|
|
||||||
Lighting.IsLit_Fast = ClassicLighting_IsLit_Fast;
|
Lighting.IsLit_Fast = ClassicLighting_IsLit_Fast;
|
||||||
Lighting.Color_Fast = ClassicLighting_Color_Fast;
|
Lighting.Color_Fast = ClassicLighting_Color_Fast;
|
||||||
Lighting.Color_YMax_Fast = ClassicLighting_Color_YMax_Fast;
|
|
||||||
Lighting.Color_YMin_Fast = ClassicLighting_Color_YMin_Fast;
|
Lighting.Color_YMin_Fast = ClassicLighting_Color_YMin_Fast;
|
||||||
Lighting.Color_XSide_Fast = ClassicLighting_Color_XSide_Fast;
|
Lighting.Color_XSide_Fast = ClassicLighting_Color_XSide_Fast;
|
||||||
Lighting.Color_ZSide_Fast = ClassicLighting_Color_ZSide_Fast;
|
Lighting.Color_ZSide_Fast = ClassicLighting_Color_ZSide_Fast;
|
||||||
|
|
||||||
Lighting.FreeState = Heightmap_Free;
|
Lighting.FreeState = Heightmap_Free;
|
||||||
Lighting.AllocState = Heightmap_Allocate;
|
Lighting.AllocState = Heightmap_Allocate;
|
||||||
Lighting.LightHint = Heightmap_PreCalcColumns;
|
Lighting.LightHint = ClassicLighting_LightHint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -554,12 +553,14 @@ static void ModernLighting_InitPalettes(void) {
|
|||||||
ModernLighting_InitPalette(modernLighting_paletteY, PACKEDCOL_SHADE_YMIN);
|
ModernLighting_InitPalette(modernLighting_paletteY, PACKEDCOL_SHADE_YMIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int chunksCount;
|
||||||
static void ModernLighting_AllocState(void) {
|
static void ModernLighting_AllocState(void) {
|
||||||
Heightmap_Allocate();
|
Heightmap_Allocate();
|
||||||
ModernLighting_InitPalettes();
|
ModernLighting_InitPalettes();
|
||||||
|
chunksCount = World.ChunksCount;
|
||||||
|
|
||||||
chunkLightingDataFlags = (cc_uint8*)Mem_TryAllocCleared(World.ChunksCount, sizeof(cc_uint8));
|
chunkLightingDataFlags = (cc_uint8*)Mem_TryAllocCleared(chunksCount, sizeof(cc_uint8));
|
||||||
chunkLightingData = (LightingChunk*)Mem_TryAllocCleared(World.ChunksCount, sizeof(LightingChunk));
|
chunkLightingData = (LightingChunk*)Mem_TryAllocCleared(chunksCount, sizeof(LightingChunk));
|
||||||
LightQueue_Init(&lightQueue);
|
LightQueue_Init(&lightQueue);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -568,16 +569,17 @@ static void ModernLighting_FreeState(void) {
|
|||||||
Heightmap_Free();
|
Heightmap_Free();
|
||||||
int i;
|
int i;
|
||||||
/* This function can be called multiple times without calling ModernLighting_AllocState, so... */
|
/* This function can be called multiple times without calling ModernLighting_AllocState, so... */
|
||||||
if (chunkLightingDataFlags == NULL) { return; }
|
if (!chunkLightingDataFlags) return;
|
||||||
|
|
||||||
for (i = 0; i < World.ChunksCount; i++) {
|
for (i = 0; i < chunksCount; i++) {
|
||||||
if (chunkLightingDataFlags[i] > CHUNK_SELF_CALCULATED || chunkLightingDataFlags[i] == CHUNK_UNCALCULATED) { continue; }
|
if (chunkLightingDataFlags[i] == CHUNK_UNCALCULATED) continue;
|
||||||
Mem_Free(chunkLightingData[i]);
|
Mem_Free(chunkLightingData[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mem_Free(chunkLightingDataFlags);
|
Mem_Free(chunkLightingDataFlags);
|
||||||
Mem_Free(chunkLightingData);
|
Mem_Free(chunkLightingData);
|
||||||
chunkLightingDataFlags = NULL;
|
chunkLightingDataFlags = NULL;
|
||||||
chunkLightingData = NULL;
|
chunkLightingData = NULL;
|
||||||
LightQueue_Clear(&lightQueue);
|
LightQueue_Clear(&lightQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -849,6 +851,7 @@ static void CalculateChunkLightingSelf(int chunkIndex, int cx, int cy, int cz) {
|
|||||||
}
|
}
|
||||||
chunkLightingDataFlags[chunkIndex] = CHUNK_SELF_CALCULATED;
|
chunkLightingDataFlags[chunkIndex] = CHUNK_SELF_CALCULATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CalculateChunkLightingAll(int chunkIndex, int cx, int cy, int cz) {
|
static void CalculateChunkLightingAll(int chunkIndex, int cx, int cy, int cz) {
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
int chunkStartX, chunkStartY, chunkStartZ; //chunk coords
|
int chunkStartX, chunkStartY, chunkStartZ; //chunk coords
|
||||||
@ -943,8 +946,10 @@ static PackedCol ModernLighting_Color_YMinSide(int x, int y, int z) {
|
|||||||
return ModernLighting_Color_Core(x, y, z, modernLighting_paletteY, Env.SunYMin);
|
return ModernLighting_Color_Core(x, y, z, modernLighting_paletteY, Env.SunYMin);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ModernLighting_LightHint(int startX, int startZ) {
|
static void ModernLighting_LightHint(int startX, int startY, int startZ) {
|
||||||
|
int cx, cy, cz, x, y, z;
|
||||||
Heightmap_PreCalcColumns(startX, startZ);
|
Heightmap_PreCalcColumns(startX, startZ);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ModernLighting_SetActive(void) {
|
static void ModernLighting_SetActive(void) {
|
||||||
@ -956,7 +961,6 @@ static void ModernLighting_SetActive(void) {
|
|||||||
|
|
||||||
Lighting.IsLit_Fast = ModernLighting_IsLit_Fast;
|
Lighting.IsLit_Fast = ModernLighting_IsLit_Fast;
|
||||||
Lighting.Color_Fast = ModernLighting_Color;
|
Lighting.Color_Fast = ModernLighting_Color;
|
||||||
Lighting.Color_YMax_Fast = ModernLighting_Color;
|
|
||||||
Lighting.Color_YMin_Fast = ModernLighting_Color_YMinSide;
|
Lighting.Color_YMin_Fast = ModernLighting_Color_YMinSide;
|
||||||
Lighting.Color_XSide_Fast = ModernLighting_Color_XSide;
|
Lighting.Color_XSide_Fast = ModernLighting_Color_XSide;
|
||||||
Lighting.Color_ZSide_Fast = ModernLighting_Color_ZSide;
|
Lighting.Color_ZSide_Fast = ModernLighting_Color_ZSide;
|
||||||
|
@ -24,11 +24,9 @@ CC_VAR extern struct _Lighting {
|
|||||||
/* Allocates the per-level lighting state */
|
/* Allocates the per-level lighting state */
|
||||||
/* (called after map has been fully loaded) */
|
/* (called after map has been fully loaded) */
|
||||||
void (*AllocState)(void);
|
void (*AllocState)(void);
|
||||||
/* Equivalent to (but far more optimised form of)
|
/* Quickly calculates lighting between
|
||||||
* for x = startX; x < startX + 18; x++
|
/* (startX, startY, startZ) to (startX + 18, startY + 18, startZ + 18) */
|
||||||
* for z = startZ; z < startZ + 18; z++
|
void (*LightHint)(int startX, int startY, int startZ);
|
||||||
* CalcLight(x, maxY, z) */
|
|
||||||
void (*LightHint)(int startX, int startZ);
|
|
||||||
|
|
||||||
/* Called when a block is changed to update internal lighting state. */
|
/* Called when a block is changed to update internal lighting state. */
|
||||||
/* NOTE: Implementations ***MUST*** mark all chunks affected by this lighting change as needing to be refreshed. */
|
/* NOTE: Implementations ***MUST*** mark all chunks affected by this lighting change as needing to be refreshed. */
|
||||||
@ -51,7 +49,6 @@ CC_VAR extern struct _Lighting {
|
|||||||
|
|
||||||
cc_bool (*IsLit_Fast)(int x, int y, int z);
|
cc_bool (*IsLit_Fast)(int x, int y, int z);
|
||||||
PackedCol (*Color_Fast)(int x, int y, int z);
|
PackedCol (*Color_Fast)(int x, int y, int z);
|
||||||
PackedCol (*Color_YMax_Fast)(int x, int y, int z);
|
|
||||||
PackedCol (*Color_YMin_Fast)(int x, int y, int z);
|
PackedCol (*Color_YMin_Fast)(int x, int y, int z);
|
||||||
PackedCol (*Color_XSide_Fast)(int x, int y, int z);
|
PackedCol (*Color_XSide_Fast)(int x, int y, int z);
|
||||||
PackedCol (*Color_ZSide_Fast)(int x, int y, int z);
|
PackedCol (*Color_ZSide_Fast)(int x, int y, int z);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user