Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jmatth11/hotreload-c
Simple setup to hotreload a C project. Setup is in SDL2.
https://github.com/jmatth11/hotreload-c
c hotreload sdl2 shared-library
Last synced: about 1 month ago
JSON representation
Simple setup to hotreload a C project. Setup is in SDL2.
- Host: GitHub
- URL: https://github.com/jmatth11/hotreload-c
- Owner: jmatth11
- License: gpl-3.0
- Created: 2024-07-25T03:16:25.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-07-25T03:27:56.000Z (5 months ago)
- Last Synced: 2024-07-25T04:29:07.556Z (5 months ago)
- Topics: c, hotreload, sdl2, shared-library
- Language: C
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hot-Reloading in C
This is a simple project to demonstrate how you can have a hot-reloading project in C.
I structure my program around SDL2 with a "game" concept, but the general idea should be transferrable.
## Main Loop
The core portion of this project is located in `main.c` and `driver/command.[h|c]`.
Main does general setup of SDL2 internals and handling the main loop.
We load in our shared library and have a simple even handler for the 'r' key to hotreload. (This should be able to be implmented in different ways, we use this for simplicity.)## Driver
The rest of our application is behind a "driver" file. Ours is located in `driver/driver.[h|c]`.
This is where we implement the expected functions defined in `driver/command.h` for our application.We have a little setup at the beginning of most functions to handle if we are hotreloaded at any instance.
Technically with our setup it only needs to be in the `event` function (as this is the next function that is called after hotreloading) but with different setups it could be setup
to hotreload at any instance.## Running this Project
Steps to running this project:
- Run `install_deps.sh` file.
- Run `make` to build the project.
- Run `./bin/hotreload` to run the executable.
- Make a change in `objects/player.c` in the render function.
- Run `make shared` to recompile the shared library.
- In the main application press the 'r' key to hot reload and your changes should show.## Demo
The demo is slightly older before I cleaned up the project, so ignore the old executable name.
https://github.com/user-attachments/assets/0ad69384-b061-440d-ac01-609439396c96