QGearsBackgroundFile.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. -----------------------------------------------------------------------------
  3. The MIT License (MIT)
  4. Copyright (c) 2013-08-19 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 __QGearsBackgroundFile_H__
  23. #define __QGearsBackgroundFile_H__
  24. #include <OgreResource.h>
  25. #include <OgreImage.h>
  26. #include <OgreVector3.h>
  27. #include "common/TypeDefine.h"
  28. #include "data/QGearsPaletteFile.h"
  29. #include <array>
  30. namespace QGears
  31. {
  32. // TODO inherit from Qgears Ressource
  33. class BackgroundFile : public Ogre::Resource
  34. {
  35. public:
  36. BackgroundFile( Ogre::ResourceManager *creator, const String &name
  37. ,Ogre::ResourceHandle handle, const String &group
  38. ,bool isManual = false, Ogre::ManualResourceLoader *loader = NULL );
  39. virtual ~BackgroundFile();
  40. static const String RESOURCE_TYPE;
  41. enum {
  42. PAGE_DATA_WIDTH = 256
  43. ,PAGE_DATA_HEIGHT = PAGE_DATA_WIDTH
  44. ,PAGE_DATA_SIZE = PAGE_DATA_WIDTH * PAGE_DATA_HEIGHT
  45. ,SPRITE_WIDTH = 16
  46. ,SPRITE_HEIGHT = SPRITE_WIDTH
  47. ,SPRITE_PIXEL_COUNT = SPRITE_WIDTH * SPRITE_HEIGHT
  48. ,LAYER_COUNT = 4
  49. ,PALETTE_ENTRY_COUNT = 20
  50. ,PAGE_COUNT = 42
  51. };
  52. struct SpriteData
  53. {
  54. Pixel dst;
  55. uint16 unknown_04[2];
  56. Pixel src;
  57. uint16 unknown_0C[4];
  58. uint16 palette_page;
  59. uint16 depth;
  60. uint8 flags_18[2];
  61. bool flags_20[2];
  62. uint16 unknown_1C; // maybe some 'mode'
  63. uint16 data_page;
  64. uint16 data_page2; // used for special effects pages, when data_page2 != 0, it must be used instead of data_page
  65. uint16 colourDepth;
  66. Ogre::Vector3 unknown_24;
  67. };
  68. typedef std::vector<SpriteData> SpriteList;
  69. struct Layer
  70. {
  71. bool enabled;
  72. uint16 width;
  73. uint16 height;
  74. // uint16 sprite_count only read in serializer
  75. uint16 unknown_06; // unused in layer0
  76. uint16 unknown_08[3]; // layer 1,2,3
  77. uint16 unknown_0E[4]; // layer 2,3
  78. SpriteList sprites;
  79. };
  80. typedef PaletteFile::Color Color;
  81. typedef std::vector<uint8> Buffer;
  82. typedef std::vector<Color> Colors;
  83. struct Page
  84. {
  85. bool enabled; // only read further if this is > 0
  86. uint16 unknown_02;
  87. uint16 value_size;
  88. // uint8 if value_size == 1, uint16 if value_size == 2
  89. //uint8 data[PAGE_DATA_WIDTH][PAGE_DATA_HEIGHT];
  90. Buffer data;
  91. Colors colors;
  92. };
  93. std::array<Layer, LAYER_COUNT>& getLayers(void) { return m_layers; }
  94. std::array<uint8, PALETTE_ENTRY_COUNT>& getPalette(void) { return m_palette; }
  95. std::array<Page, PAGE_COUNT>& getPages(void) { return m_pages; }
  96. virtual Ogre::Image* createImage ( const PaletteFilePtr &palette ) const;
  97. virtual void addAllSprites( SpriteList& sprites ) const;
  98. protected:
  99. virtual void loadImpl();
  100. virtual void unloadImpl();
  101. virtual size_t calculateSize() const;
  102. virtual size_t calculateSize( const Layer &layer ) const;
  103. virtual size_t calculateSize( const Page &page ) const;
  104. private:
  105. std::array<Layer, LAYER_COUNT> m_layers;
  106. std::array<uint8, PALETTE_ENTRY_COUNT> m_palette;
  107. std::array<Page, PAGE_COUNT> m_pages;
  108. };
  109. typedef Ogre::SharedPtr<BackgroundFile> BackgroundFilePtr;
  110. }
  111. #endif // __QGearsBackgroundFile_H__