Compare commits
2 Commits
76e3d2435e
...
fix-refres
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e406a06f61 | ||
|
|
034867d2a7 |
@@ -88,7 +88,7 @@ void core1_entry() {
|
|||||||
while (1) {
|
while (1) {
|
||||||
// Wait for refresh request
|
// Wait for refresh request
|
||||||
if (refresh_requested && refresh_buffer && refresh_display) {
|
if (refresh_requested && refresh_buffer && refresh_display) {
|
||||||
refresh_in_progress = true;
|
// refresh_in_progress is already set by Core 0 to lock the buffer
|
||||||
|
|
||||||
// Get local copies for safe access
|
// Get local copies for safe access
|
||||||
LowLevelDisplay* display = refresh_display;
|
LowLevelDisplay* display = refresh_display;
|
||||||
@@ -100,7 +100,7 @@ void core1_entry() {
|
|||||||
|
|
||||||
// Clear flags
|
// Clear flags
|
||||||
refresh_requested = false;
|
refresh_requested = false;
|
||||||
refresh_in_progress = false;
|
refresh_in_progress = false; // Unlock buffer for Core 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Small delay to avoid busy-waiting
|
// Small delay to avoid busy-waiting
|
||||||
@@ -124,6 +124,10 @@ bool refresh_screen_async(const uint8_t *buffer, LowLevelDisplay* display) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lock the buffer immediately on Core 0 to prevent race condition
|
||||||
|
// Core 1 will unlock it (set to false) when done
|
||||||
|
refresh_in_progress = true;
|
||||||
|
|
||||||
// Queue refresh on Core 1
|
// Queue refresh on Core 1
|
||||||
refresh_buffer = buffer;
|
refresh_buffer = buffer;
|
||||||
refresh_display = display;
|
refresh_display = display;
|
||||||
|
|||||||
@@ -110,12 +110,12 @@ function draw()
|
|||||||
|
|
||||||
-- Draw: MENU
|
-- Draw: MENU
|
||||||
if state == STATE_MENU then
|
if state == STATE_MENU then
|
||||||
renderer.text_scaled(game.width(, 2) / 2 - 30, game.height() / 2 - 20, "SNAKE", true)
|
renderer.text(game.width() / 2 - 30, game.height() / 2 - 20, "SNAKE", true)
|
||||||
renderer.text_scaled(game.width(, 2) / 2 - 50, game.height() / 2, "Tap to Start", true)
|
renderer.text(game.width() / 2 - 50, game.height() / 2, "Tap to Start", true)
|
||||||
|
|
||||||
if game.vars.high_score > 0 then
|
if game.vars.high_score > 0 then
|
||||||
local hs_text = "High: " .. tostring(game.vars.high_score)
|
local hs_text = "High: " .. tostring(game.vars.high_score)
|
||||||
renderer.text_scaled(game.width(, 2) / 2 - 30, game.height() / 2 + 20, hs_text, true)
|
renderer.text(game.width() / 2 - 30, game.height() / 2 + 20, hs_text, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Draw: PLAYING
|
-- Draw: PLAYING
|
||||||
@@ -134,16 +134,16 @@ function draw()
|
|||||||
|
|
||||||
-- Draw score
|
-- Draw score
|
||||||
local score_text = "Score: " .. tostring(game.vars.score)
|
local score_text = "Score: " .. tostring(game.vars.score)
|
||||||
renderer.text_scaled(5, 5, score_text, true, 2)
|
renderer.text(5, 5, score_text, true)
|
||||||
|
|
||||||
-- Draw: GAME_OVER
|
-- Draw: GAME_OVER
|
||||||
elseif state == STATE_GAME_OVER then
|
elseif state == STATE_GAME_OVER then
|
||||||
renderer.text_scaled(game.width(, 2) / 2 - 40, game.height() / 2 - 20, "GAME OVER", true)
|
renderer.text(game.width() / 2 - 40, game.height() / 2 - 20, "GAME OVER", true)
|
||||||
|
|
||||||
local score_text = "Score: " .. tostring(game.vars.score)
|
local score_text = "Score: " .. tostring(game.vars.score)
|
||||||
renderer.text_scaled(game.width(, 2) / 2 - 40, game.height() / 2, score_text, true)
|
renderer.text(game.width() / 2 - 40, game.height() / 2, score_text, true)
|
||||||
|
|
||||||
renderer.text_scaled(game.width(, 2) / 2 - 60, game.height() / 2 + 20, "Tap to Continue", true)
|
renderer.text(game.width() / 2 - 60, game.height() / 2 + 20, "Tap to Continue", true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user