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

  1. // Copyright (C) 2004 Id Software, Inc.
  2. //
  3.  
  4. #ifndef __DECLAF_H__
  5. #define __DECLAF_H__
  6.  
  7. /*
  8. ===============================================================================
  9.  
  10.     Articulated Figure
  11.  
  12. ===============================================================================
  13. */
  14.  
  15. class idDeclAF;
  16.  
  17. typedef enum {
  18.     DECLAF_CONSTRAINT_INVALID,
  19.     DECLAF_CONSTRAINT_FIXED,
  20.     DECLAF_CONSTRAINT_BALLANDSOCKETJOINT,
  21.     DECLAF_CONSTRAINT_UNIVERSALJOINT,
  22.     DECLAF_CONSTRAINT_HINGE,
  23.     DECLAF_CONSTRAINT_SLIDER,
  24.     DECLAF_CONSTRAINT_SPRING
  25. } declAFConstraintType_t;
  26.  
  27. typedef enum {
  28.     DECLAF_JOINTMOD_AXIS,
  29.     DECLAF_JOINTMOD_ORIGIN,
  30.     DECLAF_JOINTMOD_BOTH
  31. } declAFJointMod_t;
  32.  
  33. typedef bool (*getJointTransform_t)( void *model, const idJointMat *frame, const char *jointName, idVec3 &origin, idMat3 &axis );
  34.  
  35. // RAVEN BEGIN
  36. // jsinger: added to support serialization/deserialization of binary decls
  37. #ifdef RV_BINARYDECLS
  38. class idAFVector : public Serializable<'AFV '> {
  39. public:
  40.     // Serialization methods
  41.     void                    Write(SerialOutputStream &stream) const;
  42.     void                    AddReferences() const;
  43.                             idAFVector(SerialInputStream &stream);
  44.  
  45.  
  46. #else
  47. class idAFVector {
  48. public:
  49. #endif
  50.     enum idAFVectorType_t {
  51. // RAVEN END
  52.         VEC_COORDS = 0,
  53.         VEC_JOINT,
  54.         VEC_BONECENTER,
  55.         VEC_BONEDIR
  56.     }                        type;
  57.     idStr                    joint1;
  58.     idStr                    joint2;
  59.  
  60. public:
  61.                             idAFVector( void );
  62.  
  63.     bool                    Parse( idLexer &src );
  64.     bool                    Finish( const char *fileName, const getJointTransform_t GetJointTransform, const idJointMat *frame, void *model ) const;
  65.     bool                    Write( idFile *f ) const;
  66.     const char *            ToString( idStr &str, const int precision = 8 );
  67.     const idVec3 &            ToVec3( void ) const { return vec; }
  68.     idVec3 &                ToVec3( void ) { return vec; }
  69.  
  70. private:
  71.     mutable idVec3            vec;
  72.     bool                    negate;
  73. };
  74.  
  75. // RAVEN BEGIN
  76. // jsinger: added to support serialization/deserialization of binary decls
  77. #ifdef RV_BINARYDECLS
  78. class idDeclAF_Body : public Serializable<'DAFB'> {
  79. public:
  80.  
  81.     // Serializable Methods
  82.     void                    Write( SerialOutputStream &stream ) const;
  83.                             idDeclAF_Body( SerialInputStream &stream );
  84.     void                    AddReferences() const;
  85. #else
  86. class idDeclAF_Body {
  87. #endif
  88. public:
  89.                             idDeclAF_Body();
  90. // RAVEN END
  91.     idStr                    name;
  92.     idStr                    jointName;
  93.     declAFJointMod_t        jointMod;
  94.     int                        modelType;
  95.     idAFVector                v1, v2;
  96.     int                        numSides;
  97.     float                    width;
  98.     float                    density;
  99.     idAFVector                origin;
  100.     idAngles                angles;
  101.     int                        contents;
  102.     int                        clipMask;
  103.     bool                    selfCollision;
  104.     idMat3                    inertiaScale;
  105.     float                    linearFriction;
  106.     float                    angularFriction;
  107.     float                    contactFriction;
  108.     idStr                    containedJoints;
  109.     idAFVector                frictionDirection;
  110.     idAFVector                contactMotorDirection;
  111. public:
  112.     void                    SetDefault( const idDeclAF *file );
  113. };
  114.  
  115. // RAVEN BEGIN
  116. // jsinger: added to support serialization/deserialization of binary decls
  117. #ifdef RV_BINARYDECLS
  118. class idDeclAF_Constraint : public Serializable<'DAFC'> {
  119. public:
  120.     // Serializable Methods
  121.     void                    Write( SerialOutputStream &stream ) const;
  122.                             idDeclAF_Constraint( SerialInputStream &stream );
  123.     void                    AddReferences() const;
  124. #else
  125. class idDeclAF_Constraint {
  126. public:
  127. #endif
  128.                             idDeclAF_Constraint();
  129. // RAVEN END
  130.     idStr                    name;
  131.     idStr                    body1;
  132.     idStr                    body2;
  133.     declAFConstraintType_t    type;
  134.     float                    friction;
  135.     float                    stretch;
  136.     float                    compress;
  137.     float                    damping;
  138.     float                    restLength;
  139.     float                    minLength;
  140.     float                    maxLength;
  141.     idAFVector                anchor;
  142.     idAFVector                anchor2;
  143.     idAFVector                shaft[2];
  144.     idAFVector                axis;
  145. // RAVEN BEGIN
  146. // jsinger: added declAFLimitType_t to support serialization/deserialization of binary decls
  147.     enum declAFLimitType_t {
  148.         LIMIT_NONE = -1,
  149.         LIMIT_CONE,
  150.         LIMIT_PYRAMID
  151.     }                        limit;
  152. // RAVEN END
  153.     idAFVector                limitAxis;
  154.     float                    limitAngles[3];
  155.  
  156. public:
  157.     void                    SetDefault( const idDeclAF *file );
  158. };
  159.  
  160. // RAVEN BEGIN
  161. // jsinger: added to support serialization/deserialization of binary decls
  162. #ifdef RV_BINARYDECLS
  163. class idDeclAF : public idDecl, public Serializable<'DAF '> {
  164. public:
  165.                             idDeclAF( SerialInputStream &stream );
  166.     void                    Write( SerialOutputStream &stream ) const;
  167.     void                    AddReferences() const;
  168. #else
  169. class idDeclAF : public idDecl {
  170. #endif
  171. // RAVEN END
  172.     friend class idAFFileManager;
  173. public:
  174.                             idDeclAF( void );
  175.     virtual                    ~idDeclAF( void );
  176.  
  177.     virtual size_t            Size( void ) const;
  178.     virtual const char *    DefaultDefinition( void ) const;
  179.     virtual bool            Parse( const char *text, const int textLength, bool noCaching );
  180.     virtual void            FreeData( void );
  181.  
  182. // RAVEN BEGIN
  183. // scork: for detailed error-reporting
  184.     virtual bool            Validate( const char *psText, int iTextLength, idStr &strReportTo ) const;
  185. // RAVEN END
  186.  
  187.     virtual void            Finish( const getJointTransform_t GetJointTransform, const idJointMat *frame, void *model ) const;
  188.  
  189.     bool                    Save( void );
  190.  
  191.     void                    NewBody( const char *name );
  192.     void                    RenameBody( const char *oldName, const char *newName );
  193.     void                    DeleteBody( const char *name );
  194.  
  195.     void                    NewConstraint( const char *name );
  196.     void                    RenameConstraint( const char *oldName, const char *newName );
  197.     void                    DeleteConstraint( const char *name );
  198.  
  199.     static int                ContentsFromString( const char *str );
  200.     static const char *        ContentsToString( const int contents, idStr &str );
  201.  
  202.     static declAFJointMod_t    JointModFromString( const char *str );
  203.     static const char *        JointModToString( declAFJointMod_t jointMod );
  204.  
  205. public:
  206.     bool                    modified;
  207.     idStr                    model;
  208.     idStr                    skin;
  209.     float                    defaultLinearFriction;
  210.     float                    defaultAngularFriction;
  211.     float                    defaultContactFriction;
  212.     float                    defaultConstraintFriction;
  213.     float                    totalMass;
  214.     idVec2                    suspendVelocity;
  215.     idVec2                    suspendAcceleration;
  216.     float                    noMoveTime;
  217.     float                    noMoveTranslation;
  218.     float                    noMoveRotation;
  219.     float                    minMoveTime;
  220.     float                    maxMoveTime;
  221.     int                        contents;
  222.     int                        clipMask;
  223.     bool                    selfCollision;
  224. // RAVEN BEGIN
  225. // rjohnson: fast AF eval to skip some things that are not needed for specific circumstances
  226.     bool                    fastEval;
  227. // RAVEN END
  228.     idList<idDeclAF_Body *>            bodies;
  229.     idList<idDeclAF_Constraint *>    constraints;
  230.  
  231. private:
  232.     bool                    ParseContents( idLexer &src, int &c ) const;
  233.     bool                    ParseBody( idLexer &src );
  234.     bool                    ParseFixed( idLexer &src );
  235.     bool                    ParseBallAndSocketJoint( idLexer &src );
  236.     bool                    ParseUniversalJoint( idLexer &src );
  237.     bool                    ParseHinge( idLexer &src );
  238.     bool                    ParseSlider( idLexer &src );
  239.     bool                    ParseSpring( idLexer &src );
  240.     bool                    ParseSettings( idLexer &src );
  241.  
  242.     bool                    WriteBody( idFile *f, const idDeclAF_Body &body ) const;
  243.     bool                    WriteFixed( idFile *f, const idDeclAF_Constraint &c ) const;
  244.     bool                    WriteBallAndSocketJoint( idFile *f, const idDeclAF_Constraint &c ) const;
  245.     bool                    WriteUniversalJoint( idFile *f, const idDeclAF_Constraint &c ) const;
  246.     bool                    WriteHinge( idFile *f, const idDeclAF_Constraint &c ) const;
  247.     bool                    WriteSlider( idFile *f, const idDeclAF_Constraint &c ) const;
  248.     bool                    WriteSpring( idFile *f, const idDeclAF_Constraint &c ) const;
  249.     bool                    WriteConstraint( idFile *f, const idDeclAF_Constraint &c ) const;
  250.     bool                    WriteSettings( idFile *f ) const;
  251.  
  252.     bool                    RebuildTextSource( void );
  253. };
  254.  
  255. // RAVEN BEGIN
  256. class rvDeclAFEdit
  257. {
  258. public:
  259.     virtual bool             Save( idDeclAF *edit ) = 0;
  260.     virtual void             NewBody( idDeclAF *edit, char const *name ) = 0;
  261.     virtual void             RenameBody( idDeclAF *edit, char const *oldName, char const *newName ) = 0;
  262.     virtual void             DeleteBody( idDeclAF *edit, char const *name ) = 0;
  263.     virtual void             NewConstraint( idDeclAF *edit, char const *name ) = 0;
  264.     virtual void             RenameConstraint( idDeclAF *edit, char const *oldName, char const *newName ) = 0;
  265.     virtual void             DeleteConstraint( idDeclAF *edit, char const *name ) = 0;
  266. };
  267.  
  268. extern rvDeclAFEdit            *declAFEdit;
  269. // RAVEN END
  270.  
  271. #endif /* !__DECLAF_H__ */
  272.