Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Effect - Emitter - Scene.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##Emitter##__VA_ARGS__
#define T_TYPE( A, ... ) A##EMITTER##__VA_ARGS__
#define T_TEXT( ... ) __VA_ARGS__ TgT("Emitter")
#define T_EFFECT_TIME_DEFAULT 0
#define T_EFFECT_NOTIFY 1

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


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

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

#include "TgS Effect - Effect - Scene.c_inc"




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

/* ---- tgFX_Emitter__Update_BA ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgVOID tgFX_Emitter__Update_BA( TgFX_DATA_INST_ID tiData )
{
    P_STg2_FX__Emitter                  psEmitter;
    P_STg2_FX__Emitter__Particle        psParticle;

    TgVEC_M_F32_04                      vX, vY;
    TgVEC_M_F32_04                      vBA_Radius;

    psEmitter = g_asFX__Emitter + tiData.m.iI;

    if (psEmitter->m_sExtend.m_psFile_Data__Particle->m_enOrientation == ETgFX_PARTICLE_ORIENTATION__SCREEN_SPACE)
    {
        return;
    };

    /* Effect will not render, generate an approximate bounding box for client thread */
    psEmitter->m_vBA_Max_W = MS_SET1_F32_04( -FLT_MAX );
    psEmitter->m_vBA_Min_W = MS_SET1_F32_04( FLT_MAX );
    psParticle = psEmitter->m_sExtend.m_psParticle_Active;
    while (psParticle)
    {
        vX = M_SPX_F32_04( psParticle->m_vSize );
        vY = M_SPY_F32_04( psParticle->m_vSize );
        vBA_Radius = M_MAX_F32_04( vX, vY );
        psEmitter->m_vBA_Max_W = M_MAX_F32_04( psEmitter->m_vBA_Max_W, M_ADD_F32_04( psParticle->m_vPos_W, vBA_Radius ) );
        psEmitter->m_vBA_Min_W = M_MIN_F32_04( psEmitter->m_vBA_Min_W, M_SUB_F32_04( psParticle->m_vPos_W, vBA_Radius ) );
        psParticle = psParticle->m_psNext;
    };
}


/* ---- tgFX__Scene__Emitter_Cull__Insert_Frame_Mesh -------------------------------------------------------------------------------------------------------------------- */
/* Mesh emission requires adding a mesh for every "particle" into the scene context                                                                                       */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgVOID tgFX__Scene__Emitter_Cull__Insert_Frame_Mesh( PC_STg2_SE_Context psSE_Context, C_TgSINT32 iView_Index, TgFX_DATA_INST_ID tiActive )
{
    P_STg2_FX__Emitter                  psEmitter;
    CP_STg2_FX_Emitter__File_Data       psFile_Data;
    CP_STg2_FX_Particle__File_Data      psFile_Data__Particle;
    TgSINT32                            iEmitter_Frame_Mesh_Set__LOD_Index;
    TgVEC_M_F32_04                      vEmitter_Frame_Mesh_Set__Scale;
    TgVEC_F32_04                        vEmitter_Frame_Mesh_Set__Ambient;
    P_TgUINT32                          auiEmitter_Frame_Mesh_Set__Light_List;
    TgUINT32                            nuiEmitter_Frame_Mesh_Set__Light;
    TgUINT32                            uiEmitter_Frame_Mesh__Flag;
    P_STg2_FX__Emitter__Particle        psParticle;
    TgSINT32                            iIndex_In_SE_Context;
    TgSINT32                            iMax_Index_In_SE_Context;
    TgSINT32                            iView_Inst_Index;
    TgSINT32                            iView_Inst_Max_Index;
    P_TgSINT32                          piRN_Frame_Mesh_Inst;

    psEmitter = g_asFX__Emitter + tiActive.m.iI;
    psFile_Data = psEmitter->m_psFile_Data;
    psFile_Data__Particle = psEmitter->m_sExtend.m_psFile_Data__Particle;

    iIndex_In_SE_Context = tgAM32_XADD( &psSE_Context->m_niRN_Frame_Mesh, psEmitter->m_sExtend.m_niParticle );
    if (iIndex_In_SE_Context >= psSE_Context->m_niRN_Max_Frame_Mesh)
    {
        tgAM32_XADD( &psSE_Context->m_niRN_Frame_Mesh, -psEmitter->m_sExtend.m_niParticle );
        return;
    }

    iMax_Index_In_SE_Context = iIndex_In_SE_Context + psEmitter->m_sExtend.m_niParticle;

    if (TgTRUE == tgRN_Material__Is_Opaque( psEmitter->m_tiMaterial ))
    {
        iView_Inst_Index = tgAM32_XADD( psSE_Context->m_asView[iView_Index].m_aniRN_Frame_Mesh_Inst + ETgSE_DRAW_TYPE__OPAQUE, 1 );
        iView_Inst_Max_Index = psSE_Context->m_asView[iView_Index].m_aniRN_Max_Frame_Mesh_Inst[ETgSE_DRAW_TYPE__OPAQUE];
        piRN_Frame_Mesh_Inst = psSE_Context->m_asView[iView_Index].m_apiRN_Frame_Mesh_Inst[ETgSE_DRAW_TYPE__OPAQUE];
    }
    else
    {
        iView_Inst_Index = tgAM32_XADD( psSE_Context->m_asView[iView_Index].m_aniRN_Frame_Mesh_Inst + ETgSE_DRAW_TYPE__TRANSPARENT, 1 );
        iView_Inst_Max_Index = psSE_Context->m_asView[iView_Index].m_aniRN_Max_Frame_Mesh_Inst[ETgSE_DRAW_TYPE__TRANSPARENT];
        piRN_Frame_Mesh_Inst = psSE_Context->m_asView[iView_Index].m_apiRN_Frame_Mesh_Inst[ETgSE_DRAW_TYPE__TRANSPARENT];
    };

    iEmitter_Frame_Mesh_Set__LOD_Index = psSE_Context->m_asRN_Frame_Mesh[psEmitter->m_iIndex_In_SE_Context].m_iLOD_Index;
    vEmitter_Frame_Mesh_Set__Scale = psSE_Context->m_asRN_Frame_Mesh[psEmitter->m_iIndex_In_SE_Context].m_vScale;
    vEmitter_Frame_Mesh_Set__Ambient = psSE_Context->m_asRN_Frame_Mesh[psEmitter->m_iIndex_In_SE_Context].m_vAmbient;
    auiEmitter_Frame_Mesh_Set__Light_List = psSE_Context->m_asRN_Frame_Mesh[psEmitter->m_iIndex_In_SE_Context].m_auiLight;
    nuiEmitter_Frame_Mesh_Set__Light = psSE_Context->m_asRN_Frame_Mesh[psEmitter->m_iIndex_In_SE_Context].m_nuiLight;
    uiEmitter_Frame_Mesh__Flag = psSE_Context->m_asRN_Frame_Mesh[psEmitter->m_iIndex_In_SE_Context].m_uiFlags;

    psParticle = psEmitter->m_sExtend.m_psParticle_Active;

    while (iIndex_In_SE_Context < iMax_Index_In_SE_Context)
    {
        TgVEC_F32_04                                vPos_W;
        TgVEC_F32_04                                qRot_W;
        P_STg2_RN_Cxt_Mesh                          pRN_Cxt_Mesh;

        pRN_Cxt_Mesh = psSE_Context->m_asRN_Frame_Mesh + iIndex_In_SE_Context;
        pRN_Cxt_Mesh->m_tiMesh_Set = psEmitter->m_tiMesh_Set;
        pRN_Cxt_Mesh->m_iLOD_Index = iEmitter_Frame_Mesh_Set__LOD_Index;
        pRN_Cxt_Mesh->m_uiFlags = uiEmitter_Frame_Mesh__Flag;

        pRN_Cxt_Mesh->m_vScale = vEmitter_Frame_Mesh_Set__Scale;
        vPos_W.m_mData = psParticle->m_vPos_W;
        qRot_W.m_mData = M_QT_MUL_F32_04( psEmitter->m_qRot_W, psParticle->m_qRot_M );
        F_Init_Quat_F32_34( &pRN_Cxt_Mesh->m_xTX, &qRot_W );
        F_SET_T_F32_34( &pRN_Cxt_Mesh->m_xTX, &vPos_W );

        pRN_Cxt_Mesh->m_vLast_Scale = KTgV_ONE_F32_04.m_mData;
        pRN_Cxt_Mesh->m_xLast_TX = KTgX_IDENT_F32_34;

        pRN_Cxt_Mesh->m_vBA_Max_W = psEmitter->m_vBA_Max_W;
        pRN_Cxt_Mesh->m_vBA_Min_W = psEmitter->m_vBA_Min_W;

        pRN_Cxt_Mesh->m_vAmbient = vEmitter_Frame_Mesh_Set__Ambient;
        pRN_Cxt_Mesh->m_vLM = KTgV_ZERO_F32_04;
        pRN_Cxt_Mesh->m_tiLM = KTgKN_TX_IMG_ID__INVALID;
        pRN_Cxt_Mesh->m_tiMaterial = psEmitter->m_tiMaterial;
        memcpy( pRN_Cxt_Mesh->m_auiLight, auiEmitter_Frame_Mesh_Set__Light_List, KTgRN_CXT_MAX_LIGHT_PER_INSTANCE * sizeof( TgUINT32 ) );
        pRN_Cxt_Mesh->m_nuiLight = nuiEmitter_Frame_Mesh_Set__Light;

        pRN_Cxt_Mesh->m_iSkeleton_0 = -1;
        pRN_Cxt_Mesh->m_iSkeleton_1 = -1;

        pRN_Cxt_Mesh->m_fOpacity = 1.0F;

        if (iView_Inst_Index < iView_Inst_Max_Index)
        {
            piRN_Frame_Mesh_Inst[iView_Inst_Index] = iIndex_In_SE_Context;
            ++iView_Inst_Index;
        };

        ++iIndex_In_SE_Context;

        psParticle = psParticle->m_psNext;
    };

    /* Invalidate the emitter in the SE Context */
    psSE_Context->m_asRN_Frame_Mesh[psEmitter->m_iIndex_In_SE_Context].m_tiMesh_Set = KTgRN_MESH_SET_ID__INVALID;
    psSE_Context->m_asRN_Frame_Mesh[psEmitter->m_iIndex_In_SE_Context].m_tiMaterial = KTgRN_MATERIAL_ID__INVALID;
}