6 ms·
I can see how it might be fun to do something like this for a blog post or simple project, but in a real game this just doesn't work for many reasons, most list
by optionalparens 10y ago
I can see how it might be fun to do something like this for a blog post or simple project, but in a real game this just doesn't work for many reasons, most listed here already.
There are tons of ways of doing dialog system. Mostly it comes down to your specific game and I highly recommend against generic dialog systems. Rather, the most you can do at a generic level is try to come up with a good way to store dialog and retrieve it in the ways you need. This isn't the best thing I've seen or worked with, but here's an easy to understand and documented method and presentation about it form Valve:
http://www.gdcvault.com/play/1015317/AI-driven-Dynamic-Dialog-through http://www.gdcvault.com/play/1015317/AI-driven-Dynamic-Dialo...
Anyway, I've been programming games and game engines for several decades, and coroutines are always in the list of things that you can throw in the junk pile along with other cool things like continuations, various theoretical data structures, fancy dispatch mechanisms, events/signals, application-wide functional purity, etc. Of course all of these things are useful, but they tend to have problems that make them of limited use in professional game development.
Here's a brief checklist of show-stoppers off the top of my head I tend to go through before introducing anything "creative" into a game, and especially a game engine. Most of the aforementioned items fail one or more of these.
- Performs awful in common cases or when applied to actual game-like conditions vs. theoretical
- Murders cache lines
- Hard or impossible to debug
- Hard to save, load, serialize, deserialize, or snapshot
- Doesn't work over networks
- Doesn't play nice with libraries or data coming from other libraries or languages (ex: 3rd party physics lib)
- Unpredictable execution start or end times
- Non-determinant memory usage or allocation patterns
- Risk of stack-overflows
- Non-portable or problems on specific target architectures
- Requires "religion" meaning it infects all your code or forces you to write all of your code a certain way, everywhere
- Fragments memory
- Long blocking or uninterruptable processing
Conversely, besides the obvious opposites of most of the above, I look for the following when introducing some major data structure or conceptual item like coroutines to a game or game engine:
- Leads to predictable, consistent code and resource usage
- Data-driven
- Editor friendly (as a corollary to the above)
- Clear debugging story
- Both simple and easy if possible. No, they are not the same.
- Plays well with the world around it
- Portable
- Fast
- Loved by the CPU, GPU, and/or compiler, and produces reasonable assembly on target hardware
- Easy for someone else to jump in and understand the flow and how it works, assuming they are not a moron.
Pretty much these two lists mean that games tend to be made of meat and potatoes things. Simple data structures like arrays, custom allocators, predictable branching and execution patterns, up-front memory allocation, and CPU and GPU loving goodness. Pretty much anything stashing things away and building up massive states or jumping around all over the place, pointer chasing, and so-on should always be a no-go.
Anyway, if you're building a truly simple game, as in a 2 day sort of affair, do whatever you want. If you want to build something even remotely complex that you will work on for awhile, it's best to do things the right way which means detach yourself from everything you think you know about most of computer science and think in terms of pipelines, CPU instructions, caches, and predictability among other things. This often means programming against the grain of your language a bit, throwing out sugar, std libraries, and all kinds of things. It really sucks, but that's the essence of good game programming. I hope one day it will be different, but as long as there's still need to push gameplay and graphical boundaries, professional developers almost always need to squeeze out what they can.
- davexunit 10y ago>Anyway, I've been programming games and game engines for several decades, and coroutines are always in the list of things that you can throw in the junk pile along with other cool things like continuations, various theoretical data structures, fancy dispatch mechanisms, events/signals, application-wide functional purity, etc. This is one of the worst outlooks on programming I've ever seen. Did you know that any control flow operator such as try/catch is really an application of continuations?
- optionalparens 10y agoNot sure what your point is here, could you elaborate? It seems to me maybe you are missing the point. As I said, this is about programming games, primarily in C/C++ or a related language (though applies mostly to others), not programming in general. If you enter into other high-performance domains, you will encounter the same issues. Conversely, other domains such as general application programming do not adhere to this. Regarding try/catch, I am well aware of low-level implementations in various languages. Did you know that in most game engines, you don't use that much try/catch for this exact reason? If you're littering your game code with try/catch everywhere, you are doing something wrong. Not to say you don't have any, but there are other error handling and return methods or you just let things bubble-up and handle them there. What would you actually do in most try/catch situations deep inside a game loop outside of things where resources can leak horribly like IO? When you're working on a game, there are of course areas you can compromise. It also as I mentioned depends on the nature of your game. I'm speaking strictly of properly designed, professional games that have to be competitive in terms of features and run at a smooth frame rate while doing many things (i.e. your average AAA console game). In case you still doubt what I am saying, go look at GDC talks, game dev papers, etc. and you'll see the same thing. As far as someone people around here might be more familiar with as a source, I seem to recall there were multiple times Jonathan Blow mentioning exactly what I did (maybe a talk he gave at Berkley?). Anyway, the point is that as programmers we learn all these cool and fascinating things, but in game dev, you tend to have to let go of "cool" things and spin your thinking a bit towards things like predictability, performance, stability, transparency, and composeability.
- kazinator 10y ago