diff --git a/src/Client/Animations.c b/src/Client/Animations.c index ab6b8a2dc..d6bc23464 100644 --- a/src/Client/Animations.c +++ b/src/Client/Animations.c @@ -23,8 +23,7 @@ static void LavaAnimation_Tick(UInt32* ptr, Int32 size) { Random_InitFromCurrentTime(&L_rnd); L_rndInitalised = true; } - Int32 mask = size - 1; - Int32 shift = Math_Log2(size); + Int32 mask = size - 1, shift = Math_Log2(size); Int32 x, y, i = 0; for (y = 0; y < size; y++) { @@ -221,8 +220,9 @@ static void Animations_Draw(struct AnimationData* data, TextureLoc texLoc, Int32 Bitmap_CopyBlock(x, data->FrameY, 0, 0, &anims_bmp, &animPart, size); } + GfxResourceID tex = Atlas1D_TexIds[index_1D]; Int32 dstY = rowId_1D * Atlas2D_TileSize; - Gfx_UpdateTexturePart(Atlas1D_TexIds[index_1D], 0, dstY, &animPart, Gfx_Mipmaps); + if (tex) { Gfx_UpdateTexturePart(tex, 0, dstY, &animPart, Gfx_Mipmaps); } if (size > ANIMS_FAST_SIZE) Mem_Free(&ptr); } diff --git a/src/Client/ExtMath.c b/src/Client/ExtMath.c index 37a98fe6c..6542289b8 100644 --- a/src/Client/ExtMath.c +++ b/src/Client/ExtMath.c @@ -28,10 +28,10 @@ Int32 Math_Ceil(Real32 value) { return valueI < value ? valueI + 1 : valueI; } -Int32 Math_Log2(Int32 value) { - Int32 shift = 0; - while (value > 1) { shift++; value >>= 1; } - return shift; +Int32 Math_Log2(UInt32 value) { + UInt32 r = 0; + while (value >>= 1) r++; + return r; } Int32 Math_CeilDiv(Int32 a, Int32 b) { diff --git a/src/Client/ExtMath.h b/src/Client/ExtMath.h index 67649afed..258a43a7b 100644 --- a/src/Client/ExtMath.h +++ b/src/Client/ExtMath.h @@ -31,7 +31,7 @@ Real64 Math_FastTan(Real64 x); Int32 Math_Floor(Real32 value); Int32 Math_Ceil(Real32 value); -Int32 Math_Log2(Int32 value); +Int32 Math_Log2(UInt32 value); Int32 Math_CeilDiv(Int32 a, Int32 b); Int32 Math_Sign(Real32 value); diff --git a/src/Client/Particle.c b/src/Client/Particle.c index 1ab60e391..f67293642 100644 --- a/src/Client/Particle.c +++ b/src/Client/Particle.c @@ -227,8 +227,8 @@ static void TerrainParticle_Render(struct TerrainParticle* p, Real32 t, VertexP3 static void Terrain_Update1DCounts(void) { Int32 i; - for (i = 0; i < Atlas1D_Count; i++) { - Terrain_1DCount[i] = 0; + for (i = 0; i < ATLAS1D_MAX_ATLASES; i++) { + Terrain_1DCount[i] = 0; Terrain_1DIndices[i] = 0; } for (i = 0; i < Terrain_Count; i++) { diff --git a/src/Client/Program.c b/src/Client/Program.c index 1fb4892bb..e4f61e564 100644 --- a/src/Client/Program.c +++ b/src/Client/Program.c @@ -92,7 +92,7 @@ int main(void) { String title = String_FromConst(PROGRAM_APP_NAME); String rawArgs = Platform_GetCommandLineArgs(); /* NOTE: Make sure to comment this out before pushing a commit */ - //rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25565"); + rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25565"); String args[5]; Int32 argsCount = Array_Elems(args); String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount); diff --git a/src/Client/TerrainAtlas.c b/src/Client/TerrainAtlas.c index 61e06357a..8d129b4ab 100644 --- a/src/Client/TerrainAtlas.c +++ b/src/Client/TerrainAtlas.c @@ -97,6 +97,9 @@ void Atlas1D_UpdateState(void) { Int32 atlasHeight = Atlas1D_TilesPerAtlas * Atlas2D_TileSize; Atlas1D_InvTileSize = 1.0f / Atlas1D_TilesPerAtlas; + Atlas1D_Mask = Atlas1D_TilesPerAtlas - 1; + Atlas1D_Shift = Math_Log2(Atlas1D_TilesPerAtlas); + Atlas1D_Convert2DTo1D(atlasesCount, atlasHeight); } diff --git a/src/Client/TerrainAtlas.h b/src/Client/TerrainAtlas.h index c10e4212c..8c165a35c 100644 --- a/src/Client/TerrainAtlas.h +++ b/src/Client/TerrainAtlas.h @@ -12,20 +12,22 @@ struct Bitmap Atlas2D_Bitmap; Int32 Atlas2D_TileSize, Atlas2D_RowsCount; +Int32 Atlas1D_Count, Atlas1D_TilesPerAtlas; +Int32 Atlas1D_Mask, Atlas1D_Shift; +Real32 Atlas1D_InvTileSize; +GfxResourceID Atlas1D_TexIds[ATLAS1D_MAX_ATLASES]; + +#define Atlas2D_TileX(texLoc) ((texLoc) % ATLAS2D_TILES_PER_ROW) +#define Atlas2D_TileY(texLoc) ((texLoc) / ATLAS2D_TILES_PER_ROW) +/* Returns the index of the given tile id within a 1D atlas */ +#define Atlas1D_RowId(texLoc) ((texLoc) & Atlas1D_Mask) /* texLoc % Atlas1D_TilesPerAtlas */ +/* Returns the index of the 1D atlas within the array of 1D atlases that contains the given tile id */ +#define Atlas1D_Index(texLoc) ((texLoc) >> Atlas1D_Shift) /* texLoc / Atlas1D_TilesPerAtlas */ + void Atlas2D_UpdateState(struct Bitmap* bmp); GfxResourceID Atlas2D_LoadTile(TextureLoc texLoc); void Atlas2D_Free(void); -#define Atlas2D_TileX(texLoc) ((texLoc) % ATLAS2D_TILES_PER_ROW) -#define Atlas2D_TileY(texLoc) ((texLoc) / ATLAS2D_TILES_PER_ROW) - -Int32 Atlas1D_Count, Atlas1D_TilesPerAtlas; -Real32 Atlas1D_InvTileSize; -GfxResourceID Atlas1D_TexIds[ATLAS1D_MAX_ATLASES]; struct TextureRec Atlas1D_TexRec(TextureLoc texLoc, Int32 uCount, Int32* index); -/* Returns the index of the given texture id within a 1D atlas. */ -#define Atlas1D_RowId(texLoc) ((texLoc) % Atlas1D_TilesPerAtlas) -/* Returns the index of the 1D atlas within the array of 1D atlases that contains the given texture id.*/ -#define Atlas1D_Index(texLoc) ((texLoc) / Atlas1D_TilesPerAtlas) void Atlas1D_UpdateState(void); Int32 Atlas1D_UsedAtlasesCount(void); void Atlas1D_Free(void); diff --git a/src/Client/Vorbis.c b/src/Client/Vorbis.c index 676702627..664cb0ade 100644 --- a/src/Client/Vorbis.c +++ b/src/Client/Vorbis.c @@ -828,14 +828,8 @@ static UInt32 Vorbis_ReverseBits(UInt32 v) { return v; } -static UInt32 Vorbis_Log2(UInt32 v) { - UInt32 r = 0; - while (v >>= 1) r++; - return r; -} - void imdct_init(struct imdct_state* state, Int32 n) { - Int32 k, k2, n4 = n >> 2, n8 = n >> 3, log2_n = Vorbis_Log2(n); + Int32 k, k2, n4 = n >> 2, n8 = n >> 3, log2_n = Math_Log2(n); Real32 *A = state->A, *B = state->B, *C = state->C; state->n = n; state->log2_n = log2_n;