Ok, so..
In my pistol class (which handles the drawing of the gun in the hand + firing (and effects) + hits), I have an imagePtr for my muzzle flash (m_MuzzleFlash). I also have a bool that indicates when the muzzle flash will be drawn (m_DrawMuzzleFlash) and a timer for the duration.
On my gun model, I've created a slot facing away from the barrel (m_BulletSlot).
When you fire the gun, I do some raytesting, .. but also set the m_DrawMuzzleFlash to true. In the update, I now start the timer and check for the duration + a small random value. If the timer is finished, set back to false.
Then, in drawBlend(), I draw my imagePtr (m_MuzzleFlash), like so:
Code:
if(m_DrawMuzzleFlash)
{
// Set identity matrix before drawing an image in worldSpace
SetMatrix();
m_MuzzleFlash->draw3D(Color(255, 255, 255, 128), 0.1f, 0, m_BulletSlot.pos);
}
Don't forget to request RM_BLEND in drawPrepare for this.
In drawPrepare(), I also draw a lightSqr to add a small light to the scene, like so:
Code:
if(m_DrawMuzzleFlash)
{
Vec color(1, 0.9f, 0.5f);
LightSqr(0.9f, m_BulletSlot.pos, color).add();
}
I hope that helps. I know you just asked for the most optimal way to do it, but I don't know how well your programming is. So that's just how I did it.