From cc61f5de318f14d04edf1a49d7c8678d759cc8ed Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Sun, 25 Aug 2024 00:01:37 +0300 Subject: [PATCH] Convert win32 to use new logging facility --- win32/CMakeLists.txt | 2 ++ win32/WinController.cpp | 19 +++++++------------ win32/winapp.cpp | 20 ++++++++++---------- win32/windata.cpp | 16 ++++++++-------- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/win32/CMakeLists.txt b/win32/CMakeLists.txt index a4b646a4..a3967526 100644 --- a/win32/CMakeLists.txt +++ b/win32/CMakeLists.txt @@ -10,6 +10,8 @@ add_dependencies(win32 get_git_hash) target_include_directories(win32 PRIVATE ${PROJECT_BINARY_DIR}/lib) target_compile_definitions(win32 PRIVATE DX_APP) target_link_libraries(win32 PRIVATE + ddebug ddio misc + plog::plog ) diff --git a/win32/WinController.cpp b/win32/WinController.cpp index e427a831..cfe49bf3 100644 --- a/win32/WinController.cpp +++ b/win32/WinController.cpp @@ -320,6 +320,7 @@ #include "joystick.h" #include "Macros.h" #include "inffile.h" +#include "log.h" // Sorry! This is needed for the semi-hacky mouselook support #include "descent.h" @@ -536,7 +537,6 @@ ct_config_data gameWinController::get_controller_value(ct_type type_req) { case ctMouseButton: for (j = 0; j < CT_MAX_BUTTONS; j++) { if (ddio_MouseBtnUpCount(j)) { - // mprintf(0, "MseBtn %d down\n", j); val = MAKE_CONFIG_DATA(CONTROLLER_CTL_INFO(1, NULL_CONTROLLER), CONTROLLER_CTL_VALUE(j + 1, NULL_BINDING)); return val; } @@ -554,7 +554,7 @@ ct_config_data gameWinController::get_controller_value(ct_type type_req) { : (m_ControlList[i].sens[CT_V_AXIS - 1] > 1.0f) ? 0.80f : (m_ControlList[i].sens[CT_V_AXIS - 1] / 2); pos = get_axis_value(i, CT_V_AXIS, ctAnalog); - mprintf(0, "pos=%.2f\n", pos); + LOG_DEBUG.printf("pos=%.2f", pos); if (fabs(pos) > limit) val = MAKE_CONFIG_DATA(ctl, CONTROLLER_CTL_VALUE(CT_V_AXIS, NULL_BINDING)); } @@ -629,13 +629,11 @@ ct_config_data gameWinController::get_controller_value(ct_type type_req) { } if (m_ControlList[i].flags & CTF_Y_AXIS) { pos = get_axis_value(i, CT_Y_AXIS, ctAnalog); - // mprintf(0, "y=%.2f ", pos); if (fabs(pos) >= 0.90f) val = MAKE_CONFIG_DATA(ctl, CONTROLLER_CTL_VALUE(CT_Y_AXIS, NULL_BINDING)); } if (m_ControlList[i].flags & CTF_X_AXIS) { pos = get_axis_value(i, CT_X_AXIS, ctAnalog); - // mprintf(0, "x=%.2f\n", pos); if (fabs(pos) >= 0.90f) val = MAKE_CONFIG_DATA(ctl, CONTROLLER_CTL_VALUE(CT_X_AXIS, NULL_BINDING)); } @@ -903,7 +901,7 @@ float gameWinController::get_axis_value(int8_t controller, uint8_t axis, ct_form val -= 1.0f; } else { val = 0.0f; - mprintf(1, "gameController::axis unsupported format for function.\n"); + LOG_DEBUG << "gameController::axis unsupported format for function."; } ct_packet key_slide1, key_bank; @@ -1046,7 +1044,7 @@ float gameWinController::get_button_value(int8_t controller, ct_format format, u break; default: - mprintf(1, "gameController::button unsupported format for function\n"); + LOG_WARNING << "gameController::button unsupported format for function"; } return val; @@ -1113,7 +1111,7 @@ float gameWinController::get_pov_value(int8_t controller, ct_format format, uint break; default: - mprintf(1, "gameController::pov unsupported format for function\n"); + LOG_WARNING << "gameController::pov unsupported format for function"; } return val; @@ -1141,7 +1139,7 @@ float gameWinController::get_key_value(int key, ct_format format) { break; default: - mprintf(1, "gameController::key unsupported format for function\n"); + LOG_WARNING << "gameController::key unsupported format for function"; } return val; @@ -1381,7 +1379,7 @@ bool gameWinController::enum_controllers(char *remote_adr) { } m_ControlList[num_devs].deadzone = JOY_DEADZONE; - mprintf(0, "Controller %s found.\n", jc.name); + LOG_INFO.printf("Controller %s found.", jc.name); // okay, now search for a '****.ctl' file in the current directory. parse_ctl_file(num_devs, jc.name); @@ -1454,7 +1452,6 @@ void gameWinController::extctl_getpos(int id) { if ((ji.buttons & (1 << i)) && !(m_ExtCtlStates[id].buttons & (1 << i))) { m_ExtCtlStates[id].btnpresses[i]++; m_ExtCtlStates[id].btnstarts[i] = timer_val; - // mprintf(0, "Start time for %d = %f\n", i, timer_val); } if (ji.buttons & (1 << i)) // if button is down @@ -1484,8 +1481,6 @@ void gameWinController::mouse_geteval() { m_MseState.m_absX = x; m_MseState.m_absY = y; m_MseState.m_buttonMask = btnmask; - - mprintf_at(1, 5, 30, "btnmask=%08d\n", btnmask); } // gets sensitivity of axis item diff --git a/win32/winapp.cpp b/win32/winapp.cpp index 60b17ea3..21163e4e 100644 --- a/win32/winapp.cpp +++ b/win32/winapp.cpp @@ -149,7 +149,8 @@ #include "Application.h" #include "AppConsole.h" -#include "mono.h" +#include "debugbreak.h" +#include "log.h" #include "networking.h" #include @@ -234,7 +235,7 @@ oeWin32Application::oeWin32Application(const char *name, unsigned flags, HInstan #endif if (!RegisterClass(&wc)) { - mprintf(0, "Failure to register window class (err:%x).\n", GetLastError()); + LOG_ERROR.printf("Failure to register window class (err:%x).", GetLastError()); return; } @@ -353,7 +354,7 @@ void oeWin32Application::init() { if (m_hWnd == NULL) { DWORD err = GetLastError(); - mprintf(0, "Failed to create game window (err: %x)\n", err); + LOG_ERROR.printf("Failed to create game window (err: %x)", err); return; } @@ -401,7 +402,7 @@ int oeWin32Application::defer_block() { // QUIT APP. exit(1); } else if (msg.message == WM_MOVE) { - mprintf(0, "move msg\n"); + LOG_DEBUG << "move msg"; } TranslateMessage(&msg); DispatchMessage(&msg); @@ -416,7 +417,7 @@ int oeWin32Application::defer_block() { if (this->active()) { #ifndef _DEBUG if (GetForegroundWindow() != (HWND)this->m_hWnd && !(m_Flags & OEAPP_CONSOLE)) { - mprintf(0, "forcing this window into the foreground.\n"); + LOG_DEBUG << "forcing this window into the foreground."; SetForegroundWindow((HWND)this->m_hWnd); } #endif @@ -466,11 +467,11 @@ void oeWin32Application::os_init() { #ifdef _DEBUG if (os == Win9x) { - mprintf(0, "Win9x system\n"); + LOG_DEBUG << "Win9x system"; } else if (os == WinNT) { - mprintf(0, "WinNT %d.%d.%d system\n", major, minor, build); + LOG_DEBUG.printf( "WinNT %d.%d.%d system", major, minor, build); } else { - mprintf(0, "Win32 non-standard operating system\n"); + LOG_DEBUG << "Win32 non-standard operating system"; } #endif @@ -541,7 +542,6 @@ LResult oeWin32Application::WndProc(HWnd hwnd, unsigned msg, WParam wParam, LPar switch (msg) { case WM_ACTIVATEAPP: m_AppActive = wParam ? true : false; - // mprintf(0, "WM_ACTIVATEAPP (%u,%l)\n", wParam, lParam); break; } @@ -679,7 +679,7 @@ LRESULT WINAPI MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { break; case WM_POWERBROADCAST: // Won't allow OS to suspend operation for now. - mprintf(0, "WM_POWERBROADCAST=%u,%d\n", wParam, lParam); + LOG_DEBUG.printf("WM_POWERBROADCAST=%u,%d", wParam, lParam); if (wParam == PBT_APMQUERYSUSPEND) { return BROADCAST_QUERY_DENY; } diff --git a/win32/windata.cpp b/win32/windata.cpp index 43761e0e..7ea03cfd 100644 --- a/win32/windata.cpp +++ b/win32/windata.cpp @@ -73,7 +73,7 @@ #include #include -#include "mono.h" +#include "log.h" #include "pserror.h" // Construction and destruction. @@ -91,7 +91,7 @@ oeWin32AppDatabase::oeWin32AppDatabase() { if (!res) { res = create_record(m_Basepath); if (!res) { - mprintf(1, "Unable to create registry directory.\n"); + LOG_WARNING << "Unable to create registry directory."; } } } @@ -120,7 +120,7 @@ bool oeWin32AppDatabase::create_record(const char *pathname) { lres = RegCreateKeyEx((HKEY)hBaseKey, pathname, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &disp); if (lres != ERROR_SUCCESS) { - mprintf(1, "Unable to create key %s (%x)\n", pathname, lres); + LOG_WARNING.printf("Unable to create key %s (%x)", pathname, lres); return 0; } @@ -142,7 +142,7 @@ bool oeWin32AppDatabase::lookup_record(const char *pathname) { lres = RegOpenKeyEx((HKEY)hBaseKey, pathname, 0, KEY_READ | KEY_WRITE | KEY_EXECUTE, &hkey); if (lres != ERROR_SUCCESS) { - mprintf(1, "Unable to open key %s (%x)\n", pathname, lres); + LOG_WARNING.printf("Unable to open key %s (%x)", pathname, lres); return 0; } @@ -166,7 +166,7 @@ bool oeWin32AppDatabase::read(const char *label, char *entry, int *entrylen) { assert(type != REG_DWORD); if (lres != ERROR_SUCCESS) { - mprintf(1, "Unable to query str key %s (%x)\n", label, lres); + LOG_WARNING.printf("Unable to query str key %s (%x)", label, lres); return 0; } return 1; @@ -188,7 +188,7 @@ bool oeWin32AppDatabase::read(const char *label, void *entry, int wordsize) { assert(len == 4); if (lres != ERROR_SUCCESS) { - mprintf(1, "Unable to query int key %s (%x)\n", label, lres); + LOG_WARNING.printf("Unable to query int key %s (%x)", label, lres); return 0; } @@ -234,7 +234,7 @@ bool oeWin32AppDatabase::write(const char *label, const char *entry, int entryle lres = RegSetValueEx((HKEY)hCurKey, label, 0, REG_SZ, (LPBYTE)entry, entrylen); if (lres != ERROR_SUCCESS) { - mprintf(1, "Unable to write str key %s (%x)\n", label, lres); + LOG_WARNING.printf("Unable to write str key %s (%x)", label, lres); return 0; } return 1; @@ -249,7 +249,7 @@ bool oeWin32AppDatabase::write(const char *label, int entry) { lres = RegSetValueEx((HKEY)hCurKey, label, 0, REG_DWORD, (LPBYTE)&entry, sizeof(int)); if (lres != ERROR_SUCCESS) { - mprintf(1, "Unable to write int key %s (%x)\n", label, lres); + LOG_WARNING.printf("Unable to write int key %s (%x)", label, lres); return 0; }