mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-24 05:10:42 -04:00
Partially port EnvRenderer to C.
This commit is contained in:
parent
a257955998
commit
4cd17f8aab
@ -58,8 +58,8 @@ namespace ClassicalSharp.Map {
|
||||
|
||||
int baseIndex = (y * length + z) * width + x;
|
||||
for (int i = 0; i < chunk.Length; i++) {
|
||||
int bx = i & 0xF, by = (i >> 8) & 0xF, bz = (i >> 4) & 0xF;
|
||||
int index = baseIndex + (by * length + bz) * width + bx;
|
||||
int xx = i & 0xF, yy = (i >> 8) & 0xF, zz = (i >> 4) & 0xF;
|
||||
int index = baseIndex + (yy * length + zz) * width + xx;
|
||||
|
||||
if (blocks[index] != customTile) continue;
|
||||
blocks[index] = chunk[i];
|
||||
|
@ -37,7 +37,7 @@ void AABB_Offset(AABB* result, AABB* bb, Vector3* amount);
|
||||
bool AABB_Intersects(AABB* bb, AABB* other);
|
||||
|
||||
/* Determines whether this AABB entirely contains the AABB on all axes. */
|
||||
bool AAAB_Contains(AABB* parent, AABB* child);
|
||||
bool AABB_Contains(AABB* parent, AABB* child);
|
||||
|
||||
/* Determines whether this AABB entirely contains the coordinates on all axes. */
|
||||
bool AABB_ContainsPoint(AABB* parent, Vector3* P);
|
||||
|
@ -178,7 +178,7 @@ void BordersRenderer_RebuildSides(Int32 y, Int32 axisSize) {
|
||||
VertexP3fT2fC4b* ptr = v;
|
||||
if (borders_sidesVertices > 4096) {
|
||||
ptr = Platform_MemAlloc(borders_sidesVertices * sizeof(VertexP3fT2fC4b));
|
||||
if (ptr == NULL) ErrorHandler_Fail("BordersRenderer_RebuildSides - failed to allocate memory");
|
||||
if (ptr == NULL) ErrorHandler_Fail("BordersRenderer_Sides - failed to allocate memory");
|
||||
}
|
||||
VertexP3fT2fC4b* temp = ptr;
|
||||
|
||||
@ -219,7 +219,7 @@ void BordersRenderer_RebuildEdges(Int32 y, Int32 axisSize) {
|
||||
VertexP3fT2fC4b* ptr = v;
|
||||
if (borders_edgesVertices > 4096) {
|
||||
ptr = Platform_MemAlloc(borders_edgesVertices * sizeof(VertexP3fT2fC4b));
|
||||
if (ptr == NULL) ErrorHandler_Fail("BordersRenderer_RebuildEdges - failed to allocate memory");
|
||||
if (ptr == NULL) ErrorHandler_Fail("BordersRenderer_Edges - failed to allocate memory");
|
||||
}
|
||||
VertexP3fT2fC4b* temp = ptr;
|
||||
|
||||
|
@ -25,16 +25,12 @@ void BordersRenderer_RenderEdges(Real64 delta);
|
||||
|
||||
|
||||
static void BordersRenderer_Init(void);
|
||||
|
||||
static void BordersRenderer_Free(void);
|
||||
|
||||
static void BordersRenderer_Reset(void);
|
||||
|
||||
|
||||
static void BordersRenderer_EnvVariableChanged(EnvVar envVar);
|
||||
|
||||
static void BordersRenderer_ContextLost(void);
|
||||
|
||||
static void BordersRenderer_ContextRecreated(void);
|
||||
|
||||
|
||||
|
@ -186,6 +186,7 @@
|
||||
<ClInclude Include="Drawer.h" />
|
||||
<ClInclude Include="Entity.h" />
|
||||
<ClInclude Include="EntityEvents.h" />
|
||||
<ClInclude Include="EnvRenderer.h" />
|
||||
<ClInclude Include="ErrorHandler.h" />
|
||||
<ClInclude Include="FrustumCulling.h" />
|
||||
<ClInclude Include="GameProps.h" />
|
||||
@ -244,6 +245,7 @@
|
||||
<ClCompile Include="DefaultSet.c" />
|
||||
<ClCompile Include="Bitmap.c" />
|
||||
<ClCompile Include="Drawer.c" />
|
||||
<ClCompile Include="EnvRenderer.c" />
|
||||
<ClCompile Include="EventHandler.c" />
|
||||
<ClCompile Include="ExtMath.c" />
|
||||
<ClCompile Include="FrustumCulling.c" />
|
||||
|
@ -324,6 +324,9 @@
|
||||
<ClInclude Include="BordersRenderer.h">
|
||||
<Filter>Header Files\Rendering\Env</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="EnvRenderer.h">
|
||||
<Filter>Header Files\Rendering\Env</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="NotchyGenerator.c">
|
||||
@ -458,5 +461,8 @@
|
||||
<ClCompile Include="BordersRenderer.c">
|
||||
<Filter>Source Files\Rendering\Env</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="EnvRenderer.c">
|
||||
<Filter>Source Files\Rendering\Env</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
190
src/Client/EnvRenderer.c
Normal file
190
src/Client/EnvRenderer.c
Normal file
@ -0,0 +1,190 @@
|
||||
#include "EnvRenderer.h"
|
||||
#include "ExtMath.h"
|
||||
#include "World.h"
|
||||
#include "WorldEnv.h"
|
||||
#include "GraphicsEnums.h"
|
||||
#include "Funcs.h"
|
||||
#include "GraphicsAPI.h"
|
||||
#include "GameProps.h"
|
||||
#include "Matrix.h"
|
||||
#include "AABB.h"
|
||||
#include "Block.h"
|
||||
#include "Platform.h"
|
||||
|
||||
Int32 env_cloudsVb = -1, env_skyVb = -1, env_cloudsTex = -1;
|
||||
Int32 env_cloudVertices, env_skyVertices;
|
||||
|
||||
|
||||
BlockID EnvRenderer_BlockOn(Real32* fogDensity, PackedCol* fogCol) {
|
||||
Vector3 pos = Game_CurrentCameraPos;
|
||||
Vector3I coords;
|
||||
Vector3I_Floor(&coords, &pos); /* coords = floor(pos); */
|
||||
Vector3I_ToVector3(&pos, &coords); /* pos = coords; */
|
||||
|
||||
BlockID block = World_SafeGetBlock_3I(coords);
|
||||
AABB blockBB;
|
||||
Vector3_Add(&blockBB.Min, &pos, &Block_MinBB[block]);
|
||||
Vector3_Add(&blockBB.Max, &pos, &Block_MaxBB[block]);
|
||||
|
||||
if (AABB_ContainsPoint(&blockBB, &pos) && Block_FogDensity[block] != 0.0f) {
|
||||
*fogDensity = Block_FogDensity[block];
|
||||
*fogCol = Block_FogColour[block];
|
||||
} else {
|
||||
*fogDensity = 0.0f;
|
||||
// Blend fog and sky together
|
||||
Real32 blend = EnvRenderer_BlendFactor(Game_ViewDistance);
|
||||
*fogCol = PackedCol_Lerp(WorldEnv_FogCol, WorldEnv_SkyCol, blend);
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
Real32 EnvRenderer_BlendFactor(Real32 x) {
|
||||
/* return -0.05 + 0.22 * Math_Log(Math_Pow(x, 0.25f)); */
|
||||
double blend = -0.13 + 0.28 * Math_Log(Math_Pow(x, 0.25f));
|
||||
if (blend < 0) blend = 0;
|
||||
if (blend > 1) blend = 1;
|
||||
return blend;
|
||||
}
|
||||
|
||||
|
||||
void EnvRenderer_RenderClouds(Real64 delta) {
|
||||
if (WorldEnv_CloudsHeight < -2000) return;
|
||||
Real64 time = Game_Accumulator;
|
||||
Real32 offset = (Real32)(time / 2048.0f * 0.6f * WorldEnv_CloudsSpeed);
|
||||
|
||||
Gfx_SetMatrixMode(MatrixType_Texture);
|
||||
Matrix matrix = Matrix_Identity; matrix.Row3.X = offset; // translate X axis
|
||||
Gfx_LoadMatrix(&matrix);
|
||||
Gfx_SetMatrixMode(MatrixType_Modelview);
|
||||
|
||||
Gfx_SetAlphaTest(true);
|
||||
Gfx_SetTexturing(true);
|
||||
Gfx_BindTexture(env_cloudsTex);
|
||||
Gfx_SetBatchFormat(VertexFormat_P3fT2fC4b);
|
||||
Gfx_BindVb(env_cloudsVb);
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(env_cloudVertices * 6 / 4, 0);
|
||||
Gfx_SetAlphaTest(false);
|
||||
Gfx_SetTexturing(false);
|
||||
|
||||
Gfx_SetMatrixMode(MatrixType_Texture);
|
||||
Gfx_LoadIdentityMatrix();
|
||||
Gfx_SetMatrixMode(MatrixType_Modelview);
|
||||
}
|
||||
|
||||
void EnvRenderer_UpdateFog(void) {
|
||||
if (World_Blocks == NULL) return;
|
||||
PackedCol fogCol = PackedCol_White;
|
||||
Real32 fogDensity = 0;
|
||||
BlockID block = EnvRenderer_BlockOn(&fogDensity, &fogCol);
|
||||
|
||||
if (fogDensity != 0) {
|
||||
Gfx_SetFogMode(Fog_Exp);
|
||||
Gfx_SetFogDensity(fogDensity);
|
||||
} else if (WorldEnv_ExpFog) {
|
||||
Gfx_SetFogMode(Fog_Exp);
|
||||
/* f = 1-z/end f = e^(-dz)
|
||||
solve for f = 0.01 gives:
|
||||
e^(-dz)=0.01 --> -dz=ln(0.01)
|
||||
0.99=z/end --> z=end*0.99
|
||||
therefore
|
||||
d = -ln(0.01)/(end*0.99) */
|
||||
Real32 density = -Math_Log(0.01f) / (Game_ViewDistance * 0.99f);
|
||||
Gfx_SetFogDensity(density);
|
||||
} else {
|
||||
Gfx_SetFogMode(Fog_Linear);
|
||||
Gfx_SetFogEnd(Game_ViewDistance);
|
||||
}
|
||||
Gfx_ClearColour(fogCol);
|
||||
Gfx_SetFogColour(fogCol);
|
||||
}
|
||||
|
||||
void EnvRenderer_ResetClouds(void) {
|
||||
if (World_Blocks == NULL || Gfx_LostContext) return;
|
||||
Gfx_DeleteVb(&env_cloudsVb);
|
||||
EnvRenderer_RebuildClouds((Int32)Game_ViewDistance, EnvRenderer_Legacy ? 128 : 65536);
|
||||
}
|
||||
|
||||
void EnvRenderer_ResetSky(void) {
|
||||
if (World_Blocks == NULL || Gfx_LostContext) return;
|
||||
Gfx_DeleteVb(&env_skyVb);
|
||||
EnvRenderer_RebuildSky((Int32)Game_ViewDistance, EnvRenderer_Legacy ? 128 : 65536);
|
||||
}
|
||||
|
||||
void EnvRenderer_RebuildClouds(Int32 extent, Int32 axisSize) {
|
||||
extent = Math_AdjViewDist(extent);
|
||||
Int32 x1 = -extent, x2 = World_Width + extent;
|
||||
Int32 z1 = -extent, z2 = World_Length + extent;
|
||||
env_cloudVertices = Math_CountVertices(x2 - x1, z2 - z1, axisSize);
|
||||
|
||||
VertexP3fT2fC4b v[4096];
|
||||
VertexP3fT2fC4b* ptr = v;
|
||||
if (env_cloudVertices > 4096) {
|
||||
ptr = Platform_MemAlloc(env_cloudVertices * sizeof(VertexP3fT2fC4b));
|
||||
if (ptr == NULL) ErrorHandler_Fail("EnvRenderer_Clouds - failed to allocate memory");
|
||||
}
|
||||
|
||||
EnvRenderer_DrawCloudsY(x1, z1, x2, z2, WorldEnv_CloudsHeight, axisSize, WorldEnv_CloudsCol, ptr);
|
||||
env_cloudsVb = Gfx_CreateVb(ptr, VertexFormat_P3fT2fC4b, env_cloudVertices);
|
||||
|
||||
if (env_cloudVertices > 4096) Platform_MemFree(ptr);
|
||||
}
|
||||
|
||||
void EnvRenderer_RebuildSky(Int32 extent, Int32 axisSize) {
|
||||
extent = Math_AdjViewDist(extent);
|
||||
Int32 x1 = -extent, x2 = World_Width + extent;
|
||||
Int32 z1 = -extent, z2 = World_Length + extent;
|
||||
env_skyVertices = Math_CountVertices(x2 - x1, z2 - z1, axisSize);
|
||||
|
||||
VertexP3fC4b v[4096];
|
||||
VertexP3fC4b* ptr = v;
|
||||
if (env_skyVertices > 4096) {
|
||||
ptr = Platform_MemAlloc(env_skyVertices * sizeof(VertexP3fC4b));
|
||||
if (ptr == NULL) ErrorHandler_Fail("EnvRenderer_Sky - failed to allocate memory");
|
||||
}
|
||||
|
||||
Int32 height = max((World_Height + 2) + 6, WorldEnv_CloudsHeight + 6);
|
||||
EnvRenderer_DrawSkyY(x1, z1, x2, z2, height, axisSize, WorldEnv_SkyCol, ptr);
|
||||
env_skyVb = Gfx_CreateVb(ptr, VertexFormat_P3fC4b, env_skyVertices);
|
||||
|
||||
if (env_skyVertices > 4096) Platform_MemFree(ptr);
|
||||
}
|
||||
|
||||
void EnvRenderer_DrawSkyY(Int32 x1, Int32 z1, Int32 x2, Int32 z2, Int32 y, Int32 axisSize, PackedCol col, VertexP3fC4b* vertices) {
|
||||
Int32 endX = x2, endZ = z2, startZ = z1;
|
||||
|
||||
for (; x1 < endX; x1 += axisSize) {
|
||||
x2 = x1 + axisSize;
|
||||
if (x2 > endX) x2 = endX;
|
||||
z1 = startZ;
|
||||
for (; z1 < endZ; z1 += axisSize) {
|
||||
z2 = z1 + axisSize;
|
||||
if (z2 > endZ) z2 = endZ;
|
||||
|
||||
VertexP3fC4b_Set(vertices, x1, y, z1, col); vertices++;
|
||||
VertexP3fC4b_Set(vertices, x1, y, z2, col); vertices++;
|
||||
VertexP3fC4b_Set(vertices, x2, y, z2, col); vertices++;
|
||||
VertexP3fC4b_Set(vertices, x2, y, z1, col); vertices++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EnvRenderer_DrawCloudsY(Int32 x1, Int32 z1, Int32 x2, Int32 z2, Int32 y, Int32 axisSize, PackedCol col, VertexP3fT2fC4b* vertices) {
|
||||
Int32 endX = x2, endZ = z2, startZ = z1;
|
||||
/* adjust range so that largest negative uv coordinate is shifted to 0 or above. */
|
||||
Real32 offset = Math_CeilDiv(-x1, 2048);
|
||||
|
||||
for (; x1 < endX; x1 += axisSize) {
|
||||
x2 = x1 + axisSize;
|
||||
if (x2 > endX) x2 = endX;
|
||||
z1 = startZ;
|
||||
for (; z1 < endZ; z1 += axisSize) {
|
||||
z2 = z1 + axisSize;
|
||||
if (z2 > endZ) z2 = endZ;
|
||||
|
||||
VertexP3fT2fC4b_Set(vertices, x1, y + 0.1f, z1, x1 / 2048.0f + offset, z1 / 2048.0f + offset, col); vertices++;
|
||||
VertexP3fT2fC4b_Set(vertices, x1, y + 0.1f, z2, x1 / 2048.0f + offset, z2 / 2048.0f + offset, col); vertices++;
|
||||
VertexP3fT2fC4b_Set(vertices, x2, y + 0.1f, z2, x2 / 2048.0f + offset, z2 / 2048.0f + offset, col); vertices++;
|
||||
VertexP3fT2fC4b_Set(vertices, x2, y + 0.1f, z1, x2 / 2048.0f + offset, z1 / 2048.0f + offset, col); vertices++;
|
||||
}
|
||||
}
|
||||
}
|
63
src/Client/EnvRenderer.h
Normal file
63
src/Client/EnvRenderer.h
Normal file
@ -0,0 +1,63 @@
|
||||
#ifndef CS_ENVRENDERER_H
|
||||
#define CS_ENVRENDERER_H
|
||||
#include "Typedefs.h"
|
||||
#include "GameStructs.h"
|
||||
#include "VertexStructs.h"
|
||||
#include "WorldEvents.h"
|
||||
/* Renders environment of the map. (clouds, sky, fog)
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
/* Creates game component implementation. */
|
||||
IGameComponent EnvRenderer_MakeGameComponent(void);
|
||||
|
||||
/* Whether environment renderer breaks quads up into smaller 512x512 quads. */
|
||||
bool EnvRenderer_Legacy;
|
||||
|
||||
/* Whether environment renderer does not render sky, clouds, or smooth fog. */
|
||||
bool EnvRenderer_Minimal;
|
||||
|
||||
/* Sets whather legacy renderering mode is used. */
|
||||
void EnvRenderer_UseLegacyMode(bool legacy);
|
||||
|
||||
/* Sets whather minimal renderering mode is used. */
|
||||
void EnvRenderer_UseMinimalMode(bool minimal);
|
||||
|
||||
/* Renders the environemnt of the map. */
|
||||
void EnvRenderer_Render(Real64 delta);
|
||||
|
||||
static void EnvRenderer_Init();
|
||||
static void EnvRenderer_Reset();
|
||||
static void EnvRenderer_OnNewMapLoaded();
|
||||
static void EnvRenderer_Free();
|
||||
|
||||
static BlockID EnvRenderer_BlockOn(Real32* fogDensity, PackedCol* fogCol);
|
||||
|
||||
static Real32 EnvRenderer_BlendFactor(Real32 x);
|
||||
|
||||
|
||||
static void EnvVariableChanged(EnvVar envVar);
|
||||
static void EnvRenderer_ContextLost();
|
||||
static void EnvRenderer_ContextRecreated();
|
||||
|
||||
|
||||
static void EnvRenderer_RenderMainEnv(Real64 deltaTime);
|
||||
|
||||
static void EnvRenderer_ResetAllEnv();
|
||||
|
||||
static void EnvRenderer_RenderClouds(Real64 delta);
|
||||
|
||||
static void EnvRenderer_UpdateFog();
|
||||
|
||||
static void EnvRenderer_ResetClouds();
|
||||
|
||||
static void EnvRenderer_ResetSky();
|
||||
|
||||
static void EnvRenderer_RebuildClouds(Int32 extent, Int32 axisSize);
|
||||
|
||||
static void EnvRenderer_RebuildSky(Int32 extent, Int32 axisSize);
|
||||
|
||||
static void EnvRenderer_DrawSkyY(Int32 x1, Int32 z1, Int32 x2, Int32 z2, Int32 y, Int32 axisSize, PackedCol col, VertexP3fC4b* vertices);
|
||||
|
||||
static void EnvRenderer_DrawCloudsY(Int32 x1, Int32 z1, Int32 x2, Int32 z2, Int32 y, Int32 axisSize, PackedCol col, VertexP3fT2fC4b* vertices);
|
||||
#endif
|
@ -9,6 +9,10 @@ Int32 Math_CeilDiv(Int32 a, Int32 b) {
|
||||
return a / b + (a % b != 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
Real32 Math_Lerp(Real32 a, Real32 b, Real32 t) {
|
||||
return a + (b - a) * t;
|
||||
}
|
||||
|
||||
Int32 Math_NextPowOf2(Int32 value) {
|
||||
Int32 next = 1;
|
||||
while (value > next)
|
||||
|
@ -14,6 +14,10 @@
|
||||
|
||||
#define Math_Abs(x) abs(x)
|
||||
|
||||
#define Math_Pow(x, y) powf(x, y)
|
||||
|
||||
#define Math_Log(x) logf(x)
|
||||
|
||||
#define Math_Sin(x) sinf(x)
|
||||
|
||||
#define Math_Cos(x) cosf(x)
|
||||
@ -28,6 +32,9 @@ Int32 Math_Floor(Real32 value);
|
||||
/* Performs rounding upwards integer division.*/
|
||||
Int32 Math_CeilDiv(Int32 a, Int32 b);
|
||||
|
||||
/* Performs linear interpolation between two values. */
|
||||
Real32 Math_Lerp(Real32 a, Real32 b, Real32 t);
|
||||
|
||||
/* Returns the next highest power of 2 that is greater or equal to the given value. */
|
||||
Int32 Math_NextPowOf2(Int32 value);
|
||||
|
||||
|
@ -45,10 +45,10 @@ void GfxCommon_UpdateDynamicIndexedVb(Int32 drawMode, Int32 vb, void* vertices,
|
||||
void GfxCommon_Draw2DFlat(Real32 x, Real32 y, Real32 width, Real32 height,
|
||||
PackedCol col) {
|
||||
VertexP3fC4b quadVerts[4];
|
||||
VertexP3C4b_Set(&quadVerts[0], x, y, 0, col);
|
||||
VertexP3C4b_Set(&quadVerts[1], x + width, y, 0, col);
|
||||
VertexP3C4b_Set(&quadVerts[2], x + width, y + height, 0, col);
|
||||
VertexP3C4b_Set(&quadVerts[3], x, y + height, 0, col);
|
||||
VertexP3fC4b_Set(&quadVerts[0], x, y, 0, col);
|
||||
VertexP3fC4b_Set(&quadVerts[1], x + width, y, 0, col);
|
||||
VertexP3fC4b_Set(&quadVerts[2], x + width, y + height, 0, col);
|
||||
VertexP3fC4b_Set(&quadVerts[3], x, y + height, 0, col);
|
||||
|
||||
Gfx_SetBatchFormat(VertexFormat_P3fC4b);
|
||||
GfxCommon_UpdateDynamicIndexedVb(DrawMode_Triangles, GfxCommon_quadVb, quadVerts, 4);
|
||||
@ -57,10 +57,10 @@ void GfxCommon_Draw2DFlat(Real32 x, Real32 y, Real32 width, Real32 height,
|
||||
void GfxCommon_Draw2DGradient(Real32 x, Real32 y, Real32 width, Real32 height,
|
||||
PackedCol topCol, PackedCol bottomCol) {
|
||||
VertexP3fC4b quadVerts[4];
|
||||
VertexP3C4b_Set(&quadVerts[0], x, y, 0, topCol);
|
||||
VertexP3C4b_Set(&quadVerts[1], x + width, y, 0, topCol);
|
||||
VertexP3C4b_Set(&quadVerts[2], x + width, y + height, 0, bottomCol);
|
||||
VertexP3C4b_Set(&quadVerts[3], x, y + height, 0, bottomCol);
|
||||
VertexP3fC4b_Set(&quadVerts[0], x, y, 0, topCol);
|
||||
VertexP3fC4b_Set(&quadVerts[1], x + width, y, 0, topCol);
|
||||
VertexP3fC4b_Set(&quadVerts[2], x + width, y + height, 0, bottomCol);
|
||||
VertexP3fC4b_Set(&quadVerts[3], x, y + height, 0, bottomCol);
|
||||
|
||||
Gfx_SetBatchFormat(VertexFormat_P3fC4b);
|
||||
GfxCommon_UpdateDynamicIndexedVb(DrawMode_Triangles, GfxCommon_quadVb, quadVerts, 4);
|
||||
|
@ -51,6 +51,7 @@ PackedCol Lighting_Col_YBottom_Fast(Int32 x, Int32 y, Int32 z);
|
||||
PackedCol Lighting_Col_XSide_Fast(Int32 x, Int32 y, Int32 z);
|
||||
PackedCol Lighting_Col_ZSide_Fast(Int32 x, Int32 y, Int32 z);
|
||||
|
||||
|
||||
static void Lighting_Free(void);
|
||||
static void Lighting_Reset(void);
|
||||
static void Lighting_OnNewMap(void);
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "PackedCol.h"
|
||||
#include "ExtMath.h"
|
||||
|
||||
PackedCol PackedCol_Create4(UInt8 r, UInt8 g, UInt8 b, UInt8 a) {
|
||||
PackedCol col;
|
||||
@ -19,6 +20,13 @@ PackedCol PackedCol_Scale(PackedCol value, Real32 t) {
|
||||
return value;
|
||||
}
|
||||
|
||||
PackedCol PackedCol_Lerp(PackedCol a, PackedCol b, Real32 t) {
|
||||
a.R = (UInt8)Math_Lerp(a.R, b.R, t);
|
||||
a.G = (UInt8)Math_Lerp(a.G, b.G, t);
|
||||
a.B = (UInt8)Math_Lerp(a.B, b.B, t);
|
||||
return a;
|
||||
}
|
||||
|
||||
void PackedCol_GetShaded(PackedCol normal, PackedCol* xSide, PackedCol* zSide, PackedCol* yBottom) {
|
||||
*xSide = PackedCol_Scale(normal, PackedCol_ShadeX);
|
||||
*zSide = PackedCol_Scale(normal, PackedCol_ShadeZ);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef CS_PACKEDCOL_H
|
||||
#define CS_PACKEDCOL_H
|
||||
#include "Typedefs.h"
|
||||
/* Manipulates an ARGB colour, in a format suitable for the native graphics api.
|
||||
/* Manipulates an ARGB colour, in a format suitable for the native 3d graphics api.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
@ -30,6 +30,9 @@ PackedCol PackedCol_Create3(UInt8 r, UInt8 g, UInt8 b);
|
||||
/* Multiplies the RGB components by t, where t is in [0, 1] */
|
||||
PackedCol PackedCol_Scale(PackedCol value, Real32 t);
|
||||
|
||||
/* Linearly interpolates the RGB components of both colours by t, where t is in [0, 1] */
|
||||
PackedCol PackedCol_Lerp(PackedCol a, PackedCol b, Real32 t);
|
||||
|
||||
|
||||
#define PackedCol_ShadeX 0.6f
|
||||
#define PackedCol_ShadeZ 0.8f
|
||||
|
@ -32,10 +32,6 @@ void Platform_MemCpy(void* dst, void* src, UInt32 numBytes);
|
||||
/* Logs a message to console (if attached). Implictly puts each entry on a newline. */
|
||||
void Platform_Log(String message);
|
||||
|
||||
/* Generates a new random uuid / guid. */
|
||||
void Platform_NewUuid(UInt8* uuid);
|
||||
/* TODO: Not use OS func for this. just need OS RNG and make a random UUID. */
|
||||
|
||||
/* Gets the current time, in UTC timezone. */
|
||||
DateTime Platform_CurrentUTCTime(void);
|
||||
|
||||
|
@ -9,9 +9,12 @@
|
||||
|
||||
typedef Int64 Random;
|
||||
|
||||
/* Initalises the random number generator with a base seed. */
|
||||
/* Initalises the random number generator with an initial given seed. */
|
||||
void Random_Init(Random* rnd, Int32 seed);
|
||||
|
||||
/* Initalises the random number generator with an initial see based on current time. */
|
||||
void Random_InitFromCurrentTime(Random* rnd);
|
||||
|
||||
/* Returns a random number between min inclusive and max exclusive. */
|
||||
Int32 Random_Range(Random* rnd, Int32 min, Int32 max);
|
||||
|
||||
|
@ -46,27 +46,27 @@ void SelectionBox_Render(SelectionBox* box, VertexP3fC4b** vertices, VertexP3fC4
|
||||
void SelectionBox_VerQuad(VertexP3fC4b** vertices, PackedCol col,
|
||||
Real32 x1, Real32 y1, Real32 z1, Real32 x2, Real32 y2, Real32 z2) {
|
||||
VertexP3fC4b* ptr = *vertices;
|
||||
VertexP3C4b_Set(ptr, x1, y1, z1, col); ptr++;
|
||||
VertexP3C4b_Set(ptr, x1, y2, z1, col); ptr++;
|
||||
VertexP3C4b_Set(ptr, x2, y2, z2, col); ptr++;
|
||||
VertexP3C4b_Set(ptr, x2, y1, z2, col); ptr++;
|
||||
VertexP3fC4b_Set(ptr, x1, y1, z1, col); ptr++;
|
||||
VertexP3fC4b_Set(ptr, x1, y2, z1, col); ptr++;
|
||||
VertexP3fC4b_Set(ptr, x2, y2, z2, col); ptr++;
|
||||
VertexP3fC4b_Set(ptr, x2, y1, z2, col); ptr++;
|
||||
*vertices = ptr;
|
||||
}
|
||||
|
||||
void SelectionBox_HorQuad(VertexP3fC4b** vertices, PackedCol col,
|
||||
Real32 x1, Real32 z1, Real32 x2, Real32 z2, Real32 y) {
|
||||
VertexP3fC4b* ptr = *vertices;
|
||||
VertexP3C4b_Set(ptr, x1, y, z1, col); ptr++;
|
||||
VertexP3C4b_Set(ptr, x1, y, z2, col); ptr++;
|
||||
VertexP3C4b_Set(ptr, x2, y, z2, col); ptr++;
|
||||
VertexP3C4b_Set(ptr, x2, y, z1, col); ptr++;
|
||||
VertexP3fC4b_Set(ptr, x1, y, z1, col); ptr++;
|
||||
VertexP3fC4b_Set(ptr, x1, y, z2, col); ptr++;
|
||||
VertexP3fC4b_Set(ptr, x2, y, z2, col); ptr++;
|
||||
VertexP3fC4b_Set(ptr, x2, y, z1, col); ptr++;
|
||||
*vertices = ptr;
|
||||
}
|
||||
|
||||
void SelectionBox_Line(VertexP3fC4b** vertices, PackedCol col,
|
||||
Real32 x1, Real32 y1, Real32 z1, Real32 x2, Real32 y2, Real32 z2) {
|
||||
VertexP3fC4b* ptr = *vertices;
|
||||
VertexP3C4b_Set(ptr, x1, y1, z1, col); ptr++;
|
||||
VertexP3C4b_Set(ptr, x2, y2, z2, col); ptr++;
|
||||
VertexP3fC4b_Set(ptr, x1, y1, z1, col); ptr++;
|
||||
VertexP3fC4b_Set(ptr, x2, y2, z2, col); ptr++;
|
||||
*vertices = ptr;
|
||||
}
|
@ -10,6 +10,7 @@
|
||||
#include "TextureRec.h"
|
||||
#include "VertexStructs.h"
|
||||
#include "WorldEnv.h"
|
||||
#include "EnvRenderer.h"
|
||||
|
||||
Int32 skybox_tex, skybox_vb = -1;
|
||||
#define skybox_count (6 * 4)
|
||||
@ -24,7 +25,7 @@ IGameComponent SkyboxRenderer_MakeGameComponent(void) {
|
||||
}
|
||||
|
||||
bool SkyboxRenderer_ShouldRender(void) {
|
||||
return skybox_tex > 0 && !EnvRenderer_IsMinimal;
|
||||
return skybox_tex > 0 && !EnvRenderer_Minimal;
|
||||
}
|
||||
|
||||
void SkyboxRenderer_Init(void) {
|
||||
|
@ -16,9 +16,7 @@ void SkyboxRenderer_Render(Real64 deltaTime);
|
||||
|
||||
|
||||
static void SkyboxRenderer_Init(void);
|
||||
|
||||
static void SkyboxRenderer_Reset(void);
|
||||
|
||||
static void SkyboxRenderer_Free(void);
|
||||
|
||||
|
||||
@ -26,12 +24,8 @@ static void SkyboxRenderer_MakeVb(void);
|
||||
|
||||
|
||||
static void SkyboxRenderer_EnvVariableChanged(EnvVar envVar);
|
||||
|
||||
static void SkyboxRenderer_TexturePackChanged(void);
|
||||
|
||||
static void SkyboxRenderer_FileChanged(Stream* stream);
|
||||
|
||||
static void SkyboxRenderer_ContextLost(void);
|
||||
|
||||
static void SkyboxRenderer_ContextRecreated(void);
|
||||
#endif
|
@ -1,6 +1,6 @@
|
||||
#include "VertexStructs.h"
|
||||
|
||||
void VertexP3C4b_Set(VertexP3fC4b* target, Real32 x, Real32 y, Real32 z, PackedCol col) {
|
||||
void VertexP3fC4b_Set(VertexP3fC4b* target, Real32 x, Real32 y, Real32 z, PackedCol col) {
|
||||
target->X = x; target->Y = y; target->Z = z;
|
||||
target->Colour = col;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ typedef struct VertexP3fC4b {
|
||||
PackedCol Colour;
|
||||
} VertexP3fC4b;
|
||||
|
||||
void VertexP3C4b_Set(VertexP3fC4b* target, Real32 x, Real32 y, Real32 z, PackedCol col);
|
||||
void VertexP3fC4b_Set(VertexP3fC4b* target, Real32 x, Real32 y, Real32 z, PackedCol col);
|
||||
|
||||
/* 3 * 4 + 4 * 1 */
|
||||
#define VertexP3fC4b_Size 16
|
||||
|
@ -18,9 +18,7 @@ void WeatherRenderer_Render(Real64 deltaTime);
|
||||
|
||||
|
||||
static void WeatherRenderer_Init(void);
|
||||
|
||||
static void WeatherRenderer_Reset(void);
|
||||
|
||||
static void WeatherRenderer_Free(void);
|
||||
|
||||
|
||||
@ -34,8 +32,6 @@ static Int32 WeatherRenderer_CalcHeightAt(Int32 x, Int32 maxY, Int32 z, Int32 in
|
||||
|
||||
|
||||
static void WeatherRenderer_FileChanged(Stream* stream);
|
||||
|
||||
static void WeatherRenderer_ContextLost(void);
|
||||
|
||||
static void WeatherRenderer_ContextRecreated(void);
|
||||
#endif
|
@ -47,7 +47,7 @@ void Platform_NewUuid(UInt8* uuid) {
|
||||
Platform_MemCpy(uuid, &guid, 16);
|
||||
}
|
||||
|
||||
/* It's not worth making this an actual function, just use an inline macro.. */
|
||||
/* It's not worth making this an actual function, just use an inline macro. */
|
||||
#define Platform_ReturnDateTime(sysTime)\
|
||||
DateTime time;\
|
||||
time.Year = sysTime.wYear;\
|
||||
|
@ -5,11 +5,23 @@
|
||||
#include "WorldEnv.h"
|
||||
#include "Platform.h"
|
||||
#include "WorldEvents.h"
|
||||
#include "Random.h"
|
||||
|
||||
void World_Reset() {
|
||||
World_Width = 0; World_Height = 0; World_Length = 0;
|
||||
World_Blocks = NULL; World_BlocksSize = 0;
|
||||
Platform_NewUuid(World_Uuid);
|
||||
|
||||
Random rnd;
|
||||
Random_InitFromCurrentTime(&rnd);
|
||||
Int32 i;
|
||||
for (i = 0; i < 16; i++)
|
||||
World_Uuid[i] = (UInt8)Random_Next(&rnd, 256);
|
||||
|
||||
/* Set version and variant bits */
|
||||
World_Uuid[6] &= 0x0F;
|
||||
World_Uuid[6] |= 0x40; /* version 4*/
|
||||
World_Uuid[8] &= 0x3F;
|
||||
World_Uuid[8] |= 0x80; /* variant 2*/
|
||||
}
|
||||
|
||||
void World_SetNewMap(BlockID* blocks, Int32 blocksSize, Int32 width, Int32 height, Int32 length) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user