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 private:
147  Common::String meshlink[MAX_OBJ_MESHLINKS]; // link -> oggetto mesh (nome mesh) -> da rimuovere
148 public:
149  uint16 name; // frase nome
150  SerializableArray<uint16, MAX_PLAYERS> examine; // frase esamina
151  SerializableArray<uint16, MAX_PLAYERS> action; // frase azione
153  SerializableArray<uint16, MAX_PLAYERS> anim; // animazione su action
154  SerializableArray<uint16, MAX_PLAYERS> anim2; // animazione aggiunta (su examine)
155  uint8 room; // Stanza in cui si trova l'oggetto
156  uint8 goroom; // Se direzione num stanza - se persona num dialog
157  uint8 ninv; // ptr inventario
158  uint16 flags; // EXAMINE | EXAMINEACT | ROOM | PERSON | TAKE | USEWITH | EXTRA | EXTRA2 | DONE | ON | HIDE
159  uint8 pos; // 0 se no position
160 
161  bool meshLinkIsEmpty(int index) { return meshlink[index].empty() || meshlink[index][0] == '\0'; }
162  const Common::String& getMeshLink(int index) { return meshlink[index]; };
163  void setMeshLink(int index, const char *value) {
164  meshlink[index] = value;
165  }
166  void loadFromStream(Common::SeekableReadStream &stream) override {
167  SerializableArray<SerializableArray<uint8, T3D_NAMELEN>, MAX_OBJ_MESHLINKS> meshlink_int = {};
168  name = stream.readUint16LE();
169  examine.loadFromStream(stream);
170  action.loadFromStream(stream);
171  text.loadFromStream(stream);
172  anim.loadFromStream(stream);
173  anim2.loadFromStream(stream);
174  room = stream.readByte();
175  goroom = stream.readByte();
176  ninv = stream.readByte();
177  flags = stream.readUint16LE();
178  pos = stream.readByte();
179  meshlink_int.loadFromStream(stream);
180  // HACK:
181  for (int i = 0; i < MAX_OBJ_MESHLINKS; i++) {
182  meshlink[i] = (char*)meshlink_int.rawArray()[i].rawArray();
183  }
184  }
185 };
186 
187 struct SInvObject : public SerializableAsset {
188  uint16 name; // Nome Oggetto in inventario
189  SerializableArray<uint16, MAX_PLAYERS> examine; // Frase se si esamina
190  SerializableArray<uint16, MAX_PLAYERS> action; // Frase se si opera
191  uint16 flags; // USEWITH | EXTRA | EXTRA2 | DONE | ON | WITHI | WITHO
193  uint16 uwobj; // usewithobj automatico
194  SerializableArray<uint16, MAX_PLAYERS> anim; // animazione su usewith
195  SerializableArray<uint16, MAX_PLAYERS> anim2; // animazione su usewith
196  SerializableArray<uint8, T3D_NAMELEN> meshlink; // link -> mesh
197 
198  void loadFromStream(Common::SeekableReadStream &stream) override {
199  name = stream.readUint16LE();
200  examine.loadFromStream(stream);
201  action.loadFromStream(stream);
202  flags = stream.readUint16LE();
203  text.loadFromStream(stream);
204  uwobj = stream.readUint16LE();
205  anim.loadFromStream(stream);
206  anim2.loadFromStream(stream);
207  meshlink.loadFromStream(stream);
208  }
209 };
210 
211 struct SAtFrame : public SerializableAsset {
212  uint8 type = 0; // ATFTEXT, ATFSND, ATFEVENT
213  uint8 anim = 0; // solo se subanim e' attiva
214  int16 nframe = 0; // 10000 se attraversa portale
215  uint16 index = 0;
216 
217  void loadFromStream(Common::SeekableReadStream &stream) override {
218  type = stream.readByte();
219  anim = stream.readByte();
220  nframe = stream.readSint16LE();
221  index = stream.readUint16LE();
222  }
223 };
224 
225 struct SAnim : public SerializableAsset {
226 private:
227 
228  Common::String meshlink[MAX_SUBANIMS]; // link -> anim mesh (nome mesh) -> da rimuovere
229 public:
230  SerializableArray<SerializableArray<uint8, T3D_NAMELEN>, MAX_SUBANIMS> name; // nome animazione
231  SerializableArray<uint8, T3D_NAMELEN> RoomName; // nome stanza destinazione
233  uint32 flags;
234  int16 active; // indece tra le animazioni attive
235  int32 obj; // obj a cui e' collegato
236  uint8 pos; // posizione
237  uint8 cam; // camera per l'azione
238 
239  bool meshLinkIsEmpty(int index) { return meshlink[index].empty() || meshlink[index][0] == '\0'; }
240  const Common::String& getMeshLink(int index) { return meshlink[index]; }
241  void setMeshLink(int index, const char *value) {
242  meshlink[index] = value;
243  }
244  void setMeshLink(int index, const Common::String &value) {
245  meshlink[index] = value;
246  }
247 
248  void loadFromStream(Common::SeekableReadStream &stream) override {
250  meshlink_raw.loadFromStream(stream);
251  for (int i = 0; i < MAX_SUBANIMS; i++) {
252  meshlink[i] = (const char*)meshlink_raw.rawArray();
253  }
254  name.loadFromStream(stream);
255  RoomName.loadFromStream(stream);
256  atframe.loadFromStream(stream);
257  flags = stream.readUint32LE();
258  active = stream.readSint16LE();
259  obj = stream.readSint32LE();
260  pos = stream.readByte();
261  cam = stream.readByte();
262  }
263 };
264 
265 struct SSound : public SerializableAsset {
266  char name[T3D_NAMELEN];
267  uint8 flags;
268  SerializableArray<SerializableArray<uint8, T3D_NAMELEN>, MAX_SOUND_MESHLINKS> meshlink;
269  uint32 ConeInside, ConeOutside;
270  int32 ConeOutsideVolume;
271  t3dF32 MinDist, MaxDist;
272  int32 Angle;
273 
274  void loadFromStream(Common::SeekableReadStream &stream) override {
275  stream.read(name, T3D_NAMELEN);
276  flags = stream.readByte();
277  meshlink.loadFromStream(stream);
278  ConeInside = stream.readUint32LE();
279  ConeOutside = stream.readUint32LE();
280  ConeOutsideVolume = stream.readSint32LE();
281  MinDist = stream.readFloatLE();
282  MaxDist = stream.readFloatLE();
283  Angle = stream.readSint32LE();
284  }
285 };
286 
287 struct SMusic : public SerializableAsset {
288  char name[MAX_SUB_MUSICS][T3D_NAMELEN];
290 
291  void loadFromStream(Common::SeekableReadStream &stream) override {
292  for (int i = 0; i < MAX_SUB_MUSICS; i++) {
293  stream.read(name[i], T3D_NAMELEN);
294  }
295  vol.loadFromStream(stream);
296  }
297 };
298 
299 struct SDlgMenu : public SerializableAsset { // struttura di appoggio per riempiere i DlgItem
300  uint8 parent, on;
301  uint16 titolo; // indice della sentence di titolo
302 
303  void loadFromStream(Common::SeekableReadStream &stream) override {
304  parent = stream.readByte();
305  on = stream.readByte();
306  titolo = stream.readUint16LE();
307  }
308 };
309 
311  uint8 com; // comando
312  uint16 param1; // parametro 1
313  uint16 param2; // parametro 2
314 
315  void loadFromStream(Common::SeekableReadStream &stream) override {
316  com = stream.readByte();
317  param1 = stream.readUint16LE();
318  param2 = stream.readUint16LE();
319  }
320 };
321 
322 struct SDlgItem : public SerializableAsset {
323  SerializableArray<SerializableArray<SItemCommand, MAX_IC_PER_DLG_ITEM>, MAX_PLAYERS> item; // lista di comandi per personaggio
324 
325  void loadFromStream(Common::SeekableReadStream &stream) override {
326  item.loadFromStream(stream);
327  }
328 };
329 
330 struct SDialog : public SerializableAsset {
331  uint16 flags; // flags del dialogo - per ora non serve
332  int32 obj; // Personaggio con cui fa il dialogo
333  SerializableArray<int32, MAX_ALTERNATES> AltPosSco; // Scostamento posizione alternate
334  SerializableArray<int32, MAX_ALTERNATES> AltCamSco; // Scostamento camere alternate
335  SerializableArray<SerializableArray<SerializableArray<int32, 2>, MAX_ALT_ANIMS>, MAX_ALTERNATES> AltAnims; // Rimappatura anim alternative dialoghi
336  SerializableArray<uint16, MAX_DLG_MENUS> ItemIndex; // indice delle liste di comandi
337 
338  void loadFromStream(Common::SeekableReadStream &stream) override {
339  flags = stream.readUint16LE();
340  obj = stream.readSint32LE();
341  AltPosSco.loadFromStream(stream);
342  AltCamSco.loadFromStream(stream);
343  AltAnims.loadFromStream(stream);
344  ItemIndex.loadFromStream(stream);
345  }
346 };
347 
348 struct SDiaryItem : public SerializableAsset {
349  uint16 rand;
350  uint16 loop;
351  uint16 loopc;
352  uint16 bnd, saved_bnd;
353  uint16 cur;
354  uint16 on;
356 
357  void loadFromStream(Common::SeekableReadStream &stream) override {
358  rand = stream.readUint16LE();
359  loop = stream.readUint16LE();
360  loopc = stream.readUint16LE();
361  bnd = stream.readUint16LE();
362  saved_bnd = stream.readUint16LE();
363  cur = stream.readUint16LE();
364  on = stream.readUint16LE();
365  anim.loadFromStream(stream);
366  }
367 };
368 
369 struct SDiary : public SerializableAsset {
370  uint16 startt, endt;
371  int32 room;
372  uint16 obj;
373  uint16 cur;
374  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
376 
377  void loadFromStream(Common::SeekableReadStream &stream) override {
378  startt = stream.readUint16LE();
379  endt = stream.readUint16LE();
380  room = stream.readSint32LE();
381  obj = stream.readUint16LE();
382  cur = stream.readUint16LE();
383  end_hideobj = stream.readUint16LE();
384  item.loadFromStream(stream);
385  }
386 };
387 
388 struct SPlayerStand {
389  uint8 pos = 0;
390  int32 an = 0;
391  int32 cr = 0;
392  uint16 bnd = 0;
393  Common::String roomName;
394  SPlayerStand() = default;
396  pos = stream.readByte();
397  an = stream.readSint32LE();
398  cr = stream.readSint32LE();
399  bnd = stream.readUint16LE();
400  }
401 };
402 
403 struct SPDALog : public SerializableAsset {
404  int32 time = 0;
407  SerializableArray<SerializableString<MAX_TEXT_CHARS>, MAX_PDA_LINES *MAX_PDA_INFO> formatted;
408  int32 menu_appartenenza = 0, menu_creato = 0;
409  int32 flags = 0;
410  int32 lines = 0;
411  int32 dx = 0, dy = 0;
412 
413  void loadFromStream(Common::SeekableReadStream &stream) override {
414  time = stream.readSint32LE();
415  info.loadFromStream(stream);
416  text.loadFromStream(stream);
417  formatted.loadFromStream(stream);
418  menu_appartenenza = stream.readSint32LE();
419  menu_creato = stream.readSint32LE();
420  flags = stream.readSint32LE();
421  lines = stream.readSint32LE();
422  dx = stream.readSint32LE();
423  dy = stream.readSint32LE();
424  }
425 };
426 
427 struct SString {
428  char text[MAX_STRING_LEN] = {};
429  uint16 x = 0, y = 0, dx = 0;
430 
431  constexpr SString() = default;
432  SString(const char *_text, uint16 _x = 0, uint16 _y = 0, uint16 _dx = 0) : x(_x), y(_y), dx(_dx) {
433  if (_text != nullptr) {
434  memcpy(this->text, _text, strlen(_text));
435  }
436  }
437 };
438 
439 struct SRect {
440  int32 x1 = 0, y1 = 0, x2 = 0, y2 = 0;
441  constexpr SRect() = default;
442  constexpr SRect(int32 _x1, int32 _y1, int32 _x2, int32 _y2): x1(_x1), y1(_y1), x2(_x2), y2(_y2) {}
443 
444  void reset() {
445  x1 = 0;
446  y1 = 0;
447  x2 = 0;
448  y2 = 0;
449  }
450 };
451 
452 struct SD3DRect {
453  int32 px = 0, py = 0, dx = 0, dy = 0;
454  uint8 r = 0, g = 0, b = 0, a = 0;
455 };
456 struct SD3DTriangle {
457  int32 x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0;
458  uint8 r = 0, g = 0, b = 0, a = 0;
459 };
460 struct SD3DBitmap {
461  int32 tnum = 0;
462  int32 px = 0, py = 0, dx = 0, dy = 0;
463  int32 rtype = 0;
464 };
465 struct SDDBitmap {
466  int32 tnum;
467  int32 px, py, ox, oy, dx, dy;
468 
469  SDDBitmap() {
470  reset();
471  }
472 
473  void reset() {
474  tnum =0;
475  px = 0;
476  py = 0;
477  ox = 0;
478  oy = 0;
479  dx = 0;
480  dy = 0;
481  }
482 };
483 
484 struct SDDText {
485  SDDText() {
486  reset();
487  }
488 
489  SDDText(const char *_text, FontKind _font, FontColor _color, int32 _tnum) : font(_font),
490  color(_color),
491  tnum(_tnum) {
492  Common::strlcpy(this->text, _text, sizeof(this->text));
493  }
494 
495  void reset() {
496  for(uint i = 0; i < ARRAYSIZE(text); i++) text[i] = '\0';
497  font = FontKind::Standard;
498  color = FontColor::WHITE_FONT;
499  tnum = 0;
500  }
501 
502  char text[MAX_STRING_LEN];
503  FontKind font;
504  FontColor color;
505  int32 tnum;
506 };
507 
508 struct SScript {
509  uint16 firstframe = 0;
510  uint8 flags = 0; // 0 - BREAKABLE - Se si interrompe con la pressione dei tasti del mouse
511 }; // 1 - DIALOGEXITNOANIM - Se lo script e' lanciato da un dialogo all'ultima battuta esce dal dialogo senza anim di link e di default
512 
513 struct SGameOptions {
514  uint8 sound_on = 0;
515  uint8 sound_volume = 0;
516  uint8 music_on = 0;
517  uint8 music_volume = 0;
518  uint8 speech_on = 0;
519  uint8 speech_volume = 0;
520  uint8 subtitles_on = 0;
521 };
522 
523 
524 // MESSAGGI PER LO SCHEDULER
525 struct message {
526  EventClass classe; // message classe
527  uint8 event = 0; // message name
528  uint16 flags = 0; // message priority | NOWAIT per script
529 
530  uint8 bparam = 0;
531  int16 wparam1 = 0; // t3dS16 parameter 1
532  int16 wparam2 = 0; // t3dS16 parameter 2
533  union {
534  int32 lparam[3] = {}; // long parameter
535  t3dF32 fparam[3]; // float parameter
536  };
537 
538  message() = default;
539  message(EventClass _classe, uint8 _event, uint16 _flags) : classe(_classe), event(_event), flags(_flags) {}
540 
541  void reset() {
542  classe = MC_IDLE;
543  event = 0;
544  flags = 0;
545  bparam = 0;
546  wparam1 = 0;
547  wparam2 = 0;
548  for (uint i = 0; i < ARRAYSIZE(lparam); i++) lparam[i] = 0;
549  // fparam cleared as union with lparam i.e. shared memory
550  }
551 };
552 
553 struct pqueue {
554  uint8 head = 0, tail = 0, len = 0;
555  message *event[MAX_MESSAGES] = {};
556 };
557 
558 
559 // STRUTTURE PER TITOLI DI CODA
561  char name[64] = {};
562  uint16 role = 0;
563  uint8 flags = 0;
564 
565  void loadFromStream(Common::SeekableReadStream &stream) override {
566  stream.read(name, 64);
567  role = stream.readUint16LE();
568  flags = stream.readByte();
569  }
570 };
571 
573  char role[48] = {};
574  uint8 flags = 0;
575 
576  void loadFromStream(Common::SeekableReadStream &stream) override {
577  stream.read(role, 48);
578  flags = stream.readByte();
579  }
580 };
581 
582 struct STitoliCoda {
583  char *s = nullptr; //puntatore alla stringa
584  int32 px = 0, py = 0; //posizione
585  int32 dx = 0, dy = 0; //dimensione
586  int32 tnum = 0; //bitmap
587 
588  uint32 time = 0; //quando deve apparire (solo nel caso degli StaticCredits)
589 };
590 
591 struct SRoomInfo {
592  char name[64] = {}; //nome della stanza
593  char fullstring[64 + 16 + 1] = {}; //stringa con ora
594  int32 px = 0, py = 0; //posizione
595  int32 dx = 0, dy = 0; //dimensione totale
596  int32 _dx = 0, _dy = 0; //dimensione della stringa attuale
597  int32 tnum = 0; //bitmap
598  char *letter_ptr = nullptr; //puntatore alla lettera corrente
599  int16 t_next_letter = 0; //quando deve apparire la nuova lettera
600  FontKind f; //il font
601 };
602 
603 } // End of namespace Watchmaker
604 
605 #endif // WATCHMAKER_STRUCT_H
#define ARRAYSIZE(x)
Definition: util.h:103
Definition: struct.h:460
Definition: struct.h:80
Definition: struct.h:225
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:560
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:211
Definition: struct.h:369
Definition: struct.h:591
Definition: stream.h:745
Definition: struct.h:310
Definition: struct.h:299
Definition: struct.h:452
Definition: struct.h:33
Definition: struct.h:439
byte readByte()
Definition: stream.h:434
Definition: struct.h:121
Definition: struct.h:553
Definition: struct.h:582
Definition: struct.h:525
Definition: struct.h:465
Definition: struct.h:513
Definition: struct.h:427
Definition: struct.h:388
FORCEINLINE float readFloatLE()
Definition: stream.h:615
Definition: struct.h:508
FORCEINLINE int16 readSint16LE()
Definition: stream.h:543
Definition: struct.h:348
Definition: struct.h:187
Definition: struct.h:456
Definition: struct.h:403
Definition: struct.h:322
Definition: struct.h:572
Definition: struct.h:484
Definition: struct.h:330
Definition: struct.h:287
virtual uint32 read(void *dataPtr, uint32 dataSize)=0
Definition: struct.h:265