V-Gears 0
Free Final Fantasy VII engine.
VGearsBackgroundFile.h
Go to the documentation of this file.
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
16#pragma once
17
18#include <array>
19#include <OgreResource.h>
20#include <OgreImage.h>
21#include <Ogre.h>
22#include "common/TypeDefine.h"
24
25namespace VGears{
26
27 // TODO inherit from VGears Resource.
28
32 class BackgroundFile : public Ogre::Resource{
33
34 public:
35
55 Ogre::ResourceManager *creator, const String &name,
56 Ogre::ResourceHandle handle, const String &group,
57 bool is_manual = false, Ogre::ManualResourceLoader *loader = NULL
58 );
59
63 virtual ~BackgroundFile();
64
68 static const String RESOURCE_TYPE;
69
70 enum {
71
78
85
92
99
106
113
118
123
129 PAGE_COUNT = 42
130 };
131
136
141
146
151
159
164
169
174
179
184
189
194
199
204
212
219
226 Ogre::Vector3 src_big;
227 };
228
229 typedef std::vector<SpriteData> SpriteList;
230
231 typedef std::vector<SpriteData*> SpritePtrList;
232
236 void SortSprites();
237
241 struct Layer{
242
247
252
264
271
278
283 };
284
286
287 typedef std::vector<uint8> Buffer;
288
289 typedef std::vector<Color> Colors;
290
294 struct Page{
295
300
305
310
311 // //uint8 if value_size == 1, uint16 if value_size == 2
312 // uint8 data[PAGE_DATA_WIDTH][PAGE_DATA_HEIGHT];
313
318
323 };
324
330 std::array<Layer, LAYER_COUNT>& GetLayers(void) {return layers_;}
331
337 std::array<uint8, PALETTE_ENTRY_COUNT>& GetPalette(void) {
338 return palette_;
339 }
340
346 std::array<Page, PAGE_COUNT>& GetPages(void){return pages_;}
347
354 Ogre::Image* CreateImage(const PaletteFilePtr &palette);
355
361 void AddAllSprites(SpritePtrList& sprites) ;
362
363 protected:
364
368 virtual void loadImpl() override final;
369
373 virtual void unloadImpl() override final;
374
382 virtual size_t CalculateSize() const;
383
390 virtual size_t CalculateSize(const Layer &layer) const;
391
398 virtual size_t CalculateSize(const Page &page) const;
399
400 private:
401
406
411
415 std::array<Page, PAGE_COUNT> pages_;
416
424 static bool SpriteSorter(SpriteData sprite1, SpriteData sprite2);
425 };
426
427 typedef Ogre::SharedPtr<BackgroundFile> BackgroundFilePtr;
428}
A background file representation.
Definition: VGearsBackgroundFile.h:32
PaletteFile::Color Color
Definition: VGearsBackgroundFile.h:285
std::array< Layer, LAYER_COUNT > & GetLayers(void)
Retrieves the background layers.
Definition: VGearsBackgroundFile.h:330
void AddAllSprites(SpritePtrList &sprites)
Adds all sprites to the background.
Definition: VGearsBackgroundFile.cpp:82
BackgroundFile(Ogre::ResourceManager *creator, const String &name, Ogre::ResourceHandle handle, const String &group, bool is_manual=false, Ogre::ManualResourceLoader *loader=NULL)
Constructor.
Definition: VGearsBackgroundFile.cpp:25
virtual void unloadImpl() override final
Unloads the file.
Definition: VGearsBackgroundFile.cpp:44
std::vector< SpriteData * > SpritePtrList
Definition: VGearsBackgroundFile.h:231
Ogre::Image * CreateImage(const PaletteFilePtr &palette)
Creates an image from a palette.
Definition: VGearsBackgroundFile.cpp:102
std::vector< SpriteData > SpriteList
Definition: VGearsBackgroundFile.h:229
std::vector< uint8 > Buffer
Definition: VGearsBackgroundFile.h:287
std::array< Layer, LAYER_COUNT > layers_
The list of layers.
Definition: VGearsBackgroundFile.h:405
std::array< Page, PAGE_COUNT > pages_
The background pages.
Definition: VGearsBackgroundFile.h:415
virtual ~BackgroundFile()
Destructor.
Definition: VGearsBackgroundFile.cpp:32
virtual size_t CalculateSize() const
Calculates the size of the background.
Definition: VGearsBackgroundFile.cpp:55
std::array< uint8, PALETTE_ENTRY_COUNT > palette_
The color palette.
Definition: VGearsBackgroundFile.h:410
std::vector< Color > Colors
Definition: VGearsBackgroundFile.h:289
std::array< Page, PAGE_COUNT > & GetPages(void)
Retrieves the background pages.
Definition: VGearsBackgroundFile.h:346
std::array< uint8, PALETTE_ENTRY_COUNT > & GetPalette(void)
Retrieves the background palette.
Definition: VGearsBackgroundFile.h:337
void SortSprites()
Sorts the sprites.
Definition: VGearsBackgroundFile.cpp:94
@ PAGE_COUNT
Number of pages in a background.
Definition: VGearsBackgroundFile.h:129
@ PAGE_DATA_HEIGHT
Height of the background page, in pixels.
Definition: VGearsBackgroundFile.h:84
@ PAGE_DATA_WIDTH
Width of the background page, in pixels.
Definition: VGearsBackgroundFile.h:77
@ LAYER_COUNT
Number of layers in a background.
Definition: VGearsBackgroundFile.h:117
@ SPRITE_HEIGHT
Height of sprites, in pixels.
Definition: VGearsBackgroundFile.h:105
@ SPRITE_WIDTH
Width of sprites, in pixels.
Definition: VGearsBackgroundFile.h:98
@ PALETTE_ENTRY_COUNT
Number of palettes in a background.
Definition: VGearsBackgroundFile.h:122
@ PAGE_DATA_SIZE
Size of the background page, in pixels.
Definition: VGearsBackgroundFile.h:91
@ SPRITE_PIXEL_COUNT
Size of sprites, in pixels.
Definition: VGearsBackgroundFile.h:112
static bool SpriteSorter(SpriteData sprite1, SpriteData sprite2)
Sorting algorithm for sprite sorting.
Definition: VGearsBackgroundFile.cpp:273
static const String RESOURCE_TYPE
The type of resource.
Definition: VGearsBackgroundFile.h:68
virtual void loadImpl() override final
Loads the file.
Definition: VGearsBackgroundFile.cpp:34
Ogre::ColourValue Color
Definition: VGearsPaletteFile.h:66
Definition: FF7NameLookup.h:24
Ogre::uint16 uint16
Definition: TypeDefine.h:32
Ogre::String String
Definition: TypeDefine.h:37
Ogre::SharedPtr< BackgroundFile > BackgroundFilePtr
Definition: VGearsBackgroundFile.h:427
Ogre::SharedPtr< PaletteFile > PaletteFilePtr
Definition: VGearsPaletteFile.h:117
Ogre::uint8 uint8
Definition: TypeDefine.h:31
A layer of a background.
Definition: VGearsBackgroundFile.h:241
uint16 height
Layer height.
Definition: VGearsBackgroundFile.h:256
SpriteList sprites
List of sprites in the layer.
Definition: VGearsBackgroundFile.h:282
uint16 unknown_0E[4]
Unknown.
Definition: VGearsBackgroundFile.h:277
uint16 unknown_06
Unknown.
Definition: VGearsBackgroundFile.h:263
bool enabled
Indicates if the layer is used.
Definition: VGearsBackgroundFile.h:246
uint16 unknown_08[3]
Unknown.
Definition: VGearsBackgroundFile.h:270
uint16 width
Layer width.
Definition: VGearsBackgroundFile.h:251
A background page/.
Definition: VGearsBackgroundFile.h:294
Colors colors
Background color list.
Definition: VGearsBackgroundFile.h:322
bool enabled
Indicates if the page is used.
Definition: VGearsBackgroundFile.h:299
uint16 value_size
Definition: VGearsBackgroundFile.h:309
Buffer data
Data buffer.
Definition: VGearsBackgroundFile.h:317
uint16 unknown_02
Unknown data.
Definition: VGearsBackgroundFile.h:304
Data for sprites.
Definition: VGearsBackgroundFile.h:135
uint16 height
Sprite height.
Definition: VGearsBackgroundFile.h:168
uint8 animation_frame
Animation frame of the sprite.
Definition: VGearsBackgroundFile.h:188
uint16 unknown_04[2]
Unused data.
Definition: VGearsBackgroundFile.h:145
bool has_blending[2]
Indicates if the sprite uses color blending.
Definition: VGearsBackgroundFile.h:193
uint16 colour_depth
Color depth.
Definition: VGearsBackgroundFile.h:218
uint16 width
Sprite width.
Definition: VGearsBackgroundFile.h:163
Pixel dst
Pixel destination.
Definition: VGearsBackgroundFile.h:140
uint16 palette_page
Palete page for the sprite.
Definition: VGearsBackgroundFile.h:173
uint16 depth
Sprite depth (Z-index).
Definition: VGearsBackgroundFile.h:178
uint16 data_page
The page with the sprite data.
Definition: VGearsBackgroundFile.h:203
Pixel src2
Pixel alternate source.
Definition: VGearsBackgroundFile.h:158
uint8 animation_id
Animation ID of the sprite.
Definition: VGearsBackgroundFile.h:183
Ogre::Vector3 src_big
Sprite source.
Definition: VGearsBackgroundFile.h:226
uint16 data_page2
Page with alternate sprite data.
Definition: VGearsBackgroundFile.h:211
uint16 blending
The type of blending used.
Definition: VGearsBackgroundFile.h:198
Pixel src
Pixel source.
Definition: VGearsBackgroundFile.h:150
Pixel coordinates.
Definition: TypeDefine.h:76