Skip to content

Commit 8f7c749

Browse files
committed
different implementation was added to reduce lag on some firmwares
1 parent b75f0d7 commit 8f7c749

File tree

2 files changed

+63
-52
lines changed

2 files changed

+63
-52
lines changed

defines.h

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ typedef struct {
4949
InputKey input;
5050

5151
bool started;
52+
bool had_change;
5253
bool processing;
5354
bool longPress;
5455
PlayState state;

solitaire.c

+62-52
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <notification/notification.h>
99
#include <notification/notification_messages.h>
1010
void init(GameState *game_state);
11+
1112
const NotificationSequence sequence_fail = {
1213
&message_vibro_on,
1314
&message_note_c4,
@@ -47,62 +48,69 @@ bool can_place_card(Card where, Card what) {
4748
}
4849

4950
static void draw_scene(Canvas *const canvas, const GameState *game_state) {
50-
int deckIndex = game_state->deck.index;
51-
if (game_state->dragging_deck)
52-
deckIndex--;
53-
54-
if ((game_state->deck.index < (game_state->deck.card_count - 1) || game_state->deck.index == -1) && game_state->deck.card_count>0) {
55-
draw_card_back_at(columns[0][0], columns[0][1], canvas);
56-
if (game_state->selectRow == 0 && game_state->selectColumn == 0) {
57-
draw_rounded_box(canvas, columns[0][0] + 1, columns[0][1] + 1, CARD_WIDTH - 2, CARD_HEIGHT - 2,
58-
Inverse);
59-
}
60-
} else
61-
draw_card_space(columns[0][0], columns[0][1],
62-
game_state->selectRow == 0 && game_state->selectColumn == 0,
63-
canvas);
64-
//deck side
65-
if (deckIndex >= 0) {
66-
Card c = game_state->deck.cards[deckIndex];
67-
draw_card_at_colored(columns[1][0], columns[1][1], c.pip, c.character,
68-
game_state->selectRow == 0 && game_state->selectColumn == 1, canvas);
69-
} else
70-
draw_card_space(columns[1][0], columns[1][1],
71-
game_state->selectRow == 0 && game_state->selectColumn == 1,
72-
canvas);
7351

74-
for (uint8_t i = 0; i < 4; i++) {
75-
Card current = game_state->top_cards[i];
76-
bool selected = game_state->selectRow == 0 && game_state->selectColumn == (i + 3);
77-
if (current.disabled) {
78-
draw_card_space(columns[i + 3][0], columns[i + 3][1], selected, canvas);
79-
} else {
80-
draw_card_at(columns[i + 3][0], columns[i + 3][1], current.pip, current.character, canvas);
81-
if (selected) {
82-
draw_rounded_box(canvas, columns[i + 3][0], columns[i + 3][1], CARD_WIDTH, CARD_HEIGHT,
52+
if(game_state->had_change){
53+
int deckIndex = game_state->deck.index;
54+
if (game_state->dragging_deck)
55+
deckIndex--;
56+
57+
if ((game_state->deck.index < (game_state->deck.card_count - 1) || game_state->deck.index == -1) && game_state->deck.card_count>0) {
58+
draw_card_back_at(columns[0][0], columns[0][1], canvas);
59+
if (game_state->selectRow == 0 && game_state->selectColumn == 0) {
60+
draw_rounded_box(canvas, columns[0][0] + 1, columns[0][1] + 1, CARD_WIDTH - 2, CARD_HEIGHT - 2,
8361
Inverse);
8462
}
63+
} else
64+
draw_card_space(columns[0][0], columns[0][1],
65+
game_state->selectRow == 0 && game_state->selectColumn == 0,
66+
canvas);
67+
//deck side
68+
if (deckIndex >= 0) {
69+
Card c = game_state->deck.cards[deckIndex];
70+
draw_card_at_colored(columns[1][0], columns[1][1], c.pip, c.character,
71+
game_state->selectRow == 0 && game_state->selectColumn == 1, canvas);
72+
} else
73+
draw_card_space(columns[1][0], columns[1][1],
74+
game_state->selectRow == 0 && game_state->selectColumn == 1,
75+
canvas);
76+
77+
for (uint8_t i = 0; i < 4; i++) {
78+
Card current = game_state->top_cards[i];
79+
bool selected = game_state->selectRow == 0 && game_state->selectColumn == (i + 3);
80+
if (current.disabled) {
81+
draw_card_space(columns[i + 3][0], columns[i + 3][1], selected, canvas);
82+
} else {
83+
draw_card_at(columns[i + 3][0], columns[i + 3][1], current.pip, current.character, canvas);
84+
if (selected) {
85+
draw_rounded_box(canvas, columns[i + 3][0], columns[i + 3][1], CARD_WIDTH, CARD_HEIGHT,
86+
Inverse);
87+
}
88+
}
8589
}
86-
}
8790

88-
for (uint8_t i = 0; i < 7; i++) {
89-
bool selected = game_state->selectRow == 1 && game_state->selectColumn == i;
90-
int8_t index= (game_state->bottom_columns[i].index - 1 - game_state->selected_card);
91-
if(index<0)index=0;
92-
draw_hand_column(game_state->bottom_columns[i], columns[i][0], columns[i][2],
93-
selected ? index : -1, canvas);
94-
}
91+
for (uint8_t i = 0; i < 7; i++) {
92+
bool selected = game_state->selectRow == 1 && game_state->selectColumn == i;
93+
int8_t index= (game_state->bottom_columns[i].index - 1 - game_state->selected_card);
94+
if(index<0)index=0;
95+
draw_hand_column(game_state->bottom_columns[i], columns[i][0], columns[i][2],
96+
selected ? index : -1, canvas);
97+
}
98+
99+
int8_t pos[2] = {columns[game_state->selectColumn][0],
100+
columns[game_state->selectColumn][game_state->selectRow + 1]};
95101

96-
int8_t pos[2] = {columns[game_state->selectColumn][0],
97-
columns[game_state->selectColumn][game_state->selectRow + 1]};
102+
/* draw_icon_clip(canvas, &I_card_graphics, pos[0] + CARD_HALF_WIDTH, pos[1] + CARD_HALF_HEIGHT, 30, 5, 5, 5,
103+
Filled);*/
98104

99-
/* draw_icon_clip(canvas, &I_card_graphics, pos[0] + CARD_HALF_WIDTH, pos[1] + CARD_HALF_HEIGHT, 30, 5, 5, 5,
100-
Filled);*/
105+
if (game_state->dragging_hand.index > 0) {
106+
draw_hand_column(game_state->dragging_hand,
107+
pos[0] + CARD_HALF_WIDTH + 3, pos[1] + CARD_HALF_HEIGHT + 3,
108+
-1, canvas);
109+
}
101110

102-
if (game_state->dragging_hand.index > 0) {
103-
draw_hand_column(game_state->dragging_hand,
104-
pos[0] + CARD_HALF_WIDTH + 3, pos[1] + CARD_HALF_HEIGHT + 3,
105-
-1, canvas);
111+
clone_buffer(get_buffer(canvas), game_state->animation.buffer);
112+
}else{
113+
clone_buffer(game_state->animation.buffer, get_buffer(canvas));
106114
}
107115
}
108116

@@ -247,6 +255,7 @@ void tick(GameState *game_state, NotificationApp *notification) {
247255
if (game_state->top_cards[0].character == 11 && game_state->top_cards[1].character == 11 &&
248256
game_state->top_cards[2].character == 11 && game_state->top_cards[3].character == 11) {
249257
game_state->state = GameStateAnimate;
258+
game_state->had_change=true;
250259
dolphin_deed(DolphinDeedPluginGameWin);
251260

252261
return;
@@ -473,9 +482,10 @@ int32_t solitaire_app(void *p) {
473482
for (bool processing = true; processing;) {
474483
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 150);
475484
furi_mutex_acquire(game_state->mutex, FuriWaitForever);
476-
bool hadChange = false;
485+
game_state->had_change = false;
477486
if (event_status == FuriStatusOk) {
478487
if (event.type == EventTypeKey) {
488+
game_state->had_change = true;
479489
if (event.input.type == InputTypeLong) {
480490
game_state->longPress = true;
481491
switch (event.input.key) {
@@ -505,7 +515,6 @@ int32_t solitaire_app(void *p) {
505515
init(game_state);
506516
}
507517
else {
508-
hadChange = true;
509518
game_state->input = event.input.key;
510519
}
511520
break;
@@ -527,8 +536,8 @@ int32_t solitaire_app(void *p) {
527536
FURI_LOG_W(APP_NAME, "osMessageQueue: event timeout");
528537
// event timeout
529538
}
530-
if (hadChange || game_state->state == GameStateAnimate)
531-
view_port_update(view_port);
539+
540+
view_port_update(view_port);
532541
furi_mutex_release(game_state->mutex);
533542
}
534543

@@ -551,5 +560,6 @@ int32_t solitaire_app(void *p) {
551560
free(game_state->deck.cards);
552561
free(game_state);
553562
furi_message_queue_free(event_queue);
563+
554564
return return_code;
555565
}

0 commit comments

Comments
 (0)