19 ms·
The scenario where OO shines is game programming. Each object encapsulates a game entity and it basically runs like a simulator, allowing for complex interactio
by visarga 8y ago
The scenario where OO shines is game programming. Each object encapsulates a game entity and it basically runs like a simulator, allowing for complex interactions between objects. But software in general is not like a game and OO doesn't help as much.
- vesak 8y agoGame programmers use entity systems, not OO... or do they?
- Ace17 8y agoFun related quote from reddit: "you can tell if someone started game development as a hobby because they ARE using an ECS."
- bni 8y agoWhat do the pros use? Why is ECS bad in a game/simulation type program?
- afiori 8y agoI think it means that pros try to use an ECS but often fallback to object spaghetti. But I might be wrong
- Ace17 8y agoECS is the "microservices" of game development : it's touted as the way to go, and in some cases it's the best solution, but it comes with increased wiring complexity cost, and the hype surrounding it causes it to often be adopted for dubious reasons (e.g "deep class hierarchies are bad, therefore I need ECS"). Very interesting article here: https://www.gamedev.net/blogs/entry/2265481-oop-is-dead-long-live-oop/ https://www.gamedev.net/blogs/entry/2265481-oop-is-dead-long...
- Retra 8y agoECSs are sort of designed to be flexible and make it easy to extend and mix the behaviors of a game. Most games do not need such flexibility, because professional games are designed and you already know what capabilities are needed, and it is more efficient and less complex to implement those things directly. However, if you're designing an open-ended game engine for other people to develop in, then an ECS is a godsend, because you have no clue what they plan to make their game do.
- vesak 8y agoHaha, ok. I'm even lower on that scale: not even a hobbyist game programmer. I thought they actually just use structs and whatever data structure works.
- TeMPOraL 8y agoThat about never happens. Partly because in no mainstream OO language a game entity can "run like an [independent] simulator" - you'd need green threads for that. Partly because the industry has learned its lessons with trying to shoehorn things into inheritance structure, resulting in god classes (see e.g. original UnrealEngine's Actor class, or Pawn class). Partly because mainstream OO is too weak to be useful (e.g. no multimethods). Partly because of cross-cutting concerns - physics, "game logic", rendering, AI and networking - each preferring slightly different view of things. Partly because performance - if you structure things in exactly the wrong way according to OOP, you get better cache use patterns. Partly because OO's "complex interaction between objects" is complex in the wrong directions, and too simple in the right ones - hence the current trend of composition-based "entity" modeling, when you encapsulate behaviors in tiny tags and treat game objects as (mutable) arbitrary collections of those tags. I still struggle to find areas where full-blown classical, class-based OOP is a good fit for the problem. Game development isn't such area.
- bni 8y agoThat inheritance structures is bad, leading to very highly coupled designs that are hard to change, has been similar discovered by many in line-of-business enterprise software. Some claim (Like Gosling) that inheritance was never a major point of OOP and that it has been overused. What do you mean by "tag" here. Is a "tag" implemented as a class in C++? Do you know of an example in real code that is open source, the the curious can study?
- TeMPOraL 8y ago> What do you mean by "tag" here. Is a "tag" implemented as a class in C++? Google for "ECS", or "Entity-Component-System". It's a sorta-pattern for what I described. I say sorta, because everyone has a slightly different idea of how it's supposed to be implemented, but typically, entities are just dumb containers for (instances of) components, the components store data & type info, and systems mutate those components. So e.g. an asteroid in a game of Asteroids would consist of e.g. "kinematics" component, and "sprite" component, and a "collider" component. If you wanted that asteroid to drop a powerup on death, you'd add "drops powerup" component to it, possibly at runtime. Components may or may not be implemented as classes, and the aggregation may or may not be direct. In small games where I used this (in Common Lisp), components were classes, and each entity object had a list of instances of those components. This was a naïve approach, but got the job done. A more performant implementation might look like this: each component is a struct, and gets a dedicated array of all instances; each entity only has a) tags of the types of components it consists of, and b) indexes into the "components" array. This optimizes for data locality, especially for more isolated systems. For instance, the physics system can now just loop over the array of "kinematics" components, and mutate their state, without knowing anything about actual game objects - and all the data necessary for updating physics for all game objects are close together in memory, reducing cache misses and allowing for other optimizations. Note how this is a complete inversion of OOP - components are now storing just state, all behaviours get segregated into systems that operate on those components in batch mode, and entities exist only to tell you which instances of components together form a game object. I don't have any reference C++ implementation handy to show, but if you read up on ECS, you're bound to find something.
- drainyard 8y agoYou'll find that no one making a game that needs to run well uses OO, especially not AAA. Unity is going away from it as well, and they are arguably the biggest influence on hobby devs and newcomers out there. There are plenty of good talks regarding this such as Mike Acton's CPPCon keynote from 2014 https://www.youtube.com/watch?v=rX0ItVEVjHc https://www.youtube.com/watch?v=rX0ItVEVjHc And more Mike Acton from Unity's GDC talks https://www.youtube.com/watch?v=p65Yt20pw0g https://www.youtube.com/watch?v=p65Yt20pw0g Personally, at this point the way I write software is so far removed from this discussion that I just do what feels right and what people can generally agree on within my teams. Solve the problem, don't discuss code, discuss solving the actual problem.
- deleted 8y ago[deleted]
- afiori 8y agohttps://kyren.github.io/2018/09/14/rustconf-talk.html https://kyren.github.io/2018/09/14/rustconf-talk.html Is a good post about how that can fail from the creators of starbound. Relevant quote: A new requirement comes in: I have an idea for a special kind of item that when the player holds it and its near a specific kind of enemy, it will glow. The enemies that trigger this should be scared of the item and back away, but have a special animation where they’re mesmerized by the glowing item. This should only work for players that have achieved some specific quest goal. You throw up your hands in frustration [...]