ScummVM API documentation
plane32.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_PLANE32_H
23 #define SCI_GRAPHICS_PLANE32_H
24 
25 #include "common/array.h"
26 #include "common/rect.h"
27 #include "sci/engine/features.h"
28 #include "sci/engine/vm_types.h"
29 #include "sci/graphics/helpers.h"
30 #include "sci/graphics/lists32.h"
31 #include "sci/graphics/screen_item32.h"
32 
33 namespace Sci {
34 enum PlaneType {
35  kPlaneTypeColored = 0,
36  kPlaneTypePicture = 1,
37  kPlaneTypeTransparent = 2,
38  kPlaneTypeOpaque = 3,
39  kPlaneTypeTransparentPicture = 4
40 };
41 
42 enum PlanePictureCodes {
43  // Any value at or below 65531 means the plane is a kPlaneTypePicture
44  kPlanePic = 65531,
45  kPlanePicTransparentPicture = 65532,
46  kPlanePicOpaque = 65533,
47  kPlanePicTransparent = 65534,
48  kPlanePicColored = 65535
49 };
50 
51 #pragma mark -
52 #pragma mark RectList
53 
54 typedef StablePointerArray<Common::Rect, 200> RectListBase;
55 class RectList : public RectListBase {
56 public:
57  void add(const Common::Rect &rect) {
59  }
60 };
61 
62 #pragma mark -
63 #pragma mark DrawList
64 
65 struct DrawItem {
70 
75 
76  inline bool operator<(const DrawItem &other) const {
77  return *screenItem < *other.screenItem;
78  }
79 };
80 
82 class DrawList : public DrawListBase {
83 private:
84  inline static bool sortHelper(const DrawItem *a, const DrawItem *b) {
85  return *a < *b;
86  }
87 public:
88  void add(ScreenItem *screenItem, const Common::Rect &rect);
89  inline void sort() {
90  pack();
91  Common::sort(begin(), end(), sortHelper);
92  }
93 };
94 
95 class PlaneList;
96 
97 #pragma mark -
98 #pragma mark Plane
99 
103 class Plane {
104 private:
109  static uint16 _nextObjectId;
110 
115  static uint32 _nextCreationId;
116 
121  uint32 _creationId;
122 
128  GuiResourceId _pictureId;
129 
134  bool _mirrored;
135 
141  bool _pictureChanged;
142 
148  void convertGameRectToPlaneRect();
149 
153  void setType();
154 
155 public:
159  PlaneType _type;
160 
165  byte _back;
166 
173 
180 
185  int16 _priority;
186 
195 
205  int _created, _updated, _deleted, _moved;
206 
213 
220 
225 
231 
236 
237 public:
241  static void init();
242 
243  // In SSCI this constructor signature did not accept a picture ID, but some
244  // calls to construct planes with this signature immediately set the picture
245  // ID and then called setType again, so it made more sense to just make the
246  // picture ID a parameter instead.
247  Plane(const Common::Rect &gameRect, PlanePictureCodes pictureId = kPlanePicColored);
248 
249  Plane(const reg_t object);
250 
251  Plane(const Plane &other);
252 
253  void operator=(const Plane &other);
254 
255  inline bool operator<(const Plane &other) const {
256  if (_priority < other._priority) {
257  return true;
258  }
259 
260  if (_priority == other._priority) {
261  // This is different than SSCI; see ScreenItem::operator< for an
262  // explanation
263  return _creationId < other._creationId;
264  }
265 
266  return false;
267  }
268 
272  inline void clipScreenRect(const Common::Rect &screenRect) {
273  // LSL6 hires creates planes with invalid rects; SSCI does not care
274  // about this, but `Common::Rect::clip` does, so we need to check
275  // whether or not the rect is actually valid before clipping and only
276  // clip valid rects
277  if (_screenRect.isValidRect() && _screenRect.intersects(screenRect)) {
278  _screenRect.clip(screenRect);
279  } else {
280  _screenRect.left = 0;
281  _screenRect.top = 0;
282  _screenRect.right = 0;
283  _screenRect.bottom = 0;
284  }
285  }
286 
287  void printDebugInfo(Console *con) const;
288 
297  void sync(const Plane *other, const Common::Rect &screenRect);
298 
304  void update(const reg_t object);
305 
310  void scrollScreenItems(const int16 deltaX, const int16 deltaY, const bool scrollPics);
311 
315  inline bool isDefaultPlane() {
316  return _object.isNumber() && _object.getOffset() == (uint32)g_sci->_features->detectPlaneIdBase();
317  }
318 
319 #pragma mark -
320 #pragma mark Plane - Pic
321 private:
328  inline void addPicInternal(const GuiResourceId pictureId, const Common::Point *position, const bool mirrorX);
329 
334  void deletePic(const GuiResourceId pictureId);
335 
340  void deleteAllPics();
341 
342 public:
348  GuiResourceId addPic(const GuiResourceId pictureId, const Common::Point &position, const bool mirrorX, const bool deleteDuplicate = true);
349 
354  void changePic();
355 
361  void deletePic(const GuiResourceId oldPictureId, const GuiResourceId newPictureId);
362 
363 #pragma mark -
364 #pragma mark Plane - Rendering
365 private:
370  void breakDrawListByPlanes(DrawList &drawList, const PlaneList &planeList) const;
371 
376  void breakEraseListByPlanes(RectList &eraseList, const PlaneList &planeList) const;
377 
384  void mergeToDrawList(const DrawList::size_type index, const Common::Rect &rect, DrawList &drawList) const;
385 
390  void mergeToRectList(const Common::Rect &rect, RectList &eraseList) const;
391 
392 public:
399  void calcLists(Plane &visiblePlane, const PlaneList &planeList, DrawList &drawList, RectList &eraseList);
400 
408  void decrementScreenItemArrayCounts(Plane *visiblePlane, const bool forceUpdate);
409 
428  void filterDownEraseRects(DrawList &drawList, RectList &eraseList, RectList &higherEraseList) const;
429 
444  void filterUpEraseRects(DrawList &drawList, const RectList &lowerEraseList) const;
445 
460  void filterUpDrawRects(DrawList &drawList, const DrawList &lowerDrawList) const;
461 
466  void redrawAll(Plane *visiblePlane, const PlaneList &planeList, DrawList &drawList, RectList &eraseList);
467 
472  void remapMarkRedraw();
473 };
474 
475 #pragma mark -
476 #pragma mark PlaneList
477 
479 class PlaneList : public PlaneListBase {
480 private:
481  inline static bool sortHelper(const Plane *a, const Plane *b) {
482  return *a < *b;
483  }
484 
486 
487 public:
488  // A method for finding the index of a plane inside a PlaneList is used
489  // because entries in the main plane list and visible plane list of
490  // GfxFrameout are synchronised by index
491  int findIndexByObject(const reg_t object) const;
492  Plane *findByObject(const reg_t object) const;
493 
497  int16 getTopPlanePriority() const;
498 
503  int16 getTopSciPlanePriority() const;
504 
505  void add(Plane *plane);
506  void clear();
507  iterator erase(iterator it);
508  void erase(Plane *plane);
509  inline void sort() {
510  Common::sort(begin(), end(), sortHelper);
511  }
512  void remove_at(size_type index);
513 };
514 
515 } // End of namespace Sci
516 
517 #endif // SCI_GRAPHICS_PLANE32_H
size_type pack()
Definition: lists32.h:176
void clipScreenRect(const Common::Rect &screenRect)
Definition: plane32.h:272
Definition: array.h:52
Definition: screen_item32.h:359
int16 right
Definition: rect.h:146
SciEngine * g_sci
Definition: plane32.h:103
T * iterator
Definition: array.h:54
Definition: rect.h:144
byte _back
Definition: plane32.h:165
Common::Rect _screenRect
Definition: plane32.h:230
void add(T *item)
Definition: lists32.h:111
ScreenItem * screenItem
Definition: plane32.h:69
int _redrawAllCount
Definition: plane32.h:194
void push_back(const T &element)
Definition: array.h:180
int16 _priority
Definition: plane32.h:185
int _priorityChanged
Definition: plane32.h:172
Common::Rect rect
Definition: plane32.h:74
Common::Rect _gameRect
Definition: plane32.h:224
Definition: lists32.h:215
Definition: rect.h:45
Definition: console.h:28
int16 left
Definition: rect.h:145
Common::Point _vanishingPoint
Definition: plane32.h:212
bool intersects(const Rect &r) const
Definition: rect.h:255
bool isValidRect() const
Definition: rect.h:337
ScreenItemList _screenItemList
Definition: plane32.h:235
Definition: plane32.h:65
uint size_type
Definition: array.h:59
Definition: plane32.h:479
void clip(const Rect &r)
Definition: rect.h:300
Definition: screen_item32.h:53
Definition: plane32.h:82
Definition: plane32.h:55
void sort(T first, T last, StrictWeakOrdering comp)
Definition: algorithm.h:349
Definition: vm_types.h:39
void erase(T *item)
Definition: lists32.h:144
bool isDefaultPlane()
Definition: plane32.h:315
Definition: console.h:36
PlaneType _type
Definition: plane32.h:159
Common::Rect _planeRect
Definition: plane32.h:219
reg_t _object
Definition: plane32.h:179
int _created
Definition: plane32.h:205