2008-09-07 10:34:04 -04:00
|
|
|
// $Id:kart_update_message.cpp 2128 2008-06-13 00:53:52Z cosmosninja $
|
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2008 Joerg Henrichs
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 3
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
2009-06-11 06:00:43 -04:00
|
|
|
|
|
|
|
#include "network/kart_update_message.hpp"
|
|
|
|
|
2008-09-21 12:07:56 -04:00
|
|
|
#include "modes/world.hpp"
|
2008-11-06 23:34:01 -05:00
|
|
|
#include "karts/kart.hpp"
|
2008-09-07 10:34:04 -04:00
|
|
|
|
|
|
|
KartUpdateMessage::KartUpdateMessage()
|
|
|
|
: Message(Message::MT_KART_INFO)
|
|
|
|
{
|
2010-02-10 06:40:33 -05:00
|
|
|
World *world = RaceManager::getWorld();
|
|
|
|
unsigned int num_karts = world->getNumKarts();
|
2008-09-07 10:55:05 -04:00
|
|
|
|
2008-09-07 10:34:04 -04:00
|
|
|
// Send the number of karts and for each kart the compressed
|
|
|
|
// control structure (3 ints) and xyz,hpr (4 floats: quaternion:
|
2008-09-07 10:42:37 -04:00
|
|
|
allocate(getCharLength()+
|
2008-09-07 10:55:05 -04:00
|
|
|
num_karts*(KartControl::getLength() + getVec3Length()
|
2008-09-07 10:42:37 -04:00
|
|
|
+getQuaternionLength()) );
|
|
|
|
addChar(num_karts);
|
2008-09-07 10:34:04 -04:00
|
|
|
for(unsigned int i=0; i<num_karts; i++)
|
|
|
|
{
|
2010-02-10 06:40:33 -05:00
|
|
|
const Kart* kart = world->getKart(i);
|
2008-09-07 10:34:04 -04:00
|
|
|
const KartControl& kc=kart->getControls();
|
2008-09-07 10:55:05 -04:00
|
|
|
kc.serialise(this);
|
2008-09-07 10:42:37 -04:00
|
|
|
addVec3(kart->getXYZ());
|
|
|
|
addQuaternion(kart->getRotation());
|
2008-09-07 10:34:04 -04:00
|
|
|
} // for i
|
|
|
|
} // KartUpdateMessage
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
KartUpdateMessage::KartUpdateMessage(ENetPacket* pkt)
|
|
|
|
: Message(pkt, MT_KART_INFO)
|
|
|
|
{
|
2010-02-10 06:40:33 -05:00
|
|
|
World *world = RaceManager::getWorld();
|
2008-09-07 10:34:04 -04:00
|
|
|
unsigned int num_karts = getInt();
|
|
|
|
for(unsigned int i=0; i<num_karts; i++)
|
|
|
|
{
|
2008-09-07 10:42:37 -04:00
|
|
|
// Currently not used
|
2008-09-07 10:55:05 -04:00
|
|
|
KartControl kc(this);
|
2008-09-07 10:34:04 -04:00
|
|
|
Vec3 xyz = getVec3();
|
|
|
|
btQuaternion q = getQuaternion();
|
2010-02-10 06:40:33 -05:00
|
|
|
Kart *kart = world->getKart(i);
|
2008-09-07 10:34:04 -04:00
|
|
|
kart->setXYZ(xyz);
|
|
|
|
kart->setRotation(q);
|
|
|
|
} // for i
|
|
|
|
}; // KartUpdateMessage
|
|
|
|
|