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
This commit is contained in:
parent
9a17f748f1
commit
22c1c92bf8
@ -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++)
|
||||
|
@ -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; i<num_karts; i++)
|
||||
{
|
||||
const Kart* kart=world->getKart(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; i<m_new_flyable.size(); i++)
|
||||
{
|
||||
printf("send new type %d\n",m_new_flyable[i].m_type);
|
||||
addChar(m_new_flyable[i].m_type);
|
||||
addChar(m_new_flyable[i].m_kart_id);
|
||||
}
|
||||
m_new_flyable.clear();
|
||||
|
||||
// 4. Projectiles
|
||||
// --------------
|
||||
addShort(m_flyable_info.size());
|
||||
// The exploded flag could be compressed by combining 8 bits into one byte
|
||||
for(unsigned int i=0; i<m_flyable_info.size(); i++)
|
||||
{
|
||||
m_flyable_info[i].serialise(this);
|
||||
@ -137,8 +120,8 @@ void RaceState::receive(ENetPacket *pkt)
|
||||
kart->setSpeed(getFloat());
|
||||
} // for i
|
||||
|
||||
// Eaten herrings
|
||||
// --------------
|
||||
// 2. Eaten herrings
|
||||
// -----------------
|
||||
unsigned short num_herrings=getChar();
|
||||
for(unsigned int i=0; i<num_herrings; i++)
|
||||
{
|
||||
@ -150,19 +133,8 @@ void RaceState::receive(ENetPacket *pkt)
|
||||
world->getKart(hi.m_kart_id),
|
||||
hi.m_add_info);
|
||||
}
|
||||
// 3. New flyables
|
||||
// ---------------
|
||||
unsigned int new_fl = getChar();
|
||||
for(unsigned int i=0; i<new_fl; i++)
|
||||
{
|
||||
char type = getChar();
|
||||
char world_kart_id = getChar();
|
||||
printf("Received new type %d\n",type);
|
||||
projectile_manager->newProjectile(world->getKart(world_kart_id),
|
||||
(CollectableType)type);
|
||||
}
|
||||
|
||||
// 4. Projectiles
|
||||
// 3. Projectiles
|
||||
// --------------
|
||||
unsigned short num_flyables = getShort();
|
||||
m_flyable_info.clear();
|
||||
|
@ -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<HerringInfo> m_herring_info;
|
||||
/** Updates about existing flyables. */
|
||||
std::vector<FlyableInfo> m_flyable_info;
|
||||
/** List of new flyables. */
|
||||
struct NewFlyable{
|
||||
char m_type;
|
||||
char m_kart_id;
|
||||
};
|
||||
std::vector<NewFlyable> m_new_flyable;
|
||||
/** Stores the controls of each kart at the beginning of its update(). */
|
||||
std::vector<KartControl> 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
|
||||
|
Loading…
Reference in New Issue
Block a user