From 129857ec9d4ba88e17c79fe50ddaf8d9718025c0 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 18 Aug 2018 22:20:47 +1000 Subject: [PATCH] inf tex for C client --- .../2D/Screens/Overlays/TexIdsOverlay.cs | 10 ++--- src/Client/Animations.c | 12 +++++- src/Client/Block.c | 6 +-- src/Client/Entity.c | 2 +- src/Client/Entity.h | 10 ++--- src/Client/Menus.c | 42 ++++++++++++------- src/Client/PacketHandlers.c | 41 +++++++++++++----- src/Client/TerrainAtlas.h | 2 +- src/Client/Typedefs.h | 2 +- 9 files changed, 81 insertions(+), 46 deletions(-) diff --git a/ClassicalSharp/2D/Screens/Overlays/TexIdsOverlay.cs b/ClassicalSharp/2D/Screens/Overlays/TexIdsOverlay.cs index 22584fe42..fbb19f644 100644 --- a/ClassicalSharp/2D/Screens/Overlays/TexIdsOverlay.cs +++ b/ClassicalSharp/2D/Screens/Overlays/TexIdsOverlay.cs @@ -70,18 +70,16 @@ namespace ClassicalSharp.Gui.Screens { void RenderTerrain() { for (int i = 0; i < Atlas2D.TilesPerRow * Atlas2D.TilesPerRow;) { - int index = 0, texIdx = 0; + int index = 0, texIdx = 0, end = i + Atlas1D.TilesPerAtlas; - for (int j = 0; j < Atlas1D.TilesPerAtlas; j++) { - TextureRec rec = Atlas1D.GetTexRec((i + j) + baseTexLoc, 1, out texIdx); - int x = (i + j) % Atlas2D.TilesPerRow; - int y = (i + j) / Atlas2D.TilesPerRow; + for (; i < end; i++) { + TextureRec rec = Atlas1D.GetTexRec(i + baseTexLoc, 1, out texIdx); + int x = i % Atlas2D.TilesPerRow, y = i / Atlas2D.TilesPerRow; Texture tex = new Texture(0, xOffset + x * tileSize, yOffset + y * tileSize, tileSize, tileSize, rec); IGraphicsApi.Make2DQuad(ref tex, PackedCol.White, vertices, ref index); } - i += Atlas1D.TilesPerAtlas; game.Graphics.BindTexture(Atlas1D.TexIds[texIdx]); game.Graphics.UpdateDynamicVb_IndexedTris(dynamicVb, vertices, index); diff --git a/src/Client/Animations.c b/src/Client/Animations.c index d6bc23464..ca9554f1f 100644 --- a/src/Client/Animations.c +++ b/src/Client/Animations.c @@ -12,6 +12,9 @@ #include "Errors.h" #define LIQUID_ANIM_MAX 64 +/*########################################################################################################################* +*-----------------------------------------------------Lava animation------------------------------------------------------* +*#########################################################################################################################*/ Real32 L_soupHeat[LIQUID_ANIM_MAX * LIQUID_ANIM_MAX]; Real32 L_potHeat[LIQUID_ANIM_MAX * LIQUID_ANIM_MAX]; Real32 L_flameHeat[LIQUID_ANIM_MAX * LIQUID_ANIM_MAX]; @@ -77,6 +80,9 @@ static void LavaAnimation_Tick(UInt32* ptr, Int32 size) { } +/*########################################################################################################################* +*----------------------------------------------------Water animation------------------------------------------------------* +*#########################################################################################################################*/ Real32 W_soupHeat[LIQUID_ANIM_MAX * LIQUID_ANIM_MAX]; Real32 W_potHeat[LIQUID_ANIM_MAX * LIQUID_ANIM_MAX]; Real32 W_flameHeat[LIQUID_ANIM_MAX * LIQUID_ANIM_MAX]; @@ -88,8 +94,7 @@ static void WaterAnimation_Tick(UInt32* ptr, Int32 size) { Random_InitFromCurrentTime(&W_rnd); W_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++) { @@ -124,6 +129,9 @@ static void WaterAnimation_Tick(UInt32* ptr, Int32 size) { } +/*########################################################################################################################* +*-------------------------------------------------------Animations--------------------------------------------------------* +*#########################################################################################################################*/ struct AnimationData { TextureLoc TexLoc; /* Tile (not pixel) coordinates in terrain.png */ UInt16 FrameX, FrameY; /* Top left pixel coordinates of start frame in animatons.png */ diff --git a/src/Client/Block.c b/src/Client/Block.c index 08851382a..8eb201a5c 100644 --- a/src/Client/Block.c +++ b/src/Client/Block.c @@ -16,17 +16,17 @@ UInt32 Block_DefinedCustomBlocks[BLOCK_COUNT >> 5]; UChar Block_NamesBuffer[String_BufferSize(STRING_SIZE) * BLOCK_COUNT]; #define Block_NamePtr(i) &Block_NamesBuffer[String_BufferSize(STRING_SIZE) * i] -TextureLoc Block_TopTex[BLOCK_CPE_COUNT] = { 0, 1, 0, 2, 16, 4, 15, 17, 14, 14, +UInt8 Block_TopTex[BLOCK_CPE_COUNT] = { 0, 1, 0, 2, 16, 4, 15, 17, 14, 14, 30, 30, 18, 19, 32, 33, 34, 21, 22, 48, 49, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 13, 12, 29, 28, 24, 23, 6, 6, 7, 9, 4, 36, 37, 16, 11, 25, 50, 38, 80, 81, 82, 83, 84, 51, 54, 86, 26, 53, 52, }; -TextureLoc Block_SideTex[BLOCK_CPE_COUNT] = { 0, 1, 3, 2, 16, 4, 15, 17, 14, 14, +UInt8 Block_SideTex[BLOCK_CPE_COUNT] = { 0, 1, 3, 2, 16, 4, 15, 17, 14, 14, 30, 30, 18, 19, 32, 33, 34, 20, 22, 48, 49, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 13, 12, 29, 28, 40, 39, 5, 5, 7, 8, 35, 36, 37, 16, 11, 41, 50, 38, 80, 81, 82, 83, 84, 51, 54, 86, 42, 53, 52, }; -TextureLoc Block_BottomTex[BLOCK_CPE_COUNT] = { 0, 1, 2, 2, 16, 4, 15, 17, 14, 14, +UInt8 Block_BottomTex[BLOCK_CPE_COUNT] = { 0, 1, 2, 2, 16, 4, 15, 17, 14, 14, 30, 30, 18, 19, 32, 33, 34, 21, 22, 48, 49, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 13, 12, 29, 28, 56, 55, 6, 6, 7, 10, 4, 36, 37, 16, 11, 57, 50, 38, 80, 81, 82, 83, 84, 51, 54, 86, 58, 53, 52 }; diff --git a/src/Client/Entity.c b/src/Client/Entity.c index ae07fa74e..811141b8e 100644 --- a/src/Client/Entity.c +++ b/src/Client/Entity.c @@ -401,7 +401,7 @@ void Entities_DrawShadows(void) { *--------------------------------------------------------TabList----------------------------------------------------------* *#########################################################################################################################*/ bool TabList_Valid(EntityID id) { - return TabList_PlayerNames[id] > 0 || TabList_ListNames[id] > 0 || TabList_GroupNames[id] > 0; + return TabList_PlayerNames[id] || TabList_ListNames[id] || TabList_GroupNames[id]; } void TabList_RemoveAt(UInt32 index) { diff --git a/src/Client/Entity.h b/src/Client/Entity.h index a51e5bdcc..36f2d0c83 100644 --- a/src/Client/Entity.h +++ b/src/Client/Entity.h @@ -113,13 +113,13 @@ void Entities_DrawShadows(void); #define TABLIST_MAX_NAMES 256 StringsBuffer TabList_Buffer; -UInt32 TabList_PlayerNames[TABLIST_MAX_NAMES]; -UInt32 TabList_ListNames[TABLIST_MAX_NAMES]; -UInt32 TabList_GroupNames[TABLIST_MAX_NAMES]; -UInt8 TabList_GroupRanks[TABLIST_MAX_NAMES]; +UInt16 TabList_PlayerNames[TABLIST_MAX_NAMES]; +UInt16 TabList_ListNames[TABLIST_MAX_NAMES]; +UInt16 TabList_GroupNames[TABLIST_MAX_NAMES]; +UInt8 TabList_GroupRanks[TABLIST_MAX_NAMES]; bool TabList_Valid(EntityID id); bool TabList_Remove(EntityID id); -void TabList_Set(EntityID id, STRING_PURE String* player, STRING_PURE String* list, STRING_PURE String* group, UInt8 rank); +void TabList_Set(EntityID id, STRING_PURE String* player, STRING_PURE String* list, STRING_PURE String* group, UInt8 rank); void TabList_MakeComponent(struct IGameComponent* comp); #define TabList_UNSAFE_GetPlayer(id) StringsBuffer_UNSAFE_Get(&TabList_Buffer, TabList_PlayerNames[id]); diff --git a/src/Client/Menus.c b/src/Client/Menus.c index 00999d27e..9b3ef82b6 100644 --- a/src/Client/Menus.c +++ b/src/Client/Menus.c @@ -126,7 +126,7 @@ struct TexIdsOverlay { MenuScreen_Layout struct ButtonWidget* Buttons; GfxResourceID DynamicVb; - Int32 XOffset, YOffset, TileSize; + Int32 XOffset, YOffset, TileSize, BaseTexLoc; struct TextAtlas IdAtlas; struct TextWidget Title; }; @@ -3017,7 +3017,7 @@ static void Overlay_UseVTABLE(struct MenuScreen* screen, struct GuiElementVTABLE /*########################################################################################################################* *------------------------------------------------------TexIdsOverlay------------------------------------------------------* *#########################################################################################################################*/ -#define TEXID_OVERLAY_VERTICES_COUNT (ATLAS2D_TILES_PER_ROW * ATLAS2D_MAX_ROWS_COUNT * 4) +#define TEXID_OVERLAY_VERTICES_COUNT (ATLAS2D_TILES_PER_ROW * ATLAS2D_TILES_PER_ROW * 4) struct GuiElementVTABLE TexIdsOverlay_VTABLE; struct TexIdsOverlay TexIdsOverlay_Instance; static void TexIdsOverlay_ContextLost(void* obj) { @@ -3039,7 +3039,7 @@ static void TexIdsOverlay_ContextRecreated(void* obj) { size = (size / 8) * 8; Math_Clamp(size, 8, 40); - screen->XOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_MAX_ROWS_COUNT, Game_Width); + screen->XOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * Atlas2D_RowsCount, Game_Width); screen->YOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_TILES_PER_ROW, Game_Height); screen->TileSize = size; @@ -3050,15 +3050,14 @@ static void TexIdsOverlay_ContextRecreated(void* obj) { static void TexIdsOverlay_RenderTerrain(struct TexIdsOverlay* screen) { VertexP3fT2fC4b vertices[TEXID_OVERLAY_VERTICES_COUNT]; - Int32 elemsPerAtlas = Atlas1D_TilesPerAtlas, i; - for (i = 0; i < ATLAS2D_TILES_PER_ROW * ATLAS2D_MAX_ROWS_COUNT;) { + Int32 i, texIdx; + for (i = 0; i < ATLAS2D_TILES_PER_ROW * ATLAS2D_TILES_PER_ROW;) { VertexP3fT2fC4b* ptr = vertices; - Int32 j, ignored, size = screen->TileSize; + Int32 size = screen->TileSize, end = i + Atlas1D_TilesPerAtlas; - for (j = 0; j < elemsPerAtlas; j++) { - struct TextureRec rec = Atlas1D_TexRec(i + j, 1, &ignored); - Int32 x = (i + j) % ATLAS2D_TILES_PER_ROW; - Int32 y = (i + j) / ATLAS2D_TILES_PER_ROW; + for (; i < end; i++) { + struct TextureRec rec = Atlas1D_TexRec(i + screen->BaseTexLoc, 1, &texIdx); + Int32 x = Atlas2D_TileX(i), y = Atlas2D_TileY(i); struct Texture tex; Texture_FromRec(&tex, NULL, screen->XOffset + x * size, @@ -3068,8 +3067,7 @@ static void TexIdsOverlay_RenderTerrain(struct TexIdsOverlay* screen) { GfxCommon_Make2DQuad(&tex, col, &ptr); } - Gfx_BindTexture(Atlas1D_TexIds[i / elemsPerAtlas]); - i += elemsPerAtlas; + Gfx_BindTexture(Atlas1D_TexIds[texIdx]); Int32 count = (Int32)(ptr - vertices); GfxCommon_UpdateDynamicVb_IndexedTris(screen->DynamicVb, vertices, count); } @@ -3082,11 +3080,12 @@ static void TexIdsOverlay_RenderTextOverlay(struct TexIdsOverlay* screen) { struct TextAtlas* idAtlas = &screen->IdAtlas; idAtlas->Tex.Y = (screen->YOffset + (size - idAtlas->Tex.Height)); - for (y = 0; y < ATLAS2D_MAX_ROWS_COUNT; y++) { + + for (y = 0; y < ATLAS2D_TILES_PER_ROW; y++) { for (x = 0; x < ATLAS2D_TILES_PER_ROW; x++) { idAtlas->CurX = screen->XOffset + size * x + 3; /* offset text by 3 pixels */ Int32 id = x + y * ATLAS2D_TILES_PER_ROW; - TextAtlas_AddInt(idAtlas, id, &ptr); + TextAtlas_AddInt(idAtlas, id + screen->BaseTexLoc, &ptr); } idAtlas->Tex.Y += size; @@ -3110,8 +3109,19 @@ static void TexIdsOverlay_Render(struct GuiElem* elem, Real64 delta) { Gfx_SetTexturing(true); Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B); Menu_Render((struct MenuBase*)elem, delta); - TexIdsOverlay_RenderTerrain(screen); - TexIdsOverlay_RenderTextOverlay(screen); + + Int32 rows = Atlas2D_RowsCount, origXOffset = screen->XOffset; + screen->BaseTexLoc = 0; + while (rows > 0) { + TexIdsOverlay_RenderTerrain(screen); + TexIdsOverlay_RenderTextOverlay(screen); + rows -= ATLAS2D_TILES_PER_ROW; + + screen->XOffset += screen->TileSize * ATLAS2D_TILES_PER_ROW; + screen->BaseTexLoc += ATLAS2D_TILES_PER_ROW * ATLAS2D_TILES_PER_ROW; + } + + screen->XOffset = origXOffset; Gfx_SetTexturing(false); } diff --git a/src/Client/PacketHandlers.c b/src/Client/PacketHandlers.c index e33082f58..70a11f305 100644 --- a/src/Client/PacketHandlers.c +++ b/src/Client/PacketHandlers.c @@ -23,6 +23,7 @@ #include "TexturePack.h" #include "Gui.h" #include "Errors.h" +#include "TerrainAtlas.h" /*########################################################################################################################* *-----------------------------------------------------Common handlers-----------------------------------------------------* @@ -662,14 +663,15 @@ static void Classic_Tick(void) { Int32 cpe_serverExtensionsCount, cpe_pingTicks; Int32 cpe_envMapVer = 2, cpe_blockDefsExtVer = 2; -bool cpe_twoWayPing; +bool cpe_twoWayPing, cpe_extTextures; -const UChar* cpe_clientExtensions[28] = { +const UChar* cpe_clientExtensions[29] = { "ClickDistance", "CustomBlocks", "HeldBlock", "EmoteFix", "TextHotKey", "ExtPlayerList", "EnvColors", "SelectionCuboid", "BlockPermissions", "ChangeModel", "EnvMapAppearance", "EnvWeatherType", "MessageTypes", "HackControl", "PlayerClick", "FullCP437", "LongerMessages", "BlockDefinitions", "BlockDefinitionsExt", "BulkBlockUpdate", "TextColors", "EnvMapAspect", "EntityProperty", "ExtEntityPositions", "TwoWayPing", "InventoryOrder", "InstantMOTD", "FastMap", + "ExtendedTextures", }; static void CPE_SetMapEnvUrl(UInt8* data); @@ -818,7 +820,7 @@ static void CPE_ExtEntry(UInt8* data) { Net_PacketSizes[OPCODE_DEFINE_BLOCK_EXT] += 3; } else if (String_CaselessEqualsConst(&ext, "ExtEntityPositions")) { Net_PacketSizes[OPCODE_ENTITY_TELEPORT] += 6; - Net_PacketSizes[OPCODE_ADD_ENTITY] += 6; + Net_PacketSizes[OPCODE_ADD_ENTITY] += 6; Net_PacketSizes[OPCODE_EXT_ADD_ENTITY2] += 6; cpe_extEntityPos = true; } else if (String_CaselessEqualsConst(&ext, "TwoWayPing")) { @@ -826,6 +828,10 @@ static void CPE_ExtEntry(UInt8* data) { } else if (String_CaselessEqualsConst(&ext, "FastMap")) { Net_PacketSizes[OPCODE_LEVEL_BEGIN] += 4; cpe_fastMap = true; + } else if (String_CaselessEqualsConst(&ext, "ExtendedTextures")) { + Net_PacketSizes[OPCODE_DEFINE_BLOCK] += 3; + Net_PacketSizes[OPCODE_DEFINE_BLOCK_EXT] += 6; + cpe_extTextures = true; } } @@ -1169,7 +1175,8 @@ static void CPE_Reset(void) { cpe_serverExtensionsCount = 0; cpe_pingTicks = 0; cpe_sendHeldBlock = false; cpe_useMessageTypes = false; cpe_envMapVer = 2; cpe_blockDefsExtVer = 2; - cpe_needD3Fix = false; cpe_extEntityPos = false; cpe_twoWayPing = false; cpe_fastMap = false; + cpe_needD3Fix = false; cpe_extEntityPos = false; cpe_twoWayPing = false; + cpe_extTextures = false; cpe_fastMap = false; Game_UseCPEBlocks = false; if (!Game_UseCPE) return; @@ -1221,6 +1228,18 @@ static void BlockDefs_OnBlockUpdated(BlockID block, bool didBlockLight) { if (Block_BlocksLight[block] != didBlockLight) { Lighting_Refresh(); } } +static TextureLoc BlockDefs_Tex(UInt8** ptr) { + TextureLoc loc; UInt8* data = *ptr; + + if (!cpe_extTextures) { + loc = *data++; + } else { + loc = Stream_GetU16_BE(data) % ATLAS1D_MAX_ATLASES; data += 2; + } + + *ptr = data; return loc; +} + static BlockID BlockDefs_DefineBlockCommonStart(UInt8** ptr, bool uniqueSideTexs) { UInt8* data = *ptr; BlockID block = Handlers_ReadBlock(data); @@ -1236,16 +1255,16 @@ static BlockID BlockDefs_DefineBlockCommonStart(UInt8** ptr, bool uniqueSideTexs #define LOG_2 0.693147180559945 Block_SpeedMultiplier[block] = (Real32)Math_Exp(LOG_2 * multiplierExponent); /* pow(2, x) */ - Block_SetTex(*data++, FACE_YMAX, block); + Block_SetTex(BlockDefs_Tex(&data), FACE_YMAX, block); if (uniqueSideTexs) { - Block_SetTex(*data++, FACE_XMIN, block); - Block_SetTex(*data++, FACE_XMAX, block); - Block_SetTex(*data++, FACE_ZMIN, block); - Block_SetTex(*data++, FACE_ZMAX, block); + Block_SetTex(BlockDefs_Tex(&data), FACE_XMIN, block); + Block_SetTex(BlockDefs_Tex(&data), FACE_XMAX, block); + Block_SetTex(BlockDefs_Tex(&data), FACE_ZMIN, block); + Block_SetTex(BlockDefs_Tex(&data), FACE_ZMAX, block); } else { - Block_SetSide(*data++, block); + Block_SetSide(BlockDefs_Tex(&data), block); } - Block_SetTex(*data++, FACE_YMIN, block); + Block_SetTex(BlockDefs_Tex(&data), FACE_YMIN, block); Block_BlocksLight[block] = *data++ == 0; BlockDefs_OnBlockUpdated(block, didBlockLight); diff --git a/src/Client/TerrainAtlas.h b/src/Client/TerrainAtlas.h index 8c165a35c..e8020a952 100644 --- a/src/Client/TerrainAtlas.h +++ b/src/Client/TerrainAtlas.h @@ -7,7 +7,7 @@ */ #define ATLAS2D_TILES_PER_ROW 16 -#define ATLAS2D_MAX_ROWS_COUNT 16 +#define ATLAS2D_MAX_ROWS_COUNT 32 #define ATLAS1D_MAX_ATLASES (ATLAS2D_TILES_PER_ROW * ATLAS2D_MAX_ROWS_COUNT) struct Bitmap Atlas2D_Bitmap; diff --git a/src/Client/Typedefs.h b/src/Client/Typedefs.h index a99a00032..8abecfe4e 100644 --- a/src/Client/Typedefs.h +++ b/src/Client/Typedefs.h @@ -44,7 +44,7 @@ typedef UInt16 BlockID; typedef UInt8 BlockID; #endif typedef UInt8 EntityID; -typedef UInt8 TextureLoc; +typedef UInt16 TextureLoc; typedef UInt8 Face; typedef UInt32 ReturnCode;