Net World.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /******************************************************************************/
  2. namespace Net{
  3. /******************************************************************************/
  4. struct Area // Net Area
  5. {
  6. // get
  7. C VecI2& xy()C {return _xy;} // get area coordinates
  8. Int objs( ) {return _objs.elms();} // get number of objects in the area
  9. Obj& obj (Int i) {return *_objs[i] ;} // get i-th object in the area
  10. virtual ~Area( ) {} // force virtual class to enable memory container auto-casting when extending this class with another virtual class
  11. Area(C VecI2 &xy, Ptr grid_user);
  12. #if !EE_PRIVATE
  13. private:
  14. #endif
  15. VecI2 _xy;
  16. Memc<Obj*> _objs;
  17. };
  18. /******************************************************************************/
  19. struct World // Net World
  20. {
  21. Grid<Area> grid;
  22. // get
  23. C UID& id ()C {return _id;}
  24. C Str& name ()C {return _name;}
  25. C Str& dataPath()C {return _data_path;}
  26. Flt areaSize()C {return _area_size;} World& areaSize(Flt size); // get/set area size (in meters), default=32
  27. Flt neighborDist()C {return _neighbor_dist;} World& neighborDist(Flt dist); // get/set neighbor distance (in meters), default=64 (neighbor distance is the distance between objects at which they are considered to be neighbors, and exchange information between each other, for example characters are visible to each other only if their distance is less than neighbor distance)
  28. VecI2 worldToArea(C Vec2 &pos )C {return Floor(pos/areaSize());}
  29. VecI2 worldToArea(C Vec &pos )C {return worldToArea(pos .xz());}
  30. RectI worldToArea(C Rect &rect)C {return RectI(worldToArea(rect.min), worldToArea(rect.max));}
  31. RectI worldToArea(C Box &box )C {return RectI(worldToArea(box .min), worldToArea(box .max));}
  32. Game::Waypoint* findWaypoint(C Str &name)C {return name.is () ? Game::Waypoints.get(dataPath()+"Waypoint/"+name ) : null;} // find waypoint in this world, null on fail
  33. Game::Waypoint* findWaypoint(C UID &id )C {return id .valid() ? Game::Waypoints.get(dataPath()+"Waypoint/"+EncodeFileName(id)) : null;} // find waypoint in this world, null on fail
  34. Game::Waypoint* getWaypoint(C Str &name)C {return name.is () ? Game::Waypoints (dataPath()+"Waypoint/"+name ) : null;} // get waypoint in this world, Exit on fail
  35. Game::Waypoint* getWaypoint(C UID &id )C {return id .valid() ? Game::Waypoints (dataPath()+"Waypoint/"+EncodeFileName(id)) : null;} // get waypoint in this world, Exit on fail
  36. // io
  37. Bool load(C Str &name);
  38. World();
  39. #if !EE_PRIVATE
  40. private:
  41. #endif
  42. Flt _area_size, _neighbor_dist, _neighbor_dist2;
  43. Str _name, _data_path;
  44. UID _id;
  45. };
  46. /******************************************************************************/
  47. extern Cache<World> Worlds;
  48. /******************************************************************************/
  49. } // namespace
  50. /******************************************************************************/