ScummVM API documentation
screen.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef SWORD1_SCREEN_H
23 #define SWORD1_SCREEN_H
24 
25 #include "sword1/sworddefs.h"
26 #include "common/mutex.h"
27 
28 class OSystem;
29 
30 namespace Sword1 {
31 
32 #define MAX_FORE 20
33 #define MAX_BACK 20
34 #define MAX_SORT 20
35 
36 struct SortSpr {
37  int32 id, y;
38 };
39 
40 struct RoomDef {
41  int totalLayers;
42  int sizeX;
43  int sizeY;
44  int gridWidth; //number of 16*16 grid blocks across - including off screen edges.
45  uint32 layers[4];
46  uint32 grids[3];
47  uint32 palettes[2];
48  uint32 parallax[2];
49 };
50 
51 struct PSXDataCache { // Cache for PSX screen, to avoid decompressing background at every screen update
52  uint8 *decodedBackground;
53  uint8 *extPlxCache; // If this screen requires an external parallax, save it here
54 };
55 
56 #define SCRNGRID_X 16
57 #define SCRNGRID_Y 8
58 #define SHRINK_BUFFER_SIZE 50000
59 #define RLE_BUFFER_SIZE 50000
60 
61 #define FLASH_RED 0
62 #define FLASH_BLUE 1
63 #define BORDER_YELLOW 2
64 #define BORDER_GREEN 3
65 #define BORDER_PURPLE 4
66 #define BORDER_BLACK 5
67 #define TEXT_WHITE 6
68 
69 class SwordEngine;
70 class ResMan;
71 class ObjectMan;
72 class Text; // Text objects use sprites that are created internally at run-time
73  // the buffer belongs to Text, so we need a reference here.
74 
75 class Screen {
76  friend class Text;
77 public:
78  Screen(OSystem *system, SwordEngine *vm, ResMan *pResMan, ObjectMan *pObjMan);
79  ~Screen();
80  void clearScreen();
81  void useTextManager(Text *pTextMan);
82  void draw();
83  void initFadePaletteServer();
84 
85  void quitScreen();
86  void newScreen(uint32 screen);
87 
88  void setScrolling(int16 offsetX, int16 offsetY);
89  void addToGraphicList(uint8 listId, uint32 objId);
90 
91  void startFadePaletteDown(int speed);
92  void startFadePaletteUp(int speed);
93  void fadePalette();
94  void fnSetPalette(uint8 start, uint16 length, uint32 id);
95  void fnSetFadeTargetPalette(uint8 start, uint16 length, uint32 id, int singleColor = -1);
96  int16 stillFading();
97  void fullRefresh(bool soft = false);
98  void setNextFadeOutToBlack();
99 
100  bool showScrollFrame();
101  void updateScreen();
102  void showFrame(uint16 x, uint16 y, uint32 resId, uint32 frameNo, const byte *fadeMask = nullptr, int8 fadeStatus = 0);
103 
104  void fnSetParallax(uint32 screen, uint32 resId);
105  void fnFlash(uint8 color);
106 
107  static void decompressHIF(uint8 *src, uint8 *dest);
108 
109  void printDebugLine(uint8 *ascii, uint8 first, int x, int y);
110 
111  // Functions used by the router debug visualization routines
112  void plotLine(int32 x1, int32 y1, int32 x2, int32 y2, uint8 color);
113  void plotPoint(int32 x, int32 y, uint8 color);
114  void bresenhamLine(int32 x1, int32 y1, int32 x2, int32 y2, uint8 color);
115 
116  Common::Mutex _screenAccessMutex; // To coordinate actions between the main thread and the palette fade thread
117 
118 private:
119  // The original values are 6-bit RGB numbers, so they have to be shifted,
120  // except for white, which for some reason has to stay unshifted in order
121  // to work correctly.
122  const uint8 _white[3] = { 63, 63, 63 };
123  const uint8 _red[3] = { 63 << 2, 0 << 2, 0 << 2 };
124  const uint8 _blue[3] = { 0 << 2, 0 << 2, 63 << 2 };
125  const uint8 _yellow[3] = { 63 << 2, 63 << 2, 0 << 2 };
126  const uint8 _green[3] = { 0 << 2, 63 << 2, 0 << 2 };
127  const uint8 _purple[3] = { 32 << 2, 0 << 2, 32 << 2 };
128  const uint8 _black[3] = { 0 << 2, 0 << 2, 0 << 2 };
129  //const uint8 _grey[3] = { 32 << 2, 32 << 2, 32 << 2 };
130 
131  struct PaletteFadeInfo {
132  int16 paletteStatus;
133  int16 paletteIndex;
134  int16 paletteCount;
135  int16 fadeCount;
136  uint8 srcPalette[256 * 3];
137  uint8 dstPalette[256 * 3];
138  };
139 
140  PaletteFadeInfo _paletteFadeInfo;
141 
142  void verticalMask(uint16 x, uint16 y, uint16 bWidth, uint16 bHeight);
143  void blitBlockClear(uint16 x, uint16 y, uint8 *data);
144  void renderParallax(uint8 *data);
145  void processImage(uint32 id);
146  void spriteClipAndSet(uint16 *pSprX, uint16 *pSprY, uint16 *sprWidth, uint16 *sprHeight, uint16 *incr);
147  void drawSprite(uint8 *sprData, uint16 sprX, uint16 sprY, uint16 sprWidth, uint16 sprHeight, uint16 sprPitch);
148  void drawPsxHalfShrinkedSprite(uint8 *sprData, uint16 sprX, uint16 sprY, uint16 sprWidth, uint16 sprHeight, uint16 sprPitch);
149  void drawPsxFullShrinkedSprite(uint8 *sprData, uint16 sprX, uint16 sprY, uint16 sprWidth, uint16 sprHeight, uint16 sprPitch);
150  uint8 *psxBackgroundToIndexed(uint8 *psxBackground, uint32 bakXres, uint32 bakYres);
151  uint8 *psxShrinkedBackgroundToIndexed(uint8 *psxBackground, uint32 bakXres, uint32 bakYres);
152  void fetchPsxParallaxSize(uint8 *psxParallax, uint16 *paraSizeX, uint16 *paraSizeY);
153  void drawPsxParallax(uint8 *psxParallax, uint16 paraScrlX, uint16 scrnScrlX, uint16 scrnWidth);
154  void decompressRLE7(uint8 *src, uint32 compSize, uint8 *dest);
155  void decompressRLE0(uint8 *src, uint32 compSize, uint8 *dest);
156  void decompressTony(uint8 *src, uint32 compSize, uint8 *dest);
157  void fastShrink(uint8 *src, uint32 width, uint32 height, uint32 scale, uint8 *dest);
158 
159  void flushPsxCache();
160 
161  OSystem *_system;
162  SwordEngine *_vm;
163  ResMan *_resMan;
164  ObjectMan *_objMan;
165  Text *_textMan;
166 
167  uint16 _currentScreen;
168  uint8 *_screenBuf;
169  uint8 *_screenGrid;
170  uint16 *_layerGrid[4];
171  uint8 *_layerBlocks[4];
172  uint8 *_parallax[2];
173  uint8 _rleBuffer[RLE_BUFFER_SIZE];
174  uint8 _shrinkBuffer[SHRINK_BUFFER_SIZE];
175  bool _fullRefresh;
176  bool _updatePalette;
177  uint16 _oldScrollX, _oldScrollY; // for drawing additional frames
178 
179  PSXDataCache _psxCache; // Cache used for PSX backgrounds
180 
181  uint32 _foreList[MAX_FORE];
182  uint32 _backList[MAX_BACK];
183  SortSpr _sortList[MAX_SORT];
184  uint8 _foreLength, _backLength, _sortLength;
185  uint16 _scrnSizeX, _scrnSizeY, _gridSizeX, _gridSizeY;
186 
187  static RoomDef _roomDefTable[TOTAL_ROOMS]; // from ROOMS.C (not const, see fnSetParallax)
188 
189  uint8 _targetPalette[256 * 3];
190  uint8 _currentPalette[256 * 3]; // for fading
191  uint8 _zeroPalette[256 * 3];
192 
193  bool _forceNextFadeOutToBlack = false;
194 };
195 
196 } // End of namespace Sword1
197 
198 #endif //BSSCREEN_H
Definition: sword1.h:104
Definition: text.h:48
Definition: resman.h:65
Definition: screen.h:75
Definition: animation.h:38
Definition: screen.h:51
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: screen.h:36
Definition: mutex.h:67
Definition: objectman.h:33
Definition: system.h:161
Definition: screen.h:40