/* $Id: explosion.cpp,v 1.18 2005/11/13 11:35:14 uwe Exp $ */ #include "explosion.hpp" #include "global.hpp" #include "world.hpp" #include "serialize.hpp" /**********************************************************/ // "nearly 1.0". Since the accumulated time is incremented in each // call of update, there might be some roundoff errors. To make sure // that the condition "if(accumulatedDT >= DELTA_T_PER_ANIMATION_STEP)" // is true whenever it should be true, we use 0.99 instead of 1.0 #define DELTA_T_PER_ANIMATION_STEP 0.99 /**********************************************************/ Explosion::Explosion() : m_size( 0 ), m_AccumulatedDT( 0.0 ) { // sequence is chosen randomly in setSize() // setSize( size ); } /**********************************************************/ void Explosion::setSize( const Sint32 size ) { DBG( 1 ) ASSERT( getMinSize() <= size && size <= getMaxSize(), "Explosion::setSize: size %d is out of range [%d,%d]\n", size, getMinSize(), getMaxSize() ); // If the world does not yet have a sprite interface, the // call of setSequence below is not possible. This situation // should only occure during deserialization of the world and // should not cause any further problems in this case, since // valid data are deserialized into the object immediately. if( ! m_worldPointer->getSpriteInterface() ) return; // set new size m_size = size; //////////////////////////////////////////////// //// commented out this check on 27/06/2004 //// //// I think, we do not need it //////////////// // if( m_size < getMinSize() ) m_size = getMinSize(); // else if( m_size > getMaxSize() ) m_size = getMaxSize(); //////////////////////////////////////////////// // choose a sequence randomly // this also sets m_SequenceLength setSequence( m_worldPointer->getRandom().getUint32() % m_worldPointer->getSpriteInterface() ->getNumSequences(*this) ); // start sequence in any case m_Frame = 0; } /**********************************************************/ void Explosion::update() { if( (m_AccumulatedDT += m_worldPointer->getDT(m_pos)) >= DELTA_T_PER_ANIMATION_STEP ) { m_AccumulatedDT = 0.0; // explosions only live for one cycle if( ++m_Frame >= m_SequenceLength ) { m_removeMeAfterUpdate = true; return; } } } /******************************************************************************/ void Explosion::serialize( Uint8*& bufferPointer ) const { // expands to a check of the buffer movement START_OBJECT_SERIALIZED_SIZE_CHECK( bufferPointer ); NonCollidableObject::serialize( bufferPointer ); Serialize::serialize( m_size, bufferPointer ); Serialize::serialize( m_AccumulatedDT, bufferPointer ); // expands to tag serialization SERIALIZE_OBJECT_TAG( bufferPointer ); // expands to a check of the buffer movement END_OBJECT_SERIALIZED_SIZE_CHECK( bufferPointer, Explosion ); } /******************************************************************************/ void Explosion::deserialize( Uint8*& bufferPointer ) { NonCollidableObject::deserialize( bufferPointer ); Serialize::deserialize( bufferPointer, m_size ); Serialize::deserialize( bufferPointer, m_AccumulatedDT ); // expands to tag deserialization DESERIALIZE_OBJECT_TAG( bufferPointer ); } /******************************************************************************/ Uint32 Explosion::getSerializeBufferSize() const { return NonCollidableObject::getSerializeBufferSize() + Serialize::sizeOf( m_size ) + Serialize::sizeOf( m_AccumulatedDT ) // adds additional size for debugging (see serialize.hpp), // but only, if the tags are used PLUS_TAG_SIZE( 1 ); } /******************************************************************************/