src/engine/EntityInstance.h

Go to the documentation of this file.
00001 
00011 #ifndef ENTITYINSTANCE_H
00012 #define ENTITYINSTANCE_H
00013 
00014 #include <boost/shared_ptr.hpp>
00015 #include <vector>
00016 #include <iostream>
00017 #include "System.h"
00018 //#include "VariableTableInstance.h"
00019 #include "EntityTemplate.h"
00020 #include "BehaviorInstance.h"
00021 //#include "BehaviorTemplate.h"
00022 #include "BehaviorTemplateTable.h"
00023 
00024 namespace green
00025 {
00026                 
00027         class EntityInstance : 
00028                 public VariableTableInstance
00029         {
00030                 protected:
00031                         std::vector<BehaviorInstancePtr> mBehaviors;
00032                         
00033                 public:
00034                         EntityInstance(boost::shared_ptr<EntityInstance> copy) :
00035                                 VariableTableInstance(VARIABLE_TABLE_INSTANCE_CAST(copy)),
00036                                 mBehaviors(copy->mBehaviors)
00037                         {
00038                         }
00039                         
00043                         virtual void CopyFrom(boost::shared_ptr<EntityInstance> copy)
00044                         {
00045                                 CHECK_SHARED(copy);
00046                                 VariableTableInstance::CopyFrom(VARIABLE_TABLE_INSTANCE_CAST(copy));
00047                                 mBehaviors = copy->mBehaviors;
00048                         }
00049                                                 
00050                         EntityInstance(Key templ, EntityTemplatePtr templPtr,
00051                                                                                  BehaviorTemplateTablePtr behaviors) :
00052                                 VariableTableInstance(templ)    
00053                         {
00054                                 CHECK_SHARED(templPtr);
00055                                 CHECK_SHARED(behaviors);
00056                                 
00057                                 for(size_t i = 0; i < templPtr->GetNumBehaviors(); i++)
00058                                 {
00059                                         // Instantiate the entity's ith behavior
00060                                         BehaviorInstancePtr newBehavior( 
00061                                                         behaviors->InstantiateBehavior(templPtr->GetBehavior(i),
00062                                                                                                                                                                                 templPtr->GetBehaviorArgs(i)));
00063                                         
00064                                         CHECK_SHARED(newBehavior);
00065                                         
00066                                         // Add the behavior instance to the entity instance's list
00067                                         mBehaviors.push_back(newBehavior);
00068                                 }
00069                         }
00070                         
00071                         size_t GetNumBehaviors() const {
00072                                 return mBehaviors.size();
00073                         }
00074                         
00075                         BehaviorInstancePtr GetBehavior(size_t behavior) {
00076                                 ERROR_ASSERT(behavior < mBehaviors.size(), "behavior too large");
00077                                 return mBehaviors[behavior];
00078                         }
00079 
00080         };
00081         typedef boost::shared_ptr<EntityInstance> EntityInstancePtr;
00082         #define ENTITY_INSTANCE_CAST(x) boost::dynamic_pointer_cast<EntityInstance, VariableTableInstance>(x)
00083 }
00084 
00085 #endif

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