/* $Id: event.hpp,v 1.23 2005/07/06 10:39:40 pohlt Exp $ */ #ifndef _EVENT_HPP_ #define _EVENT_HPP_ #include #include "global.hpp" #include "serializable.hpp" #include "serialize.hpp" class Event : public Serializable { public: typedef enum Action { EMPTY = 0x00000000, WEAPON = 0x0000000f, LEFT = 0x00000010, RIGHT = 0x00000020, UP = 0x00000040, DOWN = 0x00000080, SHOOT = 0x00000100, JUMP = 0x00000200, DIG = 0x00000400, JET = 0x00000800, ROPE_ON = 0x00001000, ROPE_OFF = 0x00002000, ROPE_IN = 0x00004000, ROPE_OUT = 0x00008000, ROPE_REL = 0x00010000, INSERT_REPLAY_BOOKMARK = 0x00020000, SCREENSHOT = 0x00040000, DEBUG = 0x00080000, SPAWN = 0x00100000, N_A = 0x80000000}; Event( const Uint32 e = 0 ); Event( const Uint32 a, const Uint32 w ); void clear( void ); void addAction( const Uint32 a ); void setAction( const Uint32 a ); void removeAction( const Uint32 a ); Action get( void ) const; bool testAnyActions (const Uint32 a ) const; bool testAllActions (const Uint32 a ) const; void setWeapon( const Uint32 w ); void removeWeapon( void ); Uint32 getWeapon( void ) const; Uint32 getUInt32( void ) const; static Uint32 getStaticSerializeBufferSize() { return Serialize::sizeOf(); } virtual void serialize( Uint8*& bufferPointer ) const; virtual void deserialize( Uint8*& bufferPointer ); virtual Uint32 getSerializeBufferSize() const { return getStaticSerializeBufferSize(); } private: Action m_action; }; inline Event::Event( const Uint32 e ) { m_action = static_cast( e ); } inline Event::Event( const Uint32 a, const Uint32 w ) { DBG (3) ASSERT ((a & 0x0f) == 0, "Event::Event: Action is out of range: %i\n", a); DBG (3) ASSERT (w <= 15, "Event::Event: Weapon index is out of range [1, 15]: %i\n", w); m_action = Action( a | w ); } inline void Event::clear() { m_action = EMPTY; } inline void Event::setAction( const Uint32 a ) { DBG (3) ASSERT ((a & 0x0f) == 0, "Event::setAction: Action is out of range: %i\n", a); m_action = Action( (m_action & WEAPON) | a ); } inline void Event::addAction( const Uint32 a ) { DBG (3) ASSERT ((a & 0x0f) == 0, "Event::addAction: Action is out of range: %i\n", a); m_action = Action (m_action | a); } inline void Event::removeAction( const Uint32 a ) { DBG (3) ASSERT ((a & 0x0f) == 0, "Event::removeAction: Action is out of range: %i\n", a); m_action = Action ((m_action & WEAPON) | (m_action & ~a)); } inline Event::Action Event::get() const { return m_action; } inline bool Event::testAnyActions( const Uint32 a ) const { DBG (3) ASSERT ((a & 0x0f) == 0, "Event::testAnyActions: Action is out of range: %i\n", a); return (m_action & a) != 0; } inline bool Event::testAllActions( const Uint32 a ) const { DBG (3) ASSERT ((a & 0x0f) == 0, "Event::testAllActions: Action is out of range: %i\n", a); return (m_action & a) == a; } inline void Event::setWeapon( const Uint32 w ) { DBG (3) ASSERT (w >= 1 && w <= 15, "Event::setWeapon: Weapon index is out of range [1, 15]: %i\n", w); m_action = Action ((m_action & ~WEAPON) | w); } inline void Event::removeWeapon() { m_action = Action (m_action & ~WEAPON); } inline Uint32 Event::getWeapon() const { return m_action & WEAPON; } inline Uint32 Event::getUInt32( void ) const { return m_action; } inline void Event::serialize( Uint8*& bufferPointer ) const { Serialize::serialize( m_action, bufferPointer ); } inline void Event::deserialize( Uint8*& bufferPointer ) { Serialize::deserialize( bufferPointer, m_action ); } #endif // _EVENT_HPP_