src/engine/EntityPool.h

Go to the documentation of this file.
00001 
00010 #ifndef ENTITYPOOL_H
00011 #define ENTITYPOOL_H
00012 #include <iostream>
00013 #include <boost/shared_ptr.hpp>
00014 #include "Interpreter.h"
00015 #include "InstancePool.h"
00016 #include "EntityTemplate.h"
00017 #include "EntityInstance.h"
00018 #include "EntityTemplateTable.h"
00019 #include "BehaviorTemplateTable.h"
00020 #include "backend/RenderSystem.h"
00021 #include "util/Timer.h"
00022 
00023 namespace green
00024 {
00025 
00026 
00031         class EntityPool : public InstancePool
00032         {
00033                 protected:
00034                         static void RunBehaviors(SystemPtr sys, BehaviorTemplateTablePtr behaviorTable,
00035                                                                                                         EntityInstancePtr entity,
00036                                                                                                                                 EntityInstancePtr originalTarget, 
00037                                                                                                                                 EntityInstancePtr newTarget)
00038                         {
00039                                 CHECK_SHARED(sys);
00040                                 CHECK_SHARED(behaviorTable);
00041                                 CHECK_SHARED(entity);
00042                                 CHECK_SHARED(originalTarget);
00043                                 CHECK_SHARED(newTarget);
00044                                 
00045                                 for(size_t i = 0; i < entity->GetNumBehaviors(); i++)
00046                                 {
00047                         //              std::cerr << "processing behavior " << i << std::endl;
00048                                         if(!Interpreter::RunBehavior(sys,behaviorTable,
00049                                                  entity->GetBehavior(i), originalTarget, newTarget))
00050                                                 break;
00051                                 }
00052                         }
00053                         
00054                 public:
00055                         void ProcessEntities(SystemPtr sys, BehaviorTemplateTablePtr behaviorTable)
00056                         {
00057                                 //int j(0);
00058                                 CHECK_SHARED(sys);
00059                                 CHECK_SHARED(behaviorTable);
00060                                 
00061                                 for(_idMap::iterator i = mIDMap.begin(); i != mIDMap.end(); i++)
00062                                 {
00063                                         EntityInstancePtr current(ENTITY_INSTANCE_CAST(i->second));
00064                                         CHECK_SHARED(current);
00065                                         EntityInstancePtr originalTarget(new EntityInstance(current));
00066                                         EntityInstancePtr newTarget(new EntityInstance(current));
00067                                         RunBehaviors(sys, behaviorTable, current, originalTarget, newTarget);
00068                                         current->CopyFrom(newTarget);
00069                                 }
00070                                 //exit(1);
00071                         }
00072 
00073                         void DrawEntities(RenderSystemPtr rSys)
00074                         {
00075                                 CHECK_SHARED(rSys);
00076                                 for(_idMap::iterator i = mIDMap.begin(); i != mIDMap.end(); i++)
00077                                 {
00078                                         EntityInstancePtr current(ENTITY_INSTANCE_CAST(i->second));
00079                                         CHECK_SHARED(current);
00080                                         float x = current->GetVariable(0).floatVal;
00081                                         float y = current->GetVariable(1).floatVal;
00082                                         float rot = current->GetVariable(4).floatVal;
00083                                         rSys->DrawObject(RenderSystem::SHIP, x, y, rot);
00084                                 }
00085                         }
00086                         
00087         };
00088         typedef boost::shared_ptr<EntityPool> EntityPoolPtr;
00089         #define ENTITY_POOL_CAST(x) boost::dynamic_pointer_cast<EntityPool>(x)
00090 }
00091                 
00092 #endif

Generated on Fri Apr 27 10:27:37 2007 for Green Engine by  doxygen 1.5.1