QGearsHRCFileSerializer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 "QGearsHRCFile.h"
  17. #include "QGearsSerializer.h"
  18. namespace QGears{
  19. /**
  20. * Handles the serialization of HRC files.
  21. */
  22. class HRCFileSerializer : public Serializer{
  23. public:
  24. /**
  25. * Constructor.
  26. */
  27. HRCFileSerializer();
  28. /**
  29. * Destructor.
  30. */
  31. virtual ~HRCFileSerializer();
  32. /**
  33. * Imports a HRC file.
  34. *
  35. * @param stream[in] The contents of the HRC file.
  36. * @param dest[out] The formed HRC file.
  37. */
  38. virtual void ImportHRCFile(
  39. Ogre::DataStreamPtr &stream, HRCFile* dest
  40. );
  41. protected:
  42. /**
  43. * A comment tag.
  44. */
  45. static const String TAG_COMMENT;
  46. /**
  47. * File version tag.
  48. */
  49. static const String TAG_VERSION;
  50. /**
  51. * The name tag.
  52. */
  53. static const String TAG_NAME;
  54. /**
  55. * The bone count tag.
  56. */
  57. static const String TAG_BONE_COUNT;
  58. typedef std::vector<String> Block;
  59. typedef HRCFile::Bone Bone;
  60. /**
  61. * Reads a file header and sets the instance data.
  62. *
  63. * @param stream[in] The contents of the HRC file.
  64. */
  65. virtual void ReadFileHeader(Ogre::DataStreamPtr &stream);
  66. /**
  67. * Reads an object as a block.
  68. *
  69. * @param stream[in] Input data.
  70. * @param dest[out] The formed block data.
  71. */
  72. virtual void ReadBlock(Ogre::DataStreamPtr &stream, Block& dest);
  73. /**
  74. * Reads an object as a bone.
  75. *
  76. * @param stream[in] Input data.
  77. * @param dest[out] The formed bone data.
  78. */
  79. virtual void readObject(Ogre::DataStreamPtr &stream, Bone &dest);
  80. template<typename ValueType> void ReadVector(
  81. Ogre::DataStreamPtr &stream, std::vector<ValueType> &dest,
  82. size_t count
  83. );
  84. /**
  85. * An HRC file header.
  86. */
  87. struct Header{
  88. /**
  89. * File format version.
  90. */
  91. long version;
  92. /**
  93. * Number of bones in the file.
  94. */
  95. long bone_count;
  96. /**
  97. * Name of the skeleton in the file.
  98. */
  99. String name;
  100. };
  101. private:
  102. /**
  103. * The file header.
  104. */
  105. Header header_;
  106. };
  107. }