/* $Id: blueglow.cpp,v 1.8 2005/10/14 14:17:20 pohlt Exp $ */ #include "blueglow.hpp" #include "global.hpp" #include "world.hpp" #include "serialize.hpp" /**********************************************************/ #define UPDATES_PER_FRAME 2 /**********************************************************/ BlueGlow::BlueGlow( World* wp, const Sint32 size ) : m_size( SMALLEST_BLUEGLOW ), m_StepCounter( UPDATES_PER_FRAME ) { m_worldPointer = wp; // sequence is chosen randomly in setSize() if( m_worldPointer->getSpriteInterface() ) setSize( size ); } /**********************************************************/ inline void BlueGlow::setSize( const Sint32 size ) { DBG( 1 ) ASSERT( getMinSize() <= size && size <= getMaxSize(), "BlueGlow::setSize: size %d is out of range [%d,%d]\n", size, getMinSize(), getMaxSize() ); // set new size m_size = size; // 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; m_StepCounter = UPDATES_PER_FRAME; } /**********************************************************/ void BlueGlow::update() { if( --m_StepCounter <= 0 ) { // glowing effect only lives for one cycle if( ++m_Frame >= m_SequenceLength ) { m_removeMeAfterUpdate = true; return; } m_StepCounter = UPDATES_PER_FRAME; } } /******************************************************************************/ Uint32 BlueGlow::getSerializeBufferSize() const { return NonCollidableObject::getSerializeBufferSize() + Serialize::sizeOf( m_size ) + Serialize::sizeOf( m_StepCounter ) // adds additional size for debugging (see serialize.hpp), // but only, if the tags are used PLUS_TAG_SIZE( 1 ); } /******************************************************************************/ void BlueGlow::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_StepCounter, bufferPointer ); // expands to tag serialization SERIALIZE_OBJECT_TAG( bufferPointer ); // expands to a check of the buffer movement END_OBJECT_SERIALIZED_SIZE_CHECK( bufferPointer, BlueGlow ); } /******************************************************************************/ void BlueGlow::deserialize( Uint8*& bufferPointer ) { NonCollidableObject::deserialize( bufferPointer ); Serialize::deserialize( bufferPointer, m_size ); Serialize::deserialize( bufferPointer, m_StepCounter ); // expands to tag deserialization DESERIALIZE_OBJECT_TAG( bufferPointer ); } /******************************************************************************/