/* $Id$ */ #include "object.hpp" #include "world.hpp" #include "serialize.hpp" /**********************************************************/ // World* Object::m_worldPointer = NULL; /**********************************************************/ Object::Object( World* wp ) : m_pos ( 0.0, 0.0 ), m_vel ( 0.0, 0.0 ), m_force ( 0.0, 0.0 ), m_state( LIVING | VISIBLE | WEAPON_VISIBLE ), m_removeMeAfterUpdate( false ), m_Sequence( 0 ), m_SequenceLength( 1 ), m_Frame( 0 ), m_ColorInstance( -1 ), m_worldPointer( wp ) { } /**********************************************************/ Object::~Object() { LOG( 5 ) INFO( "Object::~Object: done\n" ); } /**********************************************************/ bool Object::initFromItem( const ObjectItem &item ) { Sint32 X = item.getX(), Y = item.getY(); // negative coordinates specify distance from right and bottom border if( X < 0 ) X += m_worldPointer->getMap()->getSizeX(); if( Y < 0 ) Y += m_worldPointer->getMap()->getSizeY(); // set position with specified random blur setPos( X + localRnd.getSint32Between(-item.getDX(), item.getDX()), Y + localRnd.getSint32Between(-item.getDY(), item.getDY()) ); // set velocity setVel( Vector( item.getVX(), item.getVY() )); return true; } /**********************************************************/ void Object::updateSequenceLength() { DBG( 1 ) ASSERT( m_worldPointer, "Object::updateSequenceLength: " "m_worldPointer == NULL\n" ); if( m_worldPointer->getSpriteInterface() ) { m_SequenceLength = m_worldPointer ->getSpriteInterface() ->getSequenceLength(this->getID(), m_Sequence); } } /**********************************************************/ void Object::serialize( Uint8*& bufferPointer ) const { // expands to a check of the buffer movement START_OBJECT_SERIALIZED_SIZE_CHECK( bufferPointer ); // expands to tag serialization SERIALIZE_OBJECT_TAG( bufferPointer ); Serialize::serialize( m_pos , bufferPointer ); Serialize::serialize( m_vel , bufferPointer ); Serialize::serialize( m_force , bufferPointer ); Serialize::serialize( m_state , bufferPointer ); Serialize::serialize( m_removeMeAfterUpdate, bufferPointer ); Serialize::serialize( m_Sequence , bufferPointer ); Serialize::serialize( m_SequenceLength , bufferPointer ); Serialize::serialize( m_Frame , bufferPointer ); // do not serialize the index for the colored instance, since // the instance must be created independently on each client // expands to tag serialization SERIALIZE_OBJECT_TAG( bufferPointer ); // expands to a check of the buffer movement END_OBJECT_SERIALIZED_SIZE_CHECK( bufferPointer, Object ); } /**********************************************************/ void Object::deserialize( Uint8*& bufferPointer ) { // expands to tag deserialization DESERIALIZE_OBJECT_TAG( bufferPointer ); Serialize::deserialize( bufferPointer, m_pos ); Serialize::deserialize( bufferPointer, m_vel ); Serialize::deserialize( bufferPointer, m_force ); Serialize::deserialize( bufferPointer, m_state ); Serialize::deserialize( bufferPointer, m_removeMeAfterUpdate ); Serialize::deserialize( bufferPointer, m_Sequence ); Serialize::deserialize( bufferPointer, m_SequenceLength ); Serialize::deserialize( bufferPointer, m_Frame ); // do not deserialize the index for the colored instance, since // the instance must be created independently on each client // expands to tag deserialization DESERIALIZE_OBJECT_TAG( bufferPointer ); } /**********************************************************/ Uint32 Object::getSerializeBufferSize() const { return 3 * Serialize::sizeOf() + Serialize::sizeOf( m_state ) + Serialize::sizeOf( m_removeMeAfterUpdate ) // NOTE: m_ColoredInstance is not (de)serialized + 3 * Serialize::sizeOf() // adds additional size for debugging (see serialize.hpp), // but only, if the tags are used PLUS_TAG_SIZE( 2 ); } /**********************************************************/ void Object::dump( std::ostream& out ) const { using namespace std; out << "Object components:" << endl; out << "\tPosition: " << m_pos.x << " " << m_pos.y << endl; out << "\tVelocity: " << m_vel.x << " " << m_vel.y << endl; out << "\tForce: " << m_force.x << " " << m_force.y << endl; }