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

  1.  
  2. #ifndef __DECLPLAYBACK_H__
  3. #define __DECLPLAYBACK_H__
  4.  
  5. // WARNING: These must stay mirrored in both Q4Monster.state
  6. #define PBFL_GET_POSITION            BIT( 0 )    // Stored in playback file
  7. #define PBFL_GET_ANGLES                BIT( 1 )
  8. #define PBFL_GET_BUTTONS            BIT( 2 )
  9.  
  10. #define PBFL_GET_VELOCITY            BIT( 4 )    // Derived from data
  11. #define PBFL_GET_ACCELERATION        BIT( 5 )
  12. #define PBFL_GET_ANGLES_FROM_VEL    BIT( 6 )
  13.  
  14. #define PBFL_AT_DEST                BIT( 7 )
  15. #define PBFL_RELATIVE_POSITION        BIT( 8 )
  16.  
  17. #define PBFL_ED_MODIFIED            BIT( 29 )
  18. #define PBFL_ED_NEW                    BIT( 30 )
  19. #define PBFL_ED_CHECKEDIN            BIT( 31 )
  20.  
  21. #define PBFL_ED_MASK                ( PBFL_ED_MODIFIED | PBFL_ED_NEW | PBFL_ED_CHECKEDIN )
  22.  
  23. #define PBCB_NONE                    0
  24. #define PBCB_BUTTON_DOWN            1
  25. #define PBCB_BUTTON_UP                2
  26. #define PBCB_IMPULSE                3
  27.  
  28. typedef void ( *pbCallback_t )( int type, float time, const void *data );
  29.  
  30. class rvDeclPlaybackData
  31. {
  32. public:
  33.     void                    Init( void ) { entity = NULL; Callback = NULL; position.Zero(); velocity.Zero(); acceleration.Zero(); angles.Zero(); changed = 0; button = 0; impulse = 0; }
  34.     
  35.     void                    SetPosition( const idVec3 &pos ) { position = pos; }
  36.     void                    SetVelocity( const idVec3 &vel ) { velocity = vel; }
  37.     void                    SetAcceleration( const idVec3 &accel ) { acceleration = accel; }
  38.     void                    SetAngles( const idAngles &ang ) { angles = ang; }
  39.     void                    SetChanged( const byte chg ) { changed = chg; }
  40.     void                    SetButtons( const byte btn ) { button = btn; }
  41.     void                    SetImpulse( const byte imp ) { impulse = imp; }
  42.  
  43.     const idVec3            &GetPosition( void ) const { return( position ); }
  44.     const idVec3            &GetVelocity( void ) const { return( velocity ); }
  45.     const idVec3            &GetAcceleration( void ) const { return( acceleration ); }
  46.     const idAngles            &GetAngles( void ) const { return( angles ); }
  47.     byte                    GetChanged( void ) const { return( changed ); }
  48.     byte                    GetButtons( void ) const { return( button ); }
  49.     byte                    GetImpulse( void ) const { return( impulse ); }
  50.  
  51.     class idEntity            *GetEntity( void ) const { return( entity ); }
  52.  
  53.     void                    SetCallback( class idEntity *ent, pbCallback_t cb ) { entity = ent; Callback = cb; }
  54.     void                    CallCallback( int type, float time ) { if( Callback ) { Callback( type, time, this ); } }
  55. private:
  56.     class idEntity            *entity;
  57.     pbCallback_t            Callback;
  58.  
  59.     idVec3                    position;
  60.     idVec3                    velocity;
  61.     idVec3                    acceleration;
  62.     idAngles                angles;
  63.     byte                    changed;
  64.     byte                    button;
  65.     byte                    impulse;
  66. };
  67.  
  68. class rvButtonState
  69. {
  70. public:
  71.     void                    Init( float t, byte b = 0, byte i = 0 ) { time = t; state = b; impulse = i; }
  72.  
  73.     float                    time;
  74.     byte                    state;
  75.     byte                    impulse;
  76. };
  77.  
  78. #ifdef RV_BINARYDECLS
  79. class rvDeclPlayback : public idDecl, public Serializable<'RDP '>
  80. {
  81. public:
  82. // jsinger: allow exporting of this decl type in a preparsed form
  83.     virtual void            Write( SerialOutputStream &stream ) const;
  84.     virtual void            AddReferences() const;
  85.                             rvDeclPlayback( SerialInputStream &stream );
  86. #else
  87. class rvDeclPlayback : public idDecl
  88. {
  89. #endif
  90. public:
  91.                             rvDeclPlayback( void );
  92.                             ~rvDeclPlayback( void );
  93.  
  94.             void            SetFlag( bool on, int flag ) { on ? flags |= flag : flags &= ~flag; }
  95.  
  96.             bool            GetHasPositions( void ) const { return( !!( flags & PBFL_GET_POSITION ) ); }
  97.             bool            GetHasAngles( void ) const { return( !!( flags & PBFL_GET_ANGLES ) ); }
  98.             bool            GetHasButtons( void ) const { return( !!( flags & PBFL_GET_BUTTONS ) ); }
  99.             bool            GetEditorModified( void ) const { return( !!( flags & PBFL_ED_MODIFIED ) ); }
  100.             bool            GetEditorNew( void ) const { return( !!( flags & PBFL_ED_NEW ) ); }
  101.             bool            GetEditorCheckedIn( void ) const { return( !!( flags & PBFL_ED_CHECKEDIN ) ); }
  102.  
  103.             void            SetHasPositions( bool pos ) { SetFlag( pos, PBFL_GET_POSITION ); }
  104.             void            SetHasAngles( bool ang ) { SetFlag( ang, PBFL_GET_ANGLES ); }
  105.             void            SetHasButtons( bool btn ) { SetFlag( btn, PBFL_GET_BUTTONS ); }
  106.             void            SetEditorModified( bool em ) { SetFlag( em, PBFL_ED_MODIFIED ); }
  107.             void            SetEditorNew( bool en ) { SetFlag( en, PBFL_ED_NEW ); }
  108.             void            SetEditorCheckedIn( bool eci ) { SetFlag( eci, PBFL_ED_CHECKEDIN ); }
  109.  
  110.             int                GetFlags( void ) const { return( flags ); }
  111.             void            SetFlags( int in ) { flags = in; }
  112.  
  113.             float            GetFrameRate( void ) const { return( frameRate ); }
  114.             void            SetFrameRate( float in ) { frameRate = in; }
  115.  
  116.             idVec3            GetOrigin( void ) const { return( origin ); }
  117.             void            SetOrigin( idVec3 &in ) { origin = in; }
  118.  
  119.             float            GetDuration( void ) const { return( duration ); }
  120.             void            SetDuration( float dur ) { duration = dur; }
  121.  
  122.             idBounds        GetBounds( void ) const { return( bounds ); }
  123.  
  124.             void            ParseSample( idLexer *src, idVec3 &pos, idAngles &ang );
  125.             void            WriteData( idFile_Memory &f );
  126.             void            WriteButtons( idFile_Memory &f );
  127.             void            WriteSequence( idFile_Memory &f );
  128.  
  129.             bool            ParseData( idLexer *src );
  130.             void            ParseButton( idLexer *src, byte &button, rvButtonState &state );
  131.             bool            ParseSequence( idLexer *src );
  132.             bool            ParseButtons( idLexer *src );
  133.  
  134.             void            Copy( rvDeclPlayback *pb );
  135.             void            SetOrigin( void );
  136.             void            Start( void );
  137.             bool            Finish( float desiredDuration = -1.0f );
  138.  
  139.             bool            SetCurrentData( float localTime, int control, rvDeclPlaybackData *pbd );
  140.             bool            GetCurrentOffset( float localTime, idVec3 &pos ) const;
  141.             bool            GetCurrentAngles( float localTime, idAngles &ang ) const;
  142.             bool            GetCurrentData( int control, float localTime, float lastTime, rvDeclPlaybackData *pbd ) const;
  143.  
  144.     virtual const char        *DefaultDefinition( void ) const;
  145.     virtual bool            Parse( const char *text, const int textLength, bool noCaching );
  146.     virtual void            FreeData( void );
  147.     virtual    bool            RebuildTextSource( void );
  148.     virtual size_t            Size( void ) const;
  149.  
  150. // RAVEN BEGIN
  151. // scork: for detailed error-reporting
  152.     virtual bool            Validate( const char *psText, int iTextLength, idStr &strReportTo ) const;
  153. // RAVEN END
  154.  
  155.  
  156.     idCurve_UniformCubicBSpline<idVec3>        &GetPoints( void ) { return( points ); }
  157.     idCurve_UniformCubicBSpline<idAngles>    &GetAngles( void ) { return( angles ); }
  158.     idList<rvButtonState>                    &GetButtons( void ) { return( buttons ); }
  159.  
  160. private:
  161.  
  162.     int                            flags;
  163.     float                        frameRate;
  164.     float                        duration;
  165.     idVec3                        origin;
  166.     idBounds                    bounds;
  167.  
  168.     idCurve_UniformCubicBSpline<idVec3>        points;
  169.     idCurve_UniformCubicBSpline<idAngles>    angles;
  170.     idList<rvButtonState>                    buttons;
  171. };
  172.  
  173. class rvDeclPlaybackEdit
  174. {
  175. public:
  176.     virtual bool            Finish( rvDeclPlayback *edit, float desiredDuration ) = 0;
  177.     virtual void            SetOrigin( rvDeclPlayback *edit ) = 0;
  178.     virtual void            SetOrigin( rvDeclPlayback *edit, idVec3 &origin ) = 0;
  179.     virtual void            Copy( rvDeclPlayback *edit, rvDeclPlayback *copy ) = 0;
  180. };
  181.  
  182. extern rvDeclPlaybackEdit        *declPlaybackEdit;
  183.  
  184. #endif // __DECLPLAYBACK_H__
  185.