Skip to content
Permalink
Browse files

Avoid creating and destroying as many textures when scrolling through…

… chat
  • Loading branch information...
UnknownShadow200 committed Jun 7, 2019
1 parent c1dd7d8 commit 8b24029dcafe3abb4fd607348188314f98a651d8
Showing with 193 additions and 194 deletions.
  1. +1 −1 src/Block.c
  2. +9 −8 src/Chat.c
  3. +2 −3 src/Chat.h
  4. +37 −30 src/Menus.c
  5. +67 −76 src/Screens.c
  6. +60 −69 src/Widgets.c
  7. +17 −7 src/Widgets.h
@@ -531,7 +531,7 @@ void Block_UpdateCulling(BlockID block) {
*#########################################################################################################################*/
bool AutoRotate_Enabled;

/* replaces a portion of a string, appends otherwise*/
/* replaces a portion of a string, appends otherwise */
static void AutoRotate_Insert(String* str, int offset, const char* suffix) {
int i = str->length - offset;

@@ -16,9 +16,9 @@
#include "GameStructs.h"

static char msgs[10][STRING_SIZE];
String Chat_Status[3] = { String_FromArray(msgs[0]), String_FromArray(msgs[1]), String_FromArray(msgs[2]) };
String Chat_BottomRight[3] = { String_FromArray(msgs[3]), String_FromArray(msgs[4]), String_FromArray(msgs[5]) };
String Chat_ClientStatus[3] = { String_FromArray(msgs[6]), String_FromArray(msgs[7]), String_FromArray(msgs[8]) };
String Chat_Status[4] = { String_FromArray(msgs[0]), String_FromArray(msgs[1]), String_FromArray(msgs[2]), String_FromArray(msgs[3]) };
String Chat_BottomRight[3] = { String_FromArray(msgs[4]), String_FromArray(msgs[5]), String_FromArray(msgs[6]) };
String Chat_ClientStatus[2] = { String_FromArray(msgs[7]), String_FromArray(msgs[8]) };

String Chat_Announcement = String_FromArray(msgs[9]);
TimeMS Chat_AnnouncementReceived;
@@ -191,22 +191,23 @@ void Chat_AddRaw(const char* raw) {
void Chat_Add(const String* text) { Chat_AddOf(text, MSG_TYPE_NORMAL); }

void Chat_AddOf(const String* text, int msgType) {
Event_RaiseChat(&ChatEvents.ChatReceived, text, msgType);

if (msgType == MSG_TYPE_NORMAL) {
StringsBuffer_Add(&Chat_Log, text);
Chat_AppendLog(text);
Chat_AppendLogTime();
} else if (msgType >= MSG_TYPE_STATUS_1 && msgType <= MSG_TYPE_STATUS_3) {
String_Copy(&Chat_Status[msgType - MSG_TYPE_STATUS_1], text);
} else if (msgType >= MSG_TYPE_BOTTOMRIGHT_1 && msgType <= MSG_TYPE_BOTTOMRIGHT_3) {
/* Status[0] is for texture pack downloading message */
String_Copy(&Chat_Status[1 + (msgType - MSG_TYPE_STATUS_1)], text);
} else if (msgType >= MSG_TYPE_BOTTOMRIGHT_1 && msgType <= MSG_TYPE_BOTTOMRIGHT_3) {
String_Copy(&Chat_BottomRight[msgType - MSG_TYPE_BOTTOMRIGHT_1], text);
} else if (msgType == MSG_TYPE_ANNOUNCEMENT) {
String_Copy(&Chat_Announcement, text);
Chat_AnnouncementReceived = DateTime_CurrentUTC_MS();
} else if (msgType >= MSG_TYPE_CLIENTSTATUS_1 && msgType <= MSG_TYPE_CLIENTSTATUS_3) {
} else if (msgType >= MSG_TYPE_CLIENTSTATUS_1 && msgType <= MSG_TYPE_CLIENTSTATUS_2) {
String_Copy(&Chat_ClientStatus[msgType - MSG_TYPE_CLIENTSTATUS_1], text);
}

Event_RaiseChat(&ChatEvents.ChatReceived, text, msgType);
}


@@ -19,11 +19,10 @@ enum MsgType {
MSG_TYPE_BOTTOMRIGHT_3 = 13,
MSG_TYPE_ANNOUNCEMENT = 100,
MSG_TYPE_CLIENTSTATUS_1 = 256, /* Cuboid messages */
MSG_TYPE_CLIENTSTATUS_2 = 257, /* Clipboard invalid character */
MSG_TYPE_CLIENTSTATUS_3 = 258 /* Tab list matching names */
MSG_TYPE_CLIENTSTATUS_2 = 257 /* Tab list matching names */
};

extern String Chat_Status[3], Chat_BottomRight[3], Chat_ClientStatus[3], Chat_Announcement;
extern String Chat_Status[4], Chat_BottomRight[3], Chat_ClientStatus[2], Chat_Announcement;
extern StringsBuffer Chat_Log, Chat_InputLog;
/* Whether chat messages are logged to disc. */
extern bool Chat_Logging;
@@ -117,7 +117,6 @@ struct MenuOptionsScreen {
struct MenuInputWidget input;
struct TextGroupWidget extHelp;
struct Texture extHelpTextures[MENUOPTIONS_MAX_DESC];
char extHelpBuffer[MENUOPTIONS_MAX_DESC * TEXTGROUPWIDGET_LEN];
};

/* Describes a menu option button */
@@ -687,7 +686,7 @@ struct Screen* PauseScreen_MakeInstance(void) {
*--------------------------------------------------OptionsGroupScreen-----------------------------------------------------*
*#########################################################################################################################*/
static struct OptionsGroupScreen OptionsGroupScreen_Instance;
const char* optsGroup_descs[7] = {
static const char* optsGroup_descs[7] = {
"&eMusic/Sound, view bobbing, and more",
"&eChat options, gui scale, font settings, and more",
"&eFPS limit, view distance, entity names/shadows",
@@ -1889,9 +1888,9 @@ static void MenuOptionsScreen_Set(struct MenuOptionsScreen* s, int i, const Stri
}

static void MenuOptionsScreen_FreeExtHelp(struct MenuOptionsScreen* s) {
if (!s->extHelp.linesCount) return;
if (!s->extHelp.lines) return;
Elem_TryFree(&s->extHelp);
s->extHelp.linesCount = 0;
s->extHelp.lines = 0;
}

static void MenuOptionsScreen_RepositionExtHelp(struct MenuOptionsScreen* s) {
@@ -1900,26 +1899,34 @@ static void MenuOptionsScreen_RepositionExtHelp(struct MenuOptionsScreen* s) {
Widget_Reposition(&s->extHelp);
}

static String MenuOptionsScreen_GetDesc(void* obj, int i) {
const char* desc = (const char*)obj;
String descRaw, descLines[5];

descRaw = String_FromReadonly(desc);
String_UNSAFE_Split(&descRaw, '\n', descLines, Array_Elems(descLines));
return descLines[i];
}

static void MenuOptionsScreen_SelectExtHelp(struct MenuOptionsScreen* s, int idx) {
const char* desc;
String descRaw, descLines[5];
int i, count;
int count;

MenuOptionsScreen_FreeExtHelp(s);
if (!s->descriptions || s->activeI >= 0) return;
desc = s->descriptions[idx];
if (!desc) return;

descRaw = String_FromReadonly(desc);
count = String_UNSAFE_Split(&descRaw, '|', descLines, Array_Elems(descLines));
count = String_UNSAFE_Split(&descRaw, '\n', descLines, Array_Elems(descLines));

TextGroupWidget_Create(&s->extHelp, count, &s->textFont, s->extHelpTextures, s->extHelpBuffer);
Widget_SetLocation((struct Widget*)(&s->extHelp), ANCHOR_MIN, ANCHOR_MIN, 0, 0);
TextGroupWidget_Create(&s->extHelp, count, &s->textFont, s->extHelpTextures, MenuOptionsScreen_GetDesc);
Widget_SetLocation((struct Widget*)&s->extHelp, ANCHOR_MIN, ANCHOR_MIN, 0, 0);
Elem_Init(&s->extHelp);

for (i = 0; i < count; i++) {
TextGroupWidget_SetText(&s->extHelp, i, &descLines[i]);
}

s->extHelp.getLineObj = desc;
TextGroupWidget_RedrawAll(&s->extHelp);
MenuOptionsScreen_RepositionExtHelp(s);
}

@@ -1960,7 +1967,7 @@ static void MenuOptionsScreen_Render(void* screen, double delta) {
PackedCol tableCol = PACKEDCOL_CONST(20, 20, 20, 200);

MenuScreen_Render(s, delta);
if (!s->extHelp.linesCount) return;
if (!s->extHelp.lines) return;

w = &s->extHelp;
Gfx_Draw2DFlat(w->x - EXTHELP_PAD, w->y - EXTHELP_PAD,
@@ -1974,7 +1981,7 @@ static void MenuOptionsScreen_Render(void* screen, double delta) {
static void MenuOptionsScreen_OnResize(void* screen) {
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
Menu_OnResize(s);
if (!s->extHelp.linesCount) return;
if (!s->extHelp.lines) return;
MenuOptionsScreen_RepositionExtHelp(s);
}

@@ -2135,7 +2142,7 @@ struct Screen* MenuOptionsScreen_MakeInstance(struct Widget** widgets, int count
s->widgets = widgets;
s->widgetsCount = count;

s->extHelp.linesCount = 0;
s->extHelp.lines = 0;
s->VTABLE = &MenuOptionsScreen_VTABLE;
s->VTABLE->ContextLost = MenuOptionsScreen_ContextLost;
s->VTABLE->ContextRecreated = contextRecreated;
@@ -2440,21 +2447,21 @@ struct Screen* GraphicsOptionsScreen_MakeInstance(void) {

static const char* descs[Array_Elems(buttons)];
descs[0] = \
"&eVSync: &fNumber of frames rendered is at most the monitor's refresh rate.|" \
"&e30/60/120/144 FPS: &fRenders 30/60/120/144 frames at most each second.|" \
"&eNoLimit: &fRenders as many frames as possible each second.|" \
"&eVSync: &fNumber of frames rendered is at most the monitor's refresh rate.\n" \
"&e30/60/120/144 FPS: &fRenders 30/60/120/144 frames at most each second.\n" \
"&eNoLimit: &fRenders as many frames as possible each second.\n" \
"&cUsing NoLimit mode is discouraged.";
descs[2] = "&cNote: &eSmooth lighting is still experimental and can heavily reduce performance.";
descs[3] = \
"&eNone: &fNo names of players are drawn.|" \
"&eHovered: &fName of the targeted player is drawn see-through.|" \
"&eAll: &fNames of all other players are drawn normally.|" \
"&eAllHovered: &fAll names of players are drawn see-through.|" \
"&eNone: &fNo names of players are drawn.\n" \
"&eHovered: &fName of the targeted player is drawn see-through.\n" \
"&eAll: &fNames of all other players are drawn normally.\n" \
"&eAllHovered: &fAll names of players are drawn see-through.\n" \
"&eAllUnscaled: &fAll names of players are drawn see-through without scaling.";
descs[4] = \
"&eNone: &fNo entity shadows are drawn.|" \
"&eSnapToBlock: &fA square shadow is shown on block you are directly above.|" \
"&eCircle: &fA circular shadow is shown across the blocks you are above.|" \
"&eNone: &fNo entity shadows are drawn.\n" \
"&eSnapToBlock: &fA square shadow is shown on block you are directly above.\n" \
"&eCircle: &fA circular shadow is shown across the blocks you are above.\n" \
"&eCircleAll: &fA circular shadow is shown underneath all entities.";

InputValidator_Enum(validators[0], FpsLimit_Names, FPS_LIMIT_COUNT);
@@ -2704,13 +2711,13 @@ struct Screen* HacksSettingsScreen_MakeInstance(void) {
static struct Widget* widgets[Array_Elems(buttons) + 3];

static const char* descs[Array_Elems(buttons)];
descs[2] = "&eIf &fON&e, then the third person cameras will limit|&etheir zoom distance if they hit a solid block.";
descs[3] = "&eSets how many blocks high you can jump up.|&eNote: You jump much higher when holding down the Speed key binding.";
descs[2] = "&eIf &fON&e, then the third person cameras will limit\n&etheir zoom distance if they hit a solid block.";
descs[3] = "&eSets how many blocks high you can jump up.\n&eNote: You jump much higher when holding down the Speed key binding.";
descs[7] = \
"&eIf &fON&e, placing blocks that intersect your own position cause|" \
"&ethe block to be placed, and you to be moved out of the way.|" \
"&eIf &fON&e, placing blocks that intersect your own position cause\n" \
"&ethe block to be placed, and you to be moved out of the way.\n" \
"&fThis is mainly useful for quick pillaring/towering.";
descs[8] = "&eIf &fOFF&e, you will immediately stop when in noclip|&emode and no movement keys are held down.";
descs[8] = "&eIf &fOFF&e, you will immediately stop when in noclip\n&emode and no movement keys are held down.";

InputValidator_Float(validators[1], 0.10f, 50.00f);
defaultValues[1] = "10";

0 comments on commit 8b24029

Please sign in to comment.
You can’t perform that action at this time.