mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Remove useless EnvRenderer_ prefix in many static functions in EnvRenderer.c
This commit is contained in:
parent
e793332132
commit
d38f3a67b8
@ -21,7 +21,7 @@
|
|||||||
cc_bool EnvRenderer_Legacy, EnvRenderer_Minimal;
|
cc_bool EnvRenderer_Legacy, EnvRenderer_Minimal;
|
||||||
|
|
||||||
#define ENV_SMALL_VERTICES 4096
|
#define ENV_SMALL_VERTICES 4096
|
||||||
static float EnvRenderer_BlendFactor(float x) {
|
static float CalcBlendFactor(float x) {
|
||||||
/* return -0.05 + 0.22 * (Math_Log(x) * 0.25f); */
|
/* return -0.05 + 0.22 * (Math_Log(x) * 0.25f); */
|
||||||
double blend = -0.13 + 0.28 * (Math_Log(x) * 0.25);
|
double blend = -0.13 + 0.28 * (Math_Log(x) * 0.25);
|
||||||
if (blend < 0.0) blend = 0.0;
|
if (blend < 0.0) blend = 0.0;
|
||||||
@ -31,7 +31,7 @@ static float EnvRenderer_BlendFactor(float x) {
|
|||||||
|
|
||||||
#define EnvRenderer_AxisSize() (EnvRenderer_Legacy ? 128 : 2048)
|
#define EnvRenderer_AxisSize() (EnvRenderer_Legacy ? 128 : 2048)
|
||||||
/* Returns the number of vertices needed to subdivide a quad */
|
/* Returns the number of vertices needed to subdivide a quad */
|
||||||
static int EnvRenderer_Vertices(int axis1Len, int axis2Len) {
|
static int CalcNumVertices(int axis1Len, int axis2Len) {
|
||||||
int axisSize = EnvRenderer_AxisSize();
|
int axisSize = EnvRenderer_AxisSize();
|
||||||
return Math_CeilDiv(axis1Len, axisSize) * Math_CeilDiv(axis2Len, axisSize) * 4;
|
return Math_CeilDiv(axis1Len, axisSize) * Math_CeilDiv(axis2Len, axisSize) * 4;
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ static int EnvRenderer_Vertices(int axis1Len, int axis2Len) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*------------------------------------------------------------Fog----------------------------------------------------------*
|
*------------------------------------------------------------Fog----------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static void EnvRenderer_CalcFog(float* density, PackedCol* col) {
|
static void CalcFog(float* density, PackedCol* col) {
|
||||||
Vec3 pos;
|
Vec3 pos;
|
||||||
IVec3 coords;
|
IVec3 coords;
|
||||||
BlockID block;
|
BlockID block;
|
||||||
@ -60,12 +60,12 @@ static void EnvRenderer_CalcFog(float* density, PackedCol* col) {
|
|||||||
} else {
|
} else {
|
||||||
*density = 0.0f;
|
*density = 0.0f;
|
||||||
/* Blend fog and sky together */
|
/* Blend fog and sky together */
|
||||||
blend = EnvRenderer_BlendFactor((float)Game_ViewDistance);
|
blend = CalcBlendFactor((float)Game_ViewDistance);
|
||||||
*col = PackedCol_Lerp(Env.FogCol, Env.SkyCol, blend);
|
*col = PackedCol_Lerp(Env.FogCol, Env.SkyCol, blend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_UpdateFogMinimal(float fogDensity) {
|
static void UpdateFogMinimal(float fogDensity) {
|
||||||
int dist;
|
int dist;
|
||||||
/* TODO: rewrite this to avoid raising the event? want to avoid recreating vbos too many times often */
|
/* TODO: rewrite this to avoid raising the event? want to avoid recreating vbos too many times often */
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ static void EnvRenderer_UpdateFogMinimal(float fogDensity) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_UpdateFogNormal(float fogDensity, PackedCol fogCol) {
|
static void UpdateFogNormal(float fogDensity, PackedCol fogCol) {
|
||||||
double density;
|
double density;
|
||||||
|
|
||||||
if (fogDensity != 0.0f) {
|
if (fogDensity != 0.0f) {
|
||||||
@ -113,13 +113,13 @@ void EnvRenderer_UpdateFog(void) {
|
|||||||
PackedCol fogCol;
|
PackedCol fogCol;
|
||||||
if (!World.Blocks) return;
|
if (!World.Blocks) return;
|
||||||
|
|
||||||
EnvRenderer_CalcFog(&fogDensity, &fogCol);
|
CalcFog(&fogDensity, &fogCol);
|
||||||
Gfx_ClearCol(fogCol);
|
Gfx_ClearCol(fogCol);
|
||||||
|
|
||||||
if (EnvRenderer_Minimal) {
|
if (EnvRenderer_Minimal) {
|
||||||
EnvRenderer_UpdateFogMinimal(fogDensity);
|
UpdateFogMinimal(fogDensity);
|
||||||
} else {
|
} else {
|
||||||
EnvRenderer_UpdateFogNormal(fogDensity, fogCol);
|
UpdateFogNormal(fogDensity, fogCol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ void EnvRenderer_RenderClouds(double deltaTime) {
|
|||||||
Gfx_LoadIdentityMatrix(MATRIX_TEXTURE);
|
Gfx_LoadIdentityMatrix(MATRIX_TEXTURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_DrawCloudsY(int x1, int z1, int x2, int z2, int y, VertexP3fT2fC4b* v) {
|
static void DrawCloudsY(int x1, int z1, int x2, int z2, int y, VertexP3fT2fC4b* v) {
|
||||||
int endX = x2, endZ = z2, startZ = z1, axisSize = EnvRenderer_AxisSize();
|
int endX = x2, endZ = z2, startZ = z1, axisSize = EnvRenderer_AxisSize();
|
||||||
float u1, u2, v1, v2;
|
float u1, u2, v1, v2;
|
||||||
float yy = (float)y + 0.1f;
|
float yy = (float)y + 0.1f;
|
||||||
@ -179,7 +179,7 @@ static void EnvRenderer_DrawCloudsY(int x1, int z1, int x2, int z2, int y, Verte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_UpdateClouds(void) {
|
static void UpdateClouds(void) {
|
||||||
VertexP3fT2fC4b v[ENV_SMALL_VERTICES];
|
VertexP3fT2fC4b v[ENV_SMALL_VERTICES];
|
||||||
VertexP3fT2fC4b* ptr;
|
VertexP3fT2fC4b* ptr;
|
||||||
int extent;
|
int extent;
|
||||||
@ -192,14 +192,14 @@ static void EnvRenderer_UpdateClouds(void) {
|
|||||||
extent = Utils_AdjViewDist(Game_ViewDistance);
|
extent = Utils_AdjViewDist(Game_ViewDistance);
|
||||||
x1 = -extent; x2 = World.Width + extent;
|
x1 = -extent; x2 = World.Width + extent;
|
||||||
z1 = -extent; z2 = World.Length + extent;
|
z1 = -extent; z2 = World.Length + extent;
|
||||||
clouds_vertices = EnvRenderer_Vertices(x2 - x1, z2 - z1);
|
clouds_vertices = CalcNumVertices(x2 - x1, z2 - z1);
|
||||||
|
|
||||||
ptr = v;
|
ptr = v;
|
||||||
if (clouds_vertices > ENV_SMALL_VERTICES) {
|
if (clouds_vertices > ENV_SMALL_VERTICES) {
|
||||||
ptr = (VertexP3fT2fC4b*)Mem_Alloc(clouds_vertices, sizeof(VertexP3fT2fC4b), "clouds vertices");
|
ptr = (VertexP3fT2fC4b*)Mem_Alloc(clouds_vertices, sizeof(VertexP3fT2fC4b), "clouds vertices");
|
||||||
}
|
}
|
||||||
|
|
||||||
EnvRenderer_DrawCloudsY(x1, z1, x2, z2, Env.CloudsHeight, ptr);
|
DrawCloudsY(x1, z1, x2, z2, Env.CloudsHeight, ptr);
|
||||||
clouds_vb = Gfx_CreateVb(ptr, VERTEX_FORMAT_P3FT2FC4B, clouds_vertices);
|
clouds_vb = Gfx_CreateVb(ptr, VERTEX_FORMAT_P3FT2FC4B, clouds_vertices);
|
||||||
|
|
||||||
if (clouds_vertices > ENV_SMALL_VERTICES) Mem_Free(ptr);
|
if (clouds_vertices > ENV_SMALL_VERTICES) Mem_Free(ptr);
|
||||||
@ -237,7 +237,7 @@ void EnvRenderer_RenderSky(double deltaTime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_DrawSkyY(int x1, int z1, int x2, int z2, int y, VertexP3fC4b* v) {
|
static void DrawSkyY(int x1, int z1, int x2, int z2, int y, VertexP3fC4b* v) {
|
||||||
int endX = x2, endZ = z2, startZ = z1, axisSize = EnvRenderer_AxisSize();
|
int endX = x2, endZ = z2, startZ = z1, axisSize = EnvRenderer_AxisSize();
|
||||||
PackedCol col = Env.SkyCol;
|
PackedCol col = Env.SkyCol;
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ static void EnvRenderer_DrawSkyY(int x1, int z1, int x2, int z2, int y, VertexP3
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_UpdateSky(void) {
|
static void UpdateSky(void) {
|
||||||
VertexP3fC4b v[ENV_SMALL_VERTICES];
|
VertexP3fC4b v[ENV_SMALL_VERTICES];
|
||||||
VertexP3fC4b* ptr;
|
VertexP3fC4b* ptr;
|
||||||
int extent, height;
|
int extent, height;
|
||||||
@ -270,7 +270,7 @@ static void EnvRenderer_UpdateSky(void) {
|
|||||||
extent = Utils_AdjViewDist(Game_ViewDistance);
|
extent = Utils_AdjViewDist(Game_ViewDistance);
|
||||||
x1 = -extent; x2 = World.Width + extent;
|
x1 = -extent; x2 = World.Width + extent;
|
||||||
z1 = -extent; z2 = World.Length + extent;
|
z1 = -extent; z2 = World.Length + extent;
|
||||||
sky_vertices = EnvRenderer_Vertices(x2 - x1, z2 - z1);
|
sky_vertices = CalcNumVertices(x2 - x1, z2 - z1);
|
||||||
|
|
||||||
ptr = v;
|
ptr = v;
|
||||||
if (sky_vertices > ENV_SMALL_VERTICES) {
|
if (sky_vertices > ENV_SMALL_VERTICES) {
|
||||||
@ -278,7 +278,7 @@ static void EnvRenderer_UpdateSky(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
height = max((World.Height + 2), Env.CloudsHeight) + 6;
|
height = max((World.Height + 2), Env.CloudsHeight) + 6;
|
||||||
EnvRenderer_DrawSkyY(x1, z1, x2, z2, height, ptr);
|
DrawSkyY(x1, z1, x2, z2, height, ptr);
|
||||||
sky_vb = Gfx_CreateVb(ptr, VERTEX_FORMAT_P3FC4B, sky_vertices);
|
sky_vb = Gfx_CreateVb(ptr, VERTEX_FORMAT_P3FC4B, sky_vertices);
|
||||||
|
|
||||||
if (sky_vertices > ENV_SMALL_VERTICES) Mem_Free(ptr);
|
if (sky_vertices > ENV_SMALL_VERTICES) Mem_Free(ptr);
|
||||||
@ -323,7 +323,7 @@ void EnvRenderer_RenderSkybox(double deltaTime) {
|
|||||||
Gfx_SetDepthWrite(true);
|
Gfx_SetDepthWrite(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_UpdateSkybox(void) {
|
static void UpdateSkybox(void) {
|
||||||
static VertexP3fT2fC4b vertices[SKYBOX_COUNT] = {
|
static VertexP3fT2fC4b vertices[SKYBOX_COUNT] = {
|
||||||
/* Front quad */
|
/* Front quad */
|
||||||
{ -1, -1, -1, 0, 0.25f, 1.00f }, { 1, -1, -1, 0, 0.50f, 1.00f },
|
{ -1, -1, -1, 0, 0.25f, 1.00f }, { 1, -1, -1, 0, 0.50f, 1.00f },
|
||||||
@ -367,7 +367,7 @@ static IVec3 lastPos;
|
|||||||
#define WEATHER_VERTS_COUNT 8 * (WEATHER_EXTENT * 2 + 1) * (WEATHER_EXTENT * 2 + 1)
|
#define WEATHER_VERTS_COUNT 8 * (WEATHER_EXTENT * 2 + 1) * (WEATHER_EXTENT * 2 + 1)
|
||||||
#define Weather_Pack(x, z) ((x) * World.Length + (z))
|
#define Weather_Pack(x, z) ((x) * World.Length + (z))
|
||||||
|
|
||||||
static void EnvRenderer_InitWeatherHeightmap(void) {
|
static void InitWeatherHeightmap(void) {
|
||||||
int i;
|
int i;
|
||||||
Weather_Heightmap = (cc_int16*)Mem_Alloc(World.Width * World.Length, 2, "weather heightmap");
|
Weather_Heightmap = (cc_int16*)Mem_Alloc(World.Width * World.Length, 2, "weather heightmap");
|
||||||
|
|
||||||
@ -376,7 +376,7 @@ static void EnvRenderer_InitWeatherHeightmap(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EnvRenderer_RainCalcBody(get_block)\
|
#define RainCalcBody(get_block)\
|
||||||
for (y = maxY; y >= 0; y--, i -= World.OneY) {\
|
for (y = maxY; y >= 0; y--, i -= World.OneY) {\
|
||||||
draw = Blocks.Draw[get_block];\
|
draw = Blocks.Draw[get_block];\
|
||||||
\
|
\
|
||||||
@ -386,17 +386,17 @@ for (y = maxY; y >= 0; y--, i -= World.OneY) {\
|
|||||||
}\
|
}\
|
||||||
}
|
}
|
||||||
|
|
||||||
static int EnvRenderer_CalcRainHeightAt(int x, int maxY, int z, int hIndex) {
|
static int CalcRainHeightAt(int x, int maxY, int z, int hIndex) {
|
||||||
int i = World_Pack(x, maxY, z), y;
|
int i = World_Pack(x, maxY, z), y;
|
||||||
cc_uint8 draw;
|
cc_uint8 draw;
|
||||||
|
|
||||||
#ifndef EXTENDED_BLOCKS
|
#ifndef EXTENDED_BLOCKS
|
||||||
EnvRenderer_RainCalcBody(World.Blocks[i]);
|
RainCalcBody(World.Blocks[i]);
|
||||||
#else
|
#else
|
||||||
if (World.IDMask <= 0xFF) {
|
if (World.IDMask <= 0xFF) {
|
||||||
EnvRenderer_RainCalcBody(World.Blocks[i]);
|
RainCalcBody(World.Blocks[i]);
|
||||||
} else {
|
} else {
|
||||||
EnvRenderer_RainCalcBody(World.Blocks[i] | (World.Blocks2[i] << 8));
|
RainCalcBody(World.Blocks[i] | (World.Blocks2[i] << 8));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -404,7 +404,7 @@ static int EnvRenderer_CalcRainHeightAt(int x, int maxY, int z, int hIndex) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float EnvRenderer_RainHeight(int x, int z) {
|
static float GetRainHeight(int x, int z) {
|
||||||
int hIndex, height;
|
int hIndex, height;
|
||||||
int y;
|
int y;
|
||||||
if (!World_ContainsXZ(x, z)) return (float)Env.EdgeHeight;
|
if (!World_ContainsXZ(x, z)) return (float)Env.EdgeHeight;
|
||||||
@ -412,7 +412,7 @@ static float EnvRenderer_RainHeight(int x, int z) {
|
|||||||
hIndex = Weather_Pack(x, z);
|
hIndex = Weather_Pack(x, z);
|
||||||
height = Weather_Heightmap[hIndex];
|
height = Weather_Heightmap[hIndex];
|
||||||
|
|
||||||
y = height == Int16_MaxValue ? EnvRenderer_CalcRainHeightAt(x, World.MaxY, z, hIndex) : height;
|
y = height == Int16_MaxValue ? CalcRainHeightAt(x, World.MaxY, z, hIndex) : height;
|
||||||
return y == -1 ? 0 : y + Blocks.MaxBB[World_GetBlock(x, y, z)].Y;
|
return y == -1 ? 0 : y + Blocks.MaxBB[World_GetBlock(x, y, z)].Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,11 +435,11 @@ void EnvRenderer_OnBlockChanged(int x, int y, int z, BlockID oldBlock, BlockID n
|
|||||||
} else {
|
} else {
|
||||||
/* Part of the column is now visible to rain, we don't know how exactly how high it should be though. */
|
/* Part of the column is now visible to rain, we don't know how exactly how high it should be though. */
|
||||||
/* However, we know that if the old block was above or equal to rain height, then the new rain height must be <= old block.y */
|
/* However, we know that if the old block was above or equal to rain height, then the new rain height must be <= old block.y */
|
||||||
EnvRenderer_CalcRainHeightAt(x, y, z, hIndex);
|
CalcRainHeightAt(x, y, z, hIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static float EnvRenderer_RainAlphaAt(float x) {
|
static float CalcRainAlphaAt(float x) {
|
||||||
/* Wolfram Alpha: fit {0,178},{1,169},{4,147},{9,114},{16,59},{25,9} */
|
/* Wolfram Alpha: fit {0,178},{1,169},{4,147},{9,114},{16,59},{25,9} */
|
||||||
float falloff = 0.05f * x * x - 7 * x;
|
float falloff = 0.05f * x * x - 7 * x;
|
||||||
return 178 + falloff * Env.WeatherFade;
|
return 178 + falloff * Env.WeatherFade;
|
||||||
@ -461,7 +461,7 @@ void EnvRenderer_RenderWeather(double deltaTime) {
|
|||||||
|
|
||||||
weather = Env.Weather;
|
weather = Env.Weather;
|
||||||
if (weather == WEATHER_SUNNY) return;
|
if (weather == WEATHER_SUNNY) return;
|
||||||
if (!Weather_Heightmap) EnvRenderer_InitWeatherHeightmap();
|
if (!Weather_Heightmap) InitWeatherHeightmap();
|
||||||
Gfx_BindTexture(weather == WEATHER_RAINY ? rain_tex : snow_tex);
|
Gfx_BindTexture(weather == WEATHER_RAINY ? rain_tex : snow_tex);
|
||||||
|
|
||||||
IVec3_Floor(&pos, &Camera.CurrentPos);
|
IVec3_Floor(&pos, &Camera.CurrentPos);
|
||||||
@ -484,7 +484,7 @@ void EnvRenderer_RenderWeather(double deltaTime) {
|
|||||||
for (dz = -WEATHER_EXTENT; dz <= WEATHER_EXTENT; dz++) {
|
for (dz = -WEATHER_EXTENT; dz <= WEATHER_EXTENT; dz++) {
|
||||||
x = pos.X + dx; z = pos.Z + dz;
|
x = pos.X + dx; z = pos.Z + dz;
|
||||||
|
|
||||||
y = EnvRenderer_RainHeight(x, z);
|
y = GetRainHeight(x, z);
|
||||||
height = pos.Y - y;
|
height = pos.Y - y;
|
||||||
if (height <= 0) continue;
|
if (height <= 0) continue;
|
||||||
|
|
||||||
@ -494,7 +494,7 @@ void EnvRenderer_RenderWeather(double deltaTime) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dist = dx * dx + dz * dz;
|
dist = dx * dx + dz * dz;
|
||||||
alpha = EnvRenderer_RainAlphaAt((float)dist);
|
alpha = CalcRainAlphaAt((float)dist);
|
||||||
Math_Clamp(alpha, 0.0f, 255.0f);
|
Math_Clamp(alpha, 0.0f, 255.0f);
|
||||||
col = (col & PACKEDCOL_RGB_MASK) | PackedCol_A_Bits(alpha);
|
col = (col & PACKEDCOL_RGB_MASK) | PackedCol_A_Bits(alpha);
|
||||||
|
|
||||||
@ -543,7 +543,7 @@ static int sides_vertices, edges_vertices;
|
|||||||
static cc_bool sides_fullBright, edges_fullBright;
|
static cc_bool sides_fullBright, edges_fullBright;
|
||||||
static TextureLoc edges_lastTexLoc, sides_lastTexLoc;
|
static TextureLoc edges_lastTexLoc, sides_lastTexLoc;
|
||||||
|
|
||||||
static void EnvRenderer_RenderBorders(BlockID block, GfxResourceID vb, GfxResourceID tex, int count) {
|
static void RenderBorders(BlockID block, GfxResourceID vb, GfxResourceID tex, int count) {
|
||||||
if (!vb) return;
|
if (!vb) return;
|
||||||
|
|
||||||
Gfx_SetTexturing(true);
|
Gfx_SetTexturing(true);
|
||||||
@ -561,8 +561,7 @@ static void EnvRenderer_RenderBorders(BlockID block, GfxResourceID vb, GfxResour
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EnvRenderer_RenderMapSides(double delta) {
|
void EnvRenderer_RenderMapSides(double delta) {
|
||||||
EnvRenderer_RenderBorders(Env.SidesBlock,
|
RenderBorders(Env.SidesBlock, sides_vb, sides_tex, sides_vertices);
|
||||||
sides_vb, sides_tex, sides_vertices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnvRenderer_RenderMapEdges(double delta) {
|
void EnvRenderer_RenderMapEdges(double delta) {
|
||||||
@ -571,11 +570,10 @@ void EnvRenderer_RenderMapEdges(double delta) {
|
|||||||
int yVisible = min(0, Env_SidesHeight);
|
int yVisible = min(0, Env_SidesHeight);
|
||||||
if (Camera.CurrentPos.Y < yVisible && sides_vb) return;
|
if (Camera.CurrentPos.Y < yVisible && sides_vb) return;
|
||||||
|
|
||||||
EnvRenderer_RenderBorders(Env.EdgeBlock,
|
RenderBorders(Env.EdgeBlock, edges_vb, edges_tex, edges_vertices);
|
||||||
edges_vb, edges_tex, edges_vertices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_MakeBorderTex(GfxResourceID* texId, BlockID block) {
|
static void MakeBorderTex(GfxResourceID* texId, BlockID block) {
|
||||||
TextureLoc loc = Block_Tex(block, FACE_YMAX);
|
TextureLoc loc = Block_Tex(block, FACE_YMAX);
|
||||||
if (Gfx.LostContext) return;
|
if (Gfx.LostContext) return;
|
||||||
|
|
||||||
@ -589,7 +587,7 @@ static Rect2D EnvRenderer_Rect(int x, int y, int width, int height) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_CalcBorderRects(Rect2D* rects) {
|
static void CalcBorderRects(Rect2D* rects) {
|
||||||
int extent = Utils_AdjViewDist(Game_ViewDistance);
|
int extent = Utils_AdjViewDist(Game_ViewDistance);
|
||||||
rects[0] = EnvRenderer_Rect(-extent, -extent, extent + World.Width + extent, extent);
|
rects[0] = EnvRenderer_Rect(-extent, -extent, extent + World.Width + extent, extent);
|
||||||
rects[1] = EnvRenderer_Rect(-extent, World.Length, extent + World.Width + extent, extent);
|
rects[1] = EnvRenderer_Rect(-extent, World.Length, extent + World.Width + extent, extent);
|
||||||
@ -598,15 +596,15 @@ static void EnvRenderer_CalcBorderRects(Rect2D* rects) {
|
|||||||
rects[3] = EnvRenderer_Rect(World.Width, 0, extent, World.Length);
|
rects[3] = EnvRenderer_Rect(World.Width, 0, extent, World.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_UpdateBorderTextures(void) {
|
static void UpdateBorderTextures(void) {
|
||||||
EnvRenderer_MakeBorderTex(&edges_tex, Env.EdgeBlock);
|
MakeBorderTex(&edges_tex, Env.EdgeBlock);
|
||||||
EnvRenderer_MakeBorderTex(&sides_tex, Env.SidesBlock);
|
MakeBorderTex(&sides_tex, Env.SidesBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define Borders_HorOffset(block) (Blocks.RenderMinBB[block].X - Blocks.MinBB[block].X)
|
#define Borders_HorOffset(block) (Blocks.RenderMinBB[block].X - Blocks.MinBB[block].X)
|
||||||
#define Borders_YOffset(block) (Blocks.RenderMinBB[block].Y - Blocks.MinBB[block].Y)
|
#define Borders_YOffset(block) (Blocks.RenderMinBB[block].Y - Blocks.MinBB[block].Y)
|
||||||
|
|
||||||
static void EnvRenderer_DrawBorderX(int x, int z1, int z2, int y1, int y2, PackedCol col, VertexP3fT2fC4b** vertices) {
|
static void DrawBorderX(int x, int z1, int z2, int y1, int y2, PackedCol col, VertexP3fT2fC4b** vertices) {
|
||||||
int endZ = z2, endY = y2, startY = y1, axisSize = EnvRenderer_AxisSize();
|
int endZ = z2, endY = y2, startY = y1, axisSize = EnvRenderer_AxisSize();
|
||||||
float u2, v2;
|
float u2, v2;
|
||||||
VertexP3fT2fC4b* v = *vertices;
|
VertexP3fT2fC4b* v = *vertices;
|
||||||
@ -629,7 +627,7 @@ static void EnvRenderer_DrawBorderX(int x, int z1, int z2, int y1, int y2, Packe
|
|||||||
*vertices = v;
|
*vertices = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_DrawBorderZ(int z, int x1, int x2, int y1, int y2, PackedCol col, VertexP3fT2fC4b** vertices) {
|
static void DrawBorderZ(int z, int x1, int x2, int y1, int y2, PackedCol col, VertexP3fT2fC4b** vertices) {
|
||||||
int endX = x2, endY = y2, startY = y1, axisSize = EnvRenderer_AxisSize();
|
int endX = x2, endY = y2, startY = y1, axisSize = EnvRenderer_AxisSize();
|
||||||
float u2, v2;
|
float u2, v2;
|
||||||
VertexP3fT2fC4b* v = *vertices;
|
VertexP3fT2fC4b* v = *vertices;
|
||||||
@ -652,7 +650,7 @@ static void EnvRenderer_DrawBorderZ(int z, int x1, int x2, int y1, int y2, Packe
|
|||||||
*vertices = v;
|
*vertices = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_DrawBorderY(int x1, int z1, int x2, int z2, float y, PackedCol col, float offset, float yOffset, VertexP3fT2fC4b** vertices) {
|
static void DrawBorderY(int x1, int z1, int x2, int z2, float y, PackedCol col, float offset, float yOffset, VertexP3fT2fC4b** vertices) {
|
||||||
int endX = x2, endZ = z2, startZ = z1, axisSize = EnvRenderer_AxisSize();
|
int endX = x2, endZ = z2, startZ = z1, axisSize = EnvRenderer_AxisSize();
|
||||||
float u2, v2;
|
float u2, v2;
|
||||||
VertexP3fT2fC4b* v = *vertices;
|
VertexP3fT2fC4b* v = *vertices;
|
||||||
@ -676,7 +674,7 @@ static void EnvRenderer_DrawBorderY(int x1, int z1, int x2, int z2, float y, Pac
|
|||||||
*vertices = v;
|
*vertices = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_UpdateMapSides(void) {
|
static void UpdateMapSides(void) {
|
||||||
Rect2D rects[4], r;
|
Rect2D rects[4], r;
|
||||||
BlockID block;
|
BlockID block;
|
||||||
PackedCol col, white = PACKEDCOL_WHITE;
|
PackedCol col, white = PACKEDCOL_WHITE;
|
||||||
@ -692,18 +690,18 @@ static void EnvRenderer_UpdateMapSides(void) {
|
|||||||
block = Env.SidesBlock;
|
block = Env.SidesBlock;
|
||||||
|
|
||||||
if (Blocks.Draw[block] == DRAW_GAS) return;
|
if (Blocks.Draw[block] == DRAW_GAS) return;
|
||||||
EnvRenderer_CalcBorderRects(rects);
|
CalcBorderRects(rects);
|
||||||
|
|
||||||
sides_vertices = 0;
|
sides_vertices = 0;
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
r = rects[i];
|
r = rects[i];
|
||||||
sides_vertices += EnvRenderer_Vertices(r.Width, r.Height); /* YQuads outside */
|
sides_vertices += CalcNumVertices(r.Width, r.Height); /* YQuads outside */
|
||||||
}
|
}
|
||||||
|
|
||||||
y = Env_SidesHeight;
|
y = Env_SidesHeight;
|
||||||
sides_vertices += EnvRenderer_Vertices(World.Width, World.Length); /* YQuads beneath map */
|
sides_vertices += CalcNumVertices(World.Width, World.Length); /* YQuads beneath map */
|
||||||
sides_vertices += 2 * EnvRenderer_Vertices(World.Width, Math_AbsI(y)); /* ZQuads */
|
sides_vertices += 2 * CalcNumVertices(World.Width, Math_AbsI(y)); /* ZQuads */
|
||||||
sides_vertices += 2 * EnvRenderer_Vertices(World.Length, Math_AbsI(y)); /* XQuads */
|
sides_vertices += 2 * CalcNumVertices(World.Length, Math_AbsI(y)); /* XQuads */
|
||||||
|
|
||||||
ptr = v;
|
ptr = v;
|
||||||
if (sides_vertices > ENV_SMALL_VERTICES) {
|
if (sides_vertices > ENV_SMALL_VERTICES) {
|
||||||
@ -717,7 +715,7 @@ static void EnvRenderer_UpdateMapSides(void) {
|
|||||||
|
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
r = rects[i];
|
r = rects[i];
|
||||||
EnvRenderer_DrawBorderY(r.X, r.Y, r.X + r.Width, r.Y + r.Height, (float)y, col,
|
DrawBorderY(r.X, r.Y, r.X + r.Width, r.Y + r.Height, (float)y, col,
|
||||||
0, Borders_YOffset(block), &cur);
|
0, Borders_YOffset(block), &cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -725,17 +723,17 @@ static void EnvRenderer_UpdateMapSides(void) {
|
|||||||
y1 = 0; y2 = y;
|
y1 = 0; y2 = y;
|
||||||
if (y < 0) { y1 = y; y2 = 0; }
|
if (y < 0) { y1 = y; y2 = 0; }
|
||||||
|
|
||||||
EnvRenderer_DrawBorderY(0, 0, World.Width, World.Length, 0, col, 0, 0, &cur);
|
DrawBorderY(0, 0, World.Width, World.Length, 0, col, 0, 0, &cur);
|
||||||
EnvRenderer_DrawBorderZ(0, 0, World.Width, y1, y2, col, &cur);
|
DrawBorderZ(0, 0, World.Width, y1, y2, col, &cur);
|
||||||
EnvRenderer_DrawBorderZ(World.Length, 0, World.Width, y1, y2, col, &cur);
|
DrawBorderZ(World.Length, 0, World.Width, y1, y2, col, &cur);
|
||||||
EnvRenderer_DrawBorderX(0, 0, World.Length, y1, y2, col, &cur);
|
DrawBorderX(0, 0, World.Length, y1, y2, col, &cur);
|
||||||
EnvRenderer_DrawBorderX(World.Width, 0, World.Length, y1, y2, col, &cur);
|
DrawBorderX(World.Width, 0, World.Length, y1, y2, col, &cur);
|
||||||
|
|
||||||
sides_vb = Gfx_CreateVb(ptr, VERTEX_FORMAT_P3FT2FC4B, sides_vertices);
|
sides_vb = Gfx_CreateVb(ptr, VERTEX_FORMAT_P3FT2FC4B, sides_vertices);
|
||||||
if (sides_vertices > ENV_SMALL_VERTICES) Mem_Free(ptr);
|
if (sides_vertices > ENV_SMALL_VERTICES) Mem_Free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_UpdateMapEdges(void) {
|
static void UpdateMapEdges(void) {
|
||||||
Rect2D rects[4], r;
|
Rect2D rects[4], r;
|
||||||
BlockID block;
|
BlockID block;
|
||||||
PackedCol col, white = PACKEDCOL_WHITE;
|
PackedCol col, white = PACKEDCOL_WHITE;
|
||||||
@ -751,12 +749,12 @@ static void EnvRenderer_UpdateMapEdges(void) {
|
|||||||
block = Env.EdgeBlock;
|
block = Env.EdgeBlock;
|
||||||
|
|
||||||
if (Blocks.Draw[block] == DRAW_GAS) return;
|
if (Blocks.Draw[block] == DRAW_GAS) return;
|
||||||
EnvRenderer_CalcBorderRects(rects);
|
CalcBorderRects(rects);
|
||||||
|
|
||||||
edges_vertices = 0;
|
edges_vertices = 0;
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
r = rects[i];
|
r = rects[i];
|
||||||
edges_vertices += EnvRenderer_Vertices(r.Width, r.Height); /* YPlanes outside */
|
edges_vertices += CalcNumVertices(r.Width, r.Height); /* YPlanes outside */
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = v;
|
ptr = v;
|
||||||
@ -772,7 +770,7 @@ static void EnvRenderer_UpdateMapEdges(void) {
|
|||||||
y = (float)Env.EdgeHeight;
|
y = (float)Env.EdgeHeight;
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
r = rects[i];
|
r = rects[i];
|
||||||
EnvRenderer_DrawBorderY(r.X, r.Y, r.X + r.Width, r.Y + r.Height, y, col,
|
DrawBorderY(r.X, r.Y, r.X + r.Width, r.Y + r.Height, y, col,
|
||||||
Borders_HorOffset(block), Borders_YOffset(block), &cur);
|
Borders_HorOffset(block), Borders_YOffset(block), &cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -801,18 +799,18 @@ static void OnContextLost(void* obj) {
|
|||||||
|
|
||||||
static void UpdateAll(void) {
|
static void UpdateAll(void) {
|
||||||
DeleteVbs();
|
DeleteVbs();
|
||||||
EnvRenderer_UpdateMapSides();
|
UpdateMapSides();
|
||||||
EnvRenderer_UpdateMapEdges();
|
UpdateMapEdges();
|
||||||
EnvRenderer_UpdateClouds();
|
UpdateClouds();
|
||||||
EnvRenderer_UpdateSky();
|
UpdateSky();
|
||||||
EnvRenderer_UpdateSkybox();
|
UpdateSkybox();
|
||||||
EnvRenderer_UpdateFog();
|
EnvRenderer_UpdateFog();
|
||||||
|
|
||||||
if (Gfx.LostContext) return;
|
if (Gfx.LostContext) return;
|
||||||
/* TODO: Don't allocate unless used? */
|
/* TODO: Don't allocate unless used? */
|
||||||
weather_vb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FT2FC4B, WEATHER_VERTS_COUNT);
|
weather_vb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FT2FC4B, WEATHER_VERTS_COUNT);
|
||||||
/* TODO: Don't need to do this on every new map */
|
/* TODO: Don't need to do this on every new map */
|
||||||
EnvRenderer_UpdateBorderTextures();
|
UpdateBorderTextures();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnContextRecreated(void* obj) {
|
static void OnContextRecreated(void* obj) {
|
||||||
@ -852,37 +850,34 @@ static void OnTexturePackChanged(void* obj) {
|
|||||||
/* TODO: Find better way, really should delete them all here */
|
/* TODO: Find better way, really should delete them all here */
|
||||||
Gfx_DeleteTexture(&skybox_tex);
|
Gfx_DeleteTexture(&skybox_tex);
|
||||||
}
|
}
|
||||||
static void OnTerrainAtlasChanged(void* obj) {
|
static void OnTerrainAtlasChanged(void* obj) { UpdateBorderTextures(); }
|
||||||
EnvRenderer_UpdateBorderTextures();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void OnViewDistanceChanged(void* obj) { UpdateAll(); }
|
static void OnViewDistanceChanged(void* obj) { UpdateAll(); }
|
||||||
|
|
||||||
static void OnEnvVariableChanged(void* obj, int envVar) {
|
static void OnEnvVariableChanged(void* obj, int envVar) {
|
||||||
if (envVar == ENV_VAR_EDGE_BLOCK) {
|
if (envVar == ENV_VAR_EDGE_BLOCK) {
|
||||||
EnvRenderer_MakeBorderTex(&edges_tex, Env.EdgeBlock);
|
MakeBorderTex(&edges_tex, Env.EdgeBlock);
|
||||||
EnvRenderer_UpdateMapEdges();
|
UpdateMapEdges();
|
||||||
} else if (envVar == ENV_VAR_SIDES_BLOCK) {
|
} else if (envVar == ENV_VAR_SIDES_BLOCK) {
|
||||||
EnvRenderer_MakeBorderTex(&sides_tex, Env.SidesBlock);
|
MakeBorderTex(&sides_tex, Env.SidesBlock);
|
||||||
EnvRenderer_UpdateMapSides();
|
UpdateMapSides();
|
||||||
} else if (envVar == ENV_VAR_EDGE_HEIGHT || envVar == ENV_VAR_SIDES_OFFSET) {
|
} else if (envVar == ENV_VAR_EDGE_HEIGHT || envVar == ENV_VAR_SIDES_OFFSET) {
|
||||||
EnvRenderer_UpdateMapEdges();
|
UpdateMapEdges();
|
||||||
EnvRenderer_UpdateMapSides();
|
UpdateMapSides();
|
||||||
} else if (envVar == ENV_VAR_SUN_COL) {
|
} else if (envVar == ENV_VAR_SUN_COL) {
|
||||||
EnvRenderer_UpdateMapEdges();
|
UpdateMapEdges();
|
||||||
} else if (envVar == ENV_VAR_SHADOW_COL) {
|
} else if (envVar == ENV_VAR_SHADOW_COL) {
|
||||||
EnvRenderer_UpdateMapSides();
|
UpdateMapSides();
|
||||||
} else if (envVar == ENV_VAR_SKY_COL) {
|
} else if (envVar == ENV_VAR_SKY_COL) {
|
||||||
EnvRenderer_UpdateSky();
|
UpdateSky();
|
||||||
} else if (envVar == ENV_VAR_FOG_COL) {
|
} else if (envVar == ENV_VAR_FOG_COL) {
|
||||||
EnvRenderer_UpdateFog();
|
EnvRenderer_UpdateFog();
|
||||||
} else if (envVar == ENV_VAR_CLOUDS_COL) {
|
} else if (envVar == ENV_VAR_CLOUDS_COL) {
|
||||||
EnvRenderer_UpdateClouds();
|
UpdateClouds();
|
||||||
} else if (envVar == ENV_VAR_CLOUDS_HEIGHT) {
|
} else if (envVar == ENV_VAR_CLOUDS_HEIGHT) {
|
||||||
EnvRenderer_UpdateSky();
|
UpdateSky();
|
||||||
EnvRenderer_UpdateClouds();
|
UpdateClouds();
|
||||||
} else if (envVar == ENV_VAR_SKYBOX_COL) {
|
} else if (envVar == ENV_VAR_SKYBOX_COL) {
|
||||||
EnvRenderer_UpdateSkybox();
|
UpdateSkybox();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user