/*****************************************************************************
 * $Id: mod_base_listeners.cc,v 1.2 2006/11/25 17:29:12 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 MOD_BASE_LISTENERS_CC 1
#include "mod_base_common.hh"
#include "mod_base_joystick.hh"
#include "mod_base_event.hh"
#include "mod_base_listeners.hh"

/*****************************************************************************
 * Start/stop event listeners.
 *****************************************************************************/
void
Module::StartStopListeners( bool start )
{
	// Listener functions in this source file:
	gEngineEvent.mEngineReady.Listen(        Listener_ModuleBase_EngineReady,       start );
	gEngineEvent.mExit.Listen(				 Listener_ModuleBase_Exit,				start );
	gEngineEvent.mAnimate.Listen(			 Listener_ModuleBase_Animate,			start );
	gEngineEvent.mTick.Listen(				 Listener_ModuleBase_Tick,				start );
	gEngineEvent.mNeedTextureDirVec.Listen(	 Listener_ModuleBase_NeedTextureDirVec,	start );
	gModuleBaseEvent.mPrintStats.Listen(	 Listener_ModuleBase_PrintStats,	    start );

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

/*****************************************************************************
 * Event listeners (some are elsewhere).
 * @note The order of calling listeners is undefined.
 *****************************************************************************/
void
Listener_ModuleBase_EngineReady( void )
{
	gModule.mInputQueue.Enable( &gJoy );
	gModule.Start();	// engine is ready, let's play!
}
void
Listener_ModuleBase_Exit( void )
{
	gModule.End();
}
void
Listener_ModuleBase_Animate( void )
{
	// Animate() returns non-zero if redisplay/paint is necessary.
	if ( gModule.Animate() ) gEng.PostRedisplay();
}
void
Listener_ModuleBase_Tick( void )
{
	gModule.Tick();
}
void
Listener_ModuleBase_NeedTextureDirVec( void )
{
	gEng.SetTextureDirVec( gModule.GetTextureDirVec() );
}
void
Listener_ModuleBase_PrintStats( void )
{
	// The module module have counterparts.
	MODULE_STATS_CODE( *gStreamStats << gEng.mStats << gModule.mStatsBase; )
}
