reman3/Rayman_X/cpa/tempgrp/MMG/Specif/RastMmg.c

946 lines
60 KiB
C

/****************************************************************
* *
* RastMmg.c *
* *
* Functions to have a dump of the memory used type by type *
* *
* Author : Alexis Vaisse *
* *
****************************************************************/
#if (defined(USE_PROFILER) && !defined(U64))
#ifdef WIN32
#include <windows.h>
#include <assert.h>
#include <malloc.h>
#endif
#include "MMG/CpaMmg.h"
#include "MMG/RastMmg.h"
#include "PrivMmg.h"
#undef assert
#define assert(a) if ((a) == FALSE) { _asm { int 3 } }
/* --- Definition of the structures ---*/
typedef struct stObjectMemoryInformation_
{
long lNumberOfBlock; /* Number of allocated blocks*/
long lNumberOfStructure; /* Number of structures (a structure can have one or several blocks)*/
long lRequestedMemory; /* Number of bytes for the requested memory*/
long lAllocatedMemory; /* Number of bytes for the allocated memory*/
long lFreedMemory; /* Number of bytes for the freed memory*/
void * p_vObject; /* The object that is using this block (an actor for instance)*/
} tdstObjectMemoryInformation;
typedef struct stSubTypeMemoryInformation_
{
char * szSubTypeName; /* The name of the sub-type*/
long lMemoryChannel; /* The memory channel where the memory is allocated*/
long lTotalNumberOfBlock; /* The number of allocated blocks for all the objects of this sub-type*/
long lTotalNumberOfStructure; /* The number of all allocated structures for all objects of this sub-type*/
long lTotalRequestedMemory; /* The requested memory for all the objects of this sub-type*/
long lTotalAllocatedMemory; /* The allocated memory for all the objects of this sub-type*/
long lTotalFreedMemory; /* The freed memory for all the objects of this sub-type*/
long lNumberOfObject; /* The number of objects of this sub-type*/
long lNumberOfUsedObject; /* The number of used objects of this sub-type*/
tdstObjectMemoryInformation * a_tdstObjectMemory; /* An array of all the object memory informations of this sub-type*/
} tdstSubTypeMemoryInformation;
typedef struct stTypeMemoryInformation_
{
char * szTypeName; /* The name of the type*/
long lTotalNumberOfBlock; /* The number of allocated blocks for all the sub-types of this type*/
long lTotalNumberOfStructure; /* The number of allocated structures for all the sub-types of this type*/
long lTotalRequestedMemory; /* The requested memory for all the sub-types of this type*/
long lTotalAllocatedMemory; /* The allocated memory for all the sub-types of this type*/
long lTotalFreedMemory; /* The freed memory for all the sub-types of this type*/
long lNumberOfSubType; /* The number of sub-type of this type*/
tdstSubTypeMemoryInformation * a_tdstSubTypeMemory; /* An array of all the sub-type memory information of this type*/
} tdstTypeMemoryInformation;
/* --- Definition of the variables ---*/
#define C_lDefaultType 0
#define C_lDefaultSubType 0
#define C_p_vDefaultObject ((void *) 0)
#define C_szFileNameForMemoryDump "MemoryDump.htm"
long g_lNumberOfType = 0; /* The number of type*/
tdstTypeMemoryInformation * g_a_tdstTypeMemory = NULL; /* A global variable for all the type memory information*/
long g_lType = C_lDefaultType; /* | These five variables are used*/
long g_lSubType = C_lDefaultSubType; /* | to store information about*/
void * g_p_vObject = C_p_vDefaultObject; /* | the next memory allocation*/
unsigned char g_ucForOneAllocation = TRUE; /* |*/
unsigned char g_ucFirstAllocation = TRUE; /* |*/
/****************************************/
/* MMG_fn_vInitMemoryRasterDeclaration*/
/* Must be called once at the beginning of the game*/
/****************************************/
void MMG_fn_vInitMemoryRasterDeclaration (void)
{
/*#ifdef ACTIVE_EDITOR*/
#define C_lNbActors 1024
/*#else*/
/* #define C_lNbActors 256*/
/*#endif*/
/* Initialization of the memory raster*/
MMG_fn_vInitMemoryRaster (25); /* 25types used*/
MMG_fn_vInitTypeForMemoryRaster (0 , "Not declared allocation" , 1); /* Type 0 has 1 sub-type*/
MMG_fn_vInitSubTypeForMemoryRaster (0 , 0 , "Not declared allocation" , 1); /* Sub-type 0-0 can have 1 object*/
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeScript , "Script" , 1); /* Type 1 has 1 sub-type*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeScript , MMG_C_lSubTypeScript , "Script" , 1); /* Sub-type 1-0 can have 1 object*/
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeMiniStructure , "Mini-structure" , 14); /* Type 2 has 14 sub-types*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMiniStructure , MMG_C_lSubType3dData , "MS 3dData" , C_lNbActors); /* Sub-type 2- 0 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeStdGame , "MS StdGame" , C_lNbActors); /* Sub-type 2- 1 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeDynamics , "MS Dynamics" , C_lNbActors); /* Sub-type 2- 2 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeBrain , "MS Brain" , C_lNbActors); /* Sub-type 2- 3 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeCineInfo , "MS CineInfo" , C_lNbActors); /* Sub-type 2- 4 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeCollSet , "MS CollSet" , C_lNbActors); /* Sub-type 2- 5 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeMSWay , "MS Way" , C_lNbActors); /* Sub-type 2- 6 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeLight , "MS Light" , C_lNbActors); /* Sub-type 2- 7 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeSectInfo , "MS SectInfo" , C_lNbActors); /* Sub-type 2- 8 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeMicro , "MS Micro" , C_lNbActors); /* Sub-type 2- 9 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMiniStructure , MMG_C_lSubTypePrtSrc , "MS PrtSrc" , C_lNbActors); /* Sub-type 2-10 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeMSSound , "MS Sound" , C_lNbActors); /* Sub-type 2-11 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeAnimEffect, "MS AnimEffect" , C_lNbActors); /* Sub-type 2-12 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeMagnet , "MS Magnet" , C_lNbActors); /* Sub-type 2-13 can have C_lNbActors objects*/
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeFamily , "Family" , 14); /* Type 3 has 14 sub-types*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFamily , MMG_C_lSubTypeFamily , "Family" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFamily , MMG_C_lSubTypeState , "State" , C_lNbActors); /* Sub-type 3- 0 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFamily , MMG_C_lSubTypeAnimation , "Animation" , C_lNbActors); /* Sub-type 3- 0 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFamily , MMG_C_lSubTypeTransition , "Transition" , C_lNbActors); /* Sub-type 3- 0 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFamily , MMG_C_lSubTypeProhibit , "Prohibit" , C_lNbActors); /* Sub-type 3- 0 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFamily , MMG_C_lSubTypeTBLList , "ObjectsTableList" , C_lNbActors); /* Sub-type 3- 0 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFamily , MMG_C_lSubTypeTBLElement , "ObjectTableElement" , C_lNbActors); /* Sub-type 3- 0 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFamily , MMG_C_lSubTypeTBLEvent , "ObjectTableEvent" , C_lNbActors); /* Sub-type 3- 0 can have C_lNbActors objects*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFamily , MMG_C_lSubTypeZdxListElement , "ZdxListElement" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFamily , MMG_C_lSubTypeZdxIndexListElement , "ZdxIndexListElement" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFamily , MMG_C_lSubTypeGeometricZdxListElement , "GeometricZdxListElement" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFamily , MMG_C_lSubTypeZoneSetListElement , "ZoneSetListElement" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFamily , MMG_C_lSubTypeCsaListElement , "CsaListElement" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFamily , MMG_C_lSubTypeZoneSetEncapsulation , "ZoneSetEncapsulation" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeAI , "AI" , 24); /* Type 4 has 23 sub-types*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeMind , "Mind" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeMacro , "Macro" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeNodeMacro , "NodeMacro" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeComport , "Comport" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeRule , "Rule" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeNodeInterpret , "Interpret" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeActionTableEntry , "ActionTableEntry" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeActionTable , "ActionTable" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeModel , "Model" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeScriptAI , "ScriptAI" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeIntelligence , "Intelligence" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeDsgVarInfo , "DsgVarInfo" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeDsgVar , "DsgVar" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeDsgMemBuffer , "DsgMemBuffer" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeDsgMem , "DsgMem" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeNodeString , "NodeString" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeNodeVector , "NodeVector" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeListOfArc , "ListOfArc" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeArc , "Arc" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeNameOfGraph , "NameOfGraph" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeNameOfGraphSection , "NameOfGraphSection" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeGraph , "Graph" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeGraphNode , "GraphNode" , 1); /* Sub-type 3- 0 can have 1 object*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeAI , MMG_C_lSubTypeAIDEBUG , "AIDebug" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypePosition , "Position" , 1); /* Type 4 has 23 sub-types*/
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypePosition , MMG_C_lSubTypePosition , "Position" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeSuperObject , "Super-Object" , 2);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeSuperObject , MMG_C_lSubTypeSuperObject , "Super-Object" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeSuperObject , MMG_C_lSubTypeSuperObjectTable , "Super-Object table" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeSector , "Sector" , 9);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeSector , MMG_C_lSubTypeSuperObject , "Sector" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeSector , MMG_C_lSubTypeGraphicElement , "Graphic Element" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeSector , MMG_C_lSubTypeCollisionElement , "Collision Element" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeSector , MMG_C_lSubTypeCharacterElement , "Character Element" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeSector , MMG_C_lSubTypeActiveElement , "Active Element" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeSector , MMG_C_lSubTypeSoundElement , "Sound Element" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeSector , MMG_C_lSubTypeDNMLightElement , "Dynamic Light" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeSector , MMG_C_lSubTypeStaticLightElement , "Static Light" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeSector , MMG_C_lSubTypeSoundEvent , "Sound Event" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeGeometricObject , "GEO" , 21);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypePointsNormals , "Normales points" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeIndexUsedByElement , "IndexByElement" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeMainObject , "Main Object" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeListOfElementType , "List Of ElementTypes" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeListOfElement , "List Of Element" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeListOfPoint , "List Of Points" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeListOfEdge , "List Of Edges" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeListOfEdgeMaterial , "List Of Edges Material" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypePointsMaterial , "List Of Points Material" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeParallelBox , "Parallel Box" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeRotativeSprite , "Rotative Sprite" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeBoundingSphere , "Bounding Sphere" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeElementSprite , "Element Sprite" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeElementIT , "Element Indexed triangles" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeElementFaceMap , "Element FaceMap" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeElementTMeshes , "Element TMeshes" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeElementPoint , "Element Point" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeElementLine , "Element Line" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeElementSphere , "Element Sphere" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeElementAlignedBox , "Element Aligned Box" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGeometricObject , MMG_C_lSubTypeElementCone , "Element Cone" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeSAI , "SAI" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeSAI , MMG_C_lSubTypeSAI , "SAI" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeIPT , "IPT" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeIPT , MMG_C_lSubTypeIPT , "IPT" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeFile , "File" , 5);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFile , MMG_C_lSubTypeBmpFile , "Bmp file" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFile , MMG_C_lSubTypeConcatFile , "Concat file" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFile , MMG_C_lSubTypeGfFile , "Gf file" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFile , MMG_C_lSubTypeTgaFile , "Tga file" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeFile , MMG_C_lSubTypeMiscellaneousFile , "Miscellaneous file" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeGMT , "GameMaterial" , 4);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGMT , MMG_C_lSubTypeCollideMaterial , "Collide Material" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGMT , MMG_C_lSubTypeFor3DOS , "3DOS" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGMT , MMG_C_lSubTypeForA3D , "A3D" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGMT , MMG_C_lSubTypeMain , "Main" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeMOR , "Morphing" , 2);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMOR , MMG_C_lSubTypeElement , "Element" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMOR , MMG_C_lSubTypePO , "PO" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeISI , "ISI" , 4);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeISI , MMG_C_lSubTypeLOD , "LOD" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeISI , MMG_C_lSubTypeArray , "Array" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeISI , MMG_C_lSubTypeStruct , "Struct" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeISI , MMG_C_lSubTypeBlendRLI , "BlendRLI" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeInterpol , "Interpol" , 14);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeInterpol , MMG_C_lSubTypeA3dGENERAL , "A3dGENERAL" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeInterpol , MMG_C_lSubTypeVectors , "Vectors" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeInterpol , MMG_C_lSubTypeQuaternions , "Quaternions" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeInterpol , MMG_C_lSubTypeHierarchies , "Hierarchy" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeInterpol , MMG_C_lSubTypeNTTO , "NTTO" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeInterpol , MMG_C_lSubTypeOnlyFrames , "Only Frames" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeInterpol , MMG_C_lSubTypeChannels , "Channels" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeInterpol , MMG_C_lSubTypeFrames , "Frames" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeInterpol , MMG_C_lSubTypeFramesKF , "FramesKF" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeInterpol , MMG_C_lSubTypeKeyFrames , "Key Frames" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeInterpol , MMG_C_lSubTypeEvents , "Events" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeInterpol , MMG_C_lSubTypeMorphData , "Morph Data" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeInterpol , MMG_C_lSubTypeSpeedCuttedAnim , "Cutted Anim" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeInterpol , MMG_C_lSubTypeSpeedMatrix , "Speed Matrix" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeVignette , "Vignette" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeVignette , MMG_C_lSubTypeVignette , "Vignette" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeGAM , "GAM" , 16);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypePlayer , "Player" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeCSO , "CSO" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeLipSynchro , "LipSynchro" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeSnapShot , "SnapShot" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeBinAnim , "BinAnim" ,C_lNbActors);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeListOfMaps , "List of Maps" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeMorphChannelList , "Morph Channels List" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeMorphList , "Morph List" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeAlwaysActiveChar , "Always Active char" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeFont , "Font" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeMainChar , "Main Char" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeEngineObject , "Engine Object" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeAlwaysGenerator , "Always Generator" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeAlwaysModel , "Always Model" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeObjectTypeElement , "ObjectType Element" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGAM , MMG_C_lSubTypeViewPortArray , "ViewPortArray" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeGLI , "GLI" , 12);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGLI , MMG_C_lSubTypeTexture , "Texture" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGLI , MMG_C_lSubTypeGlobal , "Global" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGLI , MMG_C_lSubTypeZBufferForLight , "ZBufferForLight" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGLI , MMG_C_lSubTypeGliLight , "Light" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGLI , MMG_C_lSubTypePolice , "Police" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGLI , MMG_C_lSubTypeZList , "ZList" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGLI , MMG_C_lSubTypeCamera , "Camera" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGLI , MMG_C_lSubTypeMaterial , "Material" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGLI , MMG_C_lSubTypeAnimatedTexture , "Animated texture" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGLI , MMG_C_lSubTypeMipMapping , "Mip-mapping" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGLI , MMG_C_lSubTypeVisualSet , "Visual set" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeGLI , MMG_C_lSubTypeRLI , "RLI" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeOctree , "Octree" , 7);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeOctree , MMG_C_lSubTypeElementBaseTable , "Element base table" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeOctree , MMG_C_lSubTypeFaceIndex , "Face index" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeOctree , MMG_C_lSubTypeTaggedPointTable , "Tagged point table" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeOctree , MMG_C_lSubTypeTaggedFaceTable , "Tagged face table" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeOctree , MMG_C_lSubTypeOctreeNode , "Octree node" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeOctree , MMG_C_lSubTypeFaceIndexList , "Face index list" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeOctree , MMG_C_lSubTypeOctreeStructure , "Octree structure" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypePO , "Physical objet" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypePO , MMG_C_lSubTypePOStructure , "PO structure" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypePCS , "Physical CollSet" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypePCS , MMG_C_lSubTypePCSStructure , "PCS structure" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeIPO , "IPO" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeIPO , MMG_C_lSubTypeIPOStructure , "IPO structure" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeMEC , "Mechanic" , 3);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMEC , MMG_C_lSubTypeMecMatCharacteristic,"MecMatCharacteristic" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMEC , MMG_C_lSubTypeMecCameraCard , "Camera Id Card" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeMEC , MMG_C_lSubTypeMecBaseCard , "Base Id Card" , 1);
MMG_fn_vInitTypeForMemoryRaster (MMG_C_lTypeRND , "RND" , 1);
MMG_fn_vInitSubTypeForMemoryRaster (MMG_C_lTypeRND , MMG_C_lSubTypeRND , "RND" , 1);
#undef C_lNbActors
}
/****************************************/
/* MMG_fn_vDesinitMemoryRasterDeclaration*/
/* Must be called once at the end of the game*/
/****************************************/
void MMG_fn_vDesinitMemoryRasterDeclaration (void)
{
int i , j;
int iNumberOfSubType;
tdstTypeMemoryInformation * p;
tdstSubTypeMemoryInformation * q;
for (i = 0 , p = g_a_tdstTypeMemory ; i < g_lNumberOfType ; i ++ , p ++)
{
iNumberOfSubType = p -> lNumberOfSubType;
for (j = 0 , q = p -> a_tdstSubTypeMemory ; j < iNumberOfSubType ; j ++ , q ++)
{
free (q -> a_tdstObjectMemory);
}
free (p -> a_tdstSubTypeMemory);
}
free (g_a_tdstTypeMemory);
}
/****************************************/
/* MMG_fn_vInitMemoryRaster*/
/* Allocate memory for the memory raster*/
/****************************************/
void MMG_fn_vInitMemoryRaster (long _lNumberOfType)
{
int i;
tdstTypeMemoryInformation * p;
/* Don't try to initialize twice*/
assert (g_a_tdstTypeMemory == NULL);
g_lNumberOfType = _lNumberOfType;
g_a_tdstTypeMemory = (tdstTypeMemoryInformation *) malloc (_lNumberOfType * sizeof (tdstTypeMemoryInformation));
for (i = 0 , p = g_a_tdstTypeMemory ; i < _lNumberOfType ; i ++ , p ++)
{
p -> szTypeName = NULL;
}
}
/****************************************/
/* MMG_fn_vInitTypeForMemoryRaster*/
/* Allocate memory for one type for the memory raster*/
/****************************************/
void MMG_fn_vInitTypeForMemoryRaster (long _lType , char * _szTypeName , long _lNumberOfSubType)
{
int i;
tdstTypeMemoryInformation * p;
tdstSubTypeMemoryInformation * q;
assert (_lType < g_lNumberOfType);
p = & g_a_tdstTypeMemory [_lType];
assert (p -> szTypeName == NULL); /* p -> szTypeName != NULL means that we are trying to initialize a type twice*/
p -> szTypeName = _szTypeName;
p -> lTotalNumberOfBlock = 0;
p -> lTotalNumberOfStructure = 0;
p -> lTotalRequestedMemory = 0;
p -> lTotalAllocatedMemory = 0;
p -> lTotalFreedMemory = 0;
p -> lNumberOfSubType = _lNumberOfSubType;
p -> a_tdstSubTypeMemory = (tdstSubTypeMemoryInformation *) malloc (_lNumberOfSubType * sizeof (tdstSubTypeMemoryInformation));
for (i = 0 , q = p -> a_tdstSubTypeMemory ; i < _lNumberOfSubType ; i ++ , q ++)
{
q -> szSubTypeName = NULL;
}
}
/****************************************/
/* MMG_fn_vInitSubTypeForMemoryRaster*/
/* Allocate memory for one sub-type for the memory raster*/
/****************************************/
void MMG_fn_vInitSubTypeForMemoryRaster (long _lType , long _lSubType , char * _szSubTypeName , long _lNumberOfObject)
{
tdstTypeMemoryInformation * p;
tdstSubTypeMemoryInformation * q;
assert (_lType < g_lNumberOfType);
p = & g_a_tdstTypeMemory [_lType];
/* The type must have been initialized*/
assert (p -> szTypeName != NULL);
/* _lSubType must not be too big*/
assert (_lSubType < p -> lNumberOfSubType);
q = & g_a_tdstTypeMemory [_lType] . a_tdstSubTypeMemory [_lSubType];
assert (q -> szSubTypeName == NULL); /* q -> szSubTypeName != NULL means that we are trying to initialize a sub-type twice*/
q -> szSubTypeName = _szSubTypeName;
q -> lTotalNumberOfBlock = 0;
q -> lTotalNumberOfStructure = 0;
q -> lTotalRequestedMemory = 0;
q -> lTotalAllocatedMemory = 0;
q -> lTotalFreedMemory = 0;
q -> lMemoryChannel = -1;
q -> lNumberOfObject = _lNumberOfObject;
q -> lNumberOfUsedObject = 0;
q -> a_tdstObjectMemory = (tdstObjectMemoryInformation *) malloc (_lNumberOfObject * sizeof (tdstObjectMemoryInformation));
}
/****************************************/
/* MMG_fn_vAddMemoryInfo*/
/* This function must be called before making a memory allocation*/
/****************************************/
void MMG_fn_vAddMemoryInfo (long _lType , long _lSubType , void * _p_vObject)
{
g_lType = _lType;
g_lSubType = _lSubType;
g_p_vObject = _p_vObject;
g_ucForOneAllocation = TRUE;
g_ucFirstAllocation = TRUE;
}
/****************************************/
/* MMG_fn_vBeginMemoryInfo*/
/* This function must be called before making several memory allocations*/
/* Then one must call the MMG_fn_vEndMemoryInfo function*/
/****************************************/
void MMG_fn_vBeginMemoryInfo (long _lType , long _lSubType , void * _p_vObject)
{
g_lType = _lType;
g_lSubType = _lSubType;
g_p_vObject = _p_vObject;
g_ucForOneAllocation = FALSE;
g_ucFirstAllocation = TRUE;
}
/****************************************/
/* MMG_fn_vEndMemoryInfo*/
/* This function must be called after calling*/
/* the MMG_fn_vBeginMemoryInfo and making memory allocations*/
/****************************************/
void MMG_fn_vEndMemoryInfo ()
{
g_lType = C_lDefaultType;
g_lSubType = C_lDefaultSubType;
g_p_vObject = C_p_vDefaultObject;
g_ucForOneAllocation = TRUE;
g_ucFirstAllocation = TRUE;
}
/****************************************/
/* MMG_fn_vPrivateRegisterMemoryAllocation*/
/* Private function to add the values in the array*/
/****************************************/
void MMG_fn_vPrivateRegisterMemoryAllocation (long _lType , long _lSubType , void * _p_vObject , long _lRequestedSize , long _lAllocatedSize , long _lChannelNumber ,
unsigned char _ucFirstAllocation)
{
tdstTypeMemoryInformation * p;
tdstSubTypeMemoryInformation * q;
tdstObjectMemoryInformation * r;
int iBegin , iEnd , iMiddle;
assert (_lType < g_lNumberOfType);
p = & g_a_tdstTypeMemory [_lType];
assert (_lSubType < p -> lNumberOfSubType);
q = & p -> a_tdstSubTypeMemory [_lSubType];
/* All the objects of the same sub-type must be allocated in the same memory channel, except for the default type*/
assert (_lChannelNumber == q -> lMemoryChannel || q -> lMemoryChannel == -1);
if (q -> lMemoryChannel == -1 && _lType != C_lDefaultType)
q -> lMemoryChannel = _lChannelNumber;
r = q -> a_tdstObjectMemory;
/* Search the object inside the list*/
iBegin = -1;
iEnd = (int) (q -> lNumberOfUsedObject);
while (iEnd > iBegin + 1)
{
iMiddle = (iBegin + iEnd) >> 1;
if (r [iMiddle] . p_vObject < _p_vObject) iBegin = iMiddle;
else iEnd = iMiddle;
}
r += iEnd; /* r points to the good object*/
if (iEnd < q -> lNumberOfUsedObject && r -> p_vObject == _p_vObject)
{
/* The object already exist in the list*/
if (_lAllocatedSize >= 0)
{
r -> lNumberOfBlock ++;
if (_ucFirstAllocation) r -> lNumberOfStructure ++;
r -> lRequestedMemory += _lRequestedSize;
r -> lAllocatedMemory += _lAllocatedSize;
}
else
{
r -> lFreedMemory -= _lAllocatedSize;
}
}
else
{
/* The object does not exist in the list*/
assert (q -> lNumberOfUsedObject < q -> lNumberOfObject);
memmove (r + 1 , r , (q -> lNumberOfUsedObject - iEnd) * sizeof (tdstObjectMemoryInformation));
r -> lNumberOfBlock = 1;
r -> lNumberOfStructure = _ucFirstAllocation ? 1 : 0;
r -> lRequestedMemory = _lRequestedSize;
r -> lAllocatedMemory = _lAllocatedSize;
r -> lFreedMemory = 0;
r -> p_vObject = _p_vObject;
q -> lNumberOfUsedObject ++;
}
}
/****************************************/
/* MMG_fn_vRegisterMemoryAllocation*/
/* This function is automatically called when making one memory allocation*/
/****************************************/
void MMG_fn_vRegisterMemoryAllocation (long _lChannelNumber , long _lRequestedSize)
{
/* Compute the allocated size*/
long lAllocatedSize;
if (Mmg_M_ucIsStaticMode (_lChannelNumber))
{
/* Static block*/
tdstBlockInfoPriv * p_stMyBlockInfo = (tdstBlockInfoPriv *) g_d_stCurrentModeInfo [_lChannelNumber] . p_vTdstBlockInfoOrTdstDynInfo;
if (p_stMyBlockInfo -> p_cFirstFree != C_FirstFreeValueForBlockWithoutFree)
{
/* Static block with free*/
lAllocatedSize = _lRequestedSize;
Mmg_M_BigBoundSize (lAllocatedSize , C_uwAllocSize);
lAllocatedSize >>= C_uwShiftAllocSize;
lAllocatedSize += C_ucMallocHeaderSize + C_ucMallocFooterSize;
lAllocatedSize <<= C_uwShiftAllocSize;
}
else
{
/* Static block without free*/
lAllocatedSize = _lRequestedSize;
#ifdef D_CheckSystemForBlockWithoutFree
{
tdstInformationHeaderOfBolckWithoutFree * p_stInfoHeaderBolck = (tdstInformationHeaderOfBolckWithoutFree *) p_stMyBlockInfo -> p_cBeginBlock;
if (p_stInfoHeaderBolck -> ucMode & C_Check_AlignementFlag)
{
Mmg_M_BigBoundSize (lAllocatedSize , p_stInfoHeaderBolck -> ucAlignment);
}
}
#endif
}
}
else
{
/* Dynamic block*/
lAllocatedSize = _lRequestedSize;
Mmg_M_BigBoundSize (lAllocatedSize , C_uwAllocSize);
lAllocatedSize >>= C_uwShiftAllocSize;
lAllocatedSize += C_ucMallocHeaderSize + C_ucMallocFooterSize;
lAllocatedSize <<= C_uwShiftAllocSize;
}
/* Add the values in the arrays*/
MMG_fn_vPrivateRegisterMemoryAllocation (g_lType , g_lSubType , g_p_vObject , _lRequestedSize , lAllocatedSize , _lChannelNumber , g_ucFirstAllocation);
if (g_ucForOneAllocation) MMG_fn_vEndMemoryInfo ();
else g_ucFirstAllocation = FALSE;
}
/****************************************/
/* MMG_fn_vRegisterMemoryFree*/
/* This function is automatically called when making one memory free*/
/****************************************/
void MMG_fn_vRegisterMemoryFree (long _lChannelNumber , void * _p_vBlock)
{
long lFreeSize;
unitAlloc * p_xBlock = (unitAlloc *) _p_vBlock;
if (_p_vBlock == NULL) return;
p_xBlock --;
lFreeSize = (* p_xBlock) * sizeof (unitAlloc);
/* Add the value in the arrays*/
MMG_fn_vPrivateRegisterMemoryAllocation (g_lType , g_lSubType , g_p_vObject , - lFreeSize , - lFreeSize , _lChannelNumber , g_ucFirstAllocation);
if (g_ucForOneAllocation) MMG_fn_vEndMemoryInfo ();
else g_ucFirstAllocation = FALSE;
}
/****************************************/
/* MMG_fn_vComputeSizeForSubType*/
/* Compute all the memory used for a sub-type*/
/****************************************/
void MMG_fn_vComputeSizeForSubType (long _lType , long _lSubType)
{
tdstSubTypeMemoryInformation * q;
tdstObjectMemoryInformation * r;
int i;
long lTotalNumberOfBlock = 0;
long lTotalNumberOfStructure = 0;
long lTotalRequestedMemory = 0;
long lTotalAllocatedMemory = 0;
long lTotalFreedMemory = 0;
q = & g_a_tdstTypeMemory [_lType] . a_tdstSubTypeMemory [_lSubType];
for (i = 0 , r = q -> a_tdstObjectMemory ; i < q -> lNumberOfUsedObject ; i ++ , r ++)
{
lTotalNumberOfBlock += r -> lNumberOfBlock;
lTotalNumberOfStructure += r -> lNumberOfStructure;
lTotalRequestedMemory += r -> lRequestedMemory;
lTotalAllocatedMemory += r -> lAllocatedMemory;
lTotalFreedMemory += r -> lFreedMemory;
}
q -> lTotalNumberOfBlock = lTotalNumberOfBlock;
q -> lTotalNumberOfStructure = lTotalNumberOfStructure;
q -> lTotalRequestedMemory = lTotalRequestedMemory;
q -> lTotalAllocatedMemory = lTotalAllocatedMemory;
q -> lTotalFreedMemory = lTotalFreedMemory;
}
/****************************************/
/* MMG_fn_vComputeSizeForType*/
/* COmpute all the memory used for a type*/
/****************************************/
void MMG_fn_vComputeSizeForType (long _lType)
{
tdstTypeMemoryInformation * p;
tdstSubTypeMemoryInformation * q;
long lSubType;
long lTotalNumberOfBlock = 0;
long lTotalNumberOfStructure = 0;
long lTotalRequestedMemory = 0;
long lTotalAllocatedMemory = 0;
long lTotalFreedMemory = 0;
p = & g_a_tdstTypeMemory [_lType];
for (lSubType = 0 , q = p -> a_tdstSubTypeMemory ; lSubType < p -> lNumberOfSubType ; lSubType ++ , q ++)
{
MMG_fn_vComputeSizeForSubType (_lType , lSubType);
lTotalNumberOfBlock += q -> lTotalNumberOfBlock;
lTotalNumberOfStructure += q -> lTotalNumberOfStructure;
lTotalRequestedMemory += q -> lTotalRequestedMemory;
lTotalAllocatedMemory += q -> lTotalAllocatedMemory;
lTotalFreedMemory += q -> lTotalFreedMemory;
}
p -> lTotalNumberOfBlock = lTotalNumberOfBlock;
p -> lTotalNumberOfStructure = lTotalNumberOfStructure;
p -> lTotalRequestedMemory = lTotalRequestedMemory;
p -> lTotalAllocatedMemory = lTotalAllocatedMemory;
p -> lTotalFreedMemory = lTotalFreedMemory;
}
/****************************************/
/* LToA*/
/* Convert a number into string with a comma to separate groups of 3 digits*/
/****************************************/
char g_szBuffer [8] [14];
char * LToA (long _lNumber)
{
static int iNumberOfBuffer = 0;
iNumberOfBuffer = (iNumberOfBuffer + 1) & 0x07;
if (_lNumber < 1000) sprintf (g_szBuffer [iNumberOfBuffer] , "%i" , _lNumber);
else
if (_lNumber < 1000000) sprintf (g_szBuffer [iNumberOfBuffer] , "%i,%03i" , _lNumber / 1000 , _lNumber % 1000);
else sprintf (g_szBuffer [iNumberOfBuffer] , "%i,%03i,%03i" , _lNumber / 1000000 , (_lNumber / 1000) % 1000 , _lNumber % 1000);
return g_szBuffer [iNumberOfBuffer];
}
#define HTML_C_szBeginningOfPage "<HTML>\n<BODY>\n"
#define HTML_C_szEndOfPage "</BODY>\n</HTML>\n"
#define HTML_C_szEndOfLine "</p>"
#define HTML_C_szBold "<b>"
#define HTML_C_szEndBold "</b>"
#define HTML_C_szItalic "<i>"
#define HTML_C_szEndItalic "</i>"
#define HTML_C_szUnderline "<u>"
#define HTML_C_szEndUnderline "</u>"
#define HTML_C_szBiggerOnce "<font size=+1>"
#define HTML_C_szBiggerTwice "<font size=+2>"
#define HTML_C_szEndBigger "</font>"
#define HTML_C_szLowerOnce "<font size=-1>"
#define HTML_C_szEndLower "</font>"
#define HTML_C_szTable "<table>"
#define HTML_C_szEndTable "</table>"
#define HTML_C_szTableLine "<TR>"
#define HTML_C_szTableLineCenter "<TR ALIGN=CENTER>"
#define HTML_C_szTableLineRight "<TR ALIGN=RIGHT>"
#define HTML_C_szEndTableLine "</TH>"
#define HTML_C_szTableColon "<TD>"
#define HTML_C_szTableColonCenter "<TD ALIGN=CENTER>"
#define HTML_C_szTableColonRight "<TD ALIGN=RIGHT>"
#define HTML_C_szEndTableColon "</TD>"
#define HTML_C_szDrawLine "<HR>"
#define HTML_C_szTab "&nbsp "
#define HTML_C_szTab2 "&nbsp;&nbsp "
#define HTML_C_szTab4 "&nbsp;&nbsp;&nbsp;&nbsp "
#define HTML_C_szTab8 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp "
#define HTML_C_szJumpToTarget "<A HREF=\"#"
#define HTML_C_szMiddleJump "\">"
#define HTML_C_szEndJump "</A>"
#define HTML_C_szTarget "<A NAME=\""
#define HTML_C_szEndTarget "\"></A>"
#define HTML_C_szBiggerOnceAndBold "<font size=+1><b>"
#define HTML_C_szBiggerTwiceAndBold "<font size=+2><b>"
#define HTML_C_szEndBiggerAndBold "</b></font>"
/****************************************/
/* MMG_fn_vDumpMemory*/
/* Save into a file the list of all the allocated memory*/
/****************************************/
void MMG_fn_vDumpMemory ()
{
tdstTypeMemoryInformation * p;
tdstSubTypeMemoryInformation * q;
long lType , lSubType;
long lMemory , lWastedMemory , lFreedMemory;
long lNumberOfBlock , lNumberOfStructure;
FILE * pFile = fopen (C_szFileNameForMemoryDump , "wt");
if (pFile == NULL)
{
assert (0);
return;
}
fprintf (pFile , "%s%s%s%s%s%s%s\n" , HTML_C_szBeginningOfPage , HTML_C_szDrawLine , HTML_C_szBiggerTwiceAndBold , "MEMORY DUMP" , HTML_C_szEndBiggerAndBold ,
HTML_C_szEndOfLine , HTML_C_szDrawLine);
fprintf (pFile , "Number of types : %s%i%s%s%s\n" , HTML_C_szBiggerOnceAndBold , g_lNumberOfType , HTML_C_szEndBiggerAndBold , HTML_C_szEndOfLine , HTML_C_szEndOfLine);
fprintf (pFile , "%s\n" , HTML_C_szTable);
for (lType = 0 , p = g_a_tdstTypeMemory ; lType < g_lNumberOfType ; lType ++ , p ++)
{
MMG_fn_vComputeSizeForType (lType);
lMemory = p -> lTotalAllocatedMemory;
lWastedMemory = lMemory - p -> lTotalRequestedMemory;
lFreedMemory = p -> lTotalFreedMemory;
lNumberOfBlock = p -> lTotalNumberOfBlock;
lNumberOfStructure = p -> lTotalNumberOfStructure;
fprintf (pFile , "%s%s%s%s%s%i%s\n" ,
HTML_C_szTableLine ,
HTML_C_szTableColon , HTML_C_szLowerOnce , "Type # " , HTML_C_szEndLower , lType , HTML_C_szEndTableColon);
fprintf (pFile , "%s%s%s%s%s%s%s%s%s\n" ,
HTML_C_szTableColon , HTML_C_szJumpToTarget , p -> szTypeName , HTML_C_szMiddleJump , HTML_C_szBiggerOnce , p -> szTypeName , HTML_C_szEndJump ,
HTML_C_szEndBigger , HTML_C_szEndTableColon);
fprintf (pFile , "%s%s%s%s%s%s\n" ,
HTML_C_szTableColonRight , HTML_C_szBiggerTwice , LToA (lMemory) , HTML_C_szEndBigger , " bytes allocated" , HTML_C_szEndTableColon);
fprintf (pFile , "%s%s%s%s%s%s%s\n" ,
HTML_C_szTableColonRight , "(" , HTML_C_szBiggerOnce , LToA (lWastedMemory) , HTML_C_szEndBigger , " bytes wasted)" , HTML_C_szEndTableColon);
fprintf (pFile , "%s%s%s%s%s%s%s\n" ,
HTML_C_szTableColonRight , "in " , HTML_C_szBiggerOnce , LToA (lNumberOfStructure) , HTML_C_szEndBigger , " structures" , HTML_C_szEndTableColon);
if (lFreedMemory > 0)
fprintf (pFile , "%s%s%s%s%s%s%s\n" ,
HTML_C_szTableColonRight , "(" , HTML_C_szBiggerTwice , LToA (lFreedMemory) , HTML_C_szEndBigger , " bytes freed)" , HTML_C_szEndTableColon);
if (lNumberOfBlock != lNumberOfStructure)
fprintf (pFile , "%s%s%s%s%s%s%s\n" ,
HTML_C_szTableColonRight , "(" , HTML_C_szBiggerOnce , LToA (lNumberOfBlock) , HTML_C_szEndBigger , " blocks)" , HTML_C_szEndTableColon);
else fprintf (pFile , "%s %s\n" , HTML_C_szTableColon , HTML_C_szEndTableColon);
fprintf (pFile , "%s\n" , HTML_C_szEndTableLine);
}
fprintf (pFile , "%s%s\n" , HTML_C_szEndTable , HTML_C_szDrawLine);
for (lType = 0 , p = g_a_tdstTypeMemory ; lType < g_lNumberOfType ; lType ++ , p ++)
{
lMemory = p -> lTotalAllocatedMemory;
lWastedMemory = lMemory - p -> lTotalRequestedMemory;
lNumberOfBlock = p -> lTotalNumberOfBlock;
lNumberOfStructure = p -> lTotalNumberOfStructure;
lFreedMemory = p -> lTotalFreedMemory;
fprintf (pFile , "%s%s%s\n" ,
HTML_C_szTarget , p -> szTypeName , HTML_C_szEndTarget);
fprintf (pFile , "%s%s%i%s%s%s%s%s%s\n" ,
HTML_C_szBiggerTwice , "Type # " , lType , " - " , HTML_C_szBold , p -> szTypeName , HTML_C_szEndBold , HTML_C_szEndBigger , HTML_C_szEndOfLine);
fprintf (pFile , "%s%s%s%s%s%s%s%s%s%s%s%s%s\n" ,
HTML_C_szTab4 , HTML_C_szBiggerTwice , LToA (lMemory) , HTML_C_szEndBigger , " bytes allocated (" , HTML_C_szBiggerOnce , LToA (lWastedMemory) ,
HTML_C_szEndBigger , " bytes wasted) in " , HTML_C_szBiggerOnce , LToA (lNumberOfStructure) , HTML_C_szEndBigger , " structures");
if (lNumberOfBlock != lNumberOfStructure)
fprintf (pFile , "%s%s%s%s%s\n" ,
" (" , HTML_C_szBiggerOnce , LToA (lNumberOfBlock) , HTML_C_szEndBigger , " blocks)");
fprintf (pFile , "%s\n" , HTML_C_szEndOfLine);
fprintf (pFile , "%s%s%s%s%s%s%s%s%s%s\n" ,
HTML_C_szTab4 , "Average size of structure : " , HTML_C_szBiggerOnce , LToA (lMemory / max (lNumberOfStructure , 1)) , HTML_C_szEndBigger ,
" bytes (" , HTML_C_szBiggerOnce , LToA (lWastedMemory / max (lNumberOfStructure , 1)) , HTML_C_szEndBigger , " bytes wasted)");
if (lFreedMemory > 0)
fprintf (pFile , "%s%s%s%s%s%s%s\n" ,
HTML_C_szTableColonRight , "(" , HTML_C_szBiggerTwice , LToA (lFreedMemory) , HTML_C_szEndBigger , " bytes freed)" , HTML_C_szEndTableColon);
if (lNumberOfBlock != lNumberOfStructure)
{
fprintf (pFile , "%s%s%i%s%s%s\n" ,
" - " , HTML_C_szBiggerOnce , lNumberOfBlock / max (lNumberOfStructure , 1) , HTML_C_szEndBigger , " blocks for one structure" , HTML_C_szEndOfLine);
fprintf (pFile , "%s%s%s%s%s%s%s%s%s%s\n" ,
HTML_C_szTab4 , "Average size of block : " , HTML_C_szBiggerOnce , LToA (lMemory / max (lNumberOfBlock , 1)) , HTML_C_szEndBigger ,
" bytes (" , HTML_C_szBiggerOnce , LToA (lWastedMemory / max (lNumberOfBlock , 1)) , HTML_C_szEndBigger , " bytes wasted)");
}
fprintf (pFile , "%s%s%s\n" , HTML_C_szEndOfLine , HTML_C_szTab4 , HTML_C_szTable);
for (lSubType = 0 , q = p -> a_tdstSubTypeMemory ; lSubType < p -> lNumberOfSubType ; lSubType ++ , q ++)
{
lMemory = q -> lTotalAllocatedMemory;
lWastedMemory = lMemory - q -> lTotalRequestedMemory;
lNumberOfBlock = q -> lTotalNumberOfBlock;
lNumberOfStructure = q -> lTotalNumberOfStructure;
lFreedMemory = q -> lTotalFreedMemory;
fprintf (pFile , "%s%s%s%s%s%i%s\n" ,
HTML_C_szTableLine ,
HTML_C_szTableColon , HTML_C_szLowerOnce , "Sub-type # " , HTML_C_szEndLower , lSubType , HTML_C_szEndTableColon);
fprintf (pFile , "%s%s%s%s%s\n" ,
HTML_C_szTableColon , HTML_C_szBiggerOnce , q -> szSubTypeName , HTML_C_szEndBigger , HTML_C_szEndTableColon);
fprintf (pFile , "%s%s%s%s%s%s\n" ,
HTML_C_szTableColonRight , HTML_C_szBiggerTwice , LToA (lMemory) , HTML_C_szEndBigger , " bytes allocated" , HTML_C_szEndTableColon);
fprintf (pFile , "%s%s%s%s%s%s%s\n" ,
HTML_C_szTableColonRight , "(" , HTML_C_szBiggerOnce , LToA (lWastedMemory) , HTML_C_szEndBigger , " bytes wasted)" , HTML_C_szEndTableColon);
fprintf (pFile , "%s%s%s%s%s%s%s\n" ,
HTML_C_szTableColonRight , "in " , HTML_C_szBiggerOnce , LToA (lNumberOfStructure) , HTML_C_szEndBigger , " structures" , HTML_C_szEndTableColon);
fprintf (pFile , "%s%s%s%s%s%s%s\n" ,
HTML_C_szTableColonRight , "(" , HTML_C_szBiggerOnce , LToA (lMemory / max (lNumberOfStructure , 1)) , HTML_C_szEndBigger , " bytes ave)" , HTML_C_szEndTableColon);
if (lFreedMemory > 0)
fprintf (pFile , "%s%s%s%s%s%s%s\n" ,
HTML_C_szTableColonRight , "(" , HTML_C_szBiggerTwice , LToA (lFreedMemory) , HTML_C_szEndBigger , " bytes freed)" , HTML_C_szEndTableColon);
if (lNumberOfBlock != lNumberOfStructure)
{
fprintf (pFile , "%s%s%s%s%s%s%s\n" ,
HTML_C_szTableColonRight , "(" , HTML_C_szBiggerOnce , LToA (lNumberOfBlock) , HTML_C_szEndBigger , " blocks)" , HTML_C_szEndTableColon);
fprintf (pFile , "%s%s%s%s%s%s%s\n" ,
HTML_C_szTableColonRight , "(" , HTML_C_szBiggerOnce , LToA (lMemory / max (lNumberOfBlock , 1)) , HTML_C_szEndBigger , " bytes ave)" , HTML_C_szEndTableColon);
}
fprintf (pFile , "%s" , HTML_C_szEndTableLine);
/*??? fprintf (pFile , " Average size of block : %s bytes (%s bytes wasted)\n" , LToA (lMemory / lNumberOfBlock) , LToA (lWastedMemory / lNumberOfBlock));*/
}
fprintf (pFile , "%s%s\n" , HTML_C_szEndTable , HTML_C_szDrawLine);
}
fprintf (pFile , HTML_C_szEndOfPage);
fclose (pFile);
}
/****************************************/
/* MMG_fn_vClearMemoryRaster*/
/* Set all counters to zero*/
/****************************************/
void MMG_fn_vClearMemoryRaster (void)
{
int i , j;
tdstTypeMemoryInformation * p;
tdstSubTypeMemoryInformation * q;
p = g_a_tdstTypeMemory;
for (i = 0 ; i < g_lNumberOfType ; i ++ , p ++)
{
p -> lTotalNumberOfBlock = 0;
p -> lTotalNumberOfStructure = 0;
p -> lTotalRequestedMemory = 0;
p -> lTotalAllocatedMemory = 0;
p -> lTotalFreedMemory = 0;
q = p -> a_tdstSubTypeMemory;
for (j = 0 ; j < p -> lNumberOfSubType ; j ++ , q ++)
{
q -> lTotalNumberOfBlock = 0;
q -> lTotalNumberOfStructure = 0;
q -> lTotalRequestedMemory = 0;
q -> lTotalAllocatedMemory = 0;
q -> lTotalFreedMemory = 0;
q -> lMemoryChannel = -1;
q -> lNumberOfUsedObject = 0;
}
}
}
#else /* #ifdef USE_PROFILER*/
void MMG_fn_vInitMemoryRasterDeclaration(void){} /* Called once when the first memory block is allocated*/
void MMG_fn_vDesinitMemoryRasterDeclaration (void){} /* Called once at the end of the program*/
void MMG_fn_vInitMemoryRaster (long _lNumberOfType){} /* Must be called once at the beginning of the game*/
void MMG_fn_vInitTypeForMemoryRaster (long _lType , char * _szTypeName , long _lNumberOfSubType){}
void MMG_fn_vInitSubTypeForMemoryRaster (long _lType , long _lSubType , char * _szSubTypeName , long _lNumberOfObject){}
void MMG_fn_vAddMemoryInfo (long _lType , long _lSubType , void * _p_vObject){} /* Must be called before making a memory allocation*/
void MMG_fn_vBeginMemoryInfo (long _lType , long _lSubType , void * _p_vObject){} /* Must be called before making several memory allocations. Then one must call the MMG_fn_vEndMemoryInfo function*/
void MMG_fn_vEndMemoryInfo (){} /* Must be called after calling the MMG_fn_vBeginMemoryInfo and making memory allocations*/
void MMG_fn_vRegisterMemoryAllocation (long _lChannelNumber , long _lRequestedSize){}/* This function is called only by the fn_p_vGenAlloc function*/
void MMG_fn_vRegisterMemoryFree (long _lChannelNumber , void * _p_vBlock){} /* This function is called only by the fn_p_vGenFree function*/
void MMG_fn_vDumpMemory (){} /* Save all memory informations into a dump file*/
void MMG_fn_vClearMemoryRaster (){}
#endif /* #ifdef USE_PROFILER*/