ScummVM API documentation
struct.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 WATCHMAKER_STRUCT_H
23 #define WATCHMAKER_STRUCT_H
24 
25 #include "watchmaker/t3d.h"
26 #include "watchmaker/types.h"
27 #include "watchmaker/sysdef.h"
28 #include "common/stream.h"
29 #include "watchmaker/message.h"
30 
31 namespace Watchmaker {
32 
34 public:
35  virtual ~SerializableAsset() {}
36  virtual void loadFromStream(Common::SeekableReadStream &stream) = 0;
37 };
38 
39 template<uint32 strSize>
41  char str[strSize] = {};
42 public:
43  char *c_str() {
44  return str;
45  }
46  void loadFromStream(Common::SeekableReadStream &stream) override {
47  stream.read(str, strSize);
48  };
49 };
50 
51 template<typename T>
52 void loadArrayFromStream(Common::SeekableReadStream &stream, T array[], uint32 size) {
53  for (uint32 i = 0; i < size; i++) {
54  array[i].loadFromStream(stream);
55  }
56 }
57 
58 template<>
59 inline void loadArrayFromStream(Common::SeekableReadStream &stream, uint8 array[], uint32 size) {
60  for (uint32 i = 0; i < size; i++) {
61  array[i] = stream.readByte();
62  }
63 }
64 
65 template<>
66 inline void loadArrayFromStream(Common::SeekableReadStream &stream, uint16 array[], uint32 size) {
67  for (uint32 i = 0; i < size; i++) {
68  array[i] = stream.readUint16LE();
69  }
70 }
71 
72 template<>
73 inline void loadArrayFromStream(Common::SeekableReadStream &stream, int32 array[], uint32 size) {
74  for (uint32 i = 0; i < size; i++) {
75  array[i] = stream.readSint32LE();
76  }
77 }
78 
79 template<typename T, uint32 arraySize>
81  T _array[arraySize]; // Can't do initializer here, as GCC 4.8 crashes in that case
82 public:
83  SerializableArray() : _array{} {}
84  T &operator[](int index) {
85  return _array[index];
86  };
87  T *rawArray() {
88  return _array;
89  }
90  uint32 size() const {
91  return arraySize;
92  }
93  void loadFromStream(Common::SeekableReadStream &stream) override {
94  loadArrayFromStream(stream, _array, arraySize);
95  }
96 };
97 
98 template<typename T>
100  T *_array = nullptr;
101  uint32 _size = 0;
102 public:
104  SerializableDynamicArray(uint32 size) : _size(size) {
105  _array = new T[size] {};
106  }
108  delete[] _array;
109  }
110  uint32 size() const {
111  return _size;
112  }
113  T &operator[](int index) {
114  return _array[index];
115  };
116  void loadFromStream(Common::SeekableReadStream &stream) override {
117  loadArrayFromStream(stream, _array, _size);
118  }
119 };
120 
121 struct SRoom : public SerializableAsset {
122  uint8 name[T3D_NAMELEN]; // nome della stanza
123  char desc[64]; // descrizione della stanza
124  uint16 flags; // DONE | EXTRA
125  uint16 env; // EAX preset environment number
126  uint16 music; // Music for this room
127  SerializableArray<uint16, MAX_OBJS_IN_ROOM> objects; // oggetti nella stanza rivelabili dal mouse
128  SerializableArray<uint16, MAX_SOUNDS_IN_ROOM> sounds; // sounds per room
129  SerializableArray<uint16, MAX_ANIMS_IN_ROOM> anims; // animazioni per room
130  SerializableArray<uint16, MAX_ACTIONS_IN_ROOM> actions; // azioni per room
131 
132  void loadFromStream(Common::SeekableReadStream &stream) override {
133  stream.read(name, T3D_NAMELEN);
134  stream.read(desc, 64);
135  flags = stream.readUint16LE();
136  env = stream.readUint16LE();
137  music = stream.readUint16LE();
138  objects.loadFromStream(stream);
139  sounds.loadFromStream(stream);
140  anims.loadFromStream(stream);
141  actions.loadFromStream(stream);
142  }
143 };
144 
145 struct SObject : public SerializableAsset {
146  uint16 name; // frase nome
147  SerializableArray<uint16, MAX_PLAYERS> examine; // frase esamina
148  SerializableArray<uint16, MAX_PLAYERS> action; // frase azione
150  SerializableArray<uint16, MAX_PLAYERS> anim; // animazione su action
151  SerializableArray<uint16, MAX_PLAYERS> anim2; // animazione aggiunta (su examine)
152  uint8 room; // Stanza in cui si trova l'oggetto
153  uint8 goroom; // Se direzione num stanza - se persona num dialog
154  uint8 ninv; // ptr inventario
155  uint16 flags; // EXAMINE | EXAMINEACT | ROOM | PERSON | TAKE | USEWITH | EXTRA | EXTRA2 | DONE | ON | HIDE
156  uint8 pos; // 0 se no position
157  SerializableArray<SerializableArray<uint8, T3D_NAMELEN>, MAX_OBJ_MESHLINKS> meshlink_int = {};// link -> oggetto mesh (nome mesh) -> da rimuovere
158  uint8 *meshlink[MAX_OBJ_MESHLINKS];
159 
160  void loadFromStream(Common::SeekableReadStream &stream) override {
161  name = stream.readUint16LE();
162  examine.loadFromStream(stream);
163  action.loadFromStream(stream);
164  text.loadFromStream(stream);
165  anim.loadFromStream(stream);
166  anim2.loadFromStream(stream);
167  room = stream.readByte();
168  goroom = stream.readByte();
169  ninv = stream.readByte();
170  flags = stream.readUint16LE();
171  pos = stream.readByte();
172  meshlink_int.loadFromStream(stream);
173  // HACK:
174  for (int i = 0; i < MAX_OBJ_MESHLINKS; i++) {
175  meshlink[i] = meshlink_int.rawArray()[i].rawArray();
176  }
177  }
178 };
179 
180 struct SInvObject : public SerializableAsset {
181  uint16 name; // Nome Oggetto in inventario
182  SerializableArray<uint16, MAX_PLAYERS> examine; // Frase se si esamina
183  SerializableArray<uint16, MAX_PLAYERS> action; // Frase se si opera
184  uint16 flags; // USEWITH | EXTRA | EXTRA2 | DONE | ON | WITHI | WITHO
186  uint16 uwobj; // usewithobj automatico
187  SerializableArray<uint16, MAX_PLAYERS> anim; // animazione su usewith
188  SerializableArray<uint16, MAX_PLAYERS> anim2; // animazione su usewith
189  SerializableArray<uint8, T3D_NAMELEN> meshlink; // link -> mesh
190 
191  void loadFromStream(Common::SeekableReadStream &stream) override {
192  name = stream.readUint16LE();
193  examine.loadFromStream(stream);
194  action.loadFromStream(stream);
195  flags = stream.readUint16LE();
196  text.loadFromStream(stream);
197  uwobj = stream.readUint16LE();
198  anim.loadFromStream(stream);
199  anim2.loadFromStream(stream);
200  meshlink.loadFromStream(stream);
201  }
202 };
203 
204 struct SAtFrame : public SerializableAsset {
205  uint8 type = 0; // ATFTEXT, ATFSND, ATFEVENT
206  uint8 anim = 0; // solo se subanim e' attiva
207  int16 nframe = 0; // 10000 se attraversa portale
208  uint16 index = 0;
209 
210  void loadFromStream(Common::SeekableReadStream &stream) override {
211  type = stream.readByte();
212  anim = stream.readByte();
213  nframe = stream.readSint16LE();
214  index = stream.readUint16LE();
215  }
216 };
217 
218 struct SAnim : public SerializableAsset {
219  SerializableArray<SerializableArray<uint8, T3D_NAMELEN>, MAX_SUBANIMS> meshlink; // link -> anim mesh (nome mesh) -> da rimuovere
220  SerializableArray<SerializableArray<uint8, T3D_NAMELEN>, MAX_SUBANIMS> name; // nome animazione
221  SerializableArray<uint8, T3D_NAMELEN> RoomName; // nome stanza destinazione
223  uint32 flags;
224  int16 active; // indece tra le animazioni attive
225  int32 obj; // obj a cui e' collegato
226  uint8 pos; // posizione
227  uint8 cam; // camera per l'azione
228 
229  void loadFromStream(Common::SeekableReadStream &stream) override {
230  meshlink.loadFromStream(stream);
231  name.loadFromStream(stream);
232  RoomName.loadFromStream(stream);
233  atframe.loadFromStream(stream);
234  flags = stream.readUint32LE();
235  active = stream.readSint16LE();
236  obj = stream.readSint32LE();
237  pos = stream.readByte();
238  cam = stream.readByte();
239  }
240 };
241 
242 struct SSound : public SerializableAsset {
243  char name[T3D_NAMELEN];
244  uint8 flags;
245  SerializableArray<SerializableArray<uint8, T3D_NAMELEN>, MAX_SOUND_MESHLINKS> meshlink;
246  uint32 ConeInside, ConeOutside;
247  int32 ConeOutsideVolume;
248  t3dF32 MinDist, MaxDist;
249  int32 Angle;
250 
251  void loadFromStream(Common::SeekableReadStream &stream) override {
252  stream.read(name, T3D_NAMELEN);
253  flags = stream.readByte();
254  meshlink.loadFromStream(stream);
255  ConeInside = stream.readUint32LE();
256  ConeOutside = stream.readUint32LE();
257  ConeOutsideVolume = stream.readSint32LE();
258  MinDist = stream.readFloatLE();
259  MaxDist = stream.readFloatLE();
260  Angle = stream.readSint32LE();
261  }
262 };
263 
264 struct SMusic : public SerializableAsset {
265  char name[MAX_SUB_MUSICS][T3D_NAMELEN];
267 
268  void loadFromStream(Common::SeekableReadStream &stream) override {
269  for (int i = 0; i < MAX_SUB_MUSICS; i++) {
270  stream.read(name[i], T3D_NAMELEN);
271  }
272  vol.loadFromStream(stream);
273  }
274 };
275 
276 struct SDlgMenu : public SerializableAsset { // struttura di appoggio per riempiere i DlgItem
277  uint8 parent, on;
278  uint16 titolo; // indice della sentence di titolo
279 
280  void loadFromStream(Common::SeekableReadStream &stream) override {
281  parent = stream.readByte();
282  on = stream.readByte();
283  titolo = stream.readUint16LE();
284  }
285 };
286 
288  uint8 com; // comando
289  uint16 param1; // parametro 1
290  uint16 param2; // parametro 2
291 
292  void loadFromStream(Common::SeekableReadStream &stream) override {
293  com = stream.readByte();
294  param1 = stream.readUint16LE();
295  param2 = stream.readUint16LE();
296  }
297 };
298 
299 struct SDlgItem : public SerializableAsset {
300  SerializableArray<SerializableArray<SItemCommand, MAX_IC_PER_DLG_ITEM>, MAX_PLAYERS> item; // lista di comandi per personaggio
301 
302  void loadFromStream(Common::SeekableReadStream &stream) override {
303  item.loadFromStream(stream);
304  }
305 };
306 
307 struct SDialog : public SerializableAsset {
308  uint16 flags; // flags del dialogo - per ora non serve
309  int32 obj; // Personaggio con cui fa il dialogo
310  SerializableArray<int32, MAX_ALTERNATES> AltPosSco; // Scostamento posizione alternate
311  SerializableArray<int32, MAX_ALTERNATES> AltCamSco; // Scostamento camere alternate
312  SerializableArray<SerializableArray<SerializableArray<int32, 2>, MAX_ALT_ANIMS>, MAX_ALTERNATES> AltAnims; // Rimappatura anim alternative dialoghi
313  SerializableArray<uint16, MAX_DLG_MENUS> ItemIndex; // indice delle liste di comandi
314 
315  void loadFromStream(Common::SeekableReadStream &stream) override {
316  flags = stream.readUint16LE();
317  obj = stream.readSint32LE();
318  AltPosSco.loadFromStream(stream);
319  AltCamSco.loadFromStream(stream);
320  AltAnims.loadFromStream(stream);
321  ItemIndex.loadFromStream(stream);
322  }
323 };
324 
325 struct SDiaryItem : public SerializableAsset {
326  uint16 rand;
327  uint16 loop;
328  uint16 loopc;
329  uint16 bnd, saved_bnd;
330  uint16 cur;
331  uint16 on;
333 
334  void loadFromStream(Common::SeekableReadStream &stream) override {
335  rand = stream.readUint16LE();
336  loop = stream.readUint16LE();
337  loopc = stream.readUint16LE();
338  bnd = stream.readUint16LE();
339  saved_bnd = stream.readUint16LE();
340  cur = stream.readUint16LE();
341  on = stream.readUint16LE();
342  anim.loadFromStream(stream);
343  }
344 };
345 
346 struct SDiary : public SerializableAsset {
347  uint16 startt, endt;
348  int32 room;
349  uint16 obj;
350  uint16 cur;
351  uint16 end_hideobj; //se il bit piu' alto e' settato vuol dire che il diario e' stato lanciato almeno una volta e quindi questa variabile e' valida solo per oggetti da 0..32767
353 
354  void loadFromStream(Common::SeekableReadStream &stream) override {
355  startt = stream.readUint16LE();
356  endt = stream.readUint16LE();
357  room = stream.readSint32LE();
358  obj = stream.readUint16LE();
359  cur = stream.readUint16LE();
360  end_hideobj = stream.readUint16LE();
361  item.loadFromStream(stream);
362  }
363 };
364 
365 struct SPlayerStand {
366  uint8 pos = 0;
367  int32 an = 0;
368  int32 cr = 0;
369  uint16 bnd = 0;
370  Common::String roomName;
371  SPlayerStand() = default;
373  pos = stream.readByte();
374  an = stream.readSint32LE();
375  cr = stream.readSint32LE();
376  bnd = stream.readUint16LE();
377  }
378 };
379 
380 struct SPDALog : public SerializableAsset {
381  int32 time = 0;
384  SerializableArray<SerializableString<MAX_TEXT_CHARS>, MAX_PDA_LINES *MAX_PDA_INFO> formatted;
385  int32 menu_appartenenza = 0, menu_creato = 0;
386  int32 flags = 0;
387  int32 lines = 0;
388  int32 dx = 0, dy = 0;
389 
390  void loadFromStream(Common::SeekableReadStream &stream) override {
391  time = stream.readSint32LE();
392  info.loadFromStream(stream);
393  text.loadFromStream(stream);
394  formatted.loadFromStream(stream);
395  menu_appartenenza = stream.readSint32LE();
396  menu_creato = stream.readSint32LE();
397  flags = stream.readSint32LE();
398  lines = stream.readSint32LE();
399  dx = stream.readSint32LE();
400  dy = stream.readSint32LE();
401  }
402 };
403 
404 struct SString {
405  char text[MAX_STRING_LEN] = {};
406  uint16 x = 0, y = 0, dx = 0;
407 
408  constexpr SString() = default;
409  SString(const char *_text, uint16 _x = 0, uint16 _y = 0, uint16 _dx = 0) : x(_x), y(_y), dx(_dx) {
410  if (_text != nullptr) {
411  memcpy(this->text, _text, strlen(_text));
412  }
413  }
414 };
415 
416 struct SRect {
417  int32 x1 = 0, y1 = 0, x2 = 0, y2 = 0;
418  constexpr SRect() = default;
419  constexpr SRect(int32 _x1, int32 _y1, int32 _x2, int32 _y2): x1(_x1), y1(_y1), x2(_x2), y2(_y2) {}
420 
421  void reset() {
422  x1 = 0;
423  y1 = 0;
424  x2 = 0;
425  y2 = 0;
426  }
427 };
428 
429 struct SD3DRect {
430  int32 px = 0, py = 0, dx = 0, dy = 0;
431  uint8 r = 0, g = 0, b = 0, a = 0;
432 };
433 struct SD3DTriangle {
434  int32 x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0;
435  uint8 r = 0, g = 0, b = 0, a = 0;
436 };
437 struct SD3DBitmap {
438  int32 tnum = 0;
439  int32 px = 0, py = 0, dx = 0, dy = 0;
440  int32 rtype = 0;
441 };
442 struct SDDBitmap {
443  int32 tnum;
444  int32 px, py, ox, oy, dx, dy;
445 
446  SDDBitmap() {
447  reset();
448  }
449 
450  void reset() {
451  tnum =0;
452  px = 0;
453  py = 0;
454  ox = 0;
455  oy = 0;
456  dx = 0;
457  dy = 0;
458  }
459 };
460 
461 struct SDDText {
462  SDDText() {
463  reset();
464  }
465 
466  SDDText(const char *_text, FontKind _font, FontColor _color, int32 _tnum) : font(_font),
467  color(_color),
468  tnum(_tnum) {
469  Common::strlcpy(this->text, _text, sizeof(this->text));
470  }
471 
472  void reset() {
473  for(uint i = 0; i < ARRAYSIZE(text); i++) text[i] = '\0';
474  font = FontKind::Standard;
475  color = FontColor::WHITE_FONT;
476  tnum = 0;
477  }
478 
479  char text[MAX_STRING_LEN];
480  FontKind font;
481  FontColor color;
482  int32 tnum;
483 };
484 
485 struct SScript {
486  uint16 firstframe = 0;
487  uint8 flags = 0; // 0 - BREAKABLE - Se si interrompe con la pressione dei tasti del mouse
488 }; // 1 - DIALOGEXITNOANIM - Se lo script e' lanciato da un dialogo all'ultima battuta esce dal dialogo senza anim di link e di default
489 
490 struct SGameOptions {
491  uint8 sound_on = 0;
492  uint8 sound_volume = 0;
493  uint8 music_on = 0;
494  uint8 music_volume = 0;
495  uint8 speech_on = 0;
496  uint8 speech_volume = 0;
497  uint8 subtitles_on = 0;
498 };
499 
500 
501 // MESSAGGI PER LO SCHEDULER
502 struct message {
503  EventClass classe; // message classe
504  uint8 event = 0; // message name
505  uint16 flags = 0; // message priority | NOWAIT per script
506 
507  uint8 bparam = 0;
508  int16 wparam1 = 0; // t3dS16 parameter 1
509  int16 wparam2 = 0; // t3dS16 parameter 2
510  union {
511  int32 lparam[3] = {}; // long parameter
512  t3dF32 fparam[3]; // float parameter
513  };
514 
515  message() = default;
516  message(EventClass _classe, uint8 _event, uint16 _flags) : classe(_classe), event(_event), flags(_flags) {}
517 
518  void reset() {
519  classe = MC_IDLE;
520  event = 0;
521  flags = 0;
522  bparam = 0;
523  wparam1 = 0;
524  wparam2 = 0;
525  for (uint i = 0; i < ARRAYSIZE(lparam); i++) lparam[i] = 0;
526  // fparam cleared as union with lparam i.e. shared memory
527  }
528 };
529 
530 struct pqueue {
531  uint8 head = 0, tail = 0, len = 0;
532  message *event[MAX_MESSAGES] = {};
533 };
534 
535 
536 // STRUTTURE PER TITOLI DI CODA
538  char name[64] = {};
539  uint16 role = 0;
540  uint8 flags = 0;
541 
542  void loadFromStream(Common::SeekableReadStream &stream) override {
543  stream.read(name, 64);
544  role = stream.readUint16LE();
545  flags = stream.readByte();
546  }
547 };
548 
550  char role[48] = {};
551  uint8 flags = 0;
552 
553  void loadFromStream(Common::SeekableReadStream &stream) override {
554  stream.read(role, 48);
555  flags = stream.readByte();
556  }
557 };
558 
559 struct STitoliCoda {
560  char *s = nullptr; //puntatore alla stringa
561  int32 px = 0, py = 0; //posizione
562  int32 dx = 0, dy = 0; //dimensione
563  int32 tnum = 0; //bitmap
564 
565  uint32 time = 0; //quando deve apparire (solo nel caso degli StaticCredits)
566 };
567 
568 struct SRoomInfo {
569  char name[64] = {}; //nome della stanza
570  char fullstring[64 + 16 + 1] = {}; //stringa con ora
571  int32 px = 0, py = 0; //posizione
572  int32 dx = 0, dy = 0; //dimensione totale
573  int32 _dx = 0, _dy = 0; //dimensione della stringa attuale
574  int32 tnum = 0; //bitmap
575  char *letter_ptr = nullptr; //puntatore alla lettera corrente
576  int16 t_next_letter = 0; //quando deve apparire la nuova lettera
577  FontKind f; //il font
578 };
579 
580 } // End of namespace Watchmaker
581 
582 #endif // WATCHMAKER_STRUCT_H
#define ARRAYSIZE(x)
Definition: util.h:91
Definition: struct.h:437
Definition: struct.h:80
Definition: struct.h:218
Definition: struct.h:40
Definition: struct.h:145
Definition: 2d_stuff.h:30
Definition: str.h:59
uint16 readUint16LE()
Definition: stream.h:459
Definition: struct.h:537
FORCEINLINE int32 readSint32LE()
Definition: stream.h:555
size_t strlcpy(char *dst, const char *src, size_t size)
uint32 readUint32LE()
Definition: stream.h:473
Definition: struct.h:204
Definition: struct.h:346
Definition: struct.h:568
Definition: stream.h:745
Definition: struct.h:287
Definition: struct.h:276
Definition: struct.h:429
Definition: struct.h:33
Definition: struct.h:416
byte readByte()
Definition: stream.h:434
Definition: struct.h:121
Definition: struct.h:530
Definition: struct.h:559
Definition: struct.h:502
Definition: struct.h:442
Definition: struct.h:490
Definition: struct.h:404
Definition: struct.h:365
FORCEINLINE float readFloatLE()
Definition: stream.h:615
Definition: struct.h:485
FORCEINLINE int16 readSint16LE()
Definition: stream.h:543
Definition: struct.h:325
Definition: struct.h:180
Definition: struct.h:433
Definition: struct.h:380
Definition: struct.h:299
Definition: struct.h:549
Definition: struct.h:461
Definition: struct.h:307
Definition: struct.h:264
virtual uint32 read(void *dataPtr, uint32 dataSize)=0
Definition: struct.h:242