FF7WalkmeshFileSerializer.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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/TypeDefine.h"
  17. #include "data/QGearsSerializer.h"
  18. #include "map/QGearsWalkmeshFile.h"
  19. namespace QGears{
  20. namespace FF7{
  21. /**
  22. * Handles the serialization of walkmesh files.
  23. */
  24. class WalkmeshFileSerializer : public Serializer{
  25. public:
  26. /**
  27. * Constructor.
  28. */
  29. WalkmeshFileSerializer();
  30. /**
  31. * Destructor.
  32. */
  33. virtual ~WalkmeshFileSerializer();
  34. /**
  35. * Imports a walkmesh file.
  36. *
  37. * @param stream[in] The contents of the walkmesh file.
  38. * @param dest[out] The formed walkmesh file.
  39. */
  40. virtual void ImportWalkmeshFile(
  41. Ogre::DataStreamPtr &stream, WalkmeshFile *dest
  42. );
  43. typedef WalkmeshFile::Triangle WalkmeshTriangle;
  44. typedef WalkmeshFile::TriangleList WalkmeshTriangleList;
  45. /**
  46. * @todo Understand and document.
  47. */
  48. enum{
  49. /**
  50. * @todo Understand and document.
  51. */
  52. VERTEX_PADDING_COUNT = 1,
  53. /**
  54. * @todo Understand and document.
  55. */
  56. VERTEX_COMPONENT_COUNT = 3 + VERTEX_PADDING_COUNT,
  57. /**
  58. * @todo Understand and document.
  59. */
  60. ACCESS_COMPONENT_COUNT = 3
  61. };
  62. /**
  63. * A walkmesh triangle.
  64. */
  65. struct Triangle{
  66. /**
  67. * A side of the triangle.
  68. */
  69. Ogre::Vector3 a;
  70. /**
  71. * A side of the triangle.
  72. */
  73. Ogre::Vector3 b;
  74. /**
  75. * A side of the triangle.
  76. */
  77. Ogre::Vector3 c;
  78. };
  79. /**
  80. * Defines the access to a triangle.
  81. */
  82. struct Access{
  83. /**
  84. * @todo Understand and document.
  85. */
  86. sint16 a;
  87. /**
  88. * @todo Understand and document.
  89. */
  90. sint16 b;
  91. /**
  92. * @todo Understand and document.
  93. */
  94. sint16 c;
  95. };
  96. typedef std::vector<Triangle> TriangleList;
  97. typedef std::vector<Access> AccessList;
  98. protected:
  99. /**
  100. * Reads an object as a walkmesh triangle.
  101. *
  102. * @param stream[in] Input data.
  103. * @param dest[out] The formed triangle data.
  104. */
  105. virtual void readObject(
  106. Ogre::DataStreamPtr &stream, Triangle &dest
  107. );
  108. /**
  109. * Reads an object as a 3-dimensional vector.
  110. *
  111. * @param stream[in] Input data.
  112. * @param dest[out] The formed vector data.
  113. */
  114. virtual void readObject(
  115. Ogre::DataStreamPtr &stream, Ogre::Vector3 &dest
  116. );
  117. /**
  118. * Reads an object as a triangle access point.
  119. *
  120. * @param stream[in] Input data.
  121. * @param dest[out] The formed access point data.
  122. */
  123. virtual void readObject(
  124. Ogre::DataStreamPtr &stream, Access &dest
  125. );
  126. using Serializer::readObject;
  127. /**
  128. * Reads an object as a vector.
  129. *
  130. * @param stream[in] Input data.
  131. * @param dest[out] The formed vector data.
  132. * @param count[in] The size of the data to read.
  133. */
  134. template<typename ValueType> void ReadVector(
  135. Ogre::DataStreamPtr &stream, std::vector<ValueType> &dest,
  136. size_t count
  137. );
  138. };
  139. }
  140. }