@Area.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /******************************************************************************/
  2. /******************************************************************************/
  3. class Area : BlendObject
  4. {
  5. bool loaded, changed, invalid_refs;
  6. Heightmap2 *hm;
  7. MeshGroup obj_mesh; // this should not be drawn, because objects are drawn from 'objs' container, 'obj_mesh' is just a copy in the memory for load/save
  8. PhysBody obj_phys;
  9. Memc<WaterMesh> waters; // this should not be drawn, because waters are drawn from 'lakes' 'rivers' containers, 'water' is just a copy in the memory for load/save
  10. PathMesh path;
  11. VecI2 xy;
  12. Area *_l, *_r, *_b, *_f, *_lb, *_lf, *_rb, *_rf; // neighbors
  13. Memc<Obj*> objs;
  14. WorldData *world;
  15. AreaVer *ver;
  16. flt validate_refs_time;
  17. ~Area();
  18. Area(C VecI2 &xy, ptr grid_user);
  19. Heightmap2* hm_l (); // get left neighbor heightmap
  20. Heightmap2* hm_r (); // get right neighbor heightmap
  21. Heightmap2* hm_b (); // get back neighbor heightmap
  22. Heightmap2* hm_f (); // get front neighbor heightmap
  23. Heightmap2* hm_lb(); // get left back neighbor heightmap
  24. Heightmap2* hm_lf(); // get left front neighbor heightmap
  25. Heightmap2* hm_rb(); // get right back neighbor heightmap
  26. Heightmap2* hm_rf(); // get right front neighbor heightmap
  27. bool hasSelectedObj()C;
  28. Obj* findobj(C UID &obj_id);
  29. Vec2 pos2D()C;
  30. flt hmHeight(C Vec &pos, bool smooth=true)C;
  31. flt hmHeight(C Vec2 &xz , bool smooth=true)C;
  32. Vec hmNormal(C Vec &pos)C;
  33. Vec hmNormal(C Vec2 &xz )C;
  34. Vec hmNormalAvg(C Vec &pos, flt r)C;
  35. Vec hmNormalAvg(C Vec2 &xz , flt r)C;
  36. Vec hmNormalAvg(C Matrix &matrix, C Box &box)C;
  37. Vec hmNormalNeighbor(int x, int y);
  38. bool hmColor(C Vec2 &xz, Vec &color)C;
  39. MaterialPtr hmMtrl(C Vec2 &xz, C MaterialPtr &cur_mtrl=null)C;
  40. // operations
  41. // !! these functions must be multi-threaded SAFE !!
  42. AreaVer* getVer( ); // ThreadSafeMap.get is multi-thread safe
  43. C AreaVer* getVer( )C;
  44. void setTerrainUndo ( );
  45. void setServer ( );
  46. void setChanged ( );
  47. void setChangedHmRemoved(C TimeStamp *time=null); // having 'time' means that this was called by the server, in that case don't call the undo
  48. void setChangedHeight (bool skip_mesh=true );
  49. void setChangedMtrl ( );
  50. void setChangedColor ( );
  51. void setChangedObj ( );
  52. void setChangedObj (Obj &obj ); // send only that object to the server (and not whole area)
  53. void setShader();
  54. //void hmReset() {if(hm)hm.mesh.del();} // force rebuilding of the heightmap mesh during update process
  55. bool hmDel(C TimeStamp *time=null);
  56. bool hmCreate(bool align_height_to_neighbors);
  57. void hmBuild();
  58. bool invalidRefs()C;
  59. void validateRefs();
  60. void delayedValidateRefs(); // update after 2 seconds
  61. void updateValidateRefs();
  62. void undo(C WorldChange::Terrain &undo, bool skip_mesh=false);
  63. // draw
  64. void draw();
  65. void drawShadow();
  66. virtual void drawBlend()override;
  67. void draw2D();
  68. // io
  69. bool saveEdit(C Str &name);
  70. void loadEdit(C Str &name);
  71. bool saveGame(C Str &name);
  72. void loadGame(C Str &name);
  73. void load();
  74. static void Flush(Cell<Area> &cell, ptr);
  75. void flush();
  76. void unload();
  77. public:
  78. Area();
  79. };
  80. /******************************************************************************/
  81. /******************************************************************************/
  82. /******************************************************************************/