Home

Resume

Blog

Teikitu


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//  »Project«   Teikitu Gaming System (TgS) (∂)
//  »File«      TgS Execute - Module.c
//  »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
//  »Version«   4.0
// ------------------------------------------------------------------------------------------------------------------------------ //
//  Copyright: © 2002-2010, Andrew Aye.  All Rights Reserved.
//  This software is free for non-commercial use. Redistribution and use in source and binary forms, with or without modification,
//  are permitted provided that the following conditions are met: 
//    Redistributions of source code must retain this copyright notice, this list of conditions and the following disclaimers. 
//    Redistributions in binary form must reproduce this copyright notice, this list of conditions and the following
//      disclaimers in the documentation and other materials provided with the distribution. 
//  Neither the names of the copyright owner nor the names of its contributors may be used to endorse or promote products derived
//  from this software without specific prior written permission. 
//  The intellectual property rights of the algorithms used reside with Andrew Aye.  You may not use this software, in whole or
//  in part, in support of any commercial product without the express written consent of the author.
//  There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
// == Execute =================================================================================================================== //

// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //
//  File Local Data
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //

static ETgMODULE_STATE                      s_enExecute_State = ETgMODULE_STATE_FREED;




// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //
//  Public Functions
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //

// ---- tgEX_Init_Module -------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------------------------------ //
TgRESULT tgEX_Init_Module()
{
    // Verify the state of the system
    TgASSERT(ETgMODULE_STATE_FREED == s_enExecute_State);
    s_enExecute_State = ETgMODULE_STATE_INITIALIZING;

    // Unfortunately the low-level implementation of many platform specific CRT functions make use of one-time dynamic allocations
    // or function-level static variables (whose compiler implementations are often as guarded one-time dynamic allocations).  Thus,
    // it is necessary to execute all of them on a first pass basis so that later allocations do not cause memory fragmentation.

    //tgRunTime_Common_BaseAPI();

    if (TgFAILED(tgGB_Init()))
    {
        return (TgE_FAIL);
    };

    tgEX_PM_Init_Module();

    if (TgFAILED(tgKN_Init_Module()))
        goto Fail_Init_GB;

    if (TgFAILED(tgIN_Init_Module()))
        goto Fail_Init_KN;

    if (TgFAILED(tgSN_Init_Module()))
        goto Fail_Init_IN;

    if (TgFAILED(tgRN_Init_Module()))
        goto Fail_Init_SN;

    if (TgFAILED(tgFX_Init_Module()))
        goto Fail_Init_RN;

    if (TgFAILED(tgPH_Init_Module()))
        goto Fail_Init_FX;

    if (TgFAILED(tgAM_Init_Module()))
        goto Fail_Init_PH;

    if (TgFAILED(tgOB_Init_Module()))
        goto Fail_Init_AM;

    if (TgFAILED(tgSE_Init_Module()))
        goto Fail_Init_OT;

    s_enExecute_State = ETgMODULE_STATE_INITIALIZED;
    return (TgS_OK);

    Fail_Init_OT: tgOB_Free_Module();
    Fail_Init_AM: tgAM_Free_Module();
    Fail_Init_PH: tgPH_Free_Module();
    Fail_Init_FX: tgFX_Free_Module();
    Fail_Init_RN: tgRN_Free_Module();
    Fail_Init_SN: tgSN_Free_Module();
    Fail_Init_IN: tgIN_Free_Module();
    Fail_Init_KN: tgKN_Free_Module();
    Fail_Init_GB: tgEX_PM_Free_Module();
                  tgGB_Free();
                  return (TgE_FAIL);
}


// ---- tgEX_Boot_Module -------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------------------------------ //
TgRESULT tgEX_Boot_Module()
{
    TgASSERT(ETgMODULE_STATE_INITIALIZED == s_enExecute_State);
    s_enExecute_State = ETgMODULE_STATE_BOOTING;

    TgLOGF( ETgCON_CHANEL_MESSAGE, TgT("%-16.16s(%-32.32s): %-48.48s % 14d\n"), TgT("Execute"), TgT("Boot_Module"),
        TgT("Static Memory Size"), tgEX_Query_Fixed_Memory() );

    if (TgFAILED(tgGB_Boot()))
    {
        return (TgE_FAIL);
    };

    tgEX_PM_Boot_Module();

    if (TgFAILED(tgKN_Boot_Module()))
        goto Fail_Boot_GB;

    if (TgFAILED(tgIN_Boot_Module()))
        goto Fail_Boot_KN;

    if (TgFAILED(tgSN_Boot_Module()))
        goto Fail_Boot_IN;

    if (TgFAILED(tgRN_Boot_Module()))
        goto Fail_Boot_SN;

    if (TgFAILED(tgFX_Boot_Module()))
        goto Fail_Boot_RN;

    if (TgFAILED(tgPH_Boot_Module()))
        goto Fail_Boot_FX;

    if (TgFAILED(tgAM_Boot_Module()))
        goto Fail_Boot_PH;

    if (TgFAILED(tgOB_Boot_Module()))
        goto Fail_Boot_AM;

    if (TgFAILED(tgSE_Boot_Module()))
        goto Fail_Boot_OT;

    s_enExecute_State = ETgMODULE_STATE_BOOTED;
    return (TgS_OK);

    Fail_Boot_OT: tgOB_Stop_Module();
    Fail_Boot_AM: tgAM_Stop_Module();
    Fail_Boot_PH: tgPH_Stop_Module();
    Fail_Boot_FX: tgFX_Stop_Module();
    Fail_Boot_RN: tgRN_Stop_Module();
    Fail_Boot_SN: tgSN_Stop_Module();
    Fail_Boot_IN: tgIN_Stop_Module();
    Fail_Boot_KN: tgKN_Stop_Module();
    Fail_Boot_GB: tgEX_PM_Stop_Module();
                  tgGB_Stop();
                  return (TgE_FAIL);
}


// ---- tgEX_Stop_Module -------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------------------------------ //
TgVOID tgEX_Stop_Module()
{
    TgASSERT(ETgMODULE_STATE_BOOTED == s_enExecute_State);
    s_enExecute_State = ETgMODULE_STATE_STOPPING;

    tgSE_Stop_Module();
    tgOB_Stop_Module();
    tgAM_Stop_Module();
    tgPH_Stop_Module();
    tgFX_Stop_Module();
    tgRN_Stop_Module();
    tgSN_Stop_Module();
    tgIN_Stop_Module();
    tgKN_Stop_Module();
    tgEX_PM_Stop_Module();
    tgGB_Stop();

    s_enExecute_State = ETgMODULE_STATE_STOPPED;
}


// ---- tgEX_Free_Module -------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------------------------------ //
TgVOID tgEX_Free_Module()
{
    TgASSERT(ETgMODULE_STATE_STOPPED == s_enExecute_State || ETgMODULE_STATE_INITIALIZED == s_enExecute_State);
    s_enExecute_State = ETgMODULE_STATE_FREEING;

    tgSE_Free_Module();
    tgOB_Free_Module();
    tgAM_Free_Module();
    tgPH_Free_Module();
    tgFX_Free_Module();
    tgRN_Free_Module();
    tgSN_Free_Module();
    tgIN_Free_Module();
    tgKN_Free_Module();
    tgEX_PM_Free_Module();
    tgGB_Free();

    s_enExecute_State = ETgMODULE_STATE_FREED;
}


// ---- tgEX_Update_Module ------------------------------------------------------------------------------------------------------ //
// ------------------------------------------------------------------------------------------------------------------------------ //
TgRESULT tgEX_Update_Module( C_TgFLOAT32 fDt )
{
    // Update all of the input controllers.  TBD is whether this would include updating of the network system.  For some types
    // of multiplayer code it is possible to envision the network input stream as a different type of input controller device.
    // This system is currently based on a poll system - at some point this will most likely be changed to an event mechanism
    // to help prevent/reduce controller input loss during low frame rate.
    tgIN_Update_Module( fDt );

    // Update all the low level Kernel/OS systems.  This update is one of the primary drivers of the IO system.  It does not
    // include aspects that are implemented in specific modules like input and sound.  The primary purpose of the kernel
    // module is platform level management.
    tgKN_Update_Module( fDt );

    //// Camera is updated at the start of the game loop so that render image queries done by the game systems are valid for the
    //// resulting image produced by the render.  This way game code can test for visibility in the image and other image specific
    //// queries when attempting to load balance.
    ////tgST_Update_Camera( fDt );

    //// Update the scripting system.  Scripting has to be done before actor processing so that render changes can correctly
    //// be taken into account during actor processing.
    ////tgSC_Update_Module( fDt ); //« Update Script System

    //// TBD: Elements of the set may need updating.  This may allow for some dynamic actions in the static set without having
    //// to turn the element into a loaded object.
    //tgSE_Update_PreGame( fDt ); // Process set/light animation

    //// Update the primary AI system.  A master AI controller can be very useful in dispatching deferred AI tasks.  As well
    //// this can allow for an over watch of multiple AIs to provide higher order behaviors.  This is the last mechanism by
    //// which input is passed into a game object/actor.
    ////tgAI_Update_AI( fDt ); //« Primary AI Loop

    //// Build the current list of all the processing and rendering objects.  Objects may have their desired processing state
    //// changed by either the input systems or set logic.  If this request is approved by the object and the system then at
    //// the end of this frame the object will have its state changed.  This may cause resources to be released and is not
    //// considered to be a light-weight change.
    ////tgSE_Build_Lists();



    //// Movement and Animation //

    //// This section is set up to be pipelined to allow for maximum concurrency.

    //// The animation system processes the active entities given the animation state to determine a predictive motion.  This
    //// is done by calculating the movement of only the "pivot" bone - as set by the controlling actor code.
    ////tgAM_Update_Prediction();

    //// Update the pathing system with the desired motion computed from the animation system or set by higher level logic.
    ////tgAI_Update_Pathing();

    //// Objects that are not contained by the normal motion execution update their desired physical volumes.  This is also
    //// where those physical volumes that are not swept but need to be warped/slammed to their location should verify that
    //// the desired location is valid.  This would also be the point where any external non simulated factors can apply
    //// physical affects to the world.  For instance this would be the location where a wind object may influence the world
    //// or a gravity controller can alter the force field.
    ////tgST_Update_Simulation( fDt );

    //// The primary physics loop is performed synchronously with the game loop.  This is required to provide some of the desired
    //// final reactions in the game.  For instance, use of the rag doll system in physical animation blends require the system
    //// to be update with the animation system to reduce the amount of possible popping that may occur.  However, it is possible
    //// and is quite likely that the effects physical world will be processed asynchronously and at a lower frequency than the
    //// primary loop for load balancing reasons.
    //tgPH_Update_Module( fDt );

    //// The position of the actors is updated based on the final positions as determined by the physics system.  The resulting
    //// position may be reprocessed by the actor code to allow for possible animation changes.  It is up to the programmer to
    //// make sure that any changes done at this point to the animation and/or the actor is a legal change.  The primary use of
    //// this reprocessing is to prevent the character from doing illogical animation action (like walking against a wall).
    ////tgST_Update_Movement( fDt );

    //// Now that the final animation state has been determined it is necessary to generate all of the animation blends and
    //// calculate the final skeleton.
    ////tgAM_Update_Animation( fDt );



    //// Update the sound module.  
    ////tgSN_Update( fDt );



    //// With a data buffer the following two functions could be threaded off for multi-core
    //tgEX_Update_Screen();
    //tgEX_Render_Screen();

    return (TgS_OK);
}


// ---- tgEX_Query_Init --------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------------------------------ //
TgBOOL tgEX_Query_Init()
{
    return (ETgMODULE_STATE_INITIALIZED <= s_enExecute_State && s_enExecute_State <= ETgMODULE_STATE_STOPPED);
}


// ---- tgEX_Query_Boot --------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------------------------------ //
TgBOOL tgEX_Query_Boot()
{
    return (ETgMODULE_STATE_BOOTED == s_enExecute_State);
}


// ---- tgEX_Load_Config_BIN ---------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------------------------------ //
TgVOID tgEX_Load_Config_BIN()
{

}


// ---- tgEX_Load_Config_TXT ---------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------------------------------ //
TgVOID tgEX_Load_Config_TXT()
{

}


// ---- tgEX_Save_Config_BIN ---------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------------------------------ //
TgVOID tgEX_Save_Config_BIN()
{

}


// ---- tgEX_Save_Config_TXT ---------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------------------------------ //
TgVOID tgEX_Save_Config_TXT()
{

}