Meta tags:
Headings (most frequently used words):
general, code, structure, message, passing, rules, everything, around, me, game, engine, garbage, collection, optimization, dev, console, miscellaneous, thoughts,
Text of the page (most frequently used words):
the (33), world (19), player (19), game (14), this (13), that (11), code (9), updateplayer (9), #message (8), for (7), but (7), level (7), with (6), been (5), which (4), also (4), type (4), haskell (4), gamemain (4), described (4), approach (4), could (4), implemented (4), src (4), bindings (4), has (3), during (3), development (3), about (3), more (3), something (3), other (3), let (3), possible (3), any (3), works (3), what (3), full (3), passing (3), how (3), particle (3), particles (3), much (3), thinkplayer (3), engine (3), update (3), main (2), reason (2), very (2), useful (2), changes (2), here (2), think (2), functional (2), rather (2), than (2), anything (2), make (2), general (2), modified (2), data (2), updating (2), see (2), core (2), some (2), fine (2), until (2), effect (2), switch (2), _player (2), _particles (2), _level (2), functions (2), playermessages (2), levelmessages (2), above (2), and (2), rendering (2), are (2), not (2), garbage (2), behavior (2), isn (2), testing (2), types (2), from (2), there (2), hasn (2), out (2), direct (2), commands (2), dev (2), console (2), brief (2), overview (2), defect (2), process (2), loop, tail, recursive, call, simplified, looks, like, debugging, fairly, straightforwards, being, able, isolated, sections, high, degree, confidence, refactoring, pleasant, enough, even, major, having, strong, static, system, helps, lot, purity, enforces, disciplined, management, state, among, consequences, doesn, you, extremely, have, written, number, languages, goal, wasn, only, haskelly, bits, worth, mentioning, nonetheless, since, purely, language, way, use, copies, place, top, design, similar, definition, consider, entity, needs, change, else, addition, spawn, pull, adding, individual, things, return, gets, tedious, quickly, perhaps, better, now, looking, longer, clear, field, harder, happening, taken, split, into, two, parts, move, flip, messages, used, follows, particlesmessages, thinkparticles, thinklevel, allmessages, particlemessages, allows, different, entities, communicate, each, while, keeping, their, own, clean, implementation, complicated, idea, relevant, simulation, runs, fixed, 120hz, renders, refresh, rate, windowing, input, audio, mostly, contained, kind, basic, interesting, talk, uses, recently, collector, avoids, stop, cause, stutters, flag, critical, however, default, indicates, long, pause, times, don, start, happen, ghc, runtime, managing, many, gigabytes, memory, games, potentially, case, one, minimum, spec, x86, machine, can, handle, multiple, textures, effectively, limits, slow, cpu, going, always, gpu, bound, weaker, systems, profiling, work, done, yet, likely, decent, amount, low, hanging, fruit, optimize, performance, issue, fair, point, really, computing, ton, stuff, ignore, technique, favor, these, essentially, debug, intentionally, separated, usual, flow, write, whole, messier, illustration, look, comparison, miscellaneous, thoughts, optimization, post, copying, nonmoving, collection, window, fmod, sdl2_ttf, sdl2_image, sdl2, fix, your, timestep, msg, rules, everything, around, appenv, three, layer, cake, structure, documentation, hack, slash, steam, source, available, additional, links, cross, platform, notes, github, docs,
Text of the page (random words):
defect process docs brief overview documentation of the haskell code for defect process a 2d hack n slash game on steam the full source code is available on github brief overview cross platform notes additional links general code structure the main game loop is a tail recursive call which simplified looks like gamemain world io world gamemain world do world since this is a purely functional language the way this works in general is that we use modified copies of data rather than updating the data in place 1 the top level design is very similar to what s described in three layer haskell cake see src appenv types hs type for the full definition message passing rules everything around me message passing is core to how the code works consider updating some game entity updateplayer player io player updateplayer player do player this is fine until updateplayer needs to change anything else in addition to player e g spawn a particle effect or pull a switch in the level adding individual things to the return type gets tedious quickly e g updateplayer player io player particle level perhaps a better approach is updateplayer world io world updateplayer world let player _player world particles _particles world level _level world in do player this also works but now looking at the updateplayer type it s no longer clear what it changes any field of world could be modified so it s much harder to reason about what s happening the approach taken by this game is to split update functions into two parts think update thinkplayer player message thinkplayer player message to move the player message to make a particle effect message to flip a level switch updateplayer message player io player updateplayer messages player do player which is used as follows gamemain world io world gamemain world let player _player world particles _particles world level _level world playermessages thinkplayer player particlesmessages thinkparticles particles levelmessages thinklevel level allmessages playermessages particlemessages levelmessages in do player this allows different game entities to communicate with each other while keeping their own update functions clean 2 the full implementation is more complicated but the core idea is as described above see src msg and src world main hs for the relevant code game engine the simulation runs at a fixed 120hz but renders at any refresh rate implemented as described in fix your timestep windowing rendering and input are implemented with sdl2 bindings sdl2_image bindings sdl2_ttf bindings audio is implemented with c bindings to fmod 3 the game engine code is mostly contained in src window it s kind of a basic 2d engine not that much interesting to talk about garbage collection this game uses the recently implemented nonmoving gc garbage collector which avoids stop the world behavior that could cause stutters that flag isn t critical however the default copying gc behavior is also fine in testing this post indicates that long pause times don t start to happen until the ghc runtime is managing many gigabytes of memory for some types of games that could potentially be the case 4 but not this one optimization minimum spec for this game is an x86 64 machine that can handle rendering from multiple 4k textures 5 which effectively limits how slow the cpu is going to be in testing the game has always been gpu bound on weaker systems so there hasn t been much profiling work done on the haskell code yet there s likely a decent amount of low hanging fruit to optimize performance hasn t been an issue during development but it d also be fair to point out that the game isn t really computing a ton of stuff dev console the in game dev console commands ignore the message passing technique described above in favor of a more direct approach these are essentially debug commands so the code here is intentionally separated out from the usual flow it d be possible to write the whole game with this direct approach but messier this is an illustration of how that could look for comparison miscellaneous thoughts it s extremely possible to have written this game in any of a number of other languages the goal wasn t to make something only possible with haskelly bits but worth mentioning nonetheless it s more useful to think of functional purity in haskell as something that enforces disciplined management of state among other consequences rather than something that doesn t let you do anything refactoring has been pleasant enough during development even for major changes having a strong static type system helps a lot here debugging has also been fairly straightforwards during development being able to reason about isolated sections of code with a high degree of confidence is very useful
|