mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-09 15:28:21 -04:00
Chat_LogTimes doesn't need to be a dynamic array, only needs to be a fixed size array of around GUI_MAX_CHATLINES in length
This commit is contained in:
parent
3671c1578c
commit
18ead3861d
23
src/Chat.c
23
src/Chat.c
@ -45,27 +45,10 @@ cc_bool Chat_Logging;
|
||||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------Chat logging------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#define CHAT_LOGTIMES_DEF_ELEMS 256
|
||||
static double defaultLogTimes[CHAT_LOGTIMES_DEF_ELEMS];
|
||||
static int logTimesCapacity = CHAT_LOGTIMES_DEF_ELEMS, logTimesCount;
|
||||
double* Chat_LogTime = defaultLogTimes;
|
||||
|
||||
static void AppendChatLogTime(void) {
|
||||
double now = Game.Time;
|
||||
|
||||
if (logTimesCount == logTimesCapacity) {
|
||||
Utils_Resize((void**)&Chat_LogTime, &logTimesCapacity,
|
||||
sizeof(double), CHAT_LOGTIMES_DEF_ELEMS, 512);
|
||||
}
|
||||
Chat_LogTime[logTimesCount++] = now;
|
||||
}
|
||||
double Chat_RecentLogTimes[CHATLOG_TIME_MASK + 1];
|
||||
|
||||
static void ClearChatLogs(void) {
|
||||
if (Chat_LogTime != defaultLogTimes) Mem_Free(Chat_LogTime);
|
||||
Chat_LogTime = defaultLogTimes;
|
||||
logTimesCount = 0;
|
||||
logTimesCapacity = CHAT_LOGTIMES_DEF_ELEMS;
|
||||
|
||||
Mem_Set(Chat_RecentLogTimes, 0, sizeof(Chat_RecentLogTimes));
|
||||
StringsBuffer_Clear(&Chat_Log);
|
||||
}
|
||||
|
||||
@ -236,8 +219,8 @@ void Chat_AddOf(const cc_string* text, int msgType) {
|
||||
Chat_AddRaw("&cChat log cleared as it hit 8.3 million character limit");
|
||||
}
|
||||
|
||||
Chat_GetLogTime(Chat_Log.count) = Game.Time;
|
||||
StringsBuffer_Add(&Chat_Log, text);
|
||||
AppendChatLogTime();
|
||||
AppendChatLog(text);
|
||||
} else if (msgType >= MSG_TYPE_STATUS_1 && msgType <= MSG_TYPE_STATUS_3) {
|
||||
/* Status[0] is for texture pack downloading message */
|
||||
|
26
src/Chat.h
26
src/Chat.h
@ -25,22 +25,26 @@ enum MsgType {
|
||||
MSG_TYPE_EXTRASTATUS_2 = 361
|
||||
};
|
||||
|
||||
extern cc_string Chat_Status[5], Chat_BottomRight[3], Chat_ClientStatus[2];
|
||||
extern cc_string Chat_Announcement, Chat_BigAnnouncement, Chat_SmallAnnouncement;
|
||||
/* All chat messages received. */
|
||||
extern struct StringsBuffer Chat_Log;
|
||||
/* Time each chat message was received at. */
|
||||
extern double* Chat_LogTime;
|
||||
/* All chat entered by the user. */
|
||||
extern struct StringsBuffer Chat_InputLog;
|
||||
/* Whether chat messages are logged to disc. */
|
||||
extern cc_bool Chat_Logging;
|
||||
/* NOTE: this must be: (next power of next larger than GUI_MAX_CHATLINES) - 1 */
|
||||
#define CHATLOG_TIME_MASK 31
|
||||
/* Time most recent chat message were received at */
|
||||
extern double Chat_RecentLogTimes[CHATLOG_TIME_MASK + 1];
|
||||
#define Chat_GetLogTime(i) Chat_RecentLogTimes[(i) & CHATLOG_TIME_MASK]
|
||||
|
||||
/* Times at which last announcement messages were received. */
|
||||
/* Times at which last announcement messages were received */
|
||||
extern double Chat_AnnouncementReceived;
|
||||
extern double Chat_BigAnnouncementReceived;
|
||||
extern double Chat_SmallAnnouncementReceived;
|
||||
|
||||
extern cc_string Chat_Status[5], Chat_BottomRight[3], Chat_ClientStatus[2];
|
||||
extern cc_string Chat_Announcement, Chat_BigAnnouncement, Chat_SmallAnnouncement;
|
||||
/* All chat messages received */
|
||||
extern struct StringsBuffer Chat_Log;
|
||||
/* All chat entered by the user */
|
||||
extern struct StringsBuffer Chat_InputLog;
|
||||
/* Whether chat messages are logged to disc */
|
||||
extern cc_bool Chat_Logging;
|
||||
|
||||
/* This command is only available in singleplayer */
|
||||
#define COMMAND_FLAG_SINGLEPLAYER_ONLY 0x01
|
||||
/* args is passed as a single string instead of being split by spaces */
|
||||
|
@ -48,6 +48,8 @@
|
||||
#define GAME_DEF_TICKS (1.0 / 20)
|
||||
#define GAME_NET_TICKS (1.0 / 60)
|
||||
|
||||
#define GUI_MAX_CHATLINES 30
|
||||
|
||||
enum FACE_CONSTS {
|
||||
FACE_XMIN = 0, /* Face X = 0 */
|
||||
FACE_XMAX = 1, /* Face X = 1 */
|
||||
|
@ -90,7 +90,7 @@ void Gui_ShowDefault(void) {
|
||||
|
||||
static void LoadOptions(void) {
|
||||
Gui.DefaultLines = Game_ClassicMode ? 10 : 12;
|
||||
Gui.Chatlines = Options_GetInt(OPT_CHATLINES, 0, 30, Gui.DefaultLines);
|
||||
Gui.Chatlines = Options_GetInt(OPT_CHATLINES, 0, GUI_MAX_CHATLINES, Gui.DefaultLines);
|
||||
Gui.ClickableChat = !Game_ClassicMode && Options_GetBool(OPT_CLICKABLE_CHAT, !Input_TouchMode);
|
||||
Gui.TabAutocomplete = !Game_ClassicMode && Options_GetBool(OPT_TAB_AUTOCOMPLETE, true);
|
||||
|
||||
|
@ -766,7 +766,7 @@ static struct ChatScreen {
|
||||
struct Texture statusTextures[CHAT_MAX_STATUS];
|
||||
struct Texture bottomRightTextures[CHAT_MAX_BOTTOMRIGHT];
|
||||
struct Texture clientStatusTextures[CHAT_MAX_CLIENTSTATUS];
|
||||
struct Texture chatTextures[TEXTGROUPWIDGET_MAX_LINES];
|
||||
struct Texture chatTextures[GUI_MAX_CHATLINES];
|
||||
} ChatScreen_Instance;
|
||||
#define CH_EXTENT 16
|
||||
|
||||
@ -1012,7 +1012,7 @@ static void ChatScreen_DrawChat(struct ChatScreen* s, double delta) {
|
||||
if (!tex.ID) continue;
|
||||
|
||||
if (logIdx < 0 || logIdx >= Chat_Log.count) continue;
|
||||
if (Chat_LogTime[logIdx] + 10 >= now) Texture_Render(&tex);
|
||||
if (Chat_GetLogTime(logIdx) + 10 >= now) Texture_Render(&tex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1245,7 +1245,7 @@ static int ChatScreen_PointerDown(void* screen, int id, int x, int y) {
|
||||
i = TextGroupWidget_GetSelected(&s->chat, &text, x, y);
|
||||
if (!Utils_IsUrlPrefix(&text)) return false;
|
||||
|
||||
if (Chat_LogTime[s->chatIndex + i] + 10 < Game.Time) return false;
|
||||
if (Chat_GetLogTime(s->chatIndex + i) + 10 < Game.Time) return false;
|
||||
UrlWarningOverlay_Show(&text); return TOUCH_TYPE_GUI;
|
||||
}
|
||||
|
||||
|
@ -2060,8 +2060,8 @@ static void TextGroupWidget_Output(struct Portion bit, int lineBeg, int lineEnd,
|
||||
|
||||
static int TextGroupWidget_Reduce(struct TextGroupWidget* w, char* chars, int target, struct Portion* portions) {
|
||||
struct Portion* start = portions;
|
||||
int begs[TEXTGROUPWIDGET_MAX_LINES];
|
||||
int ends[TEXTGROUPWIDGET_MAX_LINES];
|
||||
int begs[GUI_MAX_CHATLINES];
|
||||
int ends[GUI_MAX_CHATLINES];
|
||||
struct Portion bit;
|
||||
cc_string line;
|
||||
int nextStart, i, total = 0, end;
|
||||
@ -2112,7 +2112,7 @@ static void TextGroupWidget_FormatUrl(cc_string* text, const cc_string* url) {
|
||||
}
|
||||
|
||||
static cc_bool TextGroupWidget_GetUrl(struct TextGroupWidget* w, cc_string* text, int index, int mouseX) {
|
||||
char chars[TEXTGROUPWIDGET_MAX_LINES * TEXTGROUPWIDGET_LEN];
|
||||
char chars[GUI_MAX_CHATLINES * TEXTGROUPWIDGET_LEN];
|
||||
struct Portion portions[2 * (TEXTGROUPWIDGET_LEN / TEXTGROUPWIDGET_HTTP_LEN)];
|
||||
struct Portion bit;
|
||||
struct DrawTextArgs args = { 0 };
|
||||
@ -2176,7 +2176,7 @@ static cc_bool TextGroupWidget_MightHaveUrls(struct TextGroupWidget* w) {
|
||||
}
|
||||
|
||||
static void TextGroupWidget_DrawAdvanced(struct TextGroupWidget* w, struct Texture* tex, struct DrawTextArgs* args, int index, const cc_string* text) {
|
||||
char chars[TEXTGROUPWIDGET_MAX_LINES * TEXTGROUPWIDGET_LEN];
|
||||
char chars[GUI_MAX_CHATLINES * TEXTGROUPWIDGET_LEN];
|
||||
struct Portion portions[2 * (TEXTGROUPWIDGET_LEN / TEXTGROUPWIDGET_HTTP_LEN)];
|
||||
struct Portion bit;
|
||||
int width, height;
|
||||
|
@ -229,7 +229,6 @@ CC_NOINLINE void ChatInputWidget_SetFont(struct ChatInputWidget* w, struct FontD
|
||||
|
||||
/* Retrieves the text for the i'th line in the group */
|
||||
typedef cc_string (*TextGroupWidget_Get)(int i);
|
||||
#define TEXTGROUPWIDGET_MAX_LINES 30
|
||||
#define TEXTGROUPWIDGET_LEN (STRING_SIZE + (STRING_SIZE / 2))
|
||||
|
||||
/* A group of text labels. */
|
||||
@ -238,7 +237,7 @@ struct TextGroupWidget {
|
||||
int lines, defaultHeight;
|
||||
struct FontDesc* font;
|
||||
/* Whether a line has zero height when that line has no text in it. */
|
||||
cc_bool collapsible[TEXTGROUPWIDGET_MAX_LINES];
|
||||
cc_bool collapsible[GUI_MAX_CHATLINES];
|
||||
cc_bool underlineUrls;
|
||||
struct Texture* textures;
|
||||
TextGroupWidget_Get GetLine;
|
||||
|
Loading…
x
Reference in New Issue
Block a user