QGearsAFileSerializer.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 "QGearsAFile.h"
  18. #include "QGearsSerializer.h"
  19. namespace QGears{
  20. /**
  21. * Handles the serialization of A files.
  22. */
  23. class AFileSerializer : public Serializer{
  24. public:
  25. /**
  26. * Constructor.
  27. */
  28. AFileSerializer();
  29. /**
  30. * Destructor.
  31. */
  32. virtual ~AFileSerializer();
  33. /**
  34. * Imports an A file.
  35. *
  36. * @param stream[in] The contents of the A file.
  37. * @param dest[out] The A file.
  38. */
  39. void ImportAFile(Ogre::DataStreamPtr &stream, AFile* dest);
  40. /**
  41. * An A file header.
  42. */
  43. struct Header{
  44. /**
  45. * The file type version.
  46. */
  47. uint32 version;
  48. /**
  49. * The frame count.
  50. */
  51. uint32 frame_count;
  52. /**
  53. * The number of bones.
  54. */
  55. uint32 bone_count;
  56. /**
  57. * The axis rotation order.
  58. */
  59. uint32 rotation_order;
  60. /**
  61. * @todo Understand and document.
  62. */
  63. uint32 runtime_data[5];
  64. };
  65. protected:
  66. /**
  67. * Reads a file header and sets the instance data.
  68. *
  69. * @param stream[in] The contents of the A file.
  70. */
  71. virtual void ReadFileHeader(Ogre::DataStreamPtr &stream) final;
  72. /**
  73. * Reads an object as an A file.
  74. *
  75. * @param stream[in] Input data.
  76. * @param dest[out] The formed A file.
  77. */
  78. void readObject(Ogre::DataStreamPtr &stream, AFile::Frame &dest);
  79. using Serializer::readObject;
  80. /**
  81. * Reads a stream as a vector.
  82. *
  83. * @param stream[in] The input stream.
  84. * @param dest[out] The vector data will be loaded here.
  85. * @param count[in] Data units to copy.
  86. */
  87. template<typename ValueType> void ReadVector(
  88. Ogre::DataStreamPtr &stream, std::vector<ValueType> &dest,
  89. size_t count
  90. );
  91. private:
  92. /**
  93. * The file header.
  94. */
  95. Header header_;
  96. };
  97. }