2013-07-13 19:16:40 -04:00
|
|
|
#include "network/network_world.hpp"
|
|
|
|
|
2013-07-15 09:44:17 -04:00
|
|
|
#include "network/protocol_manager.hpp"
|
|
|
|
#include "network/protocols/synchronization_protocol.hpp"
|
2013-07-20 13:32:23 -04:00
|
|
|
#include "network/protocols/controller_events_protocol.hpp"
|
2013-07-13 19:16:40 -04:00
|
|
|
#include "modes/world.hpp"
|
|
|
|
|
2013-07-16 10:45:48 -04:00
|
|
|
#include "karts/controller/controller.hpp"
|
|
|
|
|
2013-07-13 19:16:40 -04:00
|
|
|
NetworkWorld::NetworkWorld()
|
|
|
|
{
|
|
|
|
m_running = false;
|
2013-07-31 21:03:07 -04:00
|
|
|
m_has_run = false;
|
2013-07-13 19:16:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
NetworkWorld::~NetworkWorld()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkWorld::update(float dt)
|
|
|
|
{
|
2013-07-31 21:03:07 -04:00
|
|
|
if (!m_has_run)
|
|
|
|
m_has_run = true;
|
2013-07-15 09:44:17 -04:00
|
|
|
SynchronizationProtocol* protocol = static_cast<SynchronizationProtocol*>(
|
|
|
|
ProtocolManager::getInstance()->getProtocol(PROTOCOL_SYNCHRONIZATION));
|
|
|
|
if (protocol) // if this protocol exists, that's that we play online
|
|
|
|
{
|
2013-07-15 11:32:36 -04:00
|
|
|
Log::debug("NetworkWorld", "Coutdown value is %f", protocol->getCountdown());
|
2013-07-15 11:06:11 -04:00
|
|
|
if (protocol->getCountdown() > 0.0)
|
2013-07-15 09:44:17 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-07-13 19:16:40 -04:00
|
|
|
World::getWorld()->updateWorld(dt);
|
2013-07-31 21:03:07 -04:00
|
|
|
if (World::getWorld()->getPhase() >= WorldStatus::RESULT_DISPLAY_PHASE) // means it's the end
|
|
|
|
{
|
|
|
|
// consider the world finished.
|
|
|
|
stop();
|
|
|
|
Log::info("NetworkWorld", "The game is considered finish.");
|
|
|
|
}
|
2013-07-13 19:16:40 -04:00
|
|
|
}
|
2013-07-16 10:45:48 -04:00
|
|
|
|
|
|
|
void NetworkWorld::controllerAction(Controller* controller, PlayerAction action, int value)
|
|
|
|
{
|
2013-07-20 13:32:23 -04:00
|
|
|
ControllerEventsProtocol* protocol = static_cast<ControllerEventsProtocol*>(
|
|
|
|
ProtocolManager::getInstance()->getProtocol(PROTOCOL_CONTROLLER_EVENTS));
|
|
|
|
if (protocol)
|
|
|
|
protocol->controllerAction(controller, action, value);
|
2013-07-16 10:45:48 -04:00
|
|
|
}
|
2013-07-31 21:03:07 -04:00
|
|
|
|
|
|
|
bool NetworkWorld::isRaceOver()
|
|
|
|
{
|
|
|
|
if (!World::getWorld())
|
|
|
|
return false;
|
|
|
|
return (World::getWorld()->getPhase() >= WorldStatus::RESULT_DISPLAY_PHASE);
|
|
|
|
}
|