reman3/Rayman_X/cpa/tempgrp/ISI/Specif/ISI_Func.cxx

463 lines
17 KiB
C++

/* ISI_Func.c*/
/* ##-###########################
## Saving / Loading
############################## */
/* ##F===================================================================================
NAME : ISI_fn_pGetLinkTable
DESCRIPTION : Function to get the link table.
OUTPUT : Link table.
=========================================================================================
LAST MODIFICATIONS : 20/11/97 David Fournier : New commentary form.
=======================================================================================*/
SCR_tdst_Link_Table *ISI_fn_pGetLinkTable(void)
{
return &ISI_stLinkTable;
}
/* ##F===================================================================================
NAME : ISI_fn_vDisinitLinkTable
DESCRIPTION : Function to disinit the link table.
=========================================================================================
LAST MODIFICATIONS : 20/11/97 David Fournier : New commentary form.
=======================================================================================*/
void ISI_fn_vDisinitLinkTable(void)
{
SCR_fn_v_Link_CloseTable(&ISI_stLinkTable);
}
/* ##F===================================================================================
NAME : ISI_fn_xLoadISI
DESCRIPTION : Load the ISI of an IPO. (Script callback)
INPUT : p_fFile = script file description.
szAction = action name.
szParams = table of param.
cType = type of action.
OUTPUT : script error code.
=========================================================================================
LAST MODIFICATIONS : 20/11/97 David Fournier : New commentary form.
=======================================================================================*/
SCR_tde_Anl_ReturnValue ISI_fn_xLoadISI(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
ACP_tdxHandleToRadiosity hISI;
ACP_tdxIndex xIndex;
char a255_cTempName[255];
static ISI_tdstColor *d_stVertexRLI;
switch (cType)
{
case SCR_EA_Anl_BeginSection:
if (SCR_fn_uc_RdL0_GetNumberOfParameters(szParams)==2)
{
/*New ISI*/
hISI=ISI_fn_hCreateISI((ACP_tdxIndex)(atol(szParams[1])));
}
else
{
hISI=ISI_fn_hCreateISI(1);
d_stVertexRLI=ISI_fn_hCreateISILOD(hISI,0,(ACP_tdxIndex)atol(szParams[0]));
}
SCR_M_RdL0_SetSectionLong(0,0,(long)hISI);
SCR_M_RdL0_SetContextLong(0,0,(long)hISI);
/*Get Path*/
strcpy(a255_cTempName,fn_szGetLevelsDataPath());
strcat(a255_cTempName,"\\");
strcat(a255_cTempName,SCR_M_RdL0_GetCompleteSectionNameR(0));
SCR_fnp_st_Link_SetValue(
&ISI_stLinkTable,
a255_cTempName,
(unsigned long)hISI
);
break;
case SCR_EA_Anl_Entry:
SCR_M_RdL0_GetContextLong(0,0,void *, hISI);
/* New LOD*/
if (strcmp(szAction,"AddLODRLI")==0)
{
d_stVertexRLI=ISI_fn_hCreateISILOD(hISI,(ACP_tdxIndex)atoi(szParams[0]),(ACP_tdxIndex)atoi(szParams[1]));
}
/* Loading of object's vertex*/
if (strcmp(szAction,"AddVertexRLILOD")==0)
{
xIndex = (ACP_tdxIndex)atoi(szParams[0]);
d_stVertexRLI[xIndex].xRed=(ISI_tdxColorComp)(atoi(szParams[1]));
d_stVertexRLI[xIndex].xGreen=(ISI_tdxColorComp)(atoi(szParams[2]));
d_stVertexRLI[xIndex].xBlue=(ISI_tdxColorComp)(atoi(szParams[3]));
if(SCR_fn_uc_RdL0_GetNumberOfParameters(szParams) == 5)
d_stVertexRLI[xIndex].xAlpha=(ISI_tdxColorComp)(atoi(szParams[4]));
}
/* Loading of object's vertex*/
if (strcmp(szAction,"AddVertexRLI")==0)
{
xIndex = (ACP_tdxIndex)atoi(szParams[0]);
d_stVertexRLI[xIndex].xRed=(ISI_tdxColorComp)(atof(szParams[1]) * 255.f);
d_stVertexRLI[xIndex].xGreen=(ISI_tdxColorComp)(atof(szParams[2]) * 255.f);
d_stVertexRLI[xIndex].xBlue=(ISI_tdxColorComp)(atof(szParams[3]) * 255.f);
if(SCR_fn_uc_RdL0_GetNumberOfParameters(szParams) == 5)
d_stVertexRLI[xIndex].xAlpha=(ISI_tdxColorComp)(atof(szParams[4]) * 255.f);
}
case SCR_EA_Anl_EndSection:
break;
}
return SCR_ERV_Anl_NormalReturn;
}
/* ##F===================================================================================
NAME : ISI_vSaveVertexISI
DESCRIPTION : Save an ISI of an IPO. (Script callback)
INPUT : _p_stFile = script file description.
_sFileName = file name.
_p_vPtr = struct adress.
_xAction = type of action
=========================================================================================
LAST MODIFICATIONS : 20/11/97 David Fournier : New commentary form.
=======================================================================================*/
void ISI_vSaveVertexISI(SCR_tdst_File_Description *_p_stFile, char *_sFileName, void *_p_vPtr, SCR_tde_Ntfy_Action _xAction)
{
ACP_tdxIndex xI,xNumISILOD,xNbVertexRLI;
ISI_HandleToISI hCpyISI;
char sFile[255];
char sSection[255];
char sIdent[255];
char sBeginSection[255];
ISI_tdstColor *d_stVertexRLI;
hCpyISI=(ISI_HandleToISI)_p_vPtr;
if(_xAction == SCR_EA_Ntfy_AddSection)
{
SCR_fn_v_SvL1_ToEndSection(_p_stFile);
}
else
{
SCR_fn_v_SvL1_DeleteSection(_p_stFile);
}
SCR_fn_v_RdL0_SplitSectionName(_sFileName, sFile, sSection, sIdent);
sprintf(sBeginSection,"%s:%s", sSection, sIdent);
/*BeginSection*/
SCR_M_SvL0_SaveBeginSection(_p_stFile, sBeginSection, SCR_CC_C_Cfg_NoChar);
SCR_fn_v_SvL0_SaveParameters_MP(_p_stFile, SCR_EF_SvL0_Scanf, 2,"%s,%d", "NBRLOD",hCpyISI->xNbISILOD);
/* For all LOD.*/
for(xNumISILOD=0;xNumISILOD<hCpyISI->xNbISILOD;xNumISILOD++)
{
xNbVertexRLI=hCpyISI->d_stISILOD[xNumISILOD].xNbVertexRLI;
d_stVertexRLI=hCpyISI->d_stISILOD[xNumISILOD].d_stVertexRLI;
SCR_M_SvL0_SaveEntry(_p_stFile, "AddLODRLI", SCR_CC_C_Cfg_NoChar);
SCR_fn_v_SvL0_SaveParameters_MP(_p_stFile,SCR_EF_SvL0_Scanf,3,"%d,%d",xNumISILOD,xNbVertexRLI);
/* For all RLI of the LOD.*/
for(xI=0;xI<xNbVertexRLI;xI++)
{
SCR_M_SvL0_SaveEntry(_p_stFile, "AddVertexRLILOD", SCR_CC_C_Cfg_NoChar);
SCR_fn_v_SvL0_SaveParameters_MP(_p_stFile,SCR_EF_SvL0_Scanf,6,"%d,%d,%d,%d,%d",
xI,(int)d_stVertexRLI[xI].xRed,(int)d_stVertexRLI[xI].xGreen,(int)d_stVertexRLI[xI].xBlue,(int)d_stVertexRLI[xI].xAlpha);
}
}
/*Endsection*/
SCR_M_SvL0_SaveEndSection(_p_stFile, SCR_CC_C_Cfg_EOL);
}
/* ##F===================================================================================
NAME : ISI_vSaveISIFromIPO
DESCRIPTION : Save all ISI for one IPO.
INPUT : _hIPO = IPO handle to save.
=========================================================================================
LAST MODIFICATIONS : 20/11/97 David Fournier : New commentary form.
=======================================================================================*/
void ISI_vSaveISIFromIPO(IPO_tdxHandleToInstanciatedPhysicalObject _hIPO)
{
ACP_tdxHandleToRadiosity hISI;
SCR_tdst_Link_Value *p_stSCRResearch;
char sFile[255];
char *p_cReplace;
hISI=IPO_fn_hGetRadiosity(_hIPO);
if(hISI)
{
p_stSCRResearch=SCR_fnp_st_Link_SearchValue(&ISI_stLinkTable,(unsigned long)hISI);
if(p_stSCRResearch)
{
strcpy(sFile,SCR_M_p_sz_Link_GetKey(p_stSCRResearch));
}
else
{
p_stSCRResearch=SCR_fnp_st_Link_SearchValue(&IPO_g_stLinkTable,(unsigned long)_hIPO);
if(p_stSCRResearch)
{
strcpy(sFile,SCR_M_p_sz_Link_GetKey(p_stSCRResearch));
p_cReplace=strstr(sFile,"ipo");
if(p_cReplace)
{
*p_cReplace='r';
p_cReplace++;
*p_cReplace='l';
p_cReplace++;
*p_cReplace='i';
}
p_cReplace=strstr(sFile,"^IPO");
if(p_cReplace) {
char * p_cSubSection;
p_cSubSection = strstr(sFile,":IPO");
if (p_cSubSection)
sprintf(p_cReplace,"^ISI:ISI%s",p_cSubSection+4);
}
/*while((p_cReplace=strstr(sFile,"IPO"))!=NULL)
{
*p_cReplace='I';
p_cReplace++;
*p_cReplace='S';
p_cReplace++;
*p_cReplace='I';
}*/
}
else
{
sprintf(sFile,"Default.rli^ISI:ISI");
}
}
SCR_fn_v_SvL1_RegisterNotify(sFile, ISI_vSaveVertexISI, (void *)hISI, SCR_EA_Ntfy_AddOrModifySection);
/* del by jt 9/6/97*/
/* SCR_fn_v_SvL1_UpdateAllNotify();*/
/* end jt 9/6/97*/
}
}
/* ##F===================================================================================
NAME : ISI_fn_vSaveISIFromIPOFromHierarchie
DESCRIPTION : Save all ISI for all IPO which are child of a super object,
or which is the super object.
INPUT : _hSuperObject = super object handle to save.
=========================================================================================
LAST MODIFICATIONS : 20/11/97 David Fournier : New commentary form.
=======================================================================================*/
void ISI_fn_vSaveISIFromIPOFromHierarchie(HIE_tdxHandleToSuperObject _hSuperObject)
{
HIE_tdxHandleToSuperObject hchildSO;
ACP_tdxIndex xI;
HIE_M_ForEachChildOf(_hSuperObject,hchildSO,xI)
{
ISI_fn_vSaveISIFromIPOFromHierarchie(hchildSO);
}
if( HIE_fn_ulGetSuperObjectType(_hSuperObject) & (HIE_C_ulIPO | HIE_C_ulIPO_Mirror ))
{
ISI_vSaveISIFromIPO((IPO_tdxHandleToInstanciatedPhysicalObject)HIE_fn_hGetSuperObjectObject(_hSuperObject));
}
}
/* Private allocation function */
/*
char* ISI_fn_p_cGenericAllocateFunction(unsigned long _ulSize)
{
char* p_cBuffer;
GEO_M_CPAMalloc (p_cBuffer,char*,_ulSize,E_uwGEONotEnoughtMemory);
return p_cBuffer;
}
*/
/* ##F===================================================================================
NAME : ISI_fn_vPrepareSaveBinaryBloc
DESCRIPTION : function to prepare the binary save process.
=========================================================================================
LAST MODIFICATIONS : 20/11/97 David Fournier : New commentary form.
=======================================================================================*/
/*
void ISI_fn_vPrepareSaveBinaryBloc()
{
BIN_fn_vCreateBinaryIds(&ISI_stLinkTable,BIN_C_ISIID);
}
*/
/* ##F===================================================================================
NAME : ISI_fn_ulWriteBinaryBloc
DESCRIPTION : Write a binary bloc for a ISI
INPUT : _ulStructAddress = Address of the element.
_p_cDestBuffer = Pointer to the buffer.
OUTPUT : length of the data written.
=========================================================================================
LAST MODIFICATIONS : 20/11/97 David Fournier : New commentary form.
=======================================================================================*/
/*
unsigned long ISI_fn_ulWriteBinaryBloc(unsigned long _ulStructAddress, char* _p_cDestBuffer)
{
ISI_HandleToISI hISI=(ISI_HandleToISI)_ulStructAddress;
ISI_tdstColor *d_stVertexRLI;
ACP_tdxIndex xNumISILOD,xNbVertexRLI;
char* p_cBufferPointer=_p_cDestBuffer;
p_cBufferPointer=BIN_fn_p_cPutStruct(p_cBufferPointer,(char*)hISI,sizeof(hISI));
p_cBufferPointer=BIN_fn_p_cPutStruct(p_cBufferPointer,(char*)hISI->d_stISILOD,sizeof(ISI_tdstISILOD)*hISI->xNbISILOD);
// For all LOD.
for(xNumISILOD=0;xNumISILOD<hISI->xNbISILOD;xNumISILOD++)
{
xNbVertexRLI=hISI->d_stISILOD[xNumISILOD].xNbVertexRLI;
d_stVertexRLI=hISI->d_stISILOD[xNumISILOD].d_stVertexRLI;
p_cBufferPointer=BIN_fn_p_cPutStruct(p_cBufferPointer,(char*)d_stVertexRLI,sizeof(ISI_tdstColor)*xNbVertexRLI);
}
return p_cBufferPointer-_p_cDestBuffer;
}
*/
/* ##F===================================================================================
NAME : ISI_fn_vWriteAllISIBinaryBlocs
DESCRIPTION : Write all the binary blocs for the ISI
INPUT : _szBinaryFileName = Name of the binary file.
=========================================================================================
LAST MODIFICATIONS : 20/11/97 David Fournier : New commentary form.
=======================================================================================*/
/*
void ISI_fn_vWriteAllISIBinaryBlocs(char* _szBinaryFileName)
{
ISI_fn_vPrepareSaveBinaryBloc();
BIN_fn_vPutBinaryDataIntoFileFromLinkTable( (char*)_szBinaryFileName,
ISI_fn_pGetLinkTable(),
ISI_C_BUFFER_SIZE,
ISI_fn_ulWriteBinaryBloc);
}
*/
/* ##F===================================================================================
NAME : ISI_fn_ulReadISIBinaryBloc
DESCRIPTION : Read the binary bloc for ISI.
INPUT : _p_cLoadedBuffer = pointer to the loaded buffer.
_ulLoadedBufferSize = Size of the loaded buffer.
OUTPUT : The pointer to the allocated element.
=========================================================================================
LAST MODIFICATIONS : 20/11/97 David Fournier : New commentary form.
=======================================================================================*/
/*
void ISI_fn_ulReadISIBinaryBloc(unsigned long _ulLoadedBuffer)
{
ISI_HandleToISI hISI=(ISI_HandleToISI)_ulLoadedBuffer;
ISI_tdstColor *d_stVertexRLI;
ACP_tdxIndex xNumISILOD;
hISI->d_stISILOD=(ISI_tdstISILOD *)(hISI+1);
d_stVertexRLI=(ISI_tdstColor *)(hISI->d_stISILOD+hISI->xNbISILOD);
// For all LOD.
for(xNumISILOD=0;xNumISILOD<hISI->xNbISILOD;xNumISILOD++)
{
hISI->d_stISILOD[xNumISILOD].d_stVertexRLI=d_stVertexRLI;
d_stVertexRLI+=hISI->d_stISILOD[xNumISILOD].xNbVertexRLI;
}
}
*/
/* ##F===================================================================================
NAME : ISI_fn_vReadAllISIBinaryBlocs
DESCRIPTION : Read all the binary blocs for the ISI.
INPUT : _szBinaryFile = Name of the binary file.
=========================================================================================
LAST MODIFICATIONS : 20/11/97 David Fournier : New commentary form.
=======================================================================================*/
/*
void ISI_fn_vReadAllISIBinaryBlocs(char* _szBinaryFile)
{
BIN_fn_vReadDataFromLinkTableWithoutAllocation(ISI_fn_pGetLinkTable(),
ISI_fn_ulReadISIBinaryBloc,
ISI_C_BUFFER_SIZE,_szBinaryFile,
ISI_fn_p_cGenericAllocateFunction);
}
*/
/*ANNECY JMD 17/02/98{*/
/* ##F===================================================================================
NAME : ISI_fn_xLoadISI2
DESCRIPTION : Load the ISI of an PO. (Script callback)
INPUT : p_fFile = script file description.
szAction = action name.
szParams = table of param.
cType = type of action.
OUTPUT : script error code.
=========================================================================================
LAST MODIFICATIONS : 13/02/98 Jean-Marc Drouaud
=======================================================================================*/
SCR_tde_Anl_ReturnValue ISI_fn_xLoadISI2(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
ACP_tdxHandleToRadiosity hISI;
ACP_tdxHandleToRadiosity *d_hRLI ;
ACP_tdxIndex xIndex;
static ISI_tdstColor *d_stVertexRLI;
switch (cType)
{
case SCR_EA_Anl_BeginSection:
SCR_M_RdL0_GetContextLong(-1,0,ACP_tdxHandleToRadiosity *, d_hRLI);
if (SCR_fn_uc_RdL0_GetNumberOfParameters(szParams)==2)
{
/*New ISI*/
hISI=ISI_fn_hCreateISI((ACP_tdxIndex)atol(szParams[1]));
}
else
{
hISI=ISI_fn_hCreateISI(1);
d_stVertexRLI=ISI_fn_hCreateISILOD(hISI,0,(ACP_tdxIndex)atol(szParams[0]));
}
*(d_hRLI++) = hISI ;
SCR_M_RdL0_SetContextLong(-1,0,(long)d_hRLI);
SCR_M_RdL0_SetSectionLong(0,0,(long)hISI);
SCR_M_RdL0_SetContextLong(0,0,(long)hISI);
break;
case SCR_EA_Anl_Entry:
SCR_M_RdL0_GetContextLong(0,0,void *, hISI);
/* New LOD*/
if (strcmp(szAction,"AddLODRLI")==0)
{
d_stVertexRLI=ISI_fn_hCreateISILOD(hISI,(ACP_tdxIndex)atoi(szParams[0]),(ACP_tdxIndex)atoi(szParams[1]));
}
/* Loading of object's vertex*/
if (strcmp(szAction,"AddVertexRLILOD")==0)
{
xIndex = (ACP_tdxIndex)atoi(szParams[0]);
d_stVertexRLI[xIndex].xRed=(ISI_tdxColorComp)(atoi(szParams[1]));
d_stVertexRLI[xIndex].xGreen=(ISI_tdxColorComp)(atoi(szParams[2]));
d_stVertexRLI[xIndex].xBlue=(ISI_tdxColorComp)(atoi(szParams[3]));
if(SCR_fn_uc_RdL0_GetNumberOfParameters(szParams) == 5)
d_stVertexRLI[xIndex].xAlpha=(ISI_tdxColorComp)(atoi(szParams[4]));
}
/* Loading of object's vertex*/
if (strcmp(szAction,"AddVertexRLI")==0)
{
xIndex = (ACP_tdxIndex)atoi(szParams[0]);
d_stVertexRLI[xIndex].xRed=(ISI_tdxColorComp)(atof(szParams[1]) * 255.f);
d_stVertexRLI[xIndex].xGreen=(ISI_tdxColorComp)(atof(szParams[2]) * 255.f);
d_stVertexRLI[xIndex].xBlue=(ISI_tdxColorComp)(atof(szParams[3]) * 255.f);
if(SCR_fn_uc_RdL0_GetNumberOfParameters(szParams) == 5)
d_stVertexRLI[xIndex].xAlpha=(ISI_tdxColorComp)(atof(szParams[4]) * 255.f);
}
case SCR_EA_Anl_EndSection:
break;
}
return SCR_ERV_Anl_NormalReturn;
}