ScummVM API documentation
frameout.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 SCI_GRAPHICS_FRAMEOUT_H
23 #define SCI_GRAPHICS_FRAMEOUT_H
24 
25 #include "engines/util.h" // for initGraphics
26 #include "sci/event.h"
27 #include "sci/graphics/plane32.h"
28 #include "sci/graphics/screen_item32.h"
29 
30 namespace Sci {
31 typedef Common::Array<DrawList> ScreenItemListList;
32 typedef Common::Array<RectList> EraseListList;
33 
34 class GfxCursor32;
35 class GfxTransitions32;
36 struct PlaneShowStyle;
37 
42 class GfxFrameout {
43  friend class GfxTransitions32;
44 
45 public:
46  GfxFrameout(SegManager *segMan, GfxPalette32 *palette, GfxTransitions32 *transitions, GfxCursor32 *cursor);
47  ~GfxFrameout();
48 
49  void clear();
50  void run();
51 
56  inline bool isHiRes() const { return _isHiRes; }
57 
61  inline int16 getScriptWidth() const { return _scriptWidth; }
62 
66  inline int16 getScriptHeight() const { return _scriptHeight; }
67 
71  inline int16 getScreenWidth() const { return _currentBuffer.w; }
72 
76  inline int16 getScreenHeight() const { return _currentBuffer.h; }
77 
78 private:
79  GfxCursor32 *_cursor;
80  GfxPalette32 *_palette;
81  GfxTransitions32 *_transitions;
82  SegManager *_segMan;
83 
87  bool _isHiRes;
88 
93  int16 _scriptWidth, _scriptHeight;
94 
99  bool detectHiRes() const;
100 
101 #pragma mark -
102 #pragma mark Screen items
103 public:
107  void addScreenItem(ScreenItem &screenItem) const;
108 
112  void updateScreenItem(ScreenItem &screenItem) const;
113 
117  void deleteScreenItem(ScreenItem &screenItem);
118 
122  void deleteScreenItem(ScreenItem &screenItem, Plane &plane);
123 
127  void deleteScreenItem(ScreenItem &screenItem, const reg_t plane);
128 
129  void kernelAddScreenItem(const reg_t object);
130  void kernelUpdateScreenItem(const reg_t object);
131  void kernelDeleteScreenItem(const reg_t object);
132  bool kernelSetNowSeen(const reg_t screenItemObject) const;
133  int16 kernelObjectIntersect(const reg_t object1, const reg_t object2) const;
134 
135 private:
136  void remapMarkRedraw();
137  bool getNowSeenRect(const reg_t screenItemObject, Common::Rect &result) const;
138 
139 #pragma mark -
140 #pragma mark Planes
141 public:
149  void addPlane(Plane *plane);
150 
157  void deletePlane(Plane &plane);
158 
163 
164  const PlaneList &getPlanes() const {
165  return _planes;
166  }
167  const PlaneList &getVisiblePlanes() const {
168  return _visiblePlanes;
169  }
170  void kernelAddPlane(const reg_t object);
171  void kernelUpdatePlane(const reg_t object);
172  void kernelDeletePlane(const reg_t object);
173  void kernelMovePlaneItems(const reg_t object, const int16 deltaX, const int16 deltaY, const bool scrollPics);
174  int16 kernelGetHighPlanePri();
175 
176 private:
183  PlaneList _planes;
184 
188  void updatePlane(Plane &plane);
189 
190 #pragma mark -
191 #pragma mark Pics
192 public:
193  void kernelAddPicAt(const reg_t planeObject, const GuiResourceId pictureId, const int16 pictureX, const int16 pictureY, const bool mirrorX, const bool deleteDuplicate);
194 
195 #pragma mark -
196 #pragma mark Rendering
197 public:
208  void updateScreen(const int delta = 0);
209 
213  void setPixelFormat(const Graphics::PixelFormat &format) const {
214  initGraphics(_currentBuffer.w, _currentBuffer.h, &format);
215  }
216 
221 
228 
229  inline const Buffer &getCurrentBuffer() const {
230  return _currentBuffer;
231  }
232 
233  void kernelFrameOut(const bool showBits);
234 
238  void throttle();
239 
245  void frameOut(const bool shouldShowBits, const Common::Rect &eraseRect = Common::Rect());
246 
250  void palMorphFrameOut(const int8 *styleRanges, PlaneShowStyle *showStyle);
251 
256  void directFrameOut(const Common::Rect &showRect);
257 
264  void redrawGameScreen(const Common::Rect &skipRect) const;
265 
266 #ifdef USE_RGB_COLOR
267 
270  void resetHardware();
271 #endif
272 
277  void alterVmap(const Palette &palette1, const Palette &palette2, const int8 style, const int8 *const styleRanges);
278 
279  // This function is used within ScreenItem subsystem and assigned to various
280  // booleanish fields that seem to represent the state of the screen item
281  // (created, updated, deleted). In GK1/DOS, Phant1/m68k, SQ6/DOS, SQ6/Win,
282  // and Phant2/Win, this function simply returns 1. If you know of any
283  // game/environment where this function returns some value other than 1, or
284  // if you used to work at Sierra and can explain why this is a thing (and if
285  // anyone needs to care about it), please open a ticket!!
286  inline int getScreenCount() const {
287  return 1;
288  };
289 
293  void shakeScreen(const int16 numShakes, const ShakeDirection direction);
294 
295  Plane *getTopVisiblePlane();
296 
297 private:
301  uint32 _lastScreenUpdateTick;
302 
306  uint8 _throttleState;
307 
314  Buffer _currentBuffer;
315 
320  bool _remapOccurred;
321 
329  RectList _showList;
330 
335  ScreenItemListList _screenItemLists;
336 
343  int _overdrawThreshold;
344 
352  PlaneList _visiblePlanes;
353 
361  void calcLists(ScreenItemListList &drawLists, EraseListList &eraseLists, const Common::Rect &eraseRect = Common::Rect());
362 
369  void drawEraseList(const RectList &eraseList, const Plane &plane);
370 
375  void drawScreenItemList(const DrawList &screenItemList);
376 
382  void mergeToShowList(const Common::Rect &drawRect, RectList &showList, const int overdrawThreshold);
383 
388  void showBits();
389 
395  inline bool validZeroStyle(const uint8 style, const int i) const {
396  if (style != 0) {
397  return false;
398  }
399 
400  // TODO: Cannot check Shivers or MGDX until those executables can be
401  // unwrapped
402  switch (g_sci->getGameId()) {
403  case GID_KQ7:
404  case GID_PHANTASMAGORIA:
405  case GID_SQ6:
406  return (i > 71 && i < 104);
407  break;
408  default:
409  return true;
410  }
411  }
412 
413 #pragma mark -
414 #pragma mark Mouse cursor
415 public:
416  reg_t kernelIsOnMe(const reg_t object, const Common::Point &position, const bool checkPixel) const;
417 
418 private:
419  void updateMousePositionForRendering() const {
420  // In SSCI, mouse events were received via hardware interrupt, so the
421  // mouse cursor would always get updated immediately when the user moved
422  // the mouse. ScummVM must poll for mouse events from the backend
423  // instead, so we poll just before rendering so that the latest mouse
424  // position is rendered instead of whatever position it was at the last
425  // time kGetEvent was called. Without this, the mouse appears stuck
426  // during loops that do not make calls to kGetEvent, like transitions.
427  g_sci->getEventManager()->getSciEvent(kSciEventPeek);
428  }
429 
434  bool isOnMe(const ScreenItem &screenItem, const Plane &plane, const Common::Point &position, const bool checkPixel) const;
435 
436 #pragma mark -
437 #pragma mark Debugging
438 public:
439  void printPlaneList(Console *con) const;
440  void printVisiblePlaneList(Console *con) const;
441  void printPlaneListInternal(Console *con, const PlaneList &planeList) const;
442  void printPlaneItemList(Console *con, const reg_t planeObject) const;
443  void printVisiblePlaneItemList(Console *con, const reg_t planeObject) const;
444  void printPlaneItemListInternal(Console *con, const ScreenItemList &screenItemList) const;
445 };
446 
447 } // End of namespace Sci
448 
449 #endif // SCI_GRAPHICS_FRAMEOUT_H
void updateScreenItem(ScreenItem &screenItem) const
int16 getScriptWidth() const
Definition: frameout.h:61
Definition: frameout.h:42
bool isHiRes() const
Definition: frameout.h:56
void directFrameOut(const Common::Rect &showRect)
void redrawGameScreen(const Common::Rect &skipRect) const
Definition: pixelformat.h:138
Definition: screen_item32.h:359
void addScreenItem(ScreenItem &screenItem) const
int16 getScriptHeight() const
Definition: frameout.h:66
SciEngine * g_sci
Definition: plane32.h:103
Definition: rect.h:144
void addPlane(Plane *plane)
int16 getScreenWidth() const
Definition: frameout.h:71
void updateScreen(const int delta=0)
void shakeScreen(const int16 numShakes, const ShakeDirection direction)
void deleteScreenItem(ScreenItem &screenItem)
Definition: palette32.h:234
void frameOut(const bool shouldShowBits, const Common::Rect &eraseRect=Common::Rect())
Definition: rect.h:45
Definition: console.h:28
int16 getScreenHeight() const
Definition: frameout.h:76
Definition: seg_manager.h:48
void deletePlane(Plane &plane)
Definition: transitions32.h:215
void initGraphics(int width, int height)
void palMorphFrameOut(const int8 *styleRanges, PlaneShowStyle *showStyle)
Definition: transitions32.h:53
Definition: display_client.h:113
bool _throttleKernelFrameOut
Definition: frameout.h:220
Definition: plane32.h:479
Definition: screen_item32.h:53
Definition: plane32.h:82
bool _palMorphIsOn
Definition: frameout.h:227
Definition: helpers.h:247
Definition: plane32.h:55
void alterVmap(const Palette &palette1, const Palette &palette2, const int8 style, const int8 *const styleRanges)
void deletePlanesForMacRestore()
Definition: vm_types.h:39
Definition: console.h:36
void setPixelFormat(const Graphics::PixelFormat &format) const
Definition: frameout.h:213
Definition: cursor32.h:34