reman3/Rayman_X/cpa/public/PRF.h

545 lines
21 KiB
C

/*********************************************************************
* *
* PRF module *
* *
**********************************************************************
* *
* This module is a profiler *
* *
* Define USE_PROFILER to use it *
* *
* Author : Alexis Vaise *
* *
*********************************************************************/
#ifndef _PRF_H__
#define _PRF_H__
/* ===========================================================================================*/
#include "acp_base.h"
#include "tmr.h" /* to have access to the target-dependant internal counter*/
#include "assert.h"
/* ===========================================================================================*/
#if defined(__cplusplus)
extern "C"
{
#endif
/* ===========================================================================================*/
#if defined(USE_PROFILER) && !defined(PRESS_DEMO)
/* ===========================================================================================*/
#if defined(U64)
#define __fastcall
#endif /* U64 */
/* ======================================== Constants ========================================*/
#define PRF_C_lMaxNbFunction 50
#define PRF_C_lMaxNbVariable 30
#define PRF_C_lMaxNbIndependantVariable 50
#define PRF_C_lMaxNbFloatIndependantVariable 10
/* independant variables use... see end of file */
#define PRF_C_lNbTramesForAverage 20
/* ======================================== Structures ========================================*/
/* used for statistics on a global raster or variable*/
typedef struct PRF_stMinMaxTotalStructure
{
unsigned long ulThisFrameValue;
unsigned long ulMinValue;
unsigned long ulMaxValue;
unsigned long ulTotalValueForAverage;
unsigned long a_ulValuesHistory[PRF_C_lNbTramesForAverage];
unsigned long ulAverageValue;
} PRF_tdstMinMaxTotalStructure;
/* used to remember what happened during the frame, for function or variable*/
typedef struct PRF_stHistory
{
unsigned long ulValue;
void *p_vUserData;
} PRF_tdstHistory;
/* used when computing chronos or variables, to group what happened during the frame, for each user data*/
typedef struct PRF_stUserDataSummary
{
void *p_vUserData;
unsigned long ulValueForThisFrame;
unsigned char ucStartStopCounter;
} PRF_tdstUserDataSummary;
/* a raster complete definition*/
typedef struct PRF_stFunctionInformation
{
char *szFunctionName;
unsigned long ulHistorySize; /* size of historic array*/
unsigned long ulUserDataSize; /* max number of UserData*/
PRF_tdstHistory *p_stFrameHistory; /* history for one frame*/
PRF_tdstUserDataSummary *p_stUserDataSummary; /* result for each user data*/
unsigned long ulNbFrame;
unsigned long ulHistoryIndex; /* number of pertinent data in history array*/
int iNbUserData; /* number of pertinent data in each-user-result array (and also number of different user data)*/
PRF_tdstMinMaxTotalStructure stFunctionDuration; /* time statistics for the raster*/
PRF_tdstMinMaxTotalStructure stNbTimeCalled; /* number of time called statistics for the raster*/
int iRunning; /* number of start less number of stop*/
} PRF_tdstFunctionInformation;
typedef struct PRF_stVariableInformation
{
char *szVariableName;
unsigned long ulHistorySize; /* size of historic array*/
unsigned long ulUserDataSize; /* max number of UserData*/
PRF_tdstHistory *p_stFrameHistory; /* history for one frame*/
PRF_tdstUserDataSummary *p_stUserDataSummary; /* result for each user data*/
unsigned long ulNbFrame;
unsigned long ulHistoryIndex; /* number of pertinent data in history array*/
int iNbUserData; /* number of pertinent data in each-user-result array (and also number of different user data)*/
PRF_tdstMinMaxTotalStructure stVariableValue; /* variable statistics*/
} PRF_tdstVariableInformation;
/* ======================================== Variables ========================================*/
extern PRF_tdstFunctionInformation PRF_g_a_stFunctionInformation [PRF_C_lMaxNbFunction];
extern PRF_tdstVariableInformation PRF_g_a_stVariableInformation [PRF_C_lMaxNbVariable];
extern BOOL PRF_g_bModuleInitialized;
/* ======================================== Inline functions ========================================*/
/*-----------------------------------------------------------------------------*/
/* PRF_fn_vStartChrono*/
/* Start a chrono*/
/*-----------------------------------------------------------------------------*/
#ifdef DREAMCAST
#pragma inline(PRF_fn_vStartChrono)
#endif
INLINE
void __fastcall PRF_fn_vStartChrono (unsigned long _ulFunctionNumber, void *p_vUserData)
{
PRF_tdstFunctionInformation *p = &PRF_g_a_stFunctionInformation[_ulFunctionNumber];
if (p->ulHistoryIndex<p->ulHistorySize)
{
register PRF_tdstHistory *h = &p->p_stFrameHistory[p->ulHistoryIndex++];
h->p_vUserData = p_vUserData;
h->ulValue = (TMR_fn_ulFastGetInternalCounter() & 0xfffffffe);
p->iRunning++;
}
else
{
/* too short history*/
p->ulHistoryIndex = p->ulHistorySize + 2;
}
}
/*-----------------------------------------------------------------------------*/
/* PRF_fn_vStopChrono*/
/* Stop a chrono*/
/*-----------------------------------------------------------------------------*/
#ifdef DREAMCAST
#pragma inline(PRF_fn_vStopChrono)
#endif
INLINE
void __fastcall PRF_fn_vStopChrono (unsigned long _ulFunctionNumber, void *p_vUserData)
{
unsigned long ulTimerValue = TMR_fn_ulFastGetInternalCounter();
PRF_tdstFunctionInformation *p = &PRF_g_a_stFunctionInformation[_ulFunctionNumber];
if (p->ulHistoryIndex<p->ulHistorySize)
{
register PRF_tdstHistory *h = &p->p_stFrameHistory[p->ulHistoryIndex++];
h->p_vUserData = p_vUserData;
h->ulValue = (ulTimerValue | 0x00000001);
p->iRunning--;
}
else
{
/* too short history*/
p->ulHistoryIndex = p->ulHistorySize + 2;
}
}
/*-----------------------------------------------------------------------------*/
/* PRF_fn_vIncreaseVariable*/
/* increase the value of a variable*/
/*-----------------------------------------------------------------------------*/
#ifdef DREAMCAST
#pragma inline(PRF_fn_vIncreaseVariable)
#endif
INLINE
void __fastcall PRF_fn_vIncreaseVariable (unsigned long _ulVariableNumber, void *_p_vUserData, unsigned long _ulDelta)
{
PRF_tdstVariableInformation *p = &PRF_g_a_stVariableInformation[_ulVariableNumber];
if (p->ulHistoryIndex<p->ulHistorySize)
{
register PRF_tdstHistory *h;
if (p->ulHistoryIndex > 0)
{
h = &p->p_stFrameHistory[p->ulHistoryIndex-1];
if (h->p_vUserData == _p_vUserData)
{
h->ulValue += _ulDelta;
return;
}
h++;
}
else
h = p->p_stFrameHistory; /* p->ulHistoryIndex = 0*/
p->ulHistoryIndex++;
/* new user data...*/
h->ulValue = _ulDelta;
h->p_vUserData = _p_vUserData;
}
else
{
/* too short history*/
p->ulHistoryIndex = p->ulHistorySize + 2;
}
}
/* ======================================== Profiler control ========================================*/
/* init module*/
void PRF_fn_vInitProfileModule ();
/* DesInit module*/
void PRF_fn_vDesInitProfileModule ();
/* create a new function raster*/
void PRF_fn_vInitChrono (unsigned long _ulFunctionNumber , char * _szFunctionName,
unsigned long _ulHistorySize, unsigned long _ulMaxNumberOfUserData);
/* create a new variable raster*/
void PRF_fn_vInitVariable (unsigned long _ulVariableNumber , char * _szVariableName,
unsigned long _ulHistorySize, unsigned long _ulMaxNumberOfUserData);
/* ReInit a function raster*/
void PRF_fn_vReInitChrono (PRF_tdstFunctionInformation *_pFunction);
/* ReInit a variable raster*/
void PRF_fn_vReInitVariable (PRF_tdstVariableInformation *_pVariable);
void PRF_fn_vReinitAllChrono (void); /* Must be called when reinitializing the map*/
void PRF_fn_vComputeChrono (unsigned long _ulFunctionNumber);
void PRF_fn_vComputeVariable (unsigned long _ulVariableNumber);
void PRF_fn_vComputeAllChrono (void); /* Must be called each trame before writing the result*/
void PRF_fn_vResetChrono (unsigned long _ulFunctionNumber);
void PRF_fn_vResetVariable (unsigned long _ulVariableNumber);
void PRF_fn_vResetAllChrono (void); /* Must be called each trame after writing the result*/
unsigned long PRF_fn_ulTimerCount2Duration(unsigned long ulDuration);
/* ======================================== Functions result ========================================*/
/* get function raster name*/
char *PRF_fn_p_cGetFunctionName(unsigned long _ulFunctionNumber);
/* get function result with user data*/
unsigned long PRF_fn_ulGetFunctionDurationWithData(unsigned long _ulFunctionNumber, void *p_vUserData);
/* get function global result*/
unsigned long PRF_fn_ulGetFunctionDuration(unsigned long _ulFunctionNumber);
unsigned long PRF_fn_ulGetFunctionAverageDuration(unsigned long _ulFunctionNumber);
unsigned long PRF_fn_ulGetFunctionMaxDuration(unsigned long _ulFunctionNumber);
unsigned long PRF_fn_ulGetFunctionMinDuration(unsigned long _ulFunctionNumber);
int PRF_fn_iGetFunctionNbStartAndStop (unsigned long _ulFunctionNumber);
unsigned long PRF_fn_ulGetFunctionStartOrStop (unsigned long _ulFunctionNumber , unsigned long _ulStartStopNumber ,
void * * _p_p_vData , BOOL * _p_bThisIsAStart);
/* get number of diferent user data*/
int PRF_fn_iGetNumberOfUserDataForFunction(unsigned long _ulFunctionNumber);
/* get function result with index*/
unsigned long PRF_fn_ulGetFunctionDurationWithIndex(unsigned long _ulFunctionNumber, void **_p_p_vUserData, int _iIndex);
/* get the current number of start less number of stop*/
int PRF_fn_iGetFunctionNumberOfStart(unsigned long _ulFunctionNumber, void **_p_p_vUserData);
/* ======================================== Variables result========================================*/
/* get variable raster name*/
char *PRF_fn_p_cGetVariableName(unsigned long _ulVariableNumber);
/* get GetVariable result with user data*/
unsigned long PRF_fn_ulGetVariableValueWithData(unsigned long _ulVariableNumber, void *p_vUserData);
/* get GetVariable global result*/
unsigned long PRF_fn_ulGetVariableValue(unsigned long _ulVariableNumber);
unsigned long PRF_fn_ulGetVariableAverageValue(unsigned long _ulVariableNumber);
unsigned long PRF_fn_ulGetVariableMaxValue(unsigned long _ulVariableNumber);
unsigned long PRF_fn_ulGetVariableMinValue(unsigned long _ulVariableNumber);
/* get number of diferent user data*/
int PRF_fn_iGetNumberOfUserDataForVariable(unsigned long _ulVariableNumber);
/* get Variable result with index*/
unsigned long PRF_fn_ulGetVariableValueWithIndex(unsigned long _ulFunctionNumber, void **_p_p_vUserData, int _iIndex);
/* ======================================== independant long Variable result========================================*/
void PRF_fn_vSetIndependantVariableName(unsigned long i, char *_szName);
long PRF_fn_lGetIndependantVariable(unsigned long i);
void PRF_fn_vSetIndependantVariable(unsigned long i, long lValue);
long PRF_fn_lIncIndependantVariable(unsigned long i, long lValue);
char *PRF_fn_szGetIndependantVariableName(unsigned long i);
/* ======================================== independant float Variable result========================================*/
void PRF_fn_vSetFloatIndependantVariableName(unsigned long i, char *_szName);
float PRF_fn_fGetFloatIndependantVariable(unsigned long i);
void PRF_fn_vSetFloatIndependantVariable(unsigned long i, float fValue);
float PRF_fn_fIncFloatIndependantVariable(unsigned long i, float fValue);
char *PRF_fn_szGetFloatIndependantVariableName(unsigned long i);
/* ======================================== Misc ============================================*/
unsigned long PRF_fn_ulGetCPUFrequency(void);
void PRF_fn_vUpdateMonitorFrequency( unsigned long _ulFrequency );
/* ======================================== Constants ========================================*/
/* ======================================== Constants ========================================*/
/* ======================================== Constants ========================================*/
/* Misc for Idp*/
#define PRF_C_ulDynamic 0 /* for Idp 1*/
#define PRF_C_ulStatic 1 /* for Idp 1*/
#define PRF_C_ulFix 2 /* for Idp 1*/
#define PRF_C_ulShadow 3 /* for Idp 1*/
/* Functions*/
#define PRF_C_ulFctMainLoop 0
#define PRF_C_ulFctDisplay 1
#define PRF_C_ulFctAI 2
#define PRF_C_ulFctCollisions 3
#define PRF_C_ulFctCollisionsChar 4
#define PRF_C_ulFctDNM 5
#define PRF_C_ulFctAnimPlayer 6
#define PRF_C_ulFctInput 7
#define PRF_C_ulFctEditor 8
#define PRF_C_ulFctSoundInit 9
#define PRF_C_ulFctSound 9
#define PRF_C_ulFctFlip 10
#define PRF_C_ulFctMainMisc 11
#define PRF_C_ulFctIADNMPLAMisc 12
#define PRF_C_ulFctHIE 13 /* COL+IA+DNM+Player+Misc => ~ 2 + 3 + 4 + 5 + 6 + 11*/
#define PRF_C_ulWaitFor3dFx 14
#define PRF_C_ulFctDisplaySpecific 15
#define PRF_C_ulFctDisplayCommon 16
#define PRF_C_ulFctDisplaySprite 17
/* sub function fot Display specific*/
#define PRF_C_ulGLI1 18
#define PRF_C_ulGLI2 19
#define PRF_C_ulGLI3 20
#define PRF_C_ulGLI4 21
#define PRF_C_ulGLI5 22
#define PRF_C_ulGLI6 23
#define PRF_C_ulGLI7 24
#define PRF_C_ulGLI8 25
/* Data for functions*/
#define M_DATA_FOR_FUNCTIONS(a,b) ((void*)((a+1)*256+(b)))
#define PRF_C_pvDisplayRDP M_DATA_FOR_FUNCTIONS(PRF_C_ulFctDisplay,0)
#define PRF_C_pvDisplayRSP M_DATA_FOR_FUNCTIONS(PRF_C_ulFctDisplay,1)
#define PRF_C_pvDisplaySynchroWait M_DATA_FOR_FUNCTIONS(PRF_C_ulFctDisplay,2)
#define PRF_C_pvDisplayGfxBuild M_DATA_FOR_FUNCTIONS(PRF_C_ulFctDisplay,3)
#define PRF_C_pvDisplaySendSector M_DATA_FOR_FUNCTIONS(PRF_C_ulFctDisplay,4)
#define PRF_C_pvDisplaySendObject M_DATA_FOR_FUNCTIONS(PRF_C_ulFctDisplay,5)
#define PRF_C_pvDisplayDisplayFix M_DATA_FOR_FUNCTIONS(PRF_C_ulFctDisplay,6)
#define PRF_C_pvDisplayRaster M_DATA_FOR_FUNCTIONS(PRF_C_ulFctDisplay,7)
#define PRF_C_pvDisplayClearVP M_DATA_FOR_FUNCTIONS(PRF_C_ulFctDisplay,8)
#define PRF_C_pvDisplaySendToList M_DATA_FOR_FUNCTIONS(PRF_C_ulFctDisplay,9)
#define PRF_C_pvSoundInit M_DATA_FOR_FUNCTIONS(PRF_C_ulFctSound,0)
#define PRF_C_pvSoundRSP M_DATA_FOR_FUNCTIONS(PRF_C_ulFctSound,1)
#define PRF_C_pvSoundPrepareAudio M_DATA_FOR_FUNCTIONS(PRF_C_ulFctSound,2)
#define PRF_C_pvEditorPRFComput M_DATA_FOR_FUNCTIONS(PRF_C_ulFctDisplay,0)
#define PRF_C_pvMisc ((void*)0) /* variable 1 : Misc*/
#define PRF_C_pvGetDevice ((void*)1) /* variable 1 : Wait for 3Dfx*/
#define PRF_C_pvSendToViewPort ((void*)2) /* variable 1 : Clipping*/
#define PRF_C_pvSendFix ((void*)3) /* variable 1 : Projection*/
#define PRF_C_pvSendSector ((void*)4) /* variable 1 : Lights*/
#define PRF_C_pvSendActor ((void*)5) /* variable 1 : Shadow*/
#define PRF_C_pvSendToList ((void*)6) /* variable 1 : SendToList*/
#define PRF_C_pvRest ((void*)9) /* variable 1 : Vignette*/
#define PRF_C_pvLight ((void*)10)
#define PRF_C_pvStack ((void*)11)
#define PRF_C_pvShadow ((void*)12)
/* Variables*/
#define PRF_C_ulVarCurrentSector 1 /* h_SO current sector*/
#define PRF_C_ulVarObjects 2 /* Objects*/
#define PRF_C_ulVarDynObjects (PRF_C_ulVarObjects + PRF_C_ulDynamic) /* 2 : number of dynamic objects visible/computed/displayed*/
#define PRF_C_ulVarStaObjects (PRF_C_ulVarObjects + PRF_C_ulStatic) /* 3 : number of static objects visible/computed/displayed*/
#define PRF_C_ulVarFixObjects (PRF_C_ulVarObjects + PRF_C_ulFix) /* 4 : number of Fix objects visible/computed/displayed*/
#define PRF_C_ulVarShwObjects (PRF_C_ulVarObjects + PRF_C_ulShadow) /* 5 : number of Shadow objects visible/computed/displayed*/
#define PRF_C_ulVarFaces 6 /* Faces*/
#define PRF_C_ulVarDynFaces (PRF_C_ulVarFaces + PRF_C_ulDynamic) /* 7 : number of dynamic faces visible/computed/displayed*/
#define PRF_C_ulVarStaFaces (PRF_C_ulVarFaces + PRF_C_ulStatic) /* 8 : number of static faces visible/computed/displayed*/
#define PRF_C_ulVarFixFaces (PRF_C_ulVarFaces + PRF_C_ulFix) /* 9 : number of Fix faces visible/computed/displayed*/
#define PRF_C_ulVarShwFaces (PRF_C_ulVarFaces + PRF_C_ulShadow) /* 10 : number of Shadow faces visible/computed/displayed*/
#define PRF_C_ulVarSectors 11
#define PRF_C_ulVarStaColl 12
#define PRF_C_ulVarDynColl 13
#define PRF_C_ulVarElements 14
#define PRF_C_ulVarDynElements (PRF_C_ulVarElements + PRF_C_ulDynamic) /* 15 : number of dynamic objects visible/computed/displayed*/
#define PRF_C_ulVarStaElements (PRF_C_ulVarElements + PRF_C_ulStatic) /* 16 : number of static objects visible/computed/displayed*/
#define PRF_C_ulVarFixElements (PRF_C_ulVarElements + PRF_C_ulFix) /* 17 : number of Fix objects visible/computed/displayed*/
#define PRF_C_ulVarShwElements (PRF_C_ulVarElements + PRF_C_ulShadow) /* 17 : number of Shadow objects visible/computed/displayed*/
#define PRF_C_ulVarGLI1 19
#define PRF_C_ulVarGLI2 20
#define PRF_C_ulVarGLI3 21
#define PRF_C_ulVarGLI4 22
#define PRF_C_ulVarGLI5 23
#define PRF_C_ulVarGLI6 24
#define PRF_C_ulVarGLI7 25
#define PRF_C_ulVarGLI8 26
/* Data for variables*/
#define PRF_C_pvVisible ((void*)2) /* variables 2/3/4/5*/
#define PRF_C_pvComputed ((void*)4) /* variables 2/3/4/5*/
#define PRF_C_pvDisplayed ((void*)5) /* variables 1/2/3/4/5*/
#define PRF_C_pvMainCharCurrentSector ((void*)0)
#define PRF_C_pvCameraCurrentSector ((void*)1)
/* Independant Variables*/
#define PRF_C_ulIdpCurrentPage 0
#define PRF_C_ulIdpDynOrSta 1 /* 0 : Dyn , 2 : Sta*/
#define PRF_C_ulIdpAdvancedPage 2
#define PRF_C_ulIdpDisplayedFaces 3 /* flag*/
#define PRF_C_ulIdpDisplayedObjects 4 /* flag*/
#define PRF_C_ulIdpRasterTime 5
#define PRF_C_ulIdpRasterDisplayMode 6
#define PRF_C_ulIdpDisplayedElements 7
#define PRF_C_ulIdpCollComputed 8
#define PRF_C_ulIdpDisplayedTriangle 9
#define PRF_C_ulIdpNbSkippedAnims 10
#define PRF_C_ulIdpNbAllocSPO 11
#define PRF_C_ulIdpNbMaxAllocSPO 12
#define PRF_C_ulIdpNbAllocCHA 13
#define PRF_C_ulIdpNbMaxAllocCHA 14
#define PRF_C_ulIdpGfxList 15
#define PRF_C_ulIdpMaxGfxList 16
#define PRF_C_ulIdpAllowedGfxList 17
#define PRF_C_ulIdpGfxList2 18
#define PRF_C_ulIdpMaxGfxList2 19
#define PRF_C_ulIdpAllowedGfxList2 20
#define PRF_C_ulIdpMtxList 21
#define PRF_C_ulIdpMaxMtxList 22
#define PRF_C_ulIdpAllowedMtxList 23
#define PRF_C_ulIdpLightList 24
#define PRF_C_ulIdpMaxLightList 25
#define PRF_C_ulIdpAllowedLightList 26
#define PRF_C_ulIdpMaxMainStackSize 27
#define PRF_C_ulIdpAllowedMainStackSize 28
#define PRF_C_ulIdpVirtualKey 29
#define PRF_C_ulIdpMaxNbCollisions 30
#define PRF_C_ulIdpAllowedNbCollisions 31
#define PRF_C_ulIdpAAMode 32
#define PRF_C_ulIdpDeltaTime 40
#define PRF_C_ulIdpMonitorFrequency 41
#define PRF_C_ulIdpTextureSize 42
#define PRF_C_ulIdpTextureMemorySize 43
#define PRF_C_ulU64Mode 0x0001
#define PRF_C_ulShowCurrent 0x0002
#define PRF_C_ulShowAverage 0x0004
#define PRF_C_ulShowMaximum 0x0008
#define PRF_C_ulFinalMode 0x0010
#define PRF_C_ulVariableMode 0x0020
#define PRF_C_ulShowStatic 0x0040
#define PRF_C_ulShowDynamic 0x0080
#define PRF_C_ulShowAll (PRF_C_ulShowStatic|PRF_C_ulShowDynamic)
#define PRF_C_ulShowPGMMode 0x0100
#define PRF_C_ulSuperImposed 0x0200
#define PRF_C_ulClearScreen 0x0400
#define PRF_C_ulChangeActor 0x0800
/* ================================================================================*/
#else /* #ifdef USE_PROFILER */
/* ===========================================================================================*/
#define PRF_fn_vStartChrono(Chrono,Data)
#define PRF_fn_vStopChrono(Chrono,Data)
#define PRF_fn_vIncreaseVariable(Var,Data,Inc)
#define PRF_fn_vSetIndependantVariable(Var,Inc)
#define PRF_fn_lGetIndependantVariable(Var) 0
#define PRF_fn_lIncIndependantVariable(Var,Inc)
#define PRF_fn_vReinitAllChrono()
#define PRF_fn_vDesInitProfileModule()
#define PRF_fn_vUpdateMonitorFrequency( _ulFrequency )
/* ===========================================================================================*/
#endif /* #ifdef USE_PROFILER*/
/* ===========================================================================================*/
#if defined(__cplusplus)
}
#endif
/* ===========================================================================================*/
#endif /* #ifndef _PRF_H__*/