Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Effect - Internal.h
    »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_INTERNAL_H)
#define TGS_EFFECT_INTERNAL_H

#include "TgS Collision.h"
#include "TgS Utility.h"
#include "TgS Render.h"
#include "TgS Sound.h"
#include "TgS Script.h"
#include "TgS Object.h"
#include "TgS Set.h"

#include "TgS Effect.h"

#include "TgS Effect - Internal - Type.h"
#include "TgS Effect - Internal - Data.h"


/* == Effects =========================================================================================================================================================== */

/* The effect system has three lanes of execution ownership.  The client thread owns creation and termination of effect instances.  The render thread owns the other */
/* two lanes - updating and rendering.  Communication between the client and render threads is done by message passing within the effect system.  Each effect instance */
/* has a client thread id and a render thread id.  The process for creation requires that the client thread create a generic effect instance, and then pass the creation */
/* message to the render thread.  As long as the render thread instance is active the entire effect instance is owned by the render thread.  Once the render */
/* instance is done it will send back a message to the client thread for termination.  Early termination requires the client thread to send a termination message to */
/* the render thread.  The client thread instance cannot be terminated until the render thread sends its termination request. */

/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Thread  | Client                               | Update (Jobs)                         | Scene (Jobs)                         | Render Thread and Jobs               | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Goal    |                                      | Update All Effects                    | Add all visible effects to the scene | Render all Effects in Scene          | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Pre     | [Previous Render Jobs in Flight]     |                                       |                                      |                                      | */
/*         | [No Update Jobs]                     |                                       |                                      |                                      | */
/*         | [No Scene Jobs]                      |                                       |                                      |                                      | */
/*         | OWN: Client Effect Data              |                                       |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Execute | SINGLE UPDATE: Default Update List   |                                       |                                      |                                      | */
/*         | SINGLE UPDATE: External Update List  |                                       |                                      |                                      | */
/*         | FLUSH: New Update List               |                                       |                                      |                                      | */
/*         | EXECUTE: ToClient Commands           |                                       |                                      |                                      | */
/*         |                                      |                                       |                                      |                                      | */
/*         | Execute all ToClient Commands        |                                       |                                      |                                      | */
/*         | Remove all deleted effects from lists|                                       |                                      |                                      | */
/*         | Add all new effects to update lists  |                                       |                                      |                                      | */
/*         |                                      |                                       |                                      |                                      | */
/*         | Submit Update Jobs                   |                                       |                                      |                                      | */
/*         |  - Update Default List               |                                       |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Pre     |                                      | [No Trigger - Start on Submit]        |                                      |                                      | */
/*         |                                      | OWN: System Effect Data               |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Execute |                                      | Update the Default Update List        |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Pre     | [Scene Camera Set]                   |                                       |                                      |                                      | */
/*         | [Buffer Toggle]                      |                                       |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Execute | Submit Scene Cull Jobs               |                                       |                                      |                                      | */
/*         |  - Update Default List               |                                       |                                      |                                      | */
/*         |  - Update External List              |                                       |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Pre     |                                      |                                       | [Scene Camera Set]                   |                                      | */
/*         |                                      |                                       |  - Known from Submit                 |                                      | */
/*         |                                      |                                       | RENDER NEXT?                         |                                      | */
/*         |                                      |                                       | OWN: Bounding Box                    |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Execute |                                      |                                       | Cull the Default Update List         |                                      | */
/*         |                                      |                                       | Cull the External Update List        |                                      | */
/*         |                                      |                                       | Culling Pass                         |                                      | */
/*         |                                      |                                       | - If visible to camera               |                                      | */
/*         |                                      |                                       |   - Add to render list               |                                      | */
/*         |                                      |                                       |   - Reserve a Context Index          |                                      | */
/*         |                                      |                                       | - Else                               |                                      | */
/*         |                                      |                                       |   - Clear the Context Index          |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Pre     | [Attachment  Update Complete]        |                                       |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Execute | Submit Update Jobs                   |                                       |                                      |                                      | */
/*         |  - Update External List              |                                       |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Pre     |                                      | [Attachment  Update Complete]         |                                      |                                      | */
/*         |                                      |  - Known from Submit                  |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Execute |                                      | Update the External Update List       |                                      |                                      | */
/*         |                                      |                                       |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Pre     | [Client Update Complete]             |                                       |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Execute | Submit all Jobs for ToUpdate Commands|                                       |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Pre     |                                      | [Default Update Complete]             |                                      |                                      | */
/*         |                                      | [External Update Complete]            |                                      |                                      | */
/*         |                                      | [Client Update Complete]              |                                      |                                      | */
/*         |                                      |  - Known from Submit                  |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Execute |                                      | Execute all ToUpdate Commands         |                                      |                                      | */
/*         |                                      |  - Creates effects (added to new list)|                                      |                                      | */
/*         |                                      |  - Notify Messages                    |                                      |                                      | */
/*         |                                      |  - Delete Effect (mark for removal)   |                                      |                                      | */
/*         |                                      |                                       |                                      |                                      | */
/*         |                                      |  - Update New Effects                 |                                      |                                      | */
/*         |                                      |  - Cull New Effects                   |                                      |                                      | */
/*         |                                      |                                       |                                      |                                      | */
/*         |                                      |  - Submit Bounding Box Update         |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Post    |                                      | UPDATE DONE: All Effects Updated      |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Pre     | [All Scene Cull Jobs Complete]       |                                       | [All Scene Cull Jobs Complete]       |                                      | */
/*         | [ToUpdate Commands Complete]         |                                       | [ToUpdate Commands Complete]         |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Execute | Scene Processing                     |                                       | Update Bounding Boxes not in Render  |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Post    |                                      |                                       | CULL DONE: Effects culled in scene   |                                      | */
/*         |                                      |                                       | SCENE DONE                           |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Pre     | [Scene Submitted for Rendering]      |                                       |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Execute | Submit all Jobs for Rendering        |                                       |                                      |                                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Pre     |                                      |                                       |                                      | [Scene Submitted for Rendering]      | */
/*         |                                      |                                       |                                      |  - Known from Submit                 | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Execute |                                      |                                       |                                      | Request Particle Headers from System | */
/*         |                                      |                                       |                                      |  - Patch Context Buffer              | */
/*         |                                      |                                       |                                      |  - Map Context to Particle Buffer    | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Pre     |                                      |                                       |                                      | [All Allocation Jobs Complete]       | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Execute |                                      |                                       |                                      | Priority sort Particle Headers       | */
/*         |                                      |                                       |                                      |  - Clamp at Max Memory for Effects   | */
/*         |                                      |                                       |                                      | Assign memory into each Header       | */
/*         |                                      |                                       |                                      |                                      | */
/*         |                                      |                                       |                                      | Submit all job for Render Generation | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Pre     |                                      |                                       |                                      | [Allocations Complete]               | */
/*         |                                      |                                       |                                      |  - Known from Submit                 | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Execute |                                      |                                       |                                      | Render Geometry                      | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */
/* Post    |                                      |                                       |                                      | RENDER DONE                          | */
/* --------|--------------------------------------|---------------------------------------|--------------------------------------|--------------------------------------| */


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

/* ---- Effect Functions ------------------------------------------------------------------------------------------------------------------------------------------------ */

TgEXTN TgSINT32                             tgFX__Client__Get_Client_Index( C_TgFX_CLIENT_INST_ID );
TgEXTN TgVOID                               tgFX__Client__Free_Internal( C_TgSINT32 );

TgEXTN TgVOID                               tgFX__Client__Set_Position_From_External_Update( C_TgFX_CLIENT_INST_ID, TgVEC_M_F32_04 );
TgEXTN TgVOID                               tgFX__Client__Set_Rotation_From_External_Update( C_TgFX_CLIENT_INST_ID, TgVEC_M_F32_04 );
TgEXTN TgVOID                               tgFX__Client__Update_Position_From_Parent( C_TgFX_CLIENT_INST_ID, TgVEC_M_F32_04 );
TgEXTN TgVOID                               tgFX__Client__Update_Rotation_From_Parent( C_TgFX_CLIENT_INST_ID, TgVEC_M_F32_04 );


/* ---- System Functions ------------------------------------------------------------------------------------------------------------------------------------------------ */

TgEXTN TgVOID                               tgFX__Client__Update_From_External_Module_Data( C_TgFLOAT32 );
TgEXTN TgVOID                               tgFX__Client__Collect_Collision_Results( C_TgBOOL );
TgEXTN TgBOOL                               tgFX__Client__Queue_Update_Command( C_ETgFX__EFFECT, C_ETgFX_COMMAND, CP_TgVOID );


/* ---- Effect File Data and PreLoad ------------------------------------------------------------------------------------------------------------------------------------ */

TgEXTN TgVOID                               tgFX__Update__Set_Render_Data_From_Material_Hash( P_TgRN_MESH_SET_ID, P_TgRN_MATERIAL_ID, P_ETgRN_VERTEX, C_TgUINTXX );

TgEXTN TgVOID                               tgFX_Effect__Increment_Reference( C_TgFX_EFFECT_ID );
TgEXTN TgVOID                               tgFX_Effect__Decrement_Reference( C_TgFX_EFFECT_ID );

TgEXTN TgSINT64                             tgFX__File__Bind_Effect( C_TgKN_FILE_ID, PC_STg2_Input_MEM );
TgEXTN TgVOID                               tgFX__File__UnBind_Effect( C_TgSINT64, C_TgKN_FILE_ID );
TgEXTN TgSINT64                             tgFX__Client__UnBind_Effect( C_TgSINT64, C_TgKN_FILE_ID );


/* ---- Utility --------------------------------------------------------------------------------------------------------------------------------------------------------- */

TgEXTN TgVEC_M_F32_04                       tgFX_Integrate_AnimData_F32_04( P_STg2_FX_AnimData, C_TgVEC_M_F32_04, C_TgVEC_M_F32_04 );
TgEXTN TgVEC_M_F32_04                       tgFX_Evaluate_AnimData_F32_04( P_STg2_FX_AnimData, C_TgVEC_M_F32_04 );
TgEXTN TgUINTXX                             tgFX_Evaluate_Single_AnimData_UXX( P_STg2_FX_AnimData, C_TgFLOAT32, C_TgFLOAT32 );


/* ---- Effect ---------------------------------------------------------------------------------------------------------------------------------------------------------- */

/* Beam Effect */
#define T_NAME( A, ... ) A##Beam##__VA_ARGS__
#define T_TYPE( A, ... ) A##BEAM##__VA_ARGS__
#include "TgS Effect - Effect.h_inc"

/* Billboard Effect */
#define T_NAME( A, ... ) A##Billboard##__VA_ARGS__
#define T_TYPE( A, ... ) A##BILLBOARD##__VA_ARGS__
#include "TgS Effect - Effect.h_inc"

/* Decal Effect */
#define T_NAME( A, ... ) A##Decal##__VA_ARGS__
#define T_TYPE( A, ... ) A##DECAL##__VA_ARGS__
#include "TgS Effect - Effect.h_inc"

/* Emitter Effect */
#define T_NAME( A, ... ) A##Emitter##__VA_ARGS__
#define T_TYPE( A, ... ) A##EMITTER##__VA_ARGS__
#include "TgS Effect - Effect.h_inc"

/* Glass Effect */
#define T_NAME( A, ... ) A##Glass##__VA_ARGS__
#define T_TYPE( A, ... ) A##GLASS##__VA_ARGS__
#include "TgS Effect - Effect.h_inc"

/* GIB Effect */
#define T_NAME( A, ... ) A##GIB##__VA_ARGS__
#define T_TYPE( A, ... ) A##GIB##__VA_ARGS__
#include "TgS Effect - Effect.h_inc"

/* Group Effect */
#define T_NAME( A, ... ) A##Group##__VA_ARGS__
#define T_TYPE( A, ... ) A##GROUP##__VA_ARGS__
#define T_EFFECT_SCENE 0
#define T_EFFECT_RENDER 0
#include "TgS Effect - Effect.h_inc"

/* Light Effect */
#define T_NAME( A, ... ) A##Light##__VA_ARGS__
#define T_TYPE( A, ... ) A##LIGHT##__VA_ARGS__
#define T_EFFECT_RENDER 0
#include "TgS Effect - Effect.h_inc"

/* Liquid Effect */
#define T_NAME( A, ... ) A##Liquid##__VA_ARGS__
#define T_TYPE( A, ... ) A##LIQUID##__VA_ARGS__
#include "TgS Effect - Effect.h_inc"

/* Post Effect */
#define T_NAME( A, ... ) A##Post##__VA_ARGS__
#define T_TYPE( A, ... ) A##POST##__VA_ARGS__
#include "TgS Effect - Effect.h_inc"

/* Sound Effect */
#define T_NAME( A, ... ) A##Sound##__VA_ARGS__
#define T_TYPE( A, ... ) A##SOUND##__VA_ARGS__
#define T_EFFECT_SCENE 0
#define T_EFFECT_RENDER 0
#include "TgS Effect - Effect.h_inc"

/* Trail Effect */
#define T_NAME( A, ... ) A##Trail##__VA_ARGS__
#define T_TYPE( A, ... ) A##TRAIL##__VA_ARGS__
#include "TgS Effect - Effect.h_inc"


/* ---- Debug ----------------------------------------------------------------------------------------------------------------------------------------------------------- */

#if TgS_DEBUG_EFFECT
TgEXTN TgVOID                               tgFX_Debug__Load_Config( TgVOID );
TgEXTN TgBOOL                               tgFX_Debug__Is_Valid( C_TgFX_CLIENT_INST_ID, C_TgFX_DATA_INST_ID );
/*# TgS_DEBUG_EFFECT */
#else
#define tgFX_Debug__Is_Valid(...)           TgTRUE
/*# TgS_DEBUG_EFFECT */
#endif

#if TgS_STAT_EFFECT
    #define STAT(...)                       __VA_ARGS__
/*# TgS_STAT_EFFECT */
#else
    #define STAT(...)
/*# TgS_STAT_EFFECT */
#endif


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