World.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /******************************************************************************
  2. Use 'World' to automatically manage the game world and game objects.
  3. It handles:
  4. -paging
  5. -updating
  6. -rendering
  7. -saving
  8. -loading
  9. /******************************************************************************/
  10. namespace Game{
  11. /******************************************************************************/
  12. T1(TYPE) struct ObjMap // Container for Game Objects, this is the same thing as 'Map<UID, TYPE>', except without the control of manual adding new elements, which should be handled by 'WorldManager' (through 'WorldManager.objCreate')
  13. {
  14. ObjMap& clear(); // remove all objects
  15. Int elms ()C; // number of valid objects
  16. Int elmSize()C; // size of object (excluding the UID KEY)
  17. TYPE& operator[](Int i) ; // get i-th object
  18. C TYPE& operator[](Int i)C; // get i-th object
  19. Bool containsId (C UID &obj_id)C; // if container contains object with 'obj_id' ID
  20. Bool containsObj(C TYPE *obj )C; // if container contains 'obj' object
  21. TYPE* find(C UID &obj_id); // find object by its ID, null on fail
  22. ObjMap& remove ( Int i ); // remove i-th object from container
  23. ObjMap& removeId (C UID &obj_id); // remove object from container by its ID
  24. ObjMap& removeObj(C TYPE *data ); // remove object from container by its memory address
  25. // misc
  26. T1(BASE) operator ObjMap<BASE>&() ; // casting to container of 'BASE' objects, 'TYPE' must be extended from BASE
  27. T1(BASE) operator C ObjMap<BASE>&()C; // casting to container of 'BASE' objects, 'TYPE' must be extended from BASE
  28. explicit ObjMap(Int block_elms=32);
  29. private:
  30. Map<UID, TYPE> _map;
  31. #if EE_PRIVATE
  32. friend struct WorldManager; // allow full functionality only to 'WorldManager'
  33. #endif
  34. };
  35. /******************************************************************************/
  36. enum WORLD_MODE // World Mode
  37. {
  38. WORLD_STREAM, // streamed world (areas are loaded and unloaded depending on their distance to center of action inside 'WorldManager.update' method, those close to center of action are automatically loaded, those far away are unloaded, recommended for most games)
  39. WORLD_FULL , // full world (at start full world is loaded with all areas, may consume lots of memory, recommended for race games with fast travelling objects, where any loading pauses are unacceptable)
  40. WORLD_MANUAL, // manual world (areas are not managed automatically, they can be loaded and unloaded only by manual use of 'WorldManager.areaSetState' method)
  41. };
  42. /******************************************************************************/
  43. struct WorldSettings // World Settings
  44. {
  45. EnvironmentPtr environment; // default environment settings for this world, defualt=null
  46. Flt areaSize()C {return _area_size ;} WorldSettings& areaSize(Flt size); // get/set area size , 0..Inf, default=32
  47. Int hmRes ()C {return _hm_res ;} WorldSettings& hmRes (Int res ); // get/set heightmap resolution, 2..129, default=65, setting resolution will automatically align the value to the "(nearest power of 2)+1"
  48. Int path2DRes ()C {return _path2d_res;} WorldSettings& path2DRes (Int res ); // get/set 2d paths resolution, 1..64 , default=32
  49. // operations
  50. WorldSettings& reset(); // reset to default values
  51. #if EE_PRIVATE
  52. WorldSettings& shr();
  53. WorldSettings& shl();
  54. // get
  55. Str asText()C;
  56. Bool compatible(C WorldSettings &settings)C; // check if settings are compatible
  57. Bool operator==(C WorldSettings &settings)C;
  58. Bool operator!=(C WorldSettings &settings)C {return !(T==settings);}
  59. #endif
  60. // io
  61. Bool save(File &f, CChar *path=null)C; // save to file, 'path'=path at which resource is located (this is needed so that the sub-resources can be accessed with relative path), false on fail
  62. Bool load(File &f, CChar *path=null) ; // load from file, 'path'=path at which resource is located (this is needed so that the sub-resources can be accessed with relative path), false on fail
  63. Bool save(C Str &name)C; // save to file, false on fail
  64. Bool load(C Str &name) ; // load from file, false on fail
  65. WorldSettings() {reset();}
  66. private:
  67. Flt _area_size;
  68. Int _hm_res, _path2d_res;
  69. };
  70. /******************************************************************************/
  71. struct WorldManager // World Manager
  72. {
  73. static Bool update_objects_after_physics, // this specifies which should be updated first - objects or the physics, default=true (setting it to false may occur in lack of synchronization between the character mesh and its controller when using Physics.draw, false is required for synchronization of character physical clothing)
  74. use_background_loading , // if enabled then nearby areas will be loaded to memory on a secondary thread, which will allow smooth travelling across big worlds without pauses for loading data, default=true (for Mobile platforms the default value is set to "Cpu.threads()>=2")
  75. use_early_z_for_terrain , // if enable early-z rendering technique when drawing terrain, enabling early-z causes the terrain to be rendered additional time (to the depth buffer only), this has the cost of rendering the terrain additional time, however it can be beneficial if rendering will occlude other parts of the screen preventing from performing some pixel shader operations at later stage, whether this option should be enabled or disabled that depends on your world, and should be tested manually
  76. low_memory_usage ; // if release resources every time they're not needed, enabling this may decrease memory usage however it will decrease loading times when loading areas/changing worlds, default=false
  77. MiniMap mini_map; // this is automatically managed by the World Manager, use it to access the maps for certain areas, however do not store references to returned images, because they may get deleted in 'WorldManager.update'
  78. Cipher *area_cipher; // pointer to custom Cipher object (default=null) used for encrypting area files in case they are stored as stdio files (if they are stored in paks, then this cipher is ignored)
  79. void (*link_references)(); // pointer to custom function (may be null) called when new objects have been loaded, and there is possibility that they should be linked with custom global 'Reference's, you can set this to a custom function and inside it manually call 'Reference.link' for all global 'Reference's (do not use this for 'Reference's stored inside 'Game.Obj' classes, as they should be linked inside 'Game.Obj.linkReferences' method)
  80. void (*physics_update )(); // pointer to custom function (may be null) called when frame physics simulation has ended. 'WorldManager.update' method automatically handles physics simulation updates. If 'physics_update' is not null then it will be called after 'Physics.stopSimulation' and before 'Physics.startSimulation'. This function can be useful when physics is being processed in a background thread, and you need to precisely access/modify actor parameters when the simulation is not being processed. For example, if physics simulation is processed in background thread (that processing could occur during entire frame) and on the main thread you wish to adjust actor velocities, then the simulation may not behave the same every time and may not be precise, due to the fact of adjusting actor parameters when the simulation is already running at unknown stage in background thread. To overcome this issue and gain ability of precise adjusting of actor values you can set this callback, which will be called when the simulation is at the moment not running in the background thread.
  81. // init
  82. T1(TYPE) WorldManager& setAreaClass( ) { _grid.replaceClass<TYPE>( ); return T;} // set class responsible for areas , TYPE must be extended from 'Game.Area'
  83. T1(TYPE) WorldManager& setAreaData ( ) {return _setAreaData<TYPE>( ); } // set class responsible for area data, TYPE must be extended from 'Game.Area.Data'
  84. T1(TYPE) WorldManager& setObjType (ObjMap<TYPE> &obj_map, Int obj_type) {return _setObjType (obj_map, obj_type, CType<TYPE>()); } // set memory container responsible for selected OBJ_TYPE
  85. // manage
  86. WorldManager& del ( ); // manually delete current world
  87. Bool NewTry(C Str &world_name ); // initialize new world from 'world_name' name , false on fail
  88. Bool NewTry(C UID &world_id ); // initialize new world from 'world_id' name ID, false on fail
  89. WorldManager& New (C Str &world_name ); // initialize new world from 'world_name' name , Exit on fail
  90. WorldManager& New (C UID &world_id ); // initialize new world from 'world_id' name ID, Exit on fail
  91. Bool load ( File &f ); // load previously saved world state from 'f' file, false on fail
  92. Bool save ( File &f ); // save active world state to 'f' file, false on fail
  93. Bool load (C Str &save_name, Bool (*load)(File &f)=null, Cipher *cipher=null); // load previously saved world state from 'save_name' file, 'load'=pointer to fuction loading custom save data (it must return false on fail), false on fail
  94. Bool save (C Str &save_name, Bool (*save)(File &f)=null, Cipher *cipher=null); // save active world state to 'save_name' file, 'save'=pointer to fuction saving custom save data (it must return false on fail), false on fail
  95. static void Create(C Str &world_name, C WorldSettings &settings); // create folders for empty game world so it can be loaded using 'New' method, and save its settings
  96. // get / set
  97. Bool is ( )C {return _name.is() ;} // if there is any world specified
  98. C UID& id ( )C {return _id ;} // get name ID of current world
  99. C Str& name ( )C {return _name ;} // get name of current world
  100. C Str& dataPath ( )C {return _data_path ;} // get data path of current world
  101. C WorldSettings& settings ( )C {return _settings ;} // get settings of current world
  102. Flt areaSize ( )C {return _settings.areaSize();} // get size of a single Area of current world
  103. C PathWorld& path ( )C {return _path ;} // get path finder of current world
  104. WORLD_MODE mode ( )C {return _mode ;} // get manager mode, default=WORLD_STREAM
  105. WorldManager& mode (WORLD_MODE mode); // set manager mode, changing mode requires current world to be deleted first
  106. Flt activeRange ( )C {return _range ;} // get World Active Range, default=100
  107. WorldManager& activeRange (Flt range); // set World Active Range
  108. Flt objUpdateTime( )C {return _time_obj_update ;} // get amount of CPU time which was needed to update all objects during last world update
  109. Vec2 areaToWorld(C VecI2 &xz )C {return xz*areaSize() ;} // convert Area Coordinates to World Position in meters
  110. VecI2 worldToArea(C Vec2 &xz )C {return Floor(xz/areaSize());} // convert World Position to Area Coordinates
  111. VecI2 worldToArea(C VecD2 &xz )C {return Floor(xz/areaSize());} // convert World Position to Area Coordinates
  112. VecI2 worldToArea(C Vec &pos )C {return worldToArea(pos .xz());} // convert World Position to Area Coordinates
  113. VecI2 worldToArea(C VecD &pos )C {return worldToArea(pos .xz());} // convert World Position to Area Coordinates
  114. RectI worldToArea(C Rect &rect)C {return RectI(worldToArea(rect.min), worldToArea(rect.max));} // convert World Position to Area Coordinates
  115. RectI worldToArea(C Box &box )C {return RectI(worldToArea(box .min), worldToArea(box .max));} // convert World Position to Area Coordinates
  116. void setShader();
  117. #if EE_PRIVATE
  118. ObjMap<Obj>* objMap ( Int type) {return InRange(type, _obj_container) ? _obj_container[type].map : null;} // get object container responsible for 'type' object types
  119. Int objType ( Obj &obj ); // get OBJ_TYPE of 'obj', this method is safer than 'Obj.type()' because it verifies the typeid, if it doesn't match, then all containers are searched
  120. AREA_STATE rangeState(C VecI2 &xzi ); // get desired area state of given area coordinates
  121. // set
  122. void setRanges();
  123. // background
  124. void threadFunc();
  125. // load
  126. Bool loadObj(Area &area, Bool active, Area::Data::AreaObj &area_obj, Bool _const);
  127. Bool loadObj(Area &area, Bool active, Int obj_type, File &f );
  128. #endif
  129. // area
  130. struct AreaState
  131. {
  132. VecI2 xz ; // xz coordinates of Area
  133. AREA_STATE state; // desired state of Area
  134. void set(C VecI2 &xz, AREA_STATE state) {T.xz=xz; T.state=state;}
  135. AreaState(C VecI2 &xz=VecI2(0, 0), AREA_STATE state=AREA_UNLOADED) {set(xz, state);}
  136. };
  137. void areaSetState (C MemPtr<AreaState> &area_states, Bool unload_remaining=false); // manually set the state of areas, this method can be used for WORLD_MANUAL (for other modes it is ignored), 'area_states'=list of area coordinates and their desired states, 'unload_remaining'=if automatically unload all areas that aren't included in the 'area_states' list
  138. Int areaActiveNum( )C; // get number of active areas
  139. Area* areaActive ( Int i )C; // get i-th active area , if the index is out of range then null is returned
  140. Area* areaActive (C VecI2 &xz)C; // get active area at 'xz' area coordinates, if the area doesn't exist or isn't active at that coordinates then null is returned (which means that only area with AREA_ACTIVE state can be returned)
  141. Area* areaLoaded (C VecI2 &xz)C; // get loaded area at 'xz' area coordinates, if the area doesn't exist or isn't loaded at that coordinates then null is returned (which means that only area with AREA_CACHE AREA_INACTIVE AREA_ACTIVE state can be returned)
  142. #if EE_PRIVATE
  143. void areaUnload (Area &area);
  144. void areaUnloadToCache(Area &area);
  145. void areaCache (Area &area, Bool inc_progress, File &file_area);
  146. void areaLoad (Area &area, Bool active , File &file_area);
  147. void areaActivate (Area &area);
  148. void areaDeactivate (Area &area);
  149. void areaUpdateState (Area &area, AREA_STATE state , File &file_area);
  150. void areaUpdateState (Area &area, File &file_area);
  151. void areaUpdateState ();
  152. void areaSetLoadedRect();
  153. void areaSetVisibility(Memc<Area*> &area_draw, Bool sort);
  154. Bool areaInsertObject (Area &area, Obj &obj, AREA_STATE obj_state);
  155. #endif
  156. // heightmap
  157. Flt hmHeight (C Vec2 &xz, Bool smooth=true); // get world heightmap height at 'xz' world 2D position, 0 on fail, this method is fast because it uses lookup table (Game.Area.Data.height Image), see also 'Game.Area.hmHeight', 'smooth'=if calculate smooth value using linear interpolation
  158. C MaterialPtr& hmMaterial(C Vec2 &xz ); // get world heightmap material at 'xz' world 2D position, null on fail, this method is fast because it uses lookup table (Game.Area.Data.materialMap Image), see also 'Game.Area.hmMaterial'
  159. // water
  160. C WaterMtrlPtr& waterUnder(C Vec &pos, Flt *depth=null); // test if 'pos' world position is under water, 'depth'=optional parameter which can receive point under water depth if it is under water, if 'pos' is underwater then the method will return water material in which the position is located, if not underwater then null is returned
  161. Waypoint* findWaypoint(C Str &name) {return name.is () ? Waypoints.get(dataPath()+"Waypoint/"+name ) : null;} // find waypoint in this world, null on fail
  162. Waypoint* findWaypoint(C UID &id ) {return id .valid() ? Waypoints.get(dataPath()+"Waypoint/"+EncodeFileName(id)) : null;} // find waypoint in this world, null on fail
  163. Waypoint* getWaypoint(C Str &name) {return name.is () ? Waypoints (dataPath()+"Waypoint/"+name ) : null;} // get waypoint in this world, Exit on fail
  164. Waypoint* getWaypoint(C UID &id ) {return id .valid() ? Waypoints (dataPath()+"Waypoint/"+EncodeFileName(id)) : null;} // get waypoint in this world, Exit on fail
  165. // objects
  166. Obj* objCreateNear( Object &object , C Matrix &matrix, C UID *obj_id=null); // dynamically create object into world from 'object' object and desired matrix, 'matrix' scale will be used as objects scale, method fails if 'matrix' is out of active range , 'obj_id'=optional parameter specifying forcing custom object id for the object (the parameter can be useful if you've created an object on the server, and need to create it on client using the same id from the server, if the parameter is not specified then object id will be randomized), null on fail
  167. Bool objCreate ( Object &object , C Matrix &matrix, C UID *obj_id=null); // dynamically create object into world from 'object' object and desired matrix, 'matrix' scale will be used as objects scale, method succeeds if 'matrix' is out of active range but pointer to object isn't returned, 'obj_id'=optional parameter specifying forcing custom object id for the object (the parameter can be useful if you've created an object on the server, and need to create it on client using the same id from the server, if the parameter is not specified then object id will be randomized), false on fail
  168. Bool objInject (Int obj_type, File &obj_save_data, C Vec *pos ); // dynamically inject object into world from previously saved object data (using 'Game.Obj.save'), 'obj_type'=OBJ_TYPE, 'pos'=optional parameter to specify new position after loading the object (if null is passed then position will not be modified), false on fail
  169. Obj* moveWorldObjToStorage (Obj & world_obj, Memx<Obj> & storage ); // move 'world_obj' world object into a custom 'storage' object container, this function will be performed only if 'world_obj' belongs to this world and 'storage' is a container storing exactly the same type as the 'world_obj', if those conditions are met then the object will have its 'willBeMovedFromWorldToStorage' method called, then it will be removed from world and placed in the storage , then it will have its 'memoryAddressChanged' method called followed by 'wasMovedFromWorldToStorage' and address of the object (now inside the storage container) will be returned, if this method fails then null is returned and no operation is performed
  170. Bool moveStorageObjToWorld (Obj &storage_obj, Memx<Obj> & storage, C Matrix *obj_matrix=null); // move 'storage_obj' storage object into world , this function will be performed only if 'storage_obj' belongs to 'storage' and world is capable (see 'setObjType') of storing exactly the same type as the 'storage_obj', if those conditions are met then the object will have its 'willBeMovedFromStorageToWorld' method called, then it will be removed from storage and placed in the world , then it will have its 'memoryAddressChanged' method called followed by 'wasMovedFromStorageToWorld' and true will be returned, if this method fails then false is returned and no operation is performed, 'obj_matrix'=optional parameter specifying new object matrix applied to the object when being moved to world (it's not applied if it's null or this method returned false)
  171. static Obj* MoveStorageObjToStorage(Obj &storage_obj, Memx<Obj> &src_storage, Memx<Obj> &dest_storage ); // move 'storage_obj' storage object from 'src_storage' into 'dest_storage' , this function will be performed only if 'storage_obj' belongs to 'src_storage' and 'storage' is a container storing exactly the same type as the 'storage_obj', if those conditions are met then the object will be removed from 'src_storage' and placed in 'dest_storage', then it will have its 'memoryAddressChanged' method called and address of the object (now inside the new storage container) will be returned, if this method fails then null is returned and no operation is performed
  172. WorldManager& objGetAdd(MemPtr<Obj*> objects, C Ball &ball , Int obj_type=-1); // get pointers to objects which position (Game.Obj.pos) is inside 'ball' , process only objects with 'obj_type' OBJ_TYPE (-1=process all types), this function does not clear 'objects' container at start which means that objects are added to the container
  173. WorldManager& objGetAdd(MemPtr<Obj*> objects, C Capsule &capsule, Int obj_type=-1); // get pointers to objects which position (Game.Obj.pos) is inside 'capsule', process only objects with 'obj_type' OBJ_TYPE (-1=process all types), this function does not clear 'objects' container at start which means that objects are added to the container
  174. WorldManager& objGetAdd(MemPtr<Obj*> objects, C Box &box , Int obj_type=-1); // get pointers to objects which position (Game.Obj.pos) is inside 'box' , process only objects with 'obj_type' OBJ_TYPE (-1=process all types), this function does not clear 'objects' container at start which means that objects are added to the container
  175. WorldManager& objGetAdd(MemPtr<Obj*> objects, C OBox &obox , Int obj_type=-1); // get pointers to objects which position (Game.Obj.pos) is inside 'obox' , process only objects with 'obj_type' OBJ_TYPE (-1=process all types), this function does not clear 'objects' container at start which means that objects are added to the container
  176. WorldManager& objGet (MemPtr<Obj*> objects, C Ball &ball , Int obj_type=-1) {objects.clear(); return objGetAdd(objects, ball , obj_type);} // get pointers to objects which position (Game.Obj.pos) is inside 'ball' , process only objects with 'obj_type' OBJ_TYPE (-1=process all types)
  177. WorldManager& objGet (MemPtr<Obj*> objects, C Capsule &capsule, Int obj_type=-1) {objects.clear(); return objGetAdd(objects, capsule, obj_type);} // get pointers to objects which position (Game.Obj.pos) is inside 'capsule', process only objects with 'obj_type' OBJ_TYPE (-1=process all types)
  178. WorldManager& objGet (MemPtr<Obj*> objects, C Box &box , Int obj_type=-1) {objects.clear(); return objGetAdd(objects, box , obj_type);} // get pointers to objects which position (Game.Obj.pos) is inside 'box' , process only objects with 'obj_type' OBJ_TYPE (-1=process all types)
  179. WorldManager& objGet (MemPtr<Obj*> objects, C OBox &obox , Int obj_type=-1) {objects.clear(); return objGetAdd(objects, obox , obj_type);} // get pointers to objects which position (Game.Obj.pos) is inside 'obox' , process only objects with 'obj_type' OBJ_TYPE (-1=process all types)
  180. Obj* findObjById(C UID &obj_id, Int obj_type=-1); // find world object by its Unique ID (this is the ID of the world object itself, and not its base object or class), 'obj_type'=OBJ_TYPE of the object (or if you don't know it, then use -1), null on fail (if not found)
  181. // terrain
  182. WorldManager& terrainAddDecal (C Color &color, C MaterialPtr &material, C Matrix & decal_matrix, Flt time_to_fade_out=10); // add a Decal to current World's terrain
  183. WorldManager& terrainAddOverlay( C MaterialPtr &material, C Matrix &overlay_matrix, Flt time_to_fade_out=10); // add a MeshOverlay to current World's terrain
  184. // path
  185. AreaPath2D* path2DGet (C VecI2 &xz ); // get pointer to Area paths at given Area coordinates, returns null when path's don't exist at specified coordinates
  186. Bool path2DWalkable(C Vec &pos); // check if path is walkable at specified world position
  187. void path2DBuild ( ); // call this once after making changes to AreaPath2D's to rebuild the path database
  188. #if EE_PRIVATE
  189. Int pathGetNode (C Vec &pos , VecI2 &path_xy);
  190. Bool pathFindFast (Int node_from, Int node_to, Memc<UInt> &path);
  191. Bool pathFind (Int node_from, Int node_to, Memc<UInt> &path);
  192. void pathDraw (Int node , C Color &color=YELLOW);
  193. void pathDrawNghb (Int node , C Color &color=ORANGE);
  194. void pathDrawBlock( C Color &color=RED );
  195. void pathDrawArea (Area &area , Byte index, C Color &color);
  196. #endif
  197. // update
  198. #if EE_PRIVATE
  199. void updateObjectAreas();
  200. void updateObjects ();
  201. #endif
  202. Bool updated ( ) {return _updated ;} // if current world has been updated at least once since it was loaded, you can use this method to startup loading screen
  203. Flt updateProgress( ) {return _update_progress;} // get update progress (0..1), this can be called in a secondary thread to access the progress of updating the world using 'update' method
  204. void updateBreak ( ); // break updating, this can be called from a secondary thread to break any current world updating, for example if during loading a world the user requests quitting the game, you can break the loading and exit immediately
  205. void update (C Vec2 &xz ); // update, 'xz' =x and z coordinates of center of action (in meters), the parameter is used only for WORLD_STREAM mode (for other modes it is ignored)
  206. void update (C Vec &pos) {update(pos.xz());} // update, 'pos'= center of action (in meters), the parameter is used only for WORLD_STREAM mode (for other modes it is ignored)
  207. // World update automatically loads all needed areas located nearby the center of action (and unloads those which are too far away).
  208. // Additionally it calls the following methods:
  209. // D.grassUpdate()
  210. // Physics.startSimulation().stopSimulation()
  211. // Game.Obj.update() on all active game objects (which are located in AREA_ACTIVE areas)
  212. // draw
  213. void draw(); // call this inside Render function for every RENDER_MODE
  214. #if EE_PRIVATE
  215. void drawDrawnAreas(C Color &color=WHITE, C Color &color_shd=YELLOW);
  216. #endif
  217. ~WorldManager();
  218. WorldManager();
  219. #if !EE_PRIVATE
  220. private:
  221. #endif
  222. struct ObjContainer
  223. {
  224. CPtr type;
  225. ObjMap<Obj> *map ;
  226. #if EE_PRIVATE
  227. void set(ObjMap<Obj> &map, CPtr type) {T.map=&map; T.type=type;}
  228. #endif
  229. };
  230. UID _id;
  231. Str _name,
  232. _data_path;
  233. WORLD_MODE _mode;
  234. Bool _updated, _update_break;
  235. Byte _update_count;
  236. Flt _update_progress;
  237. Int _areas_to_load;
  238. Int _rangei, _rangei2, _rangei2_inactive, _rangei2_cache;
  239. Flt _range;
  240. Vec2 _xz;
  241. VecI2 _xzi;
  242. Memc<ObjContainer> _obj_container;
  243. Memc<Obj *> _obj_newly_added;
  244. RectI _area_active_rect, _area_loaded_rect;
  245. Memc<Area *> _area_active , _area_draw, _area_draw_shadow, _area_draw_secondary,
  246. _area_inactive ,
  247. _area_cache ,
  248. _area_background;
  249. Area::Data& (*_area_data)(Area::Data* &data, Area &area);
  250. Grid<Area> _grid;
  251. PathWorld _path;
  252. WorldSettings _settings;
  253. UInt _path_iteration;
  254. PathFind _path_find;
  255. #if EE_PRIVATE
  256. Memc<PathNode > _path_node;
  257. Memc<PathNodeNeighbor> _path_neighbor;
  258. #else
  259. _Memc _path_node, _path_neighbor;
  260. #endif
  261. SyncLock _lock;
  262. Thread _thread;
  263. SyncEvent _thread_event;
  264. struct Decal2 : Decal {Flt time;}; Memc<Decal2 > _decals ;
  265. struct MeshOverlay2 : MeshOverlay {Flt time;}; Memc<MeshOverlay2> _mesh_overlays;
  266. Flt _time_area_update_state,
  267. _time_area_update_state_now ,
  268. _time_area_update_state_back,
  269. _time_area_update_state_path,
  270. _time_area_update_state_unload_cache,
  271. _time_area_update_state_unload,
  272. _time_area_update_state_load,
  273. _time_area_update_state_load_data,
  274. _time_area_update_state_activate,
  275. _time_area_update_state_deactivate,
  276. _time_obj_update;
  277. #if EE_PRIVATE
  278. private:
  279. #endif
  280. T1(TYPE) static Area::Data& NewAreaData(Area::Data* &data, Area &area) {data=new TYPE(area); return *data;}
  281. T1(TYPE) WorldManager& _setAreaData() {ASSERT_BASE_EXTENDED<Area::Data, TYPE>(); _area_data=NewAreaData<TYPE>; return T;}
  282. WorldManager& _setObjType (ObjMap<Obj> &obj_map, Int obj_type, CPtr c_type);
  283. #if EE_PRIVATE
  284. void linkReferences();
  285. #endif
  286. T1(TYPE) friend struct EE::Reference;
  287. NO_COPY_CONSTRUCTOR(WorldManager);
  288. }extern
  289. World; // Main World
  290. /******************************************************************************/
  291. } // namespace
  292. /******************************************************************************/