more fixes

This commit is contained in:
UnknownShadow200 2018-04-21 18:13:31 +10:00
parent 7b726ad56b
commit 81ea790f8f
32 changed files with 179 additions and 161 deletions

View File

@ -24,15 +24,12 @@ namespace ClassicalSharp.Generator {
unsafe void MapSet(BlockRaw* ptr, int yStart, int yEnd, BlockRaw block) { unsafe void MapSet(BlockRaw* ptr, int yStart, int yEnd, BlockRaw block) {
yStart = Math.Max(yStart, 0); yEnd = Math.Max(yEnd, 0); yStart = Math.Max(yStart, 0); yEnd = Math.Max(yEnd, 0);
int startIndex = yStart * Length * Width; int oneY = Width * Length, yHeight = (yEnd - yStart) + 1;
int endIndex = (yEnd * Length + (Length - 1)) * Width + (Width - 1);
int count = (endIndex - startIndex) + 1, offset = 0;
while (offset < count) { CurrentProgress = 0;
int bytes = Math.Min(count - offset, Width * Length); for (int y = yStart; y <= yEnd; y++) {
MemUtils.memset((IntPtr)ptr, block, startIndex + offset, bytes); MemUtils.memset((IntPtr)ptr, block, y * oneY, oneY);
offset += bytes; CurrentProgress = (float)(y - yStart) / yHeight;
CurrentProgress = (float)offset / count;
} }
} }
} }

View File

@ -20,7 +20,7 @@ namespace ClassicalSharp.GraphicsAPI {
public abstract bool Texturing { set; } public abstract bool Texturing { set; }
public Matrix4 Projection, View; public Matrix4 Projection, View;
internal float MinZNear = 0.1f; internal float MinZNear; // MinZNear = 0.1f;
readonly FastBitmap bmpBuffer = new FastBitmap(); readonly FastBitmap bmpBuffer = new FastBitmap();
/// <summary> Returns whether this graphics api had a valid context. </summary> /// <summary> Returns whether this graphics api had a valid context. </summary>

View File

@ -22,6 +22,7 @@ namespace ClassicalSharp.GraphicsAPI {
IntPtr dynamicListData; IntPtr dynamicListData;
public OpenGLApi() { public OpenGLApi() {
MinZNear = 0.1f;
InitFields(); InitFields();
int texDims; int texDims;
GL.GetIntegerv(GetPName.MaxTextureSize, &texDims); GL.GetIntegerv(GetPName.MaxTextureSize, &texDims);

View File

@ -13,6 +13,7 @@ namespace ClassicalSharp.GraphicsAPI {
public unsafe class OpenGLESApi : IGraphicsApi { public unsafe class OpenGLESApi : IGraphicsApi {
public OpenGLESApi() { public OpenGLESApi() {
MinZNear = 0.1f;
InitFields(); InitFields();
int texDims; int texDims;
GL.GetInteger(All.MaxTextureSize, &texDims); GL.GetInteger(All.MaxTextureSize, &texDims);

View File

@ -119,8 +119,8 @@ namespace ClassicalSharp {
chunk[chunkIndex] = rawBlock; chunk[chunkIndex] = rawBlock;
} }
} }
outAllAir = allAir; outAllSolid = allSolid;
} }
outAllAir = allAir; outAllSolid = allSolid;
} }
#if !ONLY_8BIT #if !ONLY_8BIT
@ -152,8 +152,8 @@ namespace ClassicalSharp {
chunk[chunkIndex] = rawBlock; chunk[chunkIndex] = rawBlock;
} }
} }
outAllAir = allAir; outAllSolid = allSolid;
} }
outAllAir = allAir; outAllSolid = allSolid;
} }
} }
#endif #endif

View File

@ -80,5 +80,9 @@ namespace OpenTK {
public bool Equals(Vector4 other) { public bool Equals(Vector4 other) {
return X == other.X && Y == other.Y && Z == other.Z && W == other.W; return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
} }
public override string ToString() {
return X + " : " + Y + " : " + Z + " : " + W;
}
} }
} }

View File

@ -240,8 +240,7 @@ namespace OpenTK.Platform.Windows
case WindowMessage.KEYUP: case WindowMessage.KEYUP:
case WindowMessage.SYSKEYDOWN: case WindowMessage.SYSKEYDOWN:
case WindowMessage.SYSKEYUP: case WindowMessage.SYSKEYUP:
bool pressed = message == WindowMessage.KEYDOWN || bool pressed = message == WindowMessage.KEYDOWN || message == WindowMessage.SYSKEYDOWN;
message == WindowMessage.SYSKEYDOWN;
// Shift/Control/Alt behave strangely when e.g. ShiftRight is held down and ShiftLeft is pressed // Shift/Control/Alt behave strangely when e.g. ShiftRight is held down and ShiftLeft is pressed
// and released. It looks like neither key is released in this case, or that the wrong key is // and released. It looks like neither key is released in this case, or that the wrong key is

View File

@ -65,5 +65,6 @@ void AxisLinesRenderer_Render(Real64 delta) {
} }
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FC4B); Gfx_SetBatchFormat(VERTEX_FORMAT_P3FC4B);
GfxCommon_UpdateDynamicVb_IndexedTris(axisLines_vb, vertices, axisLines_numVertices); Int32 count = (Int32)(ptr - vertices);
GfxCommon_UpdateDynamicVb_IndexedTris(axisLines_vb, vertices, count);
} }

View File

@ -47,9 +47,8 @@ void BordersRenderer_RenderSides(Real64 delta) {
} }
void BordersRenderer_RenderEdges(Real64 delta) { void BordersRenderer_RenderEdges(Real64 delta) {
if (borders_edgesVb == NULL) return;
BlockID block = WorldEnv_EdgeBlock; BlockID block = WorldEnv_EdgeBlock;
BordersRenderer_SetupState(block, borders_sideTexId, borders_sidesVb); BordersRenderer_SetupState(block, borders_edgeTexId, borders_edgesVb);
/* Do not draw water when we cannot see it. */ /* Do not draw water when we cannot see it. */
/* Fixes some 'depth bleeding through' issues with 16 bit depth buffers on large maps. */ /* Fixes some 'depth bleeding through' issues with 16 bit depth buffers on large maps. */

View File

@ -101,25 +101,22 @@ void Builder_AddVertices(BlockID block, Face face) {
part->fCount[face] += 4; part->fCount[face] += 4;
} }
void Builder_SetPartInfo(Builder1DPart* part, Int32 i, Int32 partsIndex, bool* hasParts) { void Builder_SetPartInfo(Builder1DPart* part, ChunkPartInfo* info, bool* hasParts) {
Int32 vCount = Builder1DPart_VerticesCount(part); Int32 vCount = Builder1DPart_VerticesCount(part);
if (vCount == 0) return; if (vCount == 0) return;
ChunkPartInfo info;
/* add an extra element to fix crashing on some GPUs */ /* add an extra element to fix crashing on some GPUs */
info.VbId = Gfx_CreateVb(part->vertices, VERTEX_FORMAT_P3FT2FC4B, vCount + 1); info->VbId = Gfx_CreateVb(part->vertices, VERTEX_FORMAT_P3FT2FC4B, vCount + 1);
info.HasVertices = vCount > 0; info->HasVertices = true;
info.XMinCount = (UInt16)part->fCount[FACE_XMIN];
info.XMaxCount = (UInt16)part->fCount[FACE_XMAX];
info.ZMinCount = (UInt16)part->fCount[FACE_ZMIN];
info.ZMaxCount = (UInt16)part->fCount[FACE_ZMAX];
info.YMinCount = (UInt16)part->fCount[FACE_YMIN];
info.YMaxCount = (UInt16)part->fCount[FACE_YMAX];
info.SpriteCountDiv4 = part->sCount >> 2;
*hasParts = true; *hasParts = true;
MapRenderer_PartsBuffer[partsIndex] = info;
info->XMinCount = (UInt16)part->fCount[FACE_XMIN];
info->XMaxCount = (UInt16)part->fCount[FACE_XMAX];
info->ZMinCount = (UInt16)part->fCount[FACE_ZMIN];
info->ZMaxCount = (UInt16)part->fCount[FACE_ZMAX];
info->YMinCount = (UInt16)part->fCount[FACE_YMIN];
info->YMaxCount = (UInt16)part->fCount[FACE_YMAX];
info->SpriteCountDiv4 = part->sCount >> 2;
} }
@ -239,7 +236,7 @@ void Builder_Stretch(Int32 x1, Int32 y1, Int32 z1) {
} }
} }
bool Builder_ReadChunkData(Int32 x1, Int32 y1, Int32 z1, bool* outAllAir) { void Builder_ReadChunkData(Int32 x1, Int32 y1, Int32 z1, bool* outAllAir, bool* outAllSolid) {
bool allAir = true, allSolid = true; bool allAir = true, allSolid = true;
Int32 xx, yy, zz; Int32 xx, yy, zz;
@ -272,14 +269,9 @@ bool Builder_ReadChunkData(Int32 x1, Int32 y1, Int32 z1, bool* outAllAir) {
} }
} }
} }
*outAllAir = allAir; *outAllAir = allAir;
*outAllSolid = allSolid;
if (x1 == 0 || y1 == 0 || z1 == 0 || x1 + CHUNK_SIZE >= World_Width ||
y1 + CHUNK_SIZE >= World_Height || z1 + CHUNK_SIZE >= World_Length) allSolid = false;
if (allAir || allSolid) return true;
Lighting_LightHint(x1 - 1, z1 - 1);
return false;
} }
bool Builder_BuildChunk(Int32 x1, Int32 y1, Int32 z1, bool* allAir) { bool Builder_BuildChunk(Int32 x1, Int32 y1, Int32 z1, bool* allAir) {
@ -289,9 +281,16 @@ bool Builder_BuildChunk(Int32 x1, Int32 y1, Int32 z1, bool* allAir) {
Int32 bitFlags[EXTCHUNK_SIZE_3]; Builder_BitFlags = bitFlags; Int32 bitFlags[EXTCHUNK_SIZE_3]; Builder_BitFlags = bitFlags;
Platform_MemSet(chunk, BLOCK_AIR, EXTCHUNK_SIZE_3 * sizeof(BlockID)); Platform_MemSet(chunk, BLOCK_AIR, EXTCHUNK_SIZE_3 * sizeof(BlockID));
if (Builder_ReadChunkData(x1, y1, z1, allAir)) return false; bool allSolid;
Platform_MemSet(counts, 1, CHUNK_SIZE_3 * FACE_COUNT); Builder_ReadChunkData(x1, y1, z1, allAir, &allSolid);
if (x1 == 0 || y1 == 0 || z1 == 0 || x1 + CHUNK_SIZE >= World_Width ||
y1 + CHUNK_SIZE >= World_Height || z1 + CHUNK_SIZE >= World_Length) allSolid = false;
if (*allAir || allSolid) return false;
Lighting_LightHint(x1 - 1, z1 - 1);
Platform_MemSet(counts, 1, CHUNK_SIZE_3 * FACE_COUNT);
Int32 xMax = min(World_Width, x1 + CHUNK_SIZE); Int32 xMax = min(World_Width, x1 + CHUNK_SIZE);
Int32 yMax = min(World_Height, y1 + CHUNK_SIZE); Int32 yMax = min(World_Height, y1 + CHUNK_SIZE);
Int32 zMax = min(World_Length, z1 + CHUNK_SIZE); Int32 zMax = min(World_Length, z1 + CHUNK_SIZE);
@ -323,7 +322,7 @@ bool Builder_BuildChunk(Int32 x1, Int32 y1, Int32 z1, bool* allAir) {
void Builder_MakeChunk(ChunkInfo* info) { void Builder_MakeChunk(ChunkInfo* info) {
Int32 x = info->CentreX - 8, y = info->CentreY - 8, z = info->CentreZ - 8; Int32 x = info->CentreX - 8, y = info->CentreY - 8, z = info->CentreZ - 8;
bool allAir = false, hasMesh; bool allAir = false, hasMesh;
hasMesh = Builder_BuildChunk(Builder_X, Builder_Y, Builder_Z, &allAir); hasMesh = Builder_BuildChunk(x, y, z, &allAir);
info->AllAir = allAir; info->AllAir = allAir;
if (!hasMesh) return; if (!hasMesh) return;
@ -331,18 +330,18 @@ void Builder_MakeChunk(ChunkInfo* info) {
bool hasNormal = false, hasTranslucent = false; bool hasNormal = false, hasTranslucent = false;
for (i = 0; i < Atlas1D_Count; i++) { for (i = 0; i < Atlas1D_Count; i++) {
Int32 idx = partsIndex + i * MapRenderer_ChunksCount; Int32 j = i + ATLAS1D_MAX_ATLASES_COUNT;
Builder_SetPartInfo(&Builder_Parts[i], i, Int32 curIdx = partsIndex + i * MapRenderer_ChunksCount;
idx, &hasNormal);
Builder_SetPartInfo(&Builder_Parts[i + ATLAS1D_MAX_ATLASES_COUNT], i, Builder_SetPartInfo(&Builder_Parts[i], &MapRenderer_PartsNormal[curIdx], &hasNormal);
idx + MapRenderer_TranslucentBufferOffset, &hasTranslucent); Builder_SetPartInfo(&Builder_Parts[j], &MapRenderer_PartsTranslucent[curIdx], &hasTranslucent);
} }
if (hasNormal) { if (hasNormal) {
info->NormalParts = &MapRenderer_PartsBuffer[partsIndex]; info->NormalParts = &MapRenderer_PartsNormal[partsIndex];
} }
if (hasTranslucent) { if (hasTranslucent) {
info->NormalParts = &MapRenderer_PartsBuffer[partsIndex + MapRenderer_TranslucentBufferOffset]; info->TranslucentParts = &MapRenderer_PartsTranslucent[partsIndex];
} }
#if OCCLUSION #if OCCLUSION

View File

@ -118,7 +118,10 @@ void ChunkUpdater_FreeAllocations(void) {
Platform_MemFree(&MapRenderer_SortedChunks); Platform_MemFree(&MapRenderer_SortedChunks);
Platform_MemFree(&MapRenderer_RenderChunks); Platform_MemFree(&MapRenderer_RenderChunks);
Platform_MemFree(&ChunkUpdater_Distances); Platform_MemFree(&ChunkUpdater_Distances);
Platform_MemFree(&MapRenderer_PartsBuffer); Platform_MemFree(&MapRenderer_PartsBuffer_Raw);
MapRenderer_PartsNormal = NULL;
MapRenderer_PartsTranslucent = NULL;
} }
void ChunkUpdater_PerformAllocations(void) { void ChunkUpdater_PerformAllocations(void) {
@ -134,10 +137,14 @@ void ChunkUpdater_PerformAllocations(void) {
ChunkUpdater_Distances = Platform_MemAlloc(MapRenderer_ChunksCount * sizeof(Int32)); ChunkUpdater_Distances = Platform_MemAlloc(MapRenderer_ChunksCount * sizeof(Int32));
if (ChunkUpdater_Distances == NULL) ErrorHandler_Fail("ChunkUpdater - failed to allocate chunk distances"); if (ChunkUpdater_Distances == NULL) ErrorHandler_Fail("ChunkUpdater - failed to allocate chunk distances");
UInt32 partsSize = MapRenderer_ChunksCount * (sizeof(ChunkPartInfo) * MapRenderer_1DUsedCount); UInt32 partsCount = MapRenderer_ChunksCount * MapRenderer_1DUsedCount;
MapRenderer_PartsBuffer = Platform_MemAlloc(partsSize); UInt32 partsSize = (partsCount * (UInt32)sizeof(ChunkPartInfo)) * 2;
if (MapRenderer_PartsBuffer == NULL) ErrorHandler_Fail("ChunkUpdater - failed to allocate chunk parts buffer"); MapRenderer_PartsBuffer_Raw = Platform_MemAlloc(partsSize);
Platform_MemSet(MapRenderer_PartsBuffer, 0, partsSize); if (MapRenderer_PartsBuffer_Raw == NULL) ErrorHandler_Fail("ChunkUpdater - failed to allocate chunk parts buffer");
Platform_MemSet(MapRenderer_PartsBuffer_Raw, 0, partsSize);
MapRenderer_PartsNormal = MapRenderer_PartsBuffer_Raw;
MapRenderer_PartsTranslucent = MapRenderer_PartsBuffer_Raw + partsCount;
} }
void ChunkUpdater_OnNewMap(void* obj) { void ChunkUpdater_OnNewMap(void* obj) {

View File

@ -27,12 +27,12 @@ D3DTRANSFORMSTATETYPE curMatrix;
DWORD createFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; DWORD createFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
D3DFORMAT d3d9_viewFormat, d3d9_depthFormat; D3DFORMAT d3d9_viewFormat, d3d9_depthFormat;
#define D3D9_SetRenderState(raw, state, name) \ #define D3D9_SetRenderState(state, value, name) \
ReturnCode hresult = IDirect3DDevice9_SetRenderState(device, state, raw); \ ReturnCode hresult = IDirect3DDevice9_SetRenderState(device, state, value); \
ErrorHandler_CheckOrFail(hresult, name) ErrorHandler_CheckOrFail(hresult, name)
#define D3D9_SetRenderState2(raw, state, name) \ #define D3D9_SetRenderState2(state, value, name) \
hresult = IDirect3DDevice9_SetRenderState(device, state, raw); \ hresult = IDirect3DDevice9_SetRenderState(device, state, value); \
ErrorHandler_CheckOrFail(hresult, name) ErrorHandler_CheckOrFail(hresult, name)
#define D3D9_LogLeakedResource(msg, i) \ #define D3D9_LogLeakedResource(msg, i) \
@ -301,7 +301,7 @@ void Gfx_SetFog(bool enabled) {
if (d3d9_fogEnable == enabled) return; if (d3d9_fogEnable == enabled) return;
d3d9_fogEnable = enabled; d3d9_fogEnable = enabled;
D3D9_SetRenderState((UInt32)enabled, D3DRS_FOGENABLE, "D3D9_SetFog"); D3D9_SetRenderState(D3DRS_FOGENABLE, (UInt32)enabled, "D3D9_SetFog");
} }
UInt32 d3d9_fogCol = 0xFF000000; /* black */ UInt32 d3d9_fogCol = 0xFF000000; /* black */
@ -309,7 +309,7 @@ void Gfx_SetFogColour(PackedCol col) {
if (col.Packed == d3d9_fogCol) return; if (col.Packed == d3d9_fogCol) return;
d3d9_fogCol = col.Packed; d3d9_fogCol = col.Packed;
D3D9_SetRenderState(col.Packed, D3DRS_FOGCOLOR, "D3D9_SetFogColour"); D3D9_SetRenderState(D3DRS_FOGCOLOR, col.Packed, "D3D9_SetFogColour");
} }
Real32 d3d9_fogDensity = -1.0f; Real32 d3d9_fogDensity = -1.0f;
@ -318,14 +318,14 @@ void Gfx_SetFogDensity(Real32 value) {
d3d9_fogDensity = value; d3d9_fogDensity = value;
UInt32 raw = *(UInt32*)&value; UInt32 raw = *(UInt32*)&value;
D3D9_SetRenderState(raw, D3DRS_FOGDENSITY, "D3D9_SetFogDensity"); D3D9_SetRenderState(D3DRS_FOGDENSITY, raw, "D3D9_SetFogDensity");
} }
Real32 d3d9_fogStart = -1.0f; Real32 d3d9_fogStart = -1.0f;
void Gfx_SetFogStart(Real32 value) { void Gfx_SetFogStart(Real32 value) {
d3d9_fogStart = value; d3d9_fogStart = value;
UInt32 raw = *(UInt32*)&value; UInt32 raw = *(UInt32*)&value;
D3D9_SetRenderState(raw, D3DRS_FOGSTART, "D3D9_SetFogStart"); D3D9_SetRenderState(D3DRS_FOGSTART, raw, "D3D9_SetFogStart");
} }
Real32 d3d9_fogEnd = -1.0f; Real32 d3d9_fogEnd = -1.0f;
@ -334,7 +334,7 @@ void Gfx_SetFogEnd(Real32 value) {
d3d9_fogEnd = value; d3d9_fogEnd = value;
UInt32 raw = *(UInt32*)&value; UInt32 raw = *(UInt32*)&value;
D3D9_SetRenderState(raw, D3DRS_FOGEND, "D3D9_SetFogEnd"); D3D9_SetRenderState(D3DRS_FOGEND, raw, "D3D9_SetFogEnd");
} }
D3DFOGMODE d3d9_fogTableMode = D3DFOG_NONE; D3DFOGMODE d3d9_fogTableMode = D3DFOG_NONE;
@ -343,13 +343,13 @@ void Gfx_SetFogMode(Int32 fogMode) {
if (mode == d3d9_fogTableMode) return; if (mode == d3d9_fogTableMode) return;
d3d9_fogTableMode = mode; d3d9_fogTableMode = mode;
D3D9_SetRenderState(mode, D3DRS_FOGTABLEMODE, "D3D9_SetFogMode"); D3D9_SetRenderState(D3DRS_FOGTABLEMODE, mode, "D3D9_SetFogMode");
} }
void Gfx_SetFaceCulling(bool enabled) { void Gfx_SetFaceCulling(bool enabled) {
D3DCULL mode = enabled ? D3DCULL_CW : D3DCULL_NONE; D3DCULL mode = enabled ? D3DCULL_CW : D3DCULL_NONE;
D3D9_SetRenderState(mode, D3DRS_CULLMODE, "D3D9_SetFaceCulling"); D3D9_SetRenderState(D3DRS_CULLMODE, mode, "D3D9_SetFaceCulling");
} }
bool d3d9_alphaTest = false; bool d3d9_alphaTest = false;
@ -357,16 +357,16 @@ void Gfx_SetAlphaTest(bool enabled) {
if (d3d9_alphaTest == enabled) return; if (d3d9_alphaTest == enabled) return;
d3d9_alphaTest = enabled; d3d9_alphaTest = enabled;
D3D9_SetRenderState((UInt32)enabled, D3DRS_ALPHATESTENABLE, "D3D9_SetAlphaTest"); D3D9_SetRenderState(D3DRS_ALPHATESTENABLE, (UInt32)enabled, "D3D9_SetAlphaTest");
} }
D3DCMPFUNC d3d9_alphaTestFunc = D3DCMP_ALWAYS; D3DCMPFUNC d3d9_alphaTestFunc = D3DCMP_ALWAYS;
Int32 d3d9_alphaTestRef = 0; Int32 d3d9_alphaTestRef = 0;
void Gfx_SetAlphaTestFunc(Int32 compareFunc, Real32 refValue) { void Gfx_SetAlphaTestFunc(Int32 compareFunc, Real32 refValue) {
d3d9_alphaTestFunc = d3d9_compareFuncs[compareFunc]; d3d9_alphaTestFunc = d3d9_compareFuncs[compareFunc];
D3D9_SetRenderState(d3d9_alphaTestFunc, D3DRS_ALPHAFUNC, "D3D9_SetAlphaTest_Func"); D3D9_SetRenderState(D3DRS_ALPHAFUNC, d3d9_alphaTestFunc, "D3D9_SetAlphaTest_Func");
d3d9_alphaTestRef = (Int32)(refValue * 255); d3d9_alphaTestRef = (Int32)(refValue * 255);
D3D9_SetRenderState2(d3d9_alphaTestRef, D3DRS_ALPHAREF, "D3D9_SetAlphaTest_Ref"); D3D9_SetRenderState2(D3DRS_ALPHAREF, d3d9_alphaTestRef, "D3D9_SetAlphaTest_Ref");
} }
bool d3d9_alphaBlend = false; bool d3d9_alphaBlend = false;
@ -374,16 +374,16 @@ void Gfx_SetAlphaBlending(bool enabled) {
if (d3d9_alphaBlend == enabled) return; if (d3d9_alphaBlend == enabled) return;
d3d9_alphaBlend = enabled; d3d9_alphaBlend = enabled;
D3D9_SetRenderState((UInt32)enabled, D3DRS_ALPHABLENDENABLE, "D3D9_SetAlphaBlending"); D3D9_SetRenderState(D3DRS_ALPHABLENDENABLE, (UInt32)enabled, "D3D9_SetAlphaBlending");
} }
D3DBLEND d3d9_srcBlendFunc = D3DBLEND_ONE; D3DBLEND d3d9_srcBlendFunc = D3DBLEND_ONE;
D3DBLEND d3d9_dstBlendFunc = D3DBLEND_ZERO; D3DBLEND d3d9_dstBlendFunc = D3DBLEND_ZERO;
void Gfx_SetAlphaBlendFunc(Int32 srcBlendFunc, Int32 dstBlendFunc) { void Gfx_SetAlphaBlendFunc(Int32 srcBlendFunc, Int32 dstBlendFunc) {
d3d9_srcBlendFunc = d3d9_blendFuncs[srcBlendFunc]; d3d9_srcBlendFunc = d3d9_blendFuncs[srcBlendFunc];
D3D9_SetRenderState(d3d9_srcBlendFunc, D3DRS_SRCBLEND, "D3D9_SetAlphaBlendFunc_Src"); D3D9_SetRenderState(D3DRS_SRCBLEND, d3d9_srcBlendFunc, "D3D9_SetAlphaBlendFunc_Src");
d3d9_dstBlendFunc = d3d9_blendFuncs[dstBlendFunc]; d3d9_dstBlendFunc = d3d9_blendFuncs[dstBlendFunc];
D3D9_SetRenderState2(d3d9_dstBlendFunc, D3DRS_DESTBLEND, "D3D9_SetAlphaBlendFunc_Dst"); D3D9_SetRenderState2(D3DRS_DESTBLEND, d3d9_dstBlendFunc, "D3D9_SetAlphaBlendFunc_Dst");
} }
void Gfx_SetAlphaArgBlend(bool enabled) { void Gfx_SetAlphaArgBlend(bool enabled) {
@ -407,24 +407,24 @@ void Gfx_ClearColour(PackedCol col) {
bool d3d9_depthTest = false; bool d3d9_depthTest = false;
void Gfx_SetDepthTest(bool enabled) { void Gfx_SetDepthTest(bool enabled) {
d3d9_depthTest = enabled; d3d9_depthTest = enabled;
D3D9_SetRenderState((UInt32)enabled, D3DRS_ZENABLE, "D3D9_SetDepthTest"); D3D9_SetRenderState(D3DRS_ZENABLE, (UInt32)enabled, "D3D9_SetDepthTest");
} }
D3DCMPFUNC d3d9_depthTestFunc = D3DCMP_LESSEQUAL; D3DCMPFUNC d3d9_depthTestFunc = D3DCMP_LESSEQUAL;
void Gfx_SetDepthTestFunc(Int32 compareFunc) { void Gfx_SetDepthTestFunc(Int32 compareFunc) {
d3d9_depthTestFunc = d3d9_compareFuncs[compareFunc]; d3d9_depthTestFunc = d3d9_compareFuncs[compareFunc];
D3D9_SetRenderState(d3d9_alphaTestFunc, D3DRS_ZFUNC, "D3D9_SetDepthTestFunc"); D3D9_SetRenderState(D3DRS_ZFUNC, d3d9_alphaTestFunc, "D3D9_SetDepthTestFunc");
} }
void Gfx_SetColourWriteMask(bool r, bool g, bool b, bool a) { void Gfx_SetColourWriteMask(bool r, bool g, bool b, bool a) {
UInt32 channels = (r ? 1u : 0u) | (g ? 2u : 0u) | (b ? 4u : 0u) | (a ? 8u : 0u); UInt32 channels = (r ? 1u : 0u) | (g ? 2u : 0u) | (b ? 4u : 0u) | (a ? 8u : 0u);
D3D9_SetRenderState(channels, D3DRS_COLORWRITEENABLE, "D3D9_SetColourWrite"); D3D9_SetRenderState(D3DRS_COLORWRITEENABLE, channels, "D3D9_SetColourWrite");
} }
bool d3d9_depthWrite = false; bool d3d9_depthWrite = false;
void Gfx_SetDepthWrite(bool enabled) { void Gfx_SetDepthWrite(bool enabled) {
d3d9_depthWrite = enabled; d3d9_depthWrite = enabled;
D3D9_SetRenderState((UInt32)enabled, D3DRS_ZWRITEENABLE, "D3D9_SetDepthWrite"); D3D9_SetRenderState(D3DRS_ZWRITEENABLE, (UInt32)enabled, "D3D9_SetDepthWrite");
} }
@ -584,6 +584,14 @@ void Gfx_CalcPerspectiveMatrix(Real32 fov, Real32 aspect, Real32 zNear, Real32 z
bool Gfx_WarnIfNecessary(void) { return false; } bool Gfx_WarnIfNecessary(void) { return false; }
void Gfx_SetVSync(bool value) {
if (d3d9_vsync == value) return;
d3d9_vsync = value;
GfxCommon_LoseContext(" (toggling VSync)");
D3D9_RecreateDevice();
}
void Gfx_BeginFrame(void) { void Gfx_BeginFrame(void) {
IDirect3DDevice9_BeginScene(device); IDirect3DDevice9_BeginScene(device);
} }
@ -598,15 +606,13 @@ void Gfx_EndFrame(void) {
} }
/* TODO: Make sure this actually works on all graphics cards.*/ /* TODO: Make sure this actually works on all graphics cards.*/
String reason = String_FromConst(" (Direct3D9 device lost)"); GfxCommon_LoseContext(" (Direct3D9 device lost)");
GfxCommon_LoseContext(&reason);
D3D9_LoopUntilRetrieved(); D3D9_LoopUntilRetrieved();
D3D9_RecreateDevice(); D3D9_RecreateDevice();
} }
void Gfx_OnWindowResize(void) { void Gfx_OnWindowResize(void) {
String reason = String_FromConst(" (resizing window)"); GfxCommon_LoseContext(" (resizing window)");
GfxCommon_LoseContext(&reason);
D3D9_RecreateDevice(); D3D9_RecreateDevice();
} }

View File

@ -33,7 +33,7 @@ void Drawer_XMax(Int32 count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b*
Real32 u1 = (count - Drawer_MinBB.Z); Real32 u1 = (count - Drawer_MinBB.Z);
Real32 u2 = (1 - Drawer_MaxBB.Z) * UV2_Scale; Real32 u2 = (1 - Drawer_MaxBB.Z) * UV2_Scale;
Real32 v1 = vOrigin + Drawer_MaxBB.Y * Atlas1D_InvElementSize; Real32 v1 = vOrigin + Drawer_MaxBB.Y * Atlas1D_InvElementSize;
Real32 v2 = vOrigin + Drawer_MaxBB.Y * Atlas1D_InvElementSize * UV2_Scale; Real32 v2 = vOrigin + Drawer_MinBB.Y * Atlas1D_InvElementSize * UV2_Scale;
ApplyTint; ApplyTint;
VertexP3fT2fC4b* ptr = *vertices; VertexP3fT2fC4b* ptr = *vertices;

View File

@ -100,7 +100,7 @@ void Drawer2D_Begin(Bitmap* bmp) {
} }
void Drawer2D_End(void) { void Drawer2D_End(void) {
Platform_SetBitmap(Drawer2D_Cur); Platform_ReleaseBitmap();
Drawer2D_Cur = NULL; Drawer2D_Cur = NULL;
} }

View File

@ -785,7 +785,7 @@ void Collisions_ClipYMax(CollisionsComp* comp, AABB* blockBB, AABB* entityBB, AA
comp->HitYMax = true; comp->HitYMax = true;
} }
void Collisions_CollideWithReachableBlocks(CollisionsComp* comp, UInt32 count, AABB* entityBB, AABB* extentBB) { void Collisions_CollideWithReachableBlocks(CollisionsComp* comp, Int32 count, AABB* entityBB, AABB* extentBB) {
Entity* entity = comp->Entity; Entity* entity = comp->Entity;
/* Reset collision detection states */ /* Reset collision detection states */
bool wasOn = entity->OnGround; bool wasOn = entity->OnGround;
@ -795,7 +795,7 @@ void Collisions_CollideWithReachableBlocks(CollisionsComp* comp, UInt32 count, A
AABB blockBB; AABB blockBB;
Vector3 bPos, size = entity->Size; Vector3 bPos, size = entity->Size;
UInt32 i; Int32 i;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
/* Unpack the block and coordinate data */ /* Unpack the block and coordinate data */
SearcherState state = Searcher_States[i]; SearcherState state = Searcher_States[i];
@ -863,7 +863,7 @@ void Collisions_MoveAndWallSlide(CollisionsComp* comp) {
if (Vector3_Equals(&entity->Velocity, &zero)) return; if (Vector3_Equals(&entity->Velocity, &zero)) return;
AABB entityBB, entityExtentBB; AABB entityBB, entityExtentBB;
UInt32 count = Searcher_FindReachableBlocks(entity, &entityBB, &entityExtentBB); Int32 count = Searcher_FindReachableBlocks(entity, &entityBB, &entityExtentBB);
Collisions_CollideWithReachableBlocks(comp, count, &entityBB, &entityExtentBB); Collisions_CollideWithReachableBlocks(comp, count, &entityBB, &entityExtentBB);
} }

View File

@ -772,7 +772,6 @@ void Schematic_Save(Stream* stream) { }
void Gfx_MakeApiInfo(void) { } void Gfx_MakeApiInfo(void) { }
void ServerConnection_InitMultiplayer(void) { } void ServerConnection_InitMultiplayer(void) { }
void Gfx_TakeScreenshot(STRING_PURE String* output, Int32 width, Int32 height) { } void Gfx_TakeScreenshot(STRING_PURE String* output, Int32 width, Int32 height) { }
void Gfx_SetVSync(bool value) { }
void ServerConnection_RetrieveTexturePack(STRING_PURE String* url) { } void ServerConnection_RetrieveTexturePack(STRING_PURE String* url) { }
bool Convert_TryParseInt64(STRING_PURE String* str, Int64* value) { return true; } bool Convert_TryParseInt64(STRING_PURE String* str, Int64* value) { return true; }
DateTime DateTime_FromTotalMs(Int64 ms) { DateTime time; return time; } DateTime DateTime_FromTotalMs(Int64 ms) { DateTime time; return time; }

View File

@ -22,11 +22,11 @@ void GfxCommon_Free(void) {
Gfx_DeleteIb(&GfxCommon_defaultIb); Gfx_DeleteIb(&GfxCommon_defaultIb);
} }
void GfxCommon_LoseContext(STRING_PURE String* reason) { void GfxCommon_LoseContext(const UInt8* reason) {
Gfx_LostContext = true; Gfx_LostContext = true;
String logMsg = String_FromConst("Lost graphics context:"); String logMsg = String_FromConst("Lost graphics context:");
Platform_Log(&logMsg); Platform_Log(&logMsg);
Platform_Log(reason); Platform_LogConst(reason);
Event_RaiseVoid(&GfxEvents_ContextLost); Event_RaiseVoid(&GfxEvents_ContextLost);
GfxCommon_Free(); GfxCommon_Free();
@ -126,7 +126,7 @@ void GfxCommon_Mode3D(void) {
Gfx_SetMatrixMode(MATRIX_TYPE_MODELVIEW); Gfx_SetMatrixMode(MATRIX_TYPE_MODELVIEW);
Gfx_LoadMatrix(&Gfx_View); Gfx_LoadMatrix(&Gfx_View);
Gfx_SetDepthTest(false); Gfx_SetDepthTest(true);
Gfx_SetAlphaBlending(false); Gfx_SetAlphaBlending(false);
if (gfx_hadFog) Gfx_SetFog(true); if (gfx_hadFog) Gfx_SetFog(true);
} }

View File

@ -11,7 +11,7 @@ typedef struct Texture_ Texture;
GfxResourceID GfxCommon_defaultIb; GfxResourceID GfxCommon_defaultIb;
void GfxCommon_Init(void); void GfxCommon_Init(void);
void GfxCommon_Free(void); void GfxCommon_Free(void);
void GfxCommon_LoseContext(STRING_PURE String* reason); void GfxCommon_LoseContext(const UInt8* reason);
void GfxCommon_RecreateContext(void); void GfxCommon_RecreateContext(void);
/* Binds and draws the specified subset of the vertices in the current dynamic vertex buffer /* Binds and draws the specified subset of the vertices in the current dynamic vertex buffer

View File

@ -7,7 +7,6 @@
#include "Block.h" #include "Block.h"
#include "TerrainAtlas.h" #include "TerrainAtlas.h"
Int32 iso_count;
Real32 iso_scale; Real32 iso_scale;
VertexP3fT2fC4b* iso_vertices; VertexP3fT2fC4b* iso_vertices;
VertexP3fT2fC4b* iso_base_vertices; VertexP3fT2fC4b* iso_base_vertices;
@ -54,11 +53,11 @@ void IsometricDrawer_InitCache(void) {
void IsometricDrawer_Flush(void) { void IsometricDrawer_Flush(void) {
if (iso_lastTexIndex != -1) { if (iso_lastTexIndex != -1) {
Gfx_BindTexture(Atlas1D_TexIds[iso_lastTexIndex]); Gfx_BindTexture(Atlas1D_TexIds[iso_lastTexIndex]);
GfxCommon_UpdateDynamicVb_IndexedTris(iso_vb, iso_base_vertices, iso_count); Int32 count = (Int32)(iso_vertices - iso_base_vertices);
GfxCommon_UpdateDynamicVb_IndexedTris(iso_vb, iso_base_vertices, count);
} }
iso_lastTexIndex = iso_texIndex; iso_lastTexIndex = iso_texIndex;
iso_count = 0;
iso_vertices = iso_base_vertices; iso_vertices = iso_base_vertices;
} }
@ -124,7 +123,6 @@ void IsometricDrawer_SpriteXQuad(BlockID block, bool firstPart) {
void IsometricDrawer_BeginBatch(VertexP3fT2fC4b* vertices, GfxResourceID vb) { void IsometricDrawer_BeginBatch(VertexP3fT2fC4b* vertices, GfxResourceID vb) {
IsometricDrawer_InitCache(); IsometricDrawer_InitCache();
iso_lastTexIndex = -1; iso_lastTexIndex = -1;
iso_count = 0;
iso_vertices = vertices; iso_vertices = vertices;
iso_base_vertices = vertices; iso_base_vertices = vertices;
iso_vb = vb; iso_vb = vb;
@ -175,12 +173,15 @@ void IsometricDrawer_DrawBatch(BlockID block, Real32 size, Real32 x, Real32 y) {
IsometricDrawer_GetTexLoc(block, FACE_ZMIN), &iso_vertices); IsometricDrawer_GetTexLoc(block, FACE_ZMIN), &iso_vertices);
Drawer_YMax(1, iso_colNormal, Drawer_YMax(1, iso_colNormal,
IsometricDrawer_GetTexLoc(block, FACE_YMAX), &iso_vertices); IsometricDrawer_GetTexLoc(block, FACE_YMAX), &iso_vertices);
iso_count += 4 * 3;
} }
} }
void IsometricDrawer_EndBatch(void) { void IsometricDrawer_EndBatch(void) {
if (iso_count > 0) { iso_lastTexIndex = iso_texIndex; IsometricDrawer_Flush(); } if (iso_vertices != iso_base_vertices) {
iso_lastTexIndex = iso_texIndex;
IsometricDrawer_Flush();
}
iso_lastTexIndex = -1; iso_lastTexIndex = -1;
Gfx_LoadIdentityMatrix(); Gfx_LoadIdentityMatrix();
} }

View File

@ -9,32 +9,36 @@
#include "TreeGen.h" #include "TreeGen.h"
#include "Vectors.h" #include "Vectors.h"
void FlatgrassGen_MapSet(Int32 yStart, Int32 yEnd, BlockID block) { Int32 Gen_MaxX, Gen_MaxY, Gen_MaxZ;
yStart = max(yStart, 0); yEnd = max(yEnd, 0); void Gen_Init(void) {
Int32 startIndex = yStart * Gen_Length * Gen_Width; Gen_MaxX = Gen_Width - 1; Gen_MaxY = Gen_Height - 1; Gen_MaxZ = Gen_Length - 1;
Int32 endIndex = (yEnd * Gen_Length + (Gen_Length - 1)) * Gen_Width + (Gen_Width - 1);
Int32 count = (endIndex - startIndex) + 1, offset = 0;
Gen_CurrentProgress = 0.0f;
BlockID* ptr = Gen_Blocks;
while (offset < count) {
Int32 bytes = min(count - offset, Gen_Width * Gen_Length) * sizeof(BlockID);
Platform_MemSet(ptr, block, bytes);
ptr += bytes; offset += bytes;
Gen_CurrentProgress = (Real32)offset / count;
}
}
void FlatgrassGen_Generate(void) {
Gen_CurrentProgress = 0.0f; Gen_CurrentProgress = 0.0f;
Gen_CurrentState = ""; Gen_CurrentState = "";
Gen_Blocks = Platform_MemAlloc(Gen_Width * Gen_Height * Gen_Length * sizeof(BlockID)); Gen_Blocks = Platform_MemAlloc(Gen_Width * Gen_Height * Gen_Length * sizeof(BlockID));
if (Gen_Blocks == NULL) { if (Gen_Blocks == NULL) {
ErrorHandler_Fail("FlatgrassGen - failed to allocate Blocks array"); ErrorHandler_Fail("MapGen - failed to allocate Blocks array");
} }
Gen_Done = false;
}
void FlatgrassGen_MapSet(Int32 yStart, Int32 yEnd, BlockID block) {
yStart = max(yStart, 0); yEnd = max(yEnd, 0);
Int32 y, oneY = Gen_Width * Gen_Length, yHeight = (yEnd - yStart) + 1;
BlockID* ptr = Gen_Blocks;
Gen_CurrentProgress = 0.0f;
for (y = yStart; y <= yEnd; y++) {
Platform_MemSet(ptr + y * oneY, block, oneY);
Gen_CurrentProgress = (Real32)(y - yStart) / yHeight;
}
}
void FlatgrassGen_Generate(void) {
Gen_Init();
Gen_CurrentState = "Setting air blocks";
FlatgrassGen_MapSet(Gen_Height / 2, Gen_MaxY, BLOCK_AIR);
Gen_CurrentState = "Setting dirt blocks"; Gen_CurrentState = "Setting dirt blocks";
FlatgrassGen_MapSet(0, Gen_Height / 2 - 2, BLOCK_DIRT); FlatgrassGen_MapSet(0, Gen_Height / 2 - 2, BLOCK_DIRT);
@ -455,19 +459,12 @@ void NotchyGen_PlantTrees(void) {
} }
void NotchyGen_Generate(void) { void NotchyGen_Generate(void) {
Gen_CurrentProgress = 0.0f; Gen_Init();
Gen_CurrentState = "";
Heightmap = Platform_MemAlloc(Gen_Width * Gen_Length * sizeof(Int16)); Heightmap = Platform_MemAlloc(Gen_Width * Gen_Length * sizeof(Int16));
if (Heightmap == NULL) { if (Heightmap == NULL) {
ErrorHandler_Fail("NotchyGen - Failed to allocate Heightmap array"); ErrorHandler_Fail("NotchyGen - Failed to allocate Heightmap array");
} }
Gen_Blocks = Platform_MemAlloc(Gen_Width * Gen_Height * Gen_Length * sizeof(BlockID));
if (Gen_Blocks == NULL) {
ErrorHandler_Fail("NotchyGen - Failed to allocate Blocks array");
}
Random_Init(&rnd, Gen_Seed); Random_Init(&rnd, Gen_Seed);
volume = Gen_Width * Gen_Length * Gen_Height; volume = Gen_Width * Gen_Length * Gen_Height;
oneY = Gen_Width * Gen_Length; oneY = Gen_Width * Gen_Length;

View File

@ -11,7 +11,6 @@ volatile Real32 Gen_CurrentProgress;
volatile const UInt8* Gen_CurrentState; volatile const UInt8* Gen_CurrentState;
volatile bool Gen_Done; volatile bool Gen_Done;
Int32 Gen_Width, Gen_Height, Gen_Length; Int32 Gen_Width, Gen_Height, Gen_Length;
Int32 Gen_MaxX, Gen_MaxY, Gen_MaxZ;
Int32 Gen_Seed; Int32 Gen_Seed;
BlockID* Gen_Blocks; BlockID* Gen_Blocks;
#define Gen_Pack(x, y, z) (((y) * Gen_Length + (z)) * Gen_Width + (x)) #define Gen_Pack(x, y, z) (((y) * Gen_Length + (z)) * Gen_Width + (x))

View File

@ -41,11 +41,11 @@ ChunkInfo** MapRenderer_RenderChunks;
/* The number of actually used pointers in the RenderChunks array. /* The number of actually used pointers in the RenderChunks array.
Entries past this count should be ignored and skipped. */ Entries past this count should be ignored and skipped. */
Int32 MapRenderer_RenderChunksCount; Int32 MapRenderer_RenderChunksCount;
/* Buffer for all chunk parts. /* Buffer for all chunk parts. There are (MapRenderer_ChunksCount * Atlas1D_Count) * 2 parts in the buffer,
There are MapRenderer_ChunksCount * Atlas1D_Count * 2 parts in the buffer. */ with parts for 'normal' buffer being in lower half. */
ChunkPartInfo* MapRenderer_PartsBuffer; ChunkPartInfo* MapRenderer_PartsBuffer_Raw;
/* Offset of translucent chunk parts in MapRenderer_PartsBuffer. */ ChunkPartInfo* MapRenderer_PartsNormal;
Int32 MapRenderer_TranslucentBufferOffset; ChunkPartInfo* MapRenderer_PartsTranslucent;
ChunkInfo* MapRenderer_GetChunk(Int32 cx, Int32 cy, Int32 cz); ChunkInfo* MapRenderer_GetChunk(Int32 cx, Int32 cy, Int32 cz);
void MapRenderer_RefreshChunk(Int32 cx, Int32 cy, Int32 cz); void MapRenderer_RefreshChunk(Int32 cx, Int32 cy, Int32 cz);

View File

@ -1935,7 +1935,7 @@ void MenuOptionsScreen_SelectExtHelp(MenuOptionsScreen* screen, Int32 idx) {
UInt32 descLinesCount = Array_Elems(descLines); UInt32 descLinesCount = Array_Elems(descLines);
String_UNSAFE_Split(&descRaw, '%', descLines, &descLinesCount); String_UNSAFE_Split(&descRaw, '%', descLines, &descLinesCount);
TextGroupWidget_Create(&screen->ExtHelp, descLinesCount, &screen->TextFont, NULL, screen->ExtHelp_Textures, screen->ExtHelp_Buffer); TextGroupWidget_Create(&screen->ExtHelp, descLinesCount, &screen->TextFont, &screen->TextFont, screen->ExtHelp_Textures, screen->ExtHelp_Buffer);
Widget_SetLocation((Widget*)(&screen->ExtHelp), ANCHOR_MIN, ANCHOR_MIN, 0, 0); Widget_SetLocation((Widget*)(&screen->ExtHelp), ANCHOR_MIN, ANCHOR_MIN, 0, 0);
Elem_Init(&screen->ExtHelp); Elem_Init(&screen->ExtHelp);
@ -2163,6 +2163,8 @@ Screen* MenuOptionsScreen_MakeInstance(Widget** widgets, Int32 count, ButtonWidg
screen->DefaultValues = defaultValues; screen->DefaultValues = defaultValues;
screen->Descriptions = descriptions; screen->Descriptions = descriptions;
screen->DescriptionsCount = descsCount; screen->DescriptionsCount = descsCount;
screen->ActiveI = -1;
return (Screen*)screen; return (Screen*)screen;
} }

View File

@ -32,10 +32,10 @@ FN_GLBUFFERDATA glBufferData;
FN_GLBUFFERSUBDATA glBufferSubData; FN_GLBUFFERSUBDATA glBufferSubData;
Int32 Gfx_strideSizes[2] = GFX_STRIDE_SIZES; Int32 Gfx_strideSizes[2] = GFX_STRIDE_SIZES;
bool gl_lists = false;
Int32 gl_activeList = -1; Int32 gl_activeList = -1;
#define gl_DYNAMICLISTID 1234567891 #define gl_DYNAMICLISTID 1234567891
void* gl_dynamicListData; void* gl_dynamicListData;
bool gl_lists, gl_vsync;
Int32 gl_blend[6] = { GL_ZERO, GL_ONE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA }; Int32 gl_blend[6] = { GL_ZERO, GL_ONE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA };
Int32 gl_compare[8] = { GL_ALWAYS, GL_NOTEQUAL, GL_NEVER, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER }; Int32 gl_compare[8] = { GL_ALWAYS, GL_NOTEQUAL, GL_NEVER, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER };
@ -78,6 +78,7 @@ void GL_CheckVboSupport(void) {
} }
void Gfx_Init(void) { void Gfx_Init(void) {
Gfx_MinZNear = 0.1f;
GraphicsMode mode = GraphicsMode_MakeDefault(); GraphicsMode mode = GraphicsMode_MakeDefault();
GLContext_Init(mode); GLContext_Init(mode);
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &Gfx_MaxTextureDimensions); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &Gfx_MaxTextureDimensions);
@ -517,6 +518,13 @@ bool Gfx_WarnIfNecessary(void) {
return true; return true;
} }
void Gfx_SetVSync(bool value) {
if (gl_vsync == value) return;
gl_vsync = value;
GLContext_SetVSync(value);
}
void Gfx_BeginFrame(void) { } void Gfx_BeginFrame(void) { }
void Gfx_EndFrame(void) { void Gfx_EndFrame(void) {
GLContext_SwapBuffers(); GLContext_SwapBuffers();

View File

@ -382,8 +382,7 @@ void Particles_BreakBlockEffect(Vector3I coords, BlockID oldBlock, BlockID block
rec.V2 = min(rec.V2, maxV2) - 0.01f * vScale; rec.V2 = min(rec.V2, maxV2) - 0.01f * vScale;
if (Terrain_Count == PARTICLES_MAX) Terrain_RemoveAt(0); if (Terrain_Count == PARTICLES_MAX) Terrain_RemoveAt(0);
TerrainParticle* p = &Terrain_Particles[Terrain_Count - 1]; TerrainParticle* p = &Terrain_Particles[Terrain_Count++];
Terrain_Count++;
Real32 life = 0.3f + Random_Float(&rnd) * 1.2f; Real32 life = 0.3f + Random_Float(&rnd) * 1.2f;
Vector3 pos; Vector3 pos;
@ -412,8 +411,7 @@ void Particles_RainSnowEffect(Vector3 pos) {
offset.Z = Random_Float(&rnd); offset.Z = Random_Float(&rnd);
if (Rain_Count == PARTICLES_MAX) Rain_RemoveAt(0); if (Rain_Count == PARTICLES_MAX) Rain_RemoveAt(0);
RainParticle* p = &Rain_Particles[Rain_Count - 1]; RainParticle* p = &Rain_Particles[Rain_Count++];
Rain_Count++;
Vector3_Add(&pos, &startPos, &offset); Vector3_Add(&pos, &startPos, &offset);
Particle_Reset(&p->Base, pos, velocity, 40.0f); Particle_Reset(&p->Base, pos, velocity, 40.0f);

View File

@ -145,7 +145,7 @@ void Searcher_QuickSort(Int32 left, Int32 right) {
} }
} }
UInt32 Searcher_FindReachableBlocks(Entity* entity, AABB* entityBB, AABB* entityExtentBB) { Int32 Searcher_FindReachableBlocks(Entity* entity, AABB* entityBB, AABB* entityExtentBB) {
Vector3 vel = entity->Velocity; Vector3 vel = entity->Velocity;
Entity_GetBounds(entity, entityBB); Entity_GetBounds(entity, entityBB);
@ -177,7 +177,6 @@ UInt32 Searcher_FindReachableBlocks(Entity* entity, AABB* entityBB, AABB* entity
/* Order loops so that we minimise cache misses */ /* Order loops so that we minimise cache misses */
AABB blockBB; AABB blockBB;
UInt32 count = 0;
Int32 x, y, z; Int32 x, y, z;
SearcherState* curState = Searcher_States; SearcherState* curState = Searcher_States;
@ -208,6 +207,7 @@ UInt32 Searcher_FindReachableBlocks(Entity* entity, AABB* entityBB, AABB* entity
} }
} }
Int32 count = (Int32)(curState - Searcher_States);
if (count > 0) Searcher_QuickSort(0, count - 1); if (count > 0) Searcher_QuickSort(0, count - 1);
return count; return count;
} }

View File

@ -27,7 +27,7 @@ bool Intersection_RayIntersectsBox(Vector3 origin, Vector3 dir, Vector3 min, Vec
typedef struct SearcherState_ { Int32 X, Y, Z; Real32 tSquared; } SearcherState; typedef struct SearcherState_ { Int32 X, Y, Z; Real32 tSquared; } SearcherState;
extern SearcherState* Searcher_States; extern SearcherState* Searcher_States;
UInt32 Searcher_FindReachableBlocks(Entity* entity, AABB* entityBB, AABB* entityExtentBB); Int32 Searcher_FindReachableBlocks(Entity* entity, AABB* entityBB, AABB* entityExtentBB);
void Searcher_CalcTime(Vector3* vel, AABB *entityBB, AABB* blockBB, Real32* tx, Real32* ty, Real32* tz); void Searcher_CalcTime(Vector3* vel, AABB *entityBB, AABB* blockBB, Real32* tx, Real32* ty, Real32* tz);
void Searcher_Free(void); void Searcher_Free(void);
#endif #endif

View File

@ -49,6 +49,7 @@ int main(int argc, char* argv[]) {
String title = String_FromConst(PROGRAM_APP_NAME); String title = String_FromConst(PROGRAM_APP_NAME);
// if (argc == 1 || arc == 2) { // if (argc == 1 || arc == 2) {
if (true) { if (true) {
//String_AppendConst(&Game_Username, argc > 1 ? argv[1] : "Singleplayer");
String_AppendConst(&Game_Username, "Singleplayer"); String_AppendConst(&Game_Username, "Singleplayer");
} else if (argc < 5) { } else if (argc < 5) {
Platform_LogConst("ClassicalSharp.exe is only the raw client. You must either use the launcher or provide command line arguments to start the client."); Platform_LogConst("ClassicalSharp.exe is only the raw client. You must either use the launcher or provide command line arguments to start the client.");

View File

@ -173,7 +173,7 @@ void WeatherRenderer_Render(Real64 deltaTime) {
Gfx_SetAlphaArgBlend(true); Gfx_SetAlphaArgBlend(true);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B); Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
UInt32 vCount = (UInt32)(ptr - vertices) / (UInt32)sizeof(VertexP3fT2fC4b); Int32 vCount = (Int32)(ptr - vertices);
GfxCommon_UpdateDynamicVb_IndexedTris(weather_vb, vertices, vCount); GfxCommon_UpdateDynamicVb_IndexedTris(weather_vb, vertices, vCount);
Gfx_SetAlphaArgBlend(false); Gfx_SetAlphaArgBlend(false);

View File

@ -569,7 +569,7 @@ void TableWidget_UpdateDescTexPos(TableWidget* widget) {
} }
void TableWidget_UpdatePos(TableWidget* widget) { void TableWidget_UpdatePos(TableWidget* widget) {
Int32 rowsDisplayed = min(TABLE_MAX_ROWS_DISPLAYED, widget->ElementsCount); Int32 rowsDisplayed = min(TABLE_MAX_ROWS_DISPLAYED, widget->RowsCount);
widget->Width = widget->BlockSize * widget->ElementsPerRow; widget->Width = widget->BlockSize * widget->ElementsPerRow;
widget->Height = widget->BlockSize * rowsDisplayed; widget->Height = widget->BlockSize * rowsDisplayed;
widget->X = Game_Width / 2 - widget->Width / 2; widget->X = Game_Width / 2 - widget->Width / 2;
@ -638,7 +638,7 @@ void TableWidget_RecreateElements(TableWidget* widget) {
TableWidget_UpdatePos(widget); TableWidget_UpdatePos(widget);
Int32 index = 0; Int32 index = 0;
for (i = 0; i < count; i++) { for (i = 0; i < count;) {
if ((i % widget->ElementsPerRow) == 0 && TableWidget_RowEmpty(widget, i)) { if ((i % widget->ElementsPerRow) == 0 && TableWidget_RowEmpty(widget, i)) {
i += widget->ElementsPerRow; continue; i += widget->ElementsPerRow; continue;
} }
@ -2177,11 +2177,10 @@ void PlayerListWidget_Create(PlayerListWidget* widget, FontDesc* font, bool clas
void TextGroupWidget_PushUpAndReplaceLast(TextGroupWidget* widget, STRING_PURE String* text) { void TextGroupWidget_PushUpAndReplaceLast(TextGroupWidget* widget, STRING_PURE String* text) {
Int32 y = widget->Y; Int32 y = widget->Y;
Gfx_DeleteTexture(&widget->Textures[0].ID); Gfx_DeleteTexture(&widget->Textures[0].ID);
UInt32 i; Int32 i, max_index = widget->LinesCount - 1;
#define tgw_max_idx (Array_Elems(widget->Textures) - 1)
/* Move contents of X line to X - 1 line */ /* Move contents of X line to X - 1 line */
for (i = 0; i < tgw_max_idx; i++) { for (i = 0; i < max_index; i++) {
UInt8* dst = widget->Buffer + i * TEXTGROUPWIDGET_LEN; UInt8* dst = widget->Buffer + i * TEXTGROUPWIDGET_LEN;
UInt8* src = widget->Buffer + (i + 1) * TEXTGROUPWIDGET_LEN; UInt8* src = widget->Buffer + (i + 1) * TEXTGROUPWIDGET_LEN;
UInt8 lineLen = widget->LineLengths[i + 1]; UInt8 lineLen = widget->LineLengths[i + 1];
@ -2194,8 +2193,8 @@ void TextGroupWidget_PushUpAndReplaceLast(TextGroupWidget* widget, STRING_PURE S
y += widget->Textures[i].Height; y += widget->Textures[i].Height;
} }
widget->Textures[tgw_max_idx].ID = NULL; /* Delete() is called by SetText otherwise */ widget->Textures[max_index].ID = NULL; /* Delete() is called by SetText otherwise */
TextGroupWidget_SetText(widget, tgw_max_idx, text); TextGroupWidget_SetText(widget, max_index, text);
} }
Int32 TextGroupWidget_CalcY(TextGroupWidget* widget, Int32 index, Int32 newHeight) { Int32 TextGroupWidget_CalcY(TextGroupWidget* widget, Int32 index, Int32 newHeight) {

View File

@ -342,8 +342,8 @@ LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wParam, LPAR
/* The behavior of this key is very strange. Unlike Control and Alt, there is no extended bit /* The behavior of this key is very strange. Unlike Control and Alt, there is no extended bit
to distinguish between left and right keys. Moreover, pressing both keys and releasing one to distinguish between left and right keys. Moreover, pressing both keys and releasing one
may result in both keys being held down (but not always).*/ may result in both keys being held down (but not always).*/
lShiftDown = (GetKeyState(VK_LSHIFT) >> 15) == 1; lShiftDown = ((USHORT)GetKeyState(VK_LSHIFT)) >> 15;
rShiftDown = (GetKeyState(VK_RSHIFT) >> 15) == 1; rShiftDown = ((USHORT)GetKeyState(VK_RSHIFT)) >> 15;
if (!pressed || lShiftDown != rShiftDown) { if (!pressed || lShiftDown != rShiftDown) {
Key_SetPressed(Key_ShiftLeft, lShiftDown); Key_SetPressed(Key_ShiftLeft, lShiftDown);
@ -742,7 +742,7 @@ typedef BOOL (WINAPI *FN_WGLSWAPINTERVAL)(int interval);
typedef int (WINAPI *FN_WGLGETSWAPINTERVAL)(void); typedef int (WINAPI *FN_WGLGETSWAPINTERVAL)(void);
FN_WGLSWAPINTERVAL wglSwapIntervalEXT; FN_WGLSWAPINTERVAL wglSwapIntervalEXT;
FN_WGLGETSWAPINTERVAL wglGetSwapIntervalEXT; FN_WGLGETSWAPINTERVAL wglGetSwapIntervalEXT;
bool GLContext_vSync; bool GLContext_supports_vSync;
void GLContext_Init(GraphicsMode mode) { void GLContext_Init(GraphicsMode mode) {
GLContext_SelectGraphicsMode(mode); GLContext_SelectGraphicsMode(mode);
@ -761,7 +761,7 @@ void GLContext_Init(GraphicsMode mode) {
wglGetSwapIntervalEXT = (FN_WGLGETSWAPINTERVAL)GLContext_GetAddress("wglGetSwapIntervalEXT"); wglGetSwapIntervalEXT = (FN_WGLGETSWAPINTERVAL)GLContext_GetAddress("wglGetSwapIntervalEXT");
wglSwapIntervalEXT = (FN_WGLSWAPINTERVAL)GLContext_GetAddress("wglSwapIntervalEXT"); wglSwapIntervalEXT = (FN_WGLSWAPINTERVAL)GLContext_GetAddress("wglSwapIntervalEXT");
GLContext_vSync = wglGetSwapIntervalEXT != NULL && wglSwapIntervalEXT != NULL; GLContext_supports_vSync = wglGetSwapIntervalEXT != NULL && wglSwapIntervalEXT != NULL;
} }
void GLContext_Update(void) { } void GLContext_Update(void) { }
@ -784,10 +784,10 @@ void GLContext_SwapBuffers(void) {
} }
bool GLContext_GetVSync(void) { bool GLContext_GetVSync(void) {
return GLContext_vSync && wglGetSwapIntervalEXT(); return GLContext_supports_vSync && wglGetSwapIntervalEXT();
} }
void GLContext_SetVSync(bool enabled) { void GLContext_SetVSync(bool enabled) {
if (GLContext_vSync) wglSwapIntervalEXT(enabled ? 1 : 0); if (GLContext_supports_vSync) wglSwapIntervalEXT(enabled ? 1 : 0);
} }
#endif #endif

View File

@ -70,7 +70,7 @@ bool World_IsValidPos(Int32 x, Int32 y, Int32 z) {
} }
bool World_IsValidPos_3I(Vector3I p) { bool World_IsValidPos_3I(Vector3I p) {
return p.X >= 0 && p.Y >= 0 && p.Z <= 0 && return p.X >= 0 && p.Y >= 0 && p.Z >= 0 &&
p.X < World_Width && p.Y < World_Height && p.Z < World_Length; p.X < World_Width && p.Y < World_Height && p.Z < World_Length;
} }
@ -230,7 +230,7 @@ Real32 Respawn_HighestFreeY(AABB* bb) {
if (Block_Collide[block] != COLLIDE_SOLID) continue; if (Block_Collide[block] != COLLIDE_SOLID) continue;
if (!AABB_Intersects(bb, &blockBB)) continue; if (!AABB_Intersects(bb, &blockBB)) continue;
if (blockBB.Max.Y > spawnY) blockBB.Max.Y = spawnY; if (blockBB.Max.Y > spawnY) spawnY = blockBB.Max.Y;
} }
} }
} }