VGearsMapFile.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include "common/VGearsResource.h"
  17. #include "core/EntityPoint.h"
  18. #include "core/EntityTrigger.h"
  19. namespace VGears{
  20. /**
  21. * Handles map files.
  22. */
  23. class MapFile : public Resource{
  24. public:
  25. /**
  26. * The type of resource
  27. */
  28. static const String RESOURCE_TYPE;
  29. /**
  30. * Constructor.
  31. *
  32. * @param[in] creator Pointer to the ResourceManager that is creating this resource.
  33. * @param[in] name The unique name of the resource.
  34. * @param[in] handle @todo Understand and document.
  35. * @param[in] group The name of the resource group to which this resource belong.
  36. * @param[in] is_manual True if the resource is manually loaded, false otherwise.
  37. * @param[in] loader Pointer to a ManualResourceLoader implementation which will be
  38. * called when the Resource wishes to load (should be supplied if is_manual is set to
  39. * true). It can be null, but the Resource will never be able to reload if anything
  40. * ever causes it to unload. Therefore provision of a proper ManualResourceLoader
  41. * instance is strongly recommended.
  42. */
  43. MapFile(
  44. Ogre::ResourceManager* creator, const String &name, Ogre::ResourceHandle handle,
  45. const String& group, bool is_manual = false, Ogre::ManualResourceLoader* loader = NULL
  46. );
  47. /**
  48. * Destructor.
  49. */
  50. virtual ~MapFile();
  51. typedef EntityPoint Point;
  52. typedef std::vector<Point> PointList;
  53. typedef EntityTrigger Trigger;
  54. typedef std::vector<Trigger> TriggerList;
  55. /**
  56. * Retrieves the map script name.
  57. *
  58. * @return The script name.
  59. */
  60. virtual const String& GetScriptName() const;
  61. /**
  62. * Retrieves the map background file name.
  63. *
  64. * @return The background file name.
  65. */
  66. virtual const String& GetBackground2dName() const;
  67. /**
  68. * Retrieves the map texts file name.
  69. *
  70. * @return The texts file name.
  71. */
  72. virtual const String& GetTextsName() const;
  73. /**
  74. * Retrieves the map walkmesh file name.
  75. *
  76. * @return The walkmesh file name.
  77. */
  78. virtual const String& GetWalkmeshName() const;
  79. /**
  80. * Retrieves the map forward direction.
  81. *
  82. * The forward direction is the direction the playable character moves when 'up' is
  83. * pressed.
  84. *
  85. * @return The forward direction.
  86. */
  87. virtual const Ogre::Real& GetForwardDirection() const;
  88. /**
  89. * Retrieves the list of entity points in the map.
  90. *
  91. * @return The list of entity points in the map.
  92. */
  93. virtual PointList& GetPoints();
  94. /**
  95. * Retrieves the map triggers.
  96. *
  97. * @return The list of triggers.
  98. */
  99. virtual TriggerList& GetTriggers();
  100. /**
  101. * Sets the map script name.
  102. *
  103. * @param[in] script_name The script name.
  104. */
  105. virtual void SetScriptName(const String& script_name);
  106. /**
  107. * Sets the map background file name.
  108. *
  109. * @param[in] background2d_name The background file name.
  110. */
  111. virtual void SetBackground2dName(const String& background2d_name);
  112. /**
  113. * Sets the map field texts file name.
  114. *
  115. * @param[in] texts The texts file name.
  116. */
  117. virtual void SetTextsName(const String& texts_name);
  118. /**
  119. * Sets the map walkmesh file name.
  120. *
  121. * @param[in] walkmesh_name The walkmesh file name.
  122. */
  123. virtual void SetWalkmeshName(const String& walkmesh_name);
  124. /**
  125. * Sets the map forward direction.
  126. *
  127. * The forward direction is the direction the playable character moves when 'up' is
  128. * pressed.
  129. *
  130. * @param[in] forward_direction The forward direction.
  131. */
  132. virtual void SetForwardDirection(const Ogre::Real& forward_direction);
  133. protected:
  134. /**
  135. * Loads the file.
  136. */
  137. virtual void loadImpl() override;
  138. /**
  139. * Unloads the file.
  140. */
  141. virtual void unloadImpl() override;
  142. /**
  143. * Calculates the size of the map.
  144. *
  145. * It's the size of the tiles, script, walkmesh and forward direction.
  146. *
  147. * @return The size of the map.
  148. */
  149. virtual size_t calculateSize() const;
  150. private:
  151. /**
  152. * The script file name.
  153. */
  154. String script_name_;
  155. /**
  156. * The background file name.
  157. */
  158. String background_2d_name_;
  159. /**
  160. * The background file name.
  161. */
  162. String texts_name_;
  163. /**
  164. * The walkmesh file name.
  165. */
  166. String walkmesh_name_;
  167. /**
  168. * The forward direction.
  169. */
  170. Ogre::Real forward_direction_;
  171. /**
  172. * The list of entity points.
  173. */
  174. PointList points_;
  175. /**
  176. * The list of triggers.
  177. */
  178. TriggerList triggers_;
  179. };
  180. typedef Ogre::SharedPtr<MapFile> MapFilePtr;
  181. }