Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  Adam Martin's entity system series  (Read 1678 times)
0 Members and 1 Guest are viewing this topic.
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Posted 2010-05-10 19:35:19 »

Adam has a new article out in his entity system series.  This one provides some concrete code and he did on Android.

http://t-machine.org/index.php/2010/05/09/entity-system-1-javaandroid/

Offline Roquen
« Reply #1 - Posted 2010-05-11 09:11:54 »

I commented on performance issues which such systems in another thread.

"...  so I had to make some substantial performance improvements, and now it’s happily rendering 300 things all flying around at 20-30 FPS"

Android or not, really, need I say more than the author?

Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #2 - Posted 2010-05-11 12:43:37 »

I commented on performance issues which such systems in another thread.

"...  so I had to make some substantial performance improvements, and now it’s happily rendering 300 things all flying around at 20-30 FPS"

Android or not, really, need I say more than the author?

So, because it runs at 20-30 fps on an android phone, it must be a inherently slow design? I don't agree with that assessment.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #3 - Posted 2010-05-11 14:18:03 »

I commented on performance issues which such systems in another thread.

"...  so I had to make some substantial performance improvements, and now it’s happily rendering 300 things all flying around at 20-30 FPS"

Android or not, really, need I say more than the author?


Notice he said the Java implementation on Android has serious performance problems.  The standard Java implementation would have no problem with this.

Offline Roquen
« Reply #4 - Posted 2010-05-11 15:19:09 »

So, because it runs at 20-30 fps on an android phone, it must be a inherently slow design?
Short answer: No, but it's a strong indication.  300 active entities is ridiculously small set.

Med. answer:
1) Expanded memory requirements (vastly if components are fine grain)
2) Increased pointer traversal
3) Dictionary lookup per component
4) No control over memory layout = no access pattern can be cache oblivious

= explosion of cache misses, in addition to extra code complexity.

1  
2  
3  
4  
5  
  Entity e = entitySystem.get(globalId); 

  e.getAs(Position.class).x = 5;
  e.getAs(Damage.class).hitpoints = 145;
  e.getAs(Renderable.class).foregroundColour = Color.red;


7 dictionary look-ups and something like 7 cache misses (on average) if this is in a tight loop...I'm too lazy to figure the upper bound.

Notice he said the Java implementation on Android has serious performance problems.  The standard Java implementation would have no problem with this.

Relatively, I'd expect to the impact to be larger on JIT Java-a-likes.  Interp will tend to hide the cost of cache misses.
Offline lhkbob

JGO Knight


Medals: 32



« Reply #5 - Posted 2010-05-11 15:31:59 »

I've implemented an entity system myself that uses array accesses to look up the components on an entity.  Indices within the system to perform iteration over entities with specific component types are also maintained.  Together these things are performant enough for me to render 10000+ things at about the same framerates I used to on an older engine that didn't use entities (and combined everything together).  It tends to be 1-3 ms slower but that may also be changes in rendering.

Either way, the point is that entity systems can be faster than what he presented.  I also believe he strongly recommended using something other than a plain Map for the storage.

Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #6 - Posted 2010-05-11 16:37:09 »

I can't quite see the use of this system over fairly ordinary composition and visitor patterns, which is fast as hell and totally memory efficient...? I mean, just how complex do we imagine game entities actually are?

Cas Smiley

Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #7 - Posted 2010-05-11 18:01:15 »

Yes, using Map to lookup components in each iteration is a bad way to go IMO. I can't see how each of the system can keep references that each component needs, it will always have to look it up in the map for the entity. There has to be more knowledge in the components than just pure data, as adam suggests, e.g. references to other objects at least.

In my "entity system" each component has a initialize method. In it I resolve all dependencies that the component needs, so when it's updated I don't need to ask the map.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
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.

pw (24 views)
2014-07-24 01:59:36

Riven (24 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

ctomni231 (50 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!