Particle.h

Go to the documentation of this file.
00001 #ifndef PARTICLE_H_
00002 #define PARTICLE_H_
00003 
00004 #include <memory>
00005 #include <string>
00006 #include "imodel.h"
00007 #include "texturelib.h"
00008 #include "renderable.h"
00009 #include "math/Vector2.h"
00010 #include "math/Vector3.h"
00011 #include "math/Vector4.h"
00012 #include <time.h>
00013 #include "../common/ScriptValues.h"
00014 
00015 #define     MAX_PTLDEFS     256
00016 #define     MAX_PTLCMDS     (MAX_PTLDEFS * 32)
00017 #define     MAX_PCMD_DATA   (MAX_PTLCMDS * 8)
00018 #define     MAX_STACK_DEPTH 8
00019 #define     MAX_STACK_DATA  512
00020 
00021 #define RADR(x)     ((x < 0) ? (byte*)p - x : (byte*) pcmdData + x)
00022 #define RSTACK      -0xFFF0
00023 #define F(x)        (1<<x)
00024 #define V_VECS      (F(V_FLOAT) | F(V_POS) | F(V_VECTOR) | F(V_COLOR))
00025 #define PTL_ONLY_ONE_TYPE       (1<<31)
00026 #define V_UNTYPED   0x7FFF
00027 
00028 namespace scripts
00029 {
00030     class Particle;
00031     class ParticleCommand;
00032     class ParticleDefinition;
00033 
00034     // Smart pointer typedef
00035     typedef std::auto_ptr<scripts::Particle> IParticlePtr;
00036     typedef std::auto_ptr<scripts::ParticleCommand> IParticleCommandPtr;
00037     typedef std::auto_ptr<scripts::ParticleDefinition> IParticleDefinitionPtr;
00038 
00039     class ParticleCommand
00040     {
00041         public:
00042             unsigned char cmd;
00043             unsigned char type;
00044             int ref;
00045     };
00046 
00047     class ParticleDefinition
00048     {
00049         public:
00050             std::string name;
00051             IParticleCommandPtr init;
00052             IParticleCommandPtr run;
00053             IParticleCommandPtr think;
00054             IParticleCommandPtr round;
00055             IParticleCommandPtr physics;
00056     };
00057 
00058     namespace
00059     {
00060 
00061         static IParticleDefinitionPtr ptlDef[MAX_PTLDEFS];
00062         static IParticleCommandPtr ptlCmd[MAX_PTLCMDS];
00063 
00064         enum
00065         {
00066             V_FLOAT, V_POS, V_COLOR, V_STRING, V_INT, V_BOOL, V_NUM_TYPES, V_VECTOR
00067         };
00068 
00069         static const char * vt_names[V_NUM_TYPES] = {"float", "pos", "color", "string", "int", "bool"};
00070 
00071         typedef enum pc_s
00072         {
00073             PC_END,
00074 
00075             PC_PUSH,
00076             PC_POP,
00077             PC_KPOP,
00078             PC_ADD,
00079             PC_SUB,
00080             PC_MUL,
00081             PC_DIV,
00082             PC_SIN,
00083             PC_COS,
00084             PC_TAN,
00085             PC_RAND,
00086             PC_CRAND,
00087             PC_V2,
00088             PC_V3,
00089             PC_V4,
00090 
00091             PC_KILL,
00092             PC_SPAWN,
00093             PC_NSPAWN,
00094             PC_CHILD,
00095 
00096             PC_NUM_PTLCMDS
00097         } pc_t;
00098 
00100         static const char *pc_strings[PC_NUM_PTLCMDS] = { "end",
00101 
00102         "push", "pop", "kpop", "add", "sub", "mul", "div", "sin", "cos", "tan", "rand", "crand", "v2", "v3", "v4",
00103 
00104         "kill", "spawn", "nspawn", "child" };
00105 
00107         static const int pc_types[PC_NUM_PTLCMDS] = { 0,
00108 
00109         V_UNTYPED, V_UNTYPED, V_UNTYPED, V_VECS, V_VECS, V_VECS, V_VECS, PTL_ONLY_ONE_TYPE | V_FLOAT, PTL_ONLY_ONE_TYPE
00110                 | V_FLOAT, PTL_ONLY_ONE_TYPE | V_FLOAT, V_VECS, V_VECS, 0, 0, 0,
00111 
00112         0, PTL_ONLY_ONE_TYPE | V_STRING, PTL_ONLY_ONE_TYPE | V_STRING, PTL_ONLY_ONE_TYPE | V_STRING };
00113 
00115         typedef struct value_s
00116         {
00117                 const char *string;
00118                 const int type;
00119                 const size_t ofs;
00120         } value_t;
00121 
00122 #if 0
00123     static int numPtlDefs;
00124     static int numPtlCmds;
00125 
00126     static unsigned char pcmdData[MAX_PCMD_DATA];
00127     static unsigned char *pcmdPos;
00128 
00129     static unsigned char cmdStack[MAX_STACK_DATA];
00130     static void *stackPtr[MAX_STACK_DEPTH];
00131     static unsigned char stackType[MAX_STACK_DEPTH];
00132 #endif
00133     }
00134 
00135     struct ParticleData
00136     {
00137             time_t msec;
00138             time_t frametime;
00139 
00140             model::IModelPtr modelPtr;
00141             qtexture_t *imagePtr;
00142 
00143             std::string model;
00144             std::string image;
00145 
00146             int blend;
00147             int style;
00148             Vector2 size;
00149             Vector3 scale;
00150             Vector4 color;
00151             Vector3 s; 
00152             Vector3 origin; 
00153             Vector3 offset;
00154             Vector3 angles;
00155             Vector3 lightColor;
00156             float lightIntensity;
00157             float lightSustain;
00158             int levelFlags;
00159 
00160             int skin; 
00162             IParticlePtr children; 
00163             IParticlePtr next; 
00164             IParticlePtr parent; 
00166             ParticleDefinition ctrl;
00167             int startTime;
00168             int frame, endFrame;
00169             float fps; 
00170             float lastFrame; 
00171             float tps; 
00172             float lastThink;
00173             unsigned char thinkFade, frameFade;
00174             float t; 
00175             float dt; 
00176             float life; 
00177             int rounds; 
00178             int roundsCnt;
00179             float scrollS;
00180             float scrollT;
00181             Vector3 a; 
00182             Vector3 v; 
00183             Vector3 omega; 
00184             bool physics; 
00185             bool autohide; 
00188             bool stayalive; 
00189             bool weather; 
00191     };
00192 
00193     class Particle: public Renderable
00194     {
00195         private:
00196 
00197             ParticleData _data;
00198 
00199         public:
00200             Particle ();
00201 
00202             virtual ~Particle ();
00203 
00204             std::string toString ();
00205 
00206             void render ();
00207 
00209             void renderSolid (Renderer& renderer, const VolumeTest& volume) const;
00210 
00212             void renderWireframe (Renderer& renderer, const VolumeTest& volume) const;
00213 
00214             void renderComponents (Renderer&, const VolumeTest&);
00215 
00216     };
00217     scripts::IParticlePtr loadParticle (const std::string& particleID);
00218 }
00219 
00220 #endif /* PARTICLE_H_ */

Generated by  doxygen 1.6.2