Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Effect - Sound - Update.c
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, 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:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution 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.
    The name of the author may not 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".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

#define T_NAME( A, ... ) A##Sound##__VA_ARGS__
#define T_TYPE( A, ... ) A##SOUND##__VA_ARGS__
#define T_TEXT( ... ) __VA_ARGS__ TgT("Sound")
#define T_EFFECT_TIME 0
#define T_EFFECT_SCENE 0
#define T_EFFECT_RENDER 0

#include "TgS Effect - Effect - Type.h_inc"


/* == Effect ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Shared Implementation                                                                                                                                                 */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

#include "TgS Effect - Effect - Update.i_inc"
#include "TgS Effect - Effect - Update.c_inc"




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Private Functions                                                                                                                                                     */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- tgFX__File__Sound_Patch_File_Data ------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgFX__File__Sound_Patch_File_Data( P_STg2_FX_Sound__File_Data UNUSED_PARAM psData )
{
}




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Parent File Local Functions                                                                                                                                           */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- tgFX__Update__Sound_Create_Command ------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgBOOL tgFX__Update__Sound_Create_Command( CP_STg2_FX_Instance UNUSED_PARAM psInst, C_TgFX_DATA_INST_ID tiData, CP_TgVOID UNUSED_PARAM pData1 )
{
    P_STg2_FX__Sound                    psSound;
    CP_STg2_FX_Sound__File_Data         psFile_Data;
    TgSN_INST_ID                        tiSound_Instance;

    psSound = g_asFX__Sound + tiData.m.iI;
    psFile_Data = psSound->m_psFile_Data;

    tiSound_Instance = tgSN_Sound_Inst__Init( psFile_Data->m_tiSound, nullptr );
    if (TgTRUE != tgSN_INST_ID_Is_Valid( tiSound_Instance ))
    {
        TgWARNING_MSGF( 0, TgT( "%-16.16s(%-32.32s): Sound instance init failed.\n" ), TgT("Effect"), TgT("tgFX__Sound__Client__Create_Data") );
        return (TgFALSE);
    };

    psSound->m_sExtend.m_vDir_W = M_QT_TX_F32_04( psFile_Data->m_vDirection, psSound->m_qRot_W );

    psSound->m_sExtend.m_tiSound_Instance = tiSound_Instance;

    tgSN_Sound_Inst__Set_Position( tiSound_Instance, psSound->m_vPos_W );
    tgSN_Sound_Inst__Set_Direction( tiSound_Instance, psSound->m_sExtend.m_vDir_W );

    /* Sound lift time is controlled by the audio module */
    g_aenFX__Sound__Shared__State[tiData.m.iI] = ETgFX_EFFECT_STATE__UPDATE__ACTIVE_INFINITE;

    return (TgTRUE);
}


/* ---- tgFX__Update__Sound_Update -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgVOID tgFX__Update__Sound_Update( TgVEC_M_F32_04 UNUSED_PARAM vdT, C_TgFLOAT32 UNUSED_PARAM fDT, C_ETgFX_UPDATE enUpdate )
{
    TgFX_DATA_INST_ID                   tiActive;
    P_STg2_FX__Sound                    psSound;
    CP_STg2_FX_Sound__File_Data         psFile_Data;

    tiActive = T_NAME( s_atiFX__, __Update__Head )[enUpdate];

    while (TgFALSE != tgFX_DATA_INST_ID_Is_Valid( tiActive ))
    {
        tgFX__Update__Sound_Diag_Check_Effect( tiActive );

        psSound = g_asFX__Sound + tiActive.m.iI;
        psFile_Data = psSound->m_psFile_Data;

        if (TgFALSE == tgSN_Sound_Inst__Is_Valid( psSound->m_sExtend.m_tiSound_Instance ))
        {
            psSound->m_sExtend.m_tiSound_Instance = KTgSN_INST_ID__INVALID;
            tgFX__Update__Command__Sound_Kill_Self( psSound->m_tiData );
            continue;
        };

        tiActive = psSound->m_tiNext[ETgFX_NEXT__UPDATE];
    };
}


/* ---- tgFX__Update__Sound_Process_Update_Command ---------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgVOID tgFX__Update__Sound_Process_Update_Command( C_ETgFX_COMMAND enCommand, CP_TgVOID pData, C_TgFX_DATA_INST_ID tiData )
{
    P_STg2_FX__Sound                    psSound;

    tgFX__Update__Sound_Process_Update_Command_Default( enCommand, pData, tiData );

    psSound = g_asFX__Sound + tiData.m.iI;
    switch (enCommand)
    {
        case ETgFX_COMMAND__CLIENT_TO_UPDATE__NOTIFY: /*« Fall Through - Invalid */
        case ETgFX_COMMAND__CLIENT_TO_UPDATE__CREATE: /*« Fall Through - Invalid */
        case ETgFX_COMMAND__CLIENT_TO_UPDATE__SPIN: /*« Fall Through - Invalid */
        case ETgFX_COMMAND__SCENE_TO_RENDER__BEGIN: /*« Fall Through - Invalid */
        case ETgFX_COMMAND__UPDATE_TO_CLIENT__BEGIN: /*« Fall Through - Invalid */
        case ETgFX_COMMAND__UPDATE_TO_CLIENT__NOTIFY: /*« Fall Through - Invalid */
        case ETgFX_COMMAND__UPDATE_TO_CLIENT__FREE: /*« Fall Through - Invalid */
        case ETgFX_COMMAND__MAX: /*« Fall Through - Invalid */
        default: TgS_NO_DEFAULT( break );

        case ETgFX_COMMAND__CLIENT_TO_UPDATE__KILL:
            if (TgFALSE != tgSN_INST_ID_Is_Valid( psSound->m_sExtend.m_tiSound_Instance ))
            {
                tgSN_Sound_Inst__Free( psSound->m_sExtend.m_tiSound_Instance );
                psSound->m_sExtend.m_tiSound_Instance = KTgSN_INST_ID__INVALID;
            };
            break;

        case ETgFX_COMMAND__CLIENT_TO_UPDATE__STOP:
            if (TgFALSE != tgSN_INST_ID_Is_Valid( psSound->m_sExtend.m_tiSound_Instance ))
            {
                tgSN_Sound_Inst__Event_Stop( psSound->m_sExtend.m_tiSound_Instance );
            };
            break;

        case ETgFX_COMMAND__CLIENT_TO_UPDATE__POSITION_SET:
        case ETgFX_COMMAND__CLIENT_TO_UPDATE__POSITION_UPDATE_FROM_PARENT:
            tgSN_Sound_Inst__Set_Position( psSound->m_sExtend.m_tiSound_Instance, psSound->m_vPos_W );
            break;

        case ETgFX_COMMAND__CLIENT_TO_UPDATE__ROTATION_SET:
        case ETgFX_COMMAND__CLIENT_TO_UPDATE__ROTATION_UPDATE_FROM_PARENT:
            psSound->m_sExtend.m_vDir_W = M_QT_TX_F32_04( psSound->m_psFile_Data->m_vDirection, psSound->m_qRot_W );
            tgSN_Sound_Inst__Set_Direction( psSound->m_sExtend.m_tiSound_Instance, psSound->m_sExtend.m_vDir_W );
            tgSN_Sound_Inst__Set_Position( psSound->m_sExtend.m_tiSound_Instance, psSound->m_vPos_W );
            break;

        case ETgFX_COMMAND__CLIENT_TO_UPDATE__VISIBLE: /*« Fall Through - No implementation */
            break;
    };
}