Skip to content

Commit

Permalink
breaking everything that was working. cannot even start a race now, n…
Browse files Browse the repository at this point in the history
…eed to rewrite the network manager and part of the race startup sequence

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13032 178a84e3-b1eb-0310-8ba1-8eac791a3b58
  • Loading branch information
hilnius committed Jun 29, 2013
1 parent 36673a2 commit 613e97d
Show file tree
Hide file tree
Showing 76 changed files with 2,994 additions and 2,564 deletions.
4 changes: 2 additions & 2 deletions src/io/xml_node.cpp
Expand Up @@ -41,7 +41,7 @@ XMLNode::XMLNode(const std::string &filename)
m_file_name = filename;

io::IXMLReader *xml = file_manager->createXMLReader(filename);

if (xml == NULL)
{
throw std::runtime_error("Cannot find file "+filename);
Expand Down Expand Up @@ -597,4 +597,4 @@ bool XMLNode::hasChildNamed(const char* name) const
if (m_nodes[i]->getName() == name) return true;
}
return false;
}
}
7 changes: 4 additions & 3 deletions src/items/attachment.cpp
Expand Up @@ -33,7 +33,6 @@
#include "karts/kart_properties.hpp"
#include "modes/three_strikes_battle.hpp"
#include "modes/world.hpp"
#include "network/race_state.hpp"
#include "network/network_manager.hpp"
#include "utils/constants.hpp"

Expand Down Expand Up @@ -260,11 +259,13 @@ void Attachment::hitBanana(Item *item, int new_attachment)

// Save the information about the attachment in the race state
// so that the clients can be updated.
if(network_manager->getMode()==NetworkManager::NW_SERVER)
if(NetworkManager::getInstance()->isPlayingOnline()) // if we're online
{
/*
race_state->itemCollected(m_kart->getWorldKartId(),
item->getItemId(),
new_attachment);
new_attachment);*/
//NETWORK_UPDATE_PLZ
}

if (add_a_new_item)
Expand Down
5 changes: 3 additions & 2 deletions src/items/flyable.cpp
Expand Up @@ -38,7 +38,6 @@
#include "karts/abstract_kart.hpp"
#include "karts/explosion_animation.hpp"
#include "modes/world.hpp"
#include "network/flyable_info.hpp"
#include "physics/physics.hpp"
#include "tracks/track.hpp"
#include "utils/constants.hpp"
Expand Down Expand Up @@ -416,11 +415,13 @@ bool Flyable::updateAndDelete(float dt)
*/
void Flyable::updateFromServer(const FlyableInfo &f, float dt)
{
/*
setXYZ(f.m_xyz);
setRotation(f.m_rotation);

*/
// Update the graphical position
Moveable::update(dt);

} // updateFromServer

// ----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/items/flyable.hpp
Expand Up @@ -19,6 +19,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

//NETWORK_UPDATE_PLZ
#ifndef HEADER_FLYABLE_HPP
#define HEADER_FLYABLE_HPP

Expand Down
2 changes: 1 addition & 1 deletion src/items/item_manager.cpp
Expand Up @@ -291,7 +291,7 @@ void ItemManager::collectedItem(Item *item, AbstractKart *kart, int add_info)
void ItemManager::checkItemHit(AbstractKart* kart)
{
// Only do this on the server
if(network_manager->getMode()==NetworkManager::NW_CLIENT) return;
if(NetworkManager::getInstance()->isServer()) return;

// We could use m_items_in_quads to to check for item hits: take the quad
// of the graph node of the kart, and only check items in that quad. But
Expand Down
3 changes: 1 addition & 2 deletions src/items/powerup.cpp
Expand Up @@ -16,6 +16,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

//NETWORK_UPDATE_PLZ
#include "items/powerup.hpp"

#include "audio/sfx_base.hpp"
Expand All @@ -30,8 +31,6 @@
#include "karts/controller/controller.hpp"
#include "karts/kart_properties.hpp"
#include "modes/world.hpp"
#include "network/network_manager.hpp"
#include "network/race_state.hpp"
#include "physics/triangle_mesh.hpp"
#include "tracks/track.hpp"
#include "utils/string_utils.hpp"
Expand Down
22 changes: 14 additions & 8 deletions src/items/projectile_manager.cpp
Expand Up @@ -16,6 +16,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

//NETWORK_UPDATE_PLZ

#include "items/projectile_manager.hpp"

#include "graphics/explosion.hpp"
Expand All @@ -27,7 +29,6 @@
#include "items/powerup.hpp"
#include "items/rubber_ball.hpp"
#include "network/network_manager.hpp"
#include "network/race_state.hpp"

ProjectileManager *projectile_manager=0;

Expand Down Expand Up @@ -66,7 +67,8 @@ void ProjectileManager::cleanup()
/** General projectile update call. */
void ProjectileManager::update(float dt)
{
if(network_manager->getMode()==NetworkManager::NW_CLIENT)

if(NetworkManager::getInstance()->isClient())
{
updateClient(dt);
}
Expand Down Expand Up @@ -101,21 +103,23 @@ void ProjectileManager::update(float dt)
void ProjectileManager::updateServer(float dt)
{
// First update all projectiles on the track
if(network_manager->getMode()!=NetworkManager::NW_NONE)

if(NetworkManager::getInstance()->isPlayingOnline()) //network_manager->getMode()!=NetworkManager::NW_NONE)
{
race_state->setNumFlyables(m_active_projectiles.size());
//race_state->setNumFlyables(m_active_projectiles.size());
}


Projectiles::iterator p = m_active_projectiles.begin();
while(p!=m_active_projectiles.end())
{
bool can_be_deleted = (*p)->updateAndDelete(dt);
if(network_manager->getMode()!=NetworkManager::NW_NONE)
if(NetworkManager::getInstance()->isPlayingOnline()) //network_manager->getMode()!=NetworkManager::NW_NONE)
{
race_state->setFlyableInfo(p-m_active_projectiles.begin(),
/*race_state->setFlyableInfo(p-m_active_projectiles.begin(),
FlyableInfo((*p)->getXYZ(),
(*p)->getRotation(),
can_be_deleted) );
can_be_deleted) );*/
}
if(can_be_deleted)
{
Expand All @@ -130,6 +134,7 @@ void ProjectileManager::updateServer(float dt)
else
p++;
} // while p!=m_active_projectiles.end()

} // updateServer

// -----------------------------------------------------------------------------
Expand All @@ -138,6 +143,7 @@ void ProjectileManager::updateServer(float dt)
* (i.e. position, hit effects etc) */
void ProjectileManager::updateClient(float dt)
{
/*
unsigned int num_projectiles = race_state->getNumFlyables();
if(num_projectiles != m_active_projectiles.size())
fprintf(stderr, "Warning: num_projectiles %d active %d\n",
Expand All @@ -154,7 +160,7 @@ void ProjectileManager::updateClient(float dt)
(*i)->hit(NULL);
}
} // for i in m_active_projectiles

*/
} // updateClient
// -----------------------------------------------------------------------------
Flyable *ProjectileManager::newProjectile(AbstractKart *kart, Track* track,
Expand Down
24 changes: 2 additions & 22 deletions src/karts/controller/kart_control.hpp
Expand Up @@ -19,9 +19,9 @@
#ifndef HEADER_KART_CONTROL_HPP
#define HEADER_KART_CONTROL_HPP

#include "network/message.hpp"
//NETWORK_UPDATE_PLZ

/**
/**
* \ingroup controller
*/
class KartControl
Expand Down Expand Up @@ -52,15 +52,6 @@ class KartControl
reset();
}
// ------------------------------------------------------------------------
/** Construct kart control from a Message (i.e. unserialise) */
KartControl(Message *m)
{
m_steer = m->getFloat();
m_accel = m->getFloat();
char c = m->getChar();
setButtonsCompressed(c);
} // KartControl(Message*)
// ------------------------------------------------------------------------
/** Resets all controls. */
void reset()
{
Expand All @@ -74,17 +65,6 @@ class KartControl
m_look_back = false;
} // reset
// ------------------------------------------------------------------------
/** Return the serialised size in bytes. */
static int getLength() { return 9; }
// ------------------------------------------------------------------------
/** Serialises the kart control into a message. */
void serialise(Message *m) const
{
m->addFloat(m_steer);
m->addFloat(m_accel);
m->addChar(getButtonsCompressed());
} // compress
// ------------------------------------------------------------------------
void uncompress(char *c)
{
m_steer = ((float*)c)[0];
Expand Down
2 changes: 1 addition & 1 deletion src/karts/controller/skidding_ai.cpp
Expand Up @@ -298,7 +298,7 @@ void SkiddingAI::update(float dt)
#endif

// The client does not do any AI computations.
if(network_manager->getMode()==NetworkManager::NW_CLIENT)
if(NetworkManager::getInstance()->isClient())
{
AIBaseController::update(dt);
return;
Expand Down
17 changes: 8 additions & 9 deletions src/karts/kart.cpp
Expand Up @@ -56,7 +56,6 @@
#include "karts/max_speed.hpp"
#include "karts/skidding.hpp"
#include "modes/linear_world.hpp"
#include "network/race_state.hpp"
#include "network/network_manager.hpp"
#include "physics/btKart.hpp"
#include "physics/btKartRaycast.hpp"
Expand All @@ -78,6 +77,8 @@
# include <math.h>
#endif

//NETWORK_UPDATE_PLZ

/** The kart constructor.
* \param ident The identifier for the kart model to use.
* \param position The position (or rank) for this kart (between 1 and
Expand Down Expand Up @@ -867,11 +868,11 @@ void Kart::collectedItem(Item *item, int add_info)
// Attachments and powerups are stored in the corresponding
// functions (hit{Red,Green}Item), so only coins need to be
// stored here.
if(network_manager->getMode()==NetworkManager::NW_SERVER &&
/*if(NetworkManager::getInstance()->isServer() &&
(type==Item::ITEM_NITRO_BIG || type==Item::ITEM_NITRO_SMALL) )
{
race_state->itemCollected(getWorldKartId(), item->getItemId());
}
}*/

if ( m_collected_energy > m_kart_properties->getNitroMax())
m_collected_energy = m_kart_properties->getNitroMax();
Expand Down Expand Up @@ -1012,9 +1013,9 @@ void Kart::update(float dt)
// Store the actual kart controls at the start of update in the server
// state. This makes it easier to reset some fields when they are not used
// anymore (e.g. controls.fire).
if(network_manager->getMode()==NetworkManager::NW_SERVER)
if(NetworkManager::getInstance()->isServer())
{
race_state->storeKartControls(*this);
//race_state->storeKartControls(*this);
}

if (!m_flying)
Expand Down Expand Up @@ -1815,10 +1816,8 @@ void Kart::updatePhysics(float dt)

updateSliding();

// Only compute the current speed if this is not the client. On a client the
// speed is actually received from the server.
if(network_manager->getMode()!=NetworkManager::NW_CLIENT)
m_speed = getVehicle()->getRigidBody()->getLinearVelocity().length();
// Compute the speed of the kart.
m_speed = getVehicle()->getRigidBody()->getLinearVelocity().length();

// calculate direction of m_speed
const btTransform& chassisTrans = getVehicle()->getChassisWorldTransform();
Expand Down
36 changes: 10 additions & 26 deletions src/main.cpp
Expand Up @@ -169,6 +169,8 @@
#include "modes/demo_world.hpp"
#include "modes/profile_world.hpp"
#include "network/network_manager.hpp"
#include "network/client_network_manager.hpp"
#include "network/server_network_manager.hpp"
#include "race/grand_prix_manager.hpp"
#include "race/highscore_manager.hpp"
#include "race/history.hpp"
Expand Down Expand Up @@ -683,22 +685,17 @@ int handleCmdLine(int argc, char **argv)
}
else if(sscanf(argv[i], "--server=%d",&n)==1)
{
network_manager->setMode(NetworkManager::NW_SERVER);
NetworkManager::getInstance<ServerNetworkManager>(); //create the server
UserConfigParams::m_server_port = n;
}
else if( !strcmp(argv[i], "--server") )
{
network_manager->setMode(NetworkManager::NW_SERVER);
NetworkManager::getInstance<ServerNetworkManager>();
}
else if( sscanf(argv[i], "--port=%d", &n) )
{
UserConfigParams::m_server_port=n;
}
else if( sscanf(argv[i], "--client=%1023s", s) )
{
network_manager->setMode(NetworkManager::NW_CLIENT);
UserConfigParams::m_server_address=s;
}
else if ( sscanf(argv[i], "--gfx=%d", &n) )
{
if (n)
Expand Down Expand Up @@ -1142,9 +1139,10 @@ void initRest()
kart_properties_manager = new KartPropertiesManager();
projectile_manager = new ProjectileManager ();
powerup_manager = new PowerupManager ();
// If the server has been created (--server option), this will do nothing:
NetworkManager::getInstance<ClientNetworkManager>();
attachment_manager = new AttachmentManager ();
highscore_manager = new HighscoreManager ();
network_manager = new NetworkManager ();
KartPropertiesManager::addKartSearchDir(
file_manager->getAddonsFile("karts/"));
track_manager->addTrackSearchDir(
Expand Down Expand Up @@ -1191,7 +1189,7 @@ void cleanSuperTuxKart()
INetworkHttp::destroy();
if(news_manager) delete news_manager;
if(addons_manager) delete addons_manager;
if(network_manager) delete network_manager;
NetworkManager::kill();
if(grand_prix_manager) delete grand_prix_manager;
if(highscore_manager) delete highscore_manager;
if(attachment_manager) delete attachment_manager;
Expand Down Expand Up @@ -1449,7 +1447,7 @@ int main(int argc, char *argv[] )
{
// This will setup the race manager etc.
history->Load();
network_manager->setupPlayerKartInfo();
// network_manager->setupPlayerKartInfo();
race_manager->startNew(false);
main_loop->run();
// well, actually run() will never return, since
Expand All @@ -1458,20 +1456,6 @@ int main(int argc, char *argv[] )
exit(-3);
}

// Initialise connection in case that a command line option was set
// configuring a client or server. Otherwise this function does nothing
// here (and will be called again from the network gui).
if(!network_manager->initialiseConnections())
{
Log::error("main", "Problems initialising network connections,\n"
"Running in non-network mode.");
}
// On the server start with the network information page for now
if(network_manager->getMode()==NetworkManager::NW_SERVER)
{
// TODO - network menu
//menu_manager->pushMenu(MENUID_NETWORK_GUI);
}
// Not replaying
// =============
if(!ProfileWorld::isProfileMode())
Expand All @@ -1481,7 +1465,7 @@ int main(int argc, char *argv[] )
// Quickstart (-N)
// ===============
// all defaults are set in InitTuxkart()
network_manager->setupPlayerKartInfo();
// network_manager->setupPlayerKartInfo();
race_manager->startNew(false);
}
}
Expand All @@ -1491,7 +1475,7 @@ int main(int argc, char *argv[] )
// =========
race_manager->setMajorMode (RaceManager::MAJOR_MODE_SINGLE);
race_manager->setDifficulty(RaceManager::DIFFICULTY_HARD);
network_manager->setupPlayerKartInfo();
// network_manager->setupPlayerKartInfo();
race_manager->startNew(false);
}
main_loop->run();
Expand Down

0 comments on commit 613e97d

Please sign in to comment.