Skip to content

Commit

Permalink
more usage of proper log printing
Browse files Browse the repository at this point in the history
  • Loading branch information
sandsmark committed Jul 16, 2018
1 parent 431684b commit b915b24
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/Engine.cpp
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions src/core/Entity.cpp
Expand Up @@ -64,7 +64,7 @@ Unit::Unit(const genie::Unit &data_, int playerId_, std::shared_ptr<Civilization
defaultGraphics = ResourceManager::Inst()->getGraphic(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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
33 changes: 17 additions & 16 deletions src/global/Config.cpp
Expand Up @@ -17,6 +17,7 @@
*/

#include "Config.h"
#include "Logger.h"

#include <assert.h>
#include <fstream>
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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<decltype(name), const std::string>()); // fuck auto
static_assert(std::is_same<decltype(description), const std::string>()); // 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;

}

Expand Down Expand Up @@ -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<
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mechanics/ActionBuild.cpp
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/mechanics/ActionMove.cpp
Expand Up @@ -313,7 +313,7 @@ std::vector<MapPos> 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;

Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mechanics/Civilization.cpp
Expand Up @@ -70,7 +70,7 @@ const std::vector<const genie::Tech *> 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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mechanics/GameState.cpp
Expand Up @@ -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++) {
Expand Down
4 changes: 2 additions & 2 deletions src/mechanics/Map.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/mechanics/UnitFactory.cpp
Expand Up @@ -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<Unit>(gunit, owner->playerId, owner->civ);
Expand Down
2 changes: 1 addition & 1 deletion src/mechanics/UnitManager.cpp
Expand Up @@ -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;
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/render/ActionPanel.cpp
Expand Up @@ -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; i<unitIconsSlp->getFrameCount(); i++) {
Expand All @@ -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; i<buildingIconsSlp->getFrameCount(); i++) {
Expand All @@ -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; i<researchIconsSlp->getFrameCount(); i++) {
Expand All @@ -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<int(Command::IconCount); i++) {
if (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)));
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/render/MapRenderer.cpp
Expand Up @@ -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());

Expand Down
2 changes: 1 addition & 1 deletion src/resource/DataManager.cpp
Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions src/resource/ResourceManager.cpp
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down

0 comments on commit b915b24

Please sign in to comment.