From 22c1c92bf82d9d146a8042fafc7aea10794e8dc8 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Sun, 7 Sep 2008 14:56:17 +0000 Subject: [PATCH] Fixed projectiles for network play. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2245 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/herring_manager.cpp | 2 +- src/network/race_state.cpp | 38 +++++--------------------------------- src/network/race_state.hpp | 35 ++++++++++++++++++++++------------- 3 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/herring_manager.cpp b/src/herring_manager.cpp index 80eb79d6c..0fe054e55 100644 --- a/src/herring_manager.cpp +++ b/src/herring_manager.cpp @@ -221,7 +221,7 @@ void HerringManager::eatenHerring(int herring_id, Kart *kart, void HerringManager::hitHerring(Kart* kart) { // Only do this on the server - if(network_manager->getMode()!=NetworkManager::NW_SERVER) return; + if(network_manager->getMode()==NetworkManager::NW_CLIENT) return; for(AllHerringType::iterator i =m_all_herrings.begin(); i!=m_all_herrings.end(); i++) diff --git a/src/network/race_state.cpp b/src/network/race_state.cpp index 3d6f33101..caade59a5 100644 --- a/src/network/race_state.cpp +++ b/src/network/race_state.cpp @@ -48,11 +48,7 @@ void RaceState::serialise() // We can't use sizeof() here, since the data structures might be padded len += 1 + m_herring_info.size()* HerringInfo::getLength(); - // 3. Add the data about new flyables - // ---------------------------------- - len += 1 + m_new_flyable.size() * 2; - - // 4. Add rocket positions + // 3. Add rocket positions // ----------------------- len += 2 + m_flyable_info.size()*FlyableInfo::getLength(); @@ -66,8 +62,7 @@ void RaceState::serialise() for(unsigned int i=0; igetKart(i); - const KartControl& kc=kart->getControls(); - kc.serialise(this); + m_kart_controls[i].serialise(this); addVec3(kart->getXYZ()); addQuaternion(kart->getRotation()); addFloat(kart->getSpeed()); @@ -81,21 +76,9 @@ void RaceState::serialise() m_herring_info[i].serialise(this); } - // 3. New projectiles - // ------------------ - addChar(m_new_flyable.size()); - for(unsigned int i=0; isetSpeed(getFloat()); } // for i - // Eaten herrings - // -------------- + // 2. Eaten herrings + // ----------------- unsigned short num_herrings=getChar(); for(unsigned int i=0; igetKart(hi.m_kart_id), hi.m_add_info); } - // 3. New flyables - // --------------- - unsigned int new_fl = getChar(); - for(unsigned int i=0; inewProjectile(world->getKart(world_kart_id), - (CollectableType)type); - } - // 4. Projectiles + // 3. Projectiles // -------------- unsigned short num_flyables = getShort(); m_flyable_info.clear(); diff --git a/src/network/race_state.hpp b/src/network/race_state.hpp index e78e328f9..73695198b 100644 --- a/src/network/race_state.hpp +++ b/src/network/race_state.hpp @@ -25,8 +25,11 @@ #include "network/message.hpp" #include "network/herring_info.hpp" #include "network/flyable_info.hpp" +#include "kart_control.hpp" #include "herring.hpp" #include "flyable.hpp" +#include "race_manager.hpp" +#include "kart.hpp" /** This class stores the state information of a (single) race, e.g. the position and orientation of karts, collisions that have happened etc. @@ -41,31 +44,37 @@ private: std::vector m_herring_info; /** Updates about existing flyables. */ std::vector m_flyable_info; - /** List of new flyables. */ - struct NewFlyable{ - char m_type; - char m_kart_id; - }; - std::vector m_new_flyable; + /** Stores the controls of each kart at the beginning of its update(). */ + std::vector m_kart_controls; public: - RaceState() : Message(MT_RACE_STATE) {} + /** Initialise the global race state. */ + RaceState() : Message(MT_RACE_STATE) + { + m_kart_controls.resize(race_manager->getNumKarts()); + } // RaceState() + // -------------------------------------------------------------------- void herringCollected(int kartid, int herring_id, char add_info=-1) { m_herring_info.push_back(HerringInfo(kartid, herring_id, add_info)); } + // -------------------------------------------------------------------- void setNumFlyables(int n) { m_flyable_info.resize(n); } + // -------------------------------------------------------------------- void setFlyableInfo(int n, const FlyableInfo& fi) { m_flyable_info[n] = fi; } - void newFlyable(char type, char kartid) + // -------------------------------------------------------------------- + /** Stores the current kart control (at the time kart->update() is + * called. This allows modifications of kart->m_control during the + * update (e.g. see in kart::update() how firing is handled). + */ + void storeKartControls(const Kart& kart) { - NewFlyable nf; - nf.m_type = type; - nf.m_kart_id = kartid; - m_new_flyable.push_back(nf); - } + m_kart_controls[kart.getWorldKartId()] = kart.getControls(); + } // storeKartControls + // -------------------------------------------------------------------- void serialise(); void receive(ENetPacket *pkt); void clear(); // Removes all currently stored information