-
Notifications
You must be signed in to change notification settings - Fork 175
Coding Conventions
This document outlines the coding convention that should be used when writing new code for OpenRW.
Sometimes when your pull is waiting for review, other ones can be merged. You will have to update your branch if merge conflicts occur. You can fix that by rebasing, which doesn't create unnecessary merge commits.
Steps:
-
git remote add upstream https://github.com/rwengine/openrw
-
git fetch upstream
-
git rebase upstream/master
If there's a conflict, you should also do:
- Resolve conflict
git add -A
git rebase --continue
The Google C++ style should be used for C++ code, with the following exceptions:
- Exceptions may be used for fatal situations that cannot be handled in any reasonable way
- e.g. the ScriptMachine throws when it encounters an instruction that isn't a valid opcode
- Indentation should be 4 spaces, as a good medium between horizontal space and clarity.
Dynamic allocations for large numbers of objects is discouraged. Large pools of objects should share allocations (however, this is not implemented yet).
Dynamically allocated objects should be owned by a smart pointer, with a preference for std::unique_ptr
. If it's not possible to declare a single ownership, then std::shared_ptr
should be used.
These are macros defined in rw/defines.hpp
that should be used to make the intended behaviour of code more clear:
- use RW_MESSAGE for debug messages that won't apppear in release
- use RW_UNIMPLEMENTED for noting that a particular feature is not yet implemented
- use RW_CHECK for non-fatal assertions
- Use targets and properties over variables where possible.
- use
CAPITAL_LETTERS
for variables- e.g.
set(FOO_PATH "/tmp/foo")
- e.g.
- use
lower_case
for functions- e.g.
add_executable(${EXECUTABLE_NAME} ${EXECUTABLE_SOURCES})
- e.g.
- use capitals for conditions
- e.g.
if(SOME_VAR STREQUAL "FOO")
- e.g.
- leave closing conditional statements empty
set(SOME_VAR FALSE)
if(NOT SOME_VAR)
message("SOME_VAR false")
else()
message("SOME_VAR not false")
endif()