From a66e4a7e6af4e5b7abf87fad62f521c100b4c7c1 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 7 May 2018 15:18:16 +1000 Subject: [PATCH] Don't store full model name in C client for entity, reduces size of net players list global by 3 KB --- ClassicalSharp/2D/Screens/ChatScreen.cs | 8 ++++---- src/Client/Entity.c | 10 ++++------ src/Client/Entity.h | 2 +- src/Client/ModelCache.c | 4 +--- src/Client/Screens.c | 8 ++++---- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/ClassicalSharp/2D/Screens/ChatScreen.cs b/ClassicalSharp/2D/Screens/ChatScreen.cs index b87476809..54a9fbfe2 100644 --- a/ClassicalSharp/2D/Screens/ChatScreen.cs +++ b/ClassicalSharp/2D/Screens/ChatScreen.cs @@ -356,10 +356,10 @@ namespace ClassicalSharp.Gui.Screens { input.EnterInput(); altText.SetActive(false); - // Do we need to move all chat down? - int resetIndex = game.Chat.Log.Count - chatLines; - if (chatIndex != resetIndex) { - chatIndex = ClampIndex(resetIndex); + // Reset chat when user has scrolled up in chat history + int defaultIndex = game.Chat.Log.Count - chatLines; + if (chatIndex != defaultIndex) { + chatIndex = ClampIndex(defaultIndex); ResetChat(); } } else if (key == Key.PageUp) { diff --git a/src/Client/Entity.c b/src/Client/Entity.c index 7ae01b8cd..320c8bf83 100644 --- a/src/Client/Entity.c +++ b/src/Client/Entity.c @@ -127,7 +127,6 @@ void Entity_ParseScale(Entity* entity, String scale) { void Entity_SetModel(Entity* entity, STRING_PURE String* model) { entity->ModelScale = Vector3_Create1(1.0f); entity->ModelBlock = BLOCK_AIR; - String entModel = String_InitAndClearArray(entity->ModelNameRaw); Int32 sep = String_IndexOf(model, '|', 0); String name, scale; @@ -141,20 +140,19 @@ void Entity_SetModel(Entity* entity, STRING_PURE String* model) { /* 'giant' model kept for backwards compatibility */ if (String_CaselessEqualsConst(model, "giant")) { - String_AppendConst(&entModel, "humanoid"); + name = String_FromReadonly("humanoid"); entity->ModelScale = Vector3_Create1(2.0f); } else if (Convert_TryParseUInt8(model, &entity->ModelBlock)) { - String_AppendConst(&entModel, "block"); - } else { - String_AppendString(&entModel, &name); + name = String_FromReadonly("block"); } - entity->Model = ModelCache_Get(&entModel); + entity->Model = ModelCache_Get(&name); Entity_ParseScale(entity, scale); entity->MobTextureId = NULL; entity->Model->RecalcProperties(entity); Entity_UpdateModelBounds(entity); + entity->ModelIsSheepNoFur = String_CaselessEqualsConst(&name, "sheep_nofur"); } void Entity_UpdateModelBounds(Entity* entity) { diff --git a/src/Client/Entity.h b/src/Client/Entity.h index e0061140c..bbcb0d593 100644 --- a/src/Client/Entity.h +++ b/src/Client/Entity.h @@ -73,8 +73,8 @@ typedef struct Entity_ { Vector3 Velocity, OldVelocity; IModel* Model; - UInt8 ModelNameRaw[String_BufferSize(ENTITY_MAX_MODEL_LENGTH)]; BlockID ModelBlock; /* BlockID, if model name was originally a vaid block id. */ + bool ModelIsSheepNoFur; /* Hacky, but only sheep model relies on model name. So use just 1 byte. */ AABB ModelAABB; Vector3 ModelScale, Size; Real32 StepSize; diff --git a/src/Client/ModelCache.c b/src/Client/ModelCache.c index 6804a864e..5363bc2d1 100644 --- a/src/Client/ModelCache.c +++ b/src/Client/ModelCache.c @@ -420,9 +420,7 @@ void SheepModel_DrawModel(Entity* entity) { IModel_DrawRotate(entity->Anim.LeftLegX, 0, 0, Sheep_RightLegBack, false); IModel_UpdateVB(); - String entModel = String_FromRawArray(entity->ModelNameRaw); - String sheep_nofur = String_FromConst("sheep_nofur"); - if (String_CaselessEquals(&entModel, &sheep_nofur)) return; + if (entity->ModelIsSheepNoFur) return; Gfx_BindTexture(ModelCache_Textures[fur_Index].TexID); IModel_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, Fur_Head, true); diff --git a/src/Client/Screens.c b/src/Client/Screens.c index d9f1791c6..f5a36cad3 100644 --- a/src/Client/Screens.c +++ b/src/Client/Screens.c @@ -876,10 +876,10 @@ bool ChatScreen_HandlesKeyDown(GuiElement* elem, Key key) { screen->Input.Base.OnPressedEnter(elem); SpecialInputWidget_SetActive(&screen->AltText, false); - /* Do we need to move all chat down? */ - Int32 resetIndex = Chat_Log.Count - Game_ChatLines; - if (screen->ChatIndex != resetIndex) { - screen->ChatIndex = ChatScreen_ClampIndex(resetIndex); + /* Reset chat when user has scrolled up in chat history */ + Int32 defaultIndex = Chat_Log.Count - Game_ChatLines; + if (screen->ChatIndex != defaultIndex) { + screen->ChatIndex = ChatScreen_ClampIndex(defaultIndex); ChatScreen_ResetChat(screen); } } else if (key == Key_PageUp) {