clean src/modes from printf/cout/cerr

This commit is contained in:
KroArtem 2014-02-07 02:17:49 +04:00
parent a61ee58a39
commit c0b13b01ff
11 changed files with 95 additions and 93 deletions

View File

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

View File

@ -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

View File

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

View File

@ -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;

View File

@ -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; i<m_karts.size(); i++)
{
fprintf(stderr,"kart %d: eliminated %d position %d\n",
i,m_karts[i]->isEliminated(), 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());

View File

@ -208,10 +208,10 @@ void LinearWorld::update(float dt)
{
if(pos_used[m_karts[i]->getPosition()]!=-99)
{
for(unsigned int j =0; j<kart_amount; j++)
for(unsigned int j=0; j<kart_amount; j++)
{
printf("kart id=%d, position=%d, finished=%d, laps=%d, "
"distanceDownTrack=%f overallDistance=%f %s\n",
Log::verbose("[LinearWorld]", "kart id=%u, position=%d, finished=%d, laps=%d, "
"distanceDownTrack=%f overallDistance=%f %s",
j, m_karts[j]->getPosition(),
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; d<kart_amount; d++)
{
std::cerr << " kart " << m_karts[d]->getIdent()
<< " 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; d<i; d++)
{
std::cerr << " " << m_karts[d]->getIdent() << " 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 "<<getTime()<<" seconds.\n";
Log::debug("[LinearWorld]", "Counting laps at %u seconds.", getTime());
for (unsigned int i=0; i<kart_amount; i++)
{
AbstractKart* kart = m_karts[i];
std::cout << "counting karts ahead of " << kart->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()<kart->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 i<kart_amount
std::cout << "-------------------------------------------\n";
Log::debug("LinearWorld]", "-------------------------------------------");
} // if rank_changed
#endif
#endif

View File

@ -68,8 +68,8 @@ void OverWorld::enterOverWorld()
if (!kart_properties_manager->getKart(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();

View File

@ -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

View File

@ -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

View File

@ -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; i<m_karts.size(); i++ )
{
Log::error("World", "i=%d position %d.",i,
Log::error("[World]", "i=%d position %d.",i,
m_karts[i]->getPosition());
}
#endif

View File

@ -21,6 +21,7 @@
#include "karts/kart_properties.hpp"
#include "race/history.hpp"
#include "tracks/track.hpp"
#include "utils/log.hpp"
#include <iostream>
@ -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;