diff --git a/source/controlsmgr.cpp b/source/controlsmgr.cpp index a688191..2649e22 100644 --- a/source/controlsmgr.cpp +++ b/source/controlsmgr.cpp @@ -10,7 +10,7 @@ u32 ControlsManager::buttons[ControlsManager::NUM_BUTTONS]; void ControlsManager::loadControls(void) { - mtnlogMessage(LOG_INFO, "Loading controls"); + mtnlogMessageTag(LOG_INFO, "controlsmgr", "Loading controls"); // write default controls if controls file not found if (!fsFileExists(std::string(std::string(mtnconfigGet("configDir")) + "/controls.cfg").c_str())) @@ -37,7 +37,7 @@ void ControlsManager::loadControls(void) void ControlsManager::saveControls(void) { - mtnlogMessage(LOG_INFO, "Saving controls"); + mtnlogMessageTag(LOG_INFO, "controlsmgr", "Saving controls"); std::ofstream ofs(std::string(std::string(mtnconfigGet("configDir")) + "/controls.cfg").c_str()); ofs << "goleft " << buttons[BUTTON_GO_LEFT] << "\ngoright " << buttons[BUTTON_GO_RIGHT] << "\njump " << buttons[BUTTON_JUMP] @@ -55,7 +55,7 @@ u32 ControlsManager::getButton(u8 button) void ControlsManager::writeDefaultControls(void) { - mtnlogMessage(LOG_INFO, "Writing default controls"); + mtnlogMessageTag(LOG_INFO, "controlsmgr", "Writing default controls"); buttons[BUTTON_GO_LEFT] = DEFAULT_GO_LEFT; buttons[BUTTON_GO_RIGHT] = DEFAULT_GO_RIGHT; @@ -95,7 +95,7 @@ u8 ControlsManager::buttonIDIndex(const std::string &buttonID) void ControlsManager::setButton(u8 button, u32 key) { - mtnlogMessage(LOG_INFO, "Setting button %u to key %u", button, key); + mtnlogMessageTag(LOG_INFO, "controlsmgr", "Setting button %u to key %u", button, key); // if button index invalid or key is not valid if (button >= NUM_BUTTONS || (key != KEY_A && key != KEY_B && key != KEY_X && key != KEY_Y && key != KEY_LEFT && diff --git a/source/game.cpp b/source/game.cpp index 5a82486..14fdac7 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -340,7 +340,7 @@ void Game::init(void) fsInitStatus fsInitSt = fsInit(); if (fsInitSt != FS_INIT_STATUS_OK) { - mtnlogMessage(LOG_ERROR, "Error initializing filesystem"); + mtnlogMessageTag(LOG_ERROR, "init", "Error initializing filesystem"); AssetManager::loadDirtBlock(); loadFonts(); while (true) @@ -384,7 +384,7 @@ void Game::init(void) gamever::InitStatus gvis = gamever::init(mtnconfigGet("gameVersionFile")); if (gvis == gamever::InitStatus::FileOpenError) { - mtnlogMessage(LOG_INFO, "Error opening game version file '%s': %s", mtnconfigGet("gameVersionFile"), strerror(errno)); + mtnlogMessageTag(LOG_ERROR, "init", "Error opening game version file '%s': %s", mtnconfigGet("gameVersionFile"), strerror(errno)); hang(); } @@ -392,7 +392,7 @@ void Game::init(void) mtnlogInit((MtnLogLevel)mtnconfigGetInt("logLevel"), mtnconfigGet("logFile")); mtnlogColor(true); - mtnlogMessage(LOG_INFO, "Initializing sound"); + mtnlogMessageTag(LOG_INFO, "init", "Initializing sound"); // init sound mmInitDefault((char *)mtnconfigGet("soundbankFile")); @@ -402,19 +402,19 @@ void Game::init(void) fsCreateDir(mtnconfigGet("worldsDir")); fsCreateDir(mtnconfigGet("configDir")); - mtnlogMessage(LOG_INFO, "Initializing crafting"); + mtnlogMessageTag(LOG_INFO, "init", "Initializing crafting"); // init crafting Player::initCrafting(); - mtnlogMessage(LOG_INFO, "Loading general assets"); + mtnlogMessageTag(LOG_INFO, "init", "Loading general assets"); // load some assets AssetManager::loadGeneralAssets(); sndPop = soundEffect(SFX_POP); sndClick = soundEffect(SFX_CLICK); - mtnlogMessage(LOG_INFO, "Loading settings"); + mtnlogMessageTag(LOG_INFO, "init", "Loading settings"); // update settings if need to SettingsManager::updateSettingsFormat(); @@ -425,12 +425,12 @@ void Game::init(void) // set main screen setMainScreen(SettingsManager::mainScreen); - mtnlogMessage(LOG_INFO, "Loading controls"); + mtnlogMessageTag(LOG_INFO, "init", "Loading controls"); // load controls ControlsManager::loadControls(); - mtnlogMessage(LOG_INFO, "Initializing RNG"); + mtnlogMessageTag(LOG_INFO, "init", "Initializing RNG"); // set up random number generator u32 randomSeed; @@ -451,7 +451,7 @@ void Game::init(void) for (int i = 0; i < rng::rangeSigned(10, 100); ++i) (void)rng::range(rng::range(0, 900), rng::range(0, 300)); - mtnlogMessage(LOG_INFO, "Loading menu assets"); + mtnlogMessageTag(LOG_INFO, "init", "Loading menu assets"); // load assets for menu AssetManager::loadMenuAssets(); @@ -1923,7 +1923,7 @@ void Game::update(void) std::string worldVersion = getWorldVersion(normalizeWorldFileName(worldName)); if (worldVersion == "alpha0.0.0") // alpha0.0.0 means error { - mtnlogMessage(LOG_ERROR, "Failed getting world version for world %s", worldName.c_str()); + mtnlogMessageTag(LOG_ERROR, "worldselect", "Failed getting world version for world %s", worldName.c_str()); return; } u64 worldVersionHash = gamever::getVersionHash(worldVersion); diff --git a/source/pcximage.c b/source/pcximage.c index 73b1262..7e60cd7 100644 --- a/source/pcximage.c +++ b/source/pcximage.c @@ -7,12 +7,12 @@ void pcxImageLoad(const char *filePath, bool color0Transparent, PCXImage *image) { - mtnlogMessage(LOG_INFO, "Loading PCX image from file %s", filePath); + mtnlogMessageTag(LOG_INFO, "pcx", "Loading PCX image from file %s", filePath); FILE *file = fopen(filePath, "rb"); if (!file) { - mtnlogMessage(LOG_ERROR, "Failed to open PCX image file %s because %s", filePath, strerror(errno)); + mtnlogMessageTag(LOG_ERROR, "pcx", "Failed to open PCX image file %s because %s", filePath, strerror(errno)); return; } @@ -23,7 +23,7 @@ void pcxImageLoad(const char *filePath, bool color0Transparent, PCXImage *image) u8 *pcxBytes = (u8 *)malloc(fileSize); if (!pcxBytes) { - mtnlogMessage(LOG_ERROR, "Failed to allocate memory for PCX bytes"); + mtnlogMessageTag(LOG_ERROR, "pcx", "Failed to allocate memory for PCX bytes"); fclose(file); return; } @@ -34,7 +34,7 @@ void pcxImageLoad(const char *filePath, bool color0Transparent, PCXImage *image) free(pcxBytes); if (image->simg.bpp == 0) - mtnlogMessage(LOG_WARNING, "PCX file '%s' is corrupted or has wrong color depth", filePath); + mtnlogMessageTag(LOG_WARNING, "pcx", "PCX file '%s' is corrupted or has wrong color depth", filePath); int flags = GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_OFF; if (color0Transparent) diff --git a/source/playercrafting.cpp b/source/playercrafting.cpp index 677c62f..82244b9 100644 --- a/source/playercrafting.cpp +++ b/source/playercrafting.cpp @@ -26,7 +26,7 @@ void Player::initCrafting(void) cpuStartTiming(0); // start measuring time _craftingRecipes.push_back(CraftingRecipe(line)); // parse + add the recipe float timeTook = (float)cpuEndTiming() / BUS_CLOCK; // get how much time it took - mtnlogMessage(LOG_INFO, "loaded %s in %f s", line.c_str(), timeTook); // print how much it took + mtnlogMessageTag(LOG_INFO, "crafting", "loaded %s in %f s", line.c_str(), timeTook); // print how much it took loadTimes[line] = timeTook; // put the time into the list // the time measuring functions also measure how much time it takes to @@ -39,7 +39,6 @@ void Player::initCrafting(void) float highest = 0.0f; std::string lowestName = ""; std::string highestName = ""; - mtnlogMessage(LOG_INFO, "calculating crafting load results..."); for (const auto &pair : loadTimes) { if (pair.second < lowest) @@ -54,7 +53,7 @@ void Player::initCrafting(void) } } - mtnlogMessage(LOG_INFO, "*** Load Results\nFastest time: %f (%s)\nSlowest time: %f (%s)", lowest, lowestName.c_str(), + mtnlogMessageTag(LOG_INFO, "crafting", "*** Load Results: Fastest time: %f (%s); Slowest time: %f (%s)", lowest, lowestName.c_str(), highest, highestName.c_str()); } diff --git a/source/save.cpp b/source/save.cpp index ab3a1be..3f2aff9 100644 --- a/source/save.cpp +++ b/source/save.cpp @@ -427,7 +427,7 @@ void loadWorld(const std::string &name, Block::List &blocks, EntityList &entitie { std::string worldFolder = std::string(std::string(mtnconfigGet("worldsDir")) + "/" + name); - mtnlogMessage(LOG_INFO, "Loading world with name `%s' folder `%s'", name.c_str(), worldFolder.c_str()); + mtnlogMessageTag(LOG_INFO, "save", "Loading world with name `%s' folder `%s'", name.c_str(), worldFolder.c_str()); // clear the current world state blocks.clear(); @@ -439,7 +439,7 @@ void loadWorld(const std::string &name, Block::List &blocks, EntityList &entitie // we can't load something that doesn't exist if (!fsDirExists(worldFolder.c_str())) { - mtnlogMessage(LOG_ERROR, "folder %s does not exist", worldFolder.c_str()); + mtnlogMessageTag(LOG_ERROR, "save", "folder %s does not exist", worldFolder.c_str()); return; } @@ -464,7 +464,7 @@ void loadWorld(const std::string &name, Block::List &blocks, EntityList &entitie if (!setLoc) currentLocation = 0; // default location is 0 - mtnlogMessage(LOG_INFO, "current location is %d", currentLocation); + mtnlogMessageTag(LOG_INFO, "save", "current location is %d", currentLocation); std::ifstream wld(worldFolder + "/locations/location" + std::to_string(currentLocation) + ".wld"); std::string line; @@ -760,11 +760,11 @@ void loadWorld(const std::string &name, Block::List &blocks, EntityList &entitie std::ifstream chestFile(chestFileName); if (chestFile.bad()) { - mtnlogMessage(LOG_ERROR, "bad chest file %s", line.c_str()); + mtnlogMessageTag(LOG_ERROR, "save", "bad chest file %s", line.c_str()); continue; } - mtnlogMessage(LOG_INFO, "Loading chest with ID %d", chestID); + mtnlogMessageTag(LOG_INFO, "save", "Loading chest with ID %d", chestID); std::string line2; while (std::getline(chestFile, line2)) diff --git a/source/settingsmgr.cpp b/source/settingsmgr.cpp index aef9ac8..b0b839c 100644 --- a/source/settingsmgr.cpp +++ b/source/settingsmgr.cpp @@ -21,7 +21,7 @@ void SettingsManager::loadLanguageLegacy(void) { if (fsFileExists(std::string(std::string(mtnconfigGet("configDir")) + "/lang.cfg").c_str())) { - mtnlogMessage(LOG_INFO, "Loading legacy language setting"); + mtnlogMessageTag(LOG_INFO, "settingsmgr", "Loading legacy language setting"); char *data = fsReadFile(std::string(std::string(mtnconfigGet("configDir")) + "/lang.cfg").c_str()); switch (data[0]) @@ -33,7 +33,7 @@ void SettingsManager::loadLanguageLegacy(void) Game::instance->lang = Language::Russian; break; default: - mtnlogMessage(LOG_WARNING, "Invalid language code '%c'; defaulting to English"); + mtnlogMessageTag(LOG_WARNING, "settingsmgr", "Invalid language code '%c'; defaulting to English"); Game::instance->lang = Language::English; break; } @@ -59,7 +59,7 @@ void SettingsManager::loadSettingsLegacy(void) // my reasoning might not be correct, but transitioning from using a billion files for storing settings to // having just a single file is still better. - mtnlogMessage(LOG_INFO, "Loading legacy settings"); + mtnlogMessageTag(LOG_INFO, "settingsmgr", "Loading legacy settings"); // legacy language setting loadLanguageLegacy(); @@ -80,7 +80,7 @@ void SettingsManager::loadSettingsLegacy(void) autoSaveSeconds = std::stoi(std::string(data)); if (autoSaveSeconds == 1) { - mtnlogMessage(LOG_INFO, "Auto save every 1 second detected, changing to 15"); + mtnlogMessageTag(LOG_INFO, "settingsmgr", "Auto save every 1 second detected, changing to 15"); autoSaveSeconds = 15; } } @@ -126,7 +126,7 @@ void SettingsManager::removeLegacySettings(void) void SettingsManager::updateSettingsFormat(void) { - mtnlogMessage(LOG_INFO, "Updating settings format"); + mtnlogMessageTag(LOG_INFO, "settingsmgr", "Updating settings format"); // check if we need to update if (fsFileExists(std::string(std::string(mtnconfigGet("configDir")) + "/settings.cfg").c_str())) @@ -144,7 +144,7 @@ void SettingsManager::updateSettingsFormat(void) void SettingsManager::saveSettings(void) { - mtnlogMessage(LOG_INFO, "Saving settings"); + mtnlogMessageTag(LOG_INFO, "settingsmgr", "Saving settings"); // open na file FILE *settingsFile = fopen(std::string(std::string(mtnconfigGet("configDir")) + "/settings.cfg").c_str(), "w"); @@ -152,7 +152,7 @@ void SettingsManager::saveSettings(void) // check if error if (!settingsFile) { - mtnlogMessage(LOG_ERROR, "error opening settings file: %s", strerror(errno)); + mtnlogMessageTag(LOG_ERROR, "settingsmgr", "error opening settings file: %s", strerror(errno)); return; } @@ -167,7 +167,7 @@ void SettingsManager::saveSettings(void) void SettingsManager::loadSettings(void) { - mtnlogMessage(LOG_INFO, "Loading settings"); + mtnlogMessageTag(LOG_INFO, "settingsmgr", "Loading settings"); // open file std::ifstream file(std::string(std::string(mtnconfigGet("configDir")) + "/settings.cfg")); @@ -175,7 +175,7 @@ void SettingsManager::loadSettings(void) // check if error if (file.bad()) { - mtnlogMessage(LOG_ERROR, "error opening settings file: %s", strerror(errno)); + mtnlogMessageTag(LOG_ERROR, "settingsmgr", "error opening settings file: %s", strerror(errno)); return; } @@ -217,7 +217,7 @@ void SettingsManager::loadSettings(void) else if (split[1] == "1") Game::instance->lang = Language::Russian; else - mtnlogMessage(LOG_WARNING, "Invalid language code %s", split[1].c_str()); + mtnlogMessageTag(LOG_WARNING, "settingsmgr", "Invalid language code %s", split[1].c_str()); } else if (split[0] == "blockparts") { @@ -257,7 +257,7 @@ void SettingsManager::loadSettings(void) else { // invalid key - mtnlogMessage(LOG_WARNING, "Invalid setting '%s', ignoring", split[0].c_str()); + mtnlogMessageTag(LOG_WARNING, "settingsmgr", "Invalid setting '%s', ignoring", split[0].c_str()); } } } diff --git a/source/stats.cpp b/source/stats.cpp index b7ae6c1..f1e9d2d 100644 --- a/source/stats.cpp +++ b/source/stats.cpp @@ -15,17 +15,17 @@ void statsSetWorld(const std::string &worldName) std::string worldFolder = getWorldFile(worldName); if (!fsDirExists(worldFolder.c_str())) { - mtnlogMessage(LOG_ERROR, "statsSetWorld: world %s (%s) doesnt exist", worldName.c_str(), + mtnlogMessageTag(LOG_ERROR, "stats", "world %s (%s) does not exist", worldName.c_str(), normalizeWorldFileName(worldName).c_str()); return; } - mtnlogMessage(LOG_INFO, "setting stats world to `%s'", worldName.c_str()); + mtnlogMessageTag(LOG_INFO, "stats", "setting stats world to `%s'", worldName.c_str()); _currentWorld = worldFolder; if (!fsFileExists(_getStatsFile().c_str())) { - mtnlogMessage(LOG_INFO, "Stats file does not exist. Creating."); + mtnlogMessageTag(LOG_INFO, "stats", "Stats file does not exist. Creating."); fsCreateFile(_getStatsFile().c_str()); } } @@ -44,7 +44,7 @@ void statsSetEntry(const std::string &entryKey, int value) void statsSave(void) { - mtnlogMessage(LOG_INFO, "saving stats"); + mtnlogMessageTag(LOG_INFO, "stats", "saving stats"); std::ofstream ofs(_getStatsFile()); for (const auto &entry : _stats) @@ -57,7 +57,7 @@ void statsSave(void) void statsLoad(void) { - mtnlogMessage(LOG_INFO, "Loading stats from file %s", _getStatsFile().c_str()); + mtnlogMessageTag(LOG_INFO, "stats", "Loading stats from file %s", _getStatsFile().c_str()); std::ifstream ifs(_getStatsFile()); std::string line; @@ -76,7 +76,7 @@ void statsLoad(void) split[1].end(), [](unsigned char c) { return !std::isdigit(c); }) == split[1].end())) { - mtnlogMessage(LOG_WARNING, "Value of key %s in stats file %s is not a number. Skipping.", key.c_str(), _getStatsFile().c_str()); + mtnlogMessageTag(LOG_WARNING, "stats", "Value of key %s in stats file %s is not a number. Skipping.", key.c_str(), _getStatsFile().c_str()); continue; } int value = std::stoi(split[1]);