Original Post
I was hoping to get some ideas on how engine modules should communicate with each other. For example, if I had written a c++ "script" ( I dont use a scripting language yet ) for the implementation of some hand held weapon, maybe the fire() functionality I would need to process collision, sound, HUD, animation etc etc.
Whilst the collision can be queued to some "Collision Manager" for batch collison and then later responce, I may need the results there and then, say for updating the HUD to show when an enemy is locked on. The problem is that I need access to all these elements, and Im not sure how to go about it. I invision the script being something like
For lack of better names, should thes Managers be global? or passed along?
Is there a better approach?
I see problems in the above system in making it scaleable in terms of multi-threading. If each script can access the managers like this then I wont be able to batch stuff unless I use a lot of locking. Yet I dont know how else to go about it.
Whilst the collision can be queued to some "Collision Manager" for batch collison and then later responce, I may need the results there and then, say for updating the HUD to show when an enemy is locked on. The problem is that I need access to all these elements, and Im not sure how to go about it. I invision the script being something like
void OnUpdate()
{
RayCastResult = CollisionManager.RayCast( WeaponLineOfSight );
if( RayCastResult.Hit )
{
if( RayCastResult.Item == Enemy )
{
Hud.SetCrossHair(RED);
}
else if( RayCastResult.Item == Team )
{
Hud.SetCrossHair(GREEN);
}
}
if( Weapon.AmmoCount <= LOW )
{
Hud.SetItemImage( "LowAmmoImage" );
}
}
void OnFire()
{
RayCastResult = CollisionManager.RayCast( WeaponLineOfSight );
if( RayCastResult.Hit && RayCastResult != Team )
{
if( Weapon.AmmoCount )
{
Animation.SetCurrent( "Fire", Restart );
SoundManager.PlayClip( "SingleBurst" );
AIManager.DespatchMessage( WeaponSpecs ); //alert NPCs
ParticleManager.AddSystem( "SingleFire" );
}
else
{
if( Weapon.Clips )
{
Reload();
}
else
{
Animation.SetCurrent( "Empty", Restart );
}
}
}
}
For lack of better names, should thes Managers be global? or passed along?
Is there a better approach?
I see problems in the above system in making it scaleable in terms of multi-threading. If each script can access the managers like this then I wont be able to batch stuff unless I use a lot of locking. Yet I dont know how else to go about it.