ssxog/docs/styleguide.md

134 lines
3.1 KiB
Markdown
Raw Normal View History

2022-06-18 02:54:01 -04:00
# SSX Decompilation Style Guide
Most of the documentation here is enforced by [clang-format](https://clang.llvm.org/docs/ClangFormat.html).
However, I've written other naming rules which aren't enforced down to make it more obvious, and to aid potentional contributors.
2022-06-18 02:54:01 -04:00
# Code Style
2022-06-18 03:04:15 -04:00
## Braces/Indentation
2022-06-18 02:54:01 -04:00
Any block scopes should have the brace on the next line, ala Allman bracing.
2022-06-18 02:54:01 -04:00
```cpp
if(1)
{
// do something
}
try
{
}
catch(...)
{
// An error occured
}
```
Tabs are used for indentation throughout the codebase.
## East/West Const/Volatile/...
2022-06-18 02:54:01 -04:00
It seems EA preferred west-const (where semantically possible), so, go west, collect 200$, get out of jail.
2022-06-18 02:54:01 -04:00
## Naming Rules
2022-06-18 02:54:01 -04:00
### Variables
2022-06-18 02:54:01 -04:00
Variable naming is not too complicated; just try to make it understandable.
2022-06-18 03:04:15 -04:00
There are the following special prefixes, used in certain scenarios:
2022-06-18 02:54:01 -04:00
| Name | Meaning/Scenario |
|------|-------------------------------------------|
| `m` | Class member (or static member) variable. |
| `g` | Global variable. |
2022-06-18 02:54:01 -04:00
### Types
BX/SSX types have a prefix before them, which is:
2022-06-18 02:54:01 -04:00
| Prefix | C++ Type |
|--------|-------------------------------------------------|
| `t` | `typedef struct` |
| `c` | `class/struct` |
| `T` | `template<> class/struct` (* Only seen in SSX3) |
2022-06-18 02:54:01 -04:00
Legacy types (REAL/SND) won't/don't need this due diligence, so it's ok to omit with those (as a matter of fact, it'd be more correct).
2022-06-18 02:54:01 -04:00
### Pointer/Reference Types
The pointer/reference goes on the side of the type, ala `T* name` and `T& name`.
2022-06-18 02:54:01 -04:00
### Functions
Function naming is PascalCase wherever possible, except for legacy code (specifically SND & REAL).
In this case, REAL/SND functions follow the following standard:
2022-06-18 02:54:01 -04:00
`[component/namespace, as uppercase]_[lowercase function name]`.
2022-06-18 02:54:01 -04:00
No functions should be annotated as `(void)` unless explicitly decompiled as C or exported in a C header file, as C++ ensures `()` is not surprising.
2022-06-18 02:54:01 -04:00
Member functions can use the longer `this->` access pattern for members if desired, but you don't have to unless you.. well, *have* to.
## Comments
Don't really care. If you think something might not be obvious, feel free to comment describing it.
If there's something surprising (or repulsive, considering 2000 C++), do so too.
## Example
Provided is an example of code fitting the style guide, to hopefully visualize things better.
2022-06-18 02:54:01 -04:00
```cpp
// A basic object.
class cBxObject
{
public:
int mCounter;
static int mVar;
uint32_t mUnsignedValue;
uint16_t mShort;
int16_t mSignedShort;
static uint16_t mStaticValue;
static int16_t mStaticSignedValue;
uint64_t mThing;
int64_t mSignedThing;
static int64_t mThingStatic;
static uint64_t mThingStatic;
int* mPointerVar;
2022-06-18 02:54:01 -04:00
// Morph
void Morph();
void ReferenceExample(int& output); // only for reference output
2022-06-18 02:54:01 -04:00
};
typedef struct
{
int Number;
void DoIt();
2022-06-18 02:54:01 -04:00
} tBxStructure;
// example of a legacy function and type name
FILEOP *FILE_dothing();
void cBxObject::Morph()
{
mCounter++;
if(mCounter == 32)
2022-06-18 02:54:01 -04:00
{
// Do something important.
}
}
```