Skip to content

Commit c706cd3

Browse files
refactor(ww3d2): Use statistics struct for bookkeeping
1 parent 35a9a04 commit c706cd3

2 files changed

Lines changed: 22 additions & 92 deletions

File tree

GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp

Lines changed: 11 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ const int DEFAULT_BIT_DEPTH = 32;
9393
const int DEFAULT_TEXTURE_BIT_DEPTH = 16;
9494
const D3DMULTISAMPLE_TYPE DEFAULT_MSAA = D3DMULTISAMPLE_NONE;
9595

96+
DX8FrameStatistics DX8Wrapper::FrameStatistics = { 0 };
97+
static DX8FrameStatistics LastFrameStatistics = { 0 };
98+
9699
bool DX8Wrapper_IsWindowed = true;
97100

98101
// FPU_PRESERVE
@@ -155,15 +158,6 @@ IDirect3DSurface8 * DX8Wrapper::DefaultRenderTarget = nullptr;
155158
IDirect3DSurface8 * DX8Wrapper::DefaultDepthBuffer = nullptr;
156159
bool DX8Wrapper::IsRenderToTexture = false;
157160

158-
unsigned DX8Wrapper::matrix_changes = 0;
159-
unsigned DX8Wrapper::material_changes = 0;
160-
unsigned DX8Wrapper::vertex_buffer_changes = 0;
161-
unsigned DX8Wrapper::index_buffer_changes = 0;
162-
unsigned DX8Wrapper::light_changes = 0;
163-
unsigned DX8Wrapper::texture_changes = 0;
164-
unsigned DX8Wrapper::render_state_changes = 0;
165-
unsigned DX8Wrapper::texture_stage_state_changes = 0;
166-
unsigned DX8Wrapper::draw_calls = 0;
167161
unsigned DX8Wrapper::_MainThreadID = 0;
168162
bool DX8Wrapper::CurrentDX8LightEnables[4];
169163
bool DX8Wrapper::IsDeviceLost;
@@ -183,18 +177,7 @@ D3DADAPTER_IDENTIFIER8 DX8Wrapper::CurrentAdapterIdentifier;
183177
unsigned long DX8Wrapper::FrameCount = 0;
184178

185179
bool _DX8SingleThreaded = false;
186-
187180
unsigned number_of_DX8_calls = 0;
188-
static unsigned last_frame_matrix_changes = 0;
189-
static unsigned last_frame_material_changes = 0;
190-
static unsigned last_frame_vertex_buffer_changes = 0;
191-
static unsigned last_frame_index_buffer_changes = 0;
192-
static unsigned last_frame_light_changes = 0;
193-
static unsigned last_frame_texture_changes = 0;
194-
static unsigned last_frame_render_state_changes = 0;
195-
static unsigned last_frame_texture_stage_state_changes = 0;
196-
static unsigned last_frame_number_of_DX8_calls = 0;
197-
static unsigned last_frame_draw_calls = 0;
198181

199182
static D3DDISPLAYMODE DesktopMode;
200183

@@ -1676,71 +1659,26 @@ bool DX8Wrapper::Test_Z_Mode(D3DFORMAT colorbuffer,D3DFORMAT backbuffer, D3DFORM
16761659

16771660
void DX8Wrapper::Reset_Statistics()
16781661
{
1679-
matrix_changes = 0;
1680-
material_changes = 0;
1681-
vertex_buffer_changes = 0;
1682-
index_buffer_changes = 0;
1683-
light_changes = 0;
1684-
texture_changes = 0;
1685-
render_state_changes =0;
1686-
texture_stage_state_changes =0;
1687-
draw_calls =0;
1688-
1689-
number_of_DX8_calls = 0;
1690-
last_frame_matrix_changes = 0;
1691-
last_frame_material_changes = 0;
1692-
last_frame_vertex_buffer_changes = 0;
1693-
last_frame_index_buffer_changes = 0;
1694-
last_frame_light_changes = 0;
1695-
last_frame_texture_changes = 0;
1696-
last_frame_render_state_changes = 0;
1697-
last_frame_texture_stage_state_changes = 0;
1698-
last_frame_number_of_DX8_calls = 0;
1699-
last_frame_draw_calls =0;
1662+
memset(&FrameStatistics, 0, sizeof(FrameStatistics));
1663+
memset(&LastFrameStatistics, 0, sizeof(FrameStatistics));
1664+
number_of_DX8_calls=0;
17001665
}
17011666

17021667
void DX8Wrapper::Begin_Statistics()
17031668
{
1704-
matrix_changes=0;
1705-
material_changes=0;
1706-
vertex_buffer_changes=0;
1707-
index_buffer_changes=0;
1708-
light_changes=0;
1709-
texture_changes = 0;
1710-
render_state_changes =0;
1711-
texture_stage_state_changes =0;
1669+
memset(&FrameStatistics, 0, sizeof(FrameStatistics));
17121670
number_of_DX8_calls=0;
1713-
draw_calls=0;
17141671
}
17151672

17161673
void DX8Wrapper::End_Statistics()
17171674
{
1718-
last_frame_matrix_changes=matrix_changes;
1719-
last_frame_material_changes=material_changes;
1720-
last_frame_vertex_buffer_changes=vertex_buffer_changes;
1721-
last_frame_index_buffer_changes=index_buffer_changes;
1722-
last_frame_light_changes=light_changes;
1723-
last_frame_texture_changes = texture_changes;
1724-
last_frame_render_state_changes = render_state_changes;
1725-
last_frame_texture_stage_state_changes = texture_stage_state_changes;
1726-
last_frame_number_of_DX8_calls=number_of_DX8_calls;
1727-
last_frame_draw_calls=draw_calls;
1675+
LastFrameStatistics = FrameStatistics;
1676+
LastFrameStatistics.dx8_calls = number_of_DX8_calls;
17281677
}
17291678

1730-
DX8FrameStatistics DX8Wrapper::Get_Last_Frame_Statistics()
1679+
const DX8FrameStatistics& DX8Wrapper::Get_Last_Frame_Statistics()
17311680
{
1732-
DX8FrameStatistics stats;
1733-
stats.matrix_changes = last_frame_matrix_changes;
1734-
stats.material_changes = last_frame_material_changes;
1735-
stats.vertex_buffer_changes = last_frame_vertex_buffer_changes;
1736-
stats.index_buffer_changes = last_frame_index_buffer_changes;
1737-
stats.light_changes = last_frame_light_changes;
1738-
stats.texture_changes = last_frame_texture_changes;
1739-
stats.render_state_changes = last_frame_render_state_changes;
1740-
stats.texture_stage_state_changes = last_frame_texture_stage_state_changes;
1741-
stats.dx8_calls = last_frame_number_of_DX8_calls;
1742-
stats.draw_calls = last_frame_draw_calls;
1743-
return stats;
1681+
return LastFrameStatistics;
17441682
}
17451683

17461684
unsigned long DX8Wrapper::Get_FrameCount() {return FrameCount;}

GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ struct DX8FrameStatistics
114114
unsigned draw_calls;
115115
};
116116

117-
#define DX8_RECORD_MATRIX_CHANGE() matrix_changes++
118-
#define DX8_RECORD_MATERIAL_CHANGE() material_changes++
119-
#define DX8_RECORD_VERTEX_BUFFER_CHANGE() vertex_buffer_changes++
120-
#define DX8_RECORD_INDEX_BUFFER_CHANGE() index_buffer_changes++
121-
#define DX8_RECORD_LIGHT_CHANGE() light_changes++
122-
#define DX8_RECORD_TEXTURE_CHANGE() texture_changes++
123-
#define DX8_RECORD_RENDER_STATE_CHANGE() render_state_changes++
124-
#define DX8_RECORD_TEXTURE_STAGE_STATE_CHANGE() texture_stage_state_changes++
125-
#define DX8_RECORD_DRAW_CALLS() draw_calls++
117+
#define DX8_RECORD_MATRIX_CHANGE() FrameStatistics.matrix_changes++
118+
#define DX8_RECORD_MATERIAL_CHANGE() FrameStatistics.material_changes++
119+
#define DX8_RECORD_VERTEX_BUFFER_CHANGE() FrameStatistics.vertex_buffer_changes++
120+
#define DX8_RECORD_INDEX_BUFFER_CHANGE() FrameStatistics.index_buffer_changes++
121+
#define DX8_RECORD_LIGHT_CHANGE() FrameStatistics.light_changes++
122+
#define DX8_RECORD_TEXTURE_CHANGE() FrameStatistics.texture_changes++
123+
#define DX8_RECORD_RENDER_STATE_CHANGE() FrameStatistics.render_state_changes++
124+
#define DX8_RECORD_TEXTURE_STAGE_STATE_CHANGE() FrameStatistics.texture_stage_state_changes++
125+
#define DX8_RECORD_DRAW_CALLS() FrameStatistics.draw_calls++
126126

127127
extern unsigned number_of_DX8_calls;
128128
extern bool _DX8SingleThreaded;
@@ -439,7 +439,7 @@ class DX8Wrapper
439439
*/
440440
static void Begin_Statistics();
441441
static void End_Statistics();
442-
static DX8FrameStatistics Get_Last_Frame_Statistics();
442+
static const DX8FrameStatistics& Get_Last_Frame_Statistics();
443443
static unsigned long Get_FrameCount();
444444

445445
// Needed by shader class
@@ -677,15 +677,7 @@ class DX8Wrapper
677677
static bool FogEnable;
678678
static D3DCOLOR FogColor;
679679

680-
static unsigned matrix_changes;
681-
static unsigned material_changes;
682-
static unsigned vertex_buffer_changes;
683-
static unsigned index_buffer_changes;
684-
static unsigned light_changes;
685-
static unsigned texture_changes;
686-
static unsigned render_state_changes;
687-
static unsigned texture_stage_state_changes;
688-
static unsigned draw_calls;
680+
static DX8FrameStatistics FrameStatistics;
689681
static bool CurrentDX8LightEnables[4];
690682

691683
static unsigned long FrameCount;

0 commit comments

Comments
 (0)