Re:Non-Euclidean Worlds Engine [video]
by DoctorOetker on Thursday January 03, 2019 @12:26PM
(#18816935)
There's a short segment where CNLohr shows how he recompiles the code on the fly by using TCC (Tiny C Compiler). That seems rather useful to me, but I don't fully understand what determines which variables of state are persistent across recompilation. I have never used TCC before, but from a rudimentary search I learn you can pass a flag to compile & execute such that C can be used as if it was a scripting language. He mentions storing the environment in environment variables. Is he literally storing the position and orientation of the camera in the shell environment variables? or am I missing some other way to choose what parts of the state are persistent across on-the-fly recompilation?
[ Parent
| on HN ]
Here is an example level [0]. You can see some scripts in there enclosed by InitScript { … }, RunScript { … }. This gets parsed, compiled and called in [1]. In [2] you have your scripthelpers.h, defining what parts of the engine the script can see. On a first glance I don't see support for persistence across recompilation for scripting variables, and things like position/orientation of the camera are simply stored in the engine and not recompiled.
For a similar approach, see e.g. Interactive Programming in C [3], which relies on re-loading a shared (recompiled) library. But this step could also be done by recompiling via tcc. There the persistent data lives just in the heap and pointers to it get passed to the next version of the library.
[0] https://github.com/cnlohr/noeuclid/blob/0831b9ce21620704257a... [1] https://github.com/cnlohr/noeuclid/blob/0831b9ce21620704257a... [2] https://github.com/cnlohr/noeuclid/blob/a8e1e038829686f39d48... [3] https://nullprogram.com/blog/2014/12/23/