The shwompEngine is a minimal game engine built off of raylib designed to let you program without worry*.
* unless you're the problem.
Clone the repository with git clone https://github.com/maningreen/shwompEngine
The file structure is as follows
.
├── build
│ ├── core.o
│ ├── entity.o
│ ├── example.o
│ ├── init.o
│ ├── libengine.a
│ ├── main.o
│ ├── out
│ └── root.o
├── default.nix
├── external
│ └── raylib-5.5
│ ├── libraylib.a
│ ├── raylib.h
│ └── raymath.h
├── flake.lock
├── flake.nix
├── LICENSE
├── Makefile
├── README.md
├── shell.nix
└── src
├── engine
│ ├── core.cpp
│ ├── core.h
│ ├── entity.cpp
│ ├── entity.hpp
│ ├── main.cpp
│ ├── root.cpp
│ └── root.hpp
├── example.cpp
├── example.hpp
├── include.h
└── init.cpp
It's suggested you take a gander at everything in src/ and what's in src/engine/.
init.cpp (you don't have to name it that if you wish) must contain three function.
- init(Entity* root)`
- preRendering(Entity* root)
- postRendering(Entity* root)
init is called right after the root entity is initialised, and the window is opened. preRendering is called before render gets called on root, use for things like preprocessing postRendering is called right after render gets called on root, and after all children are rendered, use for things like drawing fps and postprocessing.
When you call killDefered() on root the window will close and your tree will be freed.
The Entity superclass has four virtual functions, these are
- process(float delta)
- render()
- postRender()
- init()
- death()
When they are called is as follows.
- process is called on each child of root, it goes parent -> children, so a parent and it's children will always be processed before that parent's sibling
- render is called on each child of root, however it goes from the bottom up, it will render the children of a parent before the parent.
- postRender is called right after all of the children of the node are rendered, similar to
death()it's niche but it has it's use cases. - init is called when children are added with the addChild(Entity* child) method, after the
Entity* parentis set. - death is called before the destructor of a given entity, this one is a little more niche but still useful. It's called before all the children of a given parent are killed. eg:
parent
└── child
└── child2 the second one
death on parent will be called before any of the children are murdered, then child's death will be called then child2 the second one's death will be called. After the method is called child2 the second one will be destructed, following will be child and parent.
Entity2D is a built in class that inherits from Entity, but with a Vector2 position field.
Using make has a few options
| Commands | Effects |
|---|---|
| make | builds all the .cpp files in src/ and src/engine |
| make clean | deletes everything in build/ |
| make run | everything make does and excecutes the output |
normally the output is build/out
if you really don't like that you can change that by
- going into the makefile, finding the line that says and change the variable
# CHANGE THIS TO BE YOUR EXCECUTABLE NAME
- going into the default.nix, finding the line that says and change the variable
# CHANGE THIS TO BE YOUR EXCECUTABLE NAME
Using nix is sugguested for development due to it's powerful nature.
to get started developing in nix you'd need nix flakes enabled, you can do this
To permanently enable flakes on nixos
nix.settings.experimental-features = [ "nix-command" "flakes" ];
then rebuild with
sudo nixos-rebuild switch
Add the following to your nix.conf
experimental-features = nix-command flakes
nix develop (flake) or nix-shell (stock)
will pop you into a shell with all of the dependancies installed, if you need more packages add them in the flake.nix
You can find nix packages here
And add them in the mkShell section in shell.nix and the buildInputs section in default.nix
There is one more type of entity, that being root. Root manages many things, those being
- window initialization
- rendering and processing of children
- closing windows
- refreshing the window In order to truly customise the engine you must customise the root entity class, it's source can be found in two files:
src/engine/root.hppsrc/engine/root.cpp
In order to change the visual backend to something you prefer here is what you would do.
- Install the library.
- Update values, this means going into
entity.hppand adjusting the fields such aspositionto another type. - Edit
root.hppto account for your backend - (Optional, but suggested) edit flake.nix to account for your packages.
If for some reason you think this project has any hopes of being useful, you can fork this repo and whence you add whatever you think is needed make a pull request.
external/raylib-5.5/libraylib.ais compiled for x86_64-linux.
I'm someone terminally bored. This is my first project that isn't crap.