ScummVM API documentation
gamos.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 GAMOS_H
23 #define GAMOS_H
24 
25 #include "common/events.h"
26 #include "common/rect.h"
27 #include "common/scummsys.h"
28 #include "common/system.h"
29 #include "common/error.h"
30 #include "common/fs.h"
31 #include "common/hash-str.h"
32 #include "common/random.h"
33 #include "common/serializer.h"
34 #include "common/util.h"
35 #include "common/array.h"
36 #include "common/memstream.h"
37 #include "engines/engine.h"
38 #include "engines/savestate.h"
39 #include "graphics/screen.h"
40 #include "audio/mixer.h"
41 #include "audio/audiostream.h"
42 #include "audio/decoders/raw.h"
43 
44 #include "gamos/pool.h"
45 
46 #include "gamos/keycodes.h"
47 
48 #include "gamos/proc.h"
49 #include "gamos/music.h"
50 #include "gamos/movie.h"
51 #include "gamos/vm.h"
52 
53 #include "gamos/detection.h"
54 #include "gamos/file.h"
55 
56 #include "gamos/array2d.h"
57 
58 #include "gamos/blit.h"
59 
60 namespace Gamos {
61 
62 struct GamosGameDescription;
63 
64 enum CONFTYPE {
65  CONFTP_P1 = 1,
66  CONFTP_P2 = 2,
67  CONFTP_P3 = 3,
68  CONFTP_IDFLG = 0x80,
69  CONFTP_RESMASK = 0x7f,
70 
71 };
72 
73 
74 enum RESTYPE {
75  RESTP_GAMECONF = 0xf,
76  RESTP_GAMECONF2 = 0x10,
77  RESTP_DATACONF = 0x11,
78  RESTP_VMSTATE = 0x12,
79  RESTP_VMDATA = 0x13,
80  RESTP_BKG = 0x18,
81  RESTP_INITACT = 0x19,
82  RESTP_ACT_INFO = 0x20,
83  RESTP_ACT_ONCREATE = 0x21,
84  RESTP_ACT_ONDELETE = 0x22,
85  RESTP_ACT_COUNT = 0x23,
86  RESTP_ACT_DATA = 0x2a,
87  RESTP_ACT_COND = 0x2b,
88  RESTP_ACT_FUNC = 0x2c,
89  RESTP_UNK_MASKS = 0x38,
90  RESTP_UNK_OIDS = 0x39,
91  RESTP_UNK_ACTST = 0x3a,
92  RESTP_SPR_INFO = 0x40,
93  RESTP_SPR_SEQLEN = 0x41,
94  RESTP_SPR_SEQIMGINFO = 0x42,
95  RESTP_SPR_SEQIMGDATA = 0x43,
96  RESTP_UNKNOWN_50 = 0x50,
97  RESTP_SFX_SAMPLE = 0x51,
98  RESTP_MIDI_TRACK = 0x52,
99  RESTP_SUB_ACT = 0x60,
100  RESTP_SUB_PLACE = 0x61,
101  RESTP_XORSEQ0 = 0x7c,
102  RESTP_XORSEQ1 = 0x7d,
103  RESTP_XORSEQ2 = 0x7e,
104 };
105 
106 enum {
107  PATH_DIR_U = 0,
108  PATH_DIR_UR = 1,
109  PATH_DIR_R = 2,
110  PATH_DIR_DR = 3,
111  PATH_DIR_D = 4,
112  PATH_DIR_DL = 5,
113  PATH_DIR_L = 6,
114  PATH_DIR_UL = 7,
115 
116  PATH_FREE = 0,
117  PATH_TARGET = 2,
118  PATH_OBSTACLE = 3,
119  PATH_STEP1 = 6,
120  PATH_STEP2 = 5,
121  PATH_STEP3 = 4,
122 };
123 
124 struct Image {
125  bool loaded = false;
126  int32 offset = -1;
127  int32 size = 0;
128  int32 cSize = 0;
129 
130  Graphics::Surface surface;
131 
132  RawData rawData;
133 };
134 
135 struct ImagePos {
136  int16 xoffset = 0;
137  int16 yoffset = 0;
138 
139  Image *image = nullptr;
140 };
141 
143 
144 struct Sprite {
145  uint32 index = 0;
146 
147  byte field_0;
148  union {
149  byte flags;
150  byte startChar; // if it's font
151  };
152  byte lastChar;
153  byte frameCount;
154 
155  Common::Array<ImageSeq *> sequences;
156 };
157 
158 /* Used to xor savedata */
159 struct XorArg {
160  uint32 pos;
161  uint32 len;
162 };
163 
164 struct Unknown1 {
165  Common::Array<byte> masks;
166  Common::Array<byte> oids;
167  Common::Array<byte> actsT;
168 };
169 
170 struct ObjState {
171  uint8 actid = 0;
172  uint8 flags = 0;
173  uint8 t = 0;
174 
175  ObjState() = default;
176  ObjState(const ObjState&) = default;
177  ObjState(ObjState&&) = default;
178  ObjState& operator=(const ObjState&) = default;
179 
180  ObjState(uint8 aa, uint8 af, uint8 at): actid(aa), flags(af), t(at) {};
181 };
182 
184  int8 x = 0;
185  int8 y = 0;
186 };
187 
188 struct ActTypeEntry {
189  uint8 t = 0;
190  Common::Array<ActEntry> entries;
191 };
192 
193 struct Actions {
194  enum {
195  HAS_CONDITION = 1,
196  HAS_ACT2 = 2,
197  HAS_ACT4 = 4,
198  HAS_FUNCTION = 8,
199  HAS_ACT10 = 0x10
200  };
201 
202  byte flags = 0;
203  byte num_act_10e = 0;
204 
206 
207  ActEntry act_4;
208 
210 
211  Common::Array<ActEntry> act_10end[3];
212 
213  int32 conditionAddress = -1;
214  int32 functionAddress = -1;
215 
216  void parse(const byte *data, uint32 dataSize);
217 };
218 
219 struct ObjectAction {
220  uint8 actType = 0; // input action type?
221  uint8 mask = 0;
222  uint8 priority = 0;
223  uint8 storageSize = 0;
224  int32 onCreateAddress = -1;
225  Common::Array< Actions > actions;
226  int32 onDeleteAddress = -1;
227 };
228 
229 struct Object {
230  enum {
231  FLAG_VALID = 1,
232 
233  /* Action objects */
234  FLAG_HASACTION = 2,
235  FLAG_TRANSITION = 4, /* transition between logic cells */
236  FLAG_STORAGE = 8, /* in original engine used to indicate allocated storage */
237 
238  /* Graphic objects */
239  FLAG_GRAPHIC = 0x80,
240  FLAG_FREECOORDS = 0x40, /* coords not binded to grid */
241  FLAG_OVERLAY = 0x20, /* gfx object like titles and etc */
242  FLAG_FLIPV = 0x10,
243  FLAG_FLIPH = 8,
244  FLAG_DIRTRECT = 4,
245  };
246 
247  int16 index = 0;
248 
249  uint8 flags = 0;
250  uint8 priority = 0;
251  Common::Point cell;
252 
253  /* gfx */
254  int32 sprId = -1;
255  int32 seqId = -1;
256  int16 frame = -1;
257  int16 frameMax = -1;
258  Common::Point position;
259  int16 actObjIndex = -1;
260 
261  /* action */
262  uint8 actID = 0;
263  uint8 t = 0;
264  ObjState state;
265  uint8 inputFlag = 0;
266  int16 tgtObjectId = -1;
267  int16 curObjectId = -1;
268 
269  ImagePos *pImg = nullptr;
270  Common::Array<byte> storage;
271 
272 
273  /*
274  Original object structures:
275 
276  action:
277  flags 0
278  actID 1
279  state 2
280  inputFlag 4
281  priority 5
282  cell.x 6
283  cell.y 7
284  tgtObjectId 8
285  curObjectId 10
286  pStorage 12
287 
288  gfx:
289  flags 0
290  frame 1
291  frameMax 2
292  priority 3
293  cell.x 4
294  cell.y 5
295  actObjIndex 6
296  position.x 8
297  position.y 10
298  pImg 12
299  */
300 
301  inline bool isActionObject() const { return (flags & (FLAG_HASACTION | FLAG_VALID)) == (FLAG_HASACTION | FLAG_VALID); };
302  inline bool isGraphicObject() const { return (flags & (FLAG_GRAPHIC | FLAG_VALID | FLAG_HASACTION)) == (FLAG_GRAPHIC | FLAG_VALID); };
303  inline bool isOverlayObject() const { return (flags & (FLAG_GRAPHIC | FLAG_OVERLAY | FLAG_FREECOORDS | FLAG_VALID | FLAG_HASACTION)) ==
304  (FLAG_GRAPHIC | FLAG_OVERLAY | FLAG_FREECOORDS | FLAG_VALID); };
305  inline bool isStaticObject() const { return (flags & (FLAG_GRAPHIC | FLAG_FREECOORDS | FLAG_VALID)) == (FLAG_GRAPHIC | FLAG_VALID); };
306 };
307 
309  uint16 sprId = 0;
310 };
311 
312 struct GameScreen {
313  bool loaded = false;
314  uint32 offset = 0;
315  Graphics::Surface _bkgImage;
316  byte *palette = nullptr;
317 
318  Array2D<ObjState> _savedStates;
319  Common::Array<Object> _savedObjects;
320 
321  RawData _bkgImageData;
322 };
323 
325  VmTxtFmtAccess(VM &vm): _vm(vm) {};
326  VM &_vm;
327  byte *objMem = nullptr;
328 
329  inline bool isObjMem() const { return getMemType() == VM::REF_EBX;}
330 
331  inline Common::String getString(uint maxLen = 256) const {
332  if (isObjMem()) {
333  Common::String s = Common::String((const char *)objMem + getOffset());
334  if (s.size() > maxLen)
335  s.erase(maxLen);
336  return s;
337  }
338 
339  return _vm.readMemString(getOffset(), maxLen);
340  }
341 
342  inline uint8 getU8() const {
343  if (isObjMem())
344  return objMem[getOffset()];
345  return _vm.memory().getU8(getOffset());
346  }
347 
348  inline uint32 getU32() const {
349  if (isObjMem())
350  return _vm.getU32(objMem + getOffset());
351  return _vm.memory().getU32(getOffset());
352  }
353 
354  inline void write(byte *src, uint len) {
355  if (isObjMem())
356  memcpy(objMem + getOffset(), src, len);
357  else
358  _vm.writeMemory(getOffset(), src, len);
359  }
360 
361  inline void setU8(uint8 v) {
362  if (isObjMem())
363  objMem[getOffset()] = v;
364  else
365  _vm.memory().setU8(getOffset(), v);
366  }
367 
368  inline void setU32(uint32 v) {
369  if (isObjMem())
370  _vm.setU32(objMem + getOffset(), v);
371  else
372  _vm.memory().setU32(getOffset(), v);
373  }
374 };
375 
376 class GamosEngine : public Engine, public KeyCodes {
377  friend class MoviePlayer;
378 
379 private:
380  const GamosGameDescription *_gameDescription;
381 
382  bool _errSet = false;
383  Common::String _errMessage;
384 
385  GameFile _gameFile;
386 
387  byte _cmdByte = 0;
388 
389  bool _isResLoadingProcess = false;
390  int _currentModuleID = 0;
391 
392  byte _saveLoadID = 0;
393  uint32 _magic = 0xBAD00BAD;
394  uint32 _width = 0; //screen output width
395  uint32 _height = 0; //screen output height
396  int32 _gridCellW = 0;
397  int32 _gridCellH = 0;
398  uint32 _movieCount = 0;
399  byte _fps = 1;
400  byte _drawCursor = 0;
401  byte _fadeEffectID = 0;
402  byte _playIntro = 0;
403 
404  byte _currentFade = 0;
405 
406  int _isMoviePlay = 0;
407 
408  bool _onlyScanImage = false;
409  int32 _resReadOffset = 0;
410 
411  Common::Point _introPos;
412  Common::Point _introSize;
413  Common::String _string1;
414  Common::String _winCaption;
415 
416  Common::Array<uint32> _movieOffsets;
417 
418  Common::Array<Image *> _images;
420 
421  Common::Point _bkgSize;
422 
423  Common::Array<GameScreen> _gameScreens;
424 
425  Common::Array<Sprite> _sprites;
426 
428 
429  Common::Array< Common::Array<byte> > _soundSamples;
430 
431  Common::Array< Actions > _subtitleActions;
433 
434  uint32 _delayTime = 0;
435  uint32 _lastTimeStamp = 0;
436 
437  Common::Array<XorArg> _xorSeq[3];
438 
439  Common::RandomSource _randomSource;
440  uint32 _seed = 1;
441 
442  Object _cursorObject;
443 
444  int32 _cursorFrame = 0;
445  int32 _mouseCursorImgId = 0;
446  int32 _currentCursor = -1;
447 
448 
449 
450  bool _isSaveLoadingProcess = false;
451  bool _ignoreSoundActions = false;
452 
453 
454  uint8 _inputMouseActId = 0;
455  uint8 _inputMouseActType = 0;
456 
457  bool _midiStarted = false;
458 
459  uint8 DAT_004173ec = 0;
460 
461  /* Data2 */
462 
463  Common::String _stateExt;
464 
465  int32 _svModuleId = 0;
466  int32 _svGameScreen = 0;
467  uint32 _d2_fld10 = 0;
468  bool _enableSounds = false;
469  bool _enableInput = false;
470  bool _enableMovie = false;
471  bool _enableCDAudio = false;
472  int8 _cdAudioTrack = -1;
473  int32 _scrollX = 0;
474  int32 _scrollY = 0;
475  int32 _scrollTrackObj = 0;
476  int16 _scrollSpeed = 0;
477  int16 _scrollCutoff = 0;
478  int16 _scrollSpeedReduce = 0;
479  uint8 _scrollBorderL = 0;
480  uint8 _scrollBorderR = 0;
481  uint8 _scrollBorderU = 0;
482  uint8 _scrollBorderB = 0;
483  uint8 _sndChannels = 0;
484  uint8 _sndVolume = 0;
485  uint8 _midiVolume = 0;
486  uint8 _svFps = 0;
487  uint32 _svFrame = 0;
488 
489  uint8 _sndVolumeTarget = 0;
490  uint8 _midiVolumeTarget = 0;
491  uint8 _savedSndVolume = 0;
492  uint8 _savedMidiVolume = 0;
493 
494  bool _enableMidi = false;
495  int32 _midiTrack = 0;
496 
497  uint16 _scummMidiVolume = 256;
498  uint16 _scummSndVolume = 256;
499 
500 
501  uint32 _readingBkgOffset = 0;
502  int32 _readingBkgMainId = -1;
503  int32 _countReadedBkg = 0;
504  int32 _currentGameScreen = -1;
505  int32 _loadedDataSize = -1;
506 
507  uint32 _addrBlk12 = 0;
508  uint32 _addrFPS = 1;
509  uint32 _addrKeyDown = 2;
510  uint32 _addrKeyCode = 3;
511  uint32 _addrCurrentFrame = 4;
512 
513  MidiMusic _musicPlayer;
514  SystemProc _messageProc;
515  MoviePlayer _moviePlayer;
516 
517  uint32 _statesWidth = 0;
518  uint32 _statesHeight = 0;
519  uint32 _statesShift = 0;
520  Array2D<ObjState> _states;
521 
522 
523  uint8 _preprocDataId = 0;
524 
525  Common::Array<Unknown1> _thing2;
526  Common::Array<ObjectAction> _objectActions;
527 
528  Pool<Object> _objects;
529 
530  bool _curObjectActProcessed = false;
531 
532  Object *_firstUpdateObject = nullptr;
533 
534  ObjectAction *_curAction = nullptr;
535  Object *_curObject = nullptr;
536  Object *_inputActObj = nullptr;
537 
538  uint8 _curObjectT = 0;
539  bool _gfxObjectCreated = false;
540  bool _restartUpdateObject = false;
541 
542 
543  byte *_curObjStorage = nullptr;
544 
545  Common::Point _curObjectCurrentCell;
546  Common::Point _curObjectStartCell;
547 
548  byte *PTR_00417388 = nullptr;
549 
550  int32 _curObjIndex = 0;
551 
552 
553  Common::Point _inputActCell;
554  Common::Point _inputMouseActCell;
555 
556  uint8 _inputActId = 0;
557  bool _pathInMove = false;
558 
559  uint8 _pressedKeyCode = 0;
560 
561  Common::String _keySeq;
562 
563 
564  int32 _txtInputVmOffset = -1;
565  int32 _txtInputSpriteID = 0;
566  int32 _txtInputX = 0;
567  int32 _txtInputY = 0;
568  uint8 _txtInputBuffer[256];
569  Object *_txtInputObjects[256];
570  int32 _txtInputLength = 0;
571  int32 _txtInputMaxLength = 0;
572  VmTxtFmtAccess _txtInputVMAccess;
573  uint8 _txtInputFlags = 0;
574  bool _txtInputTyped = false;
575  bool _txtInputIsNumber = false;
576  Object *_txtInputObject = nullptr;
577  ObjectAction *_txtInputAction = nullptr;
578  int32 _txtInputObjectIndex = -1;
579 
580 
581  bool _txtInputActive = false;
582 
583 
584  /* path find ? */
585  Common::Point _pathStartCell;
586  Common::Point _pathTargetCell;
587  int8 _pathDir8 = 0;
588  int8 _pathDir4 = 0;
589 
590  Array2D<uint8> _pathMap;
591  uint32 _statesCount = 0;
592  uint32 _pathRight = 0;
593  uint32 _pathBottom = 0;
594 
595  Common::Array<Common::Rect> _dirtyRects;
596 
597  VM _vm;
598 
599  bool _needReload = false;
600 
601  uint32 _engineVersion = 0x18;
602 
603 protected:
604  // Engine APIs
605  Common::Error run() override;
606 
607  void readCMDByte() {
608  _cmdByte = _gameFile.readByte();
609  }
610 
611  bool loadModule(uint id);
612  bool loader2();
613 
614  bool loadResHandler(uint tp, uint pid, uint p1, uint p2, uint p3, const byte *data, uint32 dataSize);
615  bool loadResHandler(uint tp, uint pid, uint p1, uint p2, uint p3, const RawData &data);
616 
617  bool reuseLastResource(uint tp, uint pid, uint p1, uint p2, uint p3);
618 
619  bool initMainDatas();
620 
621  bool init(const Common::String &moduleName);
622  bool loadInitModule();
623 
624  void readElementsConfig(const RawData &data);
625 
626  void setFPS(uint fps);
627 
628  void loadXorSeq(const byte *data, uint32 dataSize, int id);
629 
630  bool loadSpriteInfo(int32 id, const byte *data, uint32 dataSize);
631  bool loadSpriteSeqLength(int32 id, const byte *data, uint32 dataSize);
632  bool loadSpriteSeqImageInfo(int32 id, int32 p1, const byte *data, uint32 dataSize);
633  bool loadSpriteSeqImageData(int32 id, int32 p1, int32 p2, const byte *data, uint32 dataSize);
634 
635  bool loadMidiTrack(int32 id, const byte *data, uint32 dataSize);
636 
637  bool loadBackground(int32 id, const byte *data, uint32 dataSize);
638 
639  void freeImages();
640  void freeSequences();
641 
642 
643  bool playMidi(Common::Array<byte> *buffer);
644 
645  bool playSound(uint id);
646  int stepVolume(int volume, int target);
647 
648  void changeVolume();
649 
650  void syncSoundSettings() override;
651 
652 
653  void stopMidi();
654  void stopCDAudio();
655  void stopSounds();
656 
657  bool playIntro();
658 
659  bool playMovie(uint32 id);
660  uint32 playMidiTrack(uint32 id);
661 
662  void setErrMessage(const Common::String &msg);
663 
664  void updateScreen(bool checkers, const Common::Rect &rect);
665 
666  void readData2(const RawData &data);
667 
668  uint8 update(Common::Point screenSize, Common::Point mouseMove, Common::Point actPos, uint8 act2, uint8 act1, uint16 keyCode, bool mouseInWindow);
669 
670  int32 doActions(const Actions &a, bool absolute);
671  uint32 savedDoActions(const Actions &a);
672 
673  static uint32 getU32(const void *ptr);
674 
675  void preprocessData(int id, ActEntry *e);
676  void preprocessDataB1(int id, ActEntry *e);
677  int processData(ActEntry e, bool absolute);
678 
679  void executeScript(int32 scriptAddr, ObjectAction *act, Object *pobj, int32 index, byte *storage, Common::Point cell, uint8 t);
680 
681  void processActionCurObject(ActEntry e);
682 
683  void createActiveObject(ActEntry e, Common::Point cell);
684 
685  void removeObjectAtCoords(Common::Point cell, bool deleteGfxObj);
686 
687  Object *getFreeObject();
688  void removeObject(Object *obj);
689  void removeObjectMarkDirty(Object *obj);
690  void removeObjectByIDMarkDirty(int32 id);
691 
692  void removeSubtitles(Object *obj);
693  void cycleNextInputObj(Object *obj);
694 
695  bool updateObjects();
696 
697  bool updateMouseCursor(Common::Point mouseMove);
698  bool scrollAndDraw();
699  bool updateVMInputFrameStates();
700  bool updateGfxFrames(Object *obj, bool p2, bool p1);
701 
702  void updateGfxObjectPosition(Object *obj);
703  void addDirtRectOnObject(Object *obj);
704  void addDirtyRect(const Common::Rect &rect);
705 
706  void doDraw();
707  void flushDirtyRects(bool apply);
708 
709  bool usePalette(const byte *pal, int num, int fade, bool winColors);
710  bool setPaletteCurrentGS();
711 
712  bool loadImage(Image *img);
713 
714  uint32 doScript(uint32 scriptAddress);
715 
716  bool createGfxObject(uint32 id, Common::Point position, bool p);
717 
718  void gfxObjectCalculateFlip(int32 sprId, Object *obj, bool p);
719 
720  void updateLinkedGfxObject(Object *obj);
721 
722  bool moviePlayerPlay(int id);
723 
724  void setCursor(int id, bool dirtRect);
725 
726  void processInput(Common::Point move, Common::Point actPos, uint8 act2, uint8 act1);
727  bool checkPointOnLinkedGfx(Object *obj, Common::Point pos);
728 
729  void setNeedReload() {
730  _needReload = true;
731  _vm._interrupt = true;
732  };
733 
734  Object *addSubtitleImage(uint32 frame, int32 spr, int32 *pX, int32 y);
735  void addSubtitles(VM::Context *ctx, byte memtype, int32 offset, int32 sprId, int32 x, int32 y);
736 
737 
738  /* Path find methods */
739  void FUN_00407db8(uint8 p);
740  byte FUN_00408648(uint8 p1, uint8 p2, uint8 p3);
741  byte FUN_004084bc(uint8 p);
742  byte FUN_00408510(uint8 p);
743  byte FUN_0040856c();
744  byte FUN_004085d8(uint8 p);
745  byte pathFindCalcMove(bool faceTarget);
746  byte pathFindMoveToTarget();
747  byte pathFindTraceMove(uint8 p);
748  byte pathFindSetNeighbor(uint8 checkVal, uint8 setVal);
749 
750  byte FUN_004088cc(uint8 p1, uint8 p2, uint8 p3);
751  byte FUN_004086e4(const Common::Array<byte> &arr);
752  byte FUN_00408778(const Common::Array<byte> &arr);
753  byte FUN_0040881c(const Common::Array<byte> &arr);
754 
755  bool FUN_0040705c(int a, int b);
756 
757 
758  void runRenewStaticGfxCurObj(uint8 val, bool rnd);
759  void removeStaticGfxCurObj();
760 
761  int txtInputBegin(VM::Context *ctx, byte memtype, int32 offset, int sprId, int32 x, int32 y);
762  void txtInputProcess(uint8 c);
763  void txtInputEraseBack(int n);
764 
765  bool onTxtInputUpdate(uint8 c);
766 
767  /* save-load */
768  void storeToGameScreen(int id);
769  bool switchToGameScreen(int id, bool doNotStore);
770 
771  Common::String makeSaveName(const Common::String &main, int id, const Common::String &ext) const;
772 
773  void writeVMData(Common::SeekableWriteStream *stream, const Common::Array<XorArg> &seq);
774  void readVMData(Common::SeekableReadStream *stream, const Common::Array<XorArg> &seq);
775 
776  bool writeStateFile();
777  void writeStateData(Common::SeekableWriteStream *stream);
778 
779  void zeroVMData(const Common::Array<XorArg> &seq);
780 
781  bool loadStateFile();
782  void loadStateData(Common::SeekableReadStream *stream);
783 
784  bool writeSaveFile(int id);
785  bool loadSaveFile(int id);
786  bool deleteSaveFile(int id);
787 
788  void writeObjectData(Common::SeekableWriteStream *stream, const Object *obj);
789  void loadObjectData(Common::SeekableReadStream *stream, Object *obj);
790 
791  void vmCallDispatcher(VM::Context *ctx, uint32 funcID);
792 
793 
794  void dumpActions();
795 
796  static void callbackVMCallDispatcher(void *engine, VM::Context *ctx, uint32 funcID);
797 
798 
799  static Common::String gamos_itoa(int value, uint radix);
800 
801 
802 
803  /* video */
804  void playVideo(const Common::String &video, const Common::Point &pos, const Common::Point &size);
805  void surfacePaletteRemap(Graphics::Surface *dst, const byte *tgtPalette, const Graphics::Surface *src, const byte *srcPalette, int srcCount);
806 
807  /* skip events */
808  bool eventsSkip(bool breakOnInput = false);
809 
810 public:
811 
812  inline void rndSeed(uint32 seed) {
813  _seed = seed * 0x41c64e6d + 0x3039;
814  }
815 
816  inline uint32 rnd() {
817  uint32 val = _seed;
818  _seed = _seed * 0x41c64e6d + 0x3039;
819  return val;
820  }
821 
822  inline uint16 rndRange16(uint32 range) {
823  uint16 percent = _seed >> 16;
824  _seed = _seed * 0x41c64e6d + 0x3039;
825  return (percent * range) >> 16;
826  }
827 
828 public:
829  Graphics::Screen *_screen = nullptr;
830 public:
831  GamosEngine(OSystem *syst, const GamosGameDescription *gameDesc);
832  ~GamosEngine() override;
833 
834  uint32 getFeatures() const {
835  return _gameDescription->desc.flags;
836  }
837 
838  Common::String getGameId() const {
839  return _gameDescription->desc.gameId;
840  }
841 
842  Common::Language getGameLanguage() {
843  return _gameDescription->desc.language;
844  }
845 
846  Common::String getRunFile() const {
847  return _gameDescription->desc.filesDescriptions[0].fileName;
848  }
849 
850  uint32 getEngineVersion() const {
851  return _gameDescription->engineVersion;
852  }
853 };
854 
855 extern GamosEngine *g_engine;
856 #define SHOULD_QUIT ::Gamos::g_engine->shouldQuit()
857 
858 } // End of namespace Gamos
859 
860 #endif // GAMOS_H
Definition: gamos.h:229
Definition: gamos.h:183
Definition: str.h:59
Definition: music.h:37
Definition: surface.h:67
Definition: gamos.h:164
Definition: error.h:81
Definition: gamos.h:144
Definition: random.h:44
const char * fileName
Name of the described file.
Definition: advancedDetector.h:79
Definition: pool.h:30
const char * gameId
Definition: advancedDetector.h:170
Definition: gamos.h:135
Definition: rect.h:524
Definition: stream.h:745
Definition: gamos.h:188
Definition: screen.h:48
Engine * g_engine
Definition: vm.h:105
uint32 flags
Definition: advancedDetector.h:207
Definition: detection.h:29
Definition: gamos.h:170
Definition: blit.h:28
Definition: vm.h:153
Common::Language language
Definition: advancedDetector.h:194
byte readByte()
Definition: stream.h:434
Definition: file.h:36
Definition: gamos.h:219
Definition: movie.h:32
Definition: keycodes.h:29
Definition: gamos.h:159
Definition: gamos.h:376
Definition: rect.h:144
void erase(uint32 p, uint32 len=npos)
Definition: gamos.h:308
Out move(In first, In last, Out dst)
Definition: algorithm.h:109
Definition: array2d.h:30
ADGameFileDescription filesDescriptions[14]
Definition: advancedDetector.h:189
Definition: vm.h:29
Definition: stream.h:351
Definition: proc.h:39
Definition: gamos.h:193
Definition: system.h:164
Definition: movie_decoder.h:32
Definition: engine.h:144
Definition: gamos.h:324
Definition: gamos.h:312
Language
Definition: language.h:45