397 lines
12 KiB
C++
397 lines
12 KiB
C++
#include "StdAfx.h"
|
|
|
|
#include "TPG_OSys.hpp"
|
|
|
|
#include "_Minterf.hpp"
|
|
#include "TPG_Strg.hpp"
|
|
#include "TPG_ClBk.hpp"
|
|
|
|
#include "PRT.h"
|
|
#include "GAM.h"
|
|
#include "MTH.h"
|
|
#include "ErO.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
|
|
//////////////////////////////////////
|
|
// Constructor and Destructor
|
|
//////////////////////////////////////
|
|
CPA_PartGen_System::CPA_PartGen_System(CString _csName, long _lNbParticles ) : CPA_SaveObject( g_pclInterface, g_C_csPartGenSystemName, E_ss_Responsible )
|
|
{
|
|
SetSectionData( this );
|
|
SetCallBackSave( m_s_fn_vCallBackSaveSystem );
|
|
SetDataPath( C_szEffectPath );
|
|
|
|
if ( fn_eRename(_csName) != E_mc_None )
|
|
SetDefaultValidName();
|
|
|
|
fn_vUpdateSectionName();
|
|
SetExistingSection( FALSE );
|
|
|
|
PRT_tdstParticlesSystem* p_stSystem;
|
|
PRT_fn_vCreateParticlesSystem( &p_stSystem, (ACP_tdxIndex)_lNbParticles );
|
|
PRT_fn_vInitParticlesSystem( p_stSystem );
|
|
fn_vUpdateData( (void*)p_stSystem );
|
|
m_pri_p_stSystem = p_stSystem;
|
|
|
|
m_pri_hGameMaterial = NULL;
|
|
m_pri_hSprite = NULL;
|
|
|
|
m_pri_fn_vFillDataList();
|
|
}
|
|
|
|
CPA_PartGen_System::CPA_PartGen_System(CString _csName, PRT_tdstParticlesSystem* _p_stSystem, BOOL _bIsLoaded )
|
|
: CPA_SaveObject( g_pclInterface, g_C_csPartGenSystemName, E_ss_Responsible )
|
|
{
|
|
SetSectionData( this );
|
|
SetCallBackSave( m_s_fn_vCallBackSaveSystem );
|
|
SetDataPath( C_szEffectPath );
|
|
|
|
if ( fn_eRename(_csName) != E_mc_None )
|
|
SetDefaultValidName();
|
|
|
|
fn_vUpdateSectionName();
|
|
SetExistingSection( TRUE );
|
|
|
|
SetAvailable( _bIsLoaded );
|
|
|
|
fn_vUpdateData( (void*)_p_stSystem );
|
|
m_pri_p_stSystem = _p_stSystem;
|
|
|
|
m_pri_hGameMaterial = NULL;
|
|
m_pri_hSprite = NULL;
|
|
|
|
if( _bIsLoaded )
|
|
{
|
|
m_pri_fn_vSetInternalParticle();
|
|
m_pri_fn_vFillDataList();
|
|
}
|
|
}
|
|
|
|
CPA_PartGen_System::~CPA_PartGen_System()
|
|
{
|
|
fn_vNotifyUnSave();
|
|
}
|
|
|
|
|
|
void CPA_PartGen_System::m_pub_fn_vSetSystem( PRT_tdstParticlesSystem *_p_stSystem )
|
|
{
|
|
fn_vUpdateData( (void*)_p_stSystem );
|
|
m_pri_p_stSystem = _p_stSystem;
|
|
SetAvailable( TRUE );
|
|
|
|
m_pri_fn_vSetInternalParticle();
|
|
m_pri_fn_vFillDataList();
|
|
}
|
|
|
|
////////////////////////////////////
|
|
// Virtual functions
|
|
long CPA_PartGen_System::GetDataType( void )
|
|
{
|
|
return( 0 );
|
|
}
|
|
|
|
void* CPA_PartGen_System::GetData( void )
|
|
{
|
|
return (void*)m_pri_p_stSystem;
|
|
}
|
|
|
|
CString CPA_PartGen_System::fn_csComputeReferencedSectionName(const CString _csNewName)
|
|
{
|
|
CString csResult = "Systems.prt^";
|
|
csResult += C_SectionPrtSysDescription;
|
|
csResult += ":";
|
|
return( csResult + _csNewName );
|
|
}
|
|
|
|
|
|
//*************************************************
|
|
// Load if necessary
|
|
BOOL CPA_PartGen_System::m_pub_fn_vLoadIfUnloaded()
|
|
{
|
|
if ( !fn_bIsAvailable() )
|
|
{
|
|
CString csSectionName = GetReferencedSectionName();
|
|
|
|
SCR_tdst_Cxt_Values *p_stValues;
|
|
p_stValues = SCR_fnp_st_RdL0_AnalyseSection((char *)LPCTSTR(csSectionName), SCR_CDF_uw_Anl_Normal);
|
|
|
|
PRT_tdstParticlesSystem *p_stSys = (PRT_tdstParticlesSystem*)p_stValues->a_ulValues[0];
|
|
fn_vUpdateData( (void*)p_stSys );
|
|
m_pri_p_stSystem = p_stSys;
|
|
SetAvailable(TRUE);
|
|
|
|
m_pri_fn_vSetInternalParticle();
|
|
m_pri_fn_vFillDataList();
|
|
return TRUE;
|
|
}
|
|
else return FALSE;
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////
|
|
// Point, Segment and Sprite
|
|
long CPA_PartGen_System::m_pub_fn_lGetParticlesType()
|
|
{
|
|
return (long)m_pri_p_stSystem->xParticlesType;
|
|
}
|
|
|
|
void CPA_PartGen_System::m_pub_fn_vSetObjectPoint( GMT_tdxHandleToGameMaterial _hGameMaterial )
|
|
{
|
|
PRT_fn_vCreatePointParticles( m_pri_p_stSystem, _hGameMaterial );
|
|
}
|
|
|
|
GMT_tdxHandleToGameMaterial CPA_PartGen_System::m_pub_fn_hGetPointGameMaterial()
|
|
{
|
|
return GEO_xGetGameMaterialOfElementPoints(m_pri_p_stSystem->hParticlesSystemObject,0);
|
|
}
|
|
|
|
void CPA_PartGen_System::m_pub_fn_vSetObjectSegment( GMT_tdxHandleToGameMaterial _hGameMaterial )
|
|
{
|
|
PRT_fn_vCreateSegmentParticles( m_pri_p_stSystem, _hGameMaterial );
|
|
}
|
|
|
|
GMT_tdxHandleToGameMaterial CPA_PartGen_System::m_pub_fn_hGetSegmentGameMaterial()
|
|
{
|
|
GMT_tdxHandleToGameMaterial hGameMaterial;
|
|
GEO_xGetGameMaterialOfElementLines(m_pri_p_stSystem->hParticlesSystemObject,0, 0, &hGameMaterial);
|
|
return hGameMaterial;
|
|
}
|
|
|
|
void CPA_PartGen_System::m_pub_fn_vSetObjectSprite( ACP_tdxHandleOfSprite _hSprite )
|
|
{
|
|
PRT_fn_vCreateSpriteParticles( m_pri_p_stSystem, _hSprite );
|
|
}
|
|
|
|
ACP_tdxHandleOfSprite CPA_PartGen_System::m_pub_fn_hGetSprite()
|
|
{
|
|
ACP_tdxHandleOfSprite hSprite;
|
|
GEO_vGetHandleOfIndexedSprite(m_pri_p_stSystem->hParticlesSystemObject, 0, 0, &hSprite );
|
|
return hSprite;
|
|
}
|
|
|
|
void CPA_PartGen_System::m_pri_fn_vSetInternalParticle()
|
|
{
|
|
ACP_tdxIndex xType = m_pri_p_stSystem->xParticlesType;
|
|
switch( xType )
|
|
{
|
|
case PRT_C_xPointParticles:
|
|
m_pri_hGameMaterial = GEO_xGetGameMaterialOfElementPoints(m_pri_p_stSystem->hParticlesSystemObject,0);
|
|
break;
|
|
|
|
case PRT_C_xSegmentParticles:
|
|
GEO_xGetGameMaterialOfElementLines(m_pri_p_stSystem->hParticlesSystemObject,0, 0, &m_pri_hGameMaterial);
|
|
break;
|
|
|
|
case PRT_C_xSpriteParticles:
|
|
GEO_vGetHandleOfIndexedSprite(m_pri_p_stSystem->hParticlesSystemObject, 0, 0, &m_pri_hSprite );
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
//****************************************************
|
|
// Gets name of the associated object using link table
|
|
CString CPA_PartGen_System::m_pub_fn_csGetObjectName()
|
|
{
|
|
CString csObjectName = "";
|
|
SCR_tdst_Link_Table *p_stLinkTable = NULL;
|
|
SCR_tdst_Link_Value *p_stValue = NULL;
|
|
unsigned long ulValue = 0;
|
|
|
|
long lIndex = m_pub_fn_lGetParticlesType();
|
|
switch( lIndex )
|
|
{
|
|
case PRT_C_xPointParticles:
|
|
p_stLinkTable = GMT_fn_p_stGetLinkTable();
|
|
ulValue = (unsigned long)m_pub_fn_hGetPointGameMaterial();
|
|
break;
|
|
|
|
case PRT_C_xSegmentParticles:
|
|
p_stLinkTable = GMT_fn_p_stGetLinkTable();
|
|
ulValue = (unsigned long)m_pub_fn_hGetSegmentGameMaterial();
|
|
break;
|
|
|
|
case PRT_C_xSpriteParticles:
|
|
p_stLinkTable = GLI_p_stGetLinkTableOfSprite();
|
|
ulValue = (unsigned long)m_pub_fn_hGetSprite();
|
|
break;
|
|
}
|
|
|
|
//*** finds the entry *****
|
|
if( p_stLinkTable != NULL )
|
|
p_stValue = SCR_fnp_st_Link_SearchValue( p_stLinkTable, ulValue );
|
|
|
|
//*** gets the name of the entry ******************************************************
|
|
if( p_stValue != NULL && SCR_M_e_Link_GetState(p_stValue) == SCR_ELS_Link_Initialized )
|
|
{
|
|
csObjectName = SCR_M_p_sz_Link_GetKey(p_stValue);
|
|
|
|
char a_256cFileName[256];
|
|
char a_256cActionName[256];
|
|
char a_256cName[256];
|
|
SCR_fn_v_RdL0_SplitSectionName((char *)LPCTSTR(csObjectName), a_256cFileName, a_256cActionName, a_256cName);
|
|
|
|
csObjectName = a_256cName;
|
|
}
|
|
return csObjectName;
|
|
}
|
|
|
|
/////////////////////////////////////////////////
|
|
// Nb particles
|
|
long CPA_PartGen_System::m_pub_fn_lGetNbParticles()
|
|
{
|
|
return (long)m_pri_p_stSystem->xNbParticles;
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
// CallBack and Function for save
|
|
void CPA_PartGen_System::m_s_fn_vCallBackSaveSystem
|
|
(
|
|
SCR_tdst_File_Description *_p_stFile,
|
|
char *_p_szSectionName,
|
|
void *_p_vData,
|
|
SCR_tde_Ntfy_Action _eAction
|
|
)
|
|
{
|
|
ERROR_PREPARE_M
|
|
(
|
|
g_c_csPartGenModuleNameForErrors,
|
|
"Saving a generator",
|
|
"CPA_PartGen_System::m_s_fn_vCallBackSaveSystem",
|
|
E_ERROR_GRAVITY_FATAL,
|
|
"trying to save a NULL system"
|
|
);
|
|
CPA_PartGen_System *p_clSys = (CPA_PartGen_System*)_p_vData;
|
|
CString csHeaderName = C_SectionPrtSysDescription;
|
|
|
|
switch( _eAction )
|
|
{
|
|
case SCR_EA_Ntfy_AddSection:
|
|
case SCR_EA_Ntfy_AddOrModifySection:
|
|
case SCR_EA_Ntfy_AddOrRebuildSection:
|
|
case SCR_EA_Ntfy_RebuildSection:
|
|
case SCR_EA_Ntfy_ModifySection:
|
|
|
|
csHeaderName += ":";
|
|
csHeaderName += p_clSys->GetName();
|
|
|
|
SCR_M_SvL0_SaveBeginSection( _p_stFile, M_MAKECHAR(csHeaderName), SCR_CC_C_Cfg_NoChar );
|
|
SCR_fn_v_SvL0_SaveParameters_MP( _p_stFile, SCR_EF_SvL0_Scanf, 2, "%d", p_clSys->m_pub_fn_lGetNbParticles() );
|
|
|
|
p_clSys->m_pri_fn_vSaveSystem( _p_stFile );
|
|
|
|
SCR_M_SvL0_SaveEndSection( _p_stFile, SCR_CC_C_Cfg_EOL );
|
|
|
|
p_clSys->fn_vSectionSaved();
|
|
break;
|
|
|
|
case SCR_EA_Ntfy_DeleteIfExists:
|
|
case SCR_EA_Ntfy_DeleteSection:
|
|
p_clSys->fn_vSectionDeleted();
|
|
break;
|
|
}
|
|
}
|
|
|
|
void CPA_PartGen_System::m_pri_fn_vSaveSystem( SCR_tdst_File_Description *_p_stFile )
|
|
{
|
|
SCR_tdst_Link_Value *p_stLinkValue = NULL;
|
|
unsigned long ulValue = 0;
|
|
SCR_tdst_Link_Table *p_stLinkTable = NULL;
|
|
CString csEntryName = "";
|
|
long lIndex = m_pub_fn_lGetParticlesType();
|
|
switch( lIndex )
|
|
{
|
|
//*** Point particles *****
|
|
case PRT_C_xPointParticles:
|
|
p_stLinkTable = GMT_fn_p_stGetLinkTable();
|
|
ulValue = (unsigned long)m_pub_fn_hGetPointGameMaterial();
|
|
csEntryName = C_EntryPrtSysCreatePoint;
|
|
break;
|
|
|
|
//*** Segment particles *****
|
|
case PRT_C_xSegmentParticles:
|
|
p_stLinkTable = GMT_fn_p_stGetLinkTable();
|
|
ulValue = (unsigned long)m_pub_fn_hGetSegmentGameMaterial();
|
|
csEntryName = C_EntryPrtSysCreateSegment;
|
|
break;
|
|
|
|
//*** Sprite particles *****
|
|
case PRT_C_xSpriteParticles:
|
|
p_stLinkTable = GLI_p_stGetLinkTableOfSprite();
|
|
ulValue = (unsigned long)m_pub_fn_hGetSprite();
|
|
csEntryName = C_EntryPrtSysCreateSprite;
|
|
break;
|
|
}
|
|
|
|
if( p_stLinkTable != NULL )
|
|
{
|
|
p_stLinkValue = SCR_fnp_st_Link_SearchValue( p_stLinkTable, ulValue );
|
|
if ( p_stLinkValue != NULL )
|
|
{
|
|
SCR_M_SvL0_SaveEntry( _p_stFile, M_MAKECHAR(csEntryName), SCR_CC_C_Cfg_NoChar );
|
|
|
|
CString csKey = SCR_M_p_sz_Link_GetKey(p_stLinkValue);
|
|
long lOffset = SCR_M_ul_Link_GetAdditionalLong(p_stLinkValue, 1);
|
|
if ( lOffset > 0 )
|
|
csKey = csKey.Right(csKey.GetLength() - lOffset);
|
|
|
|
SCR_fn_v_SvL0_SaveParameters_MP(_p_stFile, SCR_EF_SvL0_Scanf, 1, M_MAKECHAR(csKey));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void CPA_PartGen_System::m_pri_fn_vFillDataList()
|
|
{
|
|
CTL_Editor_Data *p_clData = NULL;
|
|
CTL_Editor_EnumDescriptor *p_clEnumDescriptor = NULL;
|
|
|
|
//*** Nb Particles *******************************
|
|
p_clData = m_pub_clDataList.m_fn_pclAddIntegerData( sizeof(ACP_tdxIndex), TPG_UNSIGNED, "Nb Particles" );
|
|
p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stSystem->xNbParticles) );
|
|
|
|
//*** Objects Type **************************
|
|
p_clEnumDescriptor = m_pub_fn_p_clGetDocument()->m_pub_fn_p_clGetEnumDescriptorByName( "System_ObjectsType" );
|
|
p_clData = m_pub_clDataList.m_fn_pclAddEnumData( p_clEnumDescriptor, "Particles Type" );
|
|
p_clData->m_fn_vSetMotorDataPtr( (void*)&(m_pri_p_stSystem->xParticlesType) );
|
|
p_clData->m_pub_fn_vSetDataChangedSpecialCallBackFunction( g_fn_vCallBackDataChangedSpecialDisplayGenerator );
|
|
p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSystem" );
|
|
p_clData->m_pub_fn_vSetDataChangedCallBackFunction( g_fn_vCallBackDataChangedSystem );
|
|
|
|
//*** Objects Game Material *****************
|
|
p_clEnumDescriptor = m_pub_fn_p_clGetDocument()->m_pub_fn_p_clGetEnumDescriptorByName( "System_ObjectsGameMaterials" );
|
|
p_clData = m_pub_clDataList.m_fn_pclAddEnumData( p_clEnumDescriptor, "Game Material" );
|
|
p_clData->m_fn_vSetMotorDataPtr( (void*)&m_pri_hGameMaterial );
|
|
p_clData->m_pub_fn_pclAddOwnerData( (void*)&(m_pri_p_stSystem->xParticlesType), "ObjectsType" );
|
|
p_clData->m_pub_fn_vSetModificationFunctionWhenWrite( g_fn_vModificationWriteSystemObjects );
|
|
//p_clData->m_pub_fn_vSetModificationFunctionWhenRead( g_fn_vModificationReadSystemGameMaterials );
|
|
p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSystem" );
|
|
p_clData->m_pub_fn_vSetDataChangedCallBackFunction( g_fn_vCallBackDataChangedSystem );
|
|
p_clData->m_pub_fn_vSetDataMustBeRead_CallBack( g_fn_bCallBackMustBeReadWrittenSystemGameMaterial );
|
|
p_clData->m_pub_fn_vSetDataMustBeWritten_CallBack( g_fn_bCallBackMustBeReadWrittenSystemGameMaterial );
|
|
|
|
//*** Objects Sprites ***********************
|
|
p_clEnumDescriptor = m_pub_fn_p_clGetDocument()->m_pub_fn_p_clGetEnumDescriptorByName( "System_Sprites" );
|
|
p_clData = m_pub_clDataList.m_fn_pclAddEnumData( p_clEnumDescriptor, "Sprites" );
|
|
p_clData->m_fn_vSetMotorDataPtr( (void*)&m_pri_hSprite );
|
|
p_clData->m_pub_fn_pclAddOwnerData( (void*)&(m_pri_p_stSystem->xParticlesType), "ObjectsType" );
|
|
p_clData->m_pub_fn_vSetModificationFunctionWhenWrite( g_fn_vModificationWriteSystemObjects );
|
|
p_clData->m_pub_fn_pclAddOwnerData( (void*)this, "EditedSystem" );
|
|
p_clData->m_pub_fn_vSetDataChangedCallBackFunction( g_fn_vCallBackDataChangedSystem );
|
|
p_clData->m_pub_fn_vSetDataMustBeRead_CallBack( g_fn_bCallBackMustBeReadWrittenSystemSprite );
|
|
p_clData->m_pub_fn_vSetDataMustBeWritten_CallBack( g_fn_bCallBackMustBeReadWrittenSystemSprite );
|
|
}
|
|
|
|
|
|
CPA_PartGen_MyDocument * CPA_PartGen_System::m_pub_fn_p_clGetDocument()
|
|
{
|
|
return g_pclInterface->m_pub_fn_p_clGetDocument();
|
|
} |