Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
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  
  Better ways to classify than a bunch of lists?  (Read 1404 times)
0 Members and 1 Guest are viewing this topic.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Posted 2009-10-30 17:09:20 »

I've got a game that has some pretty complicated collision algorithms and draw prioritizing (to make texture binding happen in a happier order), and as a result I ended up with 5 different lists that all do basically the same thing except they keep the groups organized for collision checks and drawing ordering. Can anyone think of any ways to make this a little bit better? This is basically what I've got:

EntityTypeA - Collides only with type A (and pathfinds only with A's), also drawn in 3D mode so some OpenGL flags get set before drawing, not ordered.
EntityTypeB - Collides only with type B and does some other B-related logic, ordered by Y position (game is isometric).
Particles - All the particle effects go into this layer. They don't collide with anything and are ordered by their texture id.
Emitters - All the particle emitters go here - they do absolutely nothing special except emit particles. They are not drawn, but can be attached to an Entity separately (which means they aren't in this list).
LevelGrid - a 2D array, contains all the different spaces in the level, links to other spaces ( ex. (0,0) might not link to (1,0) if there is a wall), and some Object inside, could be null (if the space is empty) or any Entity (an inactive Entity goes into one of these spaces).

The question is if there is a better way to do this. I need to keep the groups discrete from one another but repeating the exact same for loop with 4 different lists is pretty annoying, and I am thinking of adding yet another list.

Ideas?

See my work:
OTC Software
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2009-10-30 17:24:47 »

Just put them in 5 classes and don't expose the Lists themselves. Those classes are all doing more or less the same thing. Don't abstract too much. You could put everything 'behind' an interface, but in the end you'll probably be doing a lot of instanceof because you need one type to do a very specific thing.

If your code is for 'internal use' (within your engine)... it's all about what you think is easiest.

I'd make TypeAManager, TypeBManager, ParticleManager, EmitterManager, LevelConnectivity.

Most important is (as said) not to expose your list, so that you can replace them with probably more efficient datastructures later on. If you want to be productive, don't code it until you need it -- don't build an abstraction layer if you can manage it just fine with a quick and dirty solution -- until it gets in the way.


Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #2 - Posted 2009-10-30 17:44:06 »

Yeah, I'm keeping the unexposed already (getEntityCount and getEntityAt(int) are basically how you get to them all), although potentially I should use Iterators instead. They're all in different classes already, actually, I just figured that it would save a bit of processor if my (very commonly performed) task of comparing every entity of one type with another was limited to that one type and didn't require any instanceof.

See my work:
OTC Software
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.

atombrot (20 views)
2014-08-19 09:29:53

Tekkerue (21 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (55 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (27 views)
2014-08-08 02:01:56

Norakomi (35 views)
2014-08-06 19:49:38

BurntPizza (64 views)
2014-08-03 02:57:17
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!