From 76d93b1718b6e4aee13b562f4f38c61759a0e905 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 2 Jun 2018 13:30:04 +1000 Subject: [PATCH] fix animations for inf tex --- ClassicalSharp/Particles/Particle.cs | 2 +- ClassicalSharp/TexturePack/Animations.cs | 43 ++++++++++++----------- src/Client/Animations.c | 44 +++++++++++++----------- src/Client/Typedefs.h | 2 +- 4 files changed, 48 insertions(+), 43 deletions(-) diff --git a/ClassicalSharp/Particles/Particle.cs b/ClassicalSharp/Particles/Particle.cs index 7e1afcace..a0dede89a 100644 --- a/ClassicalSharp/Particles/Particle.cs +++ b/ClassicalSharp/Particles/Particle.cs @@ -9,7 +9,7 @@ using TexLoc = System.UInt16; namespace ClassicalSharp.Particles { - public abstract class Particle { + public abstract class Particle { public Vector3 Velocity; public float Lifetime; public byte Size; diff --git a/ClassicalSharp/TexturePack/Animations.cs b/ClassicalSharp/TexturePack/Animations.cs index 070bba58b..480c8a893 100644 --- a/ClassicalSharp/TexturePack/Animations.cs +++ b/ClassicalSharp/TexturePack/Animations.cs @@ -92,7 +92,7 @@ namespace ClassicalSharp.Textures { byte tileX, tileY; if (!Byte.TryParse(parts[0], out tileX) || !Byte.TryParse(parts[1], out tileY) - || tileX >= 16 || tileY >= 16) { + || tileX >= Atlas2D.TilesPerRow || tileY >= Atlas2D.MaxRowsCount) { game.Chat.Add("&cInvalid animation tile coords: " + line); continue; } @@ -116,7 +116,7 @@ namespace ClassicalSharp.Textures { /// that are applied to the terrain atlas. void DefineAnimation(int tileX, int tileY, int frameX, int frameY, int frameSize, int statesNum, int tickDelay) { AnimationData data = new AnimationData(); - data.TileX = tileX; data.TileY = tileY; + data.TexLoc = tileY * Atlas2D.TilesPerRow + tileX; data.FrameX = frameX; data.FrameY = frameY; data.FrameSize = frameSize; data.StatesCount = statesNum; @@ -134,34 +134,34 @@ namespace ClassicalSharp.Textures { data.State %= data.StatesCount; data.Tick = data.TickDelay; - int texId = (data.TileY << 4) | data.TileX; - if (texId == 30 && useLavaAnim) return; - if (texId == 14 && useWaterAnim) return; - DrawAnimation(data, texId, data.FrameSize); + int texLoc = data.TexLoc; + if (texLoc == 30 && useLavaAnim) return; + if (texLoc == 14 && useWaterAnim) return; + DrawAnimation(data, texLoc, data.FrameSize); } - unsafe void DrawAnimation(AnimationData data, int texId, int size) { + unsafe void DrawAnimation(AnimationData data, int texLoc, int size) { if (size <= 128) { byte* temp = stackalloc byte[size * size * 4]; - DrawAnimationCore(data, texId, size, temp); + DrawAnimationCore(data, texLoc, size, temp); } else { // cannot allocate memory on the stack for very big animation.png frames byte[] temp = new byte[size * size * 4]; fixed (byte* ptr = temp) { - DrawAnimationCore(data, texId, size, ptr); + DrawAnimationCore(data, texLoc, size, ptr); } } } - unsafe void DrawAnimationCore(AnimationData data, int texId, int size, byte* temp) { - int index = Atlas1D.Get1DIndex(texId); - int rowNum = Atlas1D.Get1DRowId(texId); + unsafe void DrawAnimationCore(AnimationData data, int texLoc, int size, byte* temp) { + int index_1D = Atlas1D.Get1DIndex(texLoc); + int rowId_1D = Atlas1D.Get1DRowId(texLoc); animPart.SetData(size, size, size * 4, (IntPtr)temp, false); if (data == null) { - if (texId == 30) { + if (texLoc == 30) { lavaAnim.Tick((int*)temp, size); - } else if (texId == 14) { + } else if (texLoc == 14) { waterAnim.Tick((int*)temp, size); } } else { @@ -169,8 +169,8 @@ namespace ClassicalSharp.Textures { data.FrameY, 0, 0, animsBuffer, animPart, size); } - int y = rowNum * Atlas2D.TileSize; - game.Graphics.UpdateTexturePart(Atlas1D.TexIds[index], 0, y, animPart, game.Graphics.Mipmaps); + int dstY = rowId_1D * Atlas2D.TileSize; + game.Graphics.UpdateTexturePart(Atlas1D.TexIds[index_1D], 0, dstY, animPart, game.Graphics.Mipmaps); } bool IsDefaultZip() { @@ -197,7 +197,7 @@ namespace ClassicalSharp.Textures { } class AnimationData { - public int TileX, TileY; // Tile (not pixel) coordinates in terrain.png + public int TexLoc; // Tile (not pixel) coordinates in terrain.png public int FrameX, FrameY; // Top left pixel coordinates of start frame in animatons.png public int FrameSize; // Size of each frame in pixel coordinates public int State; // Current animation frame index @@ -209,11 +209,12 @@ namespace ClassicalSharp.Textures { const string terrainFormat = "&cAnimation frames for tile ({0}, {1}) are bigger than the size of a tile in terrain.png"; void ValidateAnimations() { validated = true; - int elemSize = Atlas2D.TileSize; for (int i = animations.Count - 1; i >= 0; i--) { AnimationData a = animations[i]; - if (a.FrameSize > elemSize) { - game.Chat.Add(String.Format(terrainFormat, a.TileX, a.TileY)); + int tileX = a.TexLoc % Atlas2D.TilesPerRow, tileY = a.TexLoc / Atlas2D.TilesPerRow; + + if (a.FrameSize > Atlas2D.TileSize || tileY >= Atlas2D.RowsCount) { + game.Chat.Add(String.Format(terrainFormat, tileX, tileY)); animations.RemoveAt(i); continue; } @@ -222,7 +223,7 @@ namespace ClassicalSharp.Textures { int maxX = a.FrameX + a.FrameSize * a.StatesCount; if (maxX <= animsBuffer.Width && maxY <= animsBuffer.Height) continue; - game.Chat.Add(String.Format(format, a.TileX, a.TileY)); + game.Chat.Add(String.Format(format, tileX, tileY)); animations.RemoveAt(i); } } diff --git a/src/Client/Animations.c b/src/Client/Animations.c index c7f318ebb..713b844e0 100644 --- a/src/Client/Animations.c +++ b/src/Client/Animations.c @@ -126,11 +126,11 @@ static void WaterAnimation_Tick(UInt32* ptr, Int32 size) { typedef struct AnimationData_ { - TextureLoc TileX, TileY; /* Tile (not pixel) coordinates in terrain.png */ - UInt16 FrameX, FrameY; /* Top left pixel coordinates of start frame in animatons.png */ - UInt16 FrameSize; /* Size of each frame in pixel coordinates */ - UInt16 State; /* Current animation frame index */ - UInt16 StatesCount; /* Total number of animation frames */ + TextureLoc TexLoc; /* Tile (not pixel) coordinates in terrain.png */ + UInt16 FrameX, FrameY; /* Top left pixel coordinates of start frame in animatons.png */ + UInt16 FrameSize; /* Size of each frame in pixel coordinates */ + UInt16 State; /* Current animation frame index */ + UInt16 StatesCount; /* Total number of animation frames */ Int16 Tick, TickDelay; } AnimationData; @@ -158,16 +158,18 @@ static void Animations_ReadDescription(Stream* stream) { while (Stream_ReadLine(&buffered, &line)) { if (line.length == 0 || line.buffer[0] == '#') continue; AnimationData data = { 0 }; + UInt8 tileX, tileY; + UInt32 partsCount = Array_Elems(parts); String_UNSAFE_Split(&line, ' ', parts, &partsCount); if (partsCount < 7) { Animations_LogFail(&line, "Not enough arguments for anim"); continue; } - if (!Convert_TryParseUInt8(&parts[0], &data.TileX) || data.TileX >= 16) { + if (!Convert_TryParseUInt8(&parts[0], &tileX) || tileX >= ATLAS2D_TILES_PER_ROW) { Animations_LogFail(&line, "Invalid anim tile X coord"); continue; } - if (!Convert_TryParseUInt8(&parts[1], &data.TileY) || data.TileY >= 16) { + if (!Convert_TryParseUInt8(&parts[1], &tileY) || tileY >= ATLAS2D_ROWS_COUNT) { Animations_LogFail(&line, "Invalid anim tile Y coord"); continue; } if (!Convert_TryParseUInt16(&parts[2], &data.FrameX)) { @@ -189,13 +191,14 @@ static void Animations_ReadDescription(Stream* stream) { if (anims_count == Array_Elems(anims_list)) { ErrorHandler_Fail("Too many animations in animations.txt"); } + data.TexLoc = tileX + (tileY * ATLAS2D_TILES_PER_ROW); anims_list[anims_count++] = data; } } /* TODO: should we use 128 size here? */ #define ANIMS_FAST_SIZE 64 -static void Animations_Draw(AnimationData* data, Int32 texId, Int32 size) { +static void Animations_Draw(AnimationData* data, TextureLoc texLoc, Int32 size) { UInt8 buffer[Bitmap_DataSize(ANIMS_FAST_SIZE, ANIMS_FAST_SIZE)]; UInt8* ptr = buffer; if (size > ANIMS_FAST_SIZE) { @@ -204,14 +207,14 @@ static void Animations_Draw(AnimationData* data, Int32 texId, Int32 size) { if (ptr == NULL) ErrorHandler_Fail("Failed to allocate memory for anim frame"); } - Int32 index = Atlas1D_Index(texId); - Int32 rowNum = Atlas1D_RowId(texId); + Int32 index_1D = Atlas1D_Index(texLoc); + Int32 rowId_1D = Atlas1D_RowId(texLoc); Bitmap animPart; Bitmap_Create(&animPart, size, size, buffer); if (data == NULL) { - if (texId == 30) { + if (texLoc == 30) { LavaAnimation_Tick((UInt32*)animPart.Scan0, size); - } else if (texId == 14) { + } else if (texLoc == 14) { WaterAnimation_Tick((UInt32*)animPart.Scan0, size); } } else { @@ -219,8 +222,8 @@ static void Animations_Draw(AnimationData* data, Int32 texId, Int32 size) { Bitmap_CopyBlock(x, data->FrameY, 0, 0, &anims_bmp, &animPart, size); } - Int32 y = rowNum * Atlas2D_TileSize; - Gfx_UpdateTexturePart(Atlas1D_TexIds[index], 0, y, &animPart, Gfx_Mipmaps); + Int32 dstY = rowId_1D * Atlas2D_TileSize; + Gfx_UpdateTexturePart(Atlas1D_TexIds[index_1D], 0, dstY, &animPart, Gfx_Mipmaps); if (size > ANIMS_FAST_SIZE) Platform_MemFree(&ptr); } @@ -231,10 +234,10 @@ static void Animations_Apply(AnimationData* data) { data->State %= data->StatesCount; data->Tick = data->TickDelay; - Int32 texId = (data->TileY << 4) | data->TileX; - if (texId == 30 && anims_useLavaAnim) return; - if (texId == 14 && anims_useWaterAnim) return; - Animations_Draw(data, texId, data->FrameSize); + TextureLoc texLoc = data->TexLoc; + if (texLoc == 30 && anims_useLavaAnim) return; + if (texLoc == 14 && anims_useWaterAnim) return; + Animations_Draw(data, texLoc, data->FrameSize); } static bool Animations_IsDefaultZip(void) { @@ -264,10 +267,11 @@ static void Animations_Validate(void) { Int32 maxX = data.FrameX + data.FrameSize * data.StatesCount; String_Clear(&msg); + Int32 tileX = data.TexLoc % ATLAS2D_TILES_PER_ROW, tileY = data.TexLoc / ATLAS2D_TILES_PER_ROW; if (data.FrameSize > Atlas2D_TileSize) { - String_Format2(&msg, "&cAnimation frames for tile (%b, %b) are bigger than the size of a tile in terrain.png", &data.TileX, &data.TileY); + String_Format2(&msg, "&cAnimation frames for tile (%i, %i) are bigger than the size of a tile in terrain.png", &tileX, &tileY); } else if (maxX > anims_bmp.Width || maxY > anims_bmp.Height) { - String_Format2(&msg, "&cSome of the animation frames for tile (%b, %b) are at coordinates outside animations.png", &data.TileX, &data.TileY); + String_Format2(&msg, "&cSome of the animation frames for tile (%i, %i) are at coordinates outside animations.png", &tileX, &tileY); } else { continue; } diff --git a/src/Client/Typedefs.h b/src/Client/Typedefs.h index 3548503ef..fc6a462c9 100644 --- a/src/Client/Typedefs.h +++ b/src/Client/Typedefs.h @@ -57,7 +57,7 @@ typedef struct FontDesc_ { void* Handle; UInt16 Size, Style; } FontDesc; #define Int32_MaxValue ((Int32)2147483647L) #define UInt32_MaxValue ((UInt32)4294967295UL) -#define CC_BUILD_GL11 true +#define CC_BUILD_GL11 false #define CC_BUILD_D3D9 false #if CC_BUILD_D3D9