2024-10-04 01:00:02 -05:00
|
|
|
# Olympic Developer Handbook
|
2019-11-23 01:13:26 -06:00
|
|
|
|
2019-11-26 23:35:24 -06:00
|
|
|
## About
|
|
|
|
|
2021-07-17 18:16:32 -05:00
|
|
|
The purpose of the Developer Handbook is similar to that of the README.
|
|
|
|
The README should be viewed as a prerequisite to the Developer Handbook.
|
|
|
|
The README should provide information needed to build the project, which might
|
|
|
|
be used by an advanced user or a person trying to build and package the
|
|
|
|
project.
|
|
|
|
The Developer Handbook should focus on information needed by a developer
|
|
|
|
working on the project.
|
2019-11-26 23:35:24 -06:00
|
|
|
|
2019-11-23 01:13:26 -06:00
|
|
|
## Project Structure
|
|
|
|
|
|
|
|
### Overview
|
|
|
|
|
|
|
|
All components have a platform indicator next to them:
|
|
|
|
|
|
|
|
(PG) - PC, GBA
|
|
|
|
(-G) - GBA
|
|
|
|
(P-) - PC
|
|
|
|
|
|
|
|
* Nostalgia
|
2023-11-23 18:22:22 -06:00
|
|
|
* modules
|
|
|
|
* core - graphics system for Nostalgia (PG)
|
|
|
|
* gba - GBA implementation (PG)
|
|
|
|
* opengl - OpenGL implementation (P-)
|
|
|
|
* studio - studio plugin for core (P-)
|
|
|
|
* keel - keel plugin for core (PG)
|
|
|
|
* scene - defines & processes map data (PG)
|
|
|
|
* studio - studio plugin for scene (P-)
|
|
|
|
* keel - keel plugin for scene (PG)
|
2019-11-23 01:13:26 -06:00
|
|
|
* player - plays the games (PG)
|
|
|
|
* studio - makes the games (P-)
|
|
|
|
* tools - command line tools (P-)
|
|
|
|
* pack - packs a studio project directory into an OxFS file (P-)
|
2023-12-23 19:08:18 -06:00
|
|
|
* Olympic
|
|
|
|
* Applib - Library for creating apps as libraries that injects Keel and Studio modules
|
|
|
|
* Keel - asset management system (PG)
|
|
|
|
* Studio - where most of the studio code lives as library (P-)
|
|
|
|
* applib - used for per project studio executables
|
|
|
|
* modlib - used for studio modules to interact with studio
|
|
|
|
* Turbine - platform abstraction and user I/O (PG)
|
|
|
|
* gba - GBA implementation (PG)
|
|
|
|
* glfw - GLFW implementation (P-)
|
2019-11-23 01:13:26 -06:00
|
|
|
* deps - project dependencies
|
|
|
|
* Ox - Library of things useful for portable bare metal and userland code. Not really that external...
|
2022-02-10 02:05:11 -06:00
|
|
|
* clargs - Command Line Args processing (PG)
|
2020-07-29 00:26:20 -05:00
|
|
|
* claw - Reads and writes Metal or Organic Claw with header to indicate which
|
2024-10-04 01:00:02 -05:00
|
|
|
* event - Qt-like signal system (PG)
|
2019-11-23 01:13:26 -06:00
|
|
|
* fs - file system (PG)
|
2023-11-23 18:22:22 -06:00
|
|
|
* logconn - connects logging to Bullock (P-)
|
2019-11-23 01:13:26 -06:00
|
|
|
* mc - Metal Claw serialization, builds on model (PG)
|
2020-07-29 00:26:20 -05:00
|
|
|
* oc - Organic Claw serialization (wrapper around JsonCpp), builds on model (P-)
|
2019-11-23 01:13:26 -06:00
|
|
|
* model - Data structure modelling (PG)
|
2023-11-23 18:22:22 -06:00
|
|
|
* preloader - library for handling preloading of data (PG)
|
2019-11-23 01:13:26 -06:00
|
|
|
* std - Standard-ish Library with a lot missing and some things added (PG)
|
2023-12-23 19:08:18 -06:00
|
|
|
* GlUtils - OpenGL helpers (P-)
|
2023-11-23 18:22:22 -06:00
|
|
|
* teagba - GBA assembly startup code (mostly pulled from devkitPro under MPL
|
|
|
|
2.0), and custom GBA hardware interop code (-G)
|
2019-11-23 01:13:26 -06:00
|
|
|
|
2024-10-04 01:00:02 -05:00
|
|
|
Most GBA code is built on PC because it is small and helps to work on both
|
|
|
|
projects with the same CMake build dir, but GBA code is never linked with any
|
|
|
|
executables on PC.
|
|
|
|
|
2023-12-23 19:08:18 -06:00
|
|
|
## Platform Notes
|
|
|
|
|
|
|
|
### GBA
|
|
|
|
|
2023-12-29 19:02:38 -06:00
|
|
|
The GBA has two major resources for learning about its hardware:
|
|
|
|
|
|
|
|
* [Tonc](https://www.coranac.com/tonc/text/toc.htm) - This is basically a short
|
|
|
|
book on the GBA and low level development.
|
|
|
|
* [GBATEK](https://rust-console.github.io/gbatek-gbaonly/) - This is a more
|
|
|
|
concise resource that mostly tells about memory ranges and registers.
|
|
|
|
|
2023-12-23 19:08:18 -06:00
|
|
|
#### Graphics
|
|
|
|
|
|
|
|
* Background Palette: 256 colors
|
|
|
|
* Sprite Palette: 256 colors
|
|
|
|
|
2019-11-23 01:13:26 -06:00
|
|
|
## Code Base Conventions
|
|
|
|
|
|
|
|
### Formatting
|
|
|
|
|
|
|
|
* Indentation is done with tabs.
|
|
|
|
* Alignment is done with spaces.
|
|
|
|
* Opening brackets go on the same line as the thing they are opening for (if,
|
|
|
|
while, for, try, catch, function, etc.)
|
|
|
|
* No space between function parentheses and arguments.
|
|
|
|
* Spaces between arithmetic/bitwise/logical/assignment operands and operators.
|
|
|
|
* Pointer and reference designators should be bound to the identifier name and
|
2021-03-16 21:16:19 -05:00
|
|
|
not the type, unless there is not identifier name, in which case it should be
|
|
|
|
bound to the type.
|
2024-10-04 01:00:02 -05:00
|
|
|
* East const
|
2019-11-23 01:13:26 -06:00
|
|
|
|
2020-06-29 11:31:11 -05:00
|
|
|
### Write C++, Not C
|
|
|
|
|
|
|
|
On the surface, it seems like C++ changes the way we do things from C for no
|
|
|
|
reason, but there are reasons for many of these duplications of functionality.
|
2020-07-29 00:26:20 -05:00
|
|
|
The C++ language designers aren't stupid. Question them, but don't ignore them.
|
2020-06-29 11:31:11 -05:00
|
|
|
|
|
|
|
#### Casting
|
|
|
|
|
2021-07-17 18:16:32 -05:00
|
|
|
Do not use C-style casts.
|
|
|
|
C++ casts are more readable, and more explicit about the type of cast being
|
|
|
|
used.
|
|
|
|
Do not use ```dynamic_cast``` in code building for the GBA, as RTTI is disabled
|
|
|
|
in GBA builds.
|
2020-06-29 11:31:11 -05:00
|
|
|
|
|
|
|
#### Library Usage
|
|
|
|
|
2021-07-17 18:16:32 -05:00
|
|
|
C++ libraries should generally be preferred to C libraries.
|
|
|
|
C libraries are allowed, but pay extra attention.
|
2020-06-29 11:31:11 -05:00
|
|
|
|
|
|
|
This example from nostalgia::core demonstrates the type of problems that can
|
|
|
|
arise from idiomatically mixed code.
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
uint8_t *loadRom(const char *path) {
|
|
|
|
auto file = fopen(path, "r");
|
|
|
|
if (file) {
|
|
|
|
fseek(file, 0, SEEK_END);
|
|
|
|
const auto size = ftell(file);
|
|
|
|
rewind(file);
|
2022-02-26 22:52:35 -06:00
|
|
|
// new can technically throw, though this project considers out-of-memory
|
|
|
|
// to be unrecoverable
|
2020-06-29 11:31:11 -05:00
|
|
|
auto buff = new uint8_t[size];
|
|
|
|
fread(buff, size, 1, file);
|
|
|
|
fclose(file);
|
|
|
|
return buff;
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
In practice, that particular example is not something we really care about
|
|
|
|
here, but it does demonstrate that problems can arise when mixing what might be
|
|
|
|
perceived as cool old-school C-style code with lame seemingly over-complicated
|
|
|
|
C++-style code.
|
|
|
|
|
|
|
|
Here is another more concrete example observed in another project:
|
|
|
|
```cpp
|
|
|
|
int main() {
|
|
|
|
// using malloc does not call the constructor
|
|
|
|
std::vector<int> *list = (std::vector<int>*) malloc(sizeof(std::vector<int>));
|
|
|
|
doStuff(list);
|
2022-02-26 22:52:35 -06:00
|
|
|
// free does not call the destructor, which causes memory leak for array
|
|
|
|
// inside list
|
2020-06-29 11:31:11 -05:00
|
|
|
free(list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
The code base where this was observed actually got away with this for the most
|
2021-02-26 08:55:40 -06:00
|
|
|
part, as the std::vector implementation used evidently waited until the
|
2020-06-29 11:31:11 -05:00
|
|
|
internal array was needed before initializing and the memory was zeroed out
|
2021-07-17 18:16:32 -05:00
|
|
|
because the allocation occurred early in the program's execution.
|
|
|
|
While the std::vector implementation in question worked with this code and the
|
|
|
|
memory leak is not noticeable because the std::vector was meant to exist for
|
|
|
|
the entire life of the process, other classes likely will not get away with it
|
|
|
|
due to more substantial constructors and more frequent instantiations of the
|
|
|
|
classes in question.
|
2020-06-29 11:31:11 -05:00
|
|
|
|
2021-10-23 14:10:16 -05:00
|
|
|
## Project Systems
|
2019-11-23 01:13:26 -06:00
|
|
|
|
2024-10-04 01:00:02 -05:00
|
|
|
Olympic builds on Ox as its standard-ish library.
|
|
|
|
Please read the [Ox documentation](deps/ox/ox-docs.md).
|
|
|
|
The Ox way of doing things is the Olympic way of doing things.
|
2021-03-18 01:33:29 -05:00
|
|
|
|
2020-06-29 11:31:11 -05:00
|
|
|
### File I/O
|
2020-01-24 18:55:29 -06:00
|
|
|
|
2024-10-04 01:00:02 -05:00
|
|
|
All engine file I/O should go through Keel, which should go through
|
|
|
|
```ox::FileSystem```.
|
|
|
|
Similarly, all studio file I/O should go thorough
|
|
|
|
```nostalgia::studio::Project```, which should go through ```ox::FileSystem```.
|
2021-05-03 20:51:56 -05:00
|
|
|
|
2024-10-04 01:00:02 -05:00
|
|
|
```ox::FileSystem``` abstracts away differences between conventional storage
|
|
|
|
devices and ROM.
|
2021-05-03 20:51:56 -05:00
|
|
|
|
2024-10-04 01:00:02 -05:00
|
|
|
Olympic files are generally just [Claw objects](deps/ox/ox-docs.md#serialization).
|
2021-05-03 20:51:56 -05:00
|
|
|
|
2024-10-04 01:00:02 -05:00
|
|
|
#### Keel
|
2021-05-03 20:51:56 -05:00
|
|
|
|
2024-10-04 01:00:02 -05:00
|
|
|
Keel, as its name implies, is a foundational component of Olympic.
|
|
|
|
Keel is the asset management system.
|
2021-05-03 20:51:56 -05:00
|
|
|
|
2024-10-04 01:00:02 -05:00
|
|
|
Keel provides for the following needs:
|
2021-05-03 20:51:56 -05:00
|
|
|
|
2024-10-04 01:00:02 -05:00
|
|
|
* Type conversion
|
|
|
|
* Asset bundling
|
|
|
|
* Asset loading (including flyweighting on PC and preloading to ROM on the GBA)
|