Coding Conventions

From ScummVM :: Wiki
Revision as of 10:37, 22 March 2007 by Fingolfin (talk | contribs) (Added an initial simple porting guide)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Work in progress: This page is meant to list all sorts of typical portability issues that people working on ScummVM have to keep in mind. We should probably link on some nice well-established web pages for that on the net, and only focus on the most frequent or maybe unusual (ScummVM specific) issues.

Language features

ScummVM is written in a subset of C++. Due to limitations of the C++ run-times on various platforms, the following features can't be used:

  • C++ exceptions (throw/catch)
  • C++ RTTI (run-time type information, as in dynamic_cast<>)

Furthermore, the standard C++ library is a big no-no. Besides usually heavily relying on the above mentioned features, it also sucks up rather more resources than we'd like to, so we have our own replacements for various container classes etc.

We are reviewing these decisions from time to time, but so far, in our estimation the drawbacks of using any of these outweigh the hypothetical advantages.

Endianess issues

If you don't know what "Endianess issues" refers to, read up here:

ScummVM engine authors have to keep endianess issues in mind for two reasons:

  • ScummVM runs on both little endian (Windows, Intel Mac OS X, Intel Linux, ...) and big end hosts (PowerPC Mac OS X, ...). So when writing data (think savegames) to files and reading it back again, you need to compensate for this. This is easily done by using the READ_ and WRITE_ macros from common/endian.h (like READ_LE_UINT32 or WRITE_BE_UINT16.) resp. the corresponding Stream class methods (like readUint32LE or writeUint16BE)
  • Furthermore, some games existed in multiple versions, e.g. one for Windows and one for MacOS. In that case, you may have to detect and distinguish these versions and employ differnt reading calls, to compensate for endian differences in the game data files.

File access

TODO: Talk about file reading/writing, SaveFile vs. File, FSNodes vs. Paths, etc. -- maybe wait until the SoC, though? *g*