Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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 2098 times)
0 Members and 1 Guest are viewing this topic.
Offline jammas615

Junior Member


Projects: 1



« Posted 2012-04-02 03: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: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #1 - Posted 2012-04-02 05: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 09: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 15: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


http://t-machine.org


« Reply #4 - Posted 2012-04-02 17: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.

Quote
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 Member


Projects: 1



« Reply #5 - Posted 2012-04-04 01: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.

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (56 views)
2014-04-15 18:08:23

BurntPizza (54 views)
2014-04-15 03:46:01

UprightPath (67 views)
2014-04-14 17:39:50

UprightPath (50 views)
2014-04-14 17:35:47

Porlus (67 views)
2014-04-14 15:48:38

tom_mai78101 (91 views)
2014-04-10 04:04:31

BurntPizza (152 views)
2014-04-08 23:06:04

tom_mai78101 (248 views)
2014-04-05 13:34:39

trollwarrior1 (205 views)
2014-04-04 12:06:45

CJLetsGame (212 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!