-
Notifications
You must be signed in to change notification settings - Fork 6
/
conventions.txt
137 lines (111 loc) · 5.22 KB
/
conventions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
Buildat conventions
===================
C++ Coding style
----------------
Using the correct coding style is important. If you are asked to fix your style
to follow the one defined here in every detail, do it carefully.
If something is found to be missing from this document, such additions shall be
made.
util/codestyle.sh:
A code formatting script. Always run before committing. It handles most
whitespace issues. Requires Uncrustify (http://uncrustify.sourceforge.net/).
Commit your changes temporarily before running the script, as it will not save
any kind of backups of the files.
If something seems wrong or weird, use the -a flag to enable annotations in code
to check if the script knows what it's doing or not.
Identifiers:
- Class and struct names are CamelCase,
- All function names are lowercase_with_underscores,
- All variable names are lowercase_with_underscores,
- All member variables start with m_. If the struct in question is a stupid data
container, this does not need to be followed.
Never use "class", always use "struct".
Prefer lightweight interfaces with a creation function for the default
implementation, like "struct State" and "State* createState()". The default
implementation can be called "CState" in this case, if an obviously better name
does not exist.
Use std::unique_ptr and std::shared_ptr. (core/types.h: up_<> and sp_<>)
Header files must have zero preprocessor conditionals, with the exception of
headers in src/ports/.
Function naming:
- Suffix _u: Unsafe, not included in public interface
Naming:
- "type": Numeric id representing a type
- "name": A string; generally works as an identifier but not necessarily
- "id": Numeric id of an instance of something that is not a type
- "sub": Subscription; a means to trigger something based on something else
happening; data goes from the emitter to the subscriber
- "hook": A callback that can modify some of the source's data or behavior
before the source goes on with it
Logging:
- Use core/log.h. Only use stdout directly in case of an interactive command
line interface (like printing errors for command line arguments).
Ordering of #include directives:
1) The interface that the current file implements, ""
2) Internal interfaces, from core-ish to utility-ish, ""
3) Bundled libraries, <>
4) Installed libraries, <>
5) STL headers, <>
6) System headers, <>
Exceptions
----------
Do not use assert(); throw anonymous exceptions instead:
- if(fail) throw Exception("Thing failed");
In normal operation, zero exceptions should be thrown. Unless any potential bugs
are occurring, you should be able to play the game fine if you set a breakpoint
on a GCC Linux build to __cxa_throw, which will stop the program immediately
when an exception occurs.
Exceptions are allowed to occur when a resource has expired that the caller had
to expect to still be valid in order to avoid some kind of ridiculous code
structure.
Non-exception throwing and exception-throwing methods
-----------------------------------------------------
- get_x: Returns nullptr or equivalent if not found
- find_x: Returns nullptr or equivalent if not found
- check_x: Throws NullptrCatch if not found
To check for nullptr returned by get_x() or find_x(), use the check() function
in core/types.h.
Threads
-------
The program should always be debuggable with Helgrind and DRD, without false
positives.
Only use synchronization primitives that wrap pthreads, because that is what
Helgrind and DRD support.
If an object owns a thread, the thread should not be stopped in the object's
destructor. Instead the object should have thread_request_stop() and
thread_join() methods which should always be called before the object is
destructed. This allows fast parallel shutdown and better control over
destruction. You can skip this if you somehow can do it without Hellgrind and
DRD bitching at you though.
Directory structure
-------------------
├── 3rdparty << Bundled 3rd-party libraries
├── Build << Build files; "mkdir Build; cmake ..; make"
├── cache << Runtime directory used by Buildat
├── builtin << Built-in modules
├── client << Built-in client files
├── extensions << Built-in client extensions
├── src
│ ├── client << Client-specific code
│ ├── core << Core code (must be kept minimal but sufficient)
│ ├── impl << Interface implementations
│ ├── interface << Interface available to modules
│ └── server << Server-specific code
├── games << Games that can be run using buildat_server -m <path>
└── util << Miscellaneous development utilities
Commit messages
---------------
Commit messages must be formatted in the following way:
In present tense. Prepend a location to the message where possible. When adding
something, the "add" verb should be left out. Fine enough examples:
- client/sandbox.lua: Fix string concatenation when creating an error message
- interface::Server::check_module
- doc: conventions.txt, todo.txt
- Remove Module::test_add
- client, 3rdparty/c55lib: Command-line parameters
- 3rdparty/cereal
- client: Disable Urho3D log file
- extensions/__menu: Fix UI warnings
Urho3D
------
Urho3D's namespace should generally be aliased to be "magic".