From a61ee58a39bbe6f29ad1543c7d56df6c6066fd6d Mon Sep 17 00:00:00 2001 From: KroArtem Date: Thu, 6 Feb 2014 01:26:30 +0400 Subject: [PATCH 1/6] clean src/karts from cout, printf and cerr --- src/karts/abstract_kart.cpp | 2 +- src/karts/controller/ai_properties.cpp | 10 +++--- src/karts/controller/end_controller.cpp | 2 +- .../controller/network_player_controller.cpp | 2 +- src/karts/controller/player_controller.cpp | 2 +- src/karts/controller/skidding_ai.cpp | 34 +++++++++---------- src/karts/explosion_animation.cpp | 1 - src/karts/kart.cpp | 4 +-- src/karts/kart_gfx.cpp | 3 +- src/karts/kart_properties_manager.cpp | 20 +++++------ 10 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/karts/abstract_kart.cpp b/src/karts/abstract_kart.cpp index 8024f23f9..c8981ff36 100644 --- a/src/karts/abstract_kart.cpp +++ b/src/karts/abstract_kart.cpp @@ -111,7 +111,7 @@ void AbstractKart::setKartAnimation(AbstractKartAnimation *ka) ka->getName().c_str()); else Log::debug("Abstract_Kart", "Setting kart animation to NULL."); if(m_kart_animation) Log::info("Abstract_Kart", "Current kart" - "animation is '%s'.\n", + "animation is '%s'.", m_kart_animation->getName().c_str()); else Log::debug("Abstract_Kart", "Current kart animation is NULL."); } diff --git a/src/karts/controller/ai_properties.cpp b/src/karts/controller/ai_properties.cpp index c9dc6f655..720fc5a77 100644 --- a/src/karts/controller/ai_properties.cpp +++ b/src/karts/controller/ai_properties.cpp @@ -85,7 +85,7 @@ void AIProperties::load(const XMLNode *ai_node) else { Log::fatal("AIProperties", - "Incorrect nitro-usage '%s' in AI '%s'.\n",s.c_str(), + "Incorrect nitro-usage '%s' in AI '%s'.",s.c_str(), m_ident.c_str()); } // We actually need the square of the distance later @@ -102,7 +102,7 @@ void AIProperties::checkAllSet(const std::string &filename) const { #define CHECK_NEG( a,str_a) if(a<=UNDEFINED) { \ Log::fatal("AIProperties","Missing default value for" \ - " '%s' in '%s' 'for AI '%s'.\n", \ + " '%s' in '%s' 'for AI '%s'.", \ str_a, filename.c_str(), m_ident.c_str()); \ } CHECK_NEG(m_max_item_angle, "max-item-angle" ); @@ -118,17 +118,17 @@ void AIProperties::checkAllSet(const std::string &filename) const if(m_skid_probability.size()==0) { - Log::fatal("AIProperties", "No skid probability defined.\n"); + Log::fatal("AIProperties", "No skid probability defined."); } if(m_speed_cap.size()==0) { - Log::fatal("AIProperties", "No speed cap defined.\n"); + Log::fatal("AIProperties", "No speed cap defined."); } if(m_collect_item_probability.size()==0) { - Log::fatal("AIProperties", "No collect-item-probability defined.\n"); + Log::fatal("AIProperties", "No collect-item-probability defined."); } } // checkAllSet diff --git a/src/karts/controller/end_controller.cpp b/src/karts/controller/end_controller.cpp index 9e4b586d4..693e955fb 100644 --- a/src/karts/controller/end_controller.cpp +++ b/src/karts/controller/end_controller.cpp @@ -218,7 +218,7 @@ void EndController::handleSteering(float dt) const int next = m_next_node_index[m_track_node]; target_point = QuadGraph::get()->getQuadOfNode(next).getCenter(); #ifdef AI_DEBUG - Log::debug("end_controller.cpp", "- Outside of road: steer to center point.\n"); + Log::debug("end_controller.cpp", "- Outside of road: steer to center point."); #endif } else diff --git a/src/karts/controller/network_player_controller.cpp b/src/karts/controller/network_player_controller.cpp index b408727ec..84ebc105e 100644 --- a/src/karts/controller/network_player_controller.cpp +++ b/src/karts/controller/network_player_controller.cpp @@ -255,7 +255,7 @@ void NetworkPlayerController::update(float dt) { // Print a dividing line so that it's easier to see which events // get received in which order in the one frame. - Log::debug("PlayerController", "irr_driver", "-------------------------------------\n"); + Log::debug("PlayerController", "irr_driver", "-------------------------------------"); } // Don't do steering if it's replay. In position only replay it doesn't diff --git a/src/karts/controller/player_controller.cpp b/src/karts/controller/player_controller.cpp index 9886dcf81..776db3b81 100644 --- a/src/karts/controller/player_controller.cpp +++ b/src/karts/controller/player_controller.cpp @@ -311,7 +311,7 @@ void PlayerController::update(float dt) { // Print a dividing line so that it's easier to see which events // get received in which order in the one frame. - Log::debug("PlayerController", "irr_driver", "-------------------------------------\n"); + Log::debug("PlayerController", "irr_driver", "-------------------------------------"); } // Don't do steering if it's replay. In position only replay it doesn't diff --git a/src/karts/controller/skidding_ai.cpp b/src/karts/controller/skidding_ai.cpp index 84da7a086..5db0c83c3 100644 --- a/src/karts/controller/skidding_ai.cpp +++ b/src/karts/controller/skidding_ai.cpp @@ -198,7 +198,7 @@ void SkiddingAI::reset() { Log::error("SkiddingAI", "Invalid starting position for '%s' - not on track" - " - can be ignored.\n", + " - can be ignored.", m_kart->getIdent().c_str()); m_track_node = QuadGraph::get()->findOutOfRoadSector(m_kart->getXYZ()); } @@ -401,7 +401,7 @@ void SkiddingAI::handleBraking() { #ifdef DEBUG if(m_ai_debug) - Log::debug("SkiddingAI", "braking: %s ahead of leader.\n", + Log::debug("SkiddingAI", "braking: %s ahead of leader.", m_kart->getIdent().c_str()); #endif @@ -421,7 +421,7 @@ void SkiddingAI::handleBraking() { #ifdef DEBUG if(m_ai_debug) - Log::debug("SkiddingAI", "%s not aligned with track.\n", + Log::debug("SkiddingAI", "%s not aligned with track.", m_kart->getIdent().c_str()); #endif m_controls->m_brake = true; @@ -486,7 +486,7 @@ void SkiddingAI::handleSteering(float dt) #ifdef AI_DEBUG m_debug_sphere[0]->setPosition(QuadGraph::get()->getQuadOfNode(next) .getCenter().toIrrVector()); - Log::debug("skidding_ai","-Outside of road: steer to center point.\n"); + Log::debug("skidding_ai","-Outside of road: steer to center point."); #endif } //If we are going to crash against a kart, avoid it if it doesn't @@ -522,7 +522,7 @@ void SkiddingAI::handleSteering(float dt) #ifdef AI_DEBUG Log::debug("skidding_ai", "- Velocity vector crashes with kart " "and doesn't crashes with road : steer 90 " - "degrees away from kart.\n"); + "degrees away from kart."); #endif } @@ -701,7 +701,7 @@ void SkiddingAI::handleItemCollectionAndAvoidance(Vec3 *aim_point, } if(m_ai_debug) - Log::debug("SkiddingAI", "%s unselects item.\n", + Log::debug("SkiddingAI", "%s unselects item.", m_kart->getIdent().c_str()); // Otherwise remove the pre-selected item (and start // looking for a new item). @@ -771,7 +771,7 @@ void SkiddingAI::handleItemCollectionAndAvoidance(Vec3 *aim_point, .toIrrVector()); #endif if(m_ai_debug) - Log::debug("SkiddingAI", "%s selects item type '%d'.\n", + Log::debug("SkiddingAI", "%s selects item type '%d'.", m_kart->getIdent().c_str(), item_to_collect->getType()); m_item_to_collect = item_to_collect; @@ -795,7 +795,7 @@ void SkiddingAI::handleItemCollectionAndAvoidance(Vec3 *aim_point, #endif if(m_ai_debug) Log::debug("SkiddingAI", - "%s adjusts to hit type %d angle %f.\n", + "%s adjusts to hit type %d angle %f.", m_kart->getIdent().c_str(), item_to_collect->getType(), angle); } @@ -803,7 +803,7 @@ void SkiddingAI::handleItemCollectionAndAvoidance(Vec3 *aim_point, { if(m_ai_debug) Log::debug("SkiddingAI", - "%s won't hit '%d', angle %f.\n", + "%s won't hit '%d', angle %f.", m_kart->getIdent().c_str(), item_to_collect->getType(), angle); } @@ -1378,7 +1378,7 @@ void SkiddingAI::handleItems(const float dt) break; default: Log::error("SkiddingAI", - "Invalid or unhandled powerup '%d' in default AI.\n", + "Invalid or unhandled powerup '%d' in default AI.", m_kart->getPowerup()->getType()); assert(false); } @@ -1699,7 +1699,7 @@ void SkiddingAI::checkCrashes(const Vec3& pos ) if(steps<1 || steps>1000) { Log::warn("SkiddingAI", - "Incorrect STEPS=%d. kart_length %f velocity %f\n", + "Incorrect STEPS=%d. kart_length %f velocity %f", steps, m_kart_length, m_kart->getVelocityLC().getZ()); steps=1000; } @@ -2181,7 +2181,7 @@ bool SkiddingAI::doSkid(float steer_fraction) if(m_ai_debug) { if(fabsf(steer_fraction)>=2.5f) - Log::debug("SkiddingAI", "%s stops skidding (%f).\n", + Log::debug("SkiddingAI", "%s stops skidding (%f).", m_kart->getIdent().c_str(), steer_fraction); } #endif @@ -2201,7 +2201,7 @@ bool SkiddingAI::doSkid(float steer_fraction) #ifdef DEBUG if(m_controls->m_skid && m_ai_debug) { - Log::debug("SkiddingAI", "%s stops skidding on straight.\n", + Log::debug("SkiddingAI", "%s stops skidding on straight.", m_kart->getIdent().c_str()); } #endif @@ -2238,7 +2238,7 @@ bool SkiddingAI::doSkid(float steer_fraction) if(m_controls->m_skid && duration < 1.0f) { if(m_ai_debug) - Log::debug("SkiddingAI", "'%s' too short, stop skid.\n", + Log::debug("SkiddingAI", "'%s' too short, stop skid.", m_kart->getIdent().c_str()); return false; } @@ -2254,7 +2254,7 @@ bool SkiddingAI::doSkid(float steer_fraction) #ifdef DEBUG if(m_controls->m_skid && m_ai_debug) Log::debug("SkiddingAI", - "%s skidding against track direction.\n", + "%s skidding against track direction.", m_kart->getIdent().c_str()); #endif return false; @@ -2265,7 +2265,7 @@ bool SkiddingAI::doSkid(float steer_fraction) { #ifdef DEBUG if(!m_controls->m_skid && m_ai_debug) - Log::debug("SkiddingAI", "%s start skid, duration %f.\n", + Log::debug("SkiddingAI", "%s start skid, duration %f.", m_kart->getIdent().c_str(), duration); #endif return true; @@ -2274,7 +2274,7 @@ bool SkiddingAI::doSkid(float steer_fraction) #ifdef DEBUG if(m_controls->m_skid && m_ai_debug) - Log::debug("SkiddingAI", "%s has no reasons to skid anymore.\n", + Log::debug("SkiddingAI", "%s has no reasons to skid anymore.", m_kart->getIdent().c_str()); #endif return false; diff --git a/src/karts/explosion_animation.cpp b/src/karts/explosion_animation.cpp index 37656b295..53cb0e198 100644 --- a/src/karts/explosion_animation.cpp +++ b/src/karts/explosion_animation.cpp @@ -26,7 +26,6 @@ #include "karts/kart_properties.hpp" #include "modes/world.hpp" #include "tracks/track.hpp" -#include "utils/log.hpp" //TODO: remove after debugging is done /** A static create function that does only create an explosion if * the explosion happens to be close enough to affect the kart. diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index ab06a0acb..cfe52a8e5 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -198,7 +198,7 @@ void Kart::init(RaceManager::KartType type) if(!m_engine_sound) { - Log::error("Kart","Could not allocate a sfx object for the kart. Further errors may ensue!\n"); + Log::error("Kart","Could not allocate a sfx object for the kart. Further errors may ensue!"); } @@ -256,7 +256,7 @@ Kart::~Kart() if(m_slipstream) delete m_slipstream; if(m_sky_particles_emitter) delete m_sky_particles_emitter; if(m_attachment) delete m_attachment; - if (m_stars_effect) delete m_stars_effect; + if(m_stars_effect) delete m_stars_effect; delete m_shadow; diff --git a/src/karts/kart_gfx.cpp b/src/karts/kart_gfx.cpp index fa04661f9..42a5c94f6 100644 --- a/src/karts/kart_gfx.cpp +++ b/src/karts/kart_gfx.cpp @@ -27,6 +27,7 @@ #include "karts/kart_properties.hpp" #include "karts/skidding.hpp" #include "physics/btKart.hpp" +#include "utils/log.hpp" #include @@ -122,7 +123,7 @@ void KartGFX::addEffect(KartGFXType type, const std::string &file_name, // by adding a NULL to the list (which is tested for in all // cases). C++ guarantees that all memory allocated in the // constructor is properly freed. - std::cerr << e.what() << std::endl; + Log::error("[KartGFX]", "%s",e.what()); kind = NULL; emitter = NULL; } diff --git a/src/karts/kart_properties_manager.cpp b/src/karts/kart_properties_manager.cpp index f6e14978a..df0f26a0a 100644 --- a/src/karts/kart_properties_manager.cpp +++ b/src/karts/kart_properties_manager.cpp @@ -189,8 +189,8 @@ bool KartPropertiesManager::loadKart(const std::string &dir) } catch (std::runtime_error& err) { - std::cerr << "Giving up loading '" << config_filename.c_str() - << "' : " << err.what() << std::endl; + Log::error("[Kart_Properties_Manager]","Giving up loading '%s': %s", + config_filename.c_str(), err.what()); return false; } @@ -199,7 +199,7 @@ bool KartPropertiesManager::loadKart(const std::string &dir) if (kart_properties->getVersion() < stk_config->m_min_kart_version || kart_properties->getVersion() > stk_config->m_max_kart_version) { - Log::warn("Kart_Properties_Manager", "Warning: kart '%s' is not " + Log::warn("[Kart_Properties_Manager]", "Warning: kart '%s' is not " "supported by this binary, ignored.", kart_properties->getIdent().c_str()); delete kart_properties; @@ -304,7 +304,7 @@ void KartPropertiesManager::setUnavailableKarts(std::vector karts) { m_kart_available[i] = false; - Log::error("Kart_Properties_Manager", + Log::error("[Kart_Properties_Manager]", "Kart '%s' not available on all clients, disabled.", m_karts_properties[i].getIdent().c_str()); } // kart not in list @@ -425,10 +425,8 @@ void KartPropertiesManager::getRandomKartList(int count, catch (std::runtime_error& ex) { (void)ex; - std::cerr << - "[KartPropertiesManager] getRandomKartList : WARNING, " - "can't find kart '" - << existing_karts[i].getKartName() << "'\n"; + Log::error("[KartPropertiesManager]", "getRandomKartList : WARNING, " + "can't find kart '%s'", existing_karts[i].getKartName().c_str()); } } for(unsigned int i=0; isize(); i++) @@ -441,10 +439,8 @@ void KartPropertiesManager::getRandomKartList(int count, catch (std::runtime_error &ex) { (void)ex; - std::cerr << - "[KartPropertiesManager] getRandomKartList : WARNING, " - "can't find kart '" - << (*ai_list)[i] << "'\n"; + Log::error("[KartPropertiesManager]", "getRandomKartList : WARNING, " + "can't find kart '%s'",(*ai_list)[i].c_str()); } } From c0b13b01ffc2c21ee180cc22ecb2de526bee706b Mon Sep 17 00:00:00 2001 From: KroArtem Date: Fri, 7 Feb 2014 02:17:49 +0400 Subject: [PATCH 2/6] clean src/modes from printf/cout/cerr --- src/karts/kart_properties.cpp | 40 ++++++++-------- src/modes/cutscene_world.cpp | 8 ++-- src/modes/demo_world.cpp | 4 +- src/modes/easter_egg_hunt.cpp | 6 +-- src/modes/follow_the_leader.cpp | 8 ++-- src/modes/linear_world.cpp | 77 +++++++++++++++--------------- src/modes/overworld.cpp | 4 +- src/modes/soccer_world.cpp | 8 ++-- src/modes/three_strikes_battle.cpp | 2 +- src/modes/world.cpp | 16 +++---- src/modes/world_with_rank.cpp | 15 +++--- 11 files changed, 95 insertions(+), 93 deletions(-) diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index 3ac459622..8cd676fe1 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -201,9 +201,9 @@ void KartProperties::load(const std::string &filename, const std::string &node) } catch(std::exception& err) { - Log::error("KartProperties", "Error while parsing KartProperties '%s':\n", + Log::error("[KartProperties]", "Error while parsing KartProperties '%s':", filename.c_str()); - Log::error("KartProperties", "%s\n", err.what()); + Log::error("[KartProperties]", "%s", err.what()); } if(root) delete root; @@ -392,15 +392,15 @@ void KartProperties::getAllData(const XMLNode * root) engine_node->get("power", &m_engine_power); if(m_engine_power.size()!=RaceManager::DIFFICULTY_COUNT) { - Log::fatal("KartProperties", - "Incorrect engine-power specifications for kart '%s'\n", + Log::fatal("[KartProperties]", + "Incorrect engine-power specifications for kart '%s'", getIdent().c_str()); } engine_node->get("max-speed", &m_max_speed); if(m_max_speed.size()!=RaceManager::DIFFICULTY_COUNT) { - Log::fatal("KartProperties", - "Incorrect max-speed specifications for kart '%s'\n", + Log::fatal("[KartProperties]", + "Incorrect max-speed specifications for kart '%s'", getIdent().c_str()); } } // if getNode("engine") @@ -477,8 +477,8 @@ void KartProperties::getAllData(const XMLNode * root) m_terrain_impulse_type = IMPULSE_TO_DRIVELINE; else { - Log::fatal("KartProperties", - "Missing or incorrect value for impulse-type: '%s'.\n", + Log::fatal("[KartProperties]", + "Missing or incorrect value for impulse-type: '%s'.", s.c_str()); } } @@ -560,7 +560,7 @@ void KartProperties::getAllData(const XMLNode * root) else if (s == "small") m_engine_sfx_type = "engine_small"; else { - Log::warn("KartProperties", "Kart '%s' has invalid engine '%s'.", + Log::warn("[KartProperties]", "Kart '%s' has invalid engine '%s'.", m_name.c_str(), s.c_str()); m_engine_sfx_type = "engine_small"; } @@ -603,32 +603,32 @@ void KartProperties::checkAllSet(const std::string &filename) { if(m_gear_switch_ratio.size()==0) { - Log::fatal("KartProperties", - "Missing default value for 'gear-switch-ratio' in '%s'.\n", + Log::fatal("[KartProperties]", + "Missing default value for 'gear-switch-ratio' in '%s'.", filename.c_str()); } if(m_gear_power_increase.size()==0) { - Log::fatal("KartProperties", - "Missing default value for 'gear-power-increase' in '%s'.\n", + Log::fatal("[KartProperties]", + "Missing default value for 'gear-power-increase' in '%s'.", filename.c_str()); } if(m_gear_switch_ratio.size()!=m_gear_power_increase.size()) { Log::error("KartProperties", "Number of entries for 'gear-switch-ratio' and " - "'gear-power-increase\n"); - Log::fatal("KartProperties", "in '%s' must be equal.\n", + "'gear-power-increase"); + Log::fatal("KartProperties", "in '%s' must be equal.", filename.c_str()); } if(m_startup_boost.size()!=m_startup_times.size()) { - Log::error("KartProperties", - "Number of entried for 'startup times' and 'startup-boost\n"); - Log::fatal("KartProperties", "must be identical.\n"); + Log::error("[KartProperties]", + "Number of entried for 'startup times' and 'startup-boost"); + Log::fatal("KartProperties", "must be identical."); } #define CHECK_NEG( a,strA) if(a<=UNDEFINED) { \ - Log::fatal("KartProperties", \ - "Missing default value for '%s' in '%s'.\n", \ + Log::fatal("[KartProperties]", \ + "Missing default value for '%s' in '%s'.", \ strA,filename.c_str()); \ } diff --git a/src/modes/cutscene_world.cpp b/src/modes/cutscene_world.cpp index ea01df566..88178a033 100644 --- a/src/modes/cutscene_world.cpp +++ b/src/modes/cutscene_world.cpp @@ -95,7 +95,7 @@ void CutsceneWorld::init() if (!StringUtils::fromString(frameStr, frame)) { - fprintf(stderr, "[CutsceneWorld] Invalid condition '%s'\n", + Log::error("[CutsceneWorld]", "Invalid condition '%s'", condition.c_str()); continue; } @@ -115,7 +115,7 @@ void CutsceneWorld::init() if (!StringUtils::fromString(frameStr, frame)) { - fprintf(stderr, "[CutsceneWorld] Invalid condition '%s'\n", + Log::error("[CutsceneWorld]", "Invalid condition '%s'", condition.c_str()); continue; } @@ -130,7 +130,7 @@ void CutsceneWorld::init() if (!StringUtils::fromString(frameStr, frame)) { - fprintf(stderr, "[CutsceneWorld] Invalid condition '%s'\n", + Log::error("[CutsceneWorld]", "Invalid condition '%s'", condition.c_str()); continue; } @@ -150,7 +150,7 @@ void CutsceneWorld::init() if (m_duration <= 0.0f) { - fprintf(stderr, "[CutsceneWorld] WARNING: cutscene has no duration\n"); + Log::error("[CutsceneWorld]", "WARNING: cutscene has no duration"); } } // CutsceneWorld diff --git a/src/modes/demo_world.cpp b/src/modes/demo_world.cpp index c78c1abd9..756b640da 100644 --- a/src/modes/demo_world.cpp +++ b/src/modes/demo_world.cpp @@ -119,7 +119,7 @@ bool DemoWorld::updateIdleTimeAndStartDemo(float dt) && m_demo_tracks.size() > 0) { if(!track) - printf("Invalid demo track identifier '%s'.\n", + Log::warn("[DemoWorld]", "Invalid demo track identifier '%s'.", m_demo_tracks[0].c_str()); m_demo_tracks.erase(m_demo_tracks.begin()); track = track_manager->getTrack(m_demo_tracks[0]); @@ -129,7 +129,7 @@ bool DemoWorld::updateIdleTimeAndStartDemo(float dt) // be filled up with all the tracks. if(m_demo_tracks.size()==0) { - printf("No valid tracks found, no demo started.\n"); + Log::warn("[DemoWorld]", "No valid tracks found, no demo started."); return false; } diff --git a/src/modes/easter_egg_hunt.cpp b/src/modes/easter_egg_hunt.cpp index 4d44192cb..5afe05f6f 100644 --- a/src/modes/easter_egg_hunt.cpp +++ b/src/modes/easter_egg_hunt.cpp @@ -42,7 +42,7 @@ void EasterEggHunt::init() // check for possible problems if AI karts were incorrectly added if(getNumKarts() > race_manager->getNumPlayers()) { - fprintf(stderr, "No AI exists for this game mode\n"); + Log::error("EasterEggHunt]", "No AI exists for this game mode"); exit(1); } @@ -70,7 +70,7 @@ void EasterEggHunt::readData(const std::string &filename) if(easter->getName()!="EasterEggHunt") { - printf("Can't load easter egg file '%s' - no EasterEggHunt element.", + Log::error("[EasterEggHunt]", "Can't load easter egg file '%s' - no EasterEggHunt element.", filename.c_str()); delete easter; return; @@ -121,7 +121,7 @@ void EasterEggHunt::readData(const std::string &filename) const XMLNode *egg = data->getNode(i); if(egg->getName()!="easter-egg") { - printf("Unknown node '%s' in easter egg level '%s' - ignored.\n", + Log::warn("[EasterEggHunt]", "Unknown node '%s' in easter egg level '%s' - ignored.", egg->getName().c_str(), race_manager->getDifficultyAsString(act_difficulty).c_str()); continue; diff --git a/src/modes/follow_the_leader.cpp b/src/modes/follow_the_leader.cpp index 005b937ae..f9c4b2f94 100644 --- a/src/modes/follow_the_leader.cpp +++ b/src/modes/follow_the_leader.cpp @@ -108,19 +108,19 @@ void FollowTheLeaderRace::countdownReachedZero() AbstractKart *kart = getKartAtPosition(position_to_remove); if(!kart || kart->isEliminated()) { - fprintf(stderr,"Problem with removing leader: position %d not found\n", + Log::error("[FTL]", "Problem with removing leader: position %d not found", position_to_remove); for(unsigned int i=0; iisEliminated(), m_karts[i]->getPosition()); + Log::error("[FTL]", "kart %u: eliminated %d position %d", + i, m_karts[i]->isEliminated(), m_karts[i]->getPosition()); } // for i } // else { if(UserConfigParams::m_ftl_debug) { - printf("[ftl] Eliminiating kart '%s' at position %d.\n", + Log::debug("[FTL", "Eliminiating kart '%s' at position %d.", kart->getIdent().c_str(), position_to_remove); } eliminateKart(kart->getWorldKartId()); diff --git a/src/modes/linear_world.cpp b/src/modes/linear_world.cpp index b96d7ac98..d4d7b09a8 100644 --- a/src/modes/linear_world.cpp +++ b/src/modes/linear_world.cpp @@ -208,10 +208,10 @@ void LinearWorld::update(float dt) { if(pos_used[m_karts[i]->getPosition()]!=-99) { - for(unsigned int j =0; jgetPosition(), m_karts[j]->hasFinishedRace(), m_kart_info[j].m_race_lap, @@ -553,9 +553,9 @@ float LinearWorld::estimateFinishTimeForKart(AbstractKart* kart) #ifdef DEBUG if(kart_info.m_overall_distance > full_distance) { - printf("WARNING: full distance < distance covered for kart '%s':\n", + Log::debug("[LinearWorld]", "Full distance < distance covered for kart '%s':", kart->getIdent().c_str()); - printf("%f < %f\n", full_distance, kart_info.m_overall_distance); + Log::debug("[LinearWorld]", "%f < %f", full_distance, kart_info.m_overall_distance); } #endif // Avoid potential problems (floating point issues, coding bug?) if a @@ -699,29 +699,29 @@ void LinearWorld::updateRacePosition() rank_changed |= kart->getPosition()!=p; if (!setKartPosition(i,p)) { - std::cerr << "ERROR, same rank used twice!!\n"; + Log::error("[LinearWorld]", "Same rank used twice!!"); - std::cerr << "Info used to decide ranking :\n"; + Log::debug("[LinearWorld]", "Info used to decide ranking :"); for (unsigned int d=0; dgetIdent() - << " has finished(" << m_karts[d]->hasFinishedRace() - << "), is at lap (" << getLapForKart(d) - << "), is at distance(" - << m_kart_info[d].m_overall_distance - << "), is eliminated(" << m_karts[d]->isEliminated() - << ")" << std::endl; + Log::debug("[LinearWorld]", "Kart %s has finished (%d), is at lap (%u)," + "is at distance (%u), is eliminated(%d)", + m_karts[d]->getIdent().c_str(), + m_karts[d]->hasFinishedRace(), + getLapForKart(d), + m_kart_info[d].m_overall_distance, + m_karts[d]->isEliminated()); } - std::cerr << "Who has each ranking so far :\n"; + Log::debug("[LinearWorld]", "Who has each ranking so far :"); for (unsigned int d=0; dgetIdent() << " has rank " - << m_karts[d]->getPosition() << std::endl; + Log::debug("[LinearWorld]", "%s has rank %d", m_karts[d]->getIdent().c_str(), + m_karts[d]->getPosition()); } - std::cerr << " --> And " << kart->getIdent() - << " is being set at rank " << p << std::endl; + Log::debug("[LinearWorld]", " --> And %s is being set at rank %d", + kart->getIdent().c_str(), p); history->Save(); assert(false); } @@ -749,17 +749,18 @@ void LinearWorld::updateRacePosition() #ifdef DEBUG_KART_RANK if(rank_changed) { - std::cout << "Counting laps at "<getIdent() - << " (laps " << m_kart_info[i].m_race_lap - << ", progress " << m_kart_info[i].m_overall_distance - << " finished " << kart->hasFinishedRace() - << " eliminated " << kart->isEliminated() - << " initial position "<< kart->getInitialPosition() - << ").\n"; + Log::debug("[LinearWorld]", "counting karts ahead of %s (laps %u," + " progress %u, finished %d, eliminated %d, initial position %u.", + kart->getIdent().c_str(), + m_kart_info[i].m_race_lap, + m_kart_info[i].m_overall_distance, + kart->hasFinishedRace(), + kart->isEliminated(), + kart->getInitialPosition()); // Karts that are either eliminated or have finished the // race already have their (final) position assigned. If // these karts would get their rank updated, it could happen @@ -776,36 +777,36 @@ void LinearWorld::updateRacePosition() if(j == my_id) continue; if(m_karts[j]->isEliminated()) { - std::cout << " " << p << " : " << m_karts[j]->getIdent() - << " because it is eliminated.\n"; + Log::debug("[LinearWorld]", " %u: %s because it is eliminated.", + p, m_karts[j]->getIdent().c_str()); continue; } if(!kart->hasFinishedRace() && m_karts[j]->hasFinishedRace()) { p++; - std::cout << " " << p << " : " << m_karts[j]->getIdent() - << " because it has finished the race.\n"; + Log::debug("[LinearWorld]", " %u: %s because it has finished the race.", + p, m_karts[j]->getIdent().c_str()); continue; } if(m_kart_info[j].m_overall_distance > my_distance) { p++; - std::cout << " " << p << " : " << m_karts[j]->getIdent() - << " because it is ahead " - << m_kart_info[j].m_overall_distance <<".\n"; + Log::debug("[LinearWorld]", " %u: %s because it is ahead %u.", + p, m_karts[j]->getIdent().c_str(), + m_kart_info[j].m_overall_distance); continue; } if(m_kart_info[j].m_overall_distance == my_distance && m_karts[j]->getInitialPosition()getInitialPosition()) { p++; - std::cout << " " << p << " : " << m_karts[j]->getIdent() - << " has same distance, but started ahead " - << m_karts[j]->getInitialPosition()<<".\n"; + Log::debug("[LinearWorld]"," %u: %s has same distance, but started ahead %d", + p, m_karts[j]->getIdent().c_str(), + m_karts[j]->getInitialPosition()); } } // next kart j } // for igetKart(UserConfigParams::m_default_kart)) { - Log::warn("overworld", "cannot find kart '%s', " - "will revert to default\n", + Log::warn("[overworld]", "cannot find kart '%s', " + "will revert to default", UserConfigParams::m_default_kart.c_str()); UserConfigParams::m_default_kart.revertToDefaults(); diff --git a/src/modes/soccer_world.cpp b/src/modes/soccer_world.cpp index e3e8f8d8d..4331ab500 100644 --- a/src/modes/soccer_world.cpp +++ b/src/modes/soccer_world.cpp @@ -76,7 +76,7 @@ void SoccerWorld::init() // check for possible problems if AI karts were incorrectly added if(getNumKarts() > race_manager->getNumPlayers()) { - fprintf(stderr, "No AI exists for this game mode\n"); + Log::error("[SoccerWorld]", "No AI exists for this game mode"); exit(1); } m_goal_target = race_manager->getMaxGoal(); @@ -85,7 +85,7 @@ void SoccerWorld::init() } // init //----------------------------------------------------------------------------- -/** Called then a battle is restarted. +/** Called when a battle is restarted. */ void SoccerWorld::reset() { @@ -391,8 +391,8 @@ void SoccerWorld::moveKartAfterRescue(AbstractKart* kart) } else { - fprintf(stderr, "WARNING: invalid position after rescue for kart %s on track %s.\n", - (kart->getIdent().c_str()), m_track->getIdent().c_str()); + Log::warn("[SoccerWorld]", " Invalid position after rescue for kart %s on track %s.", + kart->getIdent().c_str(), m_track->getIdent().c_str()); } } // moveKartAfterRescue diff --git a/src/modes/three_strikes_battle.cpp b/src/modes/three_strikes_battle.cpp index c449fea52..185c74598 100644 --- a/src/modes/three_strikes_battle.cpp +++ b/src/modes/three_strikes_battle.cpp @@ -61,7 +61,7 @@ void ThreeStrikesBattle::init() // check for possible problems if AI karts were incorrectly added if(getNumKarts() > race_manager->getNumPlayers()) { - Log::fatal("Three Strikes Battle", "No AI exists for this game mode"); + Log::fatal("[Three Strikes Battle]", "No AI exists for this game mode"); } m_kart_info.resize(m_karts.size()); } // ThreeStrikesBattle diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 34aff5672..5596a2bda 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -332,7 +332,7 @@ Controller* World::loadAIController(AbstractKart *kart) controller = new SkiddingAI(kart); break; default: - Log::warn("World", "Unknown AI, using default."); + Log::warn("[World]", "Unknown AI, using default."); controller = new SkiddingAI(kart); break; } @@ -529,12 +529,12 @@ void World::resetAllKarts() if (!kart_over_ground) { - Log::error("World", + Log::error("[World]", "No valid starting position for kart %d on track %s.", (int)(i-m_karts.begin()), m_track->getIdent().c_str()); if (UserConfigParams::m_artist_debug_mode) { - Log::warn("World", "Activating fly mode."); + Log::warn("[World]", "Activating fly mode."); (*i)->flyUp(); continue; } @@ -580,14 +580,14 @@ void World::resetAllKarts() &normal); if(!material) { - Log::error("World", + Log::error("[World]", "No valid starting position for kart %d " "on track %s.", (int)(i-m_karts.begin()), m_track->getIdent().c_str()); if (UserConfigParams::m_artist_debug_mode) { - Log::warn("World", "Activating fly mode."); + Log::warn("[World]", "Activating fly mode."); (*i)->flyUp(); continue; } @@ -755,7 +755,7 @@ void World::updateWorld(float dt) if (!kart_properties_manager->getKart(UserConfigParams::m_default_kart)) { - Log::warn("World", + Log::warn("[World]", "Cannot find kart '%s', will revert to default.", UserConfigParams::m_default_kart.c_str()); UserConfigParams::m_default_kart.revertToDefaults(); @@ -930,10 +930,10 @@ void World::updateHighscores(int* best_highscore_rank, int* best_finish_time, // the kart location data is wrong #ifdef DEBUG - Log::error("World", "Incorrect kart positions:"); + Log::error("[World]", "Incorrect kart positions:"); for (unsigned int i=0; igetPosition()); } #endif diff --git a/src/modes/world_with_rank.cpp b/src/modes/world_with_rank.cpp index 7db5f6047..ef9ddfce1 100644 --- a/src/modes/world_with_rank.cpp +++ b/src/modes/world_with_rank.cpp @@ -21,6 +21,7 @@ #include "karts/kart_properties.hpp" #include "race/history.hpp" #include "tracks/track.hpp" +#include "utils/log.hpp" #include @@ -85,22 +86,22 @@ bool WorldWithRank::setKartPosition(unsigned int kart_id, assert(m_position_setting_initialised); if(m_position_used[position-1]) { - std::cerr << "== TWO KARTS ARE BEING GIVEN THE SAME POSITION!! ==\n"; + Log::error("[WorldWithRank]", "== TWO KARTS ARE BEING GIVEN THE SAME POSITION!! =="); for (unsigned int j=0; j < m_position_index.size(); j++) { if (!m_position_used[j]) { - std::cout << " No kart is yet set at position " << j+1 - << std::endl; + Log::warn("WorldWithRank]", "No kart is yet set at position %u", j+1); } else { - std::cout << " Kart " << m_position_index[j] - << " is at position " << j << std::endl; + Log::warn("WorldWithRank]", "Kart %u is at position %u", + m_position_index[j], j); } } - std::cout << "Kart " << kart_id << " is being given position " - << position << ", but this position is already taken\n"; + Log::warn("WorldWithRank]", "Kart %u is being given position %u," + "but this position is already taken", + kart_id, position); return false; } m_position_used[position-1] = true; From 746c1ddf5dbfd7c61e8498f1d36e9f71f682c994 Mon Sep 17 00:00:00 2001 From: KroArtem Date: Fri, 7 Feb 2014 15:38:20 +0400 Subject: [PATCH 3/6] clean src/items --- src/items/attachment.cpp | 1 - src/items/flyable.cpp | 6 +++--- src/items/item_manager.cpp | 4 ++-- src/items/plunger.cpp | 2 -- src/items/powerup_manager.cpp | 15 ++++++++------- src/items/rubber_ball.cpp | 16 ++++++++-------- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/items/attachment.cpp b/src/items/attachment.cpp index c3f4e17a6..2689cbd01 100644 --- a/src/items/attachment.cpp +++ b/src/items/attachment.cpp @@ -39,7 +39,6 @@ #include "physics/triangle_mesh.hpp" #include "tracks/track.hpp" #include "utils/constants.hpp" -#include "utils/log.hpp" /** Initialises the attachment each kart has. */ diff --git a/src/items/flyable.cpp b/src/items/flyable.cpp index 9d5525075..4f043a7cd 100644 --- a/src/items/flyable.cpp +++ b/src/items/flyable.cpp @@ -143,9 +143,9 @@ void Flyable::createPhysics(float forw_offset, const Vec3 &velocity, // Just to get some additional information if the assert is triggered if(isnan(v.getX()) || isnan(v.getY()) || isnan(v.getZ())) { - printf("vel %f %f %f v %f %f %f\n", - velocity.getX(),velocity.getY(),velocity.getZ(), - v.getX(),v.getY(),v.getZ()); + Log::debug("[Flyable]", "vel %f %f %f v %f %f %f", + velocity.getX(),velocity.getY(),velocity.getZ(), + v.getX(),v.getY(),v.getZ()); } #endif assert(!isnan(v.getX())); diff --git a/src/items/item_manager.cpp b/src/items/item_manager.cpp index f740088dc..2072b1063 100644 --- a/src/items/item_manager.cpp +++ b/src/items/item_manager.cpp @@ -97,8 +97,8 @@ void ItemManager::loadDefaultItemMeshes() scene::IMesh *mesh = irr_driver->getAnimatedMesh(model_filename); if(!node || model_filename.size()==0 || !mesh) { - fprintf(stderr, "Item model '%s' in items.xml could not be loaded " - "- aborting", name.c_str()); + Log::fatal("[ItemManager]", "Item model '%s' in items.xml could not be loaded " + "- aborting", name.c_str()); exit(-1); } mesh->grab(); diff --git a/src/items/plunger.cpp b/src/items/plunger.cpp index ca7ea56f0..8925ce1b7 100644 --- a/src/items/plunger.cpp +++ b/src/items/plunger.cpp @@ -34,8 +34,6 @@ #include "utils/constants.hpp" #include "utils/string_utils.hpp" -#include "utils/log.hpp" //TODO: remove after debugging is done - // ----------------------------------------------------------------------------- Plunger::Plunger(AbstractKart *kart) : Flyable(kart, PowerupManager::POWERUP_PLUNGER) diff --git a/src/items/powerup_manager.cpp b/src/items/powerup_manager.cpp index defd22a73..e73661388 100644 --- a/src/items/powerup_manager.cpp +++ b/src/items/powerup_manager.cpp @@ -125,8 +125,8 @@ void PowerupManager::loadAllPowerups() LoadPowerup(type, *node); else { - printf("Can't find item '%s' from powerup.xml, entry %d/\n", - name.c_str(), i+1); + Log::fatal("[PowerupManager]", "Can't find item '%s' from powerup.xml, entry %d/", + name.c_str(), i+1); exit(-1); } } @@ -157,7 +157,7 @@ void PowerupManager::LoadPowerup(PowerupType type, const XMLNode &node) #ifdef DEBUG if (icon_file.size() == 0) { - fprintf(stderr, "Cannot load powerup %i, no 'icon' attribute under XML node\n", type); + Log::debug("[PowerupManager]", "Cannot load powerup %i, no 'icon' attribute under XML node", type); assert(false); } #endif @@ -221,8 +221,9 @@ void PowerupManager::loadWeights(const XMLNode &root, if(!node || s=="" || s_multi=="") { - printf("No weights found for class '%s' - probabilities will be incorrect.\n", - class_name.c_str()); + Log::error("[PowerupManager]", "No weights found for class '%s'" + " - probabilities will be incorrect.", + class_name.c_str()); return; } @@ -245,9 +246,9 @@ void PowerupManager::loadWeights(const XMLNode &root, if(weight_list.size()!=2*(int)POWERUP_LAST) { - printf("Incorrect number of weights found in class '%s':\n", + Log::error("[PowerupManager]", "Incorrect number of weights found in class '%s':", class_name.c_str()); - printf("%d instead of %d - probabilities will be incorrect.\n", + Log::error("[PowerupManager]", "%d instead of %d - probabilities will be incorrect.", (int)weight_list.size(), (int)POWERUP_LAST); return; } diff --git a/src/items/rubber_ball.cpp b/src/items/rubber_ball.cpp index b8086a759..36a252636 100644 --- a/src/items/rubber_ball.cpp +++ b/src/items/rubber_ball.cpp @@ -158,7 +158,7 @@ void RubberBall::computeTarget() if(m_target==m_owner && m_delete_timer < 0) { #ifdef PRINT_BALL_REMOVE_INFO - Log::debug("RubberBall", + Log::debug("[RubberBall]", "ball %d removed because owner is target.", m_id); #endif m_delete_timer = m_st_delete_time; @@ -171,7 +171,7 @@ void RubberBall::computeTarget() // aim at the owner (the ball is unlikely to hit it), and // this will trigger the usage of the delete time in updateAndDelete #ifdef PRINT_BALL_REMOVE_INFO - Log::debug("RubberBall" "ball %d removed because no more active target.", + Log::debug("[RubberBall]" "ball %d removed because no more active target.", m_id); #endif m_delete_timer = m_st_delete_time; @@ -312,7 +312,7 @@ bool RubberBall::updateAndDelete(float dt) { hit(NULL); #ifdef PRINT_BALL_REMOVE_INFO - Log::debug("RubberBall", "ball %d deleted.", m_id); + Log::debug("[RubberBall]", "ball %d deleted.", m_id); #endif return true; } @@ -355,7 +355,7 @@ bool RubberBall::updateAndDelete(float dt) float new_y = getHoT()+height; if(UserConfigParams::logFlyable()) - printf("ball %d: %f %f %f height %f new_y %f gethot %f ", + Log::debug("[RubberBall]", "ball %d: %f %f %f height %f new_y %f gethot %f ", m_id, next_xyz.getX(), next_xyz.getY(), next_xyz.getZ(), height, new_y, getHoT()); // No need to check for terrain height if the ball is low to the ground @@ -503,7 +503,7 @@ bool RubberBall::checkTunneling() if(m_tunnel_count > 3) { #ifdef PRINT_BALL_REMOVE_INFO - Log::debug("RubberBall", + Log::debug("[RubberBall]", "Ball %d nearly tunneled at %f %f %f -> %f %f %f", m_id, m_previous_xyz.getX(),m_previous_xyz.getY(), m_previous_xyz.getZ(), @@ -627,7 +627,7 @@ void RubberBall::updateDistanceToTarget() m_distance_to_target += world->getTrack()->getTrackLength(); } if(UserConfigParams::logFlyable()) - printf("ball %d: target %f %f %f distance_2_target %f", + Log::debug("[RubberBall]", "ball %d: target %f %f %f distance_2_target %f", m_id, m_target->getXYZ().getX(),m_target->getXYZ().getY(), m_target->getXYZ().getZ(),m_distance_to_target ); @@ -657,7 +657,7 @@ void RubberBall::updateDistanceToTarget() { m_delete_timer = m_st_delete_time; #ifdef PRINT_BALL_REMOVE_INFO - Log::debug("RubberBall", "ball %d lost target (overtook?).", + Log::debug("[RubberBall]", "ball %d lost target (overtook?).", m_id); #endif @@ -690,7 +690,7 @@ bool RubberBall::hit(AbstractKart* kart, PhysicalObject* object) { #ifdef PRINT_BALL_REMOVE_INFO if(kart) - Log::debug("RuberBall", "ball %d hit kart.", m_id); + Log::debug("[RuberBall]", "ball %d hit kart.", m_id); #endif if(kart && kart!=m_target) { From 591e421b102772e2328ae15159d9de656869beb4 Mon Sep 17 00:00:00 2001 From: KroArtem Date: Fri, 7 Feb 2014 16:23:46 +0400 Subject: [PATCH 4/6] clean src/io --- src/io/file_manager.cpp | 62 ++++++++++++++++++++--------------------- src/io/xml_node.cpp | 50 ++++++++++++++++----------------- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/io/file_manager.cpp b/src/io/file_manager.cpp index 12db2079c..37bf5c1e1 100644 --- a/src/io/file_manager.cpp +++ b/src/io/file_manager.cpp @@ -64,7 +64,7 @@ std::vector FileManager::m_root_dirs; bool macSetBundlePathIfRelevant(std::string& data_dir) { - Log::debug("FileManager", "Checking whether we are using an app bundle... "); + Log::debug("[FileManager]", "Checking whether we are using an app bundle... "); // the following code will enable STK to find its data when placed in an // app bundle on mac OS X. // returns true if path is set, returns false if path was not set @@ -82,14 +82,14 @@ bool macSetBundlePathIfRelevant(std::string& data_dir) std::string contents = std::string(path) + std::string("/Contents"); if(contents.find(".app") != std::string::npos) { - Log::debug("FileManager", "yes\n"); + Log::debug("[FileManager]", "yes"); // executable is inside an app bundle, use app bundle-relative paths data_dir = contents + std::string("/Resources/"); return true; } else { - Log::debug("FileManager", "no\n"); + Log::debug("[FileManager]", "no"); return false; } } @@ -197,13 +197,13 @@ FileManager::FileManager() // We can't use _() here, since translations will only be initalised // after the filemanager (to get the path to the tranlsations from it) for(unsigned int i=0; iexistFile(io::path(path.c_str()))) return true; - std::cout << "[FileManager] Creating directory(ies) '" << path << "'.\n"; + Log::info("[FileManager]", "Creating directory(ies) '%s'", path.c_str()); std::vector split = StringUtils::split(path,'/'); std::string current_path = ""; for (unsigned int i=0; iexistFile(io::path(current_path.c_str()))) { if (!checkAndCreateDirectory(current_path)) { - Log::error("FileManager", "Can't create dir '%s'", + Log::error("[FileManager]", "Can't create dir '%s'", current_path.c_str()); break; } @@ -684,8 +684,8 @@ void FileManager::checkAndCreateConfigDir() m_user_config_dir = getenv("APPDATA"); if(!checkAndCreateDirectory(m_user_config_dir)) { - std::cerr << "[FileManager] Can't create config dir '" - << m_user_config_dir << "', falling back to '.'.\n"; + Log::error("[FileManager]", "Can't create config dir '%s" + ", falling back to '.'.", m_user_config_dir); m_user_config_dir = "."; } } @@ -702,8 +702,8 @@ void FileManager::checkAndCreateConfigDir() } else { - std::cerr << - "[FileManager] No home directory, this should NOT happen!\n"; + Log::error("[FileManager]", + "No home directory, this should NOT happen!"); // Fall back to system-wide app data (rather than // user-specific data), but should not happen anyway. m_user_config_dir = ""; @@ -721,9 +721,9 @@ void FileManager::checkAndCreateConfigDir() } else if (!getenv("HOME")) { - std::cerr - << "[FileManager] No home directory, this should NOT happen " - << "- trying '.' for config files!\n"; + Log::error("[FileManager]", + "No home directory, this should NOT happen " + "- trying '.' for config files!"); m_user_config_dir = "."; } else @@ -733,9 +733,9 @@ void FileManager::checkAndCreateConfigDir() if(!checkAndCreateDirectory(m_user_config_dir)) { // If $HOME/.config can not be created: - std::cerr << "[FileManager] Cannot create directory '" - << m_user_config_dir <<"', falling back to use '" - << getenv("HOME")<< "'.\n"; + Log::error("[FileManager]", + "Cannot create directory '%s', falling back to use '%s'", + m_user_config_dir.c_str(), getenv("HOME")); m_user_config_dir = getenv("HOME"); } } diff --git a/src/io/xml_node.cpp b/src/io/xml_node.cpp index 153327b3a..092dde423 100644 --- a/src/io/xml_node.cpp +++ b/src/io/xml_node.cpp @@ -56,8 +56,8 @@ XMLNode::XMLNode(const std::string &filename) { if(!is_first_element) { - fprintf(stderr, - "More than one root element in '%s' - ignored.\n", + Log::warn("[XMLNode]", + "More than one root element in '%s' - ignored.", filename.c_str()); } readXML(xml); @@ -223,8 +223,8 @@ int XMLNode::get(const std::string &attribute, Vec3 *value) const std::vector v = StringUtils::split(s,' '); if (v.size() != 3) { - fprintf(stderr, "[XMLNode] WARNING: Expected 3 floating-point values, but found '%s' in file %s\n", - s.c_str(), m_file_name.c_str()); + Log::warn("[XMLNode]", "WARNING: Expected 3 floating-point values, but found '%s' in file %s", + s.c_str(), m_file_name.c_str()); return 0; } @@ -240,8 +240,8 @@ int XMLNode::get(const std::string &attribute, Vec3 *value) const } else { - fprintf(stderr, "[XMLNode] WARNING: Expected 3 floating-point values, but found '%s' in file %s\n", - s.c_str(), m_file_name.c_str()); + Log::warn("[XMLNode]", "WARNING: Expected 3 floating-point values, but found '%s' in file %s", + s.c_str(), m_file_name.c_str()); return 0; } @@ -305,8 +305,8 @@ int XMLNode::get(const std::string &attribute, int32_t *value) const if (!StringUtils::parseString(s, value)) { - fprintf(stderr, "[XMLNode] WARNING: Expected int but found '%s' for attribute '%s' of node '%s' in file %s\n", - s.c_str(), attribute.c_str(), m_name.c_str(), m_file_name.c_str()); + Log::warn("[XMLNode]", "WARNING: Expected int but found '%s' for attribute '%s' of node '%s' in file %s", + s.c_str(), attribute.c_str(), m_name.c_str(), m_file_name.c_str()); return 0; } @@ -321,8 +321,8 @@ int XMLNode::get(const std::string &attribute, int64_t *value) const if (!StringUtils::parseString(s, value)) { - fprintf(stderr, "[XMLNode] WARNING: Expected int but found '%s' for attribute '%s' of node '%s' in file %s\n", - s.c_str(), attribute.c_str(), m_name.c_str(), m_file_name.c_str()); + Log::warn("[XMLNode]", "WARNING: Expected int but found '%s' for attribute '%s' of node '%s' in file %s", + s.c_str(), attribute.c_str(), m_name.c_str(), m_file_name.c_str()); return 0; } @@ -338,8 +338,8 @@ int XMLNode::get(const std::string &attribute, uint16_t *value) const if (!StringUtils::parseString(s, value)) { - fprintf(stderr, "[XMLNode] WARNING: Expected uint but found '%s' for attribute '%s' of node '%s' in file %s\n", - s.c_str(), attribute.c_str(), m_name.c_str(), m_file_name.c_str()); + Log::warn("[XMLNode]", "WARNING: Expected uint but found '%s' for attribute '%s' of node '%s' in file %s", + s.c_str(), attribute.c_str(), m_name.c_str(), m_file_name.c_str()); return 0; } @@ -354,8 +354,8 @@ int XMLNode::get(const std::string &attribute, uint32_t *value) const if (!StringUtils::parseString(s, value)) { - fprintf(stderr, "[XMLNode] WARNING: Expected uint but found '%s' for attribute '%s' of node '%s' in file %s\n", - s.c_str(), attribute.c_str(), m_name.c_str(), m_file_name.c_str()); + Log::warn("[XMLNode]", "WARNING: Expected uint but found '%s' for attribute '%s' of node '%s' in file %s", + s.c_str(), attribute.c_str(), m_name.c_str(), m_file_name.c_str()); return 0; } @@ -370,8 +370,8 @@ int XMLNode::get(const std::string &attribute, float *value) const if (!StringUtils::parseString(s, value)) { - fprintf(stderr, "[XMLNode] WARNING: Expected float but found '%s' for attribute '%s' of node '%s' in file %s\n", - s.c_str(), attribute.c_str(), m_name.c_str(), m_file_name.c_str()); + Log::warn("[XMLNode]", "WARNING: Expected float but found '%s' for attribute '%s' of node '%s' in file %s", + s.c_str(), attribute.c_str(), m_name.c_str(), m_file_name.c_str()); return 0; } @@ -429,8 +429,8 @@ int XMLNode::get(const std::string &attribute, float curr; if (!StringUtils::parseString(v[i], &curr)) { - fprintf(stderr, "[XMLNode] WARNING: Expected float but found '%s' for attribute '%s' of node '%s' in file %s\n", - v[i].c_str(), attribute.c_str(), m_name.c_str(), m_file_name.c_str()); + Log::warn("[XMLNode]", "WARNING: Expected float but found '%s' for attribute '%s' of node '%s' in file %s", + v[i].c_str(), attribute.c_str(), m_name.c_str(), m_file_name.c_str()); return 0; } @@ -460,8 +460,8 @@ int XMLNode::get(const std::string &attribute, std::vector *value) const int val; if (!StringUtils::parseString(v[i], &val)) { - fprintf(stderr, "[XMLNode] WARNING: Expected int but found '%s' for attribute '%s' of node '%s'\n", - v[i].c_str(), attribute.c_str(), m_name.c_str()); + Log::warn("[XMLNode]", "WARNING: Expected int but found '%s' for attribute '%s' of node '%s'", + v[i].c_str(), attribute.c_str(), m_name.c_str()); return 0; } @@ -490,22 +490,22 @@ int XMLNode::get(const std::string &attribute, InterpolationArray *value) const std::vector pair = StringUtils::split(pairs[i],':'); if(pair.size()!=2) { - printf("Incorrect interpolation pair '%s' in '%s'.\n", - pairs[i].c_str(), attribute.c_str()); - printf("Must be x:y.\n"); + Log::fatal("[XMLNode]", "Incorrect interpolation pair '%s' in '%s'.", + pairs[i].c_str(), attribute.c_str()); + Log::fatal("[XMLNode]", "Must be x:y."); exit(-1); } float x; if(!StringUtils::fromString(pair[0], x)) { - printf("Incorrect x in pair '%s' of '%s'.\n", + Log::fatal("[XMLNode]", "Incorrect x in pair '%s' of '%s'.", pairs[i].c_str(), attribute.c_str()); exit(-1); } float y; if(!StringUtils::fromString(pair[1], y)) { - printf("Incorrect y in pair '%s' in '%s'.\n", + Log::fatal("[XMLNode]", "Incorrect y in pair '%s' in '%s'.", pair[1].c_str(), attribute.c_str()); exit(-1); } From fde38a35afa521cc177cb9e77302e108813ad242 Mon Sep 17 00:00:00 2001 From: KroArtem Date: Fri, 7 Feb 2014 16:45:38 +0400 Subject: [PATCH 5/6] clean src/addons --- src/addons/addons_manager.cpp | 40 +++++++++++++++++------------------ src/addons/news_manager.cpp | 6 ++---- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/addons/addons_manager.cpp b/src/addons/addons_manager.cpp index a713d176a..79f8af473 100644 --- a/src/addons/addons_manager.cpp +++ b/src/addons/addons_manager.cpp @@ -194,7 +194,7 @@ void AddonsManager::initAddons(const XMLNode *xml) if(file_manager->fileExists(full_path)) { if(UserConfigParams::logAddons()) - Log::warn("[addons] Removing cached icon '%s'.\n", + Log::warn("[AddonsManager] Removing cached icon '%s'.\n", addon.getIconBasename().c_str()); file_manager->removeFile(full_path); } @@ -225,10 +225,9 @@ void AddonsManager::initAddons(const XMLNode *xml) } else { - fprintf(stderr, - "[addons] Found invalid node '%s' while downloading addons.\n", + Log::error("[AddonsManager]", "Found invalid node '%s' while downloading addons.", node->getName().c_str()); - fprintf(stderr, "[addons] Ignored.\n"); + Log::error("[AddonsManager]", "Ignored."); } } // for igetNumNodes delete xml; @@ -254,7 +253,7 @@ void AddonsManager::initAddons(const XMLNode *xml) // it from the list. if(UserConfigParams::logAddons()) Log::warn( - "[addons] Removing '%s' which is not on the server anymore.\n", + "[AddonsManager] Removing '%s' which is not on the server anymore.\n", m_addons_list.getData()[i].getId().c_str() ); std::string icon = m_addons_list.getData()[i].getIconBasename(); std::string icon_file =file_manager->getAddonsFile("icons/"+icon); @@ -311,7 +310,7 @@ void AddonsManager::checkInstalledAddons() if(n<0) continue; if(!m_addons_list.getData()[n].isInstalled()) { - Log::info("[addons] Marking '%s' as being installed.", + Log::info("[AddonsManager] Marking '%s' as being installed.", kp->getIdent().c_str()); m_addons_list.getData()[n].setInstalled(true); something_was_changed = true; @@ -330,7 +329,7 @@ void AddonsManager::checkInstalledAddons() if(n<0) continue; if(!m_addons_list.getData()[n].isInstalled()) { - Log::info("[addons] Marking '%s' as being installed.", + Log::info("[AddonsManager] Marking '%s' as being installed.", track->getIdent().c_str()); m_addons_list.getData()[n].setInstalled(true); something_was_changed = true; @@ -361,9 +360,8 @@ void AddonsManager::downloadIcons() if(icon=="") { if(UserConfigParams::logAddons()) - fprintf(stderr, - "[addons] No icon or image specified for '%s'.\n", - addon.getId().c_str()); + Log::error("[AddonsManager]", "No icon or image specified for '%s'.", + addon.getId().c_str()); continue; } @@ -401,8 +399,8 @@ void AddonsManager::loadInstalledAddons() /* checking for installed addons */ if(UserConfigParams::logAddons()) { - std::cout << "[addons] Loading an xml file for installed addons: "; - std::cout << m_file_installed << std::endl; + Log::info("[AddonsManager]", "Loading an xml file for installed addons: %s", + m_file_installed.c_str()); } const XMLNode *xml = file_manager->createXMLTree(m_file_installed); if(!xml) @@ -479,16 +477,16 @@ bool AddonsManager::install(const Addon &addon) if (!success) { // TODO: show a message in the interface - std::cerr << "[addons] Failed to unzip '" << from << "' to '" - << to << "'\n"; - std::cerr << "[addons] Zip file will not be removed.\n"; + Log::error("[AddonsManager]", "Failed to unzip '%s' to '%s'", + from.c_str(), to.c_str()); + Log::error("[AddonsManager]", "Zip file will not be removed."); return false; } if(!file_manager->removeFile(from)) { - std::cerr << "[addons] Problems removing temporary file '" - << from << "'.\n"; + Log::error("[AddonsManager]", "Problems removing temporary file '%s'", + from.c_str()); } int index = getAddonIndex(addon.getId()); @@ -521,8 +519,8 @@ bool AddonsManager::install(const Addon &addon) } catch (std::exception& e) { - fprintf(stderr, "[AddonsManager] ERROR: Cannot load track <%s> : %s\n", - addon.getDataDir().c_str(), e.what()); + Log::error("[AddonsManager]", "ERROR: Cannot load track <%s> : %s", + addon.getDataDir().c_str(), e.what()); } } saveInstalled(); @@ -536,8 +534,8 @@ bool AddonsManager::install(const Addon &addon) */ bool AddonsManager::uninstall(const Addon &addon) { - std::cout << "[addons] Uninstalling <" - << core::stringc(addon.getName()).c_str() << ">\n"; + Log::info("[AddonsManager]", "Uninstalling <%s>", + core::stringc(addon.getName()).c_str()); // addon is a const reference, and to avoid removing the const, we // find the proper index again to modify the installed state diff --git a/src/addons/news_manager.cpp b/src/addons/news_manager.cpp index 2c001a678..3f6671859 100644 --- a/src/addons/news_manager.cpp +++ b/src/addons/news_manager.cpp @@ -208,10 +208,8 @@ void NewsManager::checkRedirect(const XMLNode *xml) { if(UserConfigParams::logAddons()) { - std::cout << "[Addons] Current server: " - << (std::string)UserConfigParams::m_server_addons - << std::endl - << "[Addons] New server: " << new_server << std::endl; + Log::info("[Addons]", "Current server: '%s'\n [Addons] New server: '%s'", + UserConfigParams::m_server_addons.c_str(), new_server.c_str()); } UserConfigParams::m_server_addons = new_server; } From 1861c6533a20015b2a744251e8dd4759c4b14c56 Mon Sep 17 00:00:00 2001 From: KroArtem Date: Sat, 8 Feb 2014 01:21:39 +0400 Subject: [PATCH 6/6] small fix: mismatching allocation/deallocation --- src/network/stk_host.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/stk_host.cpp b/src/network/stk_host.cpp index 001130420..a6d82edfc 100644 --- a/src/network/stk_host.cpp +++ b/src/network/stk_host.cpp @@ -73,7 +73,7 @@ void* STKHost::receive_data(void* self) } } myself->m_listening = false; - delete myself->m_listening_thread; + free(myself->m_listening_thread); myself->m_listening_thread = NULL; Log::info("STKHost", "Listening has been stopped"); return NULL;