Clean all previous AI if exists in offline game

This commit is contained in:
Benau
2018-04-03 10:05:29 +08:00
parent 2dd9174b3a
commit 93d1b9136d
3 changed files with 16 additions and 13 deletions

View File

@@ -61,7 +61,8 @@ void LobbyProtocol::loadWorld()
// Race startup sequence
// ---------------------
// This creates the network world.
RaceEventManager::getInstance<RaceEventManager>()->start();
auto gep = std::make_shared<GameEventsProtocol>();
RaceEventManager::getInstance<RaceEventManager>()->start(gep);
// Make sure that if there is only a single local player this player can
// use all input devices.
@@ -75,7 +76,7 @@ void LobbyProtocol::loadWorld()
m_game_setup->loadWorld();
World::getWorld()->setNetworkWorld(true);
GameProtocol::createInstance()->requestStart();
std::make_shared<GameEventsProtocol>()->requestStart();
gep->requestStart();
} // loadWorld
@@ -130,6 +131,8 @@ void LobbyProtocol::configRemoteKart(
// Inform the race manager about the data for this kart.
race_manager->setPlayerKart(i, rki);
} // for i in players
// Clean all previous AI if exists in offline game
race_manager->computeRandomKartList();
Log::info("LobbyProtocol", "Player configuration ready.");
} // configRemoteKart

View File

@@ -51,8 +51,9 @@ void RaceEventManager::update(int ticks)
} // update
// ----------------------------------------------------------------------------
void RaceEventManager::start()
void RaceEventManager::start(std::shared_ptr<GameEventsProtocol> gep)
{
m_game_events_protocol = gep;
m_running = true;
} // start
@@ -74,9 +75,8 @@ bool RaceEventManager::isRaceOver()
// ----------------------------------------------------------------------------
void RaceEventManager::kartFinishedRace(AbstractKart *kart, float time)
{
auto protocol = std::static_pointer_cast<GameEventsProtocol>(
ProtocolManager::lock()->getProtocol(PROTOCOL_GAME_EVENTS));
protocol->kartFinishedRace(kart, time);
if (auto game_events_protocol = m_game_events_protocol.lock())
game_events_protocol->kartFinishedRace(kart, time);
} // kartFinishedRace
// ----------------------------------------------------------------------------
@@ -89,9 +89,7 @@ void RaceEventManager::collectedItem(Item *item, AbstractKart *kart)
{
// this is only called in the server
assert(NetworkConfig::get()->isServer());
auto protocol = std::static_pointer_cast<GameEventsProtocol>(
ProtocolManager::lock()->getProtocol(PROTOCOL_GAME_EVENTS));
protocol->collectedItem(item,kart);
if (auto game_events_protocol = m_game_events_protocol.lock())
game_events_protocol->collectedItem(item, kart);
} // collectedItem

View File

@@ -21,10 +21,10 @@
#include "input/input.hpp"
#include "utils/singleton.hpp"
#include <map>
#include <memory>
class Controller;
class KartUpdateProtocol;
class GameEventsProtocol;
class AbstractKart;
class Item;
@@ -40,6 +40,8 @@ private:
bool m_running;
float m_race_time;
std::weak_ptr<GameEventsProtocol> m_game_events_protocol;
friend class AbstractSingleton<RaceEventManager>;
RaceEventManager();
@@ -48,7 +50,7 @@ private:
public:
void update(int ticks);
void start();
void start(std::shared_ptr<GameEventsProtocol> gep);
void stop();
bool isRaceOver();