/*****************************************************************************
 * $Id: game_base_listeners.cc,v 1.8 2006/07/23 02:26:44 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 * @brief	Event listeners.
 *//*
 * LEGAL:	COPYRIGHT (C) 2004 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 *****************************************************************************/

#define GAME_BASE_LISTENERS_CC 1
#include "game_base_common.hh"
#include "game_base_joystick.hh"
#include "game_base_listeners.hh"

/*****************************************************************************
 * Start/stop event listeners.
 *****************************************************************************/
void
Game::StartStopListeners( bool start )
{
	// Listener functions in this source file:
	gEngineEvent.mEngineReady.Listen(       Listener_GameBase_EngineReady,          start );
	gEngineEvent.mExit.Listen(				Listener_GameBase_Exit,					start );
	gEngineEvent.mAnimate.Listen(			Listener_GameBase_Animate,				start );
	gEngineEvent.mTick.Listen(				Listener_GameBase_Tick,					start );
	gEngineEvent.mNeedTextureDirVec.Listen(	Listener_GameBase_NeedTextureDirVec,	start );
	gGameBaseEvent.mPrintStats.Listen(		Listener_GameBase_PrintStats,			start );

	// In other source files:
	gEngineEvent.mDrawObjects.Listen(		Listener_Craft_DrawObjects,				start );
	gEngineEvent.mResetScene.Listen(		Listener_Craft_ResetScene,				start );
	extern void Listener_GameBase_JoystickButton( eJoyButton button );
	gGameBaseEvent.mJoystickButton.Listen(	Listener_GameBase_JoystickButton,		start );
}

/*****************************************************************************
 * Event listeners (some are elsewhere).
 * @note The order of calling listeners is undefined.
 *****************************************************************************/
void
Listener_GameBase_EngineReady( void )
{
	gGame.mInputQueue.Enable( &gJoy );
	gGame.Start();	// engine is ready, let's play!
}
void
Listener_GameBase_Exit( void )
{
	gGame.End();
}
void
Listener_GameBase_Animate( void )
{
	// Animate() returns non-zero if redisplay/paint is necessary.
	if ( gGame.Animate() ) gEng.PostRedisplay();
}
void
Listener_GameBase_Tick( void )
{
	gGame.Tick();
}
void
Listener_GameBase_NeedTextureDirVec( void )
{
	gEng.SetTextureDirVec( gGame.GetTextureDirVec() );
}
void
Listener_GameBase_PrintStats( void )
{
	// The game module have counterparts.
	GAME_STATS_CODE( *gStreamStats << gEng.mStats << gGame.mStatsBase; )
}
