Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Entity Component System VS OOP  (Read 5871 times)
0 Members and 1 Guest are viewing this topic.
Offline RylandAlmanza

Junior Devvie


Medals: 3



« Posted 2012-03-12 20:03:28 »

So, I've always used object oriented programming. I only recently found out what an entity component system is. It sounded like a good idea, so I implemented one based on this tutorial. After asking a question about it, I found out that sproingie wasn't too impressed with the whole idea:

(...) I'd go so far as to say Entity Systems are highly overrated things that no one should be using unless they have specific knowledge of the exact benefits they gain from using them over a traditional OO approach.

It's a really great post if you read the whole thing. It helped me out a lot. I took sproingie's word on it, and decided not to use the entity component system.

However, I'm starting to question why so many people here feel this way about this type of system. While I was using it, I found it to be very helpful, and made certain things more simple. Anyone want to discuss what they like/dislike about entity component systems over OOP? Is it simply a matter of "If it aint' broke, don't fix it?"
Offline 65K
« Reply #1 - Posted 2012-03-12 20:19:36 »

An Entity Component System is OOP, so the question would rather be ECS vs approach XY.

Offline princec

« JGO Spiffy Duke »


Medals: 434
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #2 - Posted 2012-03-12 20:38:25 »

For me it's mostly that I do not work on games that have anything like the number of possible interactions that make a component based system less complex than a simple 2 or 3 level traditional object class hierarchy.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cylab

JGO Ninja


Medals: 55



« Reply #3 - Posted 2012-03-12 20:57:02 »

Anyone want to discuss what they like/dislike about entity component systems over OOP?

for me after 2 minutes of thinking:

pro ECS:
- flexible
- easy to "glue in" third party libs (physics, etc.)
- better "modding" support
- better support for resource driven development

contra ECS:
- usually more to type in non resource driven development
- bad code-completion support (typing "get" results in getComponent(...), nothing else Wink)
- prone to nullpointer exceptions
- prone to the "game engine dilemma" (more effort to the engine, less effort to the game)


Mathias - I Know What [you] Did Last Summer!
Offline sproingie

JGO Kernel


Medals: 202



« Reply #4 - Posted 2012-03-12 20:59:37 »

I'm not completely negative on Entity Systems, I just think they're oversold.  If you read the T-Machine article, a lot of the benefits being touted are things like cache coherency and reference locality, which are big deals with consoles with their in-order CPUs and small memory space.  None of these benefits are going to materialize in a typical java implementation, so what you're left with is simply the code organization principles that Entity Systems give you.  They're not bad principles -- composition is really a good thing overall -- but they're not a panacea.  Forgoing direct references in favor of "Entity IDs" all the time is just silly unless you're gaining real measurable benefit from this extra level of indirection.

Offline princec

« JGO Spiffy Duke »


Medals: 434
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2012-03-12 22:50:47 »

Cache coherency and memory locality are, it seems, pretty big deals for desktop CPUs as well these days. So... if you need that sort of stuff, well, you need it.

Cas Smiley

Offline RylandAlmanza

Junior Devvie


Medals: 3



« Reply #6 - Posted 2012-03-12 22:53:44 »

Thanks everyone. I'm going to try it out again, just to see how it works out for me. Smiley
Offline sproingie

JGO Kernel


Medals: 202



« Reply #7 - Posted 2012-03-12 23:43:48 »

Cache coherency and memory locality are, it seems, pretty big deals for desktop CPUs as well these days. So... if you need that sort of stuff, well, you need it.

Oh I agree, but stuffing object references into an Array doesn't cut it.  Something like MappedObjects would be getting there, but none of the ECS implementations I've seen actually do anything like this.
Offline princec

« JGO Spiffy Duke »


Medals: 434
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #8 - Posted 2012-03-13 00:12:32 »

Yes, mapped objects is where it's at. If you don't have them then you are probably just undergoing huge pain for no gain.

Cas Smiley

Offline lhkbob

JGO Knight


Medals: 32



« Reply #9 - Posted 2012-03-13 02:54:32 »

With regards to cache coherency, MappedObjects can be done completely in Java. Shameless self-plug: http://bitbucket.org/mludwig/entreri

And it definitely improves performance.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #10 - Posted 2012-03-13 12:00:48 »

For me it's mostly that I do not work on games that have anything like the number of possible interactions that make a component based system less complex than a simple 2 or 3 level traditional object class hierarchy.

Cas Smiley

I have largely found the same thing. An interesting question might be, how many different objects/enemies/interactions/etc. do you need to have to make a component system worthwhile?

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Roquen
« Reply #11 - Posted 2012-03-13 12:24:30 »

Component based is neither OO nor not-OO.  It's a data design model (by segregation). And in the context of languages which don't support arbitrary containers natively, it's also a design pattern. [SnarkMode]It's yet another great idea from the same brain that came up with Objective-C.  Although it was originally termed software ICs.  Can't imagine why that didn't catch on.[/SnarkMode]  It's a really fine idea.  If you're writing, say, banking software..and especially if you choose a language well suited it.  In the context of games?  Almost always a huge waste of time except in the narrow case of needing to processing massive amounts of entities.  At the same time.  Which isn't necessarily the same has having a massive number of active entities.  And even in that case I'm not sure it's a great idea.  Because you can always build your system to use data segregation instead of creating/using some arbitrary container management system.  As an aside, my guess is that most libraries are composition by type, rather than composition by name...meh.

The most recent discussion (that I recall) on this subject is here in which I say this.  Actually Cas started a rant Still hardly any games, why entity systems suck, and why 4k is good.

WRT: MappedObject.  Faking structures is a great improvement, but you're still stuck for caching hints.  And all of this is assuming that one did a good job of figuring out data segregation and maintain aux info to let you traverse the data linearity and not cause cache thrashing is some other core.

WRT: Cylabs pro list:
- flexible ... with respect to the one archtype, one class ultra deep rigid design pretty much only a beginner would do, then yeah...otherwise not really.
- easy to "glue in" third party libs (physics, etc.) ... don't see how this is true
- better "modding" support ... Pseudo-mixins and a basic extension mechanism cover pretty all your bases here and likewise these are 'at runtime' changes.  If you wanted to get really fancy, you could add hot-deployment.
- better support for resource driven development ... don't see how this is true.
Offline princec

« JGO Spiffy Duke »


Medals: 434
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #12 - Posted 2012-03-13 12:51:24 »

I was thinking if you were maybe serverside and had 100,000k entities to process 10 times a second, just possibly it might be worth the hassle. But then you'd probably have just been better off throwing another core or two at the problem and avoiding it all. Or of course if you're running on something with a tiny cache and fat bandwidth pipes through multiple processing stages like PS hardware, but none of us are doing that here.

Cas Smiley

Offline Roquen
« Reply #13 - Posted 2012-03-13 13:35:39 »

Here's the deal.  The performance gains come from the data segregation (ya gotta get this right) and approximately linear walks of memory per worker which are not component based specific.  The ES specific bits are all performance drains.  The one possible situation I might consider using a CS is if I wanted true ~100% uptime and wanted to be able to easily apply live code updates.  This "might" be easier than a more traditional hot-deployment scheme...or not I haven't thought about it enough to form an opinion.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (33 views)
2014-12-15 09:26:44

Mr.CodeIt (24 views)
2014-12-14 19:50:38

BurntPizza (51 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (46 views)
2014-12-05 12:39:02

SHC (60 views)
2014-12-03 16:27:13

CopyableCougar4 (61 views)
2014-11-29 21:32:03

toopeicgaming1999 (124 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!