00001 #ifndef SGBEHAVIORENGINE_H
00002 #define SGBEHAVIORENGINE_H
00003
00004 #include "SGEngine.h"
00005
00006 namespace Spr {;
00007
00008
00009
00010 enum SGBehaviorPriority{
00011
00012 SGBP_INITIALIZER = 100,
00013 SGBP_CLEARFORCE,
00014
00015 SGBP_FORCEGENERATOR = 200,
00016 SGBP_GRAVITYENGINE,
00017 SGBP_COLLISIONENGINE,
00018 SGBP_PENALTYENGINE,
00019 SGBP_CREATURE,
00020 SGBP_WATERCONTACTENGINE,
00021
00022 SGBP_DYNAMICALSYSTEM = 300,
00023 SGBP_JOINTENGINE,
00024 SGBP_SOLIDCONTAINER,
00025 SGBP_WATERENGINE,
00026
00027 SGBP_MOTION = 400,
00028 SGBP_CHANGEOBJECT,
00029 SGBP_CONSTRAINT,
00030
00031 SGBP_LISTENER = 500,
00032 SGBP_CONTACTENGINE,
00033 SGBP_STICKENGINE,
00034 SGBP_WARPENGINE,
00035 };
00036 class GRRender;
00037 class SGBehaviorStates;
00038
00039 class SGBehaviorEngine:public SGEngine{
00040 public:
00041 SGOBJECTDEF(SGBehaviorEngine);
00042
00043 virtual int GetPriority() const { return SGBP_FORCEGENERATOR; }
00044
00045 virtual void Step(SGScene* s){}
00046
00047 virtual void LoadState(const SGBehaviorStates& states){}
00048
00049 virtual void SaveState(SGBehaviorStates& states) const {}
00050
00051 virtual void Render(GRRender* r, SGScene* s){}
00052 };
00053
00054
00055 class SGBehaviorEngines: public SGEngines{
00056 public:
00057 iterator initializer;
00058 iterator forceGenerator;
00059 iterator dynamicalSystem;
00060 iterator motion;
00061 iterator listener;
00062 public:
00063 SGBehaviorEngines();
00064
00065
00066
00067 virtual void ClearForce(SGScene* s);
00068
00069 virtual void GenerateForce(SGScene* s);
00070
00071 virtual void Integrate(SGScene* s);
00072
00073 void Add(SGEngine* e);
00074 bool Del(SGEngine* e);
00075 void Sort();
00076
00077 virtual void Loaded(SGScene* scene);
00078
00079 virtual void Clear(SGScene* s);
00080
00081
00082 virtual void LoadState(const SGBehaviorStates& states);
00083
00084 virtual void SaveState(SGBehaviorStates& states) const;
00085
00086 virtual void Render(GRRender* r, SGScene* s){
00087 for(iterator it = begin2(); it != end2(); ++it){
00088 ((SGBehaviorEngine*)&**it)->Render(r,s);
00089 }
00090 }
00091 };
00092
00093
00094 class SGBehaviorState: public UTRefCount{
00095 public:
00096 SGOBJECTDEF(SGBehaviorState);
00097 };
00098
00099 class SGBehaviorStates:public std::vector< UTRef<SGBehaviorState> >{
00100 public:
00101 typedef std::vector< UTRef<SGBehaviorState> > base;
00102 mutable unsigned cur;
00103 SGBehaviorStates():cur(0){}
00104 void clear(){ base::clear(); cur=0; }
00105 void SetCursorFirst() const { cur = 0; }
00106 const SGBehaviorState* GetNext() const { return cur<size() ? &*at(cur++) : NULL; }
00107 SGBehaviorState* GetNext(){ return cur<size() ? &*at(cur++) : NULL; }
00108 };
00109
00110 class SGBehaviorStateStack: public std::vector<SGBehaviorStates>{
00111 };
00112 }
00113 #endif