00001 #ifndef _OPERATIONS_H
00002 #define _OPERATIONS_H
00003
00004 #include <vector>
00005 #include <gmtl/Vec.h>
00006 #include <gmtl/VecOps.h>
00007
00008 namespace ani
00009 {
00011 template<class __EntityType>
00012 class GrimReaperOperator : public ani::Operator<__EntityType>
00013 {
00014 public:
00015 typedef boost::shared_ptr<__EntityType> EntityTypePtr;
00016
00017 public:
00018 GrimReaperOperator() : ani::Operator<__EntityType>() {}
00019 virtual ~GrimReaperOperator() {}
00020 virtual void exec( DynamicSystem<__EntityType>& ps, float timeDelta );
00021 };
00022
00023 template <class __EntityType>
00024 void GrimReaperOperator<__EntityType>::exec( DynamicSystem<__EntityType>& ps, float timeDelta )
00025 {
00026 std::vector<EntityTypePtr>& psList = ps.entities();
00027 std::vector<EntityTypePtr>::iterator it;
00028 std::list< std::vector<EntityTypePtr>::iterator > deadList;
00029 for (it = psList.begin(); it != psList.end(); ++it)
00030 {
00031
00032 EntityTypePtr p = *it;
00033 p->growOlder( ps.timeDelta() );
00034
00035
00036 if (p->age() >= p->ageOfDeath() && p->ageOfDeath() >= 0.0f)
00037 {
00038 deadList.push_back( it );
00039 }
00040 }
00041
00042
00043 std::list< std::vector<EntityTypePtr>::iterator >::reverse_iterator deadListIt;
00044 for (deadListIt = deadList.rbegin(); deadListIt != deadList.rend(); ++deadListIt)
00045 {
00046
00047
00048 EntityTypePtr p = *(*deadListIt);
00049 p->isInSystem( false );
00050 ps.entities().erase( (*deadListIt) );
00051 }
00052 }
00053 }
00054
00055 #endif