5 ms·
Code, Eval, Play, Loop – Common Lisp OpenGL Environment
- orbifold 12y agoNot to take anything away from that, because it's awesome, but that can also be accomplished in C. In fact pretty much any good game engine supports both dynamic shader recompilation, hot swapping the renderer and dynamically reloading the game code. A classic example where this technique is implemented is Quake 2. Basically the renderer and game are linked into the client as dynamic libraries and reloaded on demand or when a change is detected.
- yarrel 12y agoRebuilding those dynamic libraries requires external build system and compiler invocation. In Lisp you just use the REPL.
- orbifold 12y agoOf course, but in practice that doesn't really matter. Recompilation time for small changes is negligible and if you have a sane build system setup is pretty much invoked the same way you would load new code into a repl. In the case of shader compilation, compiling and linking actually is exposed as library functions, so you have complete control over how to do that. Most of the dynamic features a repl provides, like introspection and so on is also available with a good debugger, depending on the scope of the project you can also just use Lua as a scripting language to get the majority of the benefits that Lisp has. Moreover nested parentheses sort of pale, if you can visualize most of your state in much more powerful ways on the screen. Since you have complete control over memory, you can implement time travelling debugging pretty easily, you just need a good ordinary debugger, a way to record all input to the game (easily done if you have clean separation between game and platform code) and a way to snapshot the game state at some point in time (also easy if you allocate all memory ahead of time and only let the game code use your memory allocators).
- malisper 12y agoCould you redefine a class/structure and update every instance of it at runtime? For example, let's say you are currently representing complex numbers in rectangular form. Is it possible to convert every existing instance to polar form, at runtime, without breaking any code?
- orbifold 12y agoWell no, the representation of game state and input have to remain the same ^1. I guess in lisp you could more easily write a function that maps the previous representation into the new one. Here is an example of what kind of interactive code reloading I have in mind: https://www.youtube.com/watch?v=xrUSrVvB21c https://www.youtube.com/watch?v=xrUSrVvB21c Admittedly it is more of a hack than in a Common Lisp system, but still. 1) EDIT: At least in the most simple design. Nothing prevents you from optionally stopping the simulation, serialize a snapshot of the sate to disk, change the representation of complex numbers or whatever, together with the data serialization routines and continue.
- malisper 12y ago> I guess in lisp you could more easily write a function that maps the previous representation into the new one. Lisp provides a simple way redefine classes. There is a generic function (basically a function that is extensible), update-instance-for-redefined-class[0], which is called on instances of the old representation to map them to the new one. All a programmer has to do is extend it with the behavior they want. Coincidentally, the link I gave shows how to do this to change the representation of a point from Cartesian coordinates to polar coordinates. [0] http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/stagenfun_upd_efined-class.html http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec...
- yoklov 12y agoThat's a pretty ridiculous use case. I'd think if you wanted to make a change this drastic, having to reload the game wouldn't be a huge deal. I mean, you'd want to make sure everything up to the point you were at still works anyway. (Besides, this is an awful way to represent 2D points in practice). FWIW, It's certainly possible to write code that reorders struct fields on changes, but it requires either boilerplate, macro hell, or parsing part of your C code for structure declarations (I've heard this sounds worse than it is). Arbitrary mappings are more difficult and IMO not worth the trouble. Not to say this technique doesn't have downsides. It's downsides are so huge that IMO it's benefits aren't worth it, unless you were already going to program in that style to begin with. - No pointers to static memory (globals, vtables, and pointers to string literals or constant arrays are out) - No pointers to functions (most other ways of emulating dynamic dispatch are out). - You need to use custom allocators that work out of your game state block. And since you have no global or thread local state... you need to hope that any library you want to use allows you to provide a context for any memory allocation it wants to do. Most don't. - etc, etc, etc... you get the picture. Essentially, you need to write your game like its 1995. And sure, maybe you can get this in lisp without any limitations (I don't know, but I believe it if you say you can), but the reality we live in is that it's unrealistic to write production-quality game engines in lisp. I've heard it's used for scripting and AI in some places (probably just Naughty Dog, tbh), but most of the code that goes into a game isn't in script, unless it's a slow game.
- yoklov 12y agoThe big downside with this is that you can't use function pointers or addresses to static memory (which means need to be careful with e.g. string literals). This is a pretty heavy restriction, and is too much of a limitation for a lot of cases. Not to say it's not valuable, it's great. I wouldn't exactly say it's common though.
- raphaelss 12y agoBe sure to check out the videos of it in use [1] and the Lisp to GLSL translator [2]. [1] http://www.youtube.com/playlist?list=PL2VAYZE_4wRKKr5pJzfYD1w4tKCXARs5y http://www.youtube.com/playlist?list=PL2VAYZE_4wRKKr5pJzfYD1... [2] https://github.com/cbaggers/varjo https://github.com/cbaggers/varjo
- baggers 12y agoHehe looks like I need to get some visually interesting demos up, I've been pretty lazy about that. I started looking to input and event propagation and got lost in a sea of frp and data-flow stuff for a while.
- zach 12y agoFor Clojure enthusiasts, I highly recomment Zach Oakes' environment in the same vein, Nightmod (his Nightcode IDE specialized with his play-clj library). It's an experimental platform that is a tidy, simple way to experience game programming in a functional style. https://nightmod.net/ https://nightmod.net/ Also, here is his presentation on this subject at the last Conj (great talk): https://www.youtube.com/watch?v=0GzzFeS5cMc https://www.youtube.com/watch?v=0GzzFeS5cMc
- krat0sprakhar 12y agoMy first question on clicking the link was - Does there something like this exist for Clojure? Glad to the have my question answered. Thanks for the links!
- lynndylanhurley 12y agoLol me too! I'm gonna check out Nightmod asap. Anybody here tried it yet?
- jarcane 12y agoOh wow, that's cool. Nightcode is fantastic, easily the best Clojure environment I found.