Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Design Issue

Name: Anonymous 2009-04-03 22:52

Hey /prog/,
I'm having a design Problem.

I'm making a game, and I have an over-arching class (Actor.h) that all objects in the game inherit from. I have a class that loads all objects in the current level from a text file (Level.h), and an object that loads holds and updates all of those objects (Engine.h).

The problem is, when each class shoots, I need to load the bullet from the actor object into the Engine, which holds a vector of Actors. Seeing as a bullet is derived from an Actor, including bullets in the original Actor object is not an option, and even if I could, including the Engine object in Actor would cause another circular inclusion (Engine would hold a vector of Actors, and Actor hold the main engine).

The whole power of the engine I"m trying to make hinges on being able to keep all the objects in one vector, as I thought up an algorithm that allows me to check only every third object if it's hitting something, speeding up the gameplay.

So, any ideas? Here's a shitty diagram I made while trying to think this out:
                                Game.cpp
                                   ||
                                  /  \
                      Screen.h--Level.h
                                       ||
                                Engine.h
                       ||
                         \
                      Vector of Actors <-|
                             ||          ||Bullets.
                               Actors--------|

Name: Anonymous 2009-04-03 23:28

>>3
Thanks, I'm looking into boost::ptr_vector, I"m currently only using a regular vector<Actor*>;

I tried forward declaration for another problem and failed due to other issues. I was trying to see if there was another design I could attempt that would be more elegantly structured.

Your last comment is probably correct - I was going to insert all objects into the vector based on their x coordinates, then run through every third and check if it was hitting its left and right. I fucking hate trees, though.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List