QGearsWalkmeshFileXMLSerializer.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/QGearsXMLSerializer.h"
  18. #include "QGearsWalkmeshFile.h"
  19. namespace QGears{
  20. /**
  21. * Handles the serialization of walkmesh files.
  22. */
  23. class WalkmeshFileXMLSerializer : public XMLSerializer{
  24. public:
  25. /**
  26. * Constructor.
  27. */
  28. WalkmeshFileXMLSerializer();
  29. /**
  30. * Destructor.
  31. */
  32. virtual ~WalkmeshFileXMLSerializer();
  33. /**
  34. * Imports a walkmesh file.
  35. *
  36. * @param stream[in] The contents of the map file.
  37. * @param dest[out] The formed walkmesh file.
  38. */
  39. virtual void ImportWalkmeshFile(
  40. Ogre::DataStreamPtr &stream, WalkmeshFile *dest
  41. );
  42. typedef WalkmeshFile::Triangle Triangle;
  43. typedef WalkmeshFile::TriangleList TriangleList;
  44. protected:
  45. /**
  46. * Reads a file header from an XML node and sets the instance data.
  47. *
  48. * @param node[in] The XML node to read.
  49. */
  50. virtual void ReadHeader(TiXmlNode *node);
  51. /**
  52. * Reads an XML node as a triangle.
  53. *
  54. * @param node[in] The XML node to read.
  55. * @param dest[out] The formed triangle data.
  56. */
  57. virtual void readObject(TiXmlNode &node, Triangle &dest);
  58. /**
  59. * Reads a XML node as a vector.
  60. *
  61. * @param node[in] The XML node to read.
  62. * @param dest[out] The vector data will be loaded here.
  63. * @param tag[in] XML tag to read.
  64. */
  65. template<typename ValueType> void ReadVector(
  66. TiXmlNode &node, std::vector<ValueType> &dest, const String &tag
  67. ){
  68. dest.clear();
  69. TiXmlNode* child(node.FirstChild());
  70. while (child != NULL){
  71. if (
  72. child->Type() == TiXmlNode::TINYXML_ELEMENT
  73. && child->ValueStr() == tag
  74. ){
  75. ValueType in_tmp;
  76. readObject(*child, in_tmp);
  77. dest.push_back(in_tmp);
  78. }
  79. child = child->NextSibling();
  80. }
  81. }
  82. };
  83. }