Added more statistics for profile mode:
skidding-time, and time+count for rescues and exposions. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9399 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
2fe73a6deb
commit
029e50381d
@ -280,6 +280,8 @@ add_executable(supertuxkart
|
||||
src/karts/emergency_animation.hpp
|
||||
src/karts/kart.cpp
|
||||
src/karts/kart.hpp
|
||||
src/karts/kart_with_stats.cpp
|
||||
src/karts/kart_with_stats.hpp
|
||||
src/karts/kart_model.cpp
|
||||
src/karts/kart_model.hpp
|
||||
src/karts/kart_properties.cpp
|
||||
|
@ -210,6 +210,8 @@ supertuxkart_SOURCES = \
|
||||
karts/emergency_animation.hpp \
|
||||
karts/kart.cpp \
|
||||
karts/kart.hpp \
|
||||
karts/kart_with_stats.cpp \
|
||||
karts/kart_with_stats.hpp \
|
||||
karts/kart_model.cpp \
|
||||
karts/kart_model.hpp \
|
||||
karts/kart_properties.cpp \
|
||||
|
@ -642,6 +642,10 @@
|
||||
RelativePath="..\..\karts\kart_properties_manager.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\karts\kart_with_stats.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\karts\max_speed.cpp"
|
||||
>
|
||||
@ -1716,6 +1720,10 @@
|
||||
RelativePath="..\..\karts\kart_properties_manager.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\karts\kart_with_stats.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\karts\max_speed.hpp"
|
||||
>
|
||||
|
@ -76,12 +76,12 @@ protected:
|
||||
enum {EA_NONE, EA_RESCUE, EA_EXPLOSION}
|
||||
m_kart_mode;
|
||||
public:
|
||||
EmergencyAnimation(Kart *kart);
|
||||
~EmergencyAnimation();
|
||||
void reset();
|
||||
void handleExplosion(const Vec3& pos, bool direct_hit);
|
||||
void forceRescue(bool is_auto_rescue=false);
|
||||
void update(float dt);
|
||||
EmergencyAnimation(Kart *kart);
|
||||
~EmergencyAnimation();
|
||||
void reset();
|
||||
virtual void handleExplosion(const Vec3& pos, bool direct_hit);
|
||||
virtual void forceRescue(bool is_auto_rescue=false);
|
||||
void update(float dt);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if an emergency animation is being played. */
|
||||
bool playingEmergencyAnimation() const {return m_kart_mode!=EA_NONE; }
|
||||
|
@ -230,7 +230,7 @@ public:
|
||||
void capSpeed (float max_speed);
|
||||
void updatedWeight ();
|
||||
void collectedItem (Item *item, int random_attachment);
|
||||
void reset ();
|
||||
virtual void reset ();
|
||||
void handleZipper (const Material *m=NULL, bool play_sound=false);
|
||||
void setSquash (float time, float slowdown);
|
||||
|
||||
|
97
src/karts/kart_with_stats.cpp
Normal file
97
src/karts/kart_with_stats.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
// $Id$
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2011 Joerg Henrichs
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "karts/kart_with_stats.hpp"
|
||||
|
||||
KartWithStats::KartWithStats(const std::string& ident, Track* track,
|
||||
int position, bool is_first_kart,
|
||||
const btTransform& init_transform,
|
||||
RaceManager::KartType type)
|
||||
: Kart(ident, track, position, is_first_kart,
|
||||
init_transform, type)
|
||||
{
|
||||
reset();
|
||||
} // KartWithStats
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Called at the start of each race, esp. in case of a restart.
|
||||
*/
|
||||
void KartWithStats::reset()
|
||||
{
|
||||
m_top_speed = 0.0f;
|
||||
m_explosion_time = 0.0f;
|
||||
m_explosion_count = 0;
|
||||
m_skidding_time = 0.0f;
|
||||
m_rescue_count = 0;
|
||||
m_rescue_time = 0.0f;
|
||||
} // reset
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** This function is called each timestep, and it collects most of the
|
||||
* statistics for this kart.
|
||||
* \param dt Time step size.
|
||||
*/
|
||||
void KartWithStats::update(float dt)
|
||||
{
|
||||
Kart::update(dt);
|
||||
if(getSpeed()>m_top_speed) m_top_speed = getSpeed();
|
||||
if(getControls().m_drift)
|
||||
m_skidding_time += dt;
|
||||
} // update
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Called when an explosion should be triggered. If the explosion actually
|
||||
* happens (i.e. the kart is neither invulnerable nor is it already playing
|
||||
* an emergency animation), it increases the number of times a kart was
|
||||
* exploded, and adds up the overall time spent in animation as well.
|
||||
* \param pos The position of the explosion.
|
||||
* \param direct_hit If the kart was hit directly, or if this is only a
|
||||
* seconday hit.
|
||||
*/
|
||||
void KartWithStats::handleExplosion(const Vec3& pos, bool direct_hit)
|
||||
{
|
||||
bool is_new_explosion = !playingEmergencyAnimation() && !isInvulnerable();
|
||||
Kart::handleExplosion(pos, direct_hit);
|
||||
if(is_new_explosion)
|
||||
{
|
||||
m_explosion_count ++;
|
||||
m_explosion_time +=EmergencyAnimation::m_timer;
|
||||
}
|
||||
|
||||
} // handleExplosion
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Called when a kart is being rescued. It counts the number of times a
|
||||
* kart is being rescued, and sums up the time for rescue as well.
|
||||
* \param is_auto_rescue True if this is an automatically triggered rescue.
|
||||
*/
|
||||
void KartWithStats::forceRescue(bool is_auto_rescue)
|
||||
{
|
||||
bool is_new_rescue = !playingEmergencyAnimation();
|
||||
Kart::forceRescue(is_auto_rescue);
|
||||
|
||||
// If there wasn't already a rescue happening, count this event:
|
||||
if(is_new_rescue)
|
||||
{
|
||||
m_rescue_count++;
|
||||
m_rescue_time += EmergencyAnimation::m_timer;
|
||||
}
|
||||
} // forceRescue
|
||||
|
||||
// ----------------------------------------------------------------------------
|
84
src/karts/kart_with_stats.hpp
Normal file
84
src/karts/kart_with_stats.hpp
Normal file
@ -0,0 +1,84 @@
|
||||
// $Id$
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2011 Joerg Henrichs
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_KART_WITH_STATS_HPP
|
||||
#define HEADER_KART_WITH_STATS_HPP
|
||||
|
||||
#include "karts/kart.hpp"
|
||||
|
||||
/** \defgroup karts */
|
||||
|
||||
|
||||
/** This class implements a kart that collects statistics about a race,
|
||||
* which is used in profiling mode. Example are maximum speed, number
|
||||
* of times it got hit, ...
|
||||
*/
|
||||
class KartWithStats : public Kart
|
||||
{
|
||||
private:
|
||||
/** The maximum speed of this kart had. */
|
||||
float m_top_speed;
|
||||
|
||||
/** How long this kart spent in explosions. */
|
||||
float m_explosion_time;
|
||||
|
||||
/** How often that kart was hit. */
|
||||
unsigned int m_explosion_count;
|
||||
|
||||
/** How often a kart was rescued. */
|
||||
unsigned int m_rescue_count;
|
||||
|
||||
/** How much time was spent in rescue. */
|
||||
float m_rescue_time;
|
||||
|
||||
/** How much time this kart was skidding. */
|
||||
float m_skidding_time;
|
||||
|
||||
public:
|
||||
KartWithStats(const std::string& ident, Track* track,
|
||||
int position, bool is_first_kart,
|
||||
const btTransform& init_transform,
|
||||
RaceManager::KartType type);
|
||||
virtual void update(float dt);
|
||||
virtual void reset();
|
||||
virtual void handleExplosion(const Vec3& pos, bool direct_hit);
|
||||
virtual void forceRescue(bool is_auto_rescue=false);
|
||||
|
||||
/** Returns the top speed of this kart. */
|
||||
float getTopSpeed() const { return m_top_speed; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns how much time this kart spent in explosion animations. */
|
||||
float getExplosionTime() const { return m_explosion_time; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns how often this kart was hit by an explosion. */
|
||||
unsigned int getExplosionCount() const { return m_explosion_count; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns how much time this kart spent skidding. */
|
||||
float getSkiddingTime() const { return m_skidding_time; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns how often a kart was rescued. */
|
||||
unsigned int getRescueCount() const { return m_rescue_count; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns how long a kart was rescued all in all. */
|
||||
float getRescueTime() const { return m_rescue_time; }
|
||||
// ------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
}; // KartWithStats
|
||||
#endif
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "graphics/camera.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "karts/kart_with_stats.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
|
||||
#include <ISceneManager.h>
|
||||
@ -99,7 +100,9 @@ Kart *ProfileWorld::createKart(const std::string &kart_ident, int index,
|
||||
race_manager->getNumberOfKarts()-1);
|
||||
btTransform init_pos = m_track->getStartTransform(index);
|
||||
|
||||
Kart *new_kart = new Kart(prof_kart_id, m_track, index+1, false, init_pos, RaceManager::KT_AI);
|
||||
Kart *new_kart = new KartWithStats(prof_kart_id, m_track, index+1,
|
||||
false, init_pos,
|
||||
RaceManager::KT_AI);
|
||||
|
||||
Controller *controller = loadAIController(new_kart);
|
||||
new_kart->setController(controller);
|
||||
@ -193,26 +196,40 @@ void ProfileWorld::enterRaceOverState()
|
||||
}
|
||||
|
||||
float min_t=999999.9f, max_t=0.0, av_t=0.0;
|
||||
printf("Name\t\tstart\tend\ttime\tav.speed\n");
|
||||
printf("Name\t\tstart\tend\ttime\t");
|
||||
if(m_profile_mode==PROFILE_LAPS)
|
||||
printf("av.speed\t");
|
||||
printf("top\tskid\trescue\trescue\t"
|
||||
"expl.\texpl.\n");
|
||||
printf("\t\t\t\t\tspeed\ttime\ttime\tcount\ttime\tcount\n");
|
||||
for ( KartList::size_type i = 0; i < m_karts.size(); ++i)
|
||||
{
|
||||
max_t = std::max(max_t, m_karts[i]->getFinishTime());
|
||||
min_t = std::min(min_t, m_karts[i]->getFinishTime());
|
||||
av_t += m_karts[i]->getFinishTime();
|
||||
printf("%s\t%s%d\t%d\t%f",
|
||||
m_karts[i]->getIdent().c_str(),
|
||||
m_karts[i]->getIdent().size()<8 ? "\t" : "",
|
||||
1 + (int)i,
|
||||
m_karts[i]->getPosition(),
|
||||
m_karts[i]->getFinishTime());
|
||||
printf("%s\t%s", m_karts[i]->getIdent().c_str(),
|
||||
m_karts[i]->getIdent().size()<8 ? "\t" : "");
|
||||
printf("%d\t%d\t", 1 + (int)i, m_karts[i]->getPosition());
|
||||
printf("%4.2f\t", m_karts[i]->getFinishTime());
|
||||
printf("%3.2f\t", dynamic_cast<KartWithStats*>
|
||||
(m_karts[i])->getTopSpeed());
|
||||
if(m_profile_mode==PROFILE_LAPS)
|
||||
{
|
||||
float distance = race_manager->getNumLaps()
|
||||
* m_track->getTrackLength();
|
||||
printf("\t%f\n",m_karts[i]->getFinishTime()/distance);
|
||||
printf("\t%4.2f\t",m_karts[i]->getFinishTime()/distance);
|
||||
}
|
||||
else
|
||||
printf("\n");
|
||||
printf("%4.2f\t", dynamic_cast<KartWithStats*>
|
||||
(m_karts[i])->getSkiddingTime());
|
||||
printf("%4.2f\t%d\t", dynamic_cast<KartWithStats*>
|
||||
(m_karts[i])->getRescueTime(),
|
||||
dynamic_cast<KartWithStats*>
|
||||
(m_karts[i])->getRescueCount());
|
||||
printf("%4.2f\t%d\t", dynamic_cast<KartWithStats*>
|
||||
(m_karts[i])->getExplosionTime(),
|
||||
dynamic_cast<KartWithStats*>
|
||||
(m_karts[i])->getExplosionCount() );
|
||||
printf("\n");
|
||||
}
|
||||
printf("min %f max %f av %f\n",min_t, max_t, av_t/m_karts.size());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user