QGearsMapFile.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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/QGearsResource.h"
  17. #include "core/EntityPoint.h"
  18. #include "core/EntityTrigger.h"
  19. namespace QGears{
  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 creator[in] Pointer to the ResourceManager that is
  33. * creating this resource.
  34. * @param name[in] The unique name of the resource.
  35. * @param handle[in] @todo Understand and document.
  36. * @param group[in] The name of the resource group to which this
  37. * resource belong.
  38. * @param is_manual[in] True if the resource is manually loaded,
  39. * false otherwise.
  40. * @param loader[in] Pointer to a ManualResourceLoader
  41. * implementation which will be called when the Resource wishes to
  42. * load (should be supplied if is_manual is set to true). It can be
  43. * null, but the Resource will never be able to reload if anything
  44. * ever causes it to unload. Therefore provision of a proper
  45. * ManualResourceLoader instance is strongly recommended.
  46. */
  47. MapFile(
  48. Ogre::ResourceManager* creator, const String &name,
  49. Ogre::ResourceHandle handle, const String& group,
  50. bool is_manual = false,
  51. Ogre::ManualResourceLoader* loader = NULL
  52. );
  53. /**
  54. * Destructor.
  55. */
  56. virtual ~MapFile();
  57. typedef EntityPoint Point;
  58. typedef std::vector<Point> PointList;
  59. typedef EntityTrigger Trigger;
  60. typedef std::vector<Trigger> TriggerList;
  61. /**
  62. * Retrieves the map script name.
  63. *
  64. * @return The script name.
  65. */
  66. virtual const String& GetScriptName() const;
  67. /**
  68. * Retrieves the map background name.
  69. *
  70. * @return The background name.
  71. */
  72. virtual const String& GetBackground2dName() const;
  73. /**
  74. * Retrieves the map walkmesh name.
  75. *
  76. * @return The walkmesh 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
  83. * moves when 'up' is 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] The script name.
  104. */
  105. virtual void SetScriptName(const String &script_name);
  106. /**
  107. * Sets the map background name.
  108. *
  109. * @param[in] The background name.
  110. */
  111. virtual void SetBackground2dName(const String &background2d_name);
  112. /**
  113. * Sets the map walkmesh name.
  114. *
  115. * @param[in] The walkmesh name.
  116. */
  117. virtual void SetWalkmeshName(const String &walkmesh_name);
  118. /**
  119. * Sets the map forward direction.
  120. *
  121. * The forward direction is the direction the playable character
  122. * moves when 'up' is pressed.
  123. *
  124. * @param forward_direction[in] The forward direction.
  125. */
  126. virtual void SetForwardDirection(
  127. const Ogre::Real &forward_direction
  128. );
  129. protected:
  130. /**
  131. * Loads the file.
  132. */
  133. virtual void loadImpl() override;
  134. /**
  135. * Unloads the file.
  136. */
  137. virtual void unloadImpl() override;
  138. /**
  139. * Calculates the size of the palette.
  140. *
  141. * @return The size of the palette.
  142. * @todo Units?
  143. */
  144. virtual size_t calculateSize() const;
  145. private:
  146. /**
  147. * The script name.
  148. */
  149. String script_name_;
  150. /**
  151. * The background name.
  152. */
  153. String background_2d_name;
  154. /**
  155. * The walkmesh name.
  156. */
  157. String walkmesh_name_;
  158. /**
  159. * The forward direction.
  160. */
  161. Ogre::Real forward_direction_;
  162. /**
  163. * The list of entity points.
  164. */
  165. PointList points_;
  166. /**
  167. * The list of triggers.
  168. */
  169. TriggerList triggers_;
  170. };
  171. typedef Ogre::SharedPtr<MapFile> MapFilePtr;
  172. }