Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
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 1523 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.


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

« JGO Overlord »

Medals: 1022
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.

SHC (30 views)
2015-08-01 03:58:20

Jesse (20 views)
2015-07-29 04:35:27

Riven (40 views)
2015-07-27 16:38:00

Riven (22 views)
2015-07-27 15:35:20

Riven (25 views)
2015-07-27 12:26:13

Riven (15 views)
2015-07-27 12:23:39

BurntPizza (37 views)
2015-07-25 00:14:37

BurntPizza (46 views)
2015-07-24 22:06:39

BurntPizza (31 views)
2015-07-24 06:06:53

NoxInc (37 views)
2015-07-22 22:16:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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!