home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / game / client / ClientEntity.h < prev    next >
C/C++ Source or Header  |  2005-11-14  |  5KB  |  192 lines

  1. //----------------------------------------------------------------
  2. // ClientEntity.h
  3. //
  4. // Copyright 2002-2004 Raven Software
  5. //----------------------------------------------------------------
  6.  
  7. #ifndef __GAME_CLIENT_ENTITY_H__
  8. #define __GAME_CLIENT_ENTITY_H__
  9.  
  10. class rvClientEntity : public idClass {
  11. public:
  12.  
  13.     ABSTRACT_PROTOTYPE( rvClientEntity );
  14.  
  15.     rvClientEntity ( void );
  16.     virtual ~rvClientEntity ( void );
  17.  
  18.     virtual void        Present                ( void );
  19.     virtual void        Think                ( void );
  20.     virtual idPhysics*    GetPhysics            ( void ) const;
  21.     virtual bool        Collide                ( const trace_t &collision, const idVec3 &velocity );
  22.  
  23.     void                SetOrigin            ( const idVec3& origin );
  24.     void                SetAxis                ( const idMat3& axis );
  25.     const idVec3&        GetOrigin            ( void );
  26.     const idMat3&        GetAxis                ( void );
  27.     
  28.     void                Bind                ( idEntity* master, jointHandle_t joint = INVALID_JOINT );
  29.     void                Unbind                ( void );
  30.  
  31.     virtual bool        IsClient            ( void ) const;
  32.     virtual void        DrawDebugInfo        ( void ) const;
  33.  
  34.     int                    StartSoundShader    ( const idSoundShader *shader, const s_channelType channel, int soundShaderFlags );
  35.  
  36.     // I'm guessing someone may decide to derive from rvClientEntity, so this virtual.
  37.     virtual    size_t        Size                ( void ) const;
  38.  
  39.     virtual void        FreeEntityDef        ( void );
  40.  
  41.     const idEntityPtr<idEntity>&            GetBindMaster( void ) const;
  42.  
  43.     void                Save                ( idSaveGame *savefile ) const;
  44.     void                Restore                ( idRestoreGame *savefile );
  45.  
  46. protected:
  47.  
  48.     void                RunPhysics            ( void );
  49.  
  50.     virtual void        UpdateBind            ( void );
  51.     void                UpdateSound            ( void );
  52.  
  53. public:
  54.     
  55.     int                            entityNumber;
  56.  
  57.     idLinkList<rvClientEntity>    spawnNode;
  58.     idLinkList<rvClientEntity>    bindNode;
  59.  
  60. protected:
  61.  
  62.     idVec3                        worldOrigin;
  63.     idMat3                        worldAxis;
  64.  
  65.     idEntityPtr<idEntity>        bindMaster;
  66.     idVec3                        bindOrigin;
  67.     idMat3                        bindAxis;
  68.     jointHandle_t                bindJoint;
  69.     
  70.     refSound_t                    refSound;
  71. };
  72.  
  73. ID_INLINE const idVec3& rvClientEntity::GetOrigin ( void ) {
  74.     return worldOrigin;
  75. }
  76.  
  77. ID_INLINE const idMat3& rvClientEntity::GetAxis ( void ) {
  78.     return worldAxis;
  79. }
  80.  
  81. ID_INLINE const idEntityPtr<idEntity>& rvClientEntity::GetBindMaster( void ) const {
  82.     return bindMaster;
  83. }
  84.  
  85. //============================================================================
  86.  
  87. template< class type >
  88. class rvClientEntityPtr {
  89. public:
  90.                             rvClientEntityPtr();
  91.  
  92.     rvClientEntityPtr<type> &    operator=( type* cent );
  93.  
  94.     int                        GetSpawnId        ( void ) const { return spawnId; }
  95.     bool                    SetSpawnId        ( int id );
  96.     bool                    UpdateSpawnId    ( void );
  97.  
  98.     bool                    IsValid            ( void ) const;
  99.     type *                    GetEntity        ( void ) const;
  100.     int                        GetEntityNum    ( void ) const;
  101.  
  102.     type *                    operator->        ( void ) const { return GetEntity ( ); }            
  103.     operator                type*            ( void ) const { return GetEntity ( ); }
  104.  
  105.     void                    Save            ( idSaveGame *savefile ) const;
  106.     void                    Restore            ( idRestoreGame *savefile );
  107.  
  108. private:
  109.     int                        spawnId;
  110. };
  111.  
  112. template< class type >
  113. ID_INLINE rvClientEntityPtr<type>::rvClientEntityPtr() {
  114.     spawnId = 0;
  115. }
  116.  
  117. template< class type >
  118. ID_INLINE rvClientEntityPtr<type> &rvClientEntityPtr<type>::operator=( type *cent ) {
  119.     if ( cent == NULL ) {
  120.         spawnId = 0;
  121.     } else {
  122.         spawnId = ( gameLocal.clientSpawnIds[cent->entityNumber] << CENTITYNUM_BITS ) | cent->entityNumber;
  123.     }
  124.     return *this;
  125. }
  126.  
  127. template< class type >
  128. ID_INLINE bool rvClientEntityPtr<type>::SetSpawnId( int id ) {
  129.     if ( id == spawnId ) {
  130.         return false;
  131.     }
  132.     if ( ( id >> CENTITYNUM_BITS ) == gameLocal.clientSpawnIds[ id & ( ( 1 << CENTITYNUM_BITS ) - 1 ) ] ) {
  133.         spawnId = id;
  134.         return true;
  135.     }
  136.     return false;
  137. }
  138.  
  139. template< class type >
  140. ID_INLINE bool rvClientEntityPtr<type>::IsValid( void ) const {
  141.     return ( gameLocal.clientSpawnIds[ spawnId & ( ( 1 << CENTITYNUM_BITS ) - 1 ) ] == ( spawnId >> CENTITYNUM_BITS ) );
  142. }
  143.  
  144. template< class type >
  145. ID_INLINE type *rvClientEntityPtr<type>::GetEntity( void ) const {
  146.     int entityNum = spawnId & ( ( 1 << CENTITYNUM_BITS ) - 1 );
  147.     if ( ( gameLocal.clientSpawnIds[ entityNum ] == ( spawnId >> CENTITYNUM_BITS ) ) ) {
  148.         return static_cast<type *>( gameLocal.clientEntities[ entityNum ] );
  149.     }
  150.     return NULL;
  151. }
  152.  
  153. template< class type >
  154. ID_INLINE int rvClientEntityPtr<type>::GetEntityNum( void ) const {
  155.     return ( spawnId & ( ( 1 << CENTITYNUM_BITS ) - 1 ) );
  156. }
  157.  
  158. template< class type >
  159. ID_INLINE void rvClientEntityPtr<type>::Save( idSaveGame *savefile ) const {
  160.     savefile->WriteInt( spawnId );
  161. }
  162.  
  163. template< class type >
  164. ID_INLINE void rvClientEntityPtr<type>::Restore( idRestoreGame *savefile ) {
  165.     savefile->ReadInt( spawnId );
  166. }
  167.  
  168. /*
  169. ===============================================================================
  170.  
  171. rvClientPhysics
  172.  
  173. ===============================================================================
  174. */
  175.  
  176. class rvClientPhysics : public idEntity {
  177. public:
  178.  
  179.     CLASS_PROTOTYPE( rvClientPhysics );
  180.  
  181.                         rvClientPhysics( void ) { currentEntityNumber = -1; }
  182.  
  183.     void                Spawn( void );
  184.  
  185.     virtual bool        Collide( const trace_t &collision, const idVec3 &velocity );
  186.     
  187.     int        currentEntityNumber;
  188. };
  189.  
  190.  
  191. #endif // __GAME_CLIENT_ENTITY_H__
  192.