Skip to content

Commit

Permalink
inf tex for C client
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Aug 18, 2018
1 parent 209fd2e commit 129857e
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 46 deletions.
10 changes: 4 additions & 6 deletions ClassicalSharp/2D/Screens/Overlays/TexIdsOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,16 @@ protected override void ContextRecreated() {

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);
Expand Down
12 changes: 10 additions & 2 deletions src/Client/Animations.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand All @@ -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++) {
Expand Down Expand Up @@ -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 */
Expand Down
6 changes: 3 additions & 3 deletions src/Client/Block.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions src/Client/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
42 changes: 26 additions & 16 deletions src/Client/Menus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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) {
Expand All @@ -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;

Expand All @@ -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,
Expand All @@ -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);
}
Expand All @@ -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;

Expand All @@ -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);
}

Expand Down
41 changes: 30 additions & 11 deletions src/Client/PacketHandlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "TexturePack.h"
#include "Gui.h"
#include "Errors.h"
#include "TerrainAtlas.h"

/*########################################################################################################################*
*-----------------------------------------------------Common handlers-----------------------------------------------------*
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -818,14 +820,18 @@ 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")) {
cpe_twoWayPing = true;
} 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;
}
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Client/TerrainAtlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 129857e

Please sign in to comment.