Hi !
Featured games (87)
games approved by the League of Dukes
Games in Showcase (672)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (727)
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  
  Entities and entity managers  (Read 2540 times)
0 Members and 1 Guest are viewing this topic.
Offline jammas615

Junior Devvie

Projects: 1

« Posted 2012-04-02 01:25:17 »

I'm trying to figure out a good way to manage entities in largely data-driven games where a large amount of objects need to be managed and i'd like peoples thoughts.

Is it worth building your own container classes for them?... or just using built in collections classes that Java has.

Where is efficiency lost?... in either homemade containers or Java collections.
   -> And how you increase efficiency?

and finally:
Your ideas or any other thoughts on efficient entity management?...

Offline ra4king

JGO Kernel

Medals: 422
Projects: 3
Exp: 5 years

I'm the King!

« Reply #1 - Posted 2012-04-02 03:37:52 »

Are you multithreading? If not, then a simple ArrayList is extremely fast enough. If you don't care about order, a Set is also excellent.

Offline 65K
« Reply #2 - Posted 2012-04-02 07:47:12 »

Choosing the right collection class can make a difference. But I would first look at ready-to-use solutions. For my game development I use implementations from Trove, Javolution, Colt and built in Java classes.
They have different performance signatures when it comes to dealing with items. Same is true when it comes extending/scaling. Some can store primitves, some offer synchronization.

Individual use cases are critical, like:
- iterating all items
- index based direct access
- key based access
- insertion, appending or removing
- removing of items
- keeping ordered items
- concurrent access, algorithmic or by synchronization

Some hints:
- for frequent iteration of hash maps, using HashMap results in creation of tons of avoidable iterator objects
- FastMap supports ordered maps
- Colt's maps can store primitives
- LinkedList is not that good for index access
- ArrayList isn't the best for finding concrete items
- choose the right initial capacity and growth behaviour
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lhkbob

JGO Knight

Medals: 32

« Reply #3 - Posted 2012-04-02 13:41:03 »

If you need thousands of entities simple collections will start to have performance problems because the entities will get moved around the heap with the gc and cache misses will occur.

This might not be that important to you but it can make for surprising speedups. If that is something you want I would look at mapped objects or the entity framework in my signature. I designed it for data oriented apps.

Offline blahblahblahh

JGO Coder

Medals: 1

« Reply #4 - Posted 2012-04-02 15:19:12 »

Is it worth building your own container classes for them?... or just using built in collections classes that Java has.

NB: if you're doing something SUPER intensive, but SUPER low-complexity (e.g. particle effects), then don't bother with containers, go straight to arrays/buffers. For everything else...

Only once your game is running so slowly that it's becoming frustrating to debug and test it.

You can tolerate a lot of low performance before you get to that point. Live with it. Focus on the rest of the game. Do the optimization only when it becomes *necessary*.

Not "last", but "only as soon as when you need it, and no earlier". e.g. when I notice the minimum compile/test/debug cycle being slowed down by more than 30 seconds just because of low performance ... I optimize.

Where is efficiency lost?... in either homemade containers or Java collections.
   -> And how you increase efficiency?

Worst: selecting the right subset of items from the container
Second worst: iterating over the container

For the former, you can create custom containers - or ... just use smaller containers, and pre-split your data into chunks that you frequently access as subsets.

For both items, arrays (or, better, Buffers) of flyweight impersonated objects are much faster. But don't bother until/unless you actually need it.

malloc will be first against the wall when the revolution comes...
Offline jammas615

Junior Devvie

Projects: 1

« Reply #5 - Posted 2012-04-03 23:05:49 »

Thanks, for the replies and advice. I've got more of an idea now.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

IanParcs (49 views)
2016-04-18 14:18:53

KaiHH (47 views)
2016-04-18 08:35:41

KaiHH (77 views)
2016-04-15 12:43:58

theagentd (81 views)
2016-04-14 02:16:17

theagentd (95 views)
2016-04-14 02:15:43

IanParcs (110 views)
2016-04-12 03:51:16

IanParcs (49 views)
2016-04-12 03:50:03

IanParcs (46 views)
2016-04-12 03:49:54

IanParcs (42 views)
2016-04-12 03:49:52

IanParcs (50 views)
2016-04-12 03:49:52
Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50

Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30 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‑
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!