From 81ea790f8f8edd49d21c5a8d55eaf088c82c9a02 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 21 Apr 2018 18:13:31 +1000 Subject: [PATCH] more fixes --- .../Generator/FlatGrassGenerator.cs | 13 ++-- ClassicalSharp/GraphicsAPI/IGraphicsApi.cs | 2 +- ClassicalSharp/GraphicsAPI/OpenGLApi.cs | 1 + ClassicalSharp/GraphicsAPI/OpenGLESApi.cs | 1 + ClassicalSharp/MeshBuilder/Builder.cs | 4 +- OpenTK/Math/Vector4.cs | 4 ++ OpenTK/Platform/Windows/WinGLNative.cs | 3 +- src/Client/AxisLinesRenderer.c | 3 +- src/Client/BordersRenderer.c | 3 +- src/Client/Builder.c | 63 +++++++++---------- src/Client/ChunkUpdater.c | 17 +++-- src/Client/D3D9Api.c | 56 +++++++++-------- src/Client/Drawer.c | 2 +- src/Client/Drawer2D.c | 2 +- src/Client/EntityComponents.c | 6 +- src/Client/Game.c | 1 - src/Client/GraphicsCommon.c | 18 +++--- src/Client/GraphicsCommon.h | 2 +- src/Client/IsometricDrawer.c | 13 ++-- src/Client/MapGenerator.c | 53 ++++++++-------- src/Client/MapGenerator.h | 1 - src/Client/MapRenderer.h | 10 +-- src/Client/Menus.c | 4 +- src/Client/OpenGLApi.c | 10 ++- src/Client/Particle.c | 6 +- src/Client/Physics.c | 4 +- src/Client/Physics.h | 2 +- src/Client/Program.c | 3 +- src/Client/WeatherRenderer.c | 2 +- src/Client/Widgets.c | 13 ++-- src/Client/WinWindow.c | 12 ++-- src/Client/World.c | 6 +- 32 files changed, 179 insertions(+), 161 deletions(-) diff --git a/ClassicalSharp/Generator/FlatGrassGenerator.cs b/ClassicalSharp/Generator/FlatGrassGenerator.cs index 63cd4feff..cc5c334f0 100644 --- a/ClassicalSharp/Generator/FlatGrassGenerator.cs +++ b/ClassicalSharp/Generator/FlatGrassGenerator.cs @@ -24,15 +24,12 @@ namespace ClassicalSharp.Generator { unsafe void MapSet(BlockRaw* ptr, int yStart, int yEnd, BlockRaw block) { yStart = Math.Max(yStart, 0); yEnd = Math.Max(yEnd, 0); - int startIndex = yStart * Length * Width; - int endIndex = (yEnd * Length + (Length - 1)) * Width + (Width - 1); - int count = (endIndex - startIndex) + 1, offset = 0; + int oneY = Width * Length, yHeight = (yEnd - yStart) + 1; - while (offset < count) { - int bytes = Math.Min(count - offset, Width * Length); - MemUtils.memset((IntPtr)ptr, block, startIndex + offset, bytes); - offset += bytes; - CurrentProgress = (float)offset / count; + CurrentProgress = 0; + for (int y = yStart; y <= yEnd; y++) { + MemUtils.memset((IntPtr)ptr, block, y * oneY, oneY); + CurrentProgress = (float)(y - yStart) / yHeight; } } } diff --git a/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs b/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs index 43951def2..c09544cc3 100644 --- a/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs +++ b/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs @@ -20,7 +20,7 @@ namespace ClassicalSharp.GraphicsAPI { public abstract bool Texturing { set; } public Matrix4 Projection, View; - internal float MinZNear = 0.1f; + internal float MinZNear; // MinZNear = 0.1f; readonly FastBitmap bmpBuffer = new FastBitmap(); /// Returns whether this graphics api had a valid context. diff --git a/ClassicalSharp/GraphicsAPI/OpenGLApi.cs b/ClassicalSharp/GraphicsAPI/OpenGLApi.cs index f886bbcf4..777bcd4b4 100644 --- a/ClassicalSharp/GraphicsAPI/OpenGLApi.cs +++ b/ClassicalSharp/GraphicsAPI/OpenGLApi.cs @@ -22,6 +22,7 @@ namespace ClassicalSharp.GraphicsAPI { IntPtr dynamicListData; public OpenGLApi() { + MinZNear = 0.1f; InitFields(); int texDims; GL.GetIntegerv(GetPName.MaxTextureSize, &texDims); diff --git a/ClassicalSharp/GraphicsAPI/OpenGLESApi.cs b/ClassicalSharp/GraphicsAPI/OpenGLESApi.cs index e6c18c0dc..dd25ea89a 100644 --- a/ClassicalSharp/GraphicsAPI/OpenGLESApi.cs +++ b/ClassicalSharp/GraphicsAPI/OpenGLESApi.cs @@ -13,6 +13,7 @@ namespace ClassicalSharp.GraphicsAPI { public unsafe class OpenGLESApi : IGraphicsApi { public OpenGLESApi() { + MinZNear = 0.1f; InitFields(); int texDims; GL.GetInteger(All.MaxTextureSize, &texDims); diff --git a/ClassicalSharp/MeshBuilder/Builder.cs b/ClassicalSharp/MeshBuilder/Builder.cs index a112fa626..0d38bb21f 100644 --- a/ClassicalSharp/MeshBuilder/Builder.cs +++ b/ClassicalSharp/MeshBuilder/Builder.cs @@ -119,8 +119,8 @@ namespace ClassicalSharp { chunk[chunkIndex] = rawBlock; } } - outAllAir = allAir; outAllSolid = allSolid; } + outAllAir = allAir; outAllSolid = allSolid; } #if !ONLY_8BIT @@ -152,8 +152,8 @@ namespace ClassicalSharp { chunk[chunkIndex] = rawBlock; } } - outAllAir = allAir; outAllSolid = allSolid; } + outAllAir = allAir; outAllSolid = allSolid; } } #endif diff --git a/OpenTK/Math/Vector4.cs b/OpenTK/Math/Vector4.cs index c46efce2e..0ce4b423a 100644 --- a/OpenTK/Math/Vector4.cs +++ b/OpenTK/Math/Vector4.cs @@ -80,5 +80,9 @@ namespace OpenTK { public bool Equals(Vector4 other) { return X == other.X && Y == other.Y && Z == other.Z && W == other.W; } + + public override string ToString() { + return X + " : " + Y + " : " + Z + " : " + W; + } } } diff --git a/OpenTK/Platform/Windows/WinGLNative.cs b/OpenTK/Platform/Windows/WinGLNative.cs index 891be0c89..c1391249b 100644 --- a/OpenTK/Platform/Windows/WinGLNative.cs +++ b/OpenTK/Platform/Windows/WinGLNative.cs @@ -240,8 +240,7 @@ namespace OpenTK.Platform.Windows case WindowMessage.KEYUP: case WindowMessage.SYSKEYDOWN: case WindowMessage.SYSKEYUP: - bool pressed = message == WindowMessage.KEYDOWN || - message == WindowMessage.SYSKEYDOWN; + bool pressed = message == WindowMessage.KEYDOWN || message == WindowMessage.SYSKEYDOWN; // 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 diff --git a/src/Client/AxisLinesRenderer.c b/src/Client/AxisLinesRenderer.c index 37416b490..f721876a1 100644 --- a/src/Client/AxisLinesRenderer.c +++ b/src/Client/AxisLinesRenderer.c @@ -65,5 +65,6 @@ void AxisLinesRenderer_Render(Real64 delta) { } 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); } \ No newline at end of file diff --git a/src/Client/BordersRenderer.c b/src/Client/BordersRenderer.c index f39cb461a..07a2138ce 100644 --- a/src/Client/BordersRenderer.c +++ b/src/Client/BordersRenderer.c @@ -47,9 +47,8 @@ void BordersRenderer_RenderSides(Real64 delta) { } void BordersRenderer_RenderEdges(Real64 delta) { - if (borders_edgesVb == NULL) return; 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. */ /* Fixes some 'depth bleeding through' issues with 16 bit depth buffers on large maps. */ diff --git a/src/Client/Builder.c b/src/Client/Builder.c index 8db3aedbe..54d7268fa 100644 --- a/src/Client/Builder.c +++ b/src/Client/Builder.c @@ -101,25 +101,22 @@ void Builder_AddVertices(BlockID block, Face face) { 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); if (vCount == 0) return; - ChunkPartInfo info; /* add an extra element to fix crashing on some GPUs */ - info.VbId = Gfx_CreateVb(part->vertices, VERTEX_FORMAT_P3FT2FC4B, vCount + 1); - info.HasVertices = vCount > 0; - - 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; - + info->VbId = Gfx_CreateVb(part->vertices, VERTEX_FORMAT_P3FT2FC4B, vCount + 1); + info->HasVertices = 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; Int32 xx, yy, zz; @@ -272,14 +269,9 @@ bool Builder_ReadChunkData(Int32 x1, Int32 y1, Int32 z1, bool* outAllAir) { } } } + *outAllAir = allAir; - - 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; + *outAllSolid = allSolid; } 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; Platform_MemSet(chunk, BLOCK_AIR, EXTCHUNK_SIZE_3 * sizeof(BlockID)); - if (Builder_ReadChunkData(x1, y1, z1, allAir)) return false; - Platform_MemSet(counts, 1, CHUNK_SIZE_3 * FACE_COUNT); + bool allSolid; + 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 yMax = min(World_Height, y1 + 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) { Int32 x = info->CentreX - 8, y = info->CentreY - 8, z = info->CentreZ - 8; bool allAir = false, hasMesh; - hasMesh = Builder_BuildChunk(Builder_X, Builder_Y, Builder_Z, &allAir); + hasMesh = Builder_BuildChunk(x, y, z, &allAir); info->AllAir = allAir; if (!hasMesh) return; @@ -331,18 +330,18 @@ void Builder_MakeChunk(ChunkInfo* info) { bool hasNormal = false, hasTranslucent = false; for (i = 0; i < Atlas1D_Count; i++) { - Int32 idx = partsIndex + i * MapRenderer_ChunksCount; - Builder_SetPartInfo(&Builder_Parts[i], i, - idx, &hasNormal); - Builder_SetPartInfo(&Builder_Parts[i + ATLAS1D_MAX_ATLASES_COUNT], i, - idx + MapRenderer_TranslucentBufferOffset, &hasTranslucent); + Int32 j = i + ATLAS1D_MAX_ATLASES_COUNT; + Int32 curIdx = partsIndex + i * MapRenderer_ChunksCount; + + Builder_SetPartInfo(&Builder_Parts[i], &MapRenderer_PartsNormal[curIdx], &hasNormal); + Builder_SetPartInfo(&Builder_Parts[j], &MapRenderer_PartsTranslucent[curIdx], &hasTranslucent); } if (hasNormal) { - info->NormalParts = &MapRenderer_PartsBuffer[partsIndex]; + info->NormalParts = &MapRenderer_PartsNormal[partsIndex]; } if (hasTranslucent) { - info->NormalParts = &MapRenderer_PartsBuffer[partsIndex + MapRenderer_TranslucentBufferOffset]; + info->TranslucentParts = &MapRenderer_PartsTranslucent[partsIndex]; } #if OCCLUSION diff --git a/src/Client/ChunkUpdater.c b/src/Client/ChunkUpdater.c index bef0e5d36..f779a2ccc 100644 --- a/src/Client/ChunkUpdater.c +++ b/src/Client/ChunkUpdater.c @@ -118,7 +118,10 @@ void ChunkUpdater_FreeAllocations(void) { Platform_MemFree(&MapRenderer_SortedChunks); Platform_MemFree(&MapRenderer_RenderChunks); Platform_MemFree(&ChunkUpdater_Distances); - Platform_MemFree(&MapRenderer_PartsBuffer); + Platform_MemFree(&MapRenderer_PartsBuffer_Raw); + + MapRenderer_PartsNormal = NULL; + MapRenderer_PartsTranslucent = NULL; } void ChunkUpdater_PerformAllocations(void) { @@ -134,10 +137,14 @@ void ChunkUpdater_PerformAllocations(void) { ChunkUpdater_Distances = Platform_MemAlloc(MapRenderer_ChunksCount * sizeof(Int32)); if (ChunkUpdater_Distances == NULL) ErrorHandler_Fail("ChunkUpdater - failed to allocate chunk distances"); - UInt32 partsSize = MapRenderer_ChunksCount * (sizeof(ChunkPartInfo) * MapRenderer_1DUsedCount); - MapRenderer_PartsBuffer = Platform_MemAlloc(partsSize); - if (MapRenderer_PartsBuffer == NULL) ErrorHandler_Fail("ChunkUpdater - failed to allocate chunk parts buffer"); - Platform_MemSet(MapRenderer_PartsBuffer, 0, partsSize); + UInt32 partsCount = MapRenderer_ChunksCount * MapRenderer_1DUsedCount; + UInt32 partsSize = (partsCount * (UInt32)sizeof(ChunkPartInfo)) * 2; + MapRenderer_PartsBuffer_Raw = Platform_MemAlloc(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) { diff --git a/src/Client/D3D9Api.c b/src/Client/D3D9Api.c index b9a41b38f..517022398 100644 --- a/src/Client/D3D9Api.c +++ b/src/Client/D3D9Api.c @@ -27,12 +27,12 @@ D3DTRANSFORMSTATETYPE curMatrix; DWORD createFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; D3DFORMAT d3d9_viewFormat, d3d9_depthFormat; -#define D3D9_SetRenderState(raw, state, name) \ -ReturnCode hresult = IDirect3DDevice9_SetRenderState(device, state, raw); \ +#define D3D9_SetRenderState(state, value, name) \ +ReturnCode hresult = IDirect3DDevice9_SetRenderState(device, state, value); \ ErrorHandler_CheckOrFail(hresult, name) -#define D3D9_SetRenderState2(raw, state, name) \ -hresult = IDirect3DDevice9_SetRenderState(device, state, raw); \ +#define D3D9_SetRenderState2(state, value, name) \ +hresult = IDirect3DDevice9_SetRenderState(device, state, value); \ ErrorHandler_CheckOrFail(hresult, name) #define D3D9_LogLeakedResource(msg, i) \ @@ -301,7 +301,7 @@ void Gfx_SetFog(bool enabled) { if (d3d9_fogEnable == enabled) return; d3d9_fogEnable = enabled; - D3D9_SetRenderState((UInt32)enabled, D3DRS_FOGENABLE, "D3D9_SetFog"); + D3D9_SetRenderState(D3DRS_FOGENABLE, (UInt32)enabled, "D3D9_SetFog"); } UInt32 d3d9_fogCol = 0xFF000000; /* black */ @@ -309,7 +309,7 @@ void Gfx_SetFogColour(PackedCol col) { if (col.Packed == d3d9_fogCol) return; 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; @@ -318,14 +318,14 @@ void Gfx_SetFogDensity(Real32 value) { d3d9_fogDensity = value; UInt32 raw = *(UInt32*)&value; - D3D9_SetRenderState(raw, D3DRS_FOGDENSITY, "D3D9_SetFogDensity"); + D3D9_SetRenderState(D3DRS_FOGDENSITY, raw, "D3D9_SetFogDensity"); } Real32 d3d9_fogStart = -1.0f; void Gfx_SetFogStart(Real32 value) { d3d9_fogStart = value; UInt32 raw = *(UInt32*)&value; - D3D9_SetRenderState(raw, D3DRS_FOGSTART, "D3D9_SetFogStart"); + D3D9_SetRenderState(D3DRS_FOGSTART, raw, "D3D9_SetFogStart"); } Real32 d3d9_fogEnd = -1.0f; @@ -334,7 +334,7 @@ void Gfx_SetFogEnd(Real32 value) { d3d9_fogEnd = value; UInt32 raw = *(UInt32*)&value; - D3D9_SetRenderState(raw, D3DRS_FOGEND, "D3D9_SetFogEnd"); + D3D9_SetRenderState(D3DRS_FOGEND, raw, "D3D9_SetFogEnd"); } D3DFOGMODE d3d9_fogTableMode = D3DFOG_NONE; @@ -343,13 +343,13 @@ void Gfx_SetFogMode(Int32 fogMode) { if (mode == d3d9_fogTableMode) return; d3d9_fogTableMode = mode; - D3D9_SetRenderState(mode, D3DRS_FOGTABLEMODE, "D3D9_SetFogMode"); + D3D9_SetRenderState(D3DRS_FOGTABLEMODE, mode, "D3D9_SetFogMode"); } void Gfx_SetFaceCulling(bool enabled) { 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; @@ -357,16 +357,16 @@ void Gfx_SetAlphaTest(bool enabled) { if (d3d9_alphaTest == enabled) return; d3d9_alphaTest = enabled; - D3D9_SetRenderState((UInt32)enabled, D3DRS_ALPHATESTENABLE, "D3D9_SetAlphaTest"); + D3D9_SetRenderState(D3DRS_ALPHATESTENABLE, (UInt32)enabled, "D3D9_SetAlphaTest"); } D3DCMPFUNC d3d9_alphaTestFunc = D3DCMP_ALWAYS; Int32 d3d9_alphaTestRef = 0; void Gfx_SetAlphaTestFunc(Int32 compareFunc, Real32 refValue) { 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_SetRenderState2(d3d9_alphaTestRef, D3DRS_ALPHAREF, "D3D9_SetAlphaTest_Ref"); + D3D9_SetRenderState2(D3DRS_ALPHAREF, d3d9_alphaTestRef, "D3D9_SetAlphaTest_Ref"); } bool d3d9_alphaBlend = false; @@ -374,16 +374,16 @@ void Gfx_SetAlphaBlending(bool enabled) { if (d3d9_alphaBlend == enabled) return; 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_dstBlendFunc = D3DBLEND_ZERO; void Gfx_SetAlphaBlendFunc(Int32 srcBlendFunc, Int32 dstBlendFunc) { 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_SetRenderState2(d3d9_dstBlendFunc, D3DRS_DESTBLEND, "D3D9_SetAlphaBlendFunc_Dst"); + D3D9_SetRenderState2(D3DRS_DESTBLEND, d3d9_dstBlendFunc, "D3D9_SetAlphaBlendFunc_Dst"); } void Gfx_SetAlphaArgBlend(bool enabled) { @@ -407,24 +407,24 @@ void Gfx_ClearColour(PackedCol col) { bool d3d9_depthTest = false; void Gfx_SetDepthTest(bool 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; void Gfx_SetDepthTestFunc(Int32 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) { 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; void Gfx_SetDepthWrite(bool 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; } +void Gfx_SetVSync(bool value) { + if (d3d9_vsync == value) return; + d3d9_vsync = value; + + GfxCommon_LoseContext(" (toggling VSync)"); + D3D9_RecreateDevice(); +} + void Gfx_BeginFrame(void) { IDirect3DDevice9_BeginScene(device); } @@ -598,15 +606,13 @@ void Gfx_EndFrame(void) { } /* TODO: Make sure this actually works on all graphics cards.*/ - String reason = String_FromConst(" (Direct3D9 device lost)"); - GfxCommon_LoseContext(&reason); + GfxCommon_LoseContext(" (Direct3D9 device lost)"); D3D9_LoopUntilRetrieved(); D3D9_RecreateDevice(); } void Gfx_OnWindowResize(void) { - String reason = String_FromConst(" (resizing window)"); - GfxCommon_LoseContext(&reason); + GfxCommon_LoseContext(" (resizing window)"); D3D9_RecreateDevice(); } diff --git a/src/Client/Drawer.c b/src/Client/Drawer.c index 8794bfb72..840024c0b 100644 --- a/src/Client/Drawer.c +++ b/src/Client/Drawer.c @@ -33,7 +33,7 @@ void Drawer_XMax(Int32 count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b* Real32 u1 = (count - Drawer_MinBB.Z); Real32 u2 = (1 - Drawer_MaxBB.Z) * UV2_Scale; 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; VertexP3fT2fC4b* ptr = *vertices; diff --git a/src/Client/Drawer2D.c b/src/Client/Drawer2D.c index 21f7c2850..c0b0c97bf 100644 --- a/src/Client/Drawer2D.c +++ b/src/Client/Drawer2D.c @@ -100,7 +100,7 @@ void Drawer2D_Begin(Bitmap* bmp) { } void Drawer2D_End(void) { - Platform_SetBitmap(Drawer2D_Cur); + Platform_ReleaseBitmap(); Drawer2D_Cur = NULL; } diff --git a/src/Client/EntityComponents.c b/src/Client/EntityComponents.c index 458a19b04..93db46e04 100644 --- a/src/Client/EntityComponents.c +++ b/src/Client/EntityComponents.c @@ -785,7 +785,7 @@ void Collisions_ClipYMax(CollisionsComp* comp, AABB* blockBB, AABB* entityBB, AA 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; /* Reset collision detection states */ bool wasOn = entity->OnGround; @@ -795,7 +795,7 @@ void Collisions_CollideWithReachableBlocks(CollisionsComp* comp, UInt32 count, A AABB blockBB; Vector3 bPos, size = entity->Size; - UInt32 i; + Int32 i; for (i = 0; i < count; i++) { /* Unpack the block and coordinate data */ SearcherState state = Searcher_States[i]; @@ -863,7 +863,7 @@ void Collisions_MoveAndWallSlide(CollisionsComp* comp) { if (Vector3_Equals(&entity->Velocity, &zero)) return; AABB entityBB, entityExtentBB; - UInt32 count = Searcher_FindReachableBlocks(entity, &entityBB, &entityExtentBB); + Int32 count = Searcher_FindReachableBlocks(entity, &entityBB, &entityExtentBB); Collisions_CollideWithReachableBlocks(comp, count, &entityBB, &entityExtentBB); } diff --git a/src/Client/Game.c b/src/Client/Game.c index b3c94bc51..bb27155c4 100644 --- a/src/Client/Game.c +++ b/src/Client/Game.c @@ -772,7 +772,6 @@ void Schematic_Save(Stream* stream) { } void Gfx_MakeApiInfo(void) { } void ServerConnection_InitMultiplayer(void) { } void Gfx_TakeScreenshot(STRING_PURE String* output, Int32 width, Int32 height) { } -void Gfx_SetVSync(bool value) { } void ServerConnection_RetrieveTexturePack(STRING_PURE String* url) { } bool Convert_TryParseInt64(STRING_PURE String* str, Int64* value) { return true; } DateTime DateTime_FromTotalMs(Int64 ms) { DateTime time; return time; } diff --git a/src/Client/GraphicsCommon.c b/src/Client/GraphicsCommon.c index 3a2c215f4..2068bf859 100644 --- a/src/Client/GraphicsCommon.c +++ b/src/Client/GraphicsCommon.c @@ -22,11 +22,11 @@ void GfxCommon_Free(void) { Gfx_DeleteIb(&GfxCommon_defaultIb); } -void GfxCommon_LoseContext(STRING_PURE String* reason) { +void GfxCommon_LoseContext(const UInt8* reason) { Gfx_LostContext = true; String logMsg = String_FromConst("Lost graphics context:"); Platform_Log(&logMsg); - Platform_Log(reason); + Platform_LogConst(reason); Event_RaiseVoid(&GfxEvents_ContextLost); GfxCommon_Free(); @@ -126,7 +126,7 @@ void GfxCommon_Mode3D(void) { Gfx_SetMatrixMode(MATRIX_TYPE_MODELVIEW); Gfx_LoadMatrix(&Gfx_View); - Gfx_SetDepthTest(false); + Gfx_SetDepthTest(true); Gfx_SetAlphaBlending(false); if (gfx_hadFog) Gfx_SetFog(true); } @@ -148,17 +148,17 @@ void GfxCommon_MakeIndices(UInt16* indices, Int32 iCount) { } void GfxCommon_SetupAlphaState(UInt8 draw) { - if (draw == DRAW_TRANSLUCENT) Gfx_SetAlphaBlending(true); - if (draw == DRAW_TRANSPARENT) Gfx_SetAlphaTest(true); + if (draw == DRAW_TRANSLUCENT) Gfx_SetAlphaBlending(true); + if (draw == DRAW_TRANSPARENT) Gfx_SetAlphaTest(true); if (draw == DRAW_TRANSPARENT_THICK) Gfx_SetAlphaTest(true); - if (draw == DRAW_SPRITE) Gfx_SetAlphaTest(true); + if (draw == DRAW_SPRITE) Gfx_SetAlphaTest(true); } void GfxCommon_RestoreAlphaState(UInt8 draw) { - if (draw == DRAW_TRANSLUCENT) Gfx_SetAlphaBlending(false); - if (draw == DRAW_TRANSPARENT) Gfx_SetAlphaTest(false); + if (draw == DRAW_TRANSLUCENT) Gfx_SetAlphaBlending(false); + if (draw == DRAW_TRANSPARENT) Gfx_SetAlphaTest(false); if (draw == DRAW_TRANSPARENT_THICK) Gfx_SetAlphaTest(false); - if (draw == DRAW_SPRITE) Gfx_SetAlphaTest(false); + if (draw == DRAW_SPRITE) Gfx_SetAlphaTest(false); } diff --git a/src/Client/GraphicsCommon.h b/src/Client/GraphicsCommon.h index 8341f4226..7553a9b7d 100644 --- a/src/Client/GraphicsCommon.h +++ b/src/Client/GraphicsCommon.h @@ -11,7 +11,7 @@ typedef struct Texture_ Texture; GfxResourceID GfxCommon_defaultIb; void GfxCommon_Init(void); void GfxCommon_Free(void); -void GfxCommon_LoseContext(STRING_PURE String* reason); +void GfxCommon_LoseContext(const UInt8* reason); void GfxCommon_RecreateContext(void); /* Binds and draws the specified subset of the vertices in the current dynamic vertex buffer diff --git a/src/Client/IsometricDrawer.c b/src/Client/IsometricDrawer.c index 295e53ff6..7ebf8cb6b 100644 --- a/src/Client/IsometricDrawer.c +++ b/src/Client/IsometricDrawer.c @@ -7,7 +7,6 @@ #include "Block.h" #include "TerrainAtlas.h" -Int32 iso_count; Real32 iso_scale; VertexP3fT2fC4b* iso_vertices; VertexP3fT2fC4b* iso_base_vertices; @@ -54,11 +53,11 @@ void IsometricDrawer_InitCache(void) { void IsometricDrawer_Flush(void) { if (iso_lastTexIndex != -1) { 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_count = 0; iso_vertices = iso_base_vertices; } @@ -124,7 +123,6 @@ void IsometricDrawer_SpriteXQuad(BlockID block, bool firstPart) { void IsometricDrawer_BeginBatch(VertexP3fT2fC4b* vertices, GfxResourceID vb) { IsometricDrawer_InitCache(); iso_lastTexIndex = -1; - iso_count = 0; iso_vertices = vertices; iso_base_vertices = vertices; 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); Drawer_YMax(1, iso_colNormal, IsometricDrawer_GetTexLoc(block, FACE_YMAX), &iso_vertices); - iso_count += 4 * 3; } } 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; Gfx_LoadIdentityMatrix(); } \ No newline at end of file diff --git a/src/Client/MapGenerator.c b/src/Client/MapGenerator.c index af009c66b..ce3a41a02 100644 --- a/src/Client/MapGenerator.c +++ b/src/Client/MapGenerator.c @@ -9,32 +9,36 @@ #include "TreeGen.h" #include "Vectors.h" -void FlatgrassGen_MapSet(Int32 yStart, Int32 yEnd, BlockID block) { - yStart = max(yStart, 0); yEnd = max(yEnd, 0); - Int32 startIndex = yStart * Gen_Length * Gen_Width; - 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) { +Int32 Gen_MaxX, Gen_MaxY, Gen_MaxZ; +void Gen_Init(void) { + Gen_MaxX = Gen_Width - 1; Gen_MaxY = Gen_Height - 1; Gen_MaxZ = Gen_Length - 1; Gen_CurrentProgress = 0.0f; Gen_CurrentState = ""; Gen_Blocks = Platform_MemAlloc(Gen_Width * Gen_Height * Gen_Length * sizeof(BlockID)); 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"; FlatgrassGen_MapSet(0, Gen_Height / 2 - 2, BLOCK_DIRT); @@ -455,19 +459,12 @@ void NotchyGen_PlantTrees(void) { } void NotchyGen_Generate(void) { - Gen_CurrentProgress = 0.0f; - Gen_CurrentState = ""; - + Gen_Init(); Heightmap = Platform_MemAlloc(Gen_Width * Gen_Length * sizeof(Int16)); if (Heightmap == NULL) { 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); volume = Gen_Width * Gen_Length * Gen_Height; oneY = Gen_Width * Gen_Length; diff --git a/src/Client/MapGenerator.h b/src/Client/MapGenerator.h index 370d281ed..83ea505dd 100644 --- a/src/Client/MapGenerator.h +++ b/src/Client/MapGenerator.h @@ -11,7 +11,6 @@ volatile Real32 Gen_CurrentProgress; volatile const UInt8* Gen_CurrentState; volatile bool Gen_Done; Int32 Gen_Width, Gen_Height, Gen_Length; -Int32 Gen_MaxX, Gen_MaxY, Gen_MaxZ; Int32 Gen_Seed; BlockID* Gen_Blocks; #define Gen_Pack(x, y, z) (((y) * Gen_Length + (z)) * Gen_Width + (x)) diff --git a/src/Client/MapRenderer.h b/src/Client/MapRenderer.h index 10869aa9d..9d3ec8837 100644 --- a/src/Client/MapRenderer.h +++ b/src/Client/MapRenderer.h @@ -41,11 +41,11 @@ ChunkInfo** MapRenderer_RenderChunks; /* The number of actually used pointers in the RenderChunks array. Entries past this count should be ignored and skipped. */ Int32 MapRenderer_RenderChunksCount; -/* Buffer for all chunk parts. -There are MapRenderer_ChunksCount * Atlas1D_Count * 2 parts in the buffer. */ -ChunkPartInfo* MapRenderer_PartsBuffer; -/* Offset of translucent chunk parts in MapRenderer_PartsBuffer. */ -Int32 MapRenderer_TranslucentBufferOffset; +/* Buffer for all chunk parts. There are (MapRenderer_ChunksCount * Atlas1D_Count) * 2 parts in the buffer, + with parts for 'normal' buffer being in lower half. */ +ChunkPartInfo* MapRenderer_PartsBuffer_Raw; +ChunkPartInfo* MapRenderer_PartsNormal; +ChunkPartInfo* MapRenderer_PartsTranslucent; ChunkInfo* MapRenderer_GetChunk(Int32 cx, Int32 cy, Int32 cz); void MapRenderer_RefreshChunk(Int32 cx, Int32 cy, Int32 cz); diff --git a/src/Client/Menus.c b/src/Client/Menus.c index 711b833e9..1f65915e5 100644 --- a/src/Client/Menus.c +++ b/src/Client/Menus.c @@ -1935,7 +1935,7 @@ void MenuOptionsScreen_SelectExtHelp(MenuOptionsScreen* screen, Int32 idx) { UInt32 descLinesCount = Array_Elems(descLines); 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); Elem_Init(&screen->ExtHelp); @@ -2163,6 +2163,8 @@ Screen* MenuOptionsScreen_MakeInstance(Widget** widgets, Int32 count, ButtonWidg screen->DefaultValues = defaultValues; screen->Descriptions = descriptions; screen->DescriptionsCount = descsCount; + + screen->ActiveI = -1; return (Screen*)screen; } diff --git a/src/Client/OpenGLApi.c b/src/Client/OpenGLApi.c index f3ba372fa..2e434334b 100644 --- a/src/Client/OpenGLApi.c +++ b/src/Client/OpenGLApi.c @@ -32,10 +32,10 @@ FN_GLBUFFERDATA glBufferData; FN_GLBUFFERSUBDATA glBufferSubData; Int32 Gfx_strideSizes[2] = GFX_STRIDE_SIZES; -bool gl_lists = false; Int32 gl_activeList = -1; #define gl_DYNAMICLISTID 1234567891 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_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) { + Gfx_MinZNear = 0.1f; GraphicsMode mode = GraphicsMode_MakeDefault(); GLContext_Init(mode); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &Gfx_MaxTextureDimensions); @@ -517,6 +518,13 @@ bool Gfx_WarnIfNecessary(void) { return true; } + +void Gfx_SetVSync(bool value) { + if (gl_vsync == value) return; + gl_vsync = value; + GLContext_SetVSync(value); +} + void Gfx_BeginFrame(void) { } void Gfx_EndFrame(void) { GLContext_SwapBuffers(); diff --git a/src/Client/Particle.c b/src/Client/Particle.c index 9f52dac1a..87e95d2df 100644 --- a/src/Client/Particle.c +++ b/src/Client/Particle.c @@ -382,8 +382,7 @@ void Particles_BreakBlockEffect(Vector3I coords, BlockID oldBlock, BlockID block rec.V2 = min(rec.V2, maxV2) - 0.01f * vScale; if (Terrain_Count == PARTICLES_MAX) Terrain_RemoveAt(0); - TerrainParticle* p = &Terrain_Particles[Terrain_Count - 1]; - Terrain_Count++; + TerrainParticle* p = &Terrain_Particles[Terrain_Count++]; Real32 life = 0.3f + Random_Float(&rnd) * 1.2f; Vector3 pos; @@ -412,8 +411,7 @@ void Particles_RainSnowEffect(Vector3 pos) { offset.Z = Random_Float(&rnd); if (Rain_Count == PARTICLES_MAX) Rain_RemoveAt(0); - RainParticle* p = &Rain_Particles[Rain_Count - 1]; - Rain_Count++; + RainParticle* p = &Rain_Particles[Rain_Count++]; Vector3_Add(&pos, &startPos, &offset); Particle_Reset(&p->Base, pos, velocity, 40.0f); diff --git a/src/Client/Physics.c b/src/Client/Physics.c index 2b99695b3..c2226141f 100644 --- a/src/Client/Physics.c +++ b/src/Client/Physics.c @@ -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; 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 */ AABB blockBB; - UInt32 count = 0; Int32 x, y, z; 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); return count; } diff --git a/src/Client/Physics.h b/src/Client/Physics.h index 15ddd1482..94a638725 100644 --- a/src/Client/Physics.h +++ b/src/Client/Physics.h @@ -27,7 +27,7 @@ bool Intersection_RayIntersectsBox(Vector3 origin, Vector3 dir, Vector3 min, Vec typedef struct SearcherState_ { Int32 X, Y, Z; Real32 tSquared; } SearcherState; 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_Free(void); #endif \ No newline at end of file diff --git a/src/Client/Program.c b/src/Client/Program.c index b7e8c2b2c..3a648d412 100644 --- a/src/Client/Program.c +++ b/src/Client/Program.c @@ -49,7 +49,8 @@ int main(int argc, char* argv[]) { String title = String_FromConst(PROGRAM_APP_NAME); // if (argc == 1 || arc == 2) { if (true) { - String_AppendConst(&Game_Username, "Singleplayer"); + //String_AppendConst(&Game_Username, argc > 1 ? argv[1] : "Singleplayer"); + String_AppendConst(&Game_Username, "Singleplayer"); } 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."); return; diff --git a/src/Client/WeatherRenderer.c b/src/Client/WeatherRenderer.c index b4199e3e3..ada7dc546 100644 --- a/src/Client/WeatherRenderer.c +++ b/src/Client/WeatherRenderer.c @@ -173,7 +173,7 @@ void WeatherRenderer_Render(Real64 deltaTime) { Gfx_SetAlphaArgBlend(true); 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); Gfx_SetAlphaArgBlend(false); diff --git a/src/Client/Widgets.c b/src/Client/Widgets.c index 01ea69820..bb589f175 100644 --- a/src/Client/Widgets.c +++ b/src/Client/Widgets.c @@ -569,7 +569,7 @@ void TableWidget_UpdateDescTexPos(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->Height = widget->BlockSize * rowsDisplayed; widget->X = Game_Width / 2 - widget->Width / 2; @@ -638,7 +638,7 @@ void TableWidget_RecreateElements(TableWidget* widget) { TableWidget_UpdatePos(widget); Int32 index = 0; - for (i = 0; i < count; i++) { + for (i = 0; i < count;) { if ((i % widget->ElementsPerRow) == 0 && TableWidget_RowEmpty(widget, i)) { 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) { Int32 y = widget->Y; Gfx_DeleteTexture(&widget->Textures[0].ID); - UInt32 i; -#define tgw_max_idx (Array_Elems(widget->Textures) - 1) + Int32 i, max_index = widget->LinesCount - 1; /* 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* src = widget->Buffer + (i + 1) * TEXTGROUPWIDGET_LEN; UInt8 lineLen = widget->LineLengths[i + 1]; @@ -2194,8 +2193,8 @@ void TextGroupWidget_PushUpAndReplaceLast(TextGroupWidget* widget, STRING_PURE S y += widget->Textures[i].Height; } - widget->Textures[tgw_max_idx].ID = NULL; /* Delete() is called by SetText otherwise */ - TextGroupWidget_SetText(widget, tgw_max_idx, text); + widget->Textures[max_index].ID = NULL; /* Delete() is called by SetText otherwise */ + TextGroupWidget_SetText(widget, max_index, text); } Int32 TextGroupWidget_CalcY(TextGroupWidget* widget, Int32 index, Int32 newHeight) { diff --git a/src/Client/WinWindow.c b/src/Client/WinWindow.c index c9815c805..99afb98d4 100644 --- a/src/Client/WinWindow.c +++ b/src/Client/WinWindow.c @@ -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 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).*/ - lShiftDown = (GetKeyState(VK_LSHIFT) >> 15) == 1; - rShiftDown = (GetKeyState(VK_RSHIFT) >> 15) == 1; + lShiftDown = ((USHORT)GetKeyState(VK_LSHIFT)) >> 15; + rShiftDown = ((USHORT)GetKeyState(VK_RSHIFT)) >> 15; if (!pressed || lShiftDown != rShiftDown) { Key_SetPressed(Key_ShiftLeft, lShiftDown); @@ -742,7 +742,7 @@ typedef BOOL (WINAPI *FN_WGLSWAPINTERVAL)(int interval); typedef int (WINAPI *FN_WGLGETSWAPINTERVAL)(void); FN_WGLSWAPINTERVAL wglSwapIntervalEXT; FN_WGLGETSWAPINTERVAL wglGetSwapIntervalEXT; -bool GLContext_vSync; +bool GLContext_supports_vSync; void GLContext_Init(GraphicsMode mode) { GLContext_SelectGraphicsMode(mode); @@ -761,7 +761,7 @@ void GLContext_Init(GraphicsMode mode) { wglGetSwapIntervalEXT = (FN_WGLGETSWAPINTERVAL)GLContext_GetAddress("wglGetSwapIntervalEXT"); wglSwapIntervalEXT = (FN_WGLSWAPINTERVAL)GLContext_GetAddress("wglSwapIntervalEXT"); - GLContext_vSync = wglGetSwapIntervalEXT != NULL && wglSwapIntervalEXT != NULL; + GLContext_supports_vSync = wglGetSwapIntervalEXT != NULL && wglSwapIntervalEXT != NULL; } void GLContext_Update(void) { } @@ -784,10 +784,10 @@ void GLContext_SwapBuffers(void) { } bool GLContext_GetVSync(void) { - return GLContext_vSync && wglGetSwapIntervalEXT(); + return GLContext_supports_vSync && wglGetSwapIntervalEXT(); } void GLContext_SetVSync(bool enabled) { - if (GLContext_vSync) wglSwapIntervalEXT(enabled ? 1 : 0); + if (GLContext_supports_vSync) wglSwapIntervalEXT(enabled ? 1 : 0); } #endif \ No newline at end of file diff --git a/src/Client/World.c b/src/Client/World.c index a7705e45c..6bdff4f20 100644 --- a/src/Client/World.c +++ b/src/Client/World.c @@ -65,12 +65,12 @@ BlockID World_SafeGetBlock_3I(Vector3I p) { } bool World_IsValidPos(Int32 x, Int32 y, Int32 z) { - return x >= 0 && y >= 0 && z >= 0 && + return x >= 0 && y >= 0 && z >= 0 && x < World_Width && y < World_Height && z < World_Length; } 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; } @@ -230,7 +230,7 @@ Real32 Respawn_HighestFreeY(AABB* bb) { if (Block_Collide[block] != COLLIDE_SOLID) 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; } } }