Open main menu

Difference between revisions of "Coding Conventions"

54 bytes added ,  15:16, 25 October 2018
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - "<source lang=" to "<syntaxhighlight lang=")
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 31: Line 31:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
   #include "common/pack-start.h" // START STRUCT PACKING
   #include "common/pack-start.h" // START STRUCT PACKING
</source>
</syntaxhighlight>
* After the struct(s) you need to be packed, insert
* After the struct(s) you need to be packed, insert
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
   #include "common/pack-end.h" // END STRUCT PACKING
   #include "common/pack-end.h" // END STRUCT PACKING
</source>
</syntaxhighlight>
* At the "end" of each struct you need to be packed, insert the following between the closing } and the ; after it:
* At the "end" of each struct you need to be packed, insert the following between the closing } and the ; after it:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
   PACKED_STRUCT
   PACKED_STRUCT
</source>
</syntaxhighlight>
You may want to look at some files which already do that, e.g. look at <code>engines/scumm/boxes.cpp</code>
You may want to look at some files which already do that, e.g. look at <code>engines/scumm/boxes.cpp</code>


Line 61: Line 61:
     return bar;
     return bar;
   }
   }
</source>
</syntaxhighlight>
Suppose this function is part of engine quux. When a new game using this engine is started, foo(false) will initially always return false. After foo(true) has been called the first time, foo will always return true. Maybe foo(true) is called when the user/player solves a certain puzzle in the game, and maybe the foo() function is meant to test whether this puzzle has already been solved.
Suppose this function is part of engine quux. When a new game using this engine is started, foo(false) will initially always return false. After foo(true) has been called the first time, foo will always return true. Maybe foo(true) is called when the user/player solves a certain puzzle in the game, and maybe the foo() function is meant to test whether this puzzle has already been solved.
Now imagine the player uses the "return to launcher" feature; once back in the launcher, they restart the game, again using the quux engine.
Now imagine the player uses the "return to launcher" feature; once back in the launcher, they restart the game, again using the quux engine.
Line 69: Line 69:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
   static int myGlobal = 0;
   static int myGlobal = 0;
</source>
</syntaxhighlight>
is ''not'' sufficient.
is ''not'' sufficient.


Line 77: Line 77:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
   // FIXME: non-const global var
   // FIXME: non-const global var
</source>
</syntaxhighlight>


As a minor exception, if an existing engine uses many globals (due to not (yet) being objectified), it is permissible to use a single comment to document multiple globals at once.
As a minor exception, if an existing engine uses many globals (due to not (yet) being objectified), it is permissible to use a single comment to document multiple globals at once.
TrustedUser
2,147

edits