diff --git a/src/Engine.cpp b/src/Engine.cpp index bc0a7a6..75d759b 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -99,7 +99,7 @@ bool Engine::setup(const std::string &scnFile) scenario->load(scnFile.c_str()); gameState->setScenario(scenario); } catch (const std::exception &error) { - std::cerr << "Failed to load " << scnFile << ": " << error.what() << std::endl; + WARN << "Failed to load" << scnFile << ":" << error.what(); return false; } } else { diff --git a/src/core/Entity.cpp b/src/core/Entity.cpp index 693fa0b..1f7282a 100644 --- a/src/core/Entity.cpp +++ b/src/core/Entity.cpp @@ -64,7 +64,7 @@ Unit::Unit(const genie::Unit &data_, int playerId_, std::shared_ptrgetGraphic(data.StandingGraphic.first), movingGraphics = ResourceManager::Inst()->getGraphic(data.Moving.WalkingGraphic); if (!defaultGraphics) { - std::cerr << "Failed to load default graphics" << std::endl; + WARN << "Failed to load default graphics"; } m_creationProgress = data.Creatable.TrainTime; @@ -204,7 +204,6 @@ void Unit::setCurrentAction(ActionPtr action) m_graphics.setGraphic(movingGraphics); } else if (action->type == IAction::Type::Build) { m_graphics.setGraphic(ResourceManager::Inst()->getGraphic(taskGraphicId(genie::Task::Build, Working))); - std::cout << m_graphics.graphic_->data_.AngleCount << " " << m_graphics.graphic_->data_.FrameCount << std::endl; } else { m_graphics.setGraphic(defaultGraphics); } @@ -217,11 +216,11 @@ void Unit::removeAction(IAction *action) m_graphics.setGraphic(defaultGraphics); if (!m_actionQueue.empty()) { - std::cout << "changing action to queued one" << std::endl; + DBG << "changing action to queued one"; setCurrentAction(m_actionQueue.front()); m_actionQueue.pop_front(); } else { - std::cout << "no actions queued" << std::endl; + DBG << "no actions queued"; } } else { // fuck stl diff --git a/src/global/Config.cpp b/src/global/Config.cpp index a015b2b..f905b47 100644 --- a/src/global/Config.cpp +++ b/src/global/Config.cpp @@ -17,6 +17,7 @@ */ #include "Config.h" +#include "Logger.h" #include #include @@ -45,7 +46,7 @@ static std::string getRegistryString(const char *regGroup, const char *key) LONG ret = regKey.Open(HKEY_LOCAL_MACHINE, regGroup); if (ret != ERROR_SUCCESS) { - std::cerr << "Failed to open registry group " << regGroup << std::endl; + WARN << "Failed to open registry group " << regGroup; return std::string(); } @@ -56,7 +57,7 @@ static std::string getRegistryString(const char *regGroup, const char *key) regKey.Close(); if (ret != ERROR_SUCCESS) { - std::cerr << "Failed to get key " << key << " from " << regGroup << std::endl; + WARN << "Failed to get key " << key << " from " << regGroup; return std::string(); } @@ -66,16 +67,16 @@ static std::string getRegistryString(const char *regGroup, const char *key) void Config::printUsage(const std::string &programName) { - std::cerr << "Usage: " << programName << " [options]" << std::endl; - std::cerr << "Options:" << std::endl; + WARN << "Usage:" << programName << "[options]"; + WARN << "Options:"; for (const auto &[name, description] : m_allowedOptions) { static_assert(std::is_same()); // fuck auto static_assert(std::is_same()); // fuck auto x2 - std::cerr << std::setw(25) << std::left; - std::cerr << (" --" + name + "=value"); - std::cerr << description << std::endl; + std::cout << std::setw(25) << std::left; + std::cout << (" --" + name + "=value"); + std::cout << description << std::endl; } @@ -171,7 +172,7 @@ Config::Config(const std::string &applicationName) wchar_t *rawPath = nullptr; HRESULT hr = SHGetKnownFolderPath(FOLDERID_ProgramData, 0, NULL, &rawPath); if (FAILED(hr)) { - std::cerr << "Failed to get user configuration path!" << std::endl; + WARN << "Failed to get user configuration path!"; } if (rawPath) { m_filePath = std::wstring_convert< @@ -192,14 +193,14 @@ bool Config::parseOption(const std::string &option) size_t splitPos = option.find("="); if (splitPos == std::string::npos) { - std::cerr << "Invalid line in config: " << option << std::endl; + WARN << "Invalid line in config:" << option; return false; } std::string name = option.substr(0, splitPos); std::string value = option.substr(splitPos + 1); if (!checkOption(name, value)) { - std::cerr << "Invalid option in config: " << option << std::endl; + WARN << "Invalid option in config: " << option; return false; } @@ -208,14 +209,14 @@ bool Config::parseOption(const std::string &option) void Config::parseConfigFile(const std::string &path) { - std::cout << "parsing config file " << path << std::endl; + DBG << "parsing config file" << path; if (!std::filesystem::exists(path)) { return; } std::ifstream file(path); if (!file.is_open()) { - std::cerr << "Failed to open config file" << std::endl; + WARN << "Failed to open config file"; return; } @@ -227,10 +228,10 @@ void Config::parseConfigFile(const std::string &path) void Config::writeConfigFile(const std::string &path) { - std::cout << "storing config" << std::endl; + DBG << "storing config"; std::ofstream file(path); if (!file.is_open()) { - std::cerr << "Failed to open config file " << path << std::endl; + WARN << "Failed to open config file" << path; return; } @@ -244,9 +245,9 @@ void Config::writeConfigFile(const std::string &path) bool Config::checkOption(const std::string &name, const std::string &value) { - std::cout << "checking " << name << " " << value << std::endl; + DBG << "checking" << name << value; if (m_allowedOptions.find(name) == m_allowedOptions.end()) { - std::cerr << "Unknown option " << name << std::endl; + WARN << "Unknown option" << name; return false; } diff --git a/src/main.cpp b/src/main.cpp index 4419b55..b4fbd38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,7 +49,7 @@ int main(int argc, char **argv) const std::string dataPath = config.getValue("game-path") + "/Data/"; if (!std::filesystem::exists(dataPath)) { - std::cerr << "Game path " << dataPath << " does not exist" << std::endl; + WARN << "Game path " << dataPath << " does not exist"; config.printUsage(argv[0]); return 1; } diff --git a/src/mechanics/ActionBuild.cpp b/src/mechanics/ActionBuild.cpp index 9467f5b..3f91851 100644 --- a/src/mechanics/ActionBuild.cpp +++ b/src/mechanics/ActionBuild.cpp @@ -40,7 +40,7 @@ bool ActionBuild::update(Time time) } if (building->creationProgress() >= 1.) { - std::cout << "building already finished" << std::endl; + DBG << "building already finished"; unit->removeAction(this); return true; } @@ -52,7 +52,7 @@ bool ActionBuild::update(Time time) building->increaseCreationProgress(progress); if (building->creationProgress() >= 1.) { - std::cout << "building finished" << std::endl; + DBG << "building finished"; unit->removeAction(this); return true; } diff --git a/src/mechanics/ActionMove.cpp b/src/mechanics/ActionMove.cpp index 49deb2a..963f6f8 100644 --- a/src/mechanics/ActionMove.cpp +++ b/src/mechanics/ActionMove.cpp @@ -313,7 +313,7 @@ std::vector MoveOnMap::findPath(const MapPos &start, const MapPos &end, } cleanedPath.push_back(path.back()); - std::cout << cleanedPath.size() << "/" << path.size() << std::endl; + DBG << cleanedPath.size() << "/" << path.size(); return cleanedPath; @@ -349,9 +349,9 @@ bool MoveOnMap::isPassable(const int x, const int y) // if ( < && std::abs(other->position.y - mapPos.y) < (otherUnit->data.Size[1] + unit->data.Size[1]) * Constants::TILE_SIZE) { if (xDistance < xSize && yDistance < ySize) { -// std::cout << unit->readableName << " " << other->readableName << std::endl; -// std::cout << "x: " << xDistance << " " << xSize << std::endl; -// std::cout << "y: " << yDistance << " " << ySize << std::endl; +// DBG << unit->readableName << " " << other->readableName; +// DBG << "x: " << xDistance << " " << xSize; +// DBG << "y: " << yDistance << " " << ySize; return false; } } diff --git a/src/mechanics/Civilization.cpp b/src/mechanics/Civilization.cpp index 615e6d8..742a51a 100644 --- a/src/mechanics/Civilization.cpp +++ b/src/mechanics/Civilization.cpp @@ -70,7 +70,7 @@ const std::vector Civilization::researchAvailableAt(int16_t const genie::Unit &Civilization::unit(const uint16_t id) const { if (id >= m_data.Units.size()) { - std::cerr << "Invalid unit id " << id << std::endl; + WARN << "Invalid unit id" << id; return nullUnit; } diff --git a/src/mechanics/GameState.cpp b/src/mechanics/GameState.cpp index 261b185..d0ee1e7 100644 --- a/src/mechanics/GameState.cpp +++ b/src/mechanics/GameState.cpp @@ -133,7 +133,7 @@ bool GameState::init() map_ = MapPtr(new Map()); if (scenario_) { - std::cout << "Setting up scenario: " << scenario_->scenarioInstructions << std::endl; + DBG << "Setting up scenario:" << scenario_->scenarioInstructions; map_->create(scenario_->map); for (int playerNum = 0; playerNum < scenario_->playerUnits.size(); playerNum++) { diff --git a/src/mechanics/Map.cpp b/src/mechanics/Map.cpp index 5f47b14..90d37f2 100644 --- a/src/mechanics/Map.cpp +++ b/src/mechanics/Map.cpp @@ -80,8 +80,8 @@ void Map::setUpSample() void Map::create(genie::ScnMap mapDescription) { - std::cout << "tile count " << mapDescription.tiles.size() << std::endl; - std::cout << "size: " << mapDescription.width << "x" << mapDescription.height << std::endl; + DBG << "tile count:" << mapDescription.tiles.size(); + DBG << "size:" << mapDescription.width << "x" << mapDescription.height; tiles_.clear(); cols_ = mapDescription.width; diff --git a/src/mechanics/UnitFactory.cpp b/src/mechanics/UnitFactory.cpp index 58d35d2..f7f1d4d 100644 --- a/src/mechanics/UnitFactory.cpp +++ b/src/mechanics/UnitFactory.cpp @@ -42,7 +42,7 @@ UnitFactory::~UnitFactory() Unit::Ptr UnitFactory::createUnit(int ID, const MapPos &position, Player::Ptr owner) { -// std::cout << "Creating " << ID << std::endl; +// DBG << "Creating" << ID; const genie::Unit &gunit = DataManager::Inst().getUnit(ID); Unit::Ptr unit = std::make_shared(gunit, owner->playerId, owner->civ); diff --git a/src/mechanics/UnitManager.cpp b/src/mechanics/UnitManager.cpp index 5e934f3..76faefb 100644 --- a/src/mechanics/UnitManager.cpp +++ b/src/mechanics/UnitManager.cpp @@ -254,7 +254,7 @@ void UnitManager::selectUnits(const ScreenRect &selectionRect, const CameraPtr & } if (m_selectedUnits.empty()) { - std::cout << "Unable to find anything to select in " << selectionRect << std::endl; + DBG << "Unable to find anything to select in " << selectionRect; } } diff --git a/src/render/ActionPanel.cpp b/src/render/ActionPanel.cpp index d73fbd2..a3868ef 100644 --- a/src/render/ActionPanel.cpp +++ b/src/render/ActionPanel.cpp @@ -20,7 +20,7 @@ bool ActionPanel::init() { genie::SlpFilePtr unitIconsSlp = ResourceManager::Inst()->getSlp(ResourceManager::filenameID("btnunit.shp"), ResourceManager::ResourceType::Interface); if (!unitIconsSlp) { - std::cerr << "Failed to load unit icons" << std::endl; + WARN << "Failed to load unit icons"; return false; } for (int i=0; igetFrameCount(); i++) { @@ -30,7 +30,7 @@ bool ActionPanel::init() // ico_bld1-4.shp looks identical, for some reason genie::SlpFilePtr buildingIconsSlp = ResourceManager::Inst()->getSlp(ResourceManager::filenameID("ico_bld2.shp"), ResourceManager::ResourceType::Interface); if (!buildingIconsSlp) { - std::cerr << "Failed to load building icons" << std::endl; + WARN << "Failed to load building icons"; return false; } for (int i=0; igetFrameCount(); i++) { @@ -39,7 +39,7 @@ bool ActionPanel::init() genie::SlpFilePtr researchIconsSlp = ResourceManager::Inst()->getSlp(ResourceManager::filenameID("btntech.shp"), ResourceManager::ResourceType::Interface); if (!researchIconsSlp) { - std::cerr << "Failed to load research icons" << std::endl; + WARN << "Failed to load research icons"; return false; } for (int i=0; igetFrameCount(); i++) { @@ -48,12 +48,12 @@ bool ActionPanel::init() genie::SlpFilePtr commandIconsSlp = ResourceManager::Inst()->getSlp(ResourceManager::filenameID("btncmd.shp"), ResourceManager::ResourceType::Interface); if (!commandIconsSlp) { - std::cerr << "Failed to load action icons" << std::endl; + WARN << "Failed to load action icons"; return false; } for (int i=0; i= commandIconsSlp->getFrameCount()) { - std::cerr << "icon out of range " << i << std::endl; + WARN << "icon out of range " << i; return false; } m_commandIcons[Command(i)].loadFromImage(res::Resource::convertFrameToImage(commandIconsSlp->getFrame(i))); @@ -202,7 +202,7 @@ void ActionPanel::updateButtons() Unit::Ptr unit = *m_selectedUnits.begin(); - std::cout << unit->data.Creatable.GarrisonGraphic << std::endl; + DBG << unit->data.Creatable.GarrisonGraphic; if (unit->data.Type >= genie::Unit::MovingType && unit->data.Type < genie::Unit::BuildingType) { InterfaceButton killButton; @@ -214,7 +214,7 @@ void ActionPanel::updateButtons() bool canGarrison = false; for (const genie::Task *task : unit->availableActions()) { - std::cout << task->actionTypeName() << std::endl; + DBG << task->actionTypeName(); if (task->ActionType == genie::Task::Garrison) { canGarrison = true; diff --git a/src/render/MapRenderer.cpp b/src/render/MapRenderer.cpp index 801af96..c84caa7 100644 --- a/src/render/MapRenderer.cpp +++ b/src/render/MapRenderer.cpp @@ -72,34 +72,34 @@ bool MapRenderer::update(Time time) MapPos topRightMp = cameraPos + (topRight - center); MapPos botLeftMp = cameraPos + (bottomLeft - center); -// std::cout << "nulC " << nullCenterMp.x << " " << nullCenterMp.y << std::endl; -// std::cout << "topLeftMp " << topLeftMp.x << " " << topLeftMp.y << std::endl; -// std::cout << "botRightMp " << botRightMp.x << " " << botRightMp.y << std::endl; +// DBG << "nulC " << nullCenterMp.x << " " << nullCenterMp.y; +// DBG << "topLeftMp " << topLeftMp.x << " " << topLeftMp.y; +// DBG << "botRightMp " << botRightMp.x << " " << botRightMp.y; // get column and row boundaries for rendering m_rColBegin = botLeftMp.x / Constants::TILE_SIZE; if (m_rColBegin > m_map->getCols()) { - std::cout << "E: Somethings fishy... (rColBegin_ > map_->getCols())" << std::endl; + WARN << "E: Somethings fishy... (rColBegin_ > map_->getCols())"; } m_rColBegin = std::clamp(m_rColBegin, 0, m_map->getCols()); m_rColEnd = topRightMp.x / Constants::TILE_SIZE; m_rColEnd++; //round up if (m_rColEnd < 0) { - std::cout << "E: Somethings fishy... (rColEnd_ < 0)" << std::endl; + WARN << "E: Somethings fishy... (rColEnd_ < 0)"; } m_rColEnd = std::clamp(m_rColEnd, 0, m_map->getCols()); m_rRowBegin = topLeftMp.y / Constants::TILE_SIZE; if (m_rRowBegin > m_map->getRows()) { - std::cout << "E: Somethings fishy... (rRowBegin > map_->getRows())" << std::endl; + WARN << "E: Somethings fishy... (rRowBegin > map_->getRows())"; } m_rRowBegin = std::clamp(m_rRowBegin, 0, m_map->getRows()); m_rRowEnd = botRightMp.y / Constants::TILE_SIZE; m_rRowEnd++; // round up if (m_rRowEnd < 0) { - std::cout << "E: Somethings fishy... (rColEnd_ < 0)" << std::endl; + WARN << "E: Somethings fishy... (rColEnd_ < 0)"; } m_rRowEnd = std::clamp(m_rRowEnd, 0, m_map->getRows()); diff --git a/src/resource/DataManager.cpp b/src/resource/DataManager.cpp index 3453fc3..88e6017 100644 --- a/src/resource/DataManager.cpp +++ b/src/resource/DataManager.cpp @@ -151,7 +151,7 @@ bool DataManager::initialize(const std::string dataPath) } if (filePath == "") { - std::cerr << "Failed to find any dat files in " << dataPath << std::endl; + WARN << "Failed to find any dat files in" << dataPath; return false; } diff --git a/src/resource/ResourceManager.cpp b/src/resource/ResourceManager.cpp index 16d893c..23c6038 100644 --- a/src/resource/ResourceManager.cpp +++ b/src/resource/ResourceManager.cpp @@ -57,7 +57,7 @@ genie::ScnFilePtr ResourceManager::getScn(unsigned int id) if (scnfile) { DBG << "found scn file version" << scnfile->version; - std::cout << scnfile->scenarioInstructions << std::endl; + DBG << scnfile->scenarioInstructions; return scnfile; } } @@ -224,7 +224,7 @@ bool ResourceManager::initialize(const std::string &dataPath, const genie::GameV m_gamedataFiles = loadDrs(gamedataFiles); if (m_gamedataFiles.empty()) { - std::cerr << "Failed to find any gamedata files in " << dataPath << std::endl; + WARN << "Failed to find any gamedata files in" << dataPath; return false; } @@ -254,7 +254,7 @@ bool ResourceManager::initialize(const std::string &dataPath, const genie::GameV m_soundFiles = loadDrs(soundFiles); if (m_soundFiles.empty()) { - std::cerr << "Failed to find any sound files in " << dataPath << std::endl; + WARN << "Failed to find any sound files in" << dataPath; return false; } @@ -275,7 +275,7 @@ bool ResourceManager::initialize(const std::string &dataPath, const genie::GameV WARN << "Failed to load resource" << error.what(); return false; } - std::cerr << "Loaded " << m_allFiles.size() << " files" << std::endl; + DBG << "Loaded" << m_allFiles.size() << "files"; return true; } diff --git a/src/resource/Terrain.cpp b/src/resource/Terrain.cpp index dae69a3..a2a2ce1 100644 --- a/src/resource/Terrain.cpp +++ b/src/resource/Terrain.cpp @@ -60,7 +60,7 @@ const sf::Texture &Terrain::texture(int x, int y) return m_images[frameNum]; } -// std::cerr << "------------------------ " << int(m_data.SLP) << std::endl; +// WARN << "------------------------ " << int(m_data.SLP); // sf::Image img = Resource::convertFrameToImage(ResourceManager::Inst()->getTemplatedSlp(m_data.SLP, genie::SlopeFlat)); // sf::Image img = Resource::convertFrameToImage(ResourceManager::Inst()->getTemplatedSlp(m_data.SLP, genie::SlopeWestDown)); sf::Image img = Resource::convertFrameToImage(m_slp->getFrame(frameNum));