QGearsMapListFile.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 <OgreResourceManager.h>
  17. #include "QGearsPrerequisites.h"
  18. #include "common/QGearsResource.h"
  19. #include "QGearsSerializer.h"
  20. namespace QGears{
  21. /**
  22. * A manager for map list files.
  23. */
  24. class MapListFileManager :
  25. public Ogre::ResourceManager, public Ogre::Singleton<MapListFileManager>
  26. {
  27. // TODO: Move to it's own file?
  28. public:
  29. /**
  30. * Constructor.
  31. */
  32. MapListFileManager();
  33. /**
  34. * Destructor.
  35. */
  36. virtual ~MapListFileManager();
  37. /**
  38. * Retrieves a singleton to the manager.
  39. */
  40. static MapListFileManager& GetSingleton();
  41. /**
  42. * Retrieves a pointer to the manager singleton.
  43. */
  44. static MapListFileManager* GetSingletonPtr();
  45. protected:
  46. /**
  47. * Loads the manager.
  48. *
  49. * @param name[in] The unique name of the manager.
  50. * @param handle[in] @todo Understand and document.
  51. * @param group[in] The name of the resource group to which this
  52. * resource belong.
  53. * @param is_manual[in] True if the resource is manually loaded,
  54. * false otherwise.
  55. * @param loader[in] Pointer to a ManualResourceLoader
  56. * implementation which will be called when the Resource wishes to
  57. * load (should be supplied if is_manual is set to true). It can be
  58. * null, but the Resource will never be able to reload if anything
  59. * ever causes it to unload. Therefore provision of a proper
  60. * ManualResourceLoader instance is strongly recommended.
  61. * @param create_params[in] Unused.
  62. */
  63. virtual Ogre::Resource *createImpl(
  64. const Ogre::String &name, Ogre::ResourceHandle handle,
  65. const Ogre::String &group, bool is_manual,
  66. Ogre::ManualResourceLoader *loader,
  67. const Ogre::NameValuePairList *create_params
  68. ) override;
  69. };
  70. /**
  71. * Handles map list files.
  72. */
  73. class MapListFile : public Resource{
  74. public:
  75. /**
  76. * Constructor.
  77. *
  78. * @param creator[in] Pointer to the ResourceManager that is
  79. * creating this resource.
  80. * @param name[in] The unique name of the resource.
  81. * @param handle[in] @todo Understand and document.
  82. * @param group[in] The name of the resource group to which this
  83. * resource belong.
  84. * @param is_manual[in] True if the resource is manually loaded,
  85. * false otherwise.
  86. * @param loader[in] Pointer to a ManualResourceLoader
  87. * implementation which will be called when the Resource wishes to
  88. * load (should be supplied if is_manual is set to true). It can be
  89. * null, but the Resource will never be able to reload if anything
  90. * ever causes it to unload. Therefore provision of a proper
  91. * ManualResourceLoader instance is strongly recommended.
  92. */
  93. MapListFile(
  94. Ogre::ResourceManager* creator, const String &name,
  95. Ogre::ResourceHandle handle, const String& group,
  96. bool is_manual = false,
  97. Ogre::ManualResourceLoader* loader = nullptr
  98. );
  99. /**
  100. * Destructor.
  101. */
  102. virtual ~MapListFile();
  103. /**
  104. * The type of resource.
  105. */
  106. static const String RESOURCE_TYPE;
  107. /**
  108. * Retrieves the list of maps.
  109. *
  110. * @return The list of maps.
  111. */
  112. const std::vector<std::string> GetMapList() const{return map_list_;}
  113. protected:
  114. /**
  115. * Loads the file.
  116. */
  117. virtual void loadImpl() override;
  118. /**
  119. * Unloads the file.
  120. */
  121. virtual void unloadImpl() override;
  122. /**
  123. * Calculates the size of the map list.
  124. *
  125. * @return The size of the map list.
  126. * @todo Units?
  127. */
  128. virtual size_t calculateSize(void) const override;
  129. private:
  130. friend class MapListFileSerializer;
  131. /**
  132. * The list of maps.
  133. */
  134. std::vector<std::string> map_list_;
  135. };
  136. /**
  137. * Handles the serialization of map list files.
  138. */
  139. class MapListFileSerializer : public Serializer{
  140. // TODO: Move to it's own file?
  141. public:
  142. /**
  143. * Constructor.
  144. */
  145. MapListFileSerializer() = default;
  146. /**
  147. * Imports a map list file.
  148. *
  149. * @param stream[in] The contents of the map list file.
  150. * @param dest[out] The formed map list file.
  151. */
  152. void ImportMapListFile(
  153. Ogre::DataStreamPtr &stream, MapListFile& dest
  154. );
  155. };
  156. typedef Ogre::SharedPtr<MapListFile> MapListFilePtr;
  157. }