FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Interfacing Blaze with a game project.

 
Post new topic   Reply to topic     Forum Index -> Blaze
View previous topic :: View next topic  
Author Message
SirAlaran



Joined: 19 Feb 2007
Posts: 84
Location: Silicon Valley

PostPosted: Sun Apr 13, 2008 6:20 pm    Post subject: Interfacing Blaze with a game project. Reply with quote

I've been thinking a bit about the best way to interface Blaze with an actual game project. (This is mostly because I actually want to work on mine) I've talked to both Mason and Clay separately, and what I heard was that we are leaning towards recommending that objects in a game contain a reference to blaze RigidBody objects instead of inheriting from them.

Here's some example code for the inheritance scenario.
Code:

class RigidBody
{
   public:
      abstract bool collisionResponse(..., RigidBody otherBody);
   
   private:
      ...
}

class GameObject: RigidBody
{
   public:
      override bool collisionResponse(..., RigidBody otherBody)
      {
         health -= (cast(GameObject)otherBody).damage;
      }
   
   private:
      ...
}


And this uses signals to connect collision responses to the RigidBodies. The commented lines are Phobos code. Currently this is not possible because RigidBody doesn't have a userData variable, (But GeometricShape does...) so that would have to be added along with the slots.
Code:

import tango.core.Signal;
// import std.signals;

class RigidBody
{
   public:
      Signal!(..., RigidBody otherBody) collision;
      // mixin Signal!(..., RigidBody otherBody);
      setData(Object o)
      {
         userData = o;
      }
      
   private:
      Object userData = null;
}

class gameObject
{
   public:
      
      setBody(RigidBody r)
      {
         r.collision.attach(&collisionResponse);
         //r.connect(&collisionResponse);
         r.setData(this);
      }
      
      void collisionResponse(..., RigidBody otherBody)
      {
         health -= (cast(gameObject)otherBody.userData).damage;
      }
}



In UML this situation ends up looking like this...


I think that the inheritance looks cleaner and fits better with the object oriented philosophy. The code is also a bit shorter and requires fewer references to be stored.

As soon as we decide on this, I'd like to implement it so that I can get on with my game project. Let me know what you think.
Back to top
View user's profile Send private message
zzzzrrr



Joined: 17 Feb 2007
Posts: 139
Location: Washington, DC

PostPosted: Tue Apr 15, 2008 7:46 am    Post subject: Inheritance vs. Reference Reply with quote

For various reasons I like the reference method better, although collision callbacks probably need to be added to the library for this to be feasible.

Ideally I would like to develop Blaze as a library, but if you prefer to integrate the engine directly into your game please do.

Anyone else have any thoughts/recommendations?
Back to top
View user's profile Send private message
SirAlaran



Joined: 19 Feb 2007
Posts: 84
Location: Silicon Valley

PostPosted: Tue Apr 15, 2008 8:23 am    Post subject: Re: Inheritance vs. Reference Reply with quote

zzzzrrr wrote:
For various reasons I like the reference method better, although collision callbacks probably need to be added to the library for this to be feasible.


Yes. I need a way to tell the amount of damage done to a player by a bullet. (Among other things)

Quote:

Ideally I would like to develop Blaze as a library, but if you prefer to integrate the engine directly into your game please do.


There's nothing really stopping me from doing this, but I'd really like to avoid a "fork." If I solve this problem and then it's not integrated into Blaze, somebody will have to solve this again in their code too. It would be better to just pick one and make it official.

I really don't see why we can't make Blaze a library while allowing inheritance, but which way we implement this is not as important as providing a means for collision response.
Back to top
View user's profile Send private message
zzzzrrr



Joined: 17 Feb 2007
Posts: 139
Location: Washington, DC

PostPosted: Tue Apr 15, 2008 9:26 am    Post subject: Re: Inheritance vs. Reference Reply with quote

SirAlaran wrote:

There's nothing really stopping me from doing this, but I'd really like to avoid a "fork."


I couldn't agree more. My primary goal for Blaze 1.0 was to create a stable physics engine. Now that you've broached the subject, the next step should obviously be easy game integration. Your project sounds like an excellent candidate to bring Blaze up to speed in this regard.

SirAlaran wrote:

I really don't see why we can't make Blaze a library while allowing inheritance, but which way we implement this is not as important as providing a means for collision response.


Blaze already handles collision response automatically as part of the impulse solver. I'm guessing that you're referring to collision callbacks? This thread may be of interest to you:

http://groups.google.com/group/glaze-engine/browse_thread/thread/cba3543b06f56709/37efd0ff378adc2d#37efd0ff378adc2d

Regards,
Mason
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Wed Apr 16, 2008 8:16 am    Post subject: Reply with quote

I have a feeling that this can be done 100% with collision signals, but I'm really busy as of right now and don't really have time to work out and test the system.

Over the summer I may help out (in about 2 weeks).

~ Clay
Back to top
View user's profile Send private message AIM Address
zzzzrrr



Joined: 17 Feb 2007
Posts: 139
Location: Washington, DC

PostPosted: Wed Apr 16, 2008 8:26 am    Post subject: Reply with quote

clayasaurus wrote:
I have a feeling that this can be done 100% with collision signals, but I'm really busy as of right now and don't really have time to work out and test the system.

Over the summer I may help out (in about 2 weeks).

~ Clay


Great! I'll also be preoccupied over then next few weeks, but will hopefully be able to commit some time over the summer.

Regards,
Mason
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Blaze All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group