Skip to content

Commit 4f43fde

Browse files
committed
revert part
1 parent f147cc7 commit 4f43fde

File tree

11 files changed

+37
-304
lines changed

11 files changed

+37
-304
lines changed

base_pack/air_arkanoid/engine/canvas.c

-35
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,4 @@ size_t canvas_printf_width(Canvas* canvas, const char* format, ...) {
2525
furi_string_free(string);
2626

2727
return size;
28-
}
29-
30-
void canvas_printf_aligned(
31-
Canvas* canvas,
32-
uint8_t x,
33-
uint8_t y,
34-
Align h,
35-
Align v,
36-
const char* format,
37-
...) {
38-
FuriString* string = furi_string_alloc();
39-
va_list args;
40-
va_start(args, format);
41-
furi_string_vprintf(string, format, args);
42-
va_end(args);
43-
44-
canvas_draw_str_aligned(canvas, x, y, h, v, furi_string_get_cstr(string));
45-
46-
furi_string_free(string);
47-
}
48-
49-
void canvas_draw_str_aligned_outline(
50-
Canvas* canvas,
51-
uint8_t x,
52-
uint8_t y,
53-
Align h,
54-
Align v,
55-
const char* cstr) {
56-
canvas_invert_color(canvas);
57-
canvas_draw_str_aligned(canvas, x + 1, y + 0, h, v, cstr);
58-
canvas_draw_str_aligned(canvas, x - 1, y - 0, h, v, cstr);
59-
canvas_draw_str_aligned(canvas, x + 0, y + 1, h, v, cstr);
60-
canvas_draw_str_aligned(canvas, x - 0, y - 1, h, v, cstr);
61-
canvas_invert_color(canvas);
62-
canvas_draw_str_aligned(canvas, x, y, h, v, cstr);
6328
}

base_pack/air_arkanoid/engine/canvas.h

+2-42
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ extern "C" {
1515
* @param format format string
1616
* @param ... arguments
1717
*/
18-
void canvas_printf(Canvas* canvas, uint8_t x, uint8_t y, const char* format, ...)
19-
__attribute__((__format__(__printf__, 4, 5)));
18+
void canvas_printf(Canvas* canvas, uint8_t x, uint8_t y, const char* format, ...);
2019

2120
/**
2221
* @brief Get width of formatted string
@@ -26,46 +25,7 @@ void canvas_printf(Canvas* canvas, uint8_t x, uint8_t y, const char* format, ...
2625
* @param ... arguments
2726
* @return size_t width of formatted string
2827
*/
29-
size_t canvas_printf_width(Canvas* canvas, const char* format, ...)
30-
__attribute__((__format__(__printf__, 2, 3)));
31-
32-
/**
33-
* @brief Print formatted string to canvas with alignment
34-
*
35-
* @param canvas canvas instance
36-
* @param x x position
37-
* @param y y position
38-
* @param h horizontal alignment
39-
* @param v vertical alignment
40-
* @param format format string
41-
* @param ... arguments
42-
*/
43-
void canvas_printf_aligned(
44-
Canvas* canvas,
45-
uint8_t x,
46-
uint8_t y,
47-
Align h,
48-
Align v,
49-
const char* format,
50-
...) __attribute__((__format__(__printf__, 6, 7)));
51-
52-
/**
53-
* @brief Draw aligned string with outline
54-
*
55-
* @param canvas
56-
* @param x
57-
* @param y
58-
* @param h
59-
* @param v
60-
* @param cstr
61-
*/
62-
void canvas_draw_str_aligned_outline(
63-
Canvas* canvas,
64-
uint8_t x,
65-
uint8_t y,
66-
Align h,
67-
Align v,
68-
const char* cstr);
28+
size_t canvas_printf_width(Canvas* canvas, const char* format, ...);
6929

7030
#ifdef __cplusplus
7131
}

base_pack/air_arkanoid/engine/entity.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "entity_i.h"
33
#include <stdlib.h>
44
#include <furi.h>
5-
#include <math.h>
65

76
#ifdef ENTITY_DEBUG
87
#define ENTITY_D(...) FURI_LOG_D("Entity", __VA_ARGS__)
@@ -135,8 +134,10 @@ bool entity_collider_circle_circle(Entity* entity, Entity* other) {
135134
Vector pos1 = entity_collider_position_get(entity);
136135
Vector pos2 = entity_collider_position_get(other);
137136

138-
Vector delta = vector_sub(pos1, pos2);
139-
return vector_length(delta) < entity->collider->circle.radius + other->collider->circle.radius;
137+
float dx = pos1.x - pos2.x;
138+
float dy = pos1.y - pos2.y;
139+
float distance = sqrtf(dx * dx + dy * dy);
140+
return distance < entity->collider->circle.radius + other->collider->circle.radius;
140141
}
141142

142143
bool entity_collider_rect_rect(Entity* entity, Entity* other) {

base_pack/air_arkanoid/engine/game_engine.c

+8-30
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
#include "game_engine.h"
22
#include <furi.h>
3-
#include <furi_hal_rtc.h>
43
#include <gui/gui.h>
54
#include <input/input.h>
65
#include <notification/notification_messages.h>
76
#include "clock_timer.h"
87

98
typedef _Atomic uint32_t AtomicUint32;
109

11-
typedef struct {
12-
bool lefty;
13-
AtomicUint32 state;
14-
} InputHolder;
15-
1610
GameEngineSettings game_engine_settings_init() {
1711
GameEngineSettings settings;
1812
settings.target_fps = 30.0f;
@@ -67,7 +61,7 @@ static void clock_timer_callback(void* context) {
6761
furi_thread_flags_set(engine->thread_id, GameThreadFlagUpdate);
6862
}
6963

70-
static const GameKey keys_right_hand[] = {
64+
static const GameKey keys[] = {
7165
[InputKeyUp] = GameKeyUp,
7266
[InputKeyDown] = GameKeyDown,
7367
[InputKeyRight] = GameKeyRight,
@@ -76,32 +70,19 @@ static const GameKey keys_right_hand[] = {
7670
[InputKeyBack] = GameKeyBack,
7771
};
7872

79-
static const GameKey keys_left_hand[] = {
80-
[InputKeyUp] = GameKeyDown,
81-
[InputKeyDown] = GameKeyUp,
82-
[InputKeyRight] = GameKeyLeft,
83-
[InputKeyLeft] = GameKeyRight,
84-
[InputKeyOk] = GameKeyOk,
85-
[InputKeyBack] = GameKeyBack,
86-
};
87-
static_assert(
88-
sizeof(keys_right_hand) == sizeof(keys_left_hand),
89-
"keys_right_hand and keys_left_hand do not match!");
90-
91-
static const size_t keys_count = sizeof(keys_right_hand) / sizeof(keys_right_hand[0]);
73+
static const size_t keys_count = sizeof(keys) / sizeof(keys[0]);
9274

9375
static void input_events_callback(const void* value, void* context) {
94-
InputHolder* holder = context;
76+
AtomicUint32* input_state = context;
9577
const InputEvent* event = value;
96-
const GameKey* keys = holder->lefty ? keys_left_hand : keys_right_hand;
9778

9879
if(event->key < keys_count) {
9980
switch(event->type) {
10081
case InputTypePress:
101-
holder->state |= (keys[event->key]);
82+
*input_state |= (keys[event->key]);
10283
break;
10384
case InputTypeRelease:
104-
holder->state &= ~(keys[event->key]);
85+
*input_state &= ~(keys[event->key]);
10586
break;
10687
default:
10788
break;
@@ -111,10 +92,7 @@ static void input_events_callback(const void* value, void* context) {
11192

11293
void game_engine_run(GameEngine* engine) {
11394
// input state
114-
InputHolder input_state = {
115-
.lefty = furi_hal_rtc_is_flag_set(FuriHalRtcFlagHandOrient),
116-
.state = 0,
117-
};
95+
AtomicUint32 input_state = 0;
11896
uint32_t input_prev_state = 0;
11997

12098
// set backlight if needed
@@ -152,7 +130,7 @@ void game_engine_run(GameEngine* engine) {
152130
time_start = time_end;
153131

154132
// update input state
155-
uint32_t input_current_state = input_state.state;
133+
uint32_t input_current_state = input_state;
156134
InputState input = {
157135
.held = input_current_state,
158136
.pressed = input_current_state & ~input_prev_state,
@@ -172,7 +150,7 @@ void game_engine_run(GameEngine* engine) {
172150
// show fps if needed
173151
if(engine->settings.show_fps) {
174152
canvas_set_color(canvas, ColorXOR);
175-
canvas_printf(canvas, 0, 7, "%lu", (uint32_t)roundf(engine->fps));
153+
canvas_printf(canvas, 0, 7, "%u", (uint32_t)roundf(engine->fps));
176154
}
177155

178156
// and output screen buffer

base_pack/air_arkanoid/engine/game_manager.c

-12
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,4 @@ Sprite* game_manager_sprite_load(GameManager* manager, const char* path) {
159159
furi_string_free(path_full);
160160

161161
return sprite;
162-
}
163-
164-
Level* game_manager_entity_level_get(GameManager* manager, Entity* entity) {
165-
LevelList_it_t it;
166-
LevelList_it(it, manager->levels);
167-
while(!LevelList_end_p(it)) {
168-
if(level_contains_entity(*LevelList_cref(it), entity)) {
169-
return *LevelList_cref(it);
170-
}
171-
LevelList_next(it);
172-
}
173-
return NULL;
174162
}

base_pack/air_arkanoid/engine/game_manager.h

-19
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,8 @@ Level* game_manager_add_level(GameManager* manager, const LevelBehaviour* behavi
1313

1414
void game_manager_next_level_set(GameManager* manager, Level* level);
1515

16-
/**
17-
* @brief Get the current level
18-
* @warning This function returns current level, but in entity start or stop callbacks, the level may be different from entity's level.
19-
* For example, if an entity is added to a level_game and you currently are in level_pause, this function will return level_pause.
20-
* Use game_manager_entity_level_get to get the entity's level, or save the level pointer somewhere.
21-
*
22-
* @param manager game manager instance
23-
* @return Level* level instance
24-
*/
2516
Level* game_manager_current_level_get(GameManager* manager);
2617

27-
/**
28-
* @brief Get the level of an entity
29-
* @warning This function is kinda slow, use it only when other methods are not possible
30-
*
31-
* @param manager
32-
* @param entity
33-
* @return Level*
34-
*/
35-
Level* game_manager_entity_level_get(GameManager* manager, Entity* entity);
36-
3718
GameEngine* game_manager_engine_get(GameManager* manager);
3819

3920
InputState game_manager_input_get(GameManager* manager);

0 commit comments

Comments
 (0)