mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 09:01:57 -05:00
Add X and Z min side color functions to Lighting struct
This commit is contained in:
parent
e0d802f29a
commit
5108eeafea
3 changed files with 127 additions and 23 deletions
|
@ -124,8 +124,7 @@ static void AllocState(void) {
|
|||
AllocState_Angled();
|
||||
}
|
||||
|
||||
|
||||
static void CalcAngledShadows(int xStart, int zStart, int xWidth, int zLength) {
|
||||
static void CalcAngledShadows_Old(int xStart, int zStart, int xWidth, int zLength) {
|
||||
//xStart and zStart are zero.
|
||||
|
||||
int width = World.Width;
|
||||
|
@ -211,6 +210,102 @@ static void CalcAngledShadows(int xStart, int zStart, int xWidth, int zLength) {
|
|||
}
|
||||
}
|
||||
|
||||
static void CalcAngledShadows(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) { //this always happens when calculating shadows for the entire level
|
||||
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 FreeState_Angled(void) {
|
||||
if (Lighting_Mode != LIGHTING_MODE_ANGLED) return;
|
||||
|
||||
|
@ -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 &&
|
||||
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)];
|
||||
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);
|
||||
|
@ -705,7 +803,9 @@ void FancyLighting_SetActive(void) {
|
|||
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;
|
||||
|
|
|
@ -416,6 +416,8 @@ static void ClassicLighting_SetActive(void) {
|
|||
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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue