Expose Chat_LogTime directly instead of Chat_GetLogTime function

This commit is contained in:
UnknownShadow200 2019-08-11 12:10:15 +10:00
parent 445ff1c5a3
commit 3d82f65f45
5 changed files with 21 additions and 18 deletions

View File

@ -31,22 +31,17 @@ bool Chat_Logging;
*#########################################################################################################################*/
#define CHAT_LOGTIMES_DEF_ELEMS 256
static TimeMS defaultLogTimes[CHAT_LOGTIMES_DEF_ELEMS];
static TimeMS* logTimes = defaultLogTimes;
static int logTimesCapacity = CHAT_LOGTIMES_DEF_ELEMS, logTimesCount;
TimeMS Chat_GetLogTime(int i) {
if (i < 0 || i >= logTimesCount) Logger_Abort("Tried to get time past LogTime end");
return logTimes[i];
}
TimeMS* Chat_LogTime = defaultLogTimes;
static void Chat_AppendLogTime(void) {
TimeMS now = DateTime_CurrentUTC_MS();
if (logTimesCount == logTimesCapacity) {
Utils_Resize((void**)&logTimes, &logTimesCapacity,
Utils_Resize((void**)&Chat_LogTime, &logTimesCapacity,
sizeof(TimeMS), CHAT_LOGTIMES_DEF_ELEMS, 512);
}
logTimes[logTimesCount++] = now;
Chat_LogTime[logTimesCount++] = now;
}
#ifdef CC_BUILD_WEB
@ -64,6 +59,7 @@ static String logPath = String_FromArray(logPathBuffer);
static struct Stream logStream;
static struct DateTime lastLogDate;
/* Resets log name to empty and last log date to 0 */
static void Chat_ResetLog(void) {
logName.length = 0;
lastLogDate.Day = 0;
@ -71,6 +67,7 @@ static void Chat_ResetLog(void) {
lastLogDate.Year = 0;
}
/* Closes handle to the chat log file */
static void Chat_CloseLog(void) {
ReturnCode res;
if (!logStream.Meta.File) return;
@ -79,6 +76,7 @@ static void Chat_CloseLog(void) {
if (res) { Logger_Warn2(res, "closing", &logPath); }
}
/* Whether the given character is an allowed in a log filename */
static bool Chat_AllowedLogChar(char c) {
return
c == '{' || c == '}' || c == '[' || c == ']' || c == '(' || c == ')' ||
@ -194,8 +192,8 @@ void Chat_Add(const String* text) { Chat_AddOf(text, MSG_TYPE_NORMAL); }
void Chat_AddOf(const String* text, int msgType) {
if (msgType == MSG_TYPE_NORMAL) {
StringsBuffer_Add(&Chat_Log, text);
Chat_AppendLog(text);
Chat_AppendLogTime();
Chat_AppendLog(text);
} else if (msgType >= MSG_TYPE_STATUS_1 && msgType <= MSG_TYPE_STATUS_3) {
/* Status[0] is for texture pack downloading message */
String_Copy(&Chat_Status[1 + (msgType - MSG_TYPE_STATUS_1)], text);
@ -611,8 +609,8 @@ static void Chat_Free(void) {
Chat_CloseLog();
cmds_head = NULL;
if (logTimes != defaultLogTimes) Mem_Free(logTimes);
logTimes = defaultLogTimes;
if (Chat_LogTime != defaultLogTimes) Mem_Free(Chat_LogTime);
Chat_LogTime = defaultLogTimes;
logTimesCount = 0;
StringsBuffer_Clear(&Chat_Log);

View File

@ -21,14 +21,17 @@ enum MsgType {
};
extern String Chat_Status[4], Chat_BottomRight[3], Chat_ClientStatus[2], Chat_Announcement;
extern StringsBuffer Chat_Log, Chat_InputLog;
/* All chat messages received. */
extern StringsBuffer Chat_Log;
/* Time each chat message was received at. */
extern TimeMS* Chat_LogTime;
/* All chat entered by the user. */
extern StringsBuffer Chat_InputLog;
/* Whether chat messages are logged to disc. */
extern bool Chat_Logging;
/* Time at which last announcement message was received. */
extern TimeMS Chat_AnnouncementReceived;
/* Gets the time the ith chat message was received at. */
TimeMS Chat_GetLogTime(int i);
struct ChatCommand;
/* Represents a client-side command/action. */

View File

@ -832,6 +832,7 @@ ReturnCode Gfx_TakeScreenshot(struct Stream* output) {
IDirect3DSurface9* backbuffer = NULL;
IDirect3DSurface9* temp = NULL;
D3DSURFACE_DESC desc;
D3DLOCKED_RECT rect;
Bitmap bmp;
ReturnCode res;
@ -844,8 +845,7 @@ ReturnCode Gfx_TakeScreenshot(struct Stream* output) {
if (res) goto finished; /* TODO: For DX 8 use IDirect3DDevice8::CreateImageSurface */
res = IDirect3DDevice9_GetRenderTargetData(device, backbuffer, temp);
if (res) goto finished;
D3DLOCKED_RECT rect;
res = IDirect3DSurface9_LockRect(temp, &rect, NULL, D3DLOCK_READONLY | D3DLOCK_NO_DIRTY_UPDATE);
if (res) goto finished;
{

View File

@ -980,7 +980,7 @@ static void HUDScreen_DrawChat(struct HUDScreen* s, double delta) {
if (!tex.ID) continue;
if (logIdx < 0 || logIdx >= Chat_Log.count) continue;
if (Chat_GetLogTime(logIdx) + (10 * 1000) >= now) Texture_Render(&tex);
if (Chat_LogTime[logIdx] + (10 * 1000) >= now) Texture_Render(&tex);
}
}

View File

@ -413,7 +413,9 @@ void Window_Init(void) {
}
void Window_Create(int width, int height) {
ATOM atom;
RECT r;
win_instance = GetModuleHandle(NULL);
/* TODO: UngroupFromTaskbar(); */
width = Display_ScaleX(width);
@ -437,7 +439,7 @@ void Window_Create(int width, int height) {
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
ATOM atom = RegisterClassEx(&wc);
atom = RegisterClassEx(&wc);
if (!atom) Logger_Abort2(GetLastError(), "Failed to register window class");
win_handle = CreateWindowEx(0, MAKEINTATOM(atom), NULL, CC_WIN_STYLE,