/*****************************************************************************
 * $LastChangedDate: 2010-02-04 20:47:38 -0500 (Thu, 04 Feb 2010) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   This module contains bootstrap/kickstart routines.
 * @remarks Some modules define Init()/Start() functions.  Others omit them.
 *//*
 * LEGAL:   COPYRIGHT (C) 2007 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#define INIT_MODULE_CC 1
#include "base/module.hh"
using namespace base;
#include "glue/module.hh"
using namespace glue;
// Other modules:
#include "gfx/module.hh"
#include "shader/module.hh"
#include "fx/module.hh"
#include "input/module.hh"
#include "control/module.hh"
#include "physics/module.hh"
#include "view/module.hh"
#include "graph/module.hh"
#include "world/module.hh"
#include "hud/module.hh"
#if COMPILE_GUI
#include "gui/module.hh"
#endif
#include "sky/module.hh"
#include "sound/module.hh"
#include "game/module.hh"
#include "init/module.hh"

namespace init {

INTERN void SelfChecks( void );

#if COMPILE_GUI
#define CALL_INIT_START_GUI( FUNC, ARGS ) \
    gui::FUNC( ARGS );
#else
#define CALL_INIT_START_GUI( FUNC, ARGS ) // empty
#endif

#define CALL_INIT_START( FUNC, ARGS )               \
{{                                                  \
    base::FUNC( ARGS );                             \
    glue::FUNC( ARGS );                             \
    graph::FUNC( ARGS );                            \
    /* [2010/02] start view/OSG early */            \
    view::FUNC( ARGS );                             \
    gfx::FUNC( ARGS );                              \
    fx::FUNC( ARGS );                               \
    shader::FUNC( ARGS );                           \
    physics::FUNC( ARGS );                          \
    world::FUNC( ARGS );                            \
    hud::FUNC( ARGS );                              \
    CALL_INIT_START_GUI( FUNC, ARGS )               \
    sky::FUNC( ARGS );                              \
    sound::FUNC( ARGS );                            \
    input::FUNC( ARGS );                            \
    /* CONTROL_CONF depends on WORLD_CONF */        \
    control::FUNC( ARGS );                          \
    game::FUNC( ARGS );                             \
}}

/*****************************************************************************
 * Initialize modules (those applicable).
 *****************************************************************************/
void
Init( const base::InitArgs& initArgs )
{
    CALL_INIT_START( Init, initArgs )

    SelfChecks();
}

/*****************************************************************************
 * Start modules (those applicable).
 *****************************************************************************/
void
Start( void )
{
    CALL_INIT_START( Start, )
}

/*****************************************************************************
 * Self-checks.
 *****************************************************************************/
void
SelfChecks( void )
{
#if DEBUG
    // Ensure the matrix indexs Xx etc are correct for OSG matrix.
 {
    Matrix m;
    m.makeIdentity();
    if ( m[Xx] != 1.0f or m[Yy] != 1.0f or m[Zz] != 1.0f
      or m[Xy] != 0.0f
      or m[Ox] != 0.0f or m[Oy] != 0.0f or m[Oz] != 0.0f )
    {
        throw Exception( "DEBUG: Matrix defs Xx etc are wrong!" );
    }
 }
    // Repeat but without makeIdentity().
 {
    Matrix m;
  //m.makeIdentity();
    if ( m[Xx] != 1.0f or m[Yy] != 1.0f or m[Zz] != 1.0f
      or m[Xy] != 0.0f
      or m[Ox] != 0.0f or m[Oy] != 0.0f or m[Oz] != 0.0f )
    {
        throw Exception( "DEBUG: Matrix defs Xx etc are wrong!" );
    }
 }
#endif // DEBUG
}

} // namespace init
