Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Effect - Effect - Update.i_inc
    »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".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
#if !defined(TGS_EFFECT_EFFECT_I_INC)
#define TGS_EFFECT_EFFECT_I_INC
#pragma once


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


#if !defined(T_NAME) || !defined(T_TYPE) || !defined(T_TEXT)
#error Source Include file (template file) missing necessary definitions
/*# !defined(T_NAME) || !defined(T_TYPE) || !defined(T_TEXT) */
#endif

#if !defined(T_EFFECT_UPDATE) || !T_EFFECT_UPDATE
#error Include file only for Effect Update
/*# !defined(T_EFFECT_UPDATE) || !T_EFFECT_UPDATE */
#endif

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

TgINLINE TgBOOL                             T_NAME(tgFX__Client__, _ToClient)( C_TgFX_CLIENT_INST_ID, C_ETgFX_COMMAND, CP_TgVOID );
TgINLINE P_TgUINT08                         T_NAME(tgFX_, __ToClient__Reserve_Command)( C_ETgFX_COMMAND );
TgINLINE TgVOID                             T_NAME(tgFX__Update__Command__, _Create)( C_TgUINTXX, CP_STg2_FX_Instance );
TgINLINE TgVOID                             T_NAME(tgFX__Update__Command__, _Free)( C_TgFX_CLIENT_INST_ID, C_TgFX_DATA_INST_ID );
TgINLINE TgVOID                             T_NAME(tgFX__Update__Command__, _Notify)( CP_STg2_FX_Command__Notify );




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

/* ---- tgFX__Client__, _ToClient --------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL T_NAME(tgFX__Client__, _ToClient)( C_TgFX_CLIENT_INST_ID UNUSED_PARAM tiClient, C_ETgFX_COMMAND enCommand, CP_TgVOID pData )
{
    P_TgUINT08                          puiCommand_Stream;

    if (g_uiFX_Command_Size[enCommand] <= 0)
        return (TgFALSE);

    puiCommand_Stream = T_NAME(tgFX_, __ToClient__Reserve_Command)( enCommand );
    if (nullptr == puiCommand_Stream)
        return (TgFALSE);

    TgMEMCPY( puiCommand_Stream, g_uiFX_Command_Size[enCommand], pData, g_uiFX_Command_Size[enCommand] );
    return (TgTRUE);
}


/* ---- tgFX_, __ToClient__Reserve_Command ------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE P_TgUINT08 T_NAME(tgFX_, __ToClient__Reserve_Command)( C_ETgFX_COMMAND enCommand )
{
    TgSIZE                              uiCommand_Size;
    TgSIZE                              uiCommand_Offset;

    TgPARAM_CHECK( ETgFX_COMMAND__UPDATE_TO_CLIENT__BEGIN <= enCommand && ETgFX_COMMAND__UPDATE_TO_CLIENT__END >= enCommand );
    TgPARAM_CHECK_INDEX( enCommand, g_uiFX_Command_Size );
    TgPARAM_CHECK( ETgFX_COMMAND__MAX > enCommand );

    uiCommand_Size = g_uiFX_Command_Size[enCommand];
    while (1)
    {
        uiCommand_Offset = T_NAME(g_uiFX_Command__, __ToClient_Offset);
        if ((uiCommand_Offset + uiCommand_Size) >= ETgFX_COMMAND__CLIENT_TO_UPDATE__BYTE_MAX)
        {
            TgWARNING_MSGF( 0, TgT( "%-16.16s(%-32.32s): Failed allocation.\n" ), TgT("Effect"), T_TEXT(TgT( "tgFX_") ) TgT("__ToClient__Reserve_Command") );
            tgAM32_XCHG( &g_xiFX_Fence__TO_CLIENT__COMMAND_QUEUE_FULL, 1 );
            return (nullptr);
        };

        if (uiCommand_Offset == tgAMXX_XCMP( &T_NAME(g_uiFX_Command__, __ToClient_Offset), uiCommand_Offset + uiCommand_Size, uiCommand_Offset ))
        {
            return (T_NAME(g_asFX_Command__, __ToClient) + uiCommand_Offset);
        };
    };
}


/* ---- tgFX__Update__Command__, _Create -------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID T_NAME(tgFX__Update__Command__, _Create)( C_TgUINTXX uiHash, CP_STg2_FX_Instance psInstance )
{
    union
    {
        P_TgUINT08                          puiCommand_Stream;
        P_STg2_FX_Command__Client__Create   psCommand;
    }                                   sUnion;

    sUnion.puiCommand_Stream = T_NAME(tgFX_, __ToClient__Reserve_Command)( ETgFX_COMMAND__UPDATE_TO_CLIENT__CREATE );
    if (nullptr == sUnion.puiCommand_Stream)
        return;

    sUnion.psCommand->m_enCommand = ETgFX_COMMAND__UPDATE_TO_CLIENT__CREATE;
    sUnion.psCommand->m_uiHash = uiHash;

    TgMEMCPY( &sUnion.psCommand->m_sInstance, sizeof( sUnion.psCommand->m_sInstance ), psInstance, sizeof( STg2_FX_Instance ) );
}


/* ---- tgFX__Update__Command__, _Free ---------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID T_NAME(tgFX__Update__Command__, _Free)( C_TgFX_CLIENT_INST_ID tiClient, C_TgFX_DATA_INST_ID tiData )
{
    STg2_FX_Command__Client__Free       sCommand;

    sCommand.m_enCommand = ETgFX_COMMAND__UPDATE_TO_CLIENT__FREE;
    sCommand.m_tiData = tiData;
    sCommand.m_tiClient = tiClient;
    T_NAME(tgFX__Client__, _ToClient)( sCommand.m_tiClient, sCommand.m_enCommand, &sCommand );
}


/* ---- tgFX__Update__Command__, _Notify -------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID T_NAME(tgFX__Update__Command__, _Notify)( CP_STg2_FX_Command__Notify psNotify )
{
    STg2_FX_Command__Notify             sCommand;

    sCommand.m_enCommand = ETgFX_COMMAND__UPDATE_TO_CLIENT__NOTIFY;
    sCommand.m_uiMessage = ETgFX_NOTIFY__FRAME_COMPLETE;
    sCommand.m_pNotify = psNotify->m_pNotify;
    T_NAME(tgFX__Client__, _ToClient)( KTgFX_CLIENT_INST_ID__INVALID, sCommand.m_enCommand, &sCommand );
}


/* ====================================================================================================================================================================== */
#endif