22
33#if IS_DWIN_MARLINUI && HAS_GAMES
44
5- #define PERFORMANCE_COUNTERS 1
5+ // Show performance counters on the screen (frame timing and draw call count)
6+ #define PERFORMANCE_COUNTERS 0
7+
8+ // Compound calls are calls that are made up of multiple subcalls (e.g. draw_hline, which is made up of a draw_box call)
9+ #define INCLUDE_COMPOUNT_CALLS 0
610
711#include " ../../menu/game/types.h" // includes e3v2/marlinui/game.h
812#include " ../../lcdprint.h"
913#include " lcdprint_dwin.h"
1014#include " marlinui_dwin.h"
1115
12- #if PERFORMANCE_COUNTERS == 1
13- static uint32_t draw_call_cnt = 0 ; // total number of draw calls in the current frame
14- static millis_t frame_draw_millis = 0 , // time spent drawing the frame
15- frame_wait_millis = 0 ; // time spent waiting for the next frame
16+ #if ENABLED( PERFORMANCE_COUNTERS)
17+ static uint32_t draw_call_cnt = 0 ; // Total number of draw calls in the current frame
18+ static millis_t frame_draw_millis = 0 , // Time spent drawing the frame
19+ frame_wait_millis = 0 ; // Time spent waiting for the next frame
1620
17- #define DRAW_CALL_INC ( subcall_cnt ) draw_call_cnt++
21+ #define COUNT_DRAW_CALL ( compound_call_count ) TERN(INCLUDE_COMPOUNT_CALLS, draw_call_cnt++, draw_call_cnt = draw_call_cnt + 1 - compound_call_count)
1822#else
19- #define DRAW_CALL_INC ( subcall_cnt )
23+ #define COUNT_DRAW_CALL ( compound_call_count )
2024#endif
2125
2226void MarlinGame::frame_start () {
23- // clear the screen before each frame
27+ // Clear the screen before each frame
2428 // dwinFrameClear(CLEAR_COLOR);
2529
26- // filling the play area should be faster than clearing the whole screen
30+ // Filling the play area is faster than clearing the whole screen
2731 const uint16_t fg = dwin_font.fg ;
2832 dwin_font.fg = COLOR_BG_BLACK;
2933 draw_box (0 , 0 , GAME_WIDTH, GAME_HEIGHT);
3034 dwin_font.fg = fg;
3135
36+ // Ensure the correct font is selected
3237 dwin_font.index = DWIN_FONT_MENU;
3338
34- // reset performance counters
35- #if PERFORMANCE_COUNTERS == 1
39+ // Reset the performance counters
40+ #if ENABLED( PERFORMANCE_COUNTERS)
3641 draw_call_cnt = 0 ;
3742 frame_draw_millis = millis ();
38- frame_wait_millis = frame_draw_millis - frame_wait_millis;
43+ frame_wait_millis = frame_draw_millis - frame_wait_millis;
3944 #endif
4045}
4146
4247void MarlinGame::frame_end () {
43- #if PERFORMANCE_COUNTERS == 1
48+ #if ENABLED( PERFORMANCE_COUNTERS)
4449 const millis_t frame_wait = frame_wait_millis;
4550 frame_wait_millis = millis ();
4651 frame_draw_millis = frame_wait_millis - frame_draw_millis;
4752
48- // calculate frames per deci-seconds (100 milliseconds)
49- const uint32_t fpds = 100 / (frame_draw_millis + frame_wait);
50-
51- // format the performance counters as a string
53+ // Format the performance counters as a string
5254 char perf_str[64 ];
5355 sprintf_P (
5456 perf_str,
55- PSTR (" d%04lu w%04lu c%04lu f%02lu " ),
57+ PSTR (" d%04lu w%04lu c%04lu " ),
5658 frame_draw_millis,
5759 frame_wait,
58- draw_call_cnt,
59- fpds
60+ draw_call_cnt
6061 );
6162
62- // draw the performance counters at the (physical) origin of the screen
63+ // Draw the performance counters at the (physical) origin of the screen
6364 const uint16_t fg = dwin_font.fg ;
6465 const bool solid = dwin_font.solid ;
65- dwin_font. fg = RGB ( 0x1F , 0x3F , 0x00 );
66+ set_color (color::YELLOW );
6667 dwin_font.solid = true ;
6768
6869 lcd_moveto_xy (0 , 0 );
@@ -107,17 +108,17 @@ void MarlinGame::set_color(const color color) {
107108}
108109
109110void MarlinGame::draw_hline (const game_dim_t x, const game_dim_t y, const game_dim_t w) {
110- // draw lines as boxes, since DWIN lines are always 1px wide but we want to scale them
111+ // Draw lines as boxes, since DWIN lines are always 1px wide but we want to scale them
111112 draw_box (x, y, w, 1 );
112113
113- DRAW_CALL_INC (1 );
114+ COUNT_DRAW_CALL (1 );
114115}
115116
116117void MarlinGame::draw_vline (const game_dim_t x, const game_dim_t y, const game_dim_t h) {
117- // draw lines as boxes, since DWIN lines are always 1px wide but we want to scale them
118+ // Draw lines as boxes, since DWIN lines are always 1px wide but we want to scale them
118119 draw_box (x, y, 1 , h);
119120
120- DRAW_CALL_INC (1 );
121+ COUNT_DRAW_CALL (1 );
121122}
122123
123124void MarlinGame::draw_frame (const game_dim_t x, const game_dim_t y, const game_dim_t w, const game_dim_t h) {
@@ -130,7 +131,7 @@ void MarlinGame::draw_frame(const game_dim_t x, const game_dim_t y, const game_d
130131 dwin_game::game_to_screen (h)
131132 );
132133
133- DRAW_CALL_INC (0 );
134+ COUNT_DRAW_CALL (0 );
134135}
135136
136137void MarlinGame::draw_box (const game_dim_t x, const game_dim_t y, const game_dim_t w, const game_dim_t h) {
@@ -143,17 +144,17 @@ void MarlinGame::draw_box(const game_dim_t x, const game_dim_t y, const game_dim
143144 dwin_game::game_to_screen (h)
144145 );
145146
146- DRAW_CALL_INC (0 );
147+ COUNT_DRAW_CALL (0 );
147148}
148149
149150void MarlinGame::draw_pixel (const game_dim_t x, const game_dim_t y) {
150- // draw pixels using boxes.
151- // while DWIN protocol supports drawing points with different sizes, the
152- // 0x02 'draw point' command is way slower per pixel than 0x05 'fill rectangle'
151+ // Draw pixels using boxes.
152+ // While DWIN protocol supports drawing points with different sizes, the
153+ // 0x02 'draw point' command is slower per pixel than 0x05 'fill rectangle'
153154 // (0.4 us vs 0.14 us per pixel)
154155 draw_box (x, y, 1 , 1 );
155156
156- DRAW_CALL_INC (1 );
157+ COUNT_DRAW_CALL (1 );
157158}
158159
159160void MarlinGame::draw_bitmap (const game_dim_t x, const game_dim_t y, const game_dim_t bytes_per_row, const game_dim_t rows, const pgm_bitmap_t bitmap) {
@@ -163,20 +164,19 @@ void MarlinGame::draw_bitmap(const game_dim_t x, const game_dim_t y, const game_
163164
164165 #if DISABLED(TJC_DISPLAY)
165166 // DWIN T5UI actually supports drawing multiple points in one go using the 0x02 'draw point' command, ever since kernel 1.2.
166- // So we use that to draw the bitmap as a series of points, which should be faster than drawing rectangles using draw_pixel.
167- // This will be somewhat slow, but way faster than drawing rectangles one by one.
167+ // So we use that to draw the bitmap as a series of points, which is faster than drawing rectangles using draw_pixel.
168168 dwinDrawPointMap (
169- dwin_font.fg , // color
170- dwin_game::game_to_screen (1 ), // point size
169+ dwin_font.fg ,
170+ dwin_game::game_to_screen (1 ),
171171 dwin_game::game_to_screen (1 ),
172- dwin_game::game_to_screen (x) + dwin_game::x_offset, // x / y
172+ dwin_game::game_to_screen (x) + dwin_game::x_offset,
173173 dwin_game::game_to_screen (y) + dwin_game::y_offset,
174- bytes_per_row, // bitmap dimensions
174+ bytes_per_row,
175175 rows,
176- bitmap // U8G bitmap format is compatible to DrawPointMap format
176+ bitmap
177177 );
178178
179- DRAW_CALL_INC (0 );
179+ COUNT_DRAW_CALL (0 );
180180 #else
181181 // TJC displays don't seem to support the 0x02 'draw point' command, so instead we have to draw the bitmap
182182 // as a series of rectangles using draw_pixel.
@@ -185,10 +185,10 @@ void MarlinGame::draw_bitmap(const game_dim_t x, const game_dim_t y, const game_
185185 for (game_dim_t col = 0 ; col < bytes_per_row; col++) {
186186 const uint8_t byte = bitmap[(row * bytes_per_row) + col];
187187 for (uint8_t bit = 0 ; bit < 8 ; bit++) {
188- // assume that the screen area is cleared before drawing
188+ // Assuming that the drawing area was cleared before drawing
189189 if (byte & (1 << bit)) {
190190 draw_pixel (x + (col * 8 ) + (7 - bit + 1 ), y + row);
191- DRAW_CALL_INC (1 );
191+ COUNT_DRAW_CALL (1 );
192192 }
193193 }
194194 }
@@ -197,7 +197,7 @@ void MarlinGame::draw_bitmap(const game_dim_t x, const game_dim_t y, const game_
197197}
198198
199199int MarlinGame::draw_string (const game_dim_t x, const game_dim_t y, const char * str) {
200- DRAW_CALL_INC (0 );
200+ COUNT_DRAW_CALL (0 );
201201
202202 lcd_moveto_xy (
203203 dwin_game::game_to_screen (x) + dwin_game::x_offset,
0 commit comments