8 ms·
Game Programming Patterns (2014)
- djmips 3y agohttps://gameprogrammingpatterns.com/update-method.html https://gameprogrammingpatterns.com/update-method.html If you update every object - every frame - that's a lot of wasted updates for things that don't need to update for various reasons.
- 4pkjai 3y agoYes, but often it's okay to do these 'unnecessary' updates. The real slow part is drawing a frame. This kind of reminds me of the argument between immediate mode user interfaces and retained mode user interfaces.
- LightHugger 3y agoIt depends on the kind of game you're working on, but arguably if you're working on anything ambitious then you can't do it. Yes you can scrape by doing pointless heavy updates every frame for only 100 objects in the entire game world. The moment you want to simulate something more interesting these walls will be hit and it will directly affect your design process though (design is ongoing as the game is built!). So if you want to be a better game developer, develop in ways that you'll hit these walls less often and limit you less.
- vidarh 3y agoThose updates don't need to be heavy if nothing is happening. And as I related elsewhere, with a Ruby-based game engine it took 1000+ objects being updated every frame alongside other heavy stuff (multi-voice waveform based on-the-fly sound-synthesis, in Ruby) and actually passing each of them to the renderer, before I needed to bother to add any filtering. And then when I did need to it was a trivial change to filter the list of objects to update. To the point where I literally just currently naively every frame does a map over every object in the level and check if they're within the viewport before doing the update. Yes, you will sooner or later hit limits, but 1) you're likely to hit them later than you think, 2) it doesn't matter because when you do hit them you're likely to have a good idea of what characteristics to filter them by. E.g. for some games you want to update, but not render, objects outside the viewport in many situations based on other measures - e.g. Minecraft-style simulation of mobs within a certain distance of the player; for other games once an object is off-screen it can cease to exist instantly. But it takes consideration, and you might as well defer that consideration until you need to, because it's orthogonal to the actual update.
- deleted 3y ago[deleted]
- vidarh 3y agoBut a lot of the time it doesn't matter. And it's easy-ish to go from calling update on everything to moving objects in or out of a "currently visible or at least close enough that we bother simulating them and may need updates" bucket (which might be what's on screen, or what's in a room, or in a level, or within X amount of distance, or any number of other things) at whatever granularity you need to get the performance you want. The general advice of splitting the updates into frame-sized chunks solves the important beginner issue, and the performance tweak of reducing the number of objects you update is something you'll likely encounter much later. E.g. I'm currently doing a simple platformer with my son for fun, and just a very crude "is any part of this objects default starting position within x distance from what is currently on screen" is more than sufficient to constrain the update. Before that I just had it even naively render every single object in a level, because it was fast enough, so I didn't bother filtering anything. I only needed to start thinking about performance in the first place because of a combination of me going over-board with various effects and a fully waveform-based software synth and this all being written in Ruby (using the DragonRuby game toolkit [1]). If it'd been written in a faster, compiled language, or I'd been more reasonable in my expectations we'd likely never have needed to think about it. But 10+ parallax layers, wave-formed bases synthesis, and a bunch of pixel effects might be nothing in C, but keeping 60 FPS in Ruby that way takes a little bit of care. That said, we got to 1000+ objects updated every frame before I needed any filtering at all. I'm sure we'll eventually do more - not all objects have any animations or move, so they'd be easy to filter out too, but then I have to ensure every type of object is categorized accordingly, so I won't bother doing that until there's a need to, and it takes calling an update or render method that does nothing for a lot of objects before it starts dragging down the frame rate. [1] https://dragonruby.itch.io/dragonruby-gtk https://dragonruby.itch.io/dragonruby-gtk
- oneeyedpigeon 3y agoIt's ok to criticise, but it's more useful to suggest better alternatives. How would you optimise this? Only update objects in view or within a certain distance of the player?
- sigmoid10 3y agoIt's already very difficult to say what amounts to "good" patterns in game programming and even more so if it comes from one of the most mediocre studios in EA's portfolio. Of course financial/critical success and code quality can be totally uncorrelated, but for people who actually want to get to get a grip on game programming, there are very good free resources out there. One of the most insightful ones I've found are the dev streams of Thor from PirateSoftware. He streams on Twitch and you can also find a bunch of his stuff on youtube. He's one of the few people out there who tells you what you actually need to know if you really want to make a game and not just screw around with experiments.
- oneeyedpigeon 3y agoThis resource is free — the web version, anyway.
- krapp 3y ago>One of the most insightful ones I've found are the dev streams of Thor from PirateSoftware. I wish I could take everyone currently following Casey Muratori and Handmade Hero and point them Thor's way.
- cnity 3y agoThor is a breath of fresh air. I mean, I do like Casey and Jon Blow and so on, but Thor's positivity is infectious.
- snet0 3y agoDoes Thor ever actually code games? The few times I've seen his stream, he's basically editing config files or doing some drag-and-drop game engine thing. Being entirely unfair based on the low amount of exposure I've had to him, I've basically marked him as an edutainment streamer, where if you really want to learn game development your time is better spent consuming actual educational resources. I could be wrong, though!
- krapp 3y ago
- wokwokwok 3y agoUsually when this pops up I drop in to tell people not to waste their time with it, but, people are relentlessly drawn to free content, no matter how questionable it is. Instead, today I'll link to different free content that is actually useful advice by people who know what they're talking about: https://blog.unity.com/games/level-up-your-code-with-game-programming-patterns https://blog.unity.com/games/level-up-your-code-with-game-pr... ...also, checkout the link at the bottom to their forum where there's some (reasonably) thoughtful commentary on it by folk who've been down that rabbit hole themselves; including why "Game Programming Patterns" misses the boat in at least some respects.
- hacful-tonteg 3y agocould you summarize what's wrong with the book?
- wokwokwok 3y agoThe patterns (eg. Implementing a scripting language, double buffering, components) aren’t things you would use unless you were implementing a game engine, and are actively anti patterns if you are using an existing engine like godot, unity or unreal. Many are “generic advice” that does not apply; singletons, for example are an anti pattern in unity and other engines (due to scene loading) resetting world objects. Some of the other patterns are legitimate (eg state machines) but trivialise a complex domain (AI) and are cover far better and more comprehensively by specific resources on the topic. It also fails to address actual programming patterns that actual gamedevs use like GPU kernels, ECS (real ecs) or deterministic simulations. Patterns are not just magic sauce you sprinkle on and bam it’s a great game! Complexity solved! Use them thoughtfully to solve actual problems, when you need them. This just very generic advice, like “how to write unit tests” with no specific language or engine or framework. Yes, in general test are good, and “your test runner and package manager here can help you run tests” but the advice is deeply lacking if you want to try use it for writing actual tests in c++. …but hey, read the 10 or so previous HN threads on it. People have had opinions on it since the beginning of time, when it was first posted. This is just my opinion. My only really strong advice is to look around and consume other resources too, don’t just take this one as gospel.
- vsuperpower2020 3y agoI've read through this book 3 times over the years and it's very misguided. If you're working on a game and the words "gang of four" pop into your head you unfortunately have suffered permanent brain damage. The main problem with this book is that it focuses on things that are not actually issues for game development. Instead of deep knowledge you learn trivial factoids. You don't need or want a service locator in most cases, but if you read a book like this you'll be trained that it's some necessary and integral part of game development. If you can figure out how to draw trees, you can also figure out how not to duplicate their mesh/texture 200 times with their "flyweight pattern". You almost certainly don't want a bytecode interpreter in your game. You shouldn't be thinking in terms of prototypes. The only useful "pattern" in the book is the singleton, and hedged with "Despite noble intentions, the Singleton pattern described by the Gang of Four usually does more harm than good.". It teaches complete beginners to think incorrectly about how games should be developed, but it covers enough topics will entertain people. If you want a book, I would suggest "Game Engine Architecture" because it goes much more in depth on what actually goes into a game engine instead of abstract design patterns from textbooks that are somewhere between maliciously bad and incompetent.
- s_m_t 3y agoYes, the in-depth domain specific 1150 page book is going to be more useful for building an engine than the introductory 340 page book on design patterns with a gamedev flavor.
- vsuperpower2020 3y agoRight. I don't think "design patterns with a gamedev flavor" has any value for game developers, but I didn't want to just say the book was bad without suggesting an alternative. They're both aimed at game developers who want some deeper understanding of how to structure games and you can pick out chapters you like from the 1150 page book.
- toppy 3y agoAre you referring to this one? https://www.gameenginebook.com/ https://www.gameenginebook.com/
- k__ 3y agoHalf-OT: Anyone tried to apply ECS in a different context than games?
- dkersten 3y agoI’ve thought about it a bunch, because I quite like ECS in games, but for me, doing web service backends, there was never any real benefit over just using a relational database since ECS is basically an in-memory subset of relational. Even when that is enough, I found that I rarely deal with collections of entities with particular components in bulk like I would with ECS, but rather most web API’s operate on individual entities at a time, so the ECS benefits are less useful. I’m sure there are some use cases where it makes sense, but I’ve yet to encounter situations where I want the flexibility to compose entities out of data-components (ie entities have a lot of variety, most non-games I’ve worked on, entities tend to be one of a handful preset types), need to operate on subsets of entity data in bulk (systems) and can also tolerate in-memory (lack of transactional persistence). Eg if I need to treat data in bulk, say time series, it tends to be a subset of the data and each entry is more or less uniform (no need to compose out of components), or I need transactional guarantees. So while I’m sure there are cases where it’s useful outside of games, I feel that almost always a dull blown database us preferable (and even in games I’d say that a relational database would probably be preferable, from a data modelling point of view, if performance weren’t a concern) I’d love to hear from anyone who has used ECS outside of games, though!
- masfoobar 3y ago> I’ve thought about it a bunch, because I quite like ECS in games, but for me, doing web service backends, there was never any real benefit over just using a relational database since ECS is basically an in-memory subset of relational. This. When I try to explain ECS.. or just "data oriented" I often say it is like creating a well defined database. Most developers have experience in SQL one way or another. > I’d love to hear from anyone who has used ECS outside of games, though! I am a C# programmer. I am also the Lead Developer. While C# is, by default, an OOP language.. I try to limit on inheritence and/or overrides. Point is I try not to go hard on OOP ways of doing things, and seperate logic into their own libraries. How is this ECS? The truth is, directly.. it isn't. However, I try to encourage seperation of data and logic. You could say this mindset shares a lot with ECS. One time -- a few years ago now, where I implemented "ECS like" solution was adding a (free version of) google maps onto our web page. My boss was "but the map might do this" or "but how can the map do that?" "How can we do that?" and my answer was components! Nobody really understood what I meant so I chucked an example together and they liked it. Add the map (the entity) and tell it what components you want. Want to add pins = Component. Want to be able add a circle (point with radius) = Component. Want to create polygons = Component. The System element would update the components. Not comparable directly to games, but its an example of ECS outside of it.
- sparrowInHand 3y agoObligatory data orientated design https://www.dataorienteddesign.com/site.php https://www.dataorienteddesign.com/site.php as this is the mindset necessary to succeed with games - who will always will eat up all the resources.
- AHTERIX5000 3y agoIt's not necessary though. For every /r/gamedev ECS project there are many actually shipping products using whatever OO system and doing just fine, also in AAA space. If you are working on state of the art AAA product the situation is a bit different. But for the most games being sold on marketplaces like Steam it really doesn't matter as much as people on gamedev communities like to think.
- JoeyJoJoJr 3y agoIt should also be mentioned that you can go very, very far with absolutely abysmal code quality when making a game, and you can waste an insane amount of time attempting to lay a solid code foundation. Also, inheritance is not evil.
- ted_bunny 3y agoStreets of Rogue has notoriously awful code, but it's an absolute masterpiece.
- sparrowInHand 3y agoLook at the sauerbraten 2 engine and tell me that again.. inheritance is composition for fools
- dang 3y agoRelated: Game Programming Patterns (2014) - https://news.ycombinator.com/item?id=32837121 https://news.ycombinator.com/item?id=32837121 - Sept 2022 (20 comments) Game Programming Patterns: Event Queue (2014) - https://news.ycombinator.com/item?id=24233229 https://news.ycombinator.com/item?id=24233229 - Aug 2020 (123 comments) Game Programming Patterns (2014) - https://news.ycombinator.com/item?id=23203699 https://news.ycombinator.com/item?id=23203699 - May 2020 (86 comments) Game Loop - https://news.ycombinator.com/item?id=19009206 https://news.ycombinator.com/item?id=19009206 - Jan 2019 (56 comments) Game Programming Patterns: Double Buffer (2014) - https://news.ycombinator.com/item?id=17845334 https://news.ycombinator.com/item?id=17845334 - Aug 2018 (58 comments) Game Programming Patterns - https://news.ycombinator.com/item?id=14475489 https://news.ycombinator.com/item?id=14475489 - June 2017 (47 comments) How I made the print and eBook versions of my web book - https://news.ycombinator.com/item?id=8555285 https://news.ycombinator.com/item?id=8555285 - Nov 2014 (66 comments) Game Programming Patterns now available in print and eBook - https://news.ycombinator.com/item?id=8555248 https://news.ycombinator.com/item?id=8555248 - Nov 2014 (8 comments) How I wrote Game Programming Patterns - https://news.ycombinator.com/item?id=7646985 https://news.ycombinator.com/item?id=7646985 - April 2014 (43 comments) “Game Programming Patterns” is now finished - https://news.ycombinator.com/item?id=7634734 https://news.ycombinator.com/item?id=7634734 - April 2014 (74 comments) https://news.ycombinator.com/item?id=7569660 https://news.ycombinator.com/item?id=7569660 (April 2014) https://news.ycombinator.com/item?id=7569108 https://news.ycombinator.com/item?id=7569108 (April 2014) Speed memory access by arranging data to take advantage of CPU caching - https://news.ycombinator.com/item?id=7543158 https://news.ycombinator.com/item?id=7543158 - April 2014 (52 comments) Game Programming Patterns – Bytecode - https://news.ycombinator.com/item?id=7466711 https://news.ycombinator.com/item?id=7466711 - March 2014 (71 comments) Game Programming Patterns - https://news.ycombinator.com/item?id=6004885 https://news.ycombinator.com/item?id=6004885 - July 2013 (64 comments) Game programming patterns - https://news.ycombinator.com/item?id=874080 https://news.ycombinator.com/item?id=874080 - Oct 2009 (8 comments)
- dvh 3y agoDo the first 80% of the game the right way, do the last 20% of the game by any means necessary.
- masfoobar 3y agoI purchased this book. Might have been about 10 years ago, now. It is a nice book and, from memory, is well written. I do think that there are better books with regards to game programming. I would say this book is good is you are a web developer (or something) and want to brush over ideas on how to build games. What you learn from this book can translate to your day job to solving problems. The reality is many languages, libraries, etc, used in other domains are OOP focused.. so if thats your mindset, this is a good book. However, if you are serious about (wanting) to be a game developer/programmer, would recommend Game Engine Architecture. Real-tim collision detection is another book from memory. (I am out of touch if there are any modern books for game developers. Open to hear about them if any) Another recommendation is to watch Mike Actons 'Data Oriented Design' video on youtube. It is likely 10 years old, now. I still believe it is relevant for modern game dev. Disclaimer: I am not a game developer. I am an app developer. I builds gui apps, web sites, daemons, etc. However.. if I was to build a game, I would be using the C programming language (or maybe Odin)
- cnity 3y agoA note from someone making a game on the side (in C, actually!): beware of over-focusing on "patterns" and books about them. Yes, there are some great ideas (such as ECS and so on), but don't get bogged down in that. Solve the problems your game lays out for you first and see what difficulties arise. Don't "worship the gate" so to speak. I see many game developers who fall into this trap, and then there's the endless debates about "writing your own engine" (which is a bit of a misleading position from the beginning, my personal game has no "engine" that I can see that could clearly be separated from the rest of the game. No this does not mean it is poorly architected). All of this to say, relax about "patterns" already. Write your damn game, it's waiting for you.
- mysterydip 3y agoFellow "making a game on the side in C" here :) One of the best pieces of advice I read was "you have to ask yourself, do I want to make a game, or an engine?" Both are fine choices, but you need to know which and stick to it. And engine in that context refers to all the bits that make the game work, not necessarily that they're in a modular form for others to use. Basically, you can spend your whole time adding cool or clever features but never turning it into an actual game. It's an easy trap to fall into because adding features is a fun distraction from some of the slog of gamedev. Make the features you need, but don't "gold plate" things.
- nanmu42 3y agoThe author has another book: http://craftinginterpreters.com/ http://craftinginterpreters.com/ , which is fantastic too. I built an interpreter in WASM and Go when reading the book: https://lox.nanmu.me/en/ https://lox.nanmu.me/en/
- richrichie 3y agoI gave up at the command pattern. What an incredible way to beef up loc and to complexify the simple.
- jmacklin308 3y agoThe sacred text!