Debian Codegraph @

prboom2/src/dsda/render_stats.c

raw
1 //
2 // Copyright(C) 2022 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Render Stats
16 //
17
18 #include "dsda/time.h"
19 #include "dsda/utility.h"
20
21 #include "render_stats.h"
22
23 static dsda_render_stats_t frame_stats;
24 static dsda_render_stats_t interval_stats;
25 static int frame_count;
26
27 dsda_render_stats_t dsda_render_stats;
28 dsda_render_stats_t dsda_render_stats_max;
29 int dsda_render_stats_fps = 35;
30
31 static void dsda_UpdateMaxValues(dsda_render_stats_t* x, dsda_render_stats_t* y) {
32 if (x->visplanes < y->visplanes)
33 x->visplanes = y->visplanes;
34
35 if (x->drawsegs < y->drawsegs)
36 x->drawsegs = y->drawsegs;
37
38 if (x->vissprites < y->vissprites)
39 x->vissprites = y->vissprites;
40 }
41
42 void dsda_BeginRenderStats(void) {
43 ZERO_DATA(frame_stats);
44 ZERO_DATA(interval_stats);
45 ZERO_DATA(dsda_render_stats);
46 ZERO_DATA(dsda_render_stats_max);
47
48 dsda_StartTimer(dsda_timer_render_stats);
49 }
50
51 void dsda_RecordVisSprite(void) {
52 ++frame_stats.vissprites;
53 }
54
55 void dsda_RecordVisSprites(int n) {
56 frame_stats.vissprites += n;
57 }
58
59 void dsda_RecordVisPlane(void) {
60 ++frame_stats.visplanes;
61 }
62
63 void dsda_RecordVisPlanes(int n) {
64 frame_stats.visplanes += n;
65 }
66
67 void dsda_RecordDrawSeg(void) {
68 ++frame_stats.drawsegs;
69 }
70
71 void dsda_RecordDrawSegs(int n) {
72 frame_stats.drawsegs += n;
73 }
74
75 void dsda_UpdateRenderStats(void) {
76 dsda_UpdateMaxValues(&interval_stats, &frame_stats);
77
78 ++frame_count;
79 ZERO_DATA(frame_stats);
80
81 if (dsda_ElapsedTimeMS(dsda_timer_render_stats) >= 1000) {
82 dsda_render_stats = interval_stats;
83 ZERO_DATA(interval_stats);
84 dsda_UpdateMaxValues(&dsda_render_stats_max, &dsda_render_stats);
85 dsda_render_stats_fps = frame_count * 1000 / dsda_ElapsedTimeMS(dsda_timer_render_stats);
86 frame_count = 0;
87 dsda_StartTimer(dsda_timer_render_stats);
88 }
89 }