Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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 1196 times)
0 Members and 1 Guest are viewing this topic.
Offline Eli Delventhal
« League of Dukes »

JGO Kernel


Medals: 39
Projects: 12


Game Engineer


« Posted 2009-10-30 18: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: 438
Projects: 4


Hand over your head.


« Reply #1 - Posted 2009-10-30 18: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
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline Eli Delventhal
« League of Dukes »

JGO Kernel


Medals: 39
Projects: 12


Game Engineer


« Reply #2 - Posted 2009-10-30 18: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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (84 views)
2013-05-17 21:29:12

alaslipknot (92 views)
2013-05-16 21:24:48

gouessej (123 views)
2013-05-16 00:53:38

gouessej (115 views)
2013-05-16 00:17:58

theagentd (127 views)
2013-05-15 15:01:13

theagentd (114 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (187 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.076 seconds with 21 queries.