Mini Map.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /******************************************************************************
  2. Use 'MiniMap' to automatically manage world mini maps.
  3. /******************************************************************************/
  4. namespace Game{
  5. /******************************************************************************/
  6. struct MiniMap
  7. {
  8. struct Settings
  9. {
  10. Int areas_per_image, image_size;
  11. Flt area_size;
  12. Bool save(C Str &name)C; // save to file, false on fail
  13. Bool load(C Str &name) ; // load from file, false on fail
  14. Bool save(File &f)C; // save to file, false on fail
  15. Bool load(File &f) ; // load from file, false on fail
  16. void del();
  17. Settings() {del();}
  18. };
  19. // load
  20. void operator=(C Str &name); // load mini map from specified 'name', Exit on fail
  21. void operator=(C UID &id ); // load mini map from specified 'id' , Exit on fail
  22. Bool load (C Str &name); // load mini map from specified 'name', false on fail
  23. Bool load (C UID &id ); // load mini map from specified 'id' , false on fail
  24. // get
  25. C UID& id ()C {return _id ;} // get name ID of current mini map
  26. C Str& name ()C {return _name ;} // get name of current mini map
  27. Flt areaSize ()C {return _settings.area_size ;} // get size of an area of current mini map (in meters)
  28. Int areasPerImage()C {return _settings.areas_per_image;} // get number of areas per single image map
  29. Image& operator()(C VecI2 &image_xy) {return *_map(image_xy);} // get map image, 'image_xy'=image coordinates (these are not Area coordinates! many areas can be stored in a single map image)
  30. // convert coordinates
  31. // world (meters) <-> area
  32. Vec2 worldToArea (C Vec2 &pos )C {return pos /areaSize();} // convert world 'pos' position to area coordinates
  33. Vec2 areaToWorld(C Vec2 &area)C {return area*areaSize();} // convert area coordinates to world position
  34. // area <-> image
  35. Vec2 areaToImage(C Vec2 &area )C {return area /areasPerImage();} // convert area coordinates to image
  36. Vec2 imageToArea (C Vec2 &image)C {return image*areasPerImage();} // convert image to area coordinates
  37. // world (meters) <-> image
  38. Vec2 worldToImage(C Vec2 &pos )C {return pos /(areaSize()*areasPerImage());} // convert world 'pos' position to image
  39. Vec2 imageToWorld(C Vec2 &image)C {return image*(areaSize()*areasPerImage());} // convert image to world position
  40. // operations
  41. void clear(C RectI *leave=null); // remove all loaded images from memory, 'leave'=coordinates of images to leave in memory (without removing), if 'leave'==null then all images are removed
  42. void del(); // delete manually
  43. MiniMap();
  44. #if !EE_PRIVATE
  45. private:
  46. #endif
  47. Settings _settings;
  48. Str _name;
  49. UID _id;
  50. Map<VecI2, Image> _map;
  51. #if EE_PRIVATE
  52. static Bool Create(Image &image, C VecI2 &key, Ptr user);
  53. #endif
  54. };
  55. /******************************************************************************/
  56. } // namespace
  57. /******************************************************************************/