Try to put IA in its own thread

This commit is contained in:
Vincent Lejeune
2014-09-12 23:04:40 +02:00
parent 78e512880c
commit 2a60a84155
2 changed files with 17 additions and 8 deletions

View File

@@ -36,6 +36,7 @@
#include "race/race_manager.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/profiler.hpp"
#include <thread>
MainLoop* main_loop = 0;
@@ -108,6 +109,9 @@ void MainLoop::updateRace(float dt)
World::getWorld()->updateWorld(dt);
} // updateRace
std::thread IAThread;
//-----------------------------------------------------------------------------
/** Run the actual main loop.
*/
@@ -173,6 +177,8 @@ void MainLoop::run()
}
PROFILER_POP_CPU_MARKER();
if(IAThread.joinable())
IAThread.join();
PROFILER_SYNC_FRAME();
} // while !m_abort

View File

@@ -65,7 +65,7 @@
#include <ctime>
#include <sstream>
#include <stdexcept>
#include <thread>
World* World::m_world = NULL;
@@ -763,6 +763,8 @@ void World::scheduleUnpause()
}
} // scheduleUnpause
extern std::thread IAThread;
//-----------------------------------------------------------------------------
/** This is the main interface to update the world. This function calls
* update(), and checks then for the end of the race. Note that race over
@@ -926,13 +928,14 @@ void World::update(float dt)
}
PROFILER_PUSH_CPU_MARKER("World::update (AI)", 0x40, 0x7F, 0x00);
const int kart_amount = m_karts.size();
#pragma omp parallel for
for (int i = 0 ; i < kart_amount; ++i)
{
// Update all karts that are not eliminated
if(!m_karts[i]->isEliminated()) m_karts[i]->update(dt) ;
}
IAThread = std::thread([&]() {
const int kart_amount = m_karts.size();
for (int i = 0; i < kart_amount; ++i)
{
// Update all karts that are not eliminated
if (!m_karts[i]->isEliminated()) m_karts[i]->update(dt);
}
});
PROFILER_POP_CPU_MARKER();
PROFILER_PUSH_CPU_MARKER("World::update (camera)", 0x60, 0x7F, 0x00);