forked from id-Software/DOOM-3-BFG
-
Notifications
You must be signed in to change notification settings - Fork 251
/
Console.cpp
1674 lines (1400 loc) · 41.3 KB
/
Console.cpp
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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#pragma hdrstop
#include "precompiled.h"
#include "ConsoleHistory.h"
#include "../renderer/ResolutionScale.h"
#include "Common_local.h"
#include "../imgui/BFGimgui.h"
#define CON_TEXTSIZE 0x30000
#define NUM_CON_TIMES 4
#define CONSOLE_FIRSTREPEAT 200
#define CONSOLE_REPEAT 100
#define COMMAND_HISTORY 64
struct overlayText_t
{
idStr text;
justify_t justify;
int time;
};
// the console will query the cvar and command systems for
// command completion information
class idConsoleLocal : public idConsole
{
public:
virtual void Init();
virtual void Shutdown();
virtual bool ProcessEvent( const sysEvent_t* event, bool forceAccept );
virtual bool Active();
virtual void ClearNotifyLines();
virtual void Open();
virtual void Close();
virtual void Print( const char* text );
virtual void Draw( bool forceFullScreen );
virtual void PrintOverlay( idOverlayHandle& handle, justify_t justify, const char* text, ... );
virtual idDebugGraph* CreateGraph( int numItems );
virtual void DestroyGraph( idDebugGraph* graph );
void Dump( const char* toFile );
void Clear();
private:
void Resize();
void KeyDownEvent( int key );
void Linefeed();
void PageUp();
void PageDown();
void Top();
void Bottom();
void DrawInput();
void DrawNotify();
void DrawSolidConsole( float frac );
void Scroll();
void SetDisplayFraction( float frac );
void UpdateDisplayFraction();
void DrawTextLeftAlign( float x, float& y, const char* text, ... );
void DrawTextRightAlign( float x, float& y, const char* text, ... );
float DrawFPS( float y );
float DrawMemoryUsage( float y );
void DrawOverlayText( float& leftY, float& rightY, float& centerY );
void DrawDebugGraphs();
//============================
// allow these constants to be adjusted for HMD
int LOCALSAFE_LEFT;
int LOCALSAFE_RIGHT;
int LOCALSAFE_TOP;
int LOCALSAFE_BOTTOM;
int LOCALSAFE_WIDTH;
int LOCALSAFE_HEIGHT;
int LINE_WIDTH;
int TOTAL_LINES;
bool keyCatching;
short text[CON_TEXTSIZE];
int current; // line where next message will be printed
int x; // offset in current line for next print
int display; // bottom of console displays this line
int lastKeyEvent; // time of last key event for scroll delay
int nextKeyEvent; // keyboard repeat rate
float displayFrac; // approaches finalFrac at con_speed
float finalFrac; // 0.0 to 1.0 lines of console to display
int fracTime; // time of last displayFrac update
int vislines; // in scanlines
int times[NUM_CON_TIMES]; // cls.realtime time the line was generated
// for transparent notify lines
idVec4 color;
idEditField historyEditLines[COMMAND_HISTORY];
int nextHistoryLine;// the last line in the history buffer, not masked
int historyLine; // the line being displayed from history buffer
// will be <= nextHistoryLine
idEditField consoleField;
idList< overlayText_t > overlayText;
idList< idDebugGraph*> debugGraphs;
int lastVirtualScreenWidth;
int lastVirtualScreenHeight;
static idCVar con_speed;
static idCVar con_notifyTime;
static idCVar con_noPrint;
};
static idConsoleLocal localConsole;
idConsole* console = &localConsole;
idCVar idConsoleLocal::con_speed( "con_speed", "3", CVAR_SYSTEM, "speed at which the console moves up and down" );
idCVar idConsoleLocal::con_notifyTime( "con_notifyTime", "3", CVAR_SYSTEM, "time messages are displayed onscreen when console is pulled up" );
#ifdef DEBUG
idCVar idConsoleLocal::con_noPrint( "con_noPrint", "0", CVAR_BOOL | CVAR_SYSTEM | CVAR_NOCHEAT, "print on the console but not onscreen when console is pulled up" );
#else
idCVar idConsoleLocal::con_noPrint( "con_noPrint", "1", CVAR_BOOL | CVAR_SYSTEM | CVAR_NOCHEAT, "print on the console but not onscreen when console is pulled up" );
#endif
/*
=============================================================================
Misc stats
=============================================================================
*/
/*
==================
idConsoleLocal::DrawTextLeftAlign
==================
*/
void idConsoleLocal::DrawTextLeftAlign( float x, float& y, const char* text, ... )
{
char string[MAX_STRING_CHARS];
va_list argptr;
va_start( argptr, text );
idStr::vsnPrintf( string, sizeof( string ), text, argptr );
va_end( argptr );
renderSystem->DrawSmallStringExt( x, y + 2, string, colorWhite, true );
y += SMALLCHAR_HEIGHT + 4;
}
/*
==================
idConsoleLocal::DrawTextRightAlign
==================
*/
void idConsoleLocal::DrawTextRightAlign( float x, float& y, const char* text, ... )
{
char string[MAX_STRING_CHARS];
va_list argptr;
va_start( argptr, text );
int i = idStr::vsnPrintf( string, sizeof( string ), text, argptr );
va_end( argptr );
renderSystem->DrawSmallStringExt( x - i * SMALLCHAR_WIDTH, y + 2, string, colorWhite, true );
y += SMALLCHAR_HEIGHT + 4;
}
/*
==================
idConsoleLocal::DrawFPS
==================
*/
#define FPS_FRAMES 6
#define FPS_FRAMES_HISTORY 90
float idConsoleLocal::DrawFPS( float y )
{
static float previousTimes[FPS_FRAMES];
static float previousTimesNormalized[FPS_FRAMES_HISTORY];
static int index;
static int previous;
static int valuesOffset = 0;
bool renderImGuiPerfWindow = ImGuiHook::IsReadyToRender() && ( com_showFPS.GetInteger() > 1 );
// don't use serverTime, because that will be drifting to
// correct for internet lag changes, timescales, timedemos, etc
int t = Sys_Milliseconds();
int frameTime = t - previous;
previous = t;
int fps = 0;
const float milliSecondsPerFrame = 1000.0f / com_engineHz_latched;
previousTimes[index % FPS_FRAMES] = frameTime;
previousTimesNormalized[index % FPS_FRAMES_HISTORY] = frameTime / milliSecondsPerFrame;
valuesOffset = ( valuesOffset + 1 ) % FPS_FRAMES_HISTORY;
index++;
if( index > FPS_FRAMES )
{
// average multiple frames together to smooth changes out a bit
int total = 0;
for( int i = 0 ; i < FPS_FRAMES ; i++ )
{
total += previousTimes[i];
}
if( !total )
{
total = 1;
}
fps = 1000000 * FPS_FRAMES / total;
fps = ( fps + 500 ) / 1000;
const char* s = va( "%ifps", fps );
int w = strlen( s ) * BIGCHAR_WIDTH;
if( com_showFPS.GetInteger() == 1 )
{
renderSystem->DrawBigStringExt( LOCALSAFE_RIGHT - w, idMath::Ftoi( y ) + 2, s, colorWhite, true );
}
}
y += BIGCHAR_HEIGHT + 4;
// DG: "com_showFPS 1" means: show FPS only, like in classic doom3
if( com_showFPS.GetInteger() == 1 )
{
return y;
}
// DG end
//const uint64 gameThreadTotalTime = commonLocal.GetGameThreadTotalTime();
//const uint64 gameThreadGameTime = commonLocal.GetGameThreadGameTime();
//const uint64 gameThreadRenderTime = commonLocal.GetGameThreadRenderTime();
const uint64 gameThreadTotalTime = commonLocal.mainFrameTiming.finishDrawTime - commonLocal.mainFrameTiming.startGameTime;
const uint64 gameThreadGameTime = commonLocal.mainFrameTiming.finishGameTime - commonLocal.mainFrameTiming.startGameTime;
const uint64 gameThreadRenderTime = commonLocal.mainFrameTiming.finishDrawTime - commonLocal.mainFrameTiming.finishGameTime;
const uint64 rendererBackEndTime = commonLocal.GetRendererBackEndMicroseconds();
const uint64 rendererShadowsTime = commonLocal.GetRendererShadowsMicroseconds();
const uint64 rendererGPUIdleTime = commonLocal.GetRendererIdleMicroseconds();
const uint64 rendererGPUTime = commonLocal.GetRendererGPUMicroseconds();
const uint64 rendererGPUEarlyZTime = commonLocal.GetRendererGpuEarlyZMicroseconds();
const uint64 rendererGPU_SSAOTime = commonLocal.GetRendererGpuSSAOMicroseconds();
const uint64 rendererGPU_SSRTime = commonLocal.GetRendererGpuSSRMicroseconds();
const uint64 rendererGPUAmbientPassTime = commonLocal.GetRendererGpuAmbientPassMicroseconds();
const uint64 rendererGPUInteractionsTime = commonLocal.GetRendererGpuInteractionsMicroseconds();
const uint64 rendererGPUShaderPassesTime = commonLocal.GetRendererGpuShaderPassMicroseconds();
const uint64 rendererGPUPostProcessingTime = commonLocal.GetRendererGpuPostProcessingMicroseconds();
const int maxTime = 16 * 1000;
#if 1
// RB: use ImGui to show more detailed stats about the scene loads
if( ImGuiHook::IsReadyToRender() )
{
// start smaller
int32 statsWindowWidth = 320;
int32 statsWindowHeight = 260;
if( com_showFPS.GetInteger() > 2 )
{
statsWindowWidth = 550;
statsWindowHeight = 370;
}
ImVec2 pos;
pos.x = renderSystem->GetWidth() - statsWindowWidth;
pos.y = 0;
ImGui::SetNextWindowPos( pos );
ImGui::SetNextWindowSize( ImVec2( statsWindowWidth, statsWindowHeight ) );
static ImVec4 colorBlack = ImVec4( 0.00f, 0.00f, 0.00f, 1.00f );
static ImVec4 colorWhite = ImVec4( 1.00f, 1.00f, 1.00f, 1.00f );
static ImVec4 colorRed = ImVec4( 1.00f, 0.00f, 0.00f, 1.00f );
static ImVec4 colorGreen = ImVec4( 0.00f, 1.00f, 0.00f, 1.00f );
static ImVec4 colorBlue = ImVec4( 0.00f, 0.00f, 1.00f, 1.00f );
static ImVec4 colorYellow = ImVec4( 1.00f, 1.00f, 0.00f, 1.00f );
static ImVec4 colorMagenta = ImVec4( 1.00f, 0.00f, 1.00f, 1.00f );
static ImVec4 colorCyan = ImVec4( 0.00f, 1.00f, 1.00f, 1.00f );
static ImVec4 colorOrange = ImVec4( 1.00f, 0.50f, 0.00f, 1.00f );
static ImVec4 colorPurple = ImVec4( 0.60f, 0.00f, 0.60f, 1.00f );
static ImVec4 colorPink = ImVec4( 0.73f, 0.40f, 0.48f, 1.00f );
static ImVec4 colorBrown = ImVec4( 0.40f, 0.35f, 0.08f, 1.00f );
static ImVec4 colorLtGrey = ImVec4( 0.75f, 0.75f, 0.75f, 1.00f );
static ImVec4 colorMdGrey = ImVec4( 0.50f, 0.50f, 0.50f, 1.00f );
static ImVec4 colorDkGrey = ImVec4( 0.25f, 0.25f, 0.25f, 1.00f );
ImGui::Begin( "Performance Stats" );
#if defined( USE_VULKAN )
const char* API = "Vulkan";
#else
const char* API = "OpenGL";
#endif
extern idCVar r_antiAliasing;
static const int aaNumValues = 5;
static const char* aaValues[aaNumValues] =
{
"None",
"SMAA 1X",
"MSAA 2X",
"MSAA 4X",
"MSAA 8X"
};
compile_time_assert( aaNumValues == ( ANTI_ALIASING_MSAA_8X + 1 ) );
const char* aaMode = aaValues[ r_antiAliasing.GetInteger() ];
idStr resolutionText;
resolutionScale.GetConsoleText( resolutionText );
int width = renderSystem->GetWidth();
int height = renderSystem->GetHeight();
ImGui::TextColored( colorCyan, "API: %s, AA[%i, %i]: %s, %s", API, width, height, aaMode, resolutionText.c_str() );
ImGui::TextColored( colorLtGrey, "GENERAL: views:%i draws:%i tris:%i (shdw:%i)",
commonLocal.stats_frontend.c_numViews,
commonLocal.stats_backend.c_drawElements + commonLocal.stats_backend.c_shadowElements,
( commonLocal.stats_backend.c_drawIndexes + commonLocal.stats_backend.c_shadowIndexes ) / 3,
commonLocal.stats_backend.c_shadowIndexes / 3 );
if( com_showFPS.GetInteger() > 2 )
{
ImGui::TextColored( colorLtGrey, "DYNAMIC: callback:%i md5:%i dfrmVerts:%i dfrmTris:%i tangTris:%i guis:%i",
commonLocal.stats_frontend.c_entityDefCallbacks,
commonLocal.stats_frontend.c_generateMd5,
commonLocal.stats_frontend.c_deformedVerts,
commonLocal.stats_frontend.c_deformedIndexes / 3,
commonLocal.stats_frontend.c_tangentIndexes / 3,
commonLocal.stats_frontend.c_guiSurfs
);
//ImGui::Text( "Cull: %i box in %i box out\n",
// commonLocal.stats_frontend.c_box_cull_in, commonLocal.stats_frontend.c_box_cull_out );
ImGui::TextColored( colorLtGrey, "ADDMODEL: callback:%i createInteractions:%i createShadowVolumes:%i",
commonLocal.stats_frontend.c_entityDefCallbacks,
commonLocal.stats_frontend.c_createInteractions,
commonLocal.stats_frontend.c_createShadowVolumes );
ImGui::TextColored( colorLtGrey, "viewEntities:%i shadowEntities:%i viewLights:%i\n", commonLocal.stats_frontend.c_visibleViewEntities,
commonLocal.stats_frontend.c_shadowViewEntities,
commonLocal.stats_frontend.c_viewLights );
ImGui::TextColored( colorLtGrey, "UPDATES: entityUpdates:%i entityRefs:%i lightUpdates:%i lightRefs:%i\n",
commonLocal.stats_frontend.c_entityUpdates, commonLocal.stats_frontend.c_entityReferences,
commonLocal.stats_frontend.c_lightUpdates, commonLocal.stats_frontend.c_lightReferences );
}
//ImGui::Text( "frameData: %i (%i)\n", frameData->frameMemoryAllocated.GetValue(), frameData->highWaterAllocated );
//ImGui::Spacing();
//ImGui::Spacing();
ImGui::Spacing();
if( com_showFPS.GetInteger() > 2 )
{
const char* overlay = va( "Average FPS %i", fps );
ImGui::PlotLines( "Relative\nFrametime ms", previousTimesNormalized, FPS_FRAMES_HISTORY, valuesOffset, overlay, -10.0f, 10.0f, ImVec2( 0, 50 ) );
}
else
{
ImGui::TextColored( colorYellow, "Average FPS %i", fps );
}
ImGui::Spacing();
ImGui::TextColored( colorMdGrey, "CPU GPU" );
ImGui::TextColored( gameThreadTotalTime > maxTime ? colorRed : colorWhite, "Game+RF: %5llu us EarlyZ: %5llu us", gameThreadTotalTime, rendererGPUEarlyZTime );
ImGui::TextColored( gameThreadGameTime > maxTime ? colorRed : colorWhite, "Game: %5llu us SSAO: %5llu us", gameThreadGameTime, rendererGPU_SSAOTime );
ImGui::TextColored( gameThreadRenderTime > maxTime ? colorRed : colorWhite, "RF: %5llu us SSR: %5llu us", gameThreadRenderTime, rendererGPU_SSRTime );
ImGui::TextColored( rendererBackEndTime > maxTime ? colorRed : colorWhite, "RB: %5llu us AmbientPass: %5llu us", rendererBackEndTime, rendererGPUAmbientPassTime );
ImGui::TextColored( rendererShadowsTime > maxTime ? colorRed : colorWhite, "Shadows: %5llu us Interactions: %5llu us", rendererShadowsTime, rendererGPUInteractionsTime );
ImGui::TextColored( rendererGPUShaderPassesTime > maxTime ? colorRed : colorWhite, " ShaderPass: %5llu us", rendererGPUShaderPassesTime );
ImGui::TextColored( rendererGPUPostProcessingTime > maxTime ? colorRed : colorWhite, " PostFX: %5llu us", rendererGPUPostProcessingTime );
ImGui::TextColored( rendererGPUIdleTime > maxTime ? colorRed : colorWhite, " Idle: %5llu us", rendererGPUIdleTime );
ImGui::TextColored( rendererGPUTime > maxTime ? colorRed : colorWhite, " Total: %5llu us", rendererGPUTime );
ImGui::End();
}
return y;
#else
// print the resolution scale so we can tell when we are at reduced resolution
idStr resolutionText;
resolutionScale.GetConsoleText( resolutionText );
int w = resolutionText.Length() * BIGCHAR_WIDTH;
renderSystem->DrawBigStringExt( LOCALSAFE_RIGHT - w, idMath::Ftoi( y ) + 2, resolutionText.c_str(), colorWhite, true );
y += SMALLCHAR_HEIGHT + 4;
idStr timeStr;
timeStr.Format( "%sG+RF: %4d", gameThreadTotalTime > maxTime ? S_COLOR_RED : "", gameThreadTotalTime );
w = timeStr.LengthWithoutColors() * SMALLCHAR_WIDTH;
renderSystem->DrawSmallStringExt( LOCALSAFE_RIGHT - w, idMath::Ftoi( y ) + 2, timeStr.c_str(), colorWhite, false );
y += SMALLCHAR_HEIGHT + 4;
timeStr.Format( "%sG: %4d", gameThreadGameTime > maxTime ? S_COLOR_RED : "", gameThreadGameTime );
w = timeStr.LengthWithoutColors() * SMALLCHAR_WIDTH;
renderSystem->DrawSmallStringExt( LOCALSAFE_RIGHT - w, idMath::Ftoi( y ) + 2, timeStr.c_str(), colorWhite, false );
y += SMALLCHAR_HEIGHT + 4;
timeStr.Format( "%sRF: %4d", gameThreadRenderTime > maxTime ? S_COLOR_RED : "", gameThreadRenderTime );
w = timeStr.LengthWithoutColors() * SMALLCHAR_WIDTH;
renderSystem->DrawSmallStringExt( LOCALSAFE_RIGHT - w, idMath::Ftoi( y ) + 2, timeStr.c_str(), colorWhite, false );
y += SMALLCHAR_HEIGHT + 4;
timeStr.Format( "%sRB: %4.1f", rendererBackEndTime > maxTime * 1000 ? S_COLOR_RED : "", rendererBackEndTime / 1000.0f );
w = timeStr.LengthWithoutColors() * SMALLCHAR_WIDTH;
renderSystem->DrawSmallStringExt( LOCALSAFE_RIGHT - w, idMath::Ftoi( y ) + 2, timeStr.c_str(), colorWhite, false );
y += SMALLCHAR_HEIGHT + 4;
timeStr.Format( "%sSV: %4.1f", rendererShadowsTime > maxTime * 1000 ? S_COLOR_RED : "", rendererShadowsTime / 1000.0f );
w = timeStr.LengthWithoutColors() * SMALLCHAR_WIDTH;
renderSystem->DrawSmallStringExt( LOCALSAFE_RIGHT - w, idMath::Ftoi( y ) + 2, timeStr.c_str(), colorWhite, false );
y += SMALLCHAR_HEIGHT + 4;
timeStr.Format( "%sIDLE: %4.1f", rendererGPUIdleTime > maxTime * 1000 ? S_COLOR_RED : "", rendererGPUIdleTime / 1000.0f );
w = timeStr.LengthWithoutColors() * SMALLCHAR_WIDTH;
renderSystem->DrawSmallStringExt( LOCALSAFE_RIGHT - w, idMath::Ftoi( y ) + 2, timeStr.c_str(), colorWhite, false );
y += SMALLCHAR_HEIGHT + 4;
timeStr.Format( "%sGPU: %4.1f", rendererGPUTime > maxTime * 1000 ? S_COLOR_RED : "", rendererGPUTime / 1000.0f );
w = timeStr.LengthWithoutColors() * SMALLCHAR_WIDTH;
renderSystem->DrawSmallStringExt( LOCALSAFE_RIGHT - w, idMath::Ftoi( y ) + 2, timeStr.c_str(), colorWhite, false );
return y + BIGCHAR_HEIGHT + 4;
#endif
}
/*
==================
idConsoleLocal::DrawMemoryUsage
==================
*/
float idConsoleLocal::DrawMemoryUsage( float y )
{
return y;
}
//=========================================================================
/*
==============
Con_Clear_f
==============
*/
static void Con_Clear_f( const idCmdArgs& args )
{
localConsole.Clear();
}
/*
==============
Con_Dump_f
==============
*/
static void Con_Dump_f( const idCmdArgs& args )
{
if( args.Argc() != 2 )
{
common->Printf( "usage: conDump <filename>\n" );
return;
}
idStr fileName = args.Argv( 1 );
fileName.DefaultFileExtension( ".txt" );
common->Printf( "Dumped console text to %s.\n", fileName.c_str() );
localConsole.Dump( fileName.c_str() );
}
/*
==============
idConsoleLocal::Init
==============
*/
void idConsoleLocal::Init()
{
int i;
keyCatching = false;
LOCALSAFE_LEFT = 0;
LOCALSAFE_RIGHT = SCREEN_WIDTH - LOCALSAFE_LEFT;
LOCALSAFE_TOP = 24;
LOCALSAFE_BOTTOM = SCREEN_HEIGHT - LOCALSAFE_TOP;
LOCALSAFE_WIDTH = LOCALSAFE_RIGHT - LOCALSAFE_LEFT;
LOCALSAFE_HEIGHT = LOCALSAFE_BOTTOM - LOCALSAFE_TOP;
LINE_WIDTH = ( ( LOCALSAFE_WIDTH / SMALLCHAR_WIDTH ) - 2 );
TOTAL_LINES = ( CON_TEXTSIZE / LINE_WIDTH );
lastKeyEvent = -1;
nextKeyEvent = CONSOLE_FIRSTREPEAT;
consoleField.Clear();
consoleField.SetWidthInChars( LINE_WIDTH );
for( i = 0 ; i < COMMAND_HISTORY ; i++ )
{
historyEditLines[i].Clear();
historyEditLines[i].SetWidthInChars( LINE_WIDTH );
}
cmdSystem->AddCommand( "clear", Con_Clear_f, CMD_FL_SYSTEM, "clears the console" );
cmdSystem->AddCommand( "conDump", Con_Dump_f, CMD_FL_SYSTEM, "dumps the console text to a file" );
}
/*
==============
idConsoleLocal::Shutdown
==============
*/
void idConsoleLocal::Shutdown()
{
cmdSystem->RemoveCommand( "clear" );
cmdSystem->RemoveCommand( "conDump" );
debugGraphs.DeleteContents( true );
}
/*
================
idConsoleLocal::Active
================
*/
bool idConsoleLocal::Active()
{
return keyCatching;
}
/*
================
idConsoleLocal::ClearNotifyLines
================
*/
void idConsoleLocal::ClearNotifyLines()
{
int i;
for( i = 0 ; i < NUM_CON_TIMES ; i++ )
{
times[i] = 0;
}
}
/*
================
idConsoleLocal::Open
================
*/
void idConsoleLocal::Open()
{
if( keyCatching )
{
return; // already open
}
consoleField.ClearAutoComplete();
consoleField.Clear();
keyCatching = true;
SetDisplayFraction( 0.5f );
}
/*
================
idConsoleLocal::Close
================
*/
void idConsoleLocal::Close()
{
keyCatching = false;
SetDisplayFraction( 0 );
displayFrac = 0; // don't scroll to that point, go immediately
ClearNotifyLines();
}
/*
================
idConsoleLocal::Clear
================
*/
void idConsoleLocal::Clear()
{
int i;
for( i = 0 ; i < CON_TEXTSIZE ; i++ )
{
text[i] = ( idStr::ColorIndex( C_COLOR_WHITE ) << 8 ) | ' ';
}
Bottom(); // go to end
}
/*
================
idConsoleLocal::Dump
Save the console contents out to a file
================
*/
void idConsoleLocal::Dump( const char* fileName )
{
int l, x, i;
short* line;
idFile* f;
char* buffer = ( char* )alloca( LINE_WIDTH + 3 );
f = fileSystem->OpenFileWrite( fileName );
if( !f )
{
common->Warning( "couldn't open %s", fileName );
return;
}
// skip empty lines
l = current - TOTAL_LINES + 1;
if( l < 0 )
{
l = 0;
}
for( ; l <= current ; l++ )
{
line = text + ( l % TOTAL_LINES ) * LINE_WIDTH;
for( x = 0; x < LINE_WIDTH; x++ )
if( ( line[x] & 0xff ) > ' ' )
{
break;
}
if( x != LINE_WIDTH )
{
break;
}
}
// write the remaining lines
for( ; l <= current; l++ )
{
line = text + ( l % TOTAL_LINES ) * LINE_WIDTH;
for( i = 0; i < LINE_WIDTH; i++ )
{
buffer[i] = line[i] & 0xff;
}
for( x = LINE_WIDTH - 1; x >= 0; x-- )
{
if( buffer[x] <= ' ' )
{
buffer[x] = 0;
}
else
{
break;
}
}
buffer[x + 1] = '\r';
buffer[x + 2] = '\n';
buffer[x + 3] = 0;
f->Write( buffer, strlen( buffer ) );
}
fileSystem->CloseFile( f );
}
/*
==============
idConsoleLocal::Resize
==============
*/
void idConsoleLocal::Resize()
{
if( renderSystem->GetVirtualWidth() == lastVirtualScreenWidth && renderSystem->GetVirtualHeight() == lastVirtualScreenHeight )
{
return;
}
lastVirtualScreenWidth = renderSystem->GetVirtualWidth();
lastVirtualScreenHeight = renderSystem->GetVirtualHeight();
LOCALSAFE_RIGHT = renderSystem->GetVirtualWidth() - LOCALSAFE_LEFT;
LOCALSAFE_BOTTOM = renderSystem->GetVirtualHeight() - LOCALSAFE_TOP;
LOCALSAFE_WIDTH = LOCALSAFE_RIGHT - LOCALSAFE_LEFT;
LOCALSAFE_HEIGHT = LOCALSAFE_BOTTOM - LOCALSAFE_TOP;
}
/*
================
idConsoleLocal::PageUp
================
*/
void idConsoleLocal::PageUp()
{
display -= 2;
if( current - display >= TOTAL_LINES )
{
display = current - TOTAL_LINES + 1;
}
}
/*
================
idConsoleLocal::PageDown
================
*/
void idConsoleLocal::PageDown()
{
display += 2;
if( display > current )
{
display = current;
}
}
/*
================
idConsoleLocal::Top
================
*/
void idConsoleLocal::Top()
{
display = 0;
}
/*
================
idConsoleLocal::Bottom
================
*/
void idConsoleLocal::Bottom()
{
display = current;
}
/*
=============================================================================
CONSOLE LINE EDITING
==============================================================================
*/
/*
====================
KeyDownEvent
Handles history and console scrollback
====================
*/
void idConsoleLocal::KeyDownEvent( int key )
{
// Execute F key bindings
if( key >= K_F1 && key <= K_F12 )
{
idKeyInput::ExecKeyBinding( key );
return;
}
// ctrl-L clears screen
if( key == K_L && ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) )
{
Clear();
return;
}
// enter finishes the line
if( key == K_ENTER || key == K_KP_ENTER )
{
common->Printf( "]%s\n", consoleField.GetBuffer() );
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, consoleField.GetBuffer() ); // valid command
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "\n" );
// copy line to history buffer
if( consoleField.GetBuffer()[ 0 ] != '\n' && consoleField.GetBuffer()[ 0 ] != '\0' )
{
consoleHistory.AddToHistory( consoleField.GetBuffer() );
}
consoleField.Clear();
consoleField.SetWidthInChars( LINE_WIDTH );
const bool captureToImage = false;
common->UpdateScreen( captureToImage );// force an update, because the command
// may take some time
return;
}
// command completion
if( key == K_TAB )
{
consoleField.AutoComplete();
return;
}
// command history (ctrl-p ctrl-n for unix style)
if( ( key == K_UPARROW ) ||
( key == K_P && ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) ) )
{
idStr hist = consoleHistory.RetrieveFromHistory( true );
if( !hist.IsEmpty() )
{
consoleField.SetBuffer( hist );
}
return;
}
if( ( key == K_DOWNARROW ) ||
( key == K_N && ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) ) )
{
idStr hist = consoleHistory.RetrieveFromHistory( false );
if( !hist.IsEmpty() )
{
consoleField.SetBuffer( hist );
}
else // DG: if no more lines are in the history, show a blank line again
{
consoleField.Clear();
} // DG end
return;
}
// console scrolling
if( key == K_PGUP )
{
PageUp();
lastKeyEvent = eventLoop->Milliseconds();
nextKeyEvent = CONSOLE_FIRSTREPEAT;
return;
}
if( key == K_PGDN )
{
PageDown();
lastKeyEvent = eventLoop->Milliseconds();
nextKeyEvent = CONSOLE_FIRSTREPEAT;
return;
}
if( key == K_MWHEELUP )
{
PageUp();
return;
}
if( key == K_MWHEELDOWN )
{
PageDown();
return;
}
// ctrl-home = top of console
if( key == K_HOME && ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) )
{
Top();
return;
}
// ctrl-end = bottom of console
if( key == K_END && ( idKeyInput::IsDown( K_LCTRL ) || idKeyInput::IsDown( K_RCTRL ) ) )
{
Bottom();
return;
}
// pass to the normal editline routine
consoleField.KeyDownEvent( key );
}
/*
==============
Scroll
deals with scrolling text because we don't have key repeat
==============
*/
void idConsoleLocal::Scroll( )
{
if( lastKeyEvent == -1 || ( lastKeyEvent + 200 ) > eventLoop->Milliseconds() )
{
return;
}
// console scrolling
if( idKeyInput::IsDown( K_PGUP ) )
{
PageUp();
nextKeyEvent = CONSOLE_REPEAT;
return;
}
if( idKeyInput::IsDown( K_PGDN ) )
{
PageDown();
nextKeyEvent = CONSOLE_REPEAT;
return;
}
}
/*
==============
SetDisplayFraction
Causes the console to start opening the desired amount.
==============
*/
void idConsoleLocal::SetDisplayFraction( float frac )
{
finalFrac = frac;
fracTime = Sys_Milliseconds();
}
/*
==============
UpdateDisplayFraction
Scrolls the console up or down based on conspeed
==============
*/
void idConsoleLocal::UpdateDisplayFraction()
{
if( con_speed.GetFloat() <= 0.1f )
{
fracTime = Sys_Milliseconds();
displayFrac = finalFrac;
return;
}
// scroll towards the destination height
if( finalFrac < displayFrac )
{
displayFrac -= con_speed.GetFloat() * ( Sys_Milliseconds() - fracTime ) * 0.001f;
if( finalFrac > displayFrac )
{
displayFrac = finalFrac;
}
fracTime = Sys_Milliseconds();
}
else if( finalFrac > displayFrac )
{
displayFrac += con_speed.GetFloat() * ( Sys_Milliseconds() - fracTime ) * 0.001f;
if( finalFrac < displayFrac )
{
displayFrac = finalFrac;
}
fracTime = Sys_Milliseconds();
}
}
/*