Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- From: "Aaron J. M." <ajmacd@xxxxxxxxxxxxxxx>
- Date: 29 Mar 2007 05:34:31 -0700
On Mar 29, 2:00 am, Ed Wegner <ed.weg...@xxxxxxxxxx> wrote:
To address the collision logic you describe, I'd add an Association
class off the "collides with" reflexive relationship between instances
of Mobiles. Let's call it "Collision". When a Collision occurs, the
first thing it checks is whether the colliding Mobiles are one of each.
If so, execute the "Projectile hits Creature" logic.
But how would a Collision check whether the colliding Mobiles are one
of each
without downcasting, double dispatch, or the Visitor pattern?
I might end up doing the Visitor pattern, but I want to put it off for
now to
see if I can find an easier solution.
On Mar 29, 5:18 am, "Dmitry A. Kazakov" <mail...@xxxxxxxxxxxxxxxxx>
wrote:
You would probably need a better structures than plain lists. Collision
detection with many objects will be O(n²). Further, what happens with
tripple collisions? For example, two creatures lock each other while a
bullet hits both? That's O(n³) etc.
<snip>
You are silent about what drives your world. Are mobile objects
asynchronous active objects (like threads). Is it single threaded with
world state changed stepwise. How many actions an object may perform per
one step? Such decisions will certainly have influence on the design. For
example, in the case when each object performs one action per turn Creature
would perform Collide with Bullet for itself and change the state of Bullet
to Has_Been_Collided to prevent Bullet from colliding the same object (and
other objects) again.
Well, I meant lists as in a generic collection, though that's besides
the point.
I didn't mention what's driving the world because I was hoping that I
could
design the collision interactions of Mobiles independant of that.
However, I am
only considering collisions between at most two Mobiles at a time. I
am also
intending that my World manage when the Mobiles act by telling them
all to
move() when the World is given the message update(), which may come
from a Clock
if the game is realtime or from the UI if the game is turnbased.
.
- Follow-Ups:
- References:
- Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- From: Aaron J. M.
- Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- From: Dmitry A. Kazakov
- Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- Prev by Date: Re: Separation of concerns
- Next by Date: Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- Previous by thread: Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- Next by thread: Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- Index(es):
Relevant Pages
|