From b563a07d9fcaa58514eeb3ec78438db56ecf2e63 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 8 Mar 2022 18:17:59 +0100 Subject: Replaced GetRealTime uses with Game->Clock equivalent --- Stars45/Bitmap.cpp | 40 +++++++++++++++++++--------------------- Stars45/EditBox.cpp | 2 -- Stars45/Font.cpp | 7 ++++--- Stars45/Game.cpp | 9 --------- Stars45/ScrollWindow.cpp | 10 +++++----- 5 files changed, 28 insertions(+), 40 deletions(-) diff --git a/Stars45/Bitmap.cpp b/Stars45/Bitmap.cpp index 33d8502..e69a755 100644 --- a/Stars45/Bitmap.cpp +++ b/Stars45/Bitmap.cpp @@ -19,8 +19,6 @@ // +--------------------------------------------------------------------+ -DWORD GetRealTime(); - static inline void swap(int& a, int& b) { int tmp=a; a=b; b=tmp; } static inline void sort(int& a, int& b) { if (a>b) swap(a,b); } static inline void swap(double& a, double& b) { double tmp=a; a=b; b=tmp; } @@ -73,7 +71,7 @@ Bitmap::Bitmap(int w, int h, ColorIndex* p, int t) : type(t), width(w), height(h), ownpix(false), alpha_loaded(false), texture(false), pix(p), hipix(0), mapsize(w*h), - last_modified(GetRealTime()) + last_modified(Game::GetInstance()->GetClock()->RealTime()) { sprintf_s(filename, "Bitmap(%d, %d, index, type=%d)", w, h, (int) t); } @@ -82,7 +80,7 @@ Bitmap::Bitmap(int w, int h, Color* p, int t) : type(t), width(w), height(h), ownpix(false), alpha_loaded(false), texture(false), pix(0), hipix(p), mapsize(w*h), - last_modified(GetRealTime()) + last_modified(Game::GetInstance()->GetClock()->RealTime()) { sprintf_s(filename, "Bitmap(%d, %d, hicolor, type=%d)", w, h, (int) t); } @@ -239,7 +237,7 @@ Bitmap::BitBlt(int x, int y, const Bitmap& srcBmp, int sx, int sy, int w, int h, } alpha_loaded = srcBmp.alpha_loaded; - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } // +--------------------------------------------------------------------+ @@ -291,7 +289,7 @@ Bitmap::CopyBitmap(const Bitmap& rhs) } } - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } // +--------------------------------------------------------------------+ @@ -313,7 +311,7 @@ Bitmap::ClearImage() ownpix = false; texture = false; - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } // +--------------------------------------------------------------------+ @@ -348,7 +346,7 @@ Bitmap::CopyImage(int w, int h, BYTE* p, int t) memcpy(pix, p, mapsize); } - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } // +--------------------------------------------------------------------+ @@ -383,7 +381,7 @@ Bitmap::CopyHighColorImage(int w, int h, DWORD* p, int t) memcpy(hipix, p, mapsize*sizeof(DWORD)); } - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } // +--------------------------------------------------------------------+ @@ -405,7 +403,7 @@ Bitmap::CopyAlphaImage(int w, int h, BYTE* a) a++; } - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } void @@ -425,7 +423,7 @@ Bitmap::CopyAlphaRedChannel(int w, int h, DWORD* a) a++; } - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } // +--------------------------------------------------------------------+ @@ -451,7 +449,7 @@ Bitmap::AutoMask(DWORD mask) p++; } - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } // +--------------------------------------------------------------------+ @@ -480,7 +478,7 @@ Bitmap::FillColor(Color c) } } - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } // +--------------------------------------------------------------------+ @@ -750,7 +748,7 @@ Bitmap::SetIndex(int x, int y, ColorIndex c) *(hipix + y*width + x) = c.Index(); } - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } // +--------------------------------------------------------------------+ @@ -768,7 +766,7 @@ Bitmap::SetColor(int x, int y, Color c) *(hipix + y*width + x) = c; } - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } // +--------------------------------------------------------------------+ @@ -1024,7 +1022,7 @@ Bitmap::DrawLine(int x1, int y1, int x2, int y2, Color color) if (!s) return; - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); // vertical lines: if (x1==x2) { @@ -1302,7 +1300,7 @@ Bitmap::DrawRect(int x1, int y1, int x2, int y2, Color color) if (top) draw_strip(s, pitch, pixsize, x1, y1, fw, color); if (bottom) draw_strip(s, pitch, pixsize, x1, y2, fw, color); - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } // +--------------------------------------------------------------------+ @@ -1333,7 +1331,7 @@ Bitmap::DrawRect(const Rect& r, Color color) if (top) draw_strip(s, pitch, pixsize, x1, y1, r.w, color); if (bottom) draw_strip(s, pitch, pixsize, x1, y2, r.w, color); - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } // +--------------------------------------------------------------------+ @@ -1360,7 +1358,7 @@ Bitmap::FillRect(int x1, int y1, int x2, int y2, Color color) for (int i = 0; i < fh; i++) draw_strip(s, pitch, pixsize, x1, y1+i, fw, color); - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } // +--------------------------------------------------------------------+ @@ -1392,7 +1390,7 @@ Bitmap::FillRect(const Rect& r, Color color) for (int i = 0; i < fh; i++) draw_strip(s, pitch, pixsize, x1, y1+i, fw, color); - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } // +--------------------------------------------------------------------+ @@ -1473,7 +1471,7 @@ Bitmap::DrawEllipse(int x1, int y1, int x2, int y2, Color color, BYTE quad) DrawEllipsePoints(x0,y0,x,y,color,quad); } - last_modified = GetRealTime(); + last_modified = Game::GetInstance()->GetClock()->RealTime(); } void diff --git a/Stars45/EditBox.cpp b/Stars45/EditBox.cpp index d57639f..db5861f 100644 --- a/Stars45/EditBox.cpp +++ b/Stars45/EditBox.cpp @@ -19,8 +19,6 @@ #include "Keyboard.h" #include "Mouse.h" -DWORD GetRealTime(); - // +--------------------------------------------------------------------+ static int old_cursor; diff --git a/Stars45/Font.cpp b/Stars45/Font.cpp index ff8bff3..3d30d29 100644 --- a/Stars45/Font.cpp +++ b/Stars45/Font.cpp @@ -18,8 +18,8 @@ #include "DataLoader.h" #include "ParseUtil.h" #include "Video.h" - -DWORD GetRealTime(); +#include "Game.h" +#include "Clock.h" // +--------------------------------------------------------------------+ @@ -643,8 +643,9 @@ Font::DrawText(const char* text, int count, Rect& text_rect, DWORD flags, Bitmap // otherwise, draw caret if requested: else if (caret_index >= 0 && caret_y >= text_rect.y && caret_y <= text_rect.y + text_rect.h) {//caret_y + height < text_rect.y + text_rect.h) { Video* video = Video::GetInstance(); + Clock* clock = Game::GetInstance()->GetClock(); - if (video && (GetRealTime() / 500) & 1) { + if (video && (clock->RealTime() / 500) & 1) { float v[4]; v[0] = (float) (caret_x + 1); v[1] = (float) (caret_y); diff --git a/Stars45/Game.cpp b/Stars45/Game.cpp index 92937e6..97de488 100644 --- a/Stars45/Game.cpp +++ b/Stars45/Game.cpp @@ -1244,15 +1244,6 @@ Game::GetClock() return &clock; } - -DWORD GetRealTime() -{ - Game* game = Game::GetInstance(); - if (game) - return game->RealTime(); - return 0; -} - DWORD Game::RealTime() { return clock.RealTime(); diff --git a/Stars45/ScrollWindow.cpp b/Stars45/ScrollWindow.cpp index 8497dd6..0490da6 100644 --- a/Stars45/ScrollWindow.cpp +++ b/Stars45/ScrollWindow.cpp @@ -20,9 +20,8 @@ #include "Font.h" #include "Keyboard.h" #include "Mouse.h" - - -DWORD GetRealTime(); +#include "Game.h" +#include "Clock.h" // +--------------------------------------------------------------------+ @@ -553,9 +552,10 @@ int ScrollWindow::OnMouseWheel(int wheel) if (GetLineCount() > 0) { static double scroll_time = 0; + Clock* clock = Game::GetInstance()->GetClock(); - if (GetRealTime() - scroll_time > 0.5) { - scroll_time = GetRealTime(); + if (clock->RealTime() - scroll_time > 0.5) { + scroll_time = clock->RealTime(); Button::PlaySound(Button::SND_LIST_SCROLL); } } -- cgit v1.1