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

Pages: 1-

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 22:53

Wow, that diagram got fucked up.

Name: Anonymous 2009-04-03 23:06

keep all the [polymorphic] objects in one vector
You mean a boost::ptr_vector, I hope.

Seeing as a bullet is derived from an Actor, including bullets in the original Actor object is not an option
Why is it not an option?

class Actor {..};
class Bullet : Actor {..};
class Person : Actor {
    Bullet *ref;
}


circular inclusion
See: Forward declarations.

I thought up an algorithm that allows me to check only every third object if it's hitting something
Use a spatially-partitioned tree, hurr durr.

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.

Name: Anonymous 2009-04-03 23:57

>>4
Please consider that Sepples is the wrong language for the job.

Name: Anonymous 2009-04-04 0:11

>>1
Why do you keep referring to classes then writing file names?

Name: Anonymous 2009-04-04 0:15

So, what's so great about putting everything into one vector? Seems like it's just causing you trouble (not that it should, but apparently it did).

Name: Anonymous 2009-04-04 0:18

Game.cpp
Now you have two problems.

Name: Anonymous 2009-04-04 1:43

>>5,8
What, precisely, would you write your games in?

Name: Anonymous 2009-04-04 1:51

>>9
Not >>5,8, but I'd write my games in Common Lisp. And accordingly, I have more fun than you.

Name: Anonymous 2009-04-04 2:42

>>10
Joke life.

Name: Anonymous 2009-04-04 2:58

>>11
What does that mean?

Name: Anonymous 2009-04-04 3:13

>>12
it's like thug life, but for clowns

Name: Anonymous 2009-04-04 3:31

>>13
What does it mean to me?

Name: Anonymous 2009-04-04 3:37

>>14
everything.
What do you mean to me?

Name: Anonymous 2009-04-04 3:56

>>15
Nothing. ;_;.

Name: Anonymous 2009-04-04 4:22

how to write gaem?

Name: Anonymous 2009-04-04 4:51

>>17
http://www.lisperati.com/casting.html

Wasn't Zork originally written in MDL?

Name: Anonymous 2009-04-04 9:16

>>7
Centralized object ownership. It's an easy way to keep track of memory allocations.

Name: Anonymous 2009-04-04 13:21

>>19
Garbage collection. It's an easy way to automate memory management, which is too important to be left to the programmer.

Name: Anonymous 2009-04-04 13:25

>>20
hurr

Name: HMA FAN 2009-04-04 13:38

>>1
Seeing as a bullet is derived from an Actor, including bullets in the original Actor object is not an option,
I suggest you look more into the ``Composite Pattern for Reusable Sepples ENTERPRISE Code´´, available in the famous YHBT Expert Programming Book and similar sources.[1]

including the Engine object in Actor would cause another circular inclusion
Decently-thought object hierarchies should not generally need this, but you can declare class Engine; in Actor.h, which will allow Actor to contain an Engine* as a private member, and then include Engine.h in your Actor.cpp file in order to use the Engine's methods. This way there is no circular inclusion. The fact that you can, however, doesn't mean that you won't get your anus haxxed by this kind of shit eventually.


________________________
1 - Reference: http://en.wikipedia.org/wiki/Composite_pattern [Retrieved on April 4th, 2009]

Name: Anonymous 2011-02-04 15:44

<

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