Allow arena ai profiling
This commit is contained in:
parent
101611af3e
commit
bbde4659c1
@ -527,6 +527,9 @@ namespace UserConfigParams
|
||||
/** True if fps should be printed each frame. */
|
||||
PARAM_PREFIX bool m_fps_debug PARAM_DEFAULT(false);
|
||||
|
||||
/** True if arena (battle/soccer) ai profiling. */
|
||||
PARAM_PREFIX bool m_arena_ai_stats PARAM_DEFAULT(false);
|
||||
|
||||
/** True if slipstream debugging is activated. */
|
||||
PARAM_PREFIX bool m_slipstream_debug PARAM_DEFAULT( false );
|
||||
|
||||
|
@ -57,6 +57,8 @@ RescueAnimation::RescueAnimation(AbstractKart *kart, bool is_auto_rescue)
|
||||
{
|
||||
ThreeStrikesBattle *world=(ThreeStrikesBattle*)World::getWorld();
|
||||
world->kartHit(m_kart->getWorldKartId());
|
||||
if (UserConfigParams::m_arena_ai_stats)
|
||||
world->increaseRescueCount();
|
||||
}
|
||||
}; // RescueAnimation
|
||||
|
||||
|
33
src/main.cpp
33
src/main.cpp
@ -772,6 +772,39 @@ int handleCmdLine()
|
||||
AIBaseController::setTestAI(n);
|
||||
if (CommandLine::has("--fps-debug"))
|
||||
UserConfigParams::m_fps_debug = true;
|
||||
if(CommandLine::has("--soccer-ai-stats"))
|
||||
{
|
||||
UserConfigParams::m_arena_ai_stats=true;
|
||||
race_manager->setMinorMode(RaceManager::MINOR_MODE_SOCCER);
|
||||
std::vector<std::string> l;
|
||||
for (int i = 0; i < 8; i++)
|
||||
l.push_back("tux");
|
||||
race_manager->setDefaultAIKartList(l);
|
||||
race_manager->setNumKarts(8);
|
||||
race_manager->setMaxGoal(30);
|
||||
race_manager->setTrack("soccer_field");
|
||||
race_manager->setDifficulty(RaceManager::Difficulty(3));
|
||||
UserConfigParams::m_no_start_screen = true;
|
||||
UserConfigParams::m_race_now = true;
|
||||
UserConfigParams::m_sfx = false;
|
||||
UserConfigParams::m_music = false;
|
||||
}
|
||||
if(CommandLine::has("--battle-ai-stats"))
|
||||
{
|
||||
UserConfigParams::m_arena_ai_stats=true;
|
||||
race_manager->setMinorMode(RaceManager::MINOR_MODE_3_STRIKES);
|
||||
std::vector<std::string> l;
|
||||
for (int i = 0; i < 8; i++)
|
||||
l.push_back("tux");
|
||||
race_manager->setDefaultAIKartList(l);
|
||||
race_manager->setTrack("temple");
|
||||
race_manager->setNumKarts(8);
|
||||
race_manager->setDifficulty(RaceManager::Difficulty(3));
|
||||
UserConfigParams::m_no_start_screen = true;
|
||||
UserConfigParams::m_race_now = true;
|
||||
UserConfigParams::m_sfx = false;
|
||||
UserConfigParams::m_music = false;
|
||||
}
|
||||
|
||||
if(UserConfigParams::m_artist_debug_mode)
|
||||
{
|
||||
|
@ -62,7 +62,8 @@ MainLoop::~MainLoop()
|
||||
float MainLoop::getLimitedDt()
|
||||
{
|
||||
// In profile mode without graphics, run with a fixed dt of 1/60
|
||||
if (ProfileWorld::isProfileMode() && ProfileWorld::isNoGraphics())
|
||||
if ((ProfileWorld::isProfileMode() && ProfileWorld::isNoGraphics()) ||
|
||||
UserConfigParams::m_arena_ai_stats)
|
||||
{
|
||||
return 1.0f/60.0f;
|
||||
}
|
||||
|
@ -17,8 +17,10 @@
|
||||
|
||||
#include "modes/soccer_world.hpp"
|
||||
|
||||
#include "main_loop.hpp"
|
||||
#include "audio/music_manager.hpp"
|
||||
#include "audio/sfx_base.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "karts/abstract_kart.hpp"
|
||||
@ -53,6 +55,8 @@ SoccerWorld::SoccerWorld() : WorldWithRank()
|
||||
WorldStatus::setClockMode(CLOCK_CHRONO);
|
||||
}
|
||||
|
||||
m_frame_count = 0;
|
||||
m_start_time = irr_driver->getRealTime();
|
||||
m_use_highscores = false;
|
||||
} // SoccerWorld
|
||||
|
||||
@ -183,6 +187,8 @@ void SoccerWorld::update(float dt)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (UserConfigParams::m_arena_ai_stats)
|
||||
m_frame_count++;
|
||||
|
||||
} // update
|
||||
|
||||
@ -642,3 +648,38 @@ void SoccerWorld::resetBall()
|
||||
m_ball->reset();
|
||||
m_ball->getPhysicalObject()->reset();
|
||||
} // resetBall
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void SoccerWorld::enterRaceOverState()
|
||||
{
|
||||
if (UserConfigParams::m_arena_ai_stats)
|
||||
{
|
||||
float runtime = (irr_driver->getRealTime()-m_start_time)*0.001f;
|
||||
Log::verbose("Soccer AI profiling", "Number of frames: %d, Average FPS: %f",
|
||||
m_frame_count, (float)m_frame_count/runtime);
|
||||
Log::verbose("Soccer AI profiling", "Time for a team to have 30 goals: %f",
|
||||
runtime);
|
||||
|
||||
// Own goal rate
|
||||
int red_own_goal = 0;
|
||||
int blue_own_goal = 0;
|
||||
for (unsigned i = 0; i < m_red_scorers.size(); i++)
|
||||
{
|
||||
if (!m_red_scorers[i].m_correct_goal)
|
||||
red_own_goal++;
|
||||
}
|
||||
for (unsigned i = 0; i < m_blue_scorers.size(); i++)
|
||||
{
|
||||
if (!m_blue_scorers[i].m_correct_goal)
|
||||
blue_own_goal++;
|
||||
}
|
||||
|
||||
Log::verbose("Soccer AI profiling", "Own goal rate: red %d\%, blue %d\%",
|
||||
int(red_own_goal * 100 / m_red_scorers.size()),
|
||||
int(blue_own_goal * 100 / m_blue_scorers.size()));
|
||||
delete this;
|
||||
main_loop->abort();
|
||||
}
|
||||
else
|
||||
WorldStatus::enterRaceOverState();
|
||||
} // enterRaceOverState
|
||||
|
@ -108,6 +108,10 @@ private:
|
||||
/** Get number of teammates in a team, used by starting position assign. */
|
||||
int getTeamNum(SoccerTeam team) const;
|
||||
|
||||
/** Profiling usage */
|
||||
int m_frame_count;
|
||||
int m_start_time;
|
||||
|
||||
public:
|
||||
|
||||
SoccerWorld();
|
||||
@ -131,6 +135,8 @@ public:
|
||||
|
||||
virtual bool raceHasLaps() OVERRIDE { return false; }
|
||||
|
||||
virtual void enterRaceOverState() OVERRIDE;
|
||||
|
||||
virtual const std::string& getIdent() const OVERRIDE;
|
||||
|
||||
virtual void update(float dt) OVERRIDE;
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <string>
|
||||
#include <IMeshSceneNode.h>
|
||||
|
||||
#include "main_loop.hpp"
|
||||
#include "audio/music_manager.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/camera.hpp"
|
||||
@ -46,6 +47,12 @@ ThreeStrikesBattle::ThreeStrikesBattle() : WorldWithRank()
|
||||
m_tire = irr_driver->getMesh(file_manager->getAsset(FileManager::MODEL,
|
||||
"tire.b3d") );
|
||||
irr_driver->grabAllTextures(m_tire);
|
||||
|
||||
m_total_rescue = 0;
|
||||
m_frame_count = 0;
|
||||
m_start_time = irr_driver->getRealTime();
|
||||
m_total_hit = 0;
|
||||
|
||||
} // ThreeStrikesBattle
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -160,8 +167,12 @@ void ThreeStrikesBattle::kartHit(const unsigned int kart_id)
|
||||
if (isRaceOver()) return;
|
||||
|
||||
assert(kart_id < m_karts.size());
|
||||
// make kart lose a life
|
||||
m_kart_info[kart_id].m_lives--;
|
||||
// make kart lose a life, ignore if in profiling mode
|
||||
if (!UserConfigParams::m_arena_ai_stats)
|
||||
m_kart_info[kart_id].m_lives--;
|
||||
|
||||
if (UserConfigParams::m_arena_ai_stats)
|
||||
m_total_hit++;
|
||||
|
||||
// record event
|
||||
BattleEvent evt;
|
||||
@ -369,6 +380,9 @@ void ThreeStrikesBattle::update(float dt)
|
||||
|
||||
m_tires.push_back(tire_obj);
|
||||
} // while
|
||||
if (UserConfigParams::m_arena_ai_stats)
|
||||
m_frame_count++;
|
||||
|
||||
} // update
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -429,6 +443,9 @@ void ThreeStrikesBattle::updateKartRanks()
|
||||
*/
|
||||
bool ThreeStrikesBattle::isRaceOver()
|
||||
{
|
||||
if (UserConfigParams::m_arena_ai_stats)
|
||||
return (irr_driver->getRealTime()-m_start_time)*0.001f > 20.0f;
|
||||
|
||||
// for tests : never over when we have a single player there :)
|
||||
if (race_manager->getNumberOfKarts()==1 &&
|
||||
getCurrentNumKarts()==1 &&
|
||||
@ -515,3 +532,20 @@ void ThreeStrikesBattle::getKartsDisplayInfo(
|
||||
}
|
||||
} // getKartsDisplayInfo
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void ThreeStrikesBattle::enterRaceOverState()
|
||||
{
|
||||
if (UserConfigParams::m_arena_ai_stats)
|
||||
{
|
||||
float runtime = (irr_driver->getRealTime()-m_start_time)*0.001f;
|
||||
Log::verbose("Battle AI profiling", "Number of frames: %d, Average FPS: %f",
|
||||
m_frame_count, (float)m_frame_count/runtime);
|
||||
Log::verbose("Battle AI profiling", "Total rescue: %d , hits %d in %f seconds",
|
||||
m_total_rescue, m_total_hit, runtime);
|
||||
delete this;
|
||||
main_loop->abort();
|
||||
}
|
||||
else
|
||||
WorldStatus::enterRaceOverState();
|
||||
} // enterRaceOverState
|
||||
|
||||
|
@ -74,6 +74,12 @@ private:
|
||||
/** Function to update the locations of all karts on the polygon map */
|
||||
void updateKartNodes();
|
||||
|
||||
/** Profiling usage */
|
||||
int m_total_rescue;
|
||||
int m_frame_count;
|
||||
int m_start_time;
|
||||
int m_total_hit;
|
||||
|
||||
public:
|
||||
|
||||
/** Used to show a nice graph when battle is over */
|
||||
@ -108,10 +114,12 @@ public:
|
||||
virtual void update(float dt);
|
||||
|
||||
virtual void kartAdded(AbstractKart* kart, scene::ISceneNode* node);
|
||||
virtual void enterRaceOverState() OVERRIDE;
|
||||
|
||||
int getKartNode(unsigned int kart_id) const;
|
||||
|
||||
void updateKartRanks();
|
||||
void increaseRescueCount() { m_total_rescue++; }
|
||||
}; // ThreeStrikesBattles
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user