Skip to content

Commit 94b0495

Browse files
committed
Fixed Timing Issues
1 parent 96d19ce commit 94b0495

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"stdexcept": "cpp",
6666
"streambuf": "cpp",
6767
"cinttypes": "cpp",
68-
"typeinfo": "cpp"
68+
"typeinfo": "cpp",
69+
"list": "cpp"
6970
}
7071
}

src/displayapp/screens/Adder.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ void Adder::InitializeGame() {
4141
AdderDelayInterval, LV_TASK_PRIO_MID, this);
4242

4343
appReady = false;
44-
vTaskDelay(5);
45-
UpdateScore(0);
44+
vTaskDelay(20);
4645
}
4746

4847
void Adder::Cleanup() {
@@ -87,7 +86,7 @@ void Adder::ResetGame() {
8786
GameOver();
8887
appReady = false;
8988
highScore = std::max(highScore, static_cast<unsigned int>(adderBody.size() - 2));
90-
89+
data.HighScore=highScore;
9190
SaveGame();
9291

9392
CreateLevel();
@@ -213,11 +212,16 @@ void Adder::Refresh() {
213212
if (!appReady) {
214213
FullRedraw();
215214
CreateFood();
215+
vTaskDelay(1); //Required to let the OS draw the tile completely
216+
UpdateScore(0);
217+
vTaskDelay(1); //Required to let the OS draw the tile completely
216218
appReady = true;
217219
} else {
218220
UpdatePosition();
219221
UpdateSingleTile(adderBody.front() % fieldWidth, adderBody.front() / fieldWidth, LV_COLOR_YELLOW);
222+
vTaskDelay(1); //Required to let the OS draw the tile completely
220223
UpdateSingleTile(adderBody.back() % fieldWidth, adderBody.back() / fieldWidth, LV_COLOR_BLACK);
224+
vTaskDelay(1); //Required to let the OS draw the tile completely
221225
}
222226
}
223227

@@ -240,6 +244,7 @@ void Adder::FullRedraw() {
240244
break;
241245
}
242246
UpdateSingleTile(x, y, color);
247+
vTaskDelay(1); //Required to let the OS draw the tile completely
243248
}
244249
}
245250
}
@@ -267,7 +272,7 @@ void Adder::GameOver() {
267272
for (unsigned int i = 0; i < 4; i++) {
268273
for (unsigned int j = 0; j < 64; j++) {
269274
// Map font bits into the display buffer
270-
digitBuffer[63 - j] = (DigitFont[digits[i]][j / 8] & (1 << (j % 8))) ? LV_COLOR_WHITE : LV_COLOR_BLACK;
275+
digitBuffer[63 - j] = (DigitFont[digits[i]][j / 8] & 1 << j % 8) ? LV_COLOR_WHITE : LV_COLOR_BLACK; // Bitmagic to rotate the Digits to look like Letters
271276
}
272277

273278
lv_area_t area;
@@ -278,6 +283,7 @@ void Adder::GameOver() {
278283

279284
lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::None);
280285
lvgl.FlushDisplay(&area, digitBuffer);
286+
vTaskDelay(1); //Required to let the OS draw the tile completely
281287
}
282288
}
283289
}
@@ -301,7 +307,7 @@ void Adder::UpdateScore(unsigned int score) {
301307

302308
lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::None);
303309
lvgl.FlushDisplay(&area, digitBuffer);
304-
vTaskDelay(1); // Small delay to allow display refresh
310+
vTaskDelay(20); // Small delay to allow display refresh
305311
}
306312

307313
// Update the high score if necessary
@@ -328,7 +334,7 @@ void Adder::UpdateScore(unsigned int score) {
328334

329335
lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::None);
330336
lvgl.FlushDisplay(&area, digitBuffer);
331-
vTaskDelay(1); // Small delay to allow display refresh
337+
vTaskDelay(20); // Small delay to allow display refresh
332338
}
333339

334340
// Save the high score if it has changed

src/displayapp/screens/Adder.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include "displayapp/apps/Apps.h"
44
#include "displayapp/Controllers.h"
55
#include "displayapp/screens/Screen.h"
6-
#include "components/fs/FS.h"
76
#include <lvgl/lvgl.h>
7+
#include "components/fs/FS.h"
88
#include <list>
99
#include <vector>
1010

@@ -42,8 +42,9 @@ namespace Pinetime {
4242
static constexpr unsigned int TileSize = 9;
4343
static constexpr unsigned int AdderDelayInterval = 200;
4444

45-
Controllers::FS& filesystem;
45+
4646
Pinetime::Components::LittleVgl& lvgl;
47+
Controllers::FS& filesystem;
4748

4849
AdderSave data; // Game save data
4950
AdderField* field{nullptr};

0 commit comments

Comments
 (0)