Improved handling of controller name so that the end

controller keeps the name of the original controller, 
which allows proper statistic output in profile mode.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11287 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2012-06-09 15:48:18 +00:00
parent 7f28171b73
commit 6536b4d112
9 changed files with 29 additions and 25 deletions

View File

@@ -52,7 +52,7 @@ AIBaseController::AIBaseController(AbstractKart *kart,
m_all_look_aheads.clear();
m_successor_index.clear();
} // if battle mode
setControllerName("AIBaseController");
} // AIBaseController
//-----------------------------------------------------------------------------

View File

@@ -32,14 +32,7 @@ Controller::Controller(AbstractKart *kart, StateManager::ActivePlayer *player)
m_controls = &(kart->getControls());
m_kart = kart;
m_player = player;
setControllerName("Controller");
} // Controller
// ----------------------------------------------------------------------------
const irr::core::stringw& Controller::getNamePostfix() const
{
// Static to avoid returning the address of a temporary stringq
static irr::core::stringw name("");
return name;
} // getNamePostfix
// ----------------------------------------------------------------------------

View File

@@ -54,6 +54,9 @@ protected:
/** If this belongs to a player, it stores the active player data
* structure. Otherwise it is 0. */
StateManager::ActivePlayer *m_player;
/** The name of the controller, mainly used for debugging purposes. */
std::string m_controller_name;
public:
Controller (AbstractKart *kart,
StateManager::ActivePlayer *player=NULL);
@@ -69,7 +72,12 @@ public:
virtual void finishedRace (float time) = 0;
virtual bool isPlayerController () const = 0;
virtual bool isNetworkController() const = 0;
virtual const irr::core::stringw& getNamePostfix() const;
// ---------------------------------------------------------------------------
/** Sets the controller name for this controller. */
void setControllerName(const std::string &name) {m_controller_name = name; }
// ---------------------------------------------------------------------------
/** Returns the name of this controller. */
const std::string &getControllerName() const { return m_controller_name; }
// ---------------------------------------------------------------------------
/** Returns the active player for this controller (NULL
* if this controller does not belong to a player. */

View File

@@ -107,6 +107,7 @@ DefaultAIController::DefaultAIController(AbstractKart *kart)
#ifdef AI_DEBUG
m_debug_sphere = irr_driver->getSceneManager()->addSphereSceneNode(1);
#endif
setControllerName("DefaultAI");
} // DefaultAIController
//-----------------------------------------------------------------------------
@@ -149,14 +150,6 @@ void DefaultAIController::reset()
AIBaseController::reset();
} // reset
//-----------------------------------------------------------------------------
const irr::core::stringw& DefaultAIController::getNamePostfix() const
{
// Static to avoid returning the address of a temporary stringq
static irr::core::stringw name="(default)";
return name;
} // getNamePostfix
//-----------------------------------------------------------------------------
/** Returns the pre-computed successor of a graph node.
* \parameter index The index of the graph node for which the successor

View File

@@ -150,7 +150,6 @@ public:
~DefaultAIController();
virtual void update (float delta) ;
virtual void reset ();
virtual const irr::core::stringw& getNamePostfix() const;
};
#endif

View File

@@ -50,7 +50,8 @@
#include "tracks/track.hpp"
#include "utils/constants.hpp"
EndController::EndController(AbstractKart *kart, StateManager::ActivePlayer *player)
EndController::EndController(AbstractKart *kart, StateManager::ActivePlayer *player,
Controller *prev_controller)
: AIBaseController(kart, player)
{
if(race_manager->getMinorMode()!=RaceManager::MINOR_MODE_3_STRIKES)
@@ -102,6 +103,10 @@ EndController::EndController(AbstractKart *kart, StateManager::ActivePlayer *pla
m_debug_sphere = irr_driver->getSceneManager()->addSphereSceneNode(1);
#endif
m_kart->setSlowdown(MaxSpeed::MS_DECREASE_AI, 0.3f, 2);
// Set the name of the previous controller as this controller name, otherwise
// we get the incorrect name when printing statistics in profile mode.
setControllerName(prev_controller->getControllerName());
} // EndController
//-----------------------------------------------------------------------------

View File

@@ -78,7 +78,8 @@ private:
int calcSteps();
public:
EndController(AbstractKart *kart,
StateManager::ActivePlayer* player);
StateManager::ActivePlayer* player,
Controller *prev_controller);
~EndController();
virtual void update (float delta) ;
virtual void reset ();

View File

@@ -744,7 +744,8 @@ void Kart::finishedRace(float time)
race_manager->getMinorMode() == RaceManager::MINOR_MODE_TIME_TRIAL)
{
// in modes that support it, start end animation
setController(new EndController(this, m_controller->getPlayer()));
setController(new EndController(this, m_controller->getPlayer(),
m_controller));
if(m_race_position<=0.5f*race_manager->getNumberOfKarts() ||
m_race_position==1)
m_kart_model->setAnimation(KartModel::AF_WIN_START);
@@ -764,7 +765,8 @@ void Kart::finishedRace(float time)
else if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_FOLLOW_LEADER)
{
// start end animation
setController(new EndController(this, m_controller->getPlayer()));
setController(new EndController(this, m_controller->getPlayer(),
m_controller));
if(m_race_position<=2)
m_kart_model->setAnimation(KartModel::AF_WIN_START);
else if(m_race_position>=0.7f*race_manager->getNumberOfKarts())
@@ -782,7 +784,8 @@ void Kart::finishedRace(float time)
}
else if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_3_STRIKES)
{
setController(new EndController(this, m_controller->getPlayer()));
setController(new EndController(this, m_controller->getPlayer(),
m_controller));
}
} // finishedRace

View File

@@ -22,6 +22,7 @@
#include "graphics/camera.hpp"
#include "graphics/irr_driver.hpp"
#include "karts/kart_with_stats.hpp"
#include "karts/controller/controller.hpp"
#include "tracks/track.hpp"
#include <ISceneManager.h>
@@ -222,7 +223,8 @@ void ProfileWorld::enterRaceOverState()
max_t = std::max(max_t, kart->getFinishTime());
min_t = std::min(min_t, kart->getFinishTime());
av_t += kart->getFinishTime();
printf("%s,", kart->getIdent().c_str());
printf("%s %s,", kart->getIdent().c_str(),
kart->getController()->getControllerName().c_str());
printf("%d,", 1 + (int)i);
printf("%d,", kart->getPosition());
printf("%4.2f,", kart->getFinishTime());