109 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			109 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
# Conway's Game of Life SDL3 implementation
 | 
						|
 | 
						|
## Compiling
 | 
						|
 | 
						|
> Remember to `git submodule update --init --recursive`!
 | 
						|
 | 
						|
### Just use [`just`](https://just.systems/man/en/)
 | 
						|
 | 
						|
Use the justfile if you have `just` and `bear` installed:
 | 
						|
 | 
						|
`just configure` runs cmake configuration.
 | 
						|
 | 
						|
`just build` runs the cmake build and generates a `compile_commands.json` (assuming you have `bear` installed).
 | 
						|
 | 
						|
### CMake works too, I guess
 | 
						|
 | 
						|
`cmake -S. -Bbuild`
 | 
						|
 | 
						|
`cmake --build build`
 | 
						|
 | 
						|
Same as always
 | 
						|
 | 
						|
## Files
 | 
						|
 | 
						|
### simulation.h/cpp
 | 
						|
 | 
						|
The Conway's Game of Life generation ticking and rendering.
 | 
						|
 | 
						|
### thread_pool.h/cpp
 | 
						|
 | 
						|
Thread pool used for parallel GoL generation ticking.
 | 
						|
 | 
						|
### application.h/cpp
 | 
						|
 | 
						|
UI and layout logic.
 | 
						|
 | 
						|
### style.h/cpp
 | 
						|
 | 
						|
Reusable UI styling
 | 
						|
 | 
						|
### resources.h/cpp
 | 
						|
 | 
						|
Font loading.
 | 
						|
 | 
						|
### elements.h/cpp
 | 
						|
 | 
						|
Reusable UI elements
 | 
						|
 | 
						|
### input.h/cpp
 | 
						|
 | 
						|
Handling of input events.
 | 
						|
 | 
						|
### main.cpp:
 | 
						|
 | 
						|
Entrypoint, setup, and main application loop.
 | 
						|
 | 
						|
 | 
						|
## Prerequisites
 | 
						|
 | 
						|
* Compiler capable of C++23 and C23.
 | 
						|
 | 
						|
* CMake 3.21 or higher
 | 
						|
 | 
						|
## Dependencies
 | 
						|
 | 
						|
### SDL3
 | 
						|
 | 
						|
Included as git submodule at `vendor/SDL3/` and dynamically linked.
 | 
						|
 | 
						|
### SDL3_ttf
 | 
						|
 | 
						|
Included as git submodule at `vendor/SDL3_ttf/` and dynamically linked.
 | 
						|
 | 
						|
### Clay
 | 
						|
 | 
						|
Included as files in `vendor/clay/clay.h`; Single header library.
 | 
						|
 | 
						|
### Clay SDL3 renderer
 | 
						|
 | 
						|
Included as files in `vendor/renderer/` and compiled as part of the project.
 | 
						|
 | 
						|
## Code Standards
 | 
						|
 | 
						|
* Keep program structure as simple as possible. No `Application` class or other Java-isms. Prefer namespaces with static lifetime variables.
 | 
						|
 | 
						|
* Use STL where possible. Don't reinvent the wheel.
 | 
						|
 | 
						|
* K&R brackets. With notable exceptions(1)
 | 
						|
 | 
						|
* camelCase for variables, PascalCase for types and functions (that's what SDL and Clay do).
 | 
						|
 | 
						|
* In class member functions, always use `this->` to access member variables.
 | 
						|
 | 
						|
* const applies to the name to it's left, so it goes after the type, not `const int x;` but `int const x`.
 | 
						|
 | 
						|
* \* and & flush with the declaration name. `void Function(Object const &inRef)`
 | 
						|
 | 
						|
> (1) Bracket exceptions:
 | 
						|
> * using scoped_lock in arbitrary blocks, prefer tailed lisp brackets
 | 
						|
```
 | 
						|
void MyFunction() { // K&R here
 | 
						|
    DoAsynchronousThings();
 | 
						|
    { scoped_lock lock{ myMutex };
 | 
						|
        myVariable++;
 | 
						|
    } // not quite lisp, lisp with a tail
 | 
						|
    DoMoreAsynchronousThings();
 | 
						|
}
 | 
						|
```
 |