QGearsBackgroundFileSerializer.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. -----------------------------------------------------------------------------
  3. The MIT License (MIT)
  4. Copyright (c) 2013-08-10 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 __QGearsBackgroundFileSerializer_H__
  23. #define __QGearsBackgroundFileSerializer_H__
  24. #include "common/TypeDefine.h"
  25. #include "data/QGearsBackgroundFile.h"
  26. #include "data/QGearsSerializer.h"
  27. namespace QGears
  28. {
  29. class BackgroundFileSerializer : public Serializer
  30. {
  31. public:
  32. BackgroundFileSerializer();
  33. virtual ~BackgroundFileSerializer();
  34. void importBackgroundFile( Ogre::DataStreamPtr &stream, BackgroundFile *pDest );
  35. enum {
  36. BIT_MASK_RED = 0xF800
  37. ,BIT_MASK_GREEN = 0x07C0
  38. ,BIT_MASK_BLUE = 0x001F
  39. ,BIT_SIZE = 0x001F
  40. ,BIT_MASK_RGB = BIT_MASK_BLUE | BIT_MASK_GREEN | BIT_MASK_RED
  41. ,SPRITE_DST_MAX = 1024
  42. };
  43. struct Header
  44. {
  45. uint16 unused;
  46. uint16 sort_sprites_by_palette;
  47. };
  48. typedef BackgroundFile::Layer Layer;
  49. typedef BackgroundFile::SpriteData SpriteData;
  50. typedef BackgroundFile::SpriteList SpriteList;
  51. typedef BackgroundFile::Page Page;
  52. typedef BackgroundFile::Color Color;
  53. protected:
  54. virtual void readFileHeader( Ogre::DataStreamPtr &stream );
  55. virtual void readSectionHeader( Ogre::DataStreamPtr &stream, const String &section_name );
  56. virtual void readPallete( Ogre::DataStreamPtr &stream, BackgroundFile *pDest );
  57. virtual void readBackground( Ogre::DataStreamPtr &stream, BackgroundFile *pDest );
  58. virtual void readTexture( Ogre::DataStreamPtr &stream, BackgroundFile *pDest );
  59. virtual void readEnd( Ogre::DataStreamPtr &stream );
  60. virtual void readLayer( Ogre::DataStreamPtr &stream, Layer *pDest, size_t layer_index );
  61. virtual void readObject( Ogre::DataStreamPtr &stream, SpriteData &pDest );
  62. virtual void readObject( Ogre::DataStreamPtr &stream, Color &pDest );
  63. virtual void readObject( Ogre::DataStreamPtr &stream, Page &pDest );
  64. using Serializer::readObject;
  65. template<typename ValueType> void
  66. readVector( Ogre::DataStreamPtr &stream, std::vector<ValueType> &pDest, size_t count )
  67. {
  68. pDest.clear();
  69. pDest.reserve( count );
  70. for( size_t i( count ); i--; )
  71. {
  72. ValueType in_tmp;
  73. readObject( stream, in_tmp );
  74. pDest.push_back( in_tmp );
  75. }
  76. }
  77. static const String SECTION_NAME_PALETTE;
  78. static const String SECTION_NAME_BACK;
  79. static const String SECTION_NAME_TEXTURE;
  80. static const String TAG_FILE_END;
  81. static const Ogre::Real src_big_SCALE;
  82. private:
  83. void removeBuggySprites( SpriteList &sprites );
  84. Header m_header;
  85. size_t m_layer_index;
  86. };
  87. }
  88. #endif // __QGearsBackgroundFileSerializer_H__