mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
avoid div for getting coords of a tile in 1D atlases
This commit is contained in:
parent
97d8cede02
commit
28dc63f5c9
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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++) {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user