Skip to content

Commit

Permalink
Expose Chat_LogTime directly instead of Chat_GetLogTime function
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Aug 11, 2019
1 parent 445ff1c commit 3d82f65
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
20 changes: 9 additions & 11 deletions src/Chat.c
Expand Up @@ -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
Expand All @@ -64,13 +59,15 @@ 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;
lastLogDate.Month = 0;
lastLogDate.Year = 0;
}

/* Closes handle to the chat log file */
static void Chat_CloseLog(void) {
ReturnCode res;
if (!logStream.Meta.File) return;
Expand All @@ -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 == ')' ||
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/Chat.h
Expand Up @@ -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. */
Expand Down
4 changes: 2 additions & 2 deletions src/Graphics.c
Expand Up @@ -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;

Expand All @@ -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;
{
Expand Down
2 changes: 1 addition & 1 deletion src/Screens.c
Expand Up @@ -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);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Window.c
Expand Up @@ -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);
Expand All @@ -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,
Expand Down

0 comments on commit 3d82f65

Please sign in to comment.