wowzers!
thanks for all the different ways about it guys, very insightfull.
I am just beginning this component based quest of mine, and as such I found a tutorial somewhere (I cannot find it again though

) which described a transition from OOP to componentbased in 3 flavours varying in abstractness.
- 1) a 'GameObject' that has named variables/refernces for all possible component
so : bool hasPhysicsObject, PhysicsComponent Physics, bool hasPositionComponent, Posi .. etc
- 2) all components share a common parent/implement a IComponent part which makes it possible to just have a List with components in your GameObject
- 3) the GameObject doesn't exist anymore, there is just data and behaviour which get mixed an matched together via a database-like construction.
atm I started implementing the first GameObject way.
and then I ran into the crossroad case I described in the first post.
for the time being I just choose the happymonster way.
But I know that will not hold up further down the line and is a dangerous choice, It's intentionally breaking a clean thing to get it working. which would be a-ok if this was a game that's almost finished but I am just starting out. I imagine I could end up with a Update() function that has a gazillion special cases.
Oh wait I'll paste the actual body to illustrate:
public void Update (FrameEventArgs e)
{
if (HasSteeringComponent && HasPhysicsComponent) {
var steeringForce = steering.calculateSteeringForce(e.Time);
steering.applySteeringForce(steeringForce, e.Time);
var steeringForce2 = steering.UpdatePosition(e.Time);
physics.Body.LinearDamping = 6.2f;
double heading = Math.Atan2(steering.Velocity.Y, steering.Velocity.X);
double a = ((heading));
physics.Body.Rotation = (float)a;
rotation.Rotation = (float)a * (float)(180 / Math.PI) - 90f;
float strength = (float)(.8 / e.Time);
physics.Body.ApplyForce(new ms.Vector2((float)(steeringForce2.X * strength), (float)(steeringForce2.Y * strength)));
position.X = -4 + (float)physics.Body.Position.X * 8;
position.Y = -4 + (float)physics.Body.Position.Y * 8;
steering.Pos.X = position.X;
steering.Pos.Y = position.Y;
} else {
if (HasSteeringComponent)
{
steering.Update(e.Time);
if (HasPositionComponent)
{
position.X =(float) steering.Pos.X;
position.Y =(float) steering.Pos.Y;
}
}
if (HasPhysicsComponent)
{
if (HasPositionComponent)
{
position.X =-4+(float) physics.Body.Position.X*8;
position.Y =-4+(float) physics.Body.Position.Y*8;
}
}
}
}
I like the 2nd way where a gameobject just has a list of components, but that won't make a difference in the Update loop I've show above.
leaves the third and most abstract way, ( what Geti started talking about too)
I believe that must be the 'best' component system. But my OOP brain is working against it. No GameObject class ?! what madness !
I would like to see some implementations of that solution, any tips ?
I feel this would be the solution that would make me the happiest me in a few months.
The messaging/events that are required aren't hopefully a big thing sice I am working in c# which has a nice delegate/event system built in.
I worry a bit about the channel/mutexer/broadcaster thing because I haven't got a clear image of what that means.
@xgalaxy :
I can follow your thoughts there nicely and the saving of some data for another component down the line seems a simple solution to my original problem (I love simple solutions!)
but how will you describe which components come first in your case ?
Just the order they have on a list or something as easy as that ? Or more sturdiers ways ?
And how will that data be saved ? just a Object which other component try and cast ?
I need to check some more implemenations I suppose.