<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openclonk.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Loriel</id>
	<title>OpenClonk Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openclonk.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Loriel"/>
	<link rel="alternate" type="text/html" href="https://wiki.openclonk.org/w/Special:Contributions/Loriel"/>
	<updated>2026-04-29T01:02:09Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.44.5</generator>
	<entry>
		<id>https://wiki.openclonk.org/index.php?title=Source_code_structure&amp;diff=458</id>
		<title>Source code structure</title>
		<link rel="alternate" type="text/html" href="https://wiki.openclonk.org/index.php?title=Source_code_structure&amp;diff=458"/>
		<updated>2010-04-03T14:51:26Z</updated>

		<summary type="html">&lt;p&gt;Loriel: Link to Peter&amp;#039;s post on the main loop&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== The basic structure of Clonk ==&lt;br /&gt;
&lt;br /&gt;
This page is supposed to explain OpenClonk&#039;s source code design in a graphical manner. That will help with finding a particular code snippet which might be affected by source changes. Other than that it gives a basic understanding how the seperate components of OpenClonk work together.&lt;br /&gt;
&lt;br /&gt;
* PeterW posted a [http://forum.openclonk.org/topic_show.pl?pid=3096#pid3096 a summary of the main loop] on the forum&lt;/div&gt;</summary>
		<author><name>Loriel</name></author>
	</entry>
	<entry>
		<id>https://wiki.openclonk.org/index.php?title=Style_Guidelines&amp;diff=429</id>
		<title>Style Guidelines</title>
		<link rel="alternate" type="text/html" href="https://wiki.openclonk.org/index.php?title=Style_Guidelines&amp;diff=429"/>
		<updated>2010-03-26T19:26:11Z</updated>

		<summary type="html">&lt;p&gt;Loriel: Spaces for operators&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This document specifies the preferred source code style of files inside the&lt;br /&gt;
OpenClonk source tree. Some of the style rules are also stated implicitly&lt;br /&gt;
inside the examples.&lt;br /&gt;
&lt;br /&gt;
=== All-encompassing Guidelines ===&lt;br /&gt;
==== Line endings ====&lt;br /&gt;
Use a single line feed character (ASCII 10) for line endings. Mercurial provides&lt;br /&gt;
an extension named &#039;&#039;win32text&#039;&#039; you can use to auto-convert files from your&lt;br /&gt;
OS&#039;s native format to single LF and vice-versa.&lt;br /&gt;
&lt;br /&gt;
==== Indentation ====&lt;br /&gt;
Indent your code with tabs (ASCII 9). Use space (ASCII 32) for all other&lt;br /&gt;
formatting.&lt;br /&gt;
&lt;br /&gt;
==== Braces ====&lt;br /&gt;
Braces are on their own line, on the same level of indentation as the&lt;br /&gt;
structure they belong to. You may add braces around single statements in&lt;br /&gt;
&amp;lt;tt&amp;gt;if&amp;lt;/tt&amp;gt; statements if the first block or an &amp;lt;tt&amp;gt;else&amp;lt;/tt&amp;gt; block has them.&lt;br /&gt;
&lt;br /&gt;
 if (count &amp;lt; 10)&lt;br /&gt;
 {&lt;br /&gt;
 	printf(&amp;quot;Too few thingies!&amp;quot;);&lt;br /&gt;
 	AddMore();&lt;br /&gt;
 }&lt;br /&gt;
 else&lt;br /&gt;
 {&lt;br /&gt;
 	printf(&amp;quot;We have enough&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Spaces ====&lt;br /&gt;
Function names are not followed by space. Commas are. No space follows opening&lt;br /&gt;
brackets (&amp;quot;[&amp;quot;) or parentheses (&amp;quot;(&amp;quot;). Also no space preceeds closing brackets&lt;br /&gt;
(&amp;quot;]&amp;quot;) or parentheses (&amp;quot;)&amp;quot;), or commas. &amp;quot;::&amp;quot;, &amp;quot;-&amp;gt;&amp;quot;, &amp;quot;.&amp;quot; and unary operators do not&lt;br /&gt;
require spaces. Other binary operators do.&lt;br /&gt;
&lt;br /&gt;
Keywords (&amp;lt;tt&amp;gt;while&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt; etc.) are followed by a space.&lt;br /&gt;
&lt;br /&gt;
==== Parentheses ====&lt;br /&gt;
Do not use parentheses unless they are required for precedence or the code&lt;br /&gt;
gets confusing without them. Remember other people may have confusion&lt;br /&gt;
thresholds different from you.&lt;br /&gt;
&lt;br /&gt;
==== Control Structures ====&lt;br /&gt;
Control structures with a single statements are written without braces. If the&lt;br /&gt;
statement spans multiple lines, you may add braces for readability. Structures&lt;br /&gt;
without a statement contain a comment denoting this.&lt;br /&gt;
&lt;br /&gt;
 while (*dest++ = *src++)&lt;br /&gt;
 	/* empty */;&lt;br /&gt;
&lt;br /&gt;
Cascades in a &amp;lt;tt&amp;gt;switch&amp;lt;/tt&amp;gt; statement are marked by a FALLTHROUGH&lt;br /&gt;
comment. Code that cannot be reached has an assertion. &amp;lt;tt&amp;gt;case&amp;lt;/tt&amp;gt; elements&lt;br /&gt;
are not indented.&lt;br /&gt;
&lt;br /&gt;
 switch (foo)&lt;br /&gt;
 {&lt;br /&gt;
 case FOO_HEX:&lt;br /&gt;
 	accept_hex = true;&lt;br /&gt;
 	// FALLTHROUGH&lt;br /&gt;
 case FOO_DEC:&lt;br /&gt;
 	accept_num = true;&lt;br /&gt;
 	break;&lt;br /&gt;
 default:&lt;br /&gt;
 	assert(!&amp;quot;Invalid foo value&amp;quot;);&lt;br /&gt;
 	// Do something meaningful here anyway, if possible;&lt;br /&gt;
 	// try to not leave the program in an ill-defined state.&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Comments ====&lt;br /&gt;
 // Single-line comments look like this&lt;br /&gt;
&lt;br /&gt;
 // Multi-line comments look like this. Using C++-style comments&lt;br /&gt;
 // helps if you need to comment out large pieces of code later, or if the length of&lt;br /&gt;
 // the comment changes over time. Of course you could still use #if 0 ... #endif&lt;br /&gt;
 // to achieve that.&lt;br /&gt;
&lt;br /&gt;
 /* You may also write multi-line comments like this. Make sure you write enough&lt;br /&gt;
    text to warrant a multi-line comment. Also be sure to write in full sentences. */&lt;br /&gt;
&lt;br /&gt;
==== Type Casting ====&lt;br /&gt;
Do not use C-style or function style casts. Use a template cast instead.&lt;br /&gt;
&lt;br /&gt;
=== Source File Layout ===&lt;br /&gt;
==== Copyright Header ====&lt;br /&gt;
Every source file begins with a copyright header. If you make significant&lt;br /&gt;
changes to the code, you may (but are not required to) add your name to the&lt;br /&gt;
list of copyright holders. If you choose to add yourself, use your real name,&lt;br /&gt;
not a nickname. Legally recognized pseudonyms are accepted, as are names of&lt;br /&gt;
legal entities. If you don&#039;t want to add yourself, you may add the catch-all&lt;br /&gt;
copyright attribution phrase, if it does not already exist.&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * OpenClonk, http://www.openclonk.org&lt;br /&gt;
  *&lt;br /&gt;
  * Copyright (c) 2000-2009  John Doe&lt;br /&gt;
  * Copyright (c) 2005  Jane Q. Public&lt;br /&gt;
  *&lt;br /&gt;
  * Portions might be copyrighted by other authors who have contributed&lt;br /&gt;
  * to OpenClonk.&lt;br /&gt;
  *&lt;br /&gt;
  * Other legalese goes here, but has been omitted for brevity. See an&lt;br /&gt;
  * existing file for a template.&lt;br /&gt;
  */&lt;br /&gt;
&lt;br /&gt;
The copyright header is followed by an empty line. Put a comment explaining&lt;br /&gt;
the purpose of the file next, and leave another blank line after this.&lt;br /&gt;
&lt;br /&gt;
==== Inclusion Guards ====&lt;br /&gt;
If you are writing a header file, use #include guards. If your file is called&lt;br /&gt;
&#039;&#039;C4Foo.h&#039;&#039;, your guard should be &amp;lt;tt&amp;gt;INC_&#039;&#039;C4Foo&#039;&#039;&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 #ifndef INC_C4Foo&lt;br /&gt;
 #define INC_C4Foo&lt;br /&gt;
 class C4Foo;&lt;br /&gt;
 #endif&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;TODO: Precompiled headers.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== #include Directives ====&lt;br /&gt;
Include local headers first. Put the filename in double quotes, and use&lt;br /&gt;
forward slashes as directory separators.&lt;br /&gt;
&lt;br /&gt;
 #include &amp;quot;Standard.h&amp;quot;&lt;br /&gt;
 #include &amp;quot;StdBuf.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Leave a blank line before system headers. Use angle brackets to include these,&lt;br /&gt;
and sort them alphabetically.&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;map&amp;gt;&lt;br /&gt;
 #include &amp;lt;vector&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Declarations ===&lt;br /&gt;
==== Preprocessor Macros ====&lt;br /&gt;
Do not &amp;lt;tt&amp;gt;#define&amp;lt;/tt&amp;gt; values in headers. Use &amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt; instead, or&lt;br /&gt;
&amp;lt;tt&amp;gt;enum&amp;lt;/tt&amp;gt; if you are declaring an enumeration.&lt;br /&gt;
&lt;br /&gt;
Do not &amp;lt;tt&amp;gt;#define&amp;lt;/tt&amp;gt; inline functions either, use &amp;lt;tt&amp;gt;inline&amp;lt;/tt&amp;gt;. If your&lt;br /&gt;
functions need to work on multiple data types, overload the function or write&lt;br /&gt;
a &amp;lt;tt&amp;gt;template&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If, despite of the above, you still need to write a macro, use an all-uppercase&lt;br /&gt;
name. If your macro contains a compound statement, enclose it in a &amp;lt;tt&amp;gt;do&amp;lt;/tt&amp;gt;&lt;br /&gt;
loop to allow its use in &amp;lt;tt&amp;gt;if&amp;lt;/tt&amp;gt; statements. A terminating semicolon&lt;br /&gt;
should be provided at the place of invocation. This makes parsing the source&lt;br /&gt;
easier for pretty-printers and editors. Consider undefining your macro when&lt;br /&gt;
you are done using it.&lt;br /&gt;
&lt;br /&gt;
 #define FOO(a, b) do { \&lt;br /&gt;
 	bar += (a); \&lt;br /&gt;
 	bar /= (b); \&lt;br /&gt;
 } while(0)&lt;br /&gt;
&lt;br /&gt;
==== Data Types ====&lt;br /&gt;
Do not use the Win32 style integer declarations &amp;lt;tt&amp;gt;DWORD&amp;lt;/tt&amp;gt; and&lt;br /&gt;
&amp;lt;tt&amp;gt;BOOL&amp;lt;/tt&amp;gt;. If you need a guarantee about the size of your variables, use&lt;br /&gt;
the C99 types &amp;lt;tt&amp;gt;int&#039;&#039;XX&#039;&#039;_t&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;uint&#039;&#039;XX&#039;&#039;_t&amp;lt;/tt&amp;gt;. If you don&#039;t&lt;br /&gt;
need that guarantee, use &amp;lt;tt&amp;gt;int&amp;lt;/tt&amp;gt;. If you need a variable that is large&lt;br /&gt;
enough to store a pointer on your current platform, use &amp;lt;tt&amp;gt;intptr_t&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you come across code that still uses Win32 types, consider changing it if&lt;br /&gt;
you are working on code in the vicinity. Don&#039;t commit changes that only&lt;br /&gt;
consist of replacing &amp;lt;tt&amp;gt;DWORD&amp;lt;/tt&amp;gt; by &amp;lt;tt&amp;gt;uint32_t&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When declaring a pointer, put a space in front of the asterisk, and none&lt;br /&gt;
after. This saves some confusion when declaring multiple variables at once.&lt;br /&gt;
The same goes for references.&lt;br /&gt;
&lt;br /&gt;
 int *foo, *bar;&lt;br /&gt;
 char *Qux(const char *quux);&lt;br /&gt;
&lt;br /&gt;
==== Functions ====&lt;br /&gt;
Functions that are not used outside of the containing file are placed inside&lt;br /&gt;
of an anonymous namespace.&lt;br /&gt;
&lt;br /&gt;
 namespace&lt;br /&gt;
 {&lt;br /&gt;
 	int Frobnicate(const char *foo);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Functions that are used across multiple files are prototyped inside a common&lt;br /&gt;
header. The prototypes should be grouped where appropriate, and ordered&lt;br /&gt;
logically or, failing that, alphabetically.&lt;br /&gt;
&lt;br /&gt;
Function and class names begin with a capital letter, and use camel casing. If&lt;br /&gt;
you need to embed acronyms inside the name, pretend the acronym was all lower&lt;br /&gt;
case. Member variables use the same convention, but begin with a lower case&lt;br /&gt;
letter. Do not use hungarian prefixes.&lt;br /&gt;
&lt;br /&gt;
 XmlDocument *ParseXmlFile(const char *file);&lt;br /&gt;
&lt;br /&gt;
When passing arguments that may be changed by the called function, pass them&lt;br /&gt;
as pointers. This makes it obvious that they may be changed. Use constant&lt;br /&gt;
references for all other parameters, unless they are a primitive type.&lt;br /&gt;
&lt;br /&gt;
==== Class Members ====&lt;br /&gt;
No class member variable should be declared &amp;lt;tt&amp;gt;public&amp;lt;/tt&amp;gt; unless necessary.&lt;br /&gt;
Consider using &amp;lt;tt&amp;gt;GetFoo&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;SetFoo&amp;lt;/tt&amp;gt; accessors. If you want to &lt;br /&gt;
declare a compound data type that allows direct access to its members, use&lt;br /&gt;
&amp;lt;tt&amp;gt;struct&amp;lt;/tt&amp;gt;. Do not add more functions than constructors, destructors, and&lt;br /&gt;
assignment operators to &amp;lt;tt&amp;gt;struct&amp;lt;/tt&amp;gt;s.&lt;br /&gt;
&lt;br /&gt;
Mark all class members that do not change the visible state of the object&lt;br /&gt;
&amp;lt;tt&amp;gt;const&amp;lt;/tt&amp;gt;. If you need to modify internal state that is not visible from&lt;br /&gt;
outside of the class, mark the state variable &amp;lt;tt&amp;gt;mutable&amp;lt;/tt&amp;gt;.&lt;/div&gt;</summary>
		<author><name>Loriel</name></author>
	</entry>
</feed>