2019-11-29 04:35:39 -05:00
### Guidelines
* Code should be C89 compatible and compilable as C++.
* Each .c file should represent a module. (see architecture.md for more details)
* Public functions and variables should be prefixed by module to avoid name collisions. (e.g. `Game_Reset` )
* Private functions should be named using pascal case. Prefixing module is optional - do it when it makes sense.
* Private variables don't really have a consistent style.
2018-07-03 03:07:38 -04:00
### Types
2019-11-29 04:35:39 -05:00
* Explicit integer typedefs are provided in ```Core.h``` for when needed. Otherwise just use int.
2018-09-15 06:47:06 -04:00
* A few common simple structs are typedef-ed, but are rarely otherwise.
2019-11-29 04:35:39 -05:00
* ```cc_bool``` is an alias for 8 bit unsigned integer
2018-07-03 03:07:38 -04:00
* ```PackedCol``` field order differs depending on the underlying 3D graphics API
2018-09-20 18:36:47 -04:00
I may not have defined the appropriate types for your compiler, so you may need to modify ```Core.h```
2018-07-03 03:07:38 -04:00
### Strings
Strings are one of the most troublesome aspects of C. In this software, strings consist of:
2018-09-05 18:36:20 -04:00
- Pointer to 8 bit characters (unsigned code page 437 indices)
2018-07-03 03:07:38 -04:00
- Number of characters currently used (length)
- Maximum number of characters / buffer size (capacity)
Although this makes substrings / concatenating very fast, it also means
2018-09-05 18:36:20 -04:00
**STRINGS ARE NOT NULL TERMINATED** (and are not in most cases).
2018-07-03 03:07:38 -04:00
2018-09-20 18:36:47 -04:00
Thus, when using or implementing a per-platform API, you must null-terminate and convert characters to native encoding. You should implement the ```Platform_ConvertString``` function and use that.
2018-09-05 18:36:20 -04:00
*Note: Several functions will take raw ```char*``` for performance, but this is not encouraged*
2018-07-03 03:07:38 -04:00
#### String arguments
2018-09-20 07:07:35 -04:00
String arguments are annotated to indicate storage and readonly requirements. These are:
- ```const String*``` - String is not modified at all
- ```String*``` - Characters in string may be modified
- ```STRING_REF``` - Macro annotation indicating a **reference is kept to characters**
2018-07-03 03:07:38 -04:00
To make it extra clear, functions with ```STRING_REF``` arguments usually also have ```_UNSAFE_``` as part of their name.
2018-09-20 07:07:35 -04:00
For example, consider the function ```String Substring_UNSAFE(STRING_REF const String* str, length)```
2018-07-03 03:07:38 -04:00
2018-09-20 07:07:35 -04:00
The *input string* is not modified at all. However, the characters of the *returned string* points to the characters of the *input string* , so modifying the characters in the *input string* also modifies the *returned string* .
In general, use of ```const String*``` is preferred when possible, and ```STRING_REF``` as little as possible.