ScummVM API documentation
vga13h.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 /*
23  * This code is based on original Sfinx source code
24  * Copyright (c) 1994-1997 Janusz B. Wisniewski and L.K. Avalon
25  */
26 
27 #ifndef CGE2_VGA13H_H
28 #define CGE2_VGA13H_H
29 
30 #include "common/serializer.h"
31 #include "common/events.h"
32 #include "graphics/surface.h"
33 #include "cge2/general.h"
34 #include "cge2/bitmap.h"
35 #include "cge2/snail.h"
36 #include "cge2/spare.h"
37 #include "cge2/cge2.h"
38 
39 namespace CGE2 {
40 
41 #define kFadeStep 2
42 #define kVgaColDark 207
43 #define kVgaColDarkGray 225 /*219*/
44 #define kVgaColGray 231
45 #define kVgaColLightGray 237
46 #define kPixelTransp 0xFE
47 #define kNoSeq (-1)
48 #define kNoPtr ((uint8)-1)
49 #define kSprExt ".SPR"
50 #define kPalCount 256
51 #define kPalSize (kPalCount * 3)
52 
53 class FXP {
54  int32 v;
55 public:
56  FXP(void) : v(0) {}
57  FXP (int i0, int f0 = 0) : v((i0 * 256) + ((i0 < 0) ? -f0 : f0)) {}
58  FXP &operator=(const int &x) { v = x << 8; return *this; }
59  FXP operator+(const FXP &x) const { FXP y; y.v = v + x.v; return y; }
60  FXP operator-(const FXP &x) const { FXP y; y.v = v - x.v; return y; }
61  FXP operator*(const FXP &x) const;
62  FXP operator/(const FXP &x) const;
63 
64  friend int &operator+=(int &a, const FXP &b) { return a += b.trunc(); }
65  friend int &operator-=(int &a, const FXP &b) { return a -= b.trunc(); }
66  friend FXP &operator+=(FXP &a, const int &b) { a.v += b << 8; return a; }
67  friend FXP &operator-=(FXP &a, const int &b) { a.v -= b << 8; return a; }
68  friend bool operator==(const FXP &a, const FXP &b) { return a.v == b.v; }
69  friend bool operator!=(const FXP &a, const FXP &b) { return a.v != b.v; }
70  friend bool operator<(const FXP &a, const FXP &b) { return a.v < b.v; }
71  friend bool operator>(const FXP &a, const FXP &b) { return a.v > b.v; }
72  int trunc(void) const { return v >> 8; }
73  int round(void) const { return (v + 0x80) >> 8; }
74  bool empty() const { return v == 0; }
75  void sync(Common::Serializer &s);
76 };
77 
78 class V3D {
79 public:
80  FXP _x, _y, _z;
81  V3D() { }
82  V3D(FXP x, FXP y, FXP z = 0) : _x(x), _y(y), _z(z) { }
83  V3D operator+(const V3D &p) const { return V3D(_x + p._x, _y + p._y, _z + p._z); }
84  V3D operator-(const V3D &p) const { return V3D(_x - p._x, _y - p._y, _z - p._z); }
85  V3D operator*(long n) const { return V3D(_x * n, _y * n, _z * n); }
86  V3D operator/ (long n) const { return V3D(_x / n, _y / n, _z / n); }
87  bool operator==(const V3D &p) const { return _x == p._x && _y == p._y && _z == p._z; }
88  bool operator!=(const V3D &p) const { return _x != p._x || _y != p._y || _z != p._z; }
89  V3D& operator+=(const V3D &x) { return *this = *this + x; }
90  V3D& operator-=(const V3D &x) { return *this = *this - x; }
91  void sync(Common::Serializer &s);
92 };
93 
94 class V2D : public Common::Point {
95  CGE2Engine *_vm;
96 public:
97  V2D &operator=(const V3D &p3) {
98  FXP m = _vm->_eye->_z / (p3._z - _vm->_eye->_z);
99  FXP posx = _vm->_eye->_x + (_vm->_eye->_x - p3._x) * m;
100  x = posx.round();
101  FXP posy = _vm->_eye->_y + (_vm->_eye->_y - p3._y) * m;
102  y = posy.round();
103  return *this;
104  }
105  V2D(CGE2Engine *vm) : _vm(vm) { }
106  V2D(CGE2Engine *vm, const V3D &p3) : _vm(vm) { *this = p3; }
107  V2D(CGE2Engine *vm, int posx, int posy) : _vm(vm), Common::Point(posx, posy) { }
108  bool operator<(const V2D &p) const { return (x < p.x) && (y < p.y); }
109  bool operator<=(const V2D &p) const { return (x <= p.x) && (y <= p.y); }
110  bool operator>(const V2D &p) const { return (x > p.x) && (y > p.y); }
111  bool operator>=(const V2D &p) const { return (x >= p.x) && (y >= p.y); }
112  V2D operator+(const V2D &p) const { return V2D(_vm, x + p.x, y + p.y); }
113  V2D operator-(const V2D &p) const { return V2D(_vm, x - p.x, y - p.y); }
114  bool operator==(const V3D &p) const { V3D tmp(x, y); return tmp._x == p._x && tmp._y == p._y && tmp._z == p._z; }
115  bool operator!=(const V3D &p) const { V3D tmp(x, y); return tmp._x != p._x || tmp._y != p._y || tmp._z == p._z; }
116  bool operator==(const V2D &p) const { return x == p.x && y == p.y; }
117  uint16 area() { return x * y; }
118  bool limited(const V2D &p) {
119  return ((x < p.x) && (y < p.y));
120  }
121  V2D scale (int z) {
122  FXP m = _vm->_eye->_z / (_vm->_eye->_z - z);
123  FXP posx = m * x;
124  FXP posy = m * y;
125  return V2D(_vm, posx.trunc(), posy.trunc());
126  }
127 };
128 
129 struct Seq {
130  uint8 _now;
131  uint8 _next;
132  int8 _dx;
133  int8 _dy;
134  int8 _dz;
135  int _dly;
136 };
137 
138 class SprExt {
139 public:
140  V2D _p0;
141  V2D _p1;
142  BitmapPtr _b0;
143  BitmapPtr _b1;
144  BitmapPtr _shpList;
145  int _location;
146  Seq *_seq;
147  char *_name;
148  CommandHandler::Command *_actions[kActions];
149  SprExt(CGE2Engine *vm);
150 };
151 
152 class Sprite {
153 protected:
154  SprExt *_ext;
155  CGE2Engine *_vm;
156 public:
157  int _ref;
158  signed char _scene;
159  struct Flags {
160  bool _hide; // general visibility switch
161  bool _drag; // sprite is moveable
162  bool _hold; // sprite is held with mouse
163  bool _trim; // Trim flag
164  bool _slav; // slave object
165  bool _kill; // dispose memory after remove
166  bool _xlat; // 2nd way display: xlat table
167  bool _port; // portable
168  bool _kept; // kept in pocket
169  bool _frnt; // stay in front of sprite
170  bool _east; // talk to east (in opposite to west)
171  bool _near; // Near action lock
172  bool _shad; // shadow
173  bool _back; // 'send to background' request
174  bool _zmov; // sprite needs Z-update in queue
175  bool _tran; // transparent (untouchable)
176  } _flags;
177  V2D _pos2D;
178  V3D _pos3D;
179  V2D _siz;
180  uint16 _time;
181  struct { byte _ptr, _cnt; } _actionCtrl[kActions];
182  int _seqPtr;
183  int _seqCnt;
184  int _shpCnt;
185  char _file[kMaxFile];
186  // Following trailer is not saved with the game:
187  Sprite *_prev;
188  Sprite *_next;
189  static byte _constY;
190  static byte _follow;
191  static Seq _stdSeq8[];
192 
193  bool works(Sprite *spr);
194  bool seqTest(int n);
195  inline bool active() {
196  return _ext != nullptr;
197  }
198  Sprite(CGE2Engine *vm);
199  Sprite(CGE2Engine *vm, BitmapPtr shp, int cnt);
200  virtual ~Sprite();
201  BitmapPtr getShp();
202  void setShapeList(BitmapPtr shp, int cnt);
203  void moveShapesHi();
204  void moveShapesLo();
205  int labVal(Action snq, int lab);
206  virtual Sprite *expand();
207  virtual Sprite *contract();
208  void backShow();
209  void setName(char *newName);
210  inline char *name() {
211  return (_ext) ? _ext->_name : nullptr;
212  }
213  void gotoxyz(int x, int y, int z = 0);
214  void gotoxyz();
215  void gotoxyz(V2D pos);
216  void gotoxyz_(V2D pos);
217  void gotoxyz(V3D pos);
218  void center();
219  void show(uint16 pg);
220  void hide(uint16 pg);
221  void show();
222  void hide();
223  BitmapPtr ghost();
224  void step(int nr = -1);
225  Seq *setSeq(Seq *seq);
226  CommandHandler::Command *snList(Action type);
227  virtual void touch(uint16 mask, V2D pos);
228  virtual void tick();
229  virtual void setScene(int c);
230  void clrHide() { if (_ext) _ext->_b0 = nullptr; }
231 
232  void sync(Common::Serializer &s);
233 
234  static void (*notify) ();
235 };
236 
237 class Queue {
238  Sprite *_head;
239  Sprite *_tail;
240 public:
241  Queue(bool show);
242 
243  void append(Sprite *spr);
244  void insert(Sprite *spr, Sprite *nxt);
245  void insert(Sprite *spr);
246  Sprite *remove(Sprite *spr);
247  Sprite *first() {
248  return _head;
249  }
250  Sprite *last() {
251  return _tail;
252  }
253  Sprite *locate(int ref);
254  bool locate(Sprite *spr);
255  void clear() { _head = _tail = nullptr; }
256 };
257 
258 class Vga {
259  CGE2Engine *_vm;
260  bool _setPal;
261  Dac *_oldColors;
262  Dac *_newColors;
263  const char *_msg;
264  const char *_name;
265 
266  void updateColors();
267  void setColors();
268  void waitVR();
269  uint8 closest(Dac *pal, const uint8 colR, const uint8 colG, const uint8 colB);
270 
271 public:
272  uint32 _frmCnt;
273  Queue *_showQ;
274  bool _mono;
275  Graphics::Surface *_page[4];
276  Dac *_sysPal;
277  struct { uint8 _org, _len, _cnt, _dly; } _rot;
278 
279  Vga(CGE2Engine *vm);
280  ~Vga();
281 
282  uint8 *glass(Dac *pal, const uint8 colR, const uint8 colG, const uint8 colB);
283  void getColors(Dac *tab);
284  void setColors(Dac *tab, int lum);
285  void clear(uint8 color);
286  void copyPage(uint16 d, uint16 s);
287  void sunrise(Dac *tab);
288  void sunset();
289  void show();
290  void update();
291  void rotate();
292  uint8 closest(Dac *pal, Dac x);
293 
294  void palToDac(const byte *palData, Dac *tab);
295  void dacToPal(const Dac *tab, byte *palData);
296 };
297 
298 class Speaker: public Sprite {
299  CGE2Engine *_vm;
300 public:
301  Speaker(CGE2Engine *vm);
302 };
303 
304 } // End of namespace CGE2
305 
306 #endif // CGE2_VGA13H_H
Definition: vga13h.h:258
Definition: cge2.h:149
Definition: vga13h.h:129
Definition: surface.h:67
Definition: vga13h.h:159
Definition: snail.h:96
Definition: general.h:36
Definition: vga13h.h:152
Definition: vga13h.h:94
Definition: vga13h.h:78
Definition: vga13h.h:237
Definition: serializer.h:79
Definition: vga13h.h:138
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: bitmap.h:33
Definition: bitmap.h:57
Definition: rect.h:45
Definition: vga13h.h:53
int16 x
Definition: rect.h:46
int16 y
Definition: rect.h:47
Definition: vga13h.h:298