@@ -20,6 +20,8 @@ static uint32_t ticks_fps;
20
20
static int fps ;
21
21
uint8_t fullscreen = 0 ;
22
22
23
+ static uint8_t dirty = 0 ;
24
+
23
25
// Initializes SDL and creates a renderer and required surfaces
24
26
int initialize_sdl (int init_fullscreen , int init_use_gpu ) {
25
27
ticks = SDL_GetTicks ();
@@ -55,8 +57,7 @@ int initialize_sdl(int init_fullscreen, int init_use_gpu) {
55
57
56
58
SDL_LogSetAllPriority (SDL_LOG_PRIORITY_INFO );
57
59
58
- // Uncomment this for debug level logging
59
- // SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG);
60
+ dirty = 1 ;
60
61
61
62
return 1 ;
62
63
}
@@ -73,6 +74,8 @@ void toggle_fullscreen() {
73
74
74
75
SDL_SetWindowFullscreen (win , fullscreen_state ? 0 : SDL_WINDOW_FULLSCREEN );
75
76
SDL_ShowCursor (fullscreen_state );
77
+
78
+ dirty = 1 ;
76
79
}
77
80
78
81
int draw_character (struct draw_character_command * command ) {
@@ -91,6 +94,8 @@ int draw_character(struct draw_character_command *command) {
91
94
fgcolor , bgcolor );
92
95
}
93
96
97
+ dirty = 1 ;
98
+
94
99
return 1 ;
95
100
}
96
101
@@ -115,31 +120,49 @@ void draw_rectangle(struct draw_rectangle_command *command) {
115
120
SDL_SetRenderDrawColor (rend , command -> color .r , command -> color .g ,
116
121
command -> color .b , 0xFF );
117
122
SDL_RenderFillRect (rend , & render_rect );
123
+
124
+ dirty = 1 ;
118
125
}
119
126
120
127
void draw_waveform (struct draw_oscilloscope_waveform_command * command ) {
121
128
122
- const SDL_Rect wf_rect = { 0 , 0 , 320 , 21 } ;
129
+ static uint8_t wfm_cleared = 0 ;
123
130
124
- SDL_SetRenderDrawColor (rend , background_color .r , background_color .g ,
125
- background_color .b , background_color .a );
126
- SDL_RenderFillRect (rend , & wf_rect );
131
+ // If the waveform is not being displayed and it's already been cleared, skip rendering it
132
+ if (! (wfm_cleared && command -> waveform_size == 0 )) {
127
133
128
- SDL_SetRenderDrawColor (rend , command -> color .r , command -> color .g ,
129
- command -> color .b , 255 );
134
+ const SDL_Rect wf_rect = {0 , 0 , 320 , 21 };
130
135
131
- // Create a SDL_Point array of the waveform pixels for batch drawing
132
- SDL_Point waveform_points [command -> waveform_size ];
136
+ SDL_SetRenderDrawColor (rend , background_color .r , background_color .g ,
137
+ background_color .b , background_color .a );
138
+ SDL_RenderFillRect (rend , & wf_rect );
133
139
134
- for (int i = 0 ; i < command -> waveform_size ; i ++ ) {
135
- // Limit value because the oscilloscope commands seem to glitch occasionally
136
- if (command -> waveform [i ] > 20 )
137
- command -> waveform [i ] = 20 ;
138
- waveform_points [i ].x = i ;
139
- waveform_points [i ].y = command -> waveform [i ];
140
- }
140
+ SDL_SetRenderDrawColor (rend , command -> color .r , command -> color .g ,
141
+ command -> color .b , 255 );
141
142
142
- SDL_RenderDrawPoints (rend , waveform_points , command -> waveform_size );
143
+ // Create a SDL_Point array of the waveform pixels for batch drawing
144
+ SDL_Point waveform_points [command -> waveform_size ];
145
+
146
+ for (int i = 0 ; i < command -> waveform_size ; i ++ ) {
147
+ // Limit value because the oscilloscope commands seem to glitch occasionally
148
+ if (command -> waveform [i ] > 20 )
149
+ command -> waveform [i ] = 20 ;
150
+ waveform_points [i ].x = i ;
151
+ waveform_points [i ].y = command -> waveform [i ];
152
+ }
153
+
154
+ SDL_RenderDrawPoints (rend , waveform_points , command -> waveform_size );
155
+
156
+ // The packet we just drew was an empty waveform
157
+ if (command -> waveform_size == 0 ) {
158
+ wfm_cleared = 1 ;
159
+ }
160
+ else {
161
+ wfm_cleared = 0 ;
162
+ }
163
+
164
+ dirty = 1 ;
165
+ }
143
166
}
144
167
145
168
void display_keyjazz_overlay (uint8_t show , uint8_t base_octave ) {
@@ -175,10 +198,13 @@ void display_keyjazz_overlay(uint8_t show, uint8_t base_octave) {
175
198
176
199
draw_rectangle (& drc );
177
200
}
201
+
202
+ dirty = 1 ;
178
203
}
179
204
180
205
void render_screen () {
181
- if (SDL_GetTicks () - ticks > 14 ) {
206
+ if (dirty && (SDL_GetTicks () - ticks > 14 )) {
207
+ dirty = 0 ;
182
208
ticks = SDL_GetTicks ();
183
209
SDL_SetRenderTarget (rend , NULL );
184
210
SDL_SetRenderDrawColor (rend , 0 , 0 , 0 , 0 );
0 commit comments