Open main menu

Difference between revisions of "HOWTO-Engines"

911 bytes added ,  14:24, 19 September 2007
Describe common function wrappers, types and random sources
(Added a brief section about infrastructure and scummsys.h, update source code.)
(Describe common function wrappers, types and random sources)
Line 70: Line 70:


TODO: give descriptions for other commonly used header files.
TODO: give descriptions for other commonly used header files.
=== Common portability issues ===
There are wrapper around number of non-portable functions. These are:
  max() -> MAX()
  min() -> MIN()
  rand() -> use Common::RandomSource class
  stricmp() -> scumm_stricmp()
  strnicmp() -> scumm_strnicmp()
  strrev() -> scumm_strrev()
Also we have predefined common integer types. Please, use them instead of rolling your own:
  byte
  int8
  uint8
  int16
  uint16
  int32
  uint32
Additionally ScummVM offers way of recording all events and then playing them back on request. That could be used for "demoplay" mode. But to ensure that it will work for your engine, you have to register your RandomSource class instance. See example engine below.


=== Example: engines/quux/quux.h ===
=== Example: engines/quux/quux.h ===
Line 99: Line 121:
private:
private:
Console *_console;
Console *_console;
// We need random numbers
Common::RandomSource _rnd;
};
};


Line 116: Line 141:
<pre>
<pre>
#include "common/scummsys.h"
#include "common/scummsys.h"
#include "common/events.h" // for getEventManager()


#include "backends/fs/fs.h"
#include "backends/fs/fs.h"
Line 185: Line 211:
Common::addSpecialDebugLevel(kQuuxDebugExample, "example", "this is just an example for a engine specific debug level");
Common::addSpecialDebugLevel(kQuuxDebugExample, "example", "this is just an example for a engine specific debug level");
Common::addSpecialDebugLevel(kQuuxDebugExample2, "example2", "also an example");
Common::addSpecialDebugLevel(kQuuxDebugExample2, "example2", "also an example");
// Don't forget to register your random source
syst->getEventManager()->registerRandomSource(_rnd, "quux");


printf("QuuxEngine::QuuxEngine\n");
printf("QuuxEngine::QuuxEngine\n");