Repository navigation
Expand file tree
/
Copy pathProfile.cpp
More file actions
711 lines (577 loc) · 27.1 KB
/
Copy pathProfile.cpp
File metadata and controls
711 lines (577 loc) · 27.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
#include "Common.h"
#include "Profile.h"
#include "Platform.h"
char *my_strncpy(char *d, const char *s, int n)
{
char *r = d;
while((n > 0) && ((*(d ++) = *(s ++)) != NULL)) n --;
return r;
}
#include <stdio.h>
#include <string.h>
#if ENABLE_PROFILER == 1
//****************************************************************************************************
CProfile CProfiler::mProfiles[PE::ProfileCount];
CCounter CProfiler::mCounters[PE::CounterCount];
CMemoryMonitor CProfiler::mMemoryMonitors[PE::MemoryMonitorCount];
SINT CProfiler::mCurrentPage=1;
SINT CProfiler::mFetcher=0;
SINT CProfiler::mCounterFetcher=0;
SINT CProfiler::mMemoryMonitorFetcher=0;
char CProfiler::mPageNames[PE::ProfilePageCount][200];
bool CProfiler::mInitialised=false;
int CProfiler::mGraphPoint=0;
int CProfiler::mSelectedEntry=-1;
//****************************************************************************************************
void CProfiler::InitTimer(PE::EProfile timer, PE::EProfilePage page, char *name)
{
mProfiles[timer].mPage=page;
mProfiles[timer].mRecursiveCalled = 0 ;
my_strncpy(mProfiles[timer].mName, name, 1000); //! Don't ask me.. strcpy doesn't seem to exist?
};
//****************************************************************************************************
void CProfiler::InitCounter(PE::ECounter counter, PE::EProfilePage page, char *name)
{
mCounters[counter].mPage=page;
my_strncpy(mCounters[counter].mName, name, 1000); //! Don't ask me.. strcpy doesn't seem to exist?
};
//****************************************************************************************************
void CProfiler::InitMemoryMonitor(PE::EMemoryMonitor monitor, PE::EProfilePage page, char *name)
{
mMemoryMonitors[monitor].mPage=page;
my_strncpy(mMemoryMonitors[monitor].mName, name, 1000); //! Don't ask me.. strcpy doesn't seem to exist?
};
//****************************************************************************************************
void CProfiler::InitPage(PE::EProfilePage page, char *name)
{
my_strncpy(mPageNames[page], name, 200); //! Don't ask me.. strcpy doesn't seem to exist?
};
//****************************************************************************************************
void CProfiler::Start(PE::EProfile timer)
{
mProfiles[timer].mRecursiveCalled++ ;
if (mProfiles[timer].mRecursiveCalled > 1 ) return ;
mProfiles[timer].mStartTime =TIMER;
};
//****************************************************************************************************
void CProfiler::End(PE::EProfile timer)
{
mProfiles[timer].mRecursiveCalled-- ;
if (mProfiles[timer].mRecursiveCalled > 0 ) return ;
mProfiles[timer].mTotalTime+=TIMER-mProfiles[timer].mStartTime;mProfiles[timer].mCalls++;
};
//****************************************************************************************************
void CProfiler::Count(PE::ECounter counter)
{
mCounters[counter].mCount++;
};
//****************************************************************************************************
void CProfiler::Count(PE::ECounter counter, int n)
{
mCounters[counter].mCount+=n;
};
//****************************************************************************************************
void CProfiler::SetCount(PE::ECounter counter, int n)
{
mCounters[counter].mCount=n;
};
//****************************************************************************************************
void CProfiler::Allocate(PE::EMemoryMonitor monitor, ULONG bytes)
{
mMemoryMonitors[monitor].mAllocated+=bytes;
mMemoryMonitors[monitor].mNumber++;
if (mMemoryMonitors[monitor].mMaxAllocated<mMemoryMonitors[monitor].mAllocated)
mMemoryMonitors[monitor].mMaxAllocated=mMemoryMonitors[monitor].mAllocated;
};
//****************************************************************************************************
void CProfiler::Free(PE::EMemoryMonitor monitor, ULONG bytes)
{
mMemoryMonitors[monitor].mAllocated-=bytes;
mMemoryMonitors[monitor].mNumber--;
if (mMemoryMonitors[monitor].mMinAllocated>mMemoryMonitors[monitor].mAllocated)
mMemoryMonitors[monitor].mMinAllocated=mMemoryMonitors[monitor].mAllocated;
};
//****************************************************************************************************
void CProfiler::Init()
{
// Initialise the profiles
InitTimer(PE::TotalGameCode , PE::Globals , "Total Game") ;
InitTimer(PE::TotalRender , PE::Globals , "Total Render");
InitTimer(PE::RenderBeginScene , PE::RenderOverview , "BeginScene()");
InitTimer(PE::RenderEndScene , PE::RenderOverview , "EndScene()");
InitTimer(PE::RenderFlip , PE::RenderOverview , "Flip()");
InitTimer(PE::RenderCube , PE::RenderOverview , "Draw Cube");
InitTimer(PE::RenderSky , PE::RenderOverview , "Draw Sky");
InitTimer(PE::RenderMap , PE::RenderOverview , "Draw Map");
InitTimer(PE::BuildMap , PE::RenderOverview , "Build Map");
InitTimer(PE::RenderThings , PE::RenderOverview , "Draw Things");
InitTimer(PE::RenderImposters , PE::RenderOverview , "Draw Imposters");
InitTimer(PE::RenderParticles , PE::RenderOverview , "Draw Particles");
InitTimer(PE::RenderParticleMeshes , PE::RenderOverview , "Draw Particle Meshes");
InitTimer(PE::RenderWater , PE::RenderOverview , "Draw Water");
InitTimer(PE::RenderShadowTextures , PE::RenderOverview , "Draw Shadow Textures");
InitTimer(PE::RenderShadows , PE::RenderOverview , "Draw Shadows");
InitTimer(PE::RenderBlobShadows , PE::RenderOverview , "Draw Blob Shadows");
InitTimer(PE::RenderHud , PE::RenderOverview , "Render Hud");
InitTimer(PE::RenderCompass , PE::RenderOverview , "Draw Compass");
InitTimer(PE::RenderDebug , PE::RenderOverview , "Render Debug");
InitCounter(PE::NumParticles , PE::RenderOverview , "--- Num Particles");
InitCounter(PE::NumFoRs , PE::RenderOverview , "--- Num FoRs");
InitTimer(PE::RDMeshVB , PE::RDetails , "Mesh VB Draw");
InitTimer(PE::TotalEventManager, PE::GameOverview, "Total Event Man") ;
InitTimer(PE::ProcessParticles , PE::GameOverview , "Proc Particles");
InitTimer(PE::InitialCollisionSetup , PE::GameOverview , "Initial Col setup");
InitTimer(PE::PossibleCollisionCheck , PE::GameOverview , "Possible col Check");
InitTimer(PE::RoundHit , PE::GameOverview , "Round::Hit") ;
InitTimer(PE::RoundImpact , PE::GameOverview , "Round::Impact") ;
InitTimer(PE::ColMovedSector , PE::GameOverview , "Col moved sector");
InitTimer(PE::RoundHandleEvent , PE::GameOverview , "Round H/E") ;
InitTimer(PE::HighLevelCollisionOccured , PE::GameOverview , "HighLevel col occured");
InitTimer(PE::SphereLineCollision , PE::GameOverview , "Sphere line collision");
InitTimer(PE::SphereSphereCollision , PE::GameOverview , "sphere sphere collision");
InitTimer(PE::CylinderCylinderCollision , PE::GameOverview , "cylinder cylinder collision");
InitTimer(PE::MeshSphereCollision , PE::GameOverview , "Sphere mesh check");
InitTimer(PE::MeshLineCollision , PE::GameOverview , "Line mesh check");
InitTimer(PE::PolySphereCollision , PE::GameOverview , "Sphere poly check");
InitTimer(PE::PolyLineCollision , PE::GameOverview , "Line poly check");
InitTimer(PE::WorldLineCollisionSearch , PE::GameOverview , "World LOS test") ;
InitTimer(PE::MoveThings , PE::GameOverview , "Move objects");
InitTimer(PE::ActorMove , PE::GameOverview , "Actor move ");
InitTimer(PE::ActorLFMove , PE::GameOverview , "LF Actor move ");
InitTimer(PE::RoundMove , PE::GameOverview , "Round move ");
InitTimer(PE::UnitMove , PE::GameOverview , "Unit move ");
InitTimer(PE::GroundVehicleGuide , PE::GameOverview , "Ground Vehicle Guide ");
InitTimer(PE::GroundUnitMove , PE::GameOverview , "Ground u move ");
InitTimer(PE::AirUnitMove , PE::GameOverview , "Air U move ");
InitTimer(PE::LOSCalculations , PE::GameOverview , "Terrain LOS test");
// InitTimer(PE::MapWhoSearches , PE::GameOverview , "MapWho searches");
InitTimer(PE::GetRTEmitter , PE::GameOverview , "Get RT emitter") ;
InitTimer(PE::UnitGetEmitter , PE::GameOverview , "Unit get emitter") ;
InitTimer(PE::UnitAI , PE::GameOverview , "Unit AI");
InitTimer(PE::SquadAI , PE::GameOverview , "Squad AI") ;
InitTimer(PE::GeneralAI , PE::GameOverview , "General AI") ;
// InitTimer(PE::AddEvent , PE::GameOverview , "Add event") ;
// InitTimer(PE::AddDeletionCallback , PE::GameOverview , "Add deletion cb") ;
InitTimer(PE::SPtrSetRemove , PE::GameOverview , "Remove from sptrset");
InitTimer(PE::MonitorDestruction , PE::GameOverview , "monitor destuct") ;
InitTimer(PE::InfluenceMapHandleEvent, PE::GameOverview , "influenece map H/E") ;
InitTimer(PE::FearGrid , PE::GameOverview , "Fear Grid");
InitTimer(PE::RWRHandleEvent, PE::GameOverview , "RWR H/E") ;
InitTimer(PE::PARTProcessAll , PE::ParticleDetails, "Total Process");
InitTimer(PE::PARTProcessSprites , PE::ParticleDetails, "Process Sprites");
InitTimer(PE::PARTProcessTrails , PE::ParticleDetails, "Process Trails");
InitTimer(PE::PARTProcessMeshes , PE::ParticleDetails, "Process Meshes");
InitTimer(PE::PARTProcessEmitters , PE::ParticleDetails, "Process Emmitters");
InitTimer(PE::PARTProcessFoRs , PE::ParticleDetails, "Process FoRs");
InitTimer(PE::PARTProcessTimelines , PE::ParticleDetails, "Process Timelines");
InitTimer(PE::PARTDoInterpolation , PE::ParticleDetails, "Do Interpolation");
InitTimer(PE::PARTRender , PE::ParticleDetails, "Render");
InitTimer(PE::PARTRenderSprites , PE::ParticleDetails, "Render Sprites");
InitTimer(PE::PARTRenderTrails , PE::ParticleDetails, "Render Trails");
InitTimer(PE::PARTConstructList , PE::ParticleDetails, "Construct List");
InitTimer(PE::PARTCacheVals , PE::ParticleDetails, "Cache Vals");
InitTimer(PE::PARTEvalUVs , PE::ParticleDetails, "Eval UVs");
InitTimer(PE::PARTCalcCols , PE::ParticleDetails, "CalcCols");
InitTimer(PE::PARTCalcGeom , PE::ParticleDetails, "CalcGeom");
InitTimer(PE::PARTBuildGeom , PE::ParticleDetails, "BuildGeom");
InitTimer(PE::PARTResetValidations , PE::ParticleDetails, "Reset Validations");
InitTimer(PE::PARTGenericProcess , PE::ParticleDetails, "Generic Process");
InitTimer(PE::PARTProcessDescriptors , PE::ParticleDetails, "Process Descriptors");
InitTimer(PE::PARTCleanUpDead , PE::ParticleDetails, "Clean Up Dead");
InitTimer(PE::PARTValidateAll , PE::ParticleDetails, "Validate All");
InitTimer(PE::PARTDeleteAllInvalid , PE::ParticleDetails, "Delete All Invalid");
InitTimer(PE::PARTInterpolate , PE::ParticleDetails, "Interpolate FoRs");
InitCounter(PE::PARTParticleCount , PE::ParticleDetails, "Num Particles");
InitCounter(PE::PARTFoRCount , PE::ParticleDetails, "Num FoRs");
InitCounter(PE::PARTVFoRCount , PE::ParticleDetails, "Num Validated FoRs");
InitCounter(PE::PARTDeletedCount , PE::ParticleDetails, "Num Deleted this frame");
InitCounter(PE::PARTTrailsRejected , PE::ParticleDetails, "Trails Rejected");
InitCounter(PE::PARTTrailsDrawn , PE::ParticleDetails, "Trails Drawn");
InitCounter(PE::PARTTrailsEmpty , PE::ParticleDetails, "Trails Empty");
InitCounter(PE::PARTSpritesTotal , PE::ParticleDetails, "Sprites Total");
InitCounter(PE::PARTSpritesDrawn , PE::ParticleDetails, "Sprites Drawn");
InitTimer(PE::HUDOnScreen , PE::HudDetails, "On Screen");
InitTimer(PE::HUDTopLeft , PE::HudDetails, "Top Left");
InitTimer(PE::HUDTopCentre , PE::HudDetails, "Top Centre");
InitTimer(PE::HUDTopRight , PE::HudDetails, "Top Right");
InitTimer(PE::HUDCentre , PE::HudDetails, "Centre");
InitTimer(PE::HUDBottomLeft , PE::HudDetails, "Bottom Left");
InitTimer(PE::HUDBottomCentre , PE::HudDetails, "Bottom Centre");
InitTimer(PE::HUDBottomRight , PE::HudDetails, "Bottom Right");
InitTimer(PE::VMRunning, PE::MissionScripting, "VM") ;
InitTimer(PE::Compiling, PE::MissionScripting, "Compiling") ;
InitTimer(PE::IScriptHE, PE::MissionScripting, "IScript H/E") ;
InitTimer(PE::PBSphereStart , PE::CollisionDetail , "PB - Get sphere First");
InitTimer(PE::PBSphereNext , PE::CollisionDetail , "PB - Get sphere Next");
InitTimer(PE::PBLineStart , PE::CollisionDetail , "PB - Get line First");
InitTimer(PE::PBLineNext , PE::CollisionDetail , "PB - Get line Next");
InitTimer(PE::SkeletalEverything , PE::SkeletalOverview , "Everything");
InitTimer(PE::SkeletalBoneSetup , PE::SkeletalOverview , "Bone setup");
InitTimer(PE::SkeletalVertexCalc , PE::SkeletalOverview , "Vertex calculation");
InitTimer(PE::SkeletalRender , PE::SkeletalOverview , "Render");
InitTimer(PE::SkeletalShader , PE::SkeletalOverview , "Shader exec");
InitTimer(PE::GetWorldTransforms , PE::GameOverview , "GetWorldTransforms");
InitTimer(PE::MCMechProcess , PE::GameOverview , "MCMech Process");
InitTimer(PE::ShuffleDebris , PE::Misc , "ShuffleDebris");
InitTimer(PE::SetWorld , PE::Misc , "SetWorld");
InitTimer(PE::MMAlloc , PE::Misc , "Memory Alloc");
InitTimer(PE::MMFree , PE::Misc , "Memory Free");
InitTimer(PE::MCBuggy , PE::MotionControllers , "MCBuggy");
InitTimer(PE::PlaySound , PE::Sound , "PlaySound");
InitTimer(PE::PlayEffect , PE::Sound , "PlayEffect");
InitTimer(PE::UpdateSounds , PE::Sound , "UpdateSounds");
InitTimer(PE::LandscapeTextureRebuild,PE::Landscape , "Texture build");
InitTimer(PE::Pinmapper , PE::Landscape , "Pinmapper");
InitTimer(PE::Shadowmapper , PE::Landscape , "Shadowmapper");
InitTimer(PE::ShadowComposition , PE::Landscape , "Shadow composition");
InitCounter(PE::GWTCacheHits , PE::Misc , "GWT cache hits");
InitCounter(PE::GWTCacheMisses , PE::Misc , "GWT cache misses");
InitCounter(PE::VBufTextureOverruns , PE::VBufTexture , "VBuffer overruns");
InitCounter(PE::VBufTextureUnderruns, PE::VBufTexture , "VBuffer underruns");
InitCounter(PE::IBufTextureOverruns , PE::VBufTexture , "IBuffer overruns");
InitCounter(PE::IBufTextureUnderruns, PE::VBufTexture , "IBuffer underruns");
InitCounter(PE::StaticMeshTotalTriangles, PE::StaticMeshes , "Total triangles");
InitCounter(PE::StaticMeshTotalStrips, PE::StaticMeshes , "Total strips");
InitCounter(PE::StaticMeshMaxStripLength, PE::StaticMeshes, "Max strip length");
InitCounter(PE::StaticMeshAverageStripLength,PE::StaticMeshes,"Average strip length");
InitCounter(PE::StaticMeshPolys , PE::RendererStats , "Static mesh polys");
InitMemoryMonitor(PE::CTextureMainMemory, PE::EngineMainMemory, "CTEXTURE system copies");
InitMemoryMonitor(PE::VBufferMainMemory, PE::EngineMainMemory, "Dynamic VBs");
InitMemoryMonitor(PE::IBufferMainMemory, PE::EngineMainMemory, "Dynamic IBs");
InitMemoryMonitor(PE::SVBMainMemory, PE::EngineMainMemory, "Static mesh VBs");
InitMemoryMonitor(PE::SIBMainMemory, PE::EngineMainMemory, "Static mesh IBs");
InitMemoryMonitor(PE::MeshPartCacheMemory, PE::EngineMainMemory, "Mesh part GWT cache");
InitMemoryMonitor(PE::CTextureVideoMemory, PE::EngineVideoMemory, "CTextures");
InitMemoryMonitor(PE::CUMTextureMemory, PE::EngineVideoMemory, "CUMTextures");
InitMemoryMonitor(PE::VBufferVideoMemory, PE::EngineVideoMemory, "Dynamic VBs");
InitMemoryMonitor(PE::IBufferVideoMemory, PE::EngineVideoMemory, "Dynamic IBs");
InitMemoryMonitor(PE::SVBVideoMemory, PE::EngineVideoMemory, "Static mesh VBs");
InitMemoryMonitor(PE::SIBVideoMemory, PE::EngineVideoMemory, "Static mesh IBs");
InitMemoryMonitor(PE::RTVideoMemory, PE::EngineVideoMemory, "Rendertargets");
// initialise the pages
InitPage(PE::Globals , "Global Timers");
InitPage(PE::RenderOverview , "Rendering Overview");
InitPage(PE::RDetails , "Rendering Details");
InitPage(PE::GameOverview , "Game Processing Overview");
InitPage(PE::ParticleDetails , "Particle Processing");
InitPage(PE::MissionScripting , "Mission Scripting");
InitPage(PE::CollisionDetail , "Collision Details");
InitPage(PE::SkeletalOverview , "Skeletal renderer");
InitPage(PE::Misc , "Misc");
InitPage(PE::VBufTexture , "VBufTexture management");
InitPage(PE::EngineMainMemory , "Engine main memory usage");
InitPage(PE::EngineVideoMemory , "Engine video memory usage");
InitPage(PE::StaticMeshes , "Static meshes");
InitPage(PE::MotionControllers , "Motion controllers");
InitPage(PE::Sound , "Sound");
InitPage(PE::RendererStats , "Renderer stats");
InitPage(PE::Landscape , "Landscape");
}
//****************************************************************************************************
void CProfiler::ResetAll()
{
SINT c0;
for (c0=0;c0<PE::ProfileCount;c0++)
{
mProfiles[c0].mLastTotalTime = mProfiles[c0].mTotalTime;
mProfiles[c0].mLastCalls = mProfiles[c0].mCalls;
mProfiles[c0].mGraphTimes[mGraphPoint]=mProfiles[c0].mTotalTime;
mProfiles[c0].mTotalTime=0;
mProfiles[c0].mCalls=0;
mProfiles[c0].mRecursiveCalled = 0 ;
}
mGraphPoint++;
if (mGraphPoint>=PROFILE_GRAPH_RECORDS)
mGraphPoint=0;
int counterstoreset;
if (mInitialised)
{
for (c0=0;c0<PE::MemoryMonitorCount;c0++)
{
mMemoryMonitors[c0].mAllocated=0;
mMemoryMonitors[c0].mMaxAllocated=0;
mMemoryMonitors[c0].mMinAllocated=0;
mMemoryMonitors[c0].mNumber=0;
}
counterstoreset=PE::CounterCount;
mInitialised=true;
}
else
counterstoreset=PE::NonResettingStarthere;
for (c0=0;c0<counterstoreset;c0++)
{
if (mCounters[c0].mCount>mCounters[c0].mMax)
mCounters[c0].mMax=mCounters[c0].mCount;
if (mCounters[c0].mCount<mCounters[c0].mMin)
mCounters[c0].mMin=mCounters[c0].mCount;
mCounters[c0].mCount=0;
}
}
//****************************************************************************************************
void CProfiler::NextPage()
{
if (mCurrentPage<PE::ProfilePageCount-1)
mCurrentPage++;
}
//****************************************************************************************************
void CProfiler::PrevPage()
{
if (mCurrentPage>0)
mCurrentPage--;
}
//****************************************************************************************************
void CProfiler::SelectionUp()
{
mSelectedEntry--;
if (mSelectedEntry<-1)
mSelectedEntry=-1;
}
//****************************************************************************************************
void CProfiler::SelectionDown()
{
mSelectedEntry++;
// The position of this will be capped when the profile is drawn
}
//****************************************************************************************************
CProfile *CProfiler::Fetch()
{
while (mFetcher<PE::ProfileCount)
{
if (mProfiles[mFetcher].mPage==mCurrentPage)
return &mProfiles[mFetcher++];
mFetcher++;
}
return NULL; // no more left
}
//****************************************************************************************************
void CProfiler::ResetFetch()
{
mFetcher=0;
}
//****************************************************************************************************
CCounter *CProfiler::FetchCounter()
{
while (mCounterFetcher<PE::CounterCount)
{
if (mCounters[mCounterFetcher].mPage==mCurrentPage)
return &mCounters[mCounterFetcher++];
mCounterFetcher++;
}
return NULL; // no more left
}
//****************************************************************************************************
void CProfiler::ResetFetchCounter()
{
mCounterFetcher=0;
}
//****************************************************************************************************
CMemoryMonitor *CProfiler::FetchMemoryMonitor()
{
while (mMemoryMonitorFetcher<PE::MemoryMonitorCount)
{
if (mMemoryMonitors[mMemoryMonitorFetcher].mPage==mCurrentPage)
return &mMemoryMonitors[mMemoryMonitorFetcher++];
mMemoryMonitorFetcher++;
}
return NULL; // no more left
}
//****************************************************************************************************
void CProfiler::ResetFetchMemoryMonitor()
{
mMemoryMonitorFetcher=0;
}
//****************************************************************************************************
//****************************************************************************************************
//****************************************************************************************************
#if TARGET == XBOX
#define PC_LEFT (0 + 60)
#define PC_XT1 (120 + 60)
#define PC_XT2 (200 + 60)
#define PC_XT3 (240 + 60)
#define PC_XL (320 + 60)
#else
#define PC_LEFT 0
#define PC_XT1 120
#define PC_XT2 200
#define PC_XT3 240
#define PC_XL 320
#endif
int PC_SCALE = 19 ;
//****************************************************************************************************
void CProfiler::DrawMemoryMonitor(CMemoryMonitor *p, SINT y)
{
char text[500];
SINT size;
size = sprintf(text, "%s: ", p->mName);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_LEFT, float(y), 0xffff2000, ToWCHAR(text), 0L );
size = sprintf(text, "%d", p->mNumber);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XT1, float(y), 0xff64c832, ToWCHAR(text), 0L );
size = sprintf(text, "%dk", p->mAllocated/1024);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XT2, float(y), 0xff64c832, ToWCHAR(text), 0L );
size = sprintf(text, "%dk", p->mMinAllocated/1024);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XT3, float(y), 0xff64c832, ToWCHAR(text), 0L );
size = sprintf(text, "%dk", p->mMaxAllocated/1024);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XL, float(y), 0xff64c832, ToWCHAR(text), 0L );
}
//****************************************************************************************************
void CProfiler::DrawMemoryTotal(SINT number, ULONG total, ULONG min, ULONG max, SINT y)
{
char text[500];
SINT size;
size = sprintf(text, "Total: ");
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_LEFT, float(y), 0xffff20ff, ToWCHAR(text), 0L );
size = sprintf(text, "%d", number);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XT1, float(y), 0xff64c832, ToWCHAR(text), 0L );
size = sprintf(text, "%dk", total/1024);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XT2, float(y), 0xff64c832, ToWCHAR(text), 0L );
size = sprintf(text, "%dk", min/1024);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XT3, float(y), 0xff64c832, ToWCHAR(text), 0L );
size = sprintf(text, "%dk", max/1024);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XL, float(y), 0xff64c832, ToWCHAR(text), 0L );
}
//****************************************************************************************************
void CProfiler::DrawProfile(CProfile *p, SINT y)
{
char text[500];
SINT size;
size = sprintf(text, "%s: ", p->mName);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_LEFT, float(y), 0xffC88232, ToWCHAR(text), 0L );
size = sprintf(text, "%d", p->mLastTotalTime);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XT1, float(y), 0xff64c832, ToWCHAR(text), 0L );
size = sprintf(text, "%d", p->mLastCalls);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XT2, float(y), 0xff64c832, ToWCHAR(text), 0L );
if (p->mLastCalls)
{
size = sprintf(text, "%d", p->mLastTotalTime / p->mLastCalls);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XT3, float(y), 0xff64c832, ToWCHAR(text), 0L );
}
SINT v = (p->mLastTotalTime)>>PC_SCALE;
// draw zoomed in on game code
if ((mCurrentPage == 3) || (mCurrentPage == 4))
{
v = (p->mLastTotalTime)>>(PC_SCALE-2);
}
if (v > 150) v = 150;
memset(text, '*', v);
text[v]='\0' ;
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XL, (float)y, 0xffFF2422, ToWCHAR(text), 0L );
}
//****************************************************************************************************
void CProfiler::DrawProfileGraph(CProfile *p, SINT y)
{
char text[500];
int pt=mGraphPoint+1;
if (pt>=PROFILE_GRAPH_RECORDS)
pt=0;
for (int i=0;i<PROFILE_GRAPH_RECORDS;i++)
{
SINT v=p->mGraphTimes[pt] >> PC_SCALE;
if (v > 150) v = 150;
memset(text, '_', v);
text[v]='\0' ;
PLATFORM.Font( FONT_DEBUG )->DrawText( PC_XL, (float) y, 0xffffffff, ToWCHAR(text), 0L );
y++;
pt++;
if (pt>=PROFILE_GRAPH_RECORDS)
pt=0;
}
}
//****************************************************************************************************
void CProfiler::DrawCounter(CCounter *c, SINT y)
{
char text[500];
SINT size;
size = sprintf(text, "%s: ", c->mName);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_LEFT, float(y), 0xff0082ff, ToWCHAR(text), 0L );
size = sprintf(text, "%d", c->mCount);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XT1, float(y), 0xff64c832, ToWCHAR(text), 0L );
size = sprintf(text, "%d", c->mMin);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XT2, float(y), 0xff64c832, ToWCHAR(text), 0L );
size = sprintf(text, "%d", c->mMax);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_XT3, float(y), 0xff64c832, ToWCHAR(text), 0L );
}
//****************************************************************************************************
void CProfiler::DrawTitle(SINT y)
{
char text[300];
sprintf(text, "Page %d / %d: %s", mCurrentPage + 1, PE::ProfilePageCount, mPageNames[mCurrentPage]);
PLATFORM.Font( FONT_DEBUG )->DrawTextShadowed( PC_LEFT, float(y), 0xff4080ff, ToWCHAR(text), 0L );
}
//****************************************************************************************************
void CProfiler::ShowProfile()
{
CProfile *p;
SINT y = 32;
#if TARGET == PS2
y=64; // To avoid the PS2 render stats
#endif
// draw totals
p = &mProfiles[0];
DrawProfile(p, y);
y += 16;
p = &mProfiles[1];
DrawProfile(p, y);
y += 16;
y += 4;
DrawTitle(y);
y += 4;
y += 16;
int entrycount=0;
ResetFetch();
while ((p=Fetch())!=NULL)
{
DrawProfile(p, y);
y += 10;
if (entrycount==mSelectedEntry)
{
PLATFORM.Font( FONT_DEBUG )->DrawText( PC_LEFT, float(y-10), 0xffffffff, ToWCHAR("_______"));
DrawProfileGraph(p,(y-10));
y+=PROFILE_GRAPH_RECORDS+10;
}
entrycount++;
if (y > 450)
break;
}
y+=10;
CCounter *c;
ResetFetchCounter();
while ((c=FetchCounter())!=NULL)
{
if (entrycount==mSelectedEntry)
PLATFORM.Font( FONT_DEBUG )->DrawText( PC_LEFT, float(y), 0xffffffff, ToWCHAR("_______"));
entrycount++;
DrawCounter(c, y);
y += 10;
if (y > 450)
break;
}
if (mSelectedEntry>=entrycount)
mSelectedEntry=entrycount-1;
y+=10;
CMemoryMonitor *m;
ULONG total=0;
ULONG maxtotal=0;
ULONG mintotal=0;
ULONG ntotal=0;
ResetFetchMemoryMonitor();
while ((m=FetchMemoryMonitor())!=NULL)
{
if (entrycount==mSelectedEntry)
PLATFORM.Font( FONT_DEBUG )->DrawText( PC_LEFT, float(y), 0xffffffff, ToWCHAR("_______"));
entrycount++;
DrawMemoryMonitor(m, y);
total+=m->mAllocated;
maxtotal+=m->mMaxAllocated;
mintotal+=m->mMinAllocated;
ntotal+=m->mNumber;
y += 10;
if (y > 450)
break;
}
if (ntotal>0)
{
y += 10;
DrawMemoryTotal(ntotal,total,mintotal,maxtotal,y);
}
}
#endif