QGearsFLevelFileSerializer.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. -----------------------------------------------------------------------------
  3. The MIT License (MIT)
  4. Copyright (c) 2013-08-24 Tobias Peters <tobias.peters@kreativeffekt.at>
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. -----------------------------------------------------------------------------
  21. */
  22. #ifndef __QGearsFLevelFileSerializer_H__
  23. #define __QGearsFLevelFileSerializer_H__
  24. #include "common/TypeDefine.h"
  25. #include "QGearsFLevelFile.h"
  26. #include "QGearsSerializer.h"
  27. namespace QGears
  28. {
  29. class FLevelFileSerializer : public Serializer
  30. {
  31. public:
  32. FLevelFileSerializer();
  33. virtual ~FLevelFileSerializer();
  34. virtual void importFLevelFile( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
  35. enum
  36. {
  37. SECTION_SCRIPT
  38. ,SECTION_CAMERA_MATRIX
  39. ,SECTION_MODEL_LOADER
  40. ,SECTION_PALETTE
  41. ,SECTION_WALKMESH
  42. ,SECTION_TILE_MAP
  43. ,SECTION_ENCOUNTER
  44. ,SECTION_TRIGGER
  45. ,SECTION_BACKGROUND
  46. ,SECTION_COUNT
  47. };
  48. struct Header
  49. {
  50. uint16 version;
  51. uint32 section_count;
  52. };
  53. protected:
  54. void readFileHeader( Ogre::DataStreamPtr &stream );
  55. void readSectionData(Ogre::DataStreamPtr &stream, Ogre::DataStreamPtr &out_buffer, size_t sectionSize);
  56. virtual void readSection( Ogre::DataStreamPtr &stream, FLevelFile* pDest, const size_t section_index );
  57. template<typename ResourceManagerType>
  58. Ogre::ResourcePtr createResource( FLevelFile *pDest, const String &extension );
  59. void readCameraMatrix( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
  60. void readModelList ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
  61. void readPalette ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
  62. void readWalkmesh ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
  63. void readBackground ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
  64. void readTriggers (Ogre::DataStreamPtr &stream, FLevelFile* pDest);
  65. void readEnd( Ogre::DataStreamPtr &stream );
  66. template<typename ValueType> void
  67. readVector( Ogre::DataStreamPtr &stream, std::vector<ValueType> &pDest, size_t count );
  68. virtual String getBaseName ( const FLevelFile* pDest ) const;
  69. static const String TAG_FILE_END;
  70. private:
  71. Header m_header;
  72. };
  73. }
  74. #endif // __QGearsFLevelFileSerializer_H__