Add X and Z min side color functions to Lighting struct

This commit is contained in:
Goodlyay 2024-07-30 22:57:06 -07:00
parent e0d802f29a
commit 5108eeafea
3 changed files with 127 additions and 23 deletions

View file

@ -124,6 +124,91 @@ static void AllocState(void) {
AllocState_Angled();
}
static void CalcAngledShadows_Old(int xStart, int zStart, int xWidth, int zLength) {
//xStart and zStart are zero.
int width = World.Width;
int height = World.Height;
int length = World.Length;
xStart += height;
if (xWidth == width) { //Since xWidth starts the same as width, this always happens at first
xWidth += height;
xStart -= height;
}
zStart += height;
if (zLength == length) {
zLength += height;
zStart -= height;
}
//the size of the lightmap in each dimension
int xExtent = width + height;
int zExtent = length + height;
int x, z;
for (x = xStart; x < xStart + xWidth; ++x) {
for (z = zStart; z < zStart + zLength; ++z) {
int y = height - 1; //-1 because it starts at 0
int xD = x + height - 1;
int zD = z + height - 1;
{
int xOver = 0; //how far past the edge of the map is it?
int zOver = 0;
if (xD >= xExtent) xOver = xD - (xExtent - 1);
if (zD >= zExtent) zOver = zD - (zExtent - 1);
int maxOver = max(xOver, zOver);
//pushing y and x and z back to the edge of the map
y -= maxOver;
xD -= maxOver;
zD -= maxOver;
xD -= height;
zD -= height;
}
//y x and z safe are used to create shadow columns that are thicker than the single block that casts them
int ySafe, xSafe, zSafe;
ySafe = (y > 0) ? y - 1 : y;
xSafe = (xD > 0) ? xD - 1 : xD;
zSafe = (zD > 0) ? zD - 1 : zD;
while (
y > 0 &&
xD >= 0 && xD < width &&
zD >= 0 && zD < length &&
!(
Blocks.BlocksLight[World_GetBlock(xD, y, zD)] ||
Blocks.BlocksLight[World_GetBlock(xD, ySafe, zD)]
)
&&
!(Blocks.BlocksLight[World_GetBlock(xSafe, y, zD)] || Blocks.BlocksLight[World_GetBlock(xD, y, zSafe)]) &&
!(Blocks.BlocksLight[World_GetBlock(xSafe, ySafe, zD)] || Blocks.BlocksLight[World_GetBlock(xD, ySafe, zSafe)])
) {
--y;
--xD;
--zD;
ySafe = (y > 0) ? y - 1 : y;
xSafe = (xD > 0) ? xD - 1 : xD;
zSafe = (zD > 0) ? zD - 1 : zD;
}
//We searched all the way down the diagonal column and hit nothing, meaning we don't need to add any shadow blocker here, go next cell
if (xD < 0 || zD < 0) continue;
blockers[x + z * xExtent] = y;
}
}
}
static void CalcAngledShadows(int xStart, int zStart, int xWidth, int zLength) {
//xStart and zStart are zero.
@ -133,7 +218,7 @@ static void CalcAngledShadows(int xStart, int zStart, int xWidth, int zLength) {
int length = World.Length;
xStart += height;
if (xWidth == width) { //Since xWidth starts the same as width, this always happens at first
if (xWidth == width) { //this always happens when calculating shadows for the entire level
xWidth += height;
xStart -= height;
}
@ -143,7 +228,7 @@ static void CalcAngledShadows(int xStart, int zStart, int xWidth, int zLength) {
zLength += height;
zStart -= height;
}
//the size of the lightmap in each dimension
int xExtent = width + height;
int zExtent = length + height;
@ -181,16 +266,26 @@ static void CalcAngledShadows(int xStart, int zStart, int xWidth, int zLength) {
zSafe = (zD > 0) ? zD - 1 : zD;
while (
y > 0 &&
xD >= 0 && xD < width &&
zD >= 0 && zD < length &&
zD >= 0 && zD < length
&&
!(
Blocks.BlocksLight[World_GetBlock(xD, y , zD)] ||
Blocks.BlocksLight[World_GetBlock(xD, ySafe, zD)]
)
&&
!(Blocks.BlocksLight[World_GetBlock(xSafe, y , zD)] || Blocks.BlocksLight[World_GetBlock(xD, y , zSafe)]) &&
!(Blocks.BlocksLight[World_GetBlock(xSafe, ySafe, zD)] || Blocks.BlocksLight[World_GetBlock(xD, ySafe, zSafe)])
!(
Blocks.BlocksLight[World_GetBlock(xSafe, y , zD)] ||
Blocks.BlocksLight[World_GetBlock(xD, y , zSafe)]
)
&&
!(
Blocks.BlocksLight[World_GetBlock(xSafe, ySafe, zD)] ||
Blocks.BlocksLight[World_GetBlock(xD, ySafe, zSafe)]
)
) {
--y;
@ -586,12 +681,15 @@ static cc_bool IsLit(int x, int y, int z) { return ClassicLighting_IsLit(x, y, z
static cc_bool IsLit_Fast(int x, int y, int z) { return ClassicLighting_IsLit_Fast(x, y, z); }
static cc_bool IsLit_Angled(int x, int y, int z) {
/* Test */
return !(x >= 0 &&
y >= 0 &&
z >= 0 &&
x < World.Width &&
y < World.Height &&
z < World.Length) || y >= blockers[(x + World.Height -y) + (z + World.Height -y) * (World.Width + World.Height)];
return !(
x >= 0 &&
y >= 0 &&
z >= 0 &&
x < World.Width &&
y < World.Height &&
z < World.Length
) ||
y >= blockers[(x + World.Height -y) + (z + World.Height -y) * (World.Width + World.Height)];
}
static cc_bool IsLit_Fast_Angled(int x, int y, int z) {
return IsLit_Angled(x, y, z);
@ -700,12 +798,14 @@ void FancyLighting_SetActive(void) {
Lighting.Color_XSide = Color_XSide;
Lighting.IsLit_Fast = Lighting_Mode == LIGHTING_MODE_FANCY ? IsLit_Fast : IsLit_Fast_Angled;
Lighting.Color_Sprite_Fast = Color;
Lighting.Color_YMax_Fast = Color;
Lighting.Color_YMin_Fast = Color_YMinSide;
Lighting.Color_XSide_Fast = Color_XSide;
Lighting.Color_ZSide_Fast = Color_ZSide;
Lighting.Color_Sprite_Fast = Color;
Lighting.Color_YMax_Fast = Color;
Lighting.Color_YMin_Fast = Color_YMinSide;
Lighting.Color_XSide_Fast = Color_XSide;
Lighting.Color_ZSide_Fast = Color_ZSide;
Lighting.Color_XSideMin_Fast = Color_XSide;
Lighting.Color_ZSideMin_Fast = Color_ZSide;
//TODO X Z side min
Lighting.FreeState = FreeState;

View file

@ -410,12 +410,14 @@ static void ClassicLighting_SetActive(void) {
Lighting.Color = smoothLighting ? SmoothLighting_Color : ClassicLighting_Color;
Lighting.Color_XSide = ClassicLighting_Color_XSide;
Lighting.IsLit_Fast = ClassicLighting_IsLit_Fast;
Lighting.Color_Sprite_Fast = ClassicLighting_Color_Sprite_Fast;
Lighting.Color_YMax_Fast = ClassicLighting_Color_YMax_Fast;
Lighting.Color_YMin_Fast = ClassicLighting_Color_YMin_Fast;
Lighting.Color_XSide_Fast = ClassicLighting_Color_XSide_Fast;
Lighting.Color_ZSide_Fast = ClassicLighting_Color_ZSide_Fast;
Lighting.IsLit_Fast = ClassicLighting_IsLit_Fast;
Lighting.Color_Sprite_Fast = ClassicLighting_Color_Sprite_Fast;
Lighting.Color_YMax_Fast = ClassicLighting_Color_YMax_Fast;
Lighting.Color_YMin_Fast = ClassicLighting_Color_YMin_Fast;
Lighting.Color_XSide_Fast = ClassicLighting_Color_XSide_Fast;
Lighting.Color_ZSide_Fast = ClassicLighting_Color_ZSide_Fast;
Lighting.Color_XSideMin_Fast = ClassicLighting_Color_XSide_Fast;
Lighting.Color_ZSideMin_Fast = ClassicLighting_Color_ZSide_Fast;
Lighting.FreeState = ClassicLighting_FreeState;
Lighting.AllocState = ClassicLighting_AllocState;

View file

@ -72,6 +72,8 @@ CC_VAR extern struct _Lighting {
PackedCol (*Color_YMin_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_XSideMin_Fast)(int x, int y, int z);
PackedCol (*Color_ZSideMin_Fast)(int x, int y, int z);
} Lighting;
void FancyLighting_SetActive(void);