Handmade Hero Day 021 - Loading Game Code Dynamically
Molly Rocket2 HN recommenders · recommended in 2 months, 2021–2024
tutorial · intermediate · evergreen · 2021–2024 on HN
Day 21 of Casey Muratori's Handmade Hero, which covers loading game code dynamically from a DLL on Windows. He builds hot reloading of C game code from scratch in about an hour and a half.
Recommended as a clear, from-scratch demonstration of how simple code hot-reloading is with plain OS facilities.
Up next
6 mo on HNSimple Code, High Performance
Molly Rocket
6 HN recommender · 2021–2025
10 mo on HNOverwatch Gameplay Architecture and Netcode
GDC Festival of Gaming
16 HN recommender · 2019–2025
9 mo on HNRustConf 2018 - Closing Keynote - Using Rust For Game Development by Catherine West
Rust Programming Language
9 HN recommender · 2018–2023
9 mo on HNA Deep Dive into Nanite Virtualized Geometry
SIGGRAPH Advances in Real-Time Rendering
7 HN recommender · 2021–2026
9 mo on HNHow Crash Bandicoot Hacked The Original Playstation | War Stories | Ars Technica
Ars Technica
13 HN recommender · 2020–2026
9 mo on HNJonathan Blow - How to program independent games - CSUA Speech
Alexandre Franco
9 HN recommender · 2015–2026
9 mo on HNIdeas about a new programming language for games.
Jonathan Blow
7 HN recommender · 2014–2025
7 mo on HNExploring the Tech and Design of Noita
GDC Festival of Gaming
7 HN recommender · 2020–2026
8 mo on HNCasey Muratori – The Big OOPs: Anatomy of a Thirty-five-year Mistake – BSC 2025
Better Software Conference
11 HN recommender · 2025–2026
7 mo on HNMiguel de Icaza: Swift Godot: Fixing the Multi-million dollar mistake #GodotCon2023
Godot Engine
6 HN recommender · 2023–2026
7 mo on HNQuakeCon 2012 - John Carmack Keynote
QuakeCon Official
6 HN recommender · 2012–2018
5 mo on HNCreating a Doom-style 3D engine in C
Bisqwit
3 HN recommender · 2015–2019
4 comments from Hacker News
In one of the earlier episodes of the Handmade Hero series, Casey Muratori writes a hot-reloading functionality for C from scratch in about an hour (while giving detailed explanations of what he's doing). The following two episodes then improve upon the initial results. ▶ this video
The first time I learned about dynamic loading was while watching an episode of Casey Muratori's Handmade Hero - a series where he builds a video game, in C, from scratch. He compiles the game code as a dll and dynamically loads it at runtime in the Win32 platform layer code. This way he can keep platform code and game code separate and reload the game code at runtime if any changes are made. Being new to this technique, I was impressed to say the least. I always assumed the same functionality was available in the linux environment, but I hadn't bothered to look it up. Now I know. For those who want to learn how to do this in Win32, here's the episode I mentioned above - ▶ this video
I don't think any game engine in use today except maybe the ultra-general ones would be without sections that are recompiled and reloaded live for gameplay code in this fashion. For all I know the ultra-general ones probably do it some stupidly complex way that sucks because they're overthinking things. Most setups will likely stream both code and assets to wherever the game is running while you're developing as well, but I wouldn't necessarily call that trivial. Recompiling a shared library and hot reloading it if it's changed is (on the order of 20 or so lines), though, and I wouldn't expect any game to be developed without at least some code being reloaded this way. While I haven't seen it as much, developing servers this way is also very doable, depending on how much you have to change data structures that have to be kept around. Edit: See ▶ this video for an example of how trivial it is to get this using just your OS facilities (`stat` + `LoadLibrary`/`dlopen`). None of this stuff is new and it's certainly been used with C/C++ or any language like it for a very, very long time.
Yes. On Rust specifically link (discussed here link ) And then there's this crate link which works on the same principles as the article above, and is based on C code (i.e. the same approach works for C). On the documentation there's links to "Interactive Programming in C" link and "Loading Game Code Dynamically" ▶ this video (this video by Casey Muratori is btw where I first heard about this technique) There's a bunch of other libraries that work the same way, and some example code that can do this. I can find link and link and link and link And there's link which has a nice API but uses a deprecated rustc internal API and doesn't build anymore. Anyway there was a library that did this in a more elegant way and I just can't find it (perhaps it was rust-hotswap?).