src/thirdparty/particles/ParticleDLL/ParticleState.h

Go to the documentation of this file.
00001 // ParticleState.h
00002 //
00003 // Copyright 1998-2005 by David K. McAllister.
00004 //
00005 // Defines these classes: ParticleState
00006 
00007 #ifndef PARTICLESTATE_H
00008 #define PARTICLESTATE_H
00009 
00010 #include "papi.h"
00011 #include "actions.h"
00012 #include "ParticleGroup.h"
00013 
00014 #include <vector>
00015 #include <string>
00016 
00017 typedef std::vector<PActionBase *> ActionList;
00018 
00019 // This is the per-thread state of the API.
00020 // All API calls get their data from here.
00021 // In the non-multithreaded case there is one global instance of this class.
00022 struct ParticleState
00023 {
00024     // Any particles created will get their attributes from here.
00025     pDomain *Up;
00026     pDomain *Vel;
00027     pDomain *RotVel;
00028     pDomain *VertexB;
00029     pDomain *Size;
00030     pDomain *Color;
00031     pDomain *Alpha;
00032     float Age;
00033     float AgeSigma;
00034     float Mass;
00035 
00036     float dt;
00037     bool in_call_list;
00038     bool in_new_list;
00039     bool vertexB_tracks;
00040     int tid;                    // Only used in the multi-threaded case, but always define it.
00041     int ErrorCode;              // Stores the code of the first error this thread has hit since its latest pGetError() call.
00042 
00043     static std::vector<ParticleGroup> PGroups; // Static since all threads access the same action lists. Lock all accesses.
00044     int pgroup_id;
00045     int GeneratePGroups(int pgroups_requested);
00046     ParticleGroup &GetPGroup(int p_group_num);
00047 
00048     static std::vector<ActionList> ALists; // Static since all threads access the same action lists. Lock all accesses.
00049     int alist_id;
00050     int GenerateALists(int alists_requested);
00051     ActionList &GetAList(int a_list_num);
00052 
00053     ParticleState();
00054     ~ParticleState();
00055 
00056     // Action API entry points call this to either store the action in a list or execute and delete it.
00057     void SendAction(PActionBase *S);
00058 
00059     // Execute an action list
00060     void ExecuteActionList(ActionList &AList);
00061 
00062     // Internal functions call this to declare an error
00063     void SetError(const int err, const std::string &str);
00064 };
00065 
00066 #ifdef PARTICLE_MP
00067 // All entry points call this to get their particle state.
00068 inline ParticleState &_GetPState()
00069 {
00070     // Returns a reference to the appropriate particle state.
00071     extern ParticleState &_GetPStateWithTID();
00072 
00073     return _GetPStateWithTID();
00074 }
00075 
00076 inline void _PLock() { /* Do lock stuff here. */ }
00077 inline void _PUnLock() { /* Do unlock stuff here. */ }
00078 
00079 #else
00080 
00081 // All entry points call this to get their particle state.
00082 // For the non-multi-threaded case this is practically a no-op.
00083 inline ParticleState &_GetPState()
00084 {
00085     // This is the global state.
00086     extern ParticleState __ps;
00087 
00088     return __ps;
00089 }
00090 
00091 inline void _PLock() {}
00092 inline void _PUnLock() {}
00093 
00094 #endif
00095 
00096 #define PASSERT(x,y) {if(!(x)) { _GetPState().SetError(PERR_INTERNAL_ERROR, (y)); }}
00097 
00098 #endif // PARTICLESTATE_H

Generated on Sat Mar 15 22:55:58 2008 for Armagetron Advanced by  doxygen 1.5.4