Waypoint.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /******************************************************************************
  2. Use 'Waypoint' to handle helper world positions, paths management.
  3. You can use it to:
  4. -specify custom positions
  5. -specify custom paths
  6. /******************************************************************************/
  7. namespace Game{
  8. /******************************************************************************/
  9. struct Waypoint
  10. {
  11. enum LOOP_MODE : Byte
  12. {
  13. SINGLE , // Waypoint is a single path (for example 0, 1, 2 )
  14. LOOP , // Waypoint is a looped path (for example 0, 1, 2, 0, 1, 2, ..)
  15. PING_PONG, // Waypoint is a ping-pong path (for example 0, 1, 2, 1, 0, 1, ..)
  16. };
  17. struct Point
  18. {
  19. Vec pos ; // point position
  20. Flt total_length; // total length from starting position
  21. };
  22. LOOP_MODE loop_mode; // looping mode, default=SINGLE
  23. Mems<Point> points;
  24. // get
  25. Flt length( )C; // get total length
  26. Vec pos (Flt x, Bool smooth=false)C; // get position at 'x' total length, 'smooth' if use additional spline based smoothing
  27. // operations
  28. void New ( C Vec &pos); // create a new point at the end at 'pos' position
  29. void New (Int i, C Vec &pos); // create a new point at i-th at 'pos' position
  30. Waypoint& remove (Int i ); // remove i-th point
  31. Waypoint& rol ( ); // rotate left order of points
  32. Waypoint& ror ( ); // rotate right order of points
  33. Waypoint& reverse ( ); // reverse order of points
  34. Waypoint& updateTotalLengths( ); // update 'total_length' of points according to their positions
  35. // draw
  36. void draw(C Color &point_color=WHITE, C Color &edge_color=WHITE, Flt point_radius=0.5f, Int edge_steps=1)C; // this can be optionally called outside of Render function, 'edge_steps'=how many steps apply for edge smoothing (<=1 applies no smoothing)
  37. // io
  38. Bool save(C Str &name)C; // save, false on fail
  39. Bool load(C Str &name) ; // load, false on fail
  40. Bool save( File &f )C; // save, false on fail
  41. Bool load( File &f ) ; // load, false on fail
  42. #if EE_PRIVATE
  43. Bool saveData(File &f)C; // save, false on fail
  44. Bool loadData(File &f) ; // load, false on fail
  45. void zero();
  46. #endif
  47. Waypoint& del(); // delete manually
  48. Waypoint();
  49. };
  50. /******************************************************************************/
  51. extern Cache<Waypoint> Waypoints;
  52. /******************************************************************************/
  53. void DrawWaypoint(C Vec &pos, C Color &color=WHITE, Flt radius=0.5f);
  54. /******************************************************************************/
  55. } // namespace
  56. /******************************************************************************/
  57. inline Int Elms(C Game::Waypoint &waypoint) {return waypoint.points.elms();}
  58. /******************************************************************************/