Go to the documentation of this file.00001 #ifndef __NYTRO_Entity_H
00002 #define __NYTRO_Entity_H
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "system/nyCommon.h"
00012 #include "system/nyBase.h"
00013 #include "system/nyParameterList.h"
00014 #include "scene/nySceneNode.h"
00015 #include "physics/nyPhysicsProvider.h"
00016 #include "gui/nyUi.h"
00017
00018 namespace Nytro
00019 {
00020 namespace Game
00021 {
00022 using namespace Core;
00023 using namespace Math;
00024
00025 class Entity;
00026 class FlowGraphEventNode;
00027
00028 #define kEntityCategory_General "General"
00029 #define kEntityCategory_Environment "Environment"
00030 #define kEntityCategory_Ai "Artificial Intelligence"
00031 #define kEntityCategory_Cinematic "Cinematic"
00032 #define kEntityCategory_Effects "Effects"
00033 #define kEntityCategory_Audio "Audio"
00034
00036 class NYTRO_API EntityGroup
00037 {
00038 public:
00039
00040 EntityGroup()
00041 {
00042 m_bOpened = false;
00043 }
00044
00046 string m_name;
00048 bool m_bOpened;
00049 };
00050
00052 class NYTRO_API EntityLayer
00053 {
00054 public:
00055
00056 EntityLayer()
00057 {
00058 m_bVisible = true;
00059 m_bLocked = false;
00060 }
00061
00062 string m_name, m_description;
00063 bool m_bVisible;
00064 bool m_bLocked;
00065 };
00066
00068 class NYTRO_API PrefabEntityData
00069 {
00070 public:
00071
00072 void copyPropertiesAndAttributesTo( Base* pObj );
00073
00075 string m_className;
00077 map<string,string> m_properties,
00079 m_attributes;
00080 };
00081
00083 class NYTRO_API PrefabData : public Resource
00084 {
00085 public:
00086
00087 NYTRO_CLASS_NAME( PrefabData );
00088
00089 PrefabData();
00090 ~PrefabData();
00091
00093 EResult load( const char* pFilename = NULL );
00095 EResult save( const char* pFilename = NULL );
00097 EResult unload();
00099 vector<PrefabEntityData>& getPrefabEntities();
00100
00101 protected:
00102
00103 vector<PrefabEntityData> m_prefabEntities;
00104 };
00105
00107 class NYTRO_API EntityEvent: public Base
00108 {
00109 public:
00110
00111 EntityEvent( const char* pName = "", Variant* pParams = NULL, uint32 aParamCount = 0 );
00112
00113 virtual void trigger( Base* pInitiator, ParameterList* pParams = NULL );
00114 virtual void resetTrigger();
00115
00118 char* m_pEventName;
00120 uint32 m_maxTriggerCount,
00122 m_currentTriggerCount;
00124 Base* m_pInitiator;
00126 Entity* m_pOwner;
00128 ParameterList m_params;
00130 FlowGraph* m_pFlowGraph;
00132 FlowGraphEventNode* m_pGraphEventNode;
00134 bool m_bTriggerOnClientSide, m_bTriggered;
00135 };
00136
00139 class NYTRO_API EntityVisualEditHandle : public SceneNode
00140 {
00141 public:
00142
00143 EntityVisualEditHandle()
00144 {
00145 m_bHandleMouseHovered = m_bHandleSelected = false;
00146 }
00147
00148 bool m_bHandleMouseHovered, m_bHandleSelected;
00149 };
00150
00152 class NYTRO_API Entity : public SceneNode, public ResourceObserver
00153 {
00154 public:
00155
00156 enum EEntityFlags
00157 {
00159 eEntityFlag_Selectable = NYTRO_BIT(0),
00161 eEntityFlag_Selected = NYTRO_BIT(1),
00162 eEntityFlag_CastShadows = NYTRO_BIT(2),
00163 eEntityFlag_ReceiveShadows = NYTRO_BIT(3),
00164 eEntityFlag_CanBeReflected = NYTRO_BIT(4),
00165 eEntityFlag_StaticEntity = NYTRO_BIT(5),
00166 eEntityFlag_CanBeHiddenByOcclusion = NYTRO_BIT(6)
00167 };
00168
00169 Entity();
00170 virtual ~Entity();
00171
00173 EntityGroup* getGroup();
00175 string getPrefabFileName();
00177 PrefabData* getPrefab();
00179 uint32 getEntityFlags();
00181 void setEntityFlags( uint32 aFlags );
00183 virtual void setGroup( EntityGroup* pGroup );
00185 virtual void setPrefabFileName( const char* pFileName );
00187 virtual void setPrefab( PrefabData* pPrefab );
00189 virtual bool traceRay( Ray& rRay, SceneNodeHitInfo* pHit, ETraceRayAccuracy aAccuracy = eTraceRayAccuracy_Brute );
00191 virtual void schematicRender();
00193 virtual void triggerEvent( EntityEvent* pEvent, Base* pInitiator, ParameterList* pParams = NULL );
00195 void triggerEvent( const char* pEvent, Base* pInitiator, ParameterList* pParams = NULL );
00197 map<char*,EntityEvent*>& getEvents();
00200 void addEvent( EntityEvent* pEvent );
00202 void resetEvents();
00204 EntityLayer* getLayer();
00206 void setLayer( EntityLayer* pLayer );
00208 virtual EResult loadFromStream( Stream* pStream );
00210 virtual EResult saveToStream( Stream* pStream );
00211
00212
00213
00214
00215
00217 virtual void onEvent( EntityEvent* pEvent );
00220 virtual bool onEditorDelete();
00222 virtual void onEditorUndoDelete();
00224 virtual void onStartSimulation();
00226 virtual void onStopSimulation();
00228 virtual void onBeforeUnloadResource( Resource* pRes );
00230 virtual void onAfterReloadResource( Resource* pRes );
00231 virtual void onPropertyValueChanged( voidptr pPropertyData );
00232 virtual void onFormatGetPropertyValue( voidptr pPropertyData, string& rOutValue );
00233 virtual void prepare();
00234
00235
00236
00237
00238
00243 vector<EntityVisualEditHandle*>& getVisualEditHandles();
00245 virtual void onVisualEditHandleMove( EntityVisualEditHandle* pHandle );
00247 virtual bool onVisualEditHandleDelete( EntityVisualEditHandle* pHandle );
00248 static void setShowConstantSizedEntityIcons( bool bShow );
00249 static UiFxTimer& getSelectionBlinkTimer();
00250
00251 NYTRO_CLASS_HAS_PROPERTIES;
00252
00253 protected:
00254
00255 static bool s_bShowConstantSizedEntityIcons;
00256 static UiFxTimer s_selectionBlinkTimer;
00257
00258 void drawEntityIcon();
00259
00260 Vector3D m_initialTranslation, m_initialScale, m_iconOffsetFromAabbCenter;
00261 Quaternion m_initialRotation;
00262 EntityGroup* m_pGroup;
00263 string m_prefabFileName;
00264 int32 m_layerIndex, m_groupIndex;
00265 PrefabData* m_pPrefab;
00266 Vector3D m_entityIconCorners[4];
00267 Texture* m_pEntityIconTexture;
00268 EntityLayer* m_pLayer;
00269 uint32 m_entityFlags;
00271 uint8 m_performanceCost;
00272 map<char*,EntityEvent*> m_events;
00273 vector<EntityVisualEditHandle*> m_visualEditHandles;
00274 };
00275
00276 class NYTRO_API PrefabEntity : public Entity
00277 {
00278 public:
00279
00280 NYTRO_CLASS_NAME( PrefabEntity );
00281
00282 PrefabEntity();
00283 virtual ~PrefabEntity();
00284
00285 virtual EResult preCache();
00286 virtual void free();
00287 void disassemble();
00288
00289 protected:
00290
00291 };
00292
00293 #define NYTRO_ADD_ENTITY_EVENT( eventName, ... ) \
00294 Variant __##eventName##Params[] = { __VA_ARGS__ }; \
00295 addEvent( new EntityEvent( ""#eventName, __##eventName##Params, sizeof(__##eventName##Params)/sizeof(Variant) ) );
00296 };
00297 };
00298
00299 #endif