diff --git a/src/Application/Game.cpp b/src/Application/Game.cpp index 4d837a2cdb6..5095e97bd70 100644 --- a/src/Application/Game.cpp +++ b/src/Application/Game.cpp @@ -309,7 +309,7 @@ bool Game::loop() { pParty->Reset(); pParty->createDefaultParty(true); - __debugbreak(); + assert(false); /*extern void CreateDefaultBLVLevel(); CreateDefaultBLVLevel(); @@ -508,13 +508,13 @@ void Game::processQueuedMessages() { // Game_OpenLoadGameDialog(); continue; case UIMSG_Quit: // Game_QuitGameWhilePlaying(uMessageParam); continue; case UIMSG_80: - __debugbreak(); + assert(false); pGUIWindow_CurrentMenu->Release(); current_screen_type = SCREEN_OPTIONS; - __debugbreak(); // pGUIWindow_CurrentMenu = - // GUIWindow::Create(0, 0, - // window->GetWidth(), window->GetHeight(), - // WINDOW_8, 0, 0); + // pGUIWindow_CurrentMenu = + // GUIWindow::Create(0, 0, + // window->GetWidth(), window->GetHeight(), + // WINDOW_8, 0, 0); continue; case UIMSG_Cancel: new OnCancel({350, 302}, {106, 42}, pBtnCancel); @@ -734,7 +734,7 @@ void Game::processQueuedMessages() { pEventTimer->Resume(); continue; case SCREEN_19: - __debugbreak(); + assert(false); pWindow2 = ptr_507BC8; pWindow2->Release(); current_screen_type = SCREEN_GAME; @@ -840,20 +840,19 @@ void Game::processQueuedMessages() { continue; default: - __debugbreak(); // which GAME_MENU is - // this? + assert(false); // which GAME_MENU is this? onEscape(); continue; } - __debugbreak(); // which GAME_MENU is this? + assert(false); // which GAME_MENU is this? onEscape(); continue; } - __debugbreak(); // which GAME_MENU is this? + assert(false); // which GAME_MENU is this? CharacterUI_ReleaseButtons(); //ReleaseAwardsScrollBar(); } - // __debugbreak(); // which GAME_MENU is this? debug / fallback + // assert(false); // which GAME_MENU is this? debug / fallback onEscape(); continue; } @@ -1052,7 +1051,7 @@ void Game::processQueuedMessages() { continue; case UIMSG_HouseTransitionConfirmation: - __debugbreak(); + assert(false); playButtonSoundOnEscape = false; pAudioPlayer->playUISound(SOUND_StartMainChoice02); SaveGame(1, 0); @@ -1129,11 +1128,11 @@ void Game::processQueuedMessages() { } // strcpy((char *)userInputHandler->pPressedKeysBuffer, "2"); - // __debugbreak(); // missed break/continue? + // assert(false); // missed break/continue? continue; case UIMSG_DD: { - __debugbreak(); + assert(false); // sprintf(tmp_str.data(), "%s", // pKeyActionMap->pPressedKeysBuffer); FrameTableTxtLine frameTableTxtLine; @@ -1198,12 +1197,12 @@ void Game::processQueuedMessages() { continue; } case UIMSG_1C: - __debugbreak(); + assert(false); if (!pParty->hasActiveCharacter() || current_screen_type != SCREEN_GAME) continue; - __debugbreak(); // ptr_507BC8 = GUIWindow::Create(0, 0, - // window->GetWidth(), window->GetHeight(), - // WINDOW_68, uMessageParam, 0); + assert(false); // ptr_507BC8 = GUIWindow::Create(0, 0, + // window->GetWidth(), window->GetHeight(), + // WINDOW_68, uMessageParam, 0); current_screen_type = SCREEN_19; pEventTimer->Pause(); continue; @@ -1681,14 +1680,14 @@ void Game::processQueuedMessages() { _engine->onGameViewportClick(); continue; case UIMSG_F: // what event? - __debugbreak(); + assert(false); //pButton2 = (GUIButton *)(uint16_t)vis->get_picked_object_zbuf_val().object_pid; - __debugbreak(); // GUIWindow::Create(0, 0, 0, 0, WINDOW_F, (int)pButton2, 0); + assert(false); // GUIWindow::Create(0, 0, 0, 0, WINDOW_F, (int)pButton2, 0); continue; case UIMSG_54: // what event? - __debugbreak(); + assert(false); //pButton2 = (GUIButton *)uMessageParam; - __debugbreak(); // GUIWindow::Create(0, 0, 0, 0, WINDOW_22, (int)pButton2, 0); + assert(false); // GUIWindow::Create(0, 0, 0, 0, WINDOW_22, (int)pButton2, 0); continue; case UIMSG_Game_Action: engine->_messageQueue->clear(); diff --git a/src/Application/GameMenu.cpp b/src/Application/GameMenu.cpp index a6f207968de..5b8b2b404ce 100644 --- a/src/Application/GameMenu.cpp +++ b/src/Application/GameMenu.cpp @@ -380,7 +380,7 @@ void Menu::EventLoop() { continue; case UIMSG_SetGraphicsMode: - __debugbreak(); // Nomad: graphicsmode as it was now removed + assert(false); // Nomad: graphicsmode as it was now removed continue; case UIMSG_GameMenu_ReturnToGame: diff --git a/src/Application/GameWindowHandler.cpp b/src/Application/GameWindowHandler.cpp index 90f38a1fe8e..e8009506b86 100644 --- a/src/Application/GameWindowHandler.cpp +++ b/src/Application/GameWindowHandler.cpp @@ -5,7 +5,6 @@ #include "Arcomage/Arcomage.h" -#include "Engine/ErrorHandling.h" #include "Engine/Engine.h" #include "Engine/EngineGlobals.h" #include "Engine/Components/Control/EngineControlComponent.h" @@ -335,11 +334,11 @@ void GameWindowHandler::OnKey(PlatformKey key) { } void GameWindowHandler::OnFocus() { - __debugbreak(); + assert(false); } void GameWindowHandler::OnFocusLost() { - __debugbreak(); + assert(false); } void GameWindowHandler::OnPaint() { diff --git a/src/Arcomage/Arcomage.cpp b/src/Arcomage/Arcomage.cpp index 2d93779b362..2b30691f00f 100644 --- a/src/Arcomage/Arcomage.cpp +++ b/src/Arcomage/Arcomage.cpp @@ -240,9 +240,6 @@ void ArcomageGame::onKeyPress(PlatformKey key) { explosion_effect_struct *explosion_effect_struct::New() { explosion_effect_struct *v2 = (explosion_effect_struct *)malloc(sizeof(explosion_effect_struct)); - if (v2 == nullptr) { - Error("Malloc - explosion_effect_struct::New()"); - } v2->mem_signature = SIG_MEMALOC; v2->remaining_sparks_to_init = 0; v2->prev_init_overflow = 0; @@ -793,7 +790,7 @@ int CalculateCardPower(ArcomagePlayer *player, ArcomagePlayer *enemy, } bool OpponentsAITurn(int player_num) { - if (player_num == 0) __debugbreak(); + assert(player_num != 0); int ai_player_cards_count = GetPlayerHandCardCount(player_num); if (ai_player_cards_count == 0) return true; diff --git a/src/Bin/OpenEnroth/OpenEnroth.cpp b/src/Bin/OpenEnroth/OpenEnroth.cpp index 1eb42436880..951367629a6 100644 --- a/src/Bin/OpenEnroth/OpenEnroth.cpp +++ b/src/Bin/OpenEnroth/OpenEnroth.cpp @@ -9,7 +9,6 @@ #include "Engine/Components/Trace/EngineTraceRecorder.h" #include "Engine/Components/Trace/EngineTraceStateAccessor.h" #include "Engine/Engine.h" -#include "Engine/ErrorHandling.h" #include "Engine/EngineGlobals.h" #include "Library/Application/PlatformApplication.h" @@ -50,11 +49,6 @@ int runRetrace(OpenEnrothOptions options) { } int runOpenEnroth(OpenEnrothOptions options) { - setErrorHandler([](const std::string &title, const std::string &message) { - if (platform) - platform->showMessageBox(title, message); - }); - GameStarter(options).run(); return 0; } diff --git a/src/Engine/CMakeLists.txt b/src/Engine/CMakeLists.txt index 863c3f46cdb..8039d51e9a6 100644 --- a/src/Engine/CMakeLists.txt +++ b/src/Engine/CMakeLists.txt @@ -6,7 +6,6 @@ set(ENGINE_SOURCES Conditions.cpp Engine.cpp EngineGlobals.cpp - ErrorHandling.cpp EngineIocContainer.cpp GpuHints.cpp LOD.cpp @@ -32,7 +31,6 @@ set(ENGINE_HEADERS Conditions.h Engine.h EngineGlobals.h - ErrorHandling.h EngineIocContainer.h LOD.h LodTextureCache.h diff --git a/src/Engine/Engine.cpp b/src/Engine/Engine.cpp index e9990757e0c..ce403746f8d 100644 --- a/src/Engine/Engine.cpp +++ b/src/Engine/Engine.cpp @@ -168,11 +168,10 @@ void Engine::drawWorld() { if (uCurrentlyLoadedLevelType == LEVEL_INDOOR) { pIndoor->Draw(); - } else if (uCurrentlyLoadedLevelType == LEVEL_OUTDOOR) { + } else { + assert(uCurrentlyLoadedLevelType == LEVEL_OUTDOOR); render->uFogColor = GetLevelFogColor(); pOutdoor->Draw(); - } else { - Error("Invalid level type: %u", uCurrentlyLoadedLevelType); } decal_builder->DrawBloodsplats(); @@ -1748,7 +1747,7 @@ GameTime timeUntilDawn() { return GameTime::FromDays(1) + dawnHour - currentTimeInDay; } -void initLevelStrings(Blob &blob) { +void initLevelStrings(const Blob &blob) { engine->_levelStrings.clear(); int offs = 0; @@ -1761,12 +1760,7 @@ void initLevelStrings(Blob &blob) { } void Level_LoadEvtAndStr(const std::string &pLevelName) { - Blob blob = engine->_gameResourceManager->getEventsFile(pLevelName + ".str"); - if (!blob || (blob.size() > 9216)) { - Error("File %s Size %lu - Buffer size %lu", (pLevelName + ".str").c_str(), blob.size(), 9216); - } - - initLevelStrings(blob); + initLevelStrings(engine->_gameResourceManager->getEventsFile(pLevelName + ".str")); engine->_localEventMap = EventMap::load(engine->_gameResourceManager->getEventsFile(pLevelName + ".evt")); } diff --git a/src/Engine/Engine.h b/src/Engine/Engine.h index 2246170af39..a416d78323a 100644 --- a/src/Engine/Engine.h +++ b/src/Engine/Engine.h @@ -216,7 +216,7 @@ GameTime timeUntilDawn(); /** * @offset 0x443E31 */ -void initLevelStrings(Blob &blob); +void initLevelStrings(const Blob &blob); void Level_LoadEvtAndStr(const std::string &pLevelName); bool _44100D_should_alter_right_panel(); void Transition_StopSound_Autosave(const std::string &pMapName, MapStartPoint point); // sub_44987B idb diff --git a/src/Engine/ErrorHandling.cpp b/src/Engine/ErrorHandling.cpp deleted file mode 100644 index 8b5e376d457..00000000000 --- a/src/Engine/ErrorHandling.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "ErrorHandling.h" - -#include -#include -#include -#include -#include - -#include "Utility/Format.h" - -[[noreturn]] static void defaultErrorHandler(const std::string &title, const std::string &message) { - fmt::println(stderr, "{}", title); - fmt::println(stderr, "{}", message); - fmt::println(stderr, "Exiting..."); - assert(false); - exit(1); // TODO(captainurist): Redo. We should throw instead. -} - -ErrorHandlerFunction globalErrorHandler; - -void Error_impl_(const char *filename, const char *functionname, int line, const char *format, ...) { - char msg_body[8192] = { 0 }; - if (format != nullptr) { - va_list va; - va_start(va, format); - vsnprintf(msg_body, 8192, format, va); - va_end(va); - } - - std::stringstream out; - out << "Error in " << filename << ": "; - out << line << "\n\t" << functionname << "\n\n"; - if (strlen(msg_body) > 0) { - out << "\n\n" << msg_body; - } - - if (globalErrorHandler) - globalErrorHandler("Error", out.str()); - defaultErrorHandler("Error", out.str()); // Global handler shouldn't return. -} - -void setErrorHandler(ErrorHandlerFunction handler) { - globalErrorHandler = std::move(handler); -} diff --git a/src/Engine/ErrorHandling.h b/src/Engine/ErrorHandling.h deleted file mode 100644 index a7fccd39cd0..00000000000 --- a/src/Engine/ErrorHandling.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include -#include -#include - -#define Error(...) \ - do { \ - Error_impl_(__FILE__, __FUNCTION__, __LINE__ __VA_OPT__(,) __VA_ARGS__); /* NOLINT */ \ - } while (0) - -[[noreturn]] void Error_impl_(const char *filename, const char *functionname, int line, const char *format, ...); - -#ifndef _WINDOWS -# define __debugbreak(...) assert(false); -#endif - -using ErrorHandlerFunction = std::function; - -void setErrorHandler(ErrorHandlerFunction handler); diff --git a/src/Engine/Events/EventInterpreter.cpp b/src/Engine/Events/EventInterpreter.cpp index 7d4a58d69d1..2e99b0715c6 100644 --- a/src/Engine/Events/EventInterpreter.cpp +++ b/src/Engine/Events/EventInterpreter.cpp @@ -61,10 +61,9 @@ static bool checkSeason(Season season) { monthPlusOne == 6 && daysPlusOne <= 20); default: - Error("Unknown season"); + assert(false); + return false; } - - return false; } /** @@ -154,7 +153,7 @@ int EventInterpreter::executeOneEvent(int step, bool isNpc) { break; case EVENT_CanShowTopic_IsActorKilled: // TODO: enconunter and process - __debugbreak(); + assert(false); #if 0 if (Actor::isActorKilled(ir.data.actor_descr.policy, ir.data.actor_descr.param, ir.data.actor_descr.num)) { return ir.target_step; @@ -351,7 +350,7 @@ int EventInterpreter::executeOneEvent(int step, bool isNpc) { // // TODO(Nik-RE-dev): this event is not used in MM7. In GrayFace's data it's called "Question" and must have additional arguments // that control where events executions must be continued on correct/incorrect input. - __debugbreak(); + assert(false); #if 0 game_ui_status_bar_event_string = (ir.data.text_id < engine->_levelStrings.size()) ? engine->_levelStrings[ir.data.text_id] : ""; startBranchlessDialogue(_eventId, step + 1, EVENT_InputString); @@ -479,7 +478,7 @@ int EventInterpreter::executeOneEvent(int step, bool isNpc) { break; case EVENT_SetActorGroup: // TODO: enconunter and process - __debugbreak(); + assert(false); #if 0 *(&pActors[0].uGroup + 0x11000000 * _evt->v8 + 209 * (_evt->v5 + @@ -505,7 +504,7 @@ int EventInterpreter::executeOneEvent(int step, bool isNpc) { return -1; case EVENT_ChangeGroup: // TODO: enconunter and process - __debugbreak(); + assert(false); #if 0 v38 = EVT_DWORD(_evt->v5); v39 = EVT_DWORD(_evt->v9); @@ -517,7 +516,7 @@ int EventInterpreter::executeOneEvent(int step, bool isNpc) { break; case EVENT_ChangeGroupAlly: // TODO: enconunter and process - __debugbreak(); + assert(false); #if 0 v42 = EVT_DWORD(_evt->v5); v43 = EVT_DWORD(_evt->v9); diff --git a/src/Engine/GameResourceManager.cpp b/src/Engine/GameResourceManager.cpp index 1f55f2590e9..e9d928df0c4 100644 --- a/src/Engine/GameResourceManager.cpp +++ b/src/Engine/GameResourceManager.cpp @@ -12,6 +12,7 @@ void GameResourceManager::openGameResources() { // TODO(captainurist): // on exception: // Error(localization->GetString(LSTR_PLEASE_REINSTALL), localization->GetString(LSTR_REINSTALL_NECESSARY)); + // but we can't use localization object here cause it's not yet initialized. } Blob GameResourceManager::getEventsFile(const std::string &filename) { diff --git a/src/Engine/Graphics/Camera.cpp b/src/Engine/Graphics/Camera.cpp index 403241a34bb..b7cc641d901 100644 --- a/src/Engine/Graphics/Camera.cpp +++ b/src/Engine/Graphics/Camera.cpp @@ -2,7 +2,6 @@ #include "Engine/Engine.h" #include "Engine/OurMath.h" -#include "Engine/ErrorHandling.h" #include "Engine/Graphics/Indoor.h" #include "Engine/Graphics/Viewport.h" @@ -345,7 +344,7 @@ bool Camera3D::CullFaceToCameraFrustum(RenderVertexSoft *pInVertices, return true; } - __debugbreak(); + assert(false); return false; } @@ -384,7 +383,7 @@ bool Camera3D::CullFaceToFrustum(struct RenderVertexSoft *a1, unsigned int *pOut return true; } - __debugbreak(); + assert(false); return false; } diff --git a/src/Engine/Graphics/ClippingFunctions.cpp b/src/Engine/Graphics/ClippingFunctions.cpp index a866b91498d..2f80846c098 100644 --- a/src/Engine/Graphics/ClippingFunctions.cpp +++ b/src/Engine/Graphics/ClippingFunctions.cpp @@ -21,7 +21,7 @@ bool ClippingFunctions::ClipVertsToPortal(RenderVertexSoft *pPortalBounding, // RenderVertexSoft *v19 = nullptr; // [sp+14h] [bp-14h]@0 int v21; // [sp+1Ch] [bp-Ch]@7 - // __debugbreak(); + // assert(false); // thisa = this; @@ -281,7 +281,7 @@ bool ClippingFunctions::AdjustVertToClipEdge(RenderVertexSoft *a1, RenderVertexS char v15; // c3@24 float a1a; // [sp+10h] [bp+8h]@5 - // __debugbreak(); + // assert(false); static Vec3f static_AE3388; static Vec3f static_AE3378; diff --git a/src/Engine/Graphics/Indoor.cpp b/src/Engine/Graphics/Indoor.cpp index d817a279ef9..c6ec190f7c2 100644 --- a/src/Engine/Graphics/Indoor.cpp +++ b/src/Engine/Graphics/Indoor.cpp @@ -179,7 +179,7 @@ void BLVRenderParams::Reset() { this->uPartyEyeSectorID = pIndoor->GetSector(pParty->pos.toInt() + Vec3i(0, 0, pParty->eyeLevel)); if (!this->uPartySectorID) { - __debugbreak(); // shouldnt happen, please provide savegame + assert(false); // shouldnt happen, please provide savegame } @@ -300,22 +300,19 @@ void IndoorLocation::toggleLight(signed int sLightID, unsigned int bToggle) { void IndoorLocation::Load(const std::string &filename, int num_days_played, int respawn_interval_days, bool *indoor_was_respawned) { decal_builder->Reset(0); - if (bLoaded) - Error("BLV is already loaded"); + assert(!bLoaded); // BLV is already loaded! auto blv_filename = std::string(filename); blv_filename.replace(blv_filename.length() - 4, 4, ".blv"); this->filename = std::string(filename); - if (!pGames_LOD->exists(blv_filename)) - Error("Unable to find %s in Games.LOD", blv_filename.c_str()); Release(); bLoaded = true; IndoorLocation_MM7 location; - deserialize(lod::decodeCompressed(pGames_LOD->read(blv_filename)), &location); + deserialize(lod::decodeCompressed(pGames_LOD->read(blv_filename)), &location); // read throws if file doesn't exist. reconstruct(location, this); std::string dlv_filename = filename; @@ -378,7 +375,7 @@ int IndoorLocation::GetSector(int sX, int sY, int sZ) { return 0; if (pSectors.size() < 2) { - // __debugbreak(); + // assert(false); return 0; } @@ -463,7 +460,7 @@ int IndoorLocation::GetSector(int sX, int sY, int sZ) { // doesnt choose - so default to first - SHOULDNT GET HERE if (pSectorID == 0) { - __debugbreak(); + assert(false); pSectorID = this->pFaces[FoundFaceStore[0]].uSectorID; } } @@ -1107,7 +1104,7 @@ int BLV_GetFloorLevel(const Vec3i &pos, int uSectorID, int *pFaceID) { if (pFaceID) *pFaceID = blv_floor_id[0]; if (blv_floor_z[0] <= -29000) { - /*__debugbreak();*/ + /*assert(false);*/ } return blv_floor_z[0]; } @@ -1129,12 +1126,12 @@ int BLV_GetFloorLevel(const Vec3i &pos, int uSectorID, int *pFaceID) { if (std::abs(pos.z - v38) <= std::abs(pos.z - result)) { result = blv_floor_z[i]; - if (blv_floor_z[i] <= -29000) __debugbreak(); + if (blv_floor_z[i] <= -29000) assert(false); faceId = blv_floor_id[i]; } } - if (result <= -29000) __debugbreak(); + if (result <= -29000) assert(false); if (pFaceID) *pFaceID = faceId; @@ -1187,7 +1184,7 @@ void IndoorLocation::PrepareDecorationsRenderList_BLV(unsigned int uDecorationID v11 = pSpriteFrameTable->GetFrame(decoration->uSpriteID, v37 + v10); // error catching - if (v11->icon_name == "null") __debugbreak(); + if (v11->icon_name == "null") assert(false); v30 = 0; if (v11->uFlags & 2) v30 = 2; @@ -1226,7 +1223,7 @@ void IndoorLocation::PrepareDecorationsRenderList_BLV(unsigned int uDecorationID v11->hw_sprites[v9]; if (v11->hw_sprites[v9]->texture->height() == 0 || v11->hw_sprites[v9]->texture->width() == 0) - __debugbreak(); + assert(false); pBillboardRenderList[uNumBillboardsToDraw - 1].uPaletteIndex = v11->GetPaletteIndex(); pBillboardRenderList[uNumBillboardsToDraw - 1].uIndoorSectorID = @@ -1521,7 +1518,7 @@ void BLV_ProcessPartyActions() { // could this be combined with odm process act if (floorZ == -30000 || faceId == -1) { floorZ = GetApproximateIndoorFloorZ(pParty->pos.toInt() + Vec3i(0, 0, 40), §orId, &faceId); if (floorZ == -30000 || faceId == -1) { - __debugbreak(); // level built with errors + assert(false); // level built with errors return; } } @@ -1796,7 +1793,7 @@ void switchDoorAnimation(unsigned int uDoorID, int a2) { if (pIndoor->pDoors[door_id].uDoorID == uDoorID) break; } if (door_id >= 200) { - Error("Unable to find Door ID: %i!", uDoorID); + logger->error("Unable to find Door ID: {}!", uDoorID); } old_state = pIndoor->pDoors[door_id].uState; // old_state: 0 - в нижнем положении/закрыто diff --git a/src/Engine/Graphics/Level/Decoration.cpp b/src/Engine/Graphics/Level/Decoration.cpp index ec88a8fd3b8..cba0b390a32 100644 --- a/src/Engine/Graphics/Level/Decoration.cpp +++ b/src/Engine/Graphics/Level/Decoration.cpp @@ -6,6 +6,7 @@ #include "../../Party.h" #include "Engine/Engine.h" +#include "Library/Logger/Logger.h" #include "Library/Random/Random.h" std::vector pLevelDecorations; @@ -306,7 +307,8 @@ int LevelDecoration::GetGlobalEvent() { return 0; default: - Error("Invalid DecorationDescID: %u", uDecorationDescID); + logger->error("Invalid DecorationDescID: {}", uDecorationDescID); + return 0; } } diff --git a/src/Engine/Graphics/Outdoor.cpp b/src/Engine/Graphics/Outdoor.cpp index ae832a4b907..734d009bd77 100644 --- a/src/Engine/Graphics/Outdoor.cpp +++ b/src/Engine/Graphics/Outdoor.cpp @@ -715,7 +715,7 @@ int OutdoorLocationTerrain::_47CB57(unsigned char *pixels_8bit, int a2, result = 0; /*else { - __debugbreak(); + assert(false); v5 = PaletteManager::Get_Dark_or_Red_LUT(a2, 0, 1); v6 = 0.0; v22 = 0.0; @@ -845,9 +845,6 @@ void OutdoorLocation::Load(const std::string &filename, int days_played, int res // } //} - if (!pGames_LOD->exists(filename)) - Error("Unable to find %s in Games.LOD", filename.c_str()); - std::string minimap_filename = filename.substr(0, filename.length() - 4); if (viewparams->location_minimap) viewparams->location_minimap->Release(); @@ -857,7 +854,7 @@ void OutdoorLocation::Load(const std::string &filename, int days_played, int res odm_filename.replace(odm_filename.length() - 4, 4, ".odm"); OutdoorLocation_MM7 location; - deserialize(lod::decodeCompressed(pGames_LOD->read(odm_filename)), &location); + deserialize(lod::decodeCompressed(pGames_LOD->read(odm_filename)), &location); // read throws. reconstruct(location, this); // ****************.ddm file*********************// @@ -1363,7 +1360,7 @@ void OutdoorLocation::PrepareActorsDrawList() { // no sprite frame to draw if (frame->icon_name == "null") continue; if (frame->hw_sprites[Sprite_Octant]->texture->height() == 0 || frame->hw_sprites[Sprite_Octant]->texture->width() == 0) - __debugbreak(); + assert(false); int flags = 0; // v16 = (int *)frame->uFlags; @@ -2543,7 +2540,7 @@ Color GetLevelFogColor() { if (pWeather->bNight) { // night-time fog if (false) { logger->error("decompilation can be inaccurate, please send savegame to Nomad"); - __debugbreak(); + assert(false); } if (pWeather->bNight) { return colorTable.DarkGray; diff --git a/src/Engine/Graphics/Overlays.cpp b/src/Engine/Graphics/Overlays.cpp index 775797273c7..d933a8a0422 100644 --- a/src/Engine/Graphics/Overlays.cpp +++ b/src/Engine/Graphics/Overlays.cpp @@ -73,7 +73,7 @@ void ActiveOverlayList::DrawTurnBasedIcon() { frame = pIconsFrameTable->GetFrame(uIconID_TurnStop, pEventTimer->uStartTime); } else { - __debugbreak(); + assert(false); return; } // if ( render->pRenderD3D ) diff --git a/src/Engine/Graphics/PortalFunctions.cpp b/src/Engine/Graphics/PortalFunctions.cpp index e9f49591d74..058d956c293 100644 --- a/src/Engine/Graphics/PortalFunctions.cpp +++ b/src/Engine/Graphics/PortalFunctions.cpp @@ -1,7 +1,6 @@ #include "Engine/Graphics/PortalFunctions.h" #include "Engine/Engine.h" -#include "Engine/ErrorHandling.h" #include "Engine/Graphics/Camera.h" #include "Indoor.h" @@ -190,7 +189,8 @@ bool stru10::CalcFaceBounding(BLVFace *pFace, RenderVertexSoft *pFaceLimits, break; default: - Error("Invalid polygon type (%u)", pFace->uPolygonType); + assert(false); + return false; } float face_center_x = 0; diff --git a/src/Engine/Graphics/RenderBase.cpp b/src/Engine/Graphics/RenderBase.cpp index 6a7ed40022e..39c1788b68c 100644 --- a/src/Engine/Graphics/RenderBase.cpp +++ b/src/Engine/Graphics/RenderBase.cpp @@ -426,7 +426,7 @@ void RenderBase::TransformBillboard(const SoftwareBillboard *pSoftBillboard, con Sprite *pSprite = pBillboard->hwsprite; // error catching if (pSprite->texture->height() == 0 || pSprite->texture->width() == 0) - __debugbreak(); + assert(false); unsigned int billboard_index = Billboard_ProbablyAddToListAndSortByZOrder(pSoftBillboard->screen_space_z); RenderBillboardD3D *billboard = &pBillboardRenderListD3D[billboard_index]; @@ -778,7 +778,7 @@ void RenderBase::CreateZBuffer() { pActiveZBuffer = (int*)malloc(outputRender.w * outputRender.h * sizeof(int)); if (!pActiveZBuffer) - Error("Failed to create zbuffer"); + logger->error("Failed to create zbuffer"); ClearZBuffer(); } diff --git a/src/Engine/Graphics/Sprites.cpp b/src/Engine/Graphics/Sprites.cpp index ea39e2854e6..5b9e1327d21 100644 --- a/src/Engine/Graphics/Sprites.cpp +++ b/src/Engine/Graphics/Sprites.cpp @@ -37,7 +37,7 @@ void SpriteFrameTable::InitializeSprite(signed int uSpriteID) { if (uSpriteID <= pSpriteSFrames.size()) { if (uSpriteID >= 0) { uint iter_uSpriteID = uSpriteID; - //if (iter_uSpriteID == 603) __debugbreak(); + //if (iter_uSpriteID == 603) assert(false); int uFlags = pSpriteSFrames[iter_uSpriteID].uFlags; @@ -140,7 +140,7 @@ void SpriteFrameTable::InitializeSprite(signed int uSpriteID) { spriteName = fmt::format("{}{}", pSpriteSFrames[iter_uSpriteID].texture_name, i); } else { spriteName = pSpriteSFrames[iter_uSpriteID].texture_name; - // __debugbreak(); + // assert(false); } } @@ -187,7 +187,7 @@ SpriteFrame *SpriteFrameTable::GetFrame(int uSpriteID, int uTime) { // TODO(pskelton): investigate and fix properly - dragon breath is missing last two frames?? // quick fix so it doesnt return empty sprite while (v4->hw_sprites[0] == NULL) { - //__debugbreak(); + //assert(false); --v4; } diff --git a/src/Engine/Graphics/Texture_MM7.cpp b/src/Engine/Graphics/Texture_MM7.cpp index 953195c62c6..a2305255a5d 100644 --- a/src/Engine/Graphics/Texture_MM7.cpp +++ b/src/Engine/Graphics/Texture_MM7.cpp @@ -1,10 +1,5 @@ #include "Texture_MM7.h" -#include -#include - -#include "Engine/ErrorHandling.h" - void Texture_MM7::Release() { name.clear(); indexed = GrayscaleImage(); diff --git a/src/Engine/LodSpriteCache.cpp b/src/Engine/LodSpriteCache.cpp index f3f7c703ebb..21d309b39b3 100644 --- a/src/Engine/LodSpriteCache.cpp +++ b/src/Engine/LodSpriteCache.cpp @@ -53,7 +53,7 @@ Sprite *LodSpriteCache::loadSprite(const std::string &pContainerName) { if (!LoadSpriteFromFile(header.get(), pContainerName)) return nullptr; - // if (uNumLoadedSprites == 879) __debugbreak(); + // if (uNumLoadedSprites == 879) assert(false); Sprite &sprite = _sprites.emplace_back(); sprite.pName = pContainerName; diff --git a/src/Engine/MapInfo.cpp b/src/Engine/MapInfo.cpp index ec56ca0fe15..664248a51e0 100644 --- a/src/Engine/MapInfo.cpp +++ b/src/Engine/MapInfo.cpp @@ -3,8 +3,6 @@ #include #include -#include "Engine/ErrorHandling.h" - #include "Utility/Memory/Blob.h" #include "Utility/Workaround/ToUnderlying.h" #include "Utility/String.h" @@ -213,6 +211,6 @@ MapId MapStats::GetMapInfo(const std::string &Str2) { } } - Error("Map not found!"); + assert(false); return MAP_INVALID; } diff --git a/src/Engine/Objects/Actor.cpp b/src/Engine/Objects/Actor.cpp index b8ca1b347a8..c362db958df 100644 --- a/src/Engine/Objects/Actor.cpp +++ b/src/Engine/Objects/Actor.cpp @@ -785,7 +785,7 @@ void Actor::AI_RangedAttack(unsigned int uActorID, struct AIDirection *pDir, bool found = false; a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uType); if (a1.uObjectDescID == 0) { - Error("Item not found"); + logger->error("Item not found"); return; } a1.containing_item.Reset(); @@ -1090,7 +1090,7 @@ void Actor::AI_MeleeAttack(unsigned int uActorID, Pid sTargetPid, v7 = pParty->pos.y; v23 = pParty->pos.z + pParty->eyeLevel; } else { - Error("Should not get here"); + assert(false); return; } @@ -1328,7 +1328,7 @@ void Actor::AI_SpellAttack2(unsigned int uActorID, Pid edx0, v5 = pParty->pos.y; v21 = pParty->pos.z + pParty->eyeLevel; } else { - Error("Should not get here"); + assert(false); return; } v19 = v3->height; @@ -1401,7 +1401,7 @@ void Actor::AI_SpellAttack1(unsigned int uActorID, Pid sTargetPid, v5 = pParty->pos.y; v21 = pParty->pos.z + pParty->eyeLevel; } else { - Error("Should not get here"); + assert(false); return; } v19 = v3->height; @@ -1476,7 +1476,7 @@ void Actor::AI_MissileAttack2(unsigned int uActorID, Pid sTargetPid, v5 = pParty->pos.y; v20 = pParty->pos.z + pParty->eyeLevel; } else { - Error("Should not get here"); + assert(false); return; } v18 = v3->height; @@ -4426,7 +4426,7 @@ void SpawnEncounter(MapInfo *pMapInfo, SpawnPoint *spawn, int a3, int a4, int a5 v57 += a3; - // if (v57 == 4) __debugbreak(); + // if (v57 == 4) assert(false); if (v57 > 3) v57 = 3; Str2 = Source; diff --git a/src/Engine/Objects/Character.cpp b/src/Engine/Objects/Character.cpp index 5672f3a5383..09978f7ff0b 100644 --- a/src/Engine/Objects/Character.cpp +++ b/src/Engine/Objects/Character.cpp @@ -43,6 +43,7 @@ #include "GUI/UI/Books/AutonotesBook.h" #include "Library/Random/Random.h" +#include "Library/Logger/Logger.h" #include "Utility/Memory/MemSet.h" #include "Utility/Math/FixPoint.h" @@ -2119,22 +2120,16 @@ float Character::GetArmorRecoveryMultiplierFromSkillLevel(CharacterSkillType arm switch (skillMastery) { case CHARACTER_SKILL_MASTERY_NOVICE: return mult1; - break; case CHARACTER_SKILL_MASTERY_EXPERT: return mult2; - break; case CHARACTER_SKILL_MASTERY_MASTER: return mult3; - break; case CHARACTER_SKILL_MASTERY_GRANDMASTER: return mult4; - break; default: - break; + assert(false); + return 0; } - - Error("Unexpected input value: %d", armour_skill_type); - return 0; } //----- (0048E4F8) -------------------------------------------------------- @@ -2294,7 +2289,8 @@ int Character::GetBaseResistance(CharacterAttributeType a2) const { if (IsRaceHuman()) racialBonus = 5; break; default: - Error("Unknown attribute"); + assert(false); + return 0; } v7 = GetItemsBonus(a2) + racialBonus; result = v7 + *resStat; @@ -2344,7 +2340,8 @@ int Character::GetActualResistance(CharacterAttributeType resistance) const { resStat = &sResBodyBonus; break; default: - Error("Unexpected attribute"); + assert(false); + return 0; } baseRes = GetBaseResistance(resistance); result = v10 + GetMagicalBonus(resistance) + baseRes + *(resStat); @@ -3154,8 +3151,6 @@ unsigned int Character::GetMultiplierForSkillLevel( int mult4) const { // TODO(pskelton): ?? needs changing - check behavious CharacterSkillMastery masteryLvl = getActualSkillValue(uSkillType).mastery(); switch (masteryLvl) { - case CHARACTER_SKILL_MASTERY_NONE: - return 0; case CHARACTER_SKILL_MASTERY_NOVICE: return mult1; case CHARACTER_SKILL_MASTERY_EXPERT: @@ -3164,9 +3159,9 @@ unsigned int Character::GetMultiplierForSkillLevel( return mult3; case CHARACTER_SKILL_MASTERY_GRANDMASTER: return mult4; + default: + return 0; } - Error("(%u)", masteryLvl); - return 0; } //----- (00490109) -------------------------------------------------------- @@ -3204,7 +3199,7 @@ std::string Character::GetRaceName() const { case RACE_GOBLIN: return localization->GetString(LSTR_RACE_GOBLIN); case RACE_DWARF: return localization->GetString(LSTR_RACE_DWARF); default: - __debugbreak(); + assert(false); return std::string(); // Make the compiler happy. } } @@ -3239,9 +3234,11 @@ CharacterSex Character::GetSexByVoice() const { case 0x15u: case 0x18u: return SEX_FEMALE; + + default: + assert(false); + return SEX_MALE; } - Error("(%u)", this->uVoiceID); - return SEX_MALE; } //----- (00490188) -------------------------------------------------------- @@ -3288,7 +3285,7 @@ void Character::SetSexByVoice() { this->uSex = SEX_FEMALE; break; default: - Error("(%u)", this->uVoiceID); + assert(false); break; } } @@ -3448,8 +3445,8 @@ void Character::IncreaseAttribute(CharacterAttributeType eAttribute) { statToChange = &this->uLuck; break; default: - Error("(%u)", eAttribute); - break; + assert(false); + return; } if (*statToChange < baseValue) { tmp = baseStep; @@ -3533,7 +3530,8 @@ Color Character::GetStatColor(CharacterAttributeType uStat) const { attribute_value = uLuck; break; default: - Error("Unexpected attribute"); + assert(false); + return Color(); } if (attribute_value == base_attribute_value) @@ -4249,7 +4247,7 @@ bool Character::CompareVariable(VariableType VarNum, int pValue) { case VAR_DarkResistance: return this->sResDarkBase >= pValue; case VAR_PhysicalResistance: - Error("Physical resistance isn't used in events"); + logger->error("Physical resistance isn't used in events"); return false; case VAR_MagicResistance: return this->sResMagicBase >= pValue; @@ -4330,9 +4328,9 @@ bool Character::CompareVariable(VariableType VarNum, int pValue) { case VAR_DiplomacySkill: return CmpSkillValue(pValue, this->pActiveSkills[CHARACTER_SKILL_DIPLOMACY]); case VAR_ThieverySkill: - //Error("Thievery isn't used in events"); - //return false; - return CmpSkillValue(pValue, this->pActiveSkills[CHARACTER_SKILL_THIEVERY]); // wasn't in the original + // Original binary had this: + // Error("Thievery isn't used in events"); + return CmpSkillValue(pValue, this->pActiveSkills[CHARACTER_SKILL_THIEVERY]); case VAR_DisarmTrapSkill: // wasn't in the original return CmpSkillValue(pValue, this->pActiveSkills[CHARACTER_SKILL_TRAP_DISARM]); case VAR_DodgeSkill: // wasn't in the original @@ -4809,7 +4807,7 @@ void Character::SetVariable(VariableType var_type, signed int var_value) { PlayAwardSound_Anim_Face(SPEECH_STAT_BONUS_INC); return; case VAR_PhysicalResistanceBonus: - Error("Physical res. bonus not used"); + logger->error("Physical res. bonus not used"); return; case VAR_MagicResistanceBonus: this->sResMagicBonus = (uint8_t)var_value; @@ -5066,7 +5064,7 @@ void Character::SetVariable(VariableType var_type, signed int var_value) { SetSkillReaction(); return; case VAR_ThieverySkill: - Error("Thieving unsupported"); + logger->error("Thieving unsupported"); return; case VAR_DisarmTrapSkill: pActiveSkills[CHARACTER_SKILL_TRAP_DISARM] = CombinedSkillValue::fromJoined(var_value); @@ -5651,7 +5649,7 @@ void Character::AddVariable(VariableType var_type, signed int val) { PlayAwardSound_Anim97(); return; case VAR_ThieverySkill: - Error("Thieving unsupported"); + logger->error("Thieving unsupported"); return; case VAR_DisarmTrapSkill: AddSkillByEvent(CHARACTER_SKILL_TRAP_DISARM, val); @@ -6074,7 +6072,7 @@ void Character::SubtractVariable(VariableType VarNum, signed int pValue) { PlayAwardSound_AnimSubtract(); return; case VAR_ThieverySkill: - Error("Thieving unsupported"); + logger->error("Thieving unsupported"); return; case VAR_DisarmTrapSkill: SubtractSkillByEvent(CHARACTER_SKILL_TRAP_DISARM, pValue); @@ -6436,9 +6434,9 @@ void DamageCharacterFromMonster(Pid uObjID, ABILITY_INDEX dmgSource, Vec3i *pPos if (pidtype != OBJECT_Item) { // not an item // hit by monster - if (pidtype != OBJECT_Actor) __debugbreak(); + if (pidtype != OBJECT_Actor) assert(false); - if (targetchar == -1) __debugbreak(); + if (targetchar == -1) assert(false); unsigned int uActorID = uObjID.id(); @@ -6462,41 +6460,9 @@ void DamageCharacterFromMonster(Pid uObjID, ABILITY_INDEX dmgSource, Vec3i *pPos if (!equippedArmor || equippedArmor->IsBroken() || (equippedArmor->GetPlayerSkillType() != CHARACTER_SKILL_CHAIN && equippedArmor->GetPlayerSkillType() != CHARACTER_SKILL_PLATE)) { - int randVal = vrng->random(4); - switch (randVal) { - case 0: - soundToPlay = SOUND_dull_armor_strike1; - break; - case 1: - soundToPlay = SOUND_dull_armor_strike2; - break; - case 2: - soundToPlay = SOUND_dull_armor_strike3; - break; - case 3: - soundToPlay = SOUND_dull_strike; - break; - default: - Error("Unexpected sound value"); - } + soundToPlay = vrng->randomSample({SOUND_dull_armor_strike1, SOUND_dull_armor_strike2, SOUND_dull_armor_strike3, SOUND_dull_strike}); } else { - int randVal = vrng->random(4); - switch (randVal) { - case 0: - soundToPlay = SOUND_metal_armor_strike1; - break; - case 1: - soundToPlay = SOUND_metal_armor_strike2; - break; - case 2: - soundToPlay = SOUND_metal_armor_strike3; - break; - case 3: - soundToPlay = SOUND_metal_vs_metal01h; - break; - default: - Error("Unexpected sound value"); - } + soundToPlay = vrng->randomSample({SOUND_metal_armor_strike1, SOUND_metal_armor_strike2, SOUND_metal_armor_strike3, SOUND_metal_vs_metal01h}); } // TODO(Nik-RE-dev): is it correct to use voice volume for strike sounds? pAudioPlayer->playSound(soundToPlay, SOUND_MODE_PID, Pid(OBJECT_Character, targetchar)); @@ -7420,12 +7386,10 @@ bool Character::isClass(CharacterClass class_type, bool check_honorary) const { return _achievedAwardsBits[Award_Promotion_Archmage_Honorary]; case CLASS_LICH: return _achievedAwardsBits[Award_Promotion_Lich_Honorary]; - break; default: - Error("Should not be able to get here (%u)", class_type); - break; + assert(false); // TODO(captainurist): just implement properly? + return false; } - return false; } //----- (00490EEE) -------------------------------------------------------- @@ -7469,7 +7433,7 @@ MerchantPhrase Character::SelectPhrasesTransaction(ItemGen *pItem, BuildingType return MERCHANT_PHRASE_INCOMPATIBLE_ITEM; break; default: - Error("(%u)", building_type); + assert(false); break; } if (pItem->IsStolen()) @@ -7493,7 +7457,7 @@ MerchantPhrase Character::SelectPhrasesTransaction(ItemGen *pItem, BuildingType price = PriceCalculator::itemRepairPriceForPlayer(this, itemValue, multiplier); break; default: - Error("(%u)", ShopMenuType); + assert(false); break; } if (merchantLevel) { diff --git a/src/Engine/Objects/Character.h b/src/Engine/Objects/Character.h index 303993f8f9c..1d2337dbe7e 100644 --- a/src/Engine/Objects/Character.h +++ b/src/Engine/Objects/Character.h @@ -16,7 +16,6 @@ #include "Engine/Spells/SpellBuff.h" #include "Engine/Tables/BuildingTable.h" #include "Engine/Events/EventEnums.h" -#include "Engine/ErrorHandling.h" #include "Engine/Pid.h" #include "GUI/GUIEnums.h" @@ -532,41 +531,40 @@ class Character { inline CharacterExpressionID expressionForCondition(Condition condition) { switch (condition) { - case CONDITION_DEAD: - return CHARACTER_EXPRESSION_DEAD; - case CONDITION_PETRIFIED: - return CHARACTER_EXPRESSION_PETRIFIED; - case CONDITION_ERADICATED: - return CHARACTER_EXPRESSION_ERADICATED; - case CONDITION_CURSED: + case CONDITION_CURSED: return CHARACTER_EXPRESSION_CURSED; - case CONDITION_WEAK: + case CONDITION_WEAK: return CHARACTER_EXPRESSION_WEAK; - case CONDITION_SLEEP: + case CONDITION_SLEEP: return CHARACTER_EXPRESSION_SLEEP; - case CONDITION_FEAR: + case CONDITION_FEAR: return CHARACTER_EXPRESSION_FEAR; - case CONDITION_DRUNK: + case CONDITION_DRUNK: return CHARACTER_EXPRESSION_DRUNK; - case CONDITION_INSANE: + case CONDITION_INSANE: return CHARACTER_EXPRESSION_INSANE; - case CONDITION_POISON_WEAK: - case CONDITION_POISON_MEDIUM: - case CONDITION_POISON_SEVERE: + case CONDITION_POISON_WEAK: + case CONDITION_POISON_MEDIUM: + case CONDITION_POISON_SEVERE: return CHARACTER_EXPRESSION_POISONED; - case CONDITION_DISEASE_WEAK: - case CONDITION_DISEASE_MEDIUM: - case CONDITION_DISEASE_SEVERE: + case CONDITION_DISEASE_WEAK: + case CONDITION_DISEASE_MEDIUM: + case CONDITION_DISEASE_SEVERE: return CHARACTER_EXPRESSION_DISEASED; - case CONDITION_PARALYZED: + case CONDITION_PARALYZED: return CHARACTER_EXPRESSION_PARALYZED; - case CONDITION_UNCONSCIOUS: + case CONDITION_UNCONSCIOUS: return CHARACTER_EXPRESSION_UNCONCIOUS; - default: - Error("Invalid condition: %u", condition); + case CONDITION_DEAD: + return CHARACTER_EXPRESSION_DEAD; + case CONDITION_PETRIFIED: + return CHARACTER_EXPRESSION_PETRIFIED; + case CONDITION_ERADICATED: + return CHARACTER_EXPRESSION_ERADICATED; + default: // CONDITION_ZOMBIE & CONDITION_GOOD are handled externally. + assert(false); + return CHARACTER_EXPRESSION_NORMAL; } - - return CHARACTER_EXPRESSION_NORMAL; } void DamageCharacterFromMonster(Pid uObjID, ABILITY_INDEX dmgSource, Vec3i *pPos, signed int a4); diff --git a/src/Engine/Objects/Monsters.cpp b/src/Engine/Objects/Monsters.cpp index 0239b553f28..cb65e892733 100644 --- a/src/Engine/Objects/Monsters.cpp +++ b/src/Engine/Objects/Monsters.cpp @@ -3,8 +3,6 @@ #include #include -#include "Engine/ErrorHandling.h" - #include "../Tables/FrameTableInc.h" #include "Library/Logger/Logger.h" @@ -976,5 +974,6 @@ MonsterId MonsterList::GetMonsterIDByName(const std::string &pMonsterName) { if (iequals(pMonsters[i].pMonsterName, pMonsterName)) return i; } - Error("Monster not found: %s", pMonsterName.c_str()); + logger->error("Monster not found: {}", pMonsterName); + return MONSTER_INVALID; } diff --git a/src/Engine/SaveLoad.cpp b/src/Engine/SaveLoad.cpp index 13fd92c94d9..92b35482492 100644 --- a/src/Engine/SaveLoad.cpp +++ b/src/Engine/SaveLoad.cpp @@ -68,7 +68,7 @@ void LoadGame(unsigned int uSlot) { std::error_code ec; if (!std::filesystem::copy_file(filename, to_file_path, std::filesystem::copy_options::overwrite_existing, ec)) - Error("Failed to copy: %s", filename.c_str()); + logger->error("Failed to copy: {}", filename); pSave_LOD->open(to_file_path, LOD_ALLOW_DUPLICATES); @@ -109,7 +109,7 @@ void LoadGame(unsigned int uSlot) { .uItemID; if (pItemTable->pItems[pItemID].uEquipType == ITEM_TYPE_WAND && pItemID) { // жезл - __debugbreak(); // looks like offset in player's inventory + assert(false); // looks like offset in player's inventory // and wand_lut much like case in 0042ECB5 stru_A750F8[i].AddPartySpellSound( wand_spell_ids[pItemID], i + 9); @@ -126,7 +126,7 @@ void LoadGame(unsigned int uSlot) { pEventTimer->StopGameTime(); if (!pGames_LOD->exists(header.locationName)) { - Error("Unable to find: %s!", header.locationName.c_str()); + logger->error("Unable to find: {}!", header.locationName); } pCurrentMapName = header.locationName; @@ -279,7 +279,7 @@ void DoSavegame(unsigned int uSlot) { std::string dst = makeDataPath("saves", fmt::format("save{:03}.mm7", uSlot)); std::error_code ec; if (!std::filesystem::copy_file(src, dst, std::filesystem::copy_options::overwrite_existing, ec)) - Error("Failed to copy: %s", src.c_str()); + logger->error("Failed to copy: {}", src); } pSavegameList->selectedSlot = uSlot; diff --git a/src/Engine/SpellFxRenderer.cpp b/src/Engine/SpellFxRenderer.cpp index ba60c7fcbea..ae7c4f3821b 100644 --- a/src/Engine/SpellFxRenderer.cpp +++ b/src/Engine/SpellFxRenderer.cpp @@ -660,7 +660,7 @@ bool SpellFxRenderer::RenderAsSprite(SpriteObject *a2) { // int v19; // eax@141 // int v20; // eax@151 - // __debugbreak(); // need to refactor carefully & collect data + // assert(false); // need to refactor carefully & collect data // v2 = this; result = a2->uType; @@ -741,7 +741,7 @@ bool SpellFxRenderer::RenderAsSprite(SpriteObject *a2) { return false; case SPRITE_OBJECT_EXPLODE_IMPACT: - // __debugbreak(); // what kind of effect is this? + // assert(false); // what kind of effect is this? AddMobileLight(a2, colorTable.OrangeyRed, 256); return true; @@ -1381,7 +1381,7 @@ int SpellFX_Billboard::SpellFXNearClipAdjust(float NearClip) { // near clip adj //----- (00477927) -------------------------------------------------------- int SpellFX_Billboard::SpellFXFarClipAdjust(float farclip) { // far clip adjust - needs diffuse sorting properly?? // refactored but not tested - // __debugbreak(); + // assert(false); if (!uNumVertices) return 0; diff --git a/src/Engine/Spells/CastSpellInfo.cpp b/src/Engine/Spells/CastSpellInfo.cpp index f7457feddd7..f5719e7dec0 100644 --- a/src/Engine/Spells/CastSpellInfo.cpp +++ b/src/Engine/Spells/CastSpellInfo.cpp @@ -711,7 +711,7 @@ void CastSpellInfoHelpers::castSpell() { item->special_enchantment = ITEM_ENCHANTMENT_OF_INFERNOS; break; default: - __debugbreak(); + assert(false); } item->uAttributes |= ITEM_AURA_EFFECT_RED; @@ -721,7 +721,7 @@ void CastSpellInfoHelpers::castSpell() { item->uAttributes |= ITEM_AURA_EFFECT_PURPLE; break; default: - __debugbreak(); + assert(false); } if (spell_mastery < CHARACTER_SKILL_MASTERY_GRANDMASTER) { @@ -1397,7 +1397,7 @@ void CastSpellInfoHelpers::castSpell() { // also see STDITEMS.tx and SPCITEMS.txt in Events.lod if ((spell_mastery == CHARACTER_SKILL_MASTERY_NOVICE || spell_mastery == CHARACTER_SKILL_MASTERY_EXPERT)) { - __debugbreak(); // SPELL_WATER_ENCHANT_ITEM is a master level spell + assert(false); // SPELL_WATER_ENCHANT_ITEM is a master level spell } if ((spell_mastery == CHARACTER_SKILL_MASTERY_MASTER || spell_mastery == CHARACTER_SKILL_MASTERY_GRANDMASTER) && diff --git a/src/Engine/Tables/ItemTable.cpp b/src/Engine/Tables/ItemTable.cpp index f9ee7923f1b..fa7691ac5a5 100644 --- a/src/Engine/Tables/ItemTable.cpp +++ b/src/Engine/Tables/ItemTable.cpp @@ -467,7 +467,7 @@ void ItemTable::generateItem(ItemTreasureLevel treasure_level, RandomItemType uT requested_equip = ITEM_TYPE_GEM; break; default: - __debugbreak(); // check this condition + assert(false); // check this condition // TODO(captainurist): explore requested_equip = static_cast(std::to_underlying(uTreasureType) - 1); break; diff --git a/src/Engine/Tables/TileTable.cpp b/src/Engine/Tables/TileTable.cpp index cd325166260..6a17cb44c36 100644 --- a/src/Engine/Tables/TileTable.cpp +++ b/src/Engine/Tables/TileTable.cpp @@ -1,7 +1,5 @@ #include "TileTable.h" -#include "Engine/ErrorHandling.h" - #include "Engine/AssetsManager.h" #include "Library/Random/Random.h" diff --git a/src/Engine/mm7text_ru.cpp b/src/Engine/mm7text_ru.cpp index 559ea583d0c..0fd7e43091a 100644 --- a/src/Engine/mm7text_ru.cpp +++ b/src/Engine/mm7text_ru.cpp @@ -1,9 +1,8 @@ +#include #include #include #include -#include "Engine/ErrorHandling.h" - #include "Library/Logger/Logger.h" #ifdef _WINDOWS @@ -758,7 +757,7 @@ int sprintfex_internal(char *str) { actual_ending = ending3; actual_ending_len = src - ending3 - 1; } else { - Error("Invalid gender token"); + logger->error("Invalid gender token"); } strncpy(dst, actual_ending, actual_ending_len); @@ -841,7 +840,7 @@ int sprintfex_internal(char *str) { strncpy(token, token_begin, token_len); token[token_len] = 0; - Error("Invalid format token: %s", token); + logger->error("Invalid format token: {}", token); } break; } diff --git a/src/GUI/GUIFont.cpp b/src/GUI/GUIFont.cpp index 4acbfa88a7e..c4e0cb31ffc 100644 --- a/src/GUI/GUIFont.cpp +++ b/src/GUI/GUIFont.cpp @@ -5,7 +5,6 @@ #include "Engine/AssetsManager.h" #include "Engine/Engine.h" -#include "Engine/ErrorHandling.h" #include "Engine/LodTextureCache.h" #include "Engine/Graphics/IRender.h" @@ -15,6 +14,8 @@ #include "GUI/GUIWindow.h" +#include "Library/Logger/Logger.h" + void ReloadFonts() { if (assets->pFontBookOnlyShadow) assets->pFontBookOnlyShadow->CreateFontTex(); @@ -62,7 +63,7 @@ std::unique_ptr GUIFont::LoadFont(const std::string &pFontFile, const s Texture_MM7 *pallete_texture = pIcons_LOD->loadTexture(pFontPalette); if (!pallete_texture) { - Error("Unable to open %s", pFontPalette.c_str()); + logger->error("Unable to open {}", pFontPalette); } pFont->pData->pFontPalettes[0] = pallete_texture->palette; diff --git a/src/GUI/GUIProgressBar.cpp b/src/GUI/GUIProgressBar.cpp index 485f1e24bd6..c141efe7c05 100644 --- a/src/GUI/GUIProgressBar.cpp +++ b/src/GUI/GUIProgressBar.cpp @@ -30,18 +30,9 @@ bool GUIProgressBar::Initialize(Type type) { Release(); - switch (type) { - case TYPE_None: - return true; - - case TYPE_Box: - case TYPE_Fullscreen: - break; - - default: - Error("Invalid GUIProgressBar type: %u", type); - } - + if (type == TYPE_None) + return true; + assert(type == TYPE_Box || type == TYPE_Fullscreen); uType = type; if (uType == TYPE_Fullscreen) { diff --git a/src/GUI/GUIWindow.cpp b/src/GUI/GUIWindow.cpp index 644a468e0e7..ca98459e886 100644 --- a/src/GUI/GUIWindow.cpp +++ b/src/GUI/GUIWindow.cpp @@ -553,7 +553,7 @@ void GUI_UpdateWindows() { } // should never activte this - gameui window should always be open - if (lWindowList.size() < 1) __debugbreak(); + if (lWindowList.size() < 1) assert(false); std::list tmpWindowList(lWindowList); tmpWindowList.reverse(); // new windows are push front - but front should be drawn last?? testing @@ -832,7 +832,7 @@ void SetUserInterface(PartyAlignment align, bool bReplace) { uGameUIFontMain = colorTable.MediumBlue; uGameUIFontShadow = colorTable.White; } else { - Error("Invalid alignment type: %u", align); + assert(false); } } @@ -1066,7 +1066,7 @@ std::string BuildDialogueString(const std::string &str, uint8_t uPlayerID, ItemG case 30: if (!a6) { // result += eventId; - __debugbreak(); // should never get here? + assert(false); // should never get here? break; } v56.Initialize(*a6); @@ -1092,7 +1092,7 @@ std::string BuildDialogueString(const std::string &str, uint8_t uPlayerID, ItemG } if (mask - 51 >= 20) { // result += eventId; - __debugbreak(); // should never get here? + assert(false); // should never get here? break; } diff --git a/src/GUI/UI/Houses/MercenaryGuild.cpp b/src/GUI/UI/Houses/MercenaryGuild.cpp index a04f7dfb775..ff354e4dea3 100644 --- a/src/GUI/UI/Houses/MercenaryGuild.cpp +++ b/src/GUI/UI/Houses/MercenaryGuild.cpp @@ -46,14 +46,14 @@ void GUIWindow_MercenaryGuild::houseSpecificDialogue() { } if (checkIfPlayerCanInteract()) { - __debugbreak(); // what type of house that even is? + assert(false); // what type of house that even is? // pSkillAvailabilityPerClass[8 + v58->uClass][4 + v23] // or // skillMaxMasteryPerClass[v58->uClass][v23 - 36] // or // skillMaxMasteryPerClass[v58->uClass - 1][v23 + // 1] - __debugbreak(); // whacky condition - fix + assert(false); // whacky condition - fix short *v6; if (false // if ( !*(&byte_4ED94C[37 * v1->uClass / 3] + dword_F8B19C) diff --git a/src/GUI/UI/NPCTopics.cpp b/src/GUI/UI/NPCTopics.cpp index f7fdee277f7..9dde6692968 100644 --- a/src/GUI/UI/NPCTopics.cpp +++ b/src/GUI/UI/NPCTopics.cpp @@ -673,7 +673,7 @@ DIALOGUE_TYPE handleScriptedNPCTopicSelection(DIALOGUE_TYPE topic, NPCData *npcD if (eventId == 311) { // Original code also listed this event which presumably opened bounty dialogue but MM7 // use event 311 for some teleport in Bracada - __debugbreak(); + assert(false); return DIALOGUE_MAIN; } diff --git a/src/GUI/UI/UICharacter.cpp b/src/GUI/UI/UICharacter.cpp index 6f779c2495e..2ee7bb5c905 100644 --- a/src/GUI/UI/UICharacter.cpp +++ b/src/GUI/UI/UICharacter.cpp @@ -675,7 +675,7 @@ void GUIWindow_CharacterRecord::Update() { break; } default: - __debugbreak(); + assert(false); break; } @@ -1227,17 +1227,17 @@ void CharacterUI_DrawPaperdoll(Character *player) { case ITEM_SPELLBOOK_TORCH_LIGHT: // Mordred item_X = 596; item_Y = 86; - __debugbreak(); + assert(false); break; case ITEM_SPELLBOOK_FIRE_AURA: // Excalibur item_X = 596; item_Y = 28; - __debugbreak(); + assert(false); break; case ITEM_SPELLBOOK_JUMP: // Hades item_X = 595; item_Y = 33; - __debugbreak(); + assert(false); break; default: break; @@ -1314,7 +1314,7 @@ static void CharacterUI_DrawItem(int x, int y, ItemGen *item, int id, GraphicsIm else if (item->AuraEffectPurple()) enchantment_texture = assets->getImage_ColorKey("sp91a"); else - __debugbreak(); + assert(false); ItemEnchantmentTimer -= pEventTimer->uTimeElapsed; if (ItemEnchantmentTimer <= 0) { diff --git a/src/GUI/UI/UIGame.cpp b/src/GUI/UI/UIGame.cpp index 1ba84639161..94d9c2d0733 100644 --- a/src/GUI/UI/UIGame.cpp +++ b/src/GUI/UI/UIGame.cpp @@ -1194,7 +1194,7 @@ void GameUI_WritePointedObjectStatusString() { break; case 3: // is this one needed? - __debugbreak(); // how does this work? + assert(false); // how does this work? /* if (pX >= pButton->uX && pX <= pButton->uZ && pY >= pButton->uY && pY <= pButton->uW) @@ -1779,8 +1779,10 @@ Color GetConditionDrawColor(Condition uConditionIdx) { case CONDITION_PETRIFIED: case CONDITION_ERADICATED: return ui_character_condition_severe_color; + default: + assert(false); + return Color(); } - Error("Invalid condition (%u)", uConditionIdx); } //----- (00495430) -------------------------------------------------------- diff --git a/src/GUI/UI/UIInventory.cpp b/src/GUI/UI/UIInventory.cpp index 88d28d4ecb3..78b2b80e5ab 100644 --- a/src/GUI/UI/UIInventory.cpp +++ b/src/GUI/UI/UIInventory.cpp @@ -21,7 +21,7 @@ void GUIWindow_Inventory::Update() { // a hack to capture end of user input (enter) while avoiding listening to UI message handler // redo this in a more clean way - __debugbreak(); + assert(false); // if (userInputHandler->inputType == TextInputType::None) { // ItemGen ItemGen2; diff --git a/src/GUI/UI/UIPartyCreation.cpp b/src/GUI/UI/UIPartyCreation.cpp index 3a686e9daed..01d151d879e 100644 --- a/src/GUI/UI/UIPartyCreation.cpp +++ b/src/GUI/UI/UIPartyCreation.cpp @@ -24,6 +24,7 @@ #include "Media/Audio/AudioPlayer.h" #include "Library/Random/Random.h" +#include "Library/Logger/Logger.h" using Io::TextInputType; @@ -305,7 +306,9 @@ void GUIWindow_PartyCreation::Update() { pX = 488; break; default: - Error("Invalid selected character"); + assert(false); + pX = 0; + break; } pTextCenter = ui_partycreation_font->AlignText_Center( @@ -804,7 +807,8 @@ bool PartyCreationUI_LoopInternal() { pParty->pCharacters[i].AddItem(-1, ITEM_MACE); break; case CHARACTER_SKILL_BLASTER: - Error("No blasters at startup :p"); + logger->error("No blasters at startup :p"); + break; case CHARACTER_SKILL_SHIELD: pParty->pCharacters[i].AddItem(-1, ITEM_WOODEN_BUCKLER); break; @@ -847,8 +851,10 @@ bool PartyCreationUI_LoopInternal() { break; case CHARACTER_SKILL_LIGHT: case CHARACTER_SKILL_DARK: + logger->error("No light/dark magic at startup"); + break; case CHARACTER_SKILL_DIPLOMACY: - Error("No dimoplacy in mm7 (yet)"); + logger->error("No diplomacy in mm7 (yet)"); break; case CHARACTER_SKILL_ITEM_ID: case CHARACTER_SKILL_REPAIR: diff --git a/src/GUI/UI/UIPopup.cpp b/src/GUI/UI/UIPopup.cpp index 484db5aef0e..d70b5ce1829 100644 --- a/src/GUI/UI/UIPopup.cpp +++ b/src/GUI/UI/UIPopup.cpp @@ -2438,7 +2438,7 @@ Color GetSpellColor(signed int a1) { if (a1 < 100) return colorTable.MoonRaker; else - __debugbreak(); + assert(false); logger->warning("No color returned - GetSpellColor!"); return colorTable.White; diff --git a/src/GUI/UI/UITransition.cpp b/src/GUI/UI/UITransition.cpp index 07856e98b89..5edb1a47e48 100644 --- a/src/GUI/UI/UITransition.cpp +++ b/src/GUI/UI/UITransition.cpp @@ -24,6 +24,8 @@ #include "Media/Audio/AudioPlayer.h" #include "Media/MediaPlayer.h" +#include "Library/Logger/Logger.h" + GraphicsImage *transition_ui_icon = nullptr; std::string transition_button_label; @@ -224,6 +226,6 @@ void GUIWindow_Transition::Update() { unsigned int vertMargin = (212 - assets->pFontCreate->CalcTextHeight(str, transition_window.uFrameWidth, 0)) / 2 + 101; transition_window.DrawTitleText(assets->pFontCreate.get(), 0, vertMargin, colorTable.White, str, 3); } else { - Error("Troubles in da house"); + logger->error("Troubles in da house"); } } diff --git a/src/Media/Audio/OpenALSoundProvider.cpp b/src/Media/Audio/OpenALSoundProvider.cpp index 67cab352448..ecd7a676bd6 100644 --- a/src/Media/Audio/OpenALSoundProvider.cpp +++ b/src/Media/Audio/OpenALSoundProvider.cpp @@ -19,7 +19,6 @@ #include #include -#include "Engine/ErrorHandling.h" #include "Library/Logger/Logger.h" #include "Media/MediaPlayer.h" @@ -217,7 +216,7 @@ OpenALSoundProvider::CreateStreamingTrack16(int num_channels, int sample_rate, break; } } - Error("Unsupported number of audio channels: %u", num_channels); + logger->error("Unsupported number of audio channels: {}", num_channels); } unsigned int al_source = -1; @@ -307,7 +306,7 @@ OpenALSoundProvider::TrackBuffer *OpenALSoundProvider::CreateTrack16( break; } } - Error("Unsupported number of audio channels: %u", num_channels); + logger->error("Unsupported number of audio channels: {}", num_channels); } } @@ -724,7 +723,7 @@ bool OpenALAudioDataSource::Open() { break; } } - Error("Unsupported number of audio channels: %u", num_channels); + logger->error("Unsupported number of audio channels: {}", num_channels); } while (true) { diff --git a/src/Media/MediaPlayer.cpp b/src/Media/MediaPlayer.cpp index 34c1592905d..eb7c2b5dac7 100644 --- a/src/Media/MediaPlayer.cpp +++ b/src/Media/MediaPlayer.cpp @@ -24,7 +24,6 @@ extern "C" { #include "Engine/Engine.h" #include "Engine/EngineGlobals.h" -#include "Engine/ErrorHandling.h" #include "Engine/Graphics/IRender.h" #include "Engine/Graphics/Image.h" @@ -371,7 +370,7 @@ class Movie : public IMovie { audio.open(format_ctx); if (!video.open(format_ctx)) { - Error("Cannot open video stream: %s", filename); + logger->error("Cannot open video stream: {}", filename); Close(); return false; } @@ -1085,7 +1084,7 @@ bool AudioBaseDataSource::Open() { pCodecContext->channel_layout = AV_CH_LAYOUT_STEREO; break; default: - __debugbreak(); + assert(false); break; } }