From 77a2292d455e4ce56f15f55b2dcc4565eae47822 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 4 Sep 2018 13:05:33 +1000 Subject: [PATCH] C client: Fix clipboard being stuffed up --- src/AsyncDownloader.c | 2 +- src/Game.c | 6 +++--- src/Platform.c | 2 -- src/Platform.h | 2 +- src/String.c | 7 ++++--- src/WinWindow.c | 7 +++---- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/AsyncDownloader.c b/src/AsyncDownloader.c index 2103c1bc6..00667db32 100644 --- a/src/AsyncDownloader.c +++ b/src/AsyncDownloader.c @@ -195,7 +195,7 @@ static void AsyncDownloader_ProcessRequest(struct AsyncRequest* request) { Platform_Log2("Downloading from %s (type %b)", &url, &request->RequestType); struct Stopwatch stopwatch; - Stopwatch_Start(&stopwatch); + Stopwatch_Measure(&stopwatch); request->Result = Http_Do(request, &async_curProgress); UInt32 elapsed = Stopwatch_ElapsedMicroseconds(&stopwatch) / 1000; diff --git a/src/Game.c b/src/Game.c index 87821bd71..31ae0096d 100644 --- a/src/Game.c +++ b/src/Game.c @@ -652,7 +652,7 @@ void Game_TakeScreenshot(void) { } static void Game_RenderFrame(Real64 delta) { - Stopwatch_Start(&game_frameTimer); + Stopwatch_Measure(&game_frameTimer); Gfx_BeginFrame(); Gfx_BindIb(GfxCommon_defaultIb); @@ -731,7 +731,7 @@ void Game_Run(Int32 width, Int32 height, STRING_REF String* title, struct Displa Game_Load(); Event_RaiseVoid(&WindowEvents_Resized); - Stopwatch_Start(&game_renderTimer); + Stopwatch_Measure(&game_renderTimer); for (;;) { Window_ProcessEvents(); if (!Window_Exists) break; @@ -741,7 +741,7 @@ void Game_Run(Int32 width, Int32 height, STRING_REF String* title, struct Displa if (time > 1.0) time = 1.0; if (time <= 0.0) continue; - Stopwatch_Start(&game_renderTimer); + Stopwatch_Measure(&game_renderTimer); Game_RenderFrame(time); } } diff --git a/src/Platform.c b/src/Platform.c index 02ae5a993..c815a9630 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -209,7 +209,6 @@ void Stopwatch_Measure(struct Stopwatch* timer) { timer->Data[0] = (Int64)value.dwLowDateTime | ((Int64)value.dwHighDateTime << 32); } } -void Stopwatch_Start(struct Stopwatch* timer) { Stopwatch_Measure(timer); } /* TODO: check this is actually accurate */ Int32 Stopwatch_ElapsedMicroseconds(struct Stopwatch* timer) { @@ -269,7 +268,6 @@ void Stopwatch_Measure(struct Stopwatch* timer) { timer->Data[0] = value.tv_sec; timer->Data[1] = value.tv_nsec; } -void Stopwatch_Start(struct Stopwatch* timer) { Stopwatch_Measure(timer); } /* TODO: check this is actually accurate */ Int32 Stopwatch_ElapsedMicroseconds(struct Stopwatch* timer) { diff --git a/src/Platform.h b/src/Platform.h index 7b3c44273..d0a0077d4 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -53,7 +53,7 @@ UInt64 DateTime_CurrentUTC_MS(void); void DateTime_CurrentUTC(DateTime* time); void DateTime_CurrentLocal(DateTime* time); struct Stopwatch { Int64 Data[2]; }; -void Stopwatch_Start(struct Stopwatch* timer); +void Stopwatch_Measure(struct Stopwatch* timer); Int32 Stopwatch_ElapsedMicroseconds(struct Stopwatch* timer); bool Directory_Exists(STRING_PURE String* path); diff --git a/src/String.c b/src/String.c index 209a290c5..3a0278c53 100644 --- a/src/String.c +++ b/src/String.c @@ -481,9 +481,10 @@ UInt16 Convert_ExtendedChars[129] = { 0x2302, }; UInt16 Convert_CP437ToUnicode(char c) { - if (c < 0x20) return Convert_ControlChars[(UInt8)c]; - if (c < 0x7F) return c; - return Convert_ExtendedChars[(UInt8)c - 0x7F]; + UInt8 raw = (UInt8)c; + if (raw < 0x20) return Convert_ControlChars[raw]; + if (raw < 0x7F) return raw; + return Convert_ExtendedChars[raw - 0x7F]; } char Convert_UnicodeToCP437(UInt16 c) { diff --git a/src/WinWindow.c b/src/WinWindow.c index 53fb655db..150587593 100644 --- a/src/WinWindow.c +++ b/src/WinWindow.c @@ -478,10 +478,9 @@ void Window_SetClipboardText(STRING_PURE String* value) { HANDLE hGlobal = GlobalAlloc(GMEM_MOVEABLE, (value->length + 1) * sizeof(UInt16)); if (!hGlobal) { CloseClipboard(); return; } - LPVOID dst = GlobalLock(hGlobal); - UInt16* text = (UInt16*)dst; - for (i = 0; i < value->length; i++) { - *text = Convert_CP437ToUnicode(value->buffer[i]); text++; + UInt16* text = GlobalLock(hGlobal); + for (i = 0; i < value->length; i++, text++) { + *text = Convert_CP437ToUnicode(value->buffer[i]); } *text = '\0';