Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
wwmemlog.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WWDebug *
24 * *
25 * $Archive:: /Commando/Code/wwdebug/wwmemlog.h $*
26 * *
27 * Original Author:: Greg Hjelstrom *
28 * *
29 * $Author:: Jani_p $*
30 * *
31 * $Modtime:: 11/09/01 6:51p $*
32 * *
33 * $Revision:: 8 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39
40#if _MSC_VER >= 1000
41#pragma once
42#endif
43
44#ifndef WWMEMLOG_H
45#define WWMEMLOG_H
46
47#define LOG_MEMORY // Comment this out to disable memlog compiling in
48
49class MemLogClass;
50
56enum
57{
59 MEM_GEOMETRY, // memory used by geometry data
60 MEM_ANIMATION, // memory used by animation data
61 MEM_TEXTURE, // memory used by textures
62 MEM_PATHFIND, // memory used by the pathfind system
63 MEM_VIS, // memory used by the vis system
64 MEM_SOUND, // memory used by the sound system
65 MEM_CULLINGDATA, // culling systems
66 MEM_STRINGS, // string data
67 MEM_GAMEDATA, // game engine datastructures
68 MEM_PHYSICSDATA, // physics engine datastructures
69 MEM_W3DDATA, // w3d datastructures (not including ones more applicable to above categories)
70 MEM_STATICALLOCATION,// all the allocations that happen before the memlog Init() function call are from statically allocated objects
71 MEM_GAMEINIT, // game init time allocations
72 MEM_RENDERER, // dx8 renderer
75
77};
78
79
80
99{
100public:
101 static void Enable_Memory_Log(bool enable) { IsMemoryLogEnabled=enable; }
103
104 /*
105 ** Accessors to the current memory map
106 */
107 static int Get_Category_Count(void);
108 static const char * Get_Category_Name(int category);
109 static int Get_Current_Allocated_Memory(int category);
110 static int Get_Peak_Allocated_Memory(int category);
111
112 /*
113 ** Interface for the debug version of new and delete
114 */
115 static int Register_Memory_Allocated(int size);
116 static void Register_Memory_Released(int category,int size);
117
118 /*
119 ** New and Delete functions. If you want to use this logging system,
120 ** implement global new and delete functions which call into these
121 ** functions.
122 */
123 static void * Allocate_Memory(size_t size);
124 static void Release_Memory(void * mem);
125
126 static void Reset_Counters(); // Reset allocate and free counters
127 static int Get_Allocate_Count(); // Return allocate count since last reset
128 static int Get_Free_Count(); // Return allocate count since last reset
129
130 static void Init();
131protected:
132
133 /*
134 ** Interface for WWMemorySampleClass to set the active category
135 */
136 static void Push_Active_Category(int category);
137 static void Pop_Active_Category(void);
138
139 static MemLogClass * Get_Log(void);
140 static void Release_Log(void);
141
143
145};
146
147
148
156{
157 bool category_push;
158public:
159 WWMemorySampleClass(int category) : category_push(WWMemoryLogClass::Is_Memory_Log_Enabled())
160 {
161 if (category_push) {
163 }
164 }
165
167 {
168 if (category_push) {
170 }
171 }
172};
173
174
175
176/*
177** Use the WWMEMLOG macro to track all memory allocations within the current scope.
178** If WWDEBUG is not enabled, memory usage logging will be disabled.
179*/
180#ifdef USE_MEMLOG
181#define WWMEMLOG( category ) WWMemorySampleClass _memsample( category )
182#else
183#define WWMEMLOG( category )
184#endif
185
186
187
188
189
190
191#endif //WWMEMLOG_H
static int Register_Memory_Allocated(int size)
Definition wwmemlog.cpp:516
static bool IsMemoryLogEnabled
Definition wwmemlog.h:142
static int Get_Category_Count(void)
Definition wwmemlog.cpp:482
static int Get_Free_Count()
Definition wwmemlog.cpp:755
static void Release_Memory(void *mem)
Definition wwmemlog.cpp:705
static const char * Get_Category_Name(int category)
Definition wwmemlog.cpp:487
static void Release_Log(void)
Definition wwmemlog.cpp:574
static int Get_Allocate_Count()
Definition wwmemlog.cpp:749
static void Init()
Definition wwmemlog.cpp:760
static void Reset_Counters()
Definition wwmemlog.cpp:742
friend class WWMemorySampleClass
Definition wwmemlog.h:144
static void Enable_Memory_Log(bool enable)
Definition wwmemlog.h:101
static int Get_Current_Allocated_Memory(int category)
Definition wwmemlog.cpp:492
static bool Is_Memory_Log_Enabled()
Definition wwmemlog.h:102
static void Pop_Active_Category(void)
Definition wwmemlog.cpp:509
static void Push_Active_Category(int category)
Definition wwmemlog.cpp:502
static void Register_Memory_Released(int category, int size)
Definition wwmemlog.cpp:521
static int Get_Peak_Allocated_Memory(int category)
Definition wwmemlog.cpp:497
static void * Allocate_Memory(size_t size)
Definition wwmemlog.cpp:642
static MemLogClass * Get_Log(void)
Definition wwmemlog.cpp:533
WWMemorySampleClass(int category)
Definition wwmemlog.h:159
~WWMemorySampleClass(void)
Definition wwmemlog.h:166
@ MEM_GAMEDATA
Definition wwmemlog.h:67
@ MEM_STRINGS
Definition wwmemlog.h:66
@ MEM_COUNT
Definition wwmemlog.h:76
@ MEM_PATHFIND
Definition wwmemlog.h:62
@ MEM_STATICALLOCATION
Definition wwmemlog.h:70
@ MEM_TEXTURE
Definition wwmemlog.h:61
@ MEM_SOUND
Definition wwmemlog.h:64
@ MEM_W3DDATA
Definition wwmemlog.h:69
@ MEM_CULLINGDATA
Definition wwmemlog.h:65
@ MEM_PHYSICSDATA
Definition wwmemlog.h:68
@ MEM_GAMEINIT
Definition wwmemlog.h:71
@ MEM_UNKNOWN
Definition wwmemlog.h:58
@ MEM_BINK
Definition wwmemlog.h:74
@ MEM_ANIMATION
Definition wwmemlog.h:60
@ MEM_VIS
Definition wwmemlog.h:63
@ MEM_GEOMETRY
Definition wwmemlog.h:59
@ MEM_RENDERER
Definition wwmemlog.h:72
@ MEM_NETWORK
Definition wwmemlog.h:73