Removed isClient/isServer from NetworkManager.
This commit is contained in:
parent
5564239773
commit
1e9afd473d
@ -320,7 +320,7 @@ void ItemManager::checkItemHit(AbstractKart* kart)
|
||||
// if we're not playing online, pick the item.
|
||||
if (!NetworkWorld::getInstance()->isRunning())
|
||||
collectedItem(*i, kart);
|
||||
else if (NetworkManager::getInstance()->isServer())
|
||||
else if (STKHost::isServer())
|
||||
{
|
||||
collectedItem(*i, kart);
|
||||
NetworkWorld::getInstance()->collectedItem(*i, kart);
|
||||
|
@ -1312,7 +1312,7 @@ void Kart::update(float dt)
|
||||
|
||||
// Check if any item was hit.
|
||||
// check it if we're not in a network world, or if we're on the server (when network mode is on)
|
||||
if (!NetworkWorld::getInstance()->isRunning() || NetworkManager::getInstance()->isServer())
|
||||
if (!NetworkWorld::getInstance()->isRunning() || STKHost::isServer())
|
||||
ItemManager::get()->checkItemHit(this);
|
||||
|
||||
static video::SColor pink(255, 255, 133, 253);
|
||||
|
@ -1349,7 +1349,7 @@ int main(int argc, char *argv[] )
|
||||
if(!handleCmdLine()) exit(0);
|
||||
|
||||
// load the network manager
|
||||
if (NetworkManager::getInstance()->isServer())
|
||||
if (STKHost::isServer())
|
||||
{
|
||||
STKHost::setMaxPlayers(UserConfigParams::m_server_max_players);
|
||||
(new ServerLobbyRoomProtocol())->requestStart();
|
||||
|
@ -124,6 +124,6 @@ void StandardRace::endRaceEarly()
|
||||
} // Finish the active players
|
||||
endSetKartPositions();
|
||||
setPhase(RESULT_DISPLAY_PHASE);
|
||||
if (!isNetworkWorld() || NetworkManager::getInstance()->isServer())
|
||||
if (!isNetworkWorld() || STKHost::isServer())
|
||||
terminateRace();
|
||||
} // endRaceEarly
|
||||
|
@ -52,10 +52,6 @@ class ClientNetworkManager : public NetworkManager
|
||||
* \return The peer with whom we're connected (if it exists). NULL elseway.
|
||||
*/
|
||||
STKPeer* getPeer();
|
||||
/*! \brief Function to know if we're a server.
|
||||
* \return Returns true if we're on a server. False if we're a client.
|
||||
*/
|
||||
virtual bool isServer() { return false; }
|
||||
/*! \brief Function used to notice the manager that we're connected to a server.
|
||||
* \param value : True if we're connected, false elseway.
|
||||
*/
|
||||
|
@ -59,14 +59,6 @@ private:
|
||||
|
||||
friend class AbstractSingleton<NetworkManager>;
|
||||
public:
|
||||
// Game related functions
|
||||
virtual bool isServer() = 0;
|
||||
|
||||
// raw data management
|
||||
|
||||
// getters
|
||||
// --------------------------------------------------------------------
|
||||
inline bool isClient() { return !isServer(); }
|
||||
|
||||
|
||||
}; // class NetworkManager
|
||||
|
@ -62,7 +62,7 @@ bool NetworkWorld::isRaceOver()
|
||||
|
||||
void NetworkWorld::collectedItem(Item *item, AbstractKart *kart)
|
||||
{
|
||||
assert(NetworkManager::getInstance()->isServer()); // this is only called in the server
|
||||
assert(STKHost::isServer()); // this is only called in the server
|
||||
GameEventsProtocol* protocol = static_cast<GameEventsProtocol*>(
|
||||
ProtocolManager::getInstance()->getProtocol(PROTOCOL_GAME_EVENTS));
|
||||
protocol->collectedItem(item,kart);
|
||||
|
@ -635,15 +635,6 @@ Protocol* ProtocolManager::getProtocol(ProtocolType type)
|
||||
return NULL;
|
||||
} // getProtocol
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** \brief Know whether the app is a server.
|
||||
* \return True if this application is in server mode, false elseway.
|
||||
*/
|
||||
bool ProtocolManager::isServer()
|
||||
{
|
||||
return NetworkManager::getInstance()->isServer();
|
||||
} // isServer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/*! \brief Tells if we need to stop the update thread.
|
||||
*/
|
||||
|
@ -132,7 +132,6 @@ class ProtocolManager : public AbstractSingleton<ProtocolManager>,
|
||||
virtual uint32_t getProtocolID(Protocol* protocol);
|
||||
virtual Protocol* getProtocol(uint32_t id);
|
||||
virtual Protocol* getProtocol(ProtocolType type);
|
||||
bool isServer();
|
||||
int exit();
|
||||
|
||||
protected:
|
||||
|
@ -37,7 +37,7 @@ void ControllerEventsProtocol::setup()
|
||||
m_self_controller_index = i;
|
||||
}
|
||||
STKPeer* peer = NULL;
|
||||
if (ProtocolManager::getInstance()->isServer())
|
||||
if (STKHost::isServer())
|
||||
{
|
||||
for (unsigned int j = 0; j < peers.size(); j++)
|
||||
{
|
||||
@ -114,7 +114,7 @@ bool ControllerEventsProtocol::notifyEventAsynchronous(Event* event)
|
||||
Log::warn("ControllerEventProtocol", "Couldn't have a client id.");
|
||||
return true;
|
||||
}
|
||||
if (ProtocolManager::getInstance()->isServer())
|
||||
if (STKHost::isServer())
|
||||
{
|
||||
// notify everybody of the event :
|
||||
for (unsigned int i = 0; i < m_controllers.size(); i++)
|
||||
@ -143,7 +143,7 @@ void ControllerEventsProtocol::update()
|
||||
void ControllerEventsProtocol::controllerAction(Controller* controller,
|
||||
PlayerAction action, int value)
|
||||
{
|
||||
assert(!ProtocolManager::getInstance()->isServer());
|
||||
assert(!STKHost::isServer());
|
||||
|
||||
KartControl* controls = controller->getControls();
|
||||
uint8_t serialized_1 = 0;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "network/event.hpp"
|
||||
#include "network/network_world.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/stk_host.hpp"
|
||||
#include "utils/time.hpp"
|
||||
|
||||
KartUpdateProtocol::KartUpdateProtocol()
|
||||
@ -77,7 +78,7 @@ void KartUpdateProtocol::update()
|
||||
if (current_time > time + 0.1) // 10 updates per second
|
||||
{
|
||||
time = current_time;
|
||||
if (ProtocolManager::getInstance()->isServer())
|
||||
if (STKHost::isServer())
|
||||
{
|
||||
NetworkString ns(4+m_karts.size()*32);
|
||||
ns.af( World::getWorld()->getTime());
|
||||
@ -117,8 +118,8 @@ void KartUpdateProtocol::update()
|
||||
while (!m_next_positions.empty())
|
||||
{
|
||||
uint32_t id = m_karts_ids.back();
|
||||
if (id != m_self_kart_index ||
|
||||
ProtocolManager::getInstance()->isServer()) // server takes all updates
|
||||
// server takes all updates
|
||||
if (id != m_self_kart_index || STKHost::isServer())
|
||||
{
|
||||
Vec3 pos = m_next_positions.back();
|
||||
btTransform transform = m_karts[id]->getBody()->getInterpolationWorldTransform();
|
||||
|
@ -51,7 +51,7 @@ bool StartGameProtocol::notifyEventAsynchronous(Event* event)
|
||||
Log::error("StartGameProtocol", "Bad token received.");
|
||||
return true;
|
||||
}
|
||||
if (ProtocolManager::getInstance()->isServer() && ready) // on server, player is ready
|
||||
if (STKHost::isServer() && ready) // on server, player is ready
|
||||
{
|
||||
Log::info("StartGameProtocol", "One of the players is ready.");
|
||||
m_player_states[peer->getPlayerProfile()] = READY;
|
||||
@ -149,7 +149,7 @@ void StartGameProtocol::update()
|
||||
rki.setDifficulty(profile->difficulty);
|
||||
rki.setGlobalPlayerId(profile->race_id);
|
||||
// on the server, the race id must be the local one.
|
||||
rki.setLocalPlayerId(ProtocolManager::getInstance()->isServer()
|
||||
rki.setLocalPlayerId(STKHost::isServer()
|
||||
? profile->race_id
|
||||
: (is_me ? 0 : 1) );
|
||||
rki.setHostId(profile->race_id);
|
||||
@ -205,7 +205,7 @@ void StartGameProtocol::update()
|
||||
|
||||
void StartGameProtocol::ready() // on clients, means the loading is finished
|
||||
{
|
||||
if (!ProtocolManager::getInstance()->isServer()) // if we're a client
|
||||
if (!STKHost::isServer()) // if we're a client
|
||||
{
|
||||
assert(STKHost::get()->getPeerCount() == 1);
|
||||
NetworkString ns(5);
|
||||
|
@ -50,7 +50,7 @@ bool SynchronizationProtocol::notifyEventAsynchronous(Event* event)
|
||||
const std::vector<STKPeer*> &peers = STKHost::get()->getPeers();
|
||||
assert(peers.size() > 0);
|
||||
|
||||
if (ProtocolManager::getInstance()->isServer())
|
||||
if (STKHost::isServer())
|
||||
{
|
||||
if (talk_id > peers.size())
|
||||
{
|
||||
@ -81,7 +81,7 @@ bool SynchronizationProtocol::notifyEventAsynchronous(Event* event)
|
||||
Log::verbose("SynchronizationProtocol", "Answering sequence %u", sequence);
|
||||
|
||||
// countdown time in the message
|
||||
if (data.size() == 14 && !ProtocolManager::getInstance()->isServer())
|
||||
if (data.size() == 14 && !STKHost::isServer())
|
||||
{
|
||||
uint32_t time_to_start = data.gui32(10);
|
||||
Log::debug("SynchronizationProtocol", "Request to start game in %d.", time_to_start);
|
||||
@ -161,8 +161,7 @@ void SynchronizationProtocol::asynchronousUpdate()
|
||||
NetworkString ns(10);
|
||||
ns.ai8(i).addUInt32(peers[i]->getClientServerToken()).addUInt8(1).addUInt32(m_pings[i].size());
|
||||
// now add the countdown if necessary
|
||||
if (m_countdown_activated &&
|
||||
ProtocolManager::getInstance()->isServer())
|
||||
if (m_countdown_activated && STKHost::isServer())
|
||||
{
|
||||
ns.addUInt32((int)(m_countdown*1000.0));
|
||||
Log::debug("SynchronizationProtocol", "CNTActivated: Countdown value : %f", m_countdown);
|
||||
|
@ -214,6 +214,12 @@ public:
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns the number of currently connected peers. */
|
||||
unsigned int getPeerCount() { return (int)m_peers.size(); }
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns if this instance is a server. */
|
||||
static bool isServer() { return m_is_server; }
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns if this instance is a client. */
|
||||
static bool isclient() { return !m_is_server; }
|
||||
|
||||
}; // class STKHost
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user