4.6 KiB
4.6 KiB
General rules
- Do not change code already written unless it's related to your contribution or absolutely needed.
- Please check and try to eliminate warnings from your code.
Code style
- 4 space indentation, LF line endings
- No hungarian notation [It's useless]
- In classes, use
m_prefix to nonstatic member variables andms_for static members. Do not use a prefix in structs. - Use
s_for global variables that are only used in one source file, otherwise useg_. - If some rule about something is not specified here, refer to how it's done in the code
- Some classes may have helper functions to make code more readable. (Denoted by NOTSA) - Try adding new ones, or looking for and using them.
- If you made helper functions in a source file, mark them as
static. - Prefer
get-ters/set-ters over raw member access - Use range-based for loops as much as possible.
- Use
rangesversions ofstdfunctions as much as possible. - Use
rng::instead ofstd::rangesandrngv::instead ofstd::views. - We encourage you to write modern C++, but if that's not your style, please keep the following in mind:
- Use
rangesversions ofstdfunctions as much as possible. - Use
rng::instead ofstd::rangesandrngv::instead ofstd::views.
for (auto& element : array); // <-- GOOD
for (int i = 0; i < std::size(array); i++); // <-- BAD
- Use
rngv::enumerateif you need both the index and object.
for (auto&& [i, e] : rngv::enumerate(array));
- If there's a dynamic
countvariable associated with a fixed size array, usestd::spanorrng::views::take. E.g.:
// Bad
for (auto i = 0u; i < m_numThings; i++);
// Good
for (auto& thing : std::span{ m_things, m_numThings });
// Also good
for (auto& thing : m_things | rng::views::take(m_numThings));
// ^ If these funcs are called more than once, make a helper function in the header. Like below:
auto GetActiveThings() {
return std::span{ m_things, m_numThings }
}
- Use
fin float literals [As omitting it would make them adouble] (e.g.1.0f) - Use
stdlibrary for generic functions likemin,max,lerp, etc... CVectoris interchangible with 3 floats [As isCVector2Dwith 2 floats] for function args- Use lambdas for repetitive procedures in functions
- Use
constexprvariables instead of macros - Use
static inlineinstead ofexternandstaticin headers:
class Foo {
static uint32& m_FooCount; // Bad
static inline auto& m_FooCount = StaticRef<uint32, 0xDEADBEEF>(); // Good
}
Types
- Use
autoin function bodies if the variables' type is guessable. - Guess for enum values [Or at least leave a
TODOcomment] - Take care of const correctness [Especially of class methods] (e.g.
const char*overchar*) - Try to use SA types over RW as much as possible, except
RwMatrix. (e.g.CVectorforRwV3d,CRGBAforRwRGBA) - Use fixed width integer types (e.g.
uint8,int32). - Do not use Win32 integer types. [Except for Win32 exclusive code] (e.g.
DWORD->uint32) - For array sizes, etc... prefer using
unsignedtypes oversignedones - Whenever possible use
std::arrayoverC-Stylearray [as the former has bounds checking in debug mode, and can help us discover many bugs]
Fixing bugs
Whenever you find a bug, we encourage you to fix it [and/or at least] leave a comment explaining what the bug is.
Bug fixes should only be active if notsa::IsFixBugs() returns true.
If that's not possible [due to code complexity], then wrap into an #ifdef:
#ifdef FIX_BUGS
// Bug fixing code here
#endif
Handling translated (GXT) text
- GXT code page is a partial superset of ASCII, it's one-to-one except for
^,[and]. (translated to¡,<and>respectively) - GXT encoded characters are 1-byte long and strings are null-terminated. They can be used in
chartyped C copy/compare functions. - Do not assume anything other than above for GXT strings.
- Use
AsciiToGxtCharandGxtCharToUTF8for safely converting. UTF-8 strings should be safe to print and manipulate in general. - Use
AsciiFromGxtChar(or""_gxtfor literals) andGxtCharFromAsciifor implicitly converting. You must be sure that all characters are ASCII.
Contributing
Please make sure to test your code before opening a PR. Guess what places/missions are affected by your code and test them. Use debug menu (F7) for quick access to stuff.
If you don't know how to test the code or think you have not tested enough specify it in the PR message.