Scene.h

Engine/source/T3D/Scene.h

More...

Classes:

class

Scene This object is effectively a smart container to hold and manage any relevent scene objects and data used to run things.

Detailed Description

  1
  2#pragma once
  3
  4#include "console/engineAPI.h"
  5
  6#ifndef _NETOBJECT_H_
  7#include "sim/netObject.h"
  8#endif
  9
 10#ifndef _ITICKABLE_H_
 11#include "core/iTickable.h"
 12#endif
 13
 14#include "scene/sceneObject.h"
 15
 16/// Scene
 17/// This object is effectively a smart container to hold and manage any relevent scene objects and data
 18/// used to run things.
 19class Scene : public NetObject, public virtual ITickable
 20{
 21   typedef NetObject Parent;
 22
 23   bool mIsSubScene;
 24
 25   Scene* mParentScene;
 26
 27   Vector<Scene*> mSubScenes;
 28
 29   Vector<SceneObject*> mPermanentObjects;
 30
 31   Vector<SceneObject*> mDynamicObjects;
 32
 33   S32 mSceneId;
 34
 35   bool mIsEditing;
 36
 37   bool mIsDirty;
 38
 39   bool mEditPostFX;
 40
 41   StringTableEntry mGameModeName;
 42
 43protected:
 44   static Scene * smRootScene;
 45
 46   DECLARE_CONOBJECT(Scene);
 47
 48public:
 49   Scene();
 50   ~Scene();
 51
 52   static void initPersistFields();
 53
 54   static bool _editPostEffects(void* object, const char* index, const char* data);
 55
 56   virtual bool onAdd();
 57   virtual void onRemove();
 58   virtual void onPostAdd();
 59
 60   virtual void interpolateTick(F32 delta);
 61   virtual void processTick();
 62   virtual void advanceTime(F32 timeDelta);
 63
 64   virtual void addObject(SimObject* object);
 65   virtual void removeObject(SimObject* object);
 66
 67   void addDynamicObject(SceneObject* object);
 68   void removeDynamicObject(SceneObject* object);
 69
 70   void dumpUtilizedAssets();
 71
 72   StringTableEntry getOriginatingFile();
 73   StringTableEntry getLevelAsset();
 74
 75   bool saveScene(StringTableEntry fileName);
 76
 77   //
 78   //Networking
 79   U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream);
 80   void unpackUpdate(NetConnection *conn, BitStream *stream);
 81
 82   //
 83   Vector<SceneObject*> getObjectsByClass(String className, bool checkSubscenes);
 84
 85   void getUtilizedAssetsFromSceneObject(SimObject* object, Vector<StringTableEntry>* usedAssetsList);
 86
 87   template <class T>
 88   Vector<T*> getObjectsByClass(bool checkSubscenes);
 89
 90   static Scene *getRootScene() 
 91   { 
 92      if (Scene::smSceneList.empty())
 93         return nullptr;
 94
 95      return Scene::smSceneList[0];
 96   }
 97
 98   static Vector<Scene*> smSceneList;
 99};
100
101
102template <class T>
103Vector<T*> Scene::getObjectsByClass(bool checkSubscenes)
104{
105   Vector<T*> foundObjects;
106
107   T* curObject;
108
109   //first, check ourself
110   for (U32 i = 0; i < mPermanentObjects.size(); i++)
111   {
112      curObject = dynamic_cast<T*>(mPermanentObjects[i]);
113      if (curObject)
114         foundObjects.push_back(curObject);
115   }
116
117   for (U32 i = 0; i < mDynamicObjects.size(); i++)
118   {
119      curObject = dynamic_cast<T*>(mDynamicObjects[i]);
120      if (curObject)
121         foundObjects.push_back(curObject);
122   }
123
124   if (checkSubscenes)
125   {
126      for (U32 i = 0; i < mSubScenes.size(); i++)
127      {
128         Vector<T*> appendList = mSubScenes[i]->getObjectsByClass<T>(true);
129
130         for (U32 a = 0; a < appendList.size(); a++)
131         {
132            foundObjects.push_back(appendList[a]);
133         }
134      }
135   }
136
137   return foundObjects;
138}
139