From 51d726c2d77a71fc305245867a13903a959cc540 Mon Sep 17 00:00:00 2001 From: its your bedtime <23366927+itsyourbedtime@users.noreply.github.com> Date: Mon, 26 Apr 2021 15:19:14 +0300 Subject: [PATCH] [FL-1149] Dolphin: stage 3 (#422) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * dolphin scenes refactoring & restructuring phase 1 * Passport app: mood and level display, opens from main menu and dolphin scenes. Dolphin scenes: minor refactoring (WIP) * dolphin scene app restruct * use gui defines for screen size * mv passport to dolphin dir Co-authored-by: あく --- applications/app-loader/app-loader.c | 6 +- applications/applications.c | 13 +--- applications/applications.h | 2 +- applications/applications.mk | 16 +--- applications/dolphin/dolphin.c | 2 +- applications/dolphin/dolphin_state.c | 32 -------- applications/dolphin/dolphin_state.h | 32 ++++++++ .../{ => dolphin}/passport/passport.c | 45 ++++++----- .../scenes/assets/emotes.h} | 0 .../scenes/assets}/items.c | 18 ++++- applications/dolphin/scenes/assets/items.h | 8 ++ .../scenes/assets}/items_i.h | 2 +- .../engine.c => dolphin/scenes/scene.c} | 39 ++++++++-- .../scenes/scene.h} | 12 +-- .../scenes/scene_controls.c} | 42 +--------- .../scenes/scene_dolphin_state.c} | 31 ++++---- .../scene.c => dolphin/scenes/scene_gfx.c} | 77 ++++++++++++------- applications/dolphin_scene/dolphin_scene.c | 31 -------- applications/dolphin_scene/items.h | 5 -- 19 files changed, 199 insertions(+), 214 deletions(-) rename applications/{ => dolphin}/passport/passport.c (70%) rename applications/{dolphin_scene/dolphin_emotes.h => dolphin/scenes/assets/emotes.h} (100%) rename applications/{dolphin_scene => dolphin/scenes/assets}/items.c (89%) create mode 100644 applications/dolphin/scenes/assets/items.h rename applications/{dolphin_scene => dolphin/scenes/assets}/items_i.h (88%) rename applications/{dolphin_scene/engine.c => dolphin/scenes/scene.c} (75%) rename applications/{dolphin_scene/dolphin_scene.h => dolphin/scenes/scene.h} (91%) rename applications/{dolphin_scene/user.c => dolphin/scenes/scene_controls.c} (60%) rename applications/{dolphin_scene/state.c => dolphin/scenes/scene_dolphin_state.c} (78%) rename applications/{dolphin_scene/scene.c => dolphin/scenes/scene_gfx.c} (66%) delete mode 100644 applications/dolphin_scene/dolphin_scene.c delete mode 100644 applications/dolphin_scene/items.h diff --git a/applications/app-loader/app-loader.c b/applications/app-loader/app-loader.c index 8332dc13..5b3b9d61 100644 --- a/applications/app-loader/app-loader.c +++ b/applications/app-loader/app-loader.c @@ -103,7 +103,11 @@ int32_t app_loader(void* p) { menu, menu_item_alloc_function("Games", assets_icons_get(A_Games_14), NULL, NULL)); menu_item_add( menu, - menu_item_alloc_function("Passport", assets_icons_get(A_Passport_14), NULL, NULL)); + menu_item_alloc_function( + "Passport", + assets_icons_get(A_Passport_14), + app_loader_menu_callback, + (void*)&FLIPPER_SCENE_APPS[0])); menu_item_add( menu, menu_item_alloc_function("Settings", assets_icons_get(A_Settings_14), NULL, NULL)); diff --git a/applications/applications.c b/applications/applications.c index eada2daf..04e09118 100644 --- a/applications/applications.c +++ b/applications/applications.c @@ -33,7 +33,7 @@ int32_t sd_filesystem(void* p); int32_t subghz_app(void* p); int32_t gui_test(void* p); int32_t keypad_test(void* p); -int32_t dolphin_scene(void* p); +int32_t scene_app(void* p); int32_t passport(void* p); const FlipperApplication FLIPPER_SERVICES[] = { @@ -149,10 +149,6 @@ const FlipperApplication FLIPPER_SERVICES[] = { {.app = keypad_test, .name = "keypad_test", .icon = A_Plugins_14}, #endif -#ifdef APP_DOLPHIN_SCENE - {.app = dolphin_scene, .name = "Dolphin [beta]", .stack_size = 1024, .icon = A_Games_14}, -#endif - }; const size_t FLIPPER_SERVICES_COUNT = sizeof(FLIPPER_SERVICES) / sizeof(FlipperApplication); @@ -231,9 +227,8 @@ const FlipperApplication FLIPPER_PLUGINS[] = { const size_t FLIPPER_PLUGINS_COUNT = sizeof(FLIPPER_PLUGINS) / sizeof(FlipperApplication); -#ifdef BUILD_DOLPHIN_SCENE -const FlipperApplication FLIPPER_SCENES = - {.app = dolphin_scene, .name = "Dolphin [beta]", .stack_size = 1024, .icon = A_Games_14}; +const FlipperApplication FLIPPER_SCENE = + {.app = scene_app, .name = "Scenes", .stack_size = 1024, .icon = A_Games_14}; const FlipperApplication FLIPPER_SCENE_APPS[] = { {.app = passport, .name = "Passport", .stack_size = 1024, .icon = A_Games_14}, @@ -242,5 +237,3 @@ const FlipperApplication FLIPPER_SCENE_APPS[] = { }; const size_t FLIPPER_SCENE_APPS_COUNT = sizeof(FLIPPER_SCENE_APPS) / sizeof(FlipperApplication); - -#endif diff --git a/applications/applications.h b/applications/applications.h index 830dbcc9..98f9373f 100644 --- a/applications/applications.h +++ b/applications/applications.h @@ -31,6 +31,6 @@ extern const size_t FLIPPER_PLUGINS_COUNT; /* Seperate scene app holder * Spawned by app-loader */ -extern const FlipperApplication FLIPPER_SCENES; +extern const FlipperApplication FLIPPER_SCENE; extern const FlipperApplication FLIPPER_SCENE_APPS[]; extern const size_t FLIPPER_SCENE_APPS_COUNT; diff --git a/applications/applications.mk b/applications/applications.mk index 9cce8147..1342bb68 100644 --- a/applications/applications.mk +++ b/applications/applications.mk @@ -16,7 +16,6 @@ APP_BT = 1 APP_CLI = 1 APP_SD_FILESYSTEM = 1 BUILD_IRDA = 1 -BUILD_DOLPHIN_SCENE = 1 APP_DOLPHIN = 1 BUILD_EXAMPLE_BLINK = 1 BUILD_EXAMPLE_UART_WRITE = 1 @@ -46,6 +45,9 @@ ifeq ($(APP_DOLPHIN), 1) APP_MENU = 1 CFLAGS += -DAPP_DOLPHIN C_SOURCES += $(wildcard $(APP_DIR)/dolphin/*.c) +C_SOURCES += $(wildcard $(APP_DIR)/dolphin/scenes/*.c) +C_SOURCES += $(wildcard $(APP_DIR)/dolphin/scenes/assets/*.c) +C_SOURCES += $(wildcard $(APP_DIR)/dolphin/passport/*.c) endif APP_POWER ?= 0 @@ -261,18 +263,6 @@ CFLAGS += -DBUILD_FLOOPPER_BLOOPPER C_SOURCES += $(wildcard $(APP_DIR)/floopper-bloopper/*.c) endif -APP_DOLPHIN_SCENE ?= 0 -ifeq ($(APP_DOLPHIN_SCENE), 1) -CFLAGS += -DAPP_DOLPHIN_SCENE -BUILD_DOLPHIN_SCENE = 1 -endif -BUILD_DOLPHIN_SCENE ?= 0 -ifeq ($(BUILD_DOLPHIN_SCENE), 1) -CFLAGS += -DBUILD_DOLPHIN_SCENE -C_SOURCES += $(wildcard $(APP_DIR)/dolphin_scene/*.c) -C_SOURCES += $(wildcard $(APP_DIR)/passport/*.c) -endif - APP_IBUTTON ?= 0 ifeq ($(APP_IBUTTON), 1) CFLAGS += -DAPP_IBUTTON diff --git a/applications/dolphin/dolphin.c b/applications/dolphin/dolphin.c index 9247d71b..550c4b98 100644 --- a/applications/dolphin/dolphin.c +++ b/applications/dolphin/dolphin.c @@ -80,7 +80,7 @@ bool dolphin_view_idle_main_input(InputEvent* event, void* context) { } else if(event->key == InputKeyLeft) { view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewIdleUp); } else if(event->key == InputKeyRight) { - dolphin_switch_to_interactive_scene(dolphin, &FLIPPER_SCENES); + dolphin_switch_to_interactive_scene(dolphin, &FLIPPER_SCENE); } else if(event->key == InputKeyDown) { view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewIdleDown); } diff --git a/applications/dolphin/dolphin_state.c b/applications/dolphin/dolphin_state.c index 4c3c0574..46be7f50 100644 --- a/applications/dolphin/dolphin_state.c +++ b/applications/dolphin/dolphin_state.c @@ -3,38 +3,6 @@ #include #include -typedef struct { - uint8_t magic; - uint8_t version; - uint8_t checksum; - uint8_t flags; - uint32_t timestamp; -} DolphinDataHeader; - -#define DOLPHIN_DATA_PAGE 0xC0 -#define DOLPHIN_DATA_HEADER_ADDRESS 0x080C0000U -#define DOLPHIN_DATA_DATA_ADDRESS (DOLPHIN_DATA_HEADER_ADDRESS + sizeof(DolphinDataHeader)) - -#define DOLPHIN_DATA_HEADER_MAGIC 0xD0 -#define DOLPHIN_DATA_HEADER_VERSION 0x01 - -#define DOLPHIN_LVL_THRESHOLD 20.0f - -typedef struct { - uint32_t limit_ibutton; - uint32_t limit_nfc; - uint32_t limit_ir; - uint32_t limit_rfid; - - uint32_t flags; - uint32_t icounter; - uint32_t butthurt; -} DolphinData; - -struct DolphinState { - DolphinData data; -}; - DolphinState* dolphin_state_alloc() { DolphinState* dolphin_state = furi_alloc(sizeof(DolphinState)); return dolphin_state; diff --git a/applications/dolphin/dolphin_state.h b/applications/dolphin/dolphin_state.h index cbd9611a..5157569a 100644 --- a/applications/dolphin/dolphin_state.h +++ b/applications/dolphin/dolphin_state.h @@ -4,6 +4,38 @@ #include #include +#define DOLPHIN_DATA_PAGE 0xC0 +#define DOLPHIN_DATA_HEADER_ADDRESS 0x080C0000U +#define DOLPHIN_DATA_DATA_ADDRESS (DOLPHIN_DATA_HEADER_ADDRESS + sizeof(DolphinDataHeader)) + +#define DOLPHIN_DATA_HEADER_MAGIC 0xD0 +#define DOLPHIN_DATA_HEADER_VERSION 0x01 + +#define DOLPHIN_LVL_THRESHOLD 20.0f + +typedef struct { + uint8_t magic; + uint8_t version; + uint8_t checksum; + uint8_t flags; + uint32_t timestamp; +} DolphinDataHeader; + +typedef struct { + uint32_t limit_ibutton; + uint32_t limit_nfc; + uint32_t limit_ir; + uint32_t limit_rfid; + + uint32_t flags; + uint32_t icounter; + uint32_t butthurt; +} DolphinData; + +struct DolphinState { + DolphinData data; +}; + typedef struct DolphinState DolphinState; DolphinState* dolphin_state_alloc(); diff --git a/applications/passport/passport.c b/applications/dolphin/passport/passport.c similarity index 70% rename from applications/passport/passport.c rename to applications/dolphin/passport/passport.c index 8973183f..5d498eab 100644 --- a/applications/passport/passport.c +++ b/applications/dolphin/passport/passport.c @@ -1,6 +1,8 @@ #include #include #include +#include "dolphin/dolphin.h" +#include "dolphin/dolphin_state.h" typedef enum { EventTypeTick, @@ -14,8 +16,8 @@ typedef struct { EventType type; } AppEvent; -typedef struct { -} State; +// Moods, corresponding to butthurt level. (temp, unclear about max level) +static const char* mood_strings[5] = {[0] = "Normal", [1] = "Ok", [2] = "Sad", [3] = "Angry"}; static void input_callback(InputEvent* input_event, void* ctx) { osMessageQueueId_t event_queue = ctx; @@ -26,16 +28,17 @@ static void input_callback(InputEvent* input_event, void* ctx) { } static void render_callback(Canvas* canvas, void* ctx) { - State* state = (State*)acquire_mutex((ValueMutex*)ctx, 25); - - /* + DolphinState* state = (DolphinState*)acquire_mutex((ValueMutex*)ctx, 25); char level[20]; - uint32_t current_level = dolphin_state_get_level(dolphin->state); - uint32_t prev_cap = dolphin_state_xp_to_levelup(dolphin->state, current_level - 1, false); - uint32_t exp = (dolphin_state_xp_to_levelup(dolphin->state, current_level, true) * 63) / - (dolphin_state_xp_to_levelup(dolphin->state, current_level, false) - prev_cap); - */ + char mood[32]; + + uint32_t butthurt = dolphin_state_get_butthurt(state); + uint32_t current_level = dolphin_state_get_level(state); + uint32_t prev_cap = dolphin_state_xp_to_levelup(state, current_level - 1, false); + uint32_t exp = (dolphin_state_xp_to_levelup(state, current_level, true) * 63) / + (dolphin_state_xp_to_levelup(state, current_level, false) - prev_cap); + canvas_clear(canvas); // multipass @@ -59,29 +62,31 @@ static void render_callback(Canvas* canvas, void* ctx) { canvas_draw_line(canvas, 59, 44, 124, 44); canvas_draw_str(canvas, 59, 15, api_hal_version_get_name_ptr()); - canvas_draw_str(canvas, 59, 28, "Mood: OK"); - /* + snprintf(level, 20, "Level: %ld", current_level); + snprintf(mood, 20, "Mood: %s", mood_strings[butthurt]); + + canvas_draw_str(canvas, 59, 28, mood); canvas_draw_str(canvas, 59, 41, level); canvas_set_color(canvas, ColorWhite); canvas_draw_box(canvas, 123 - exp, 48, exp + 1, 6); canvas_set_color(canvas, ColorBlack); canvas_draw_line(canvas, 123 - exp, 48, 123 - exp, 54); - */ release_mutex((ValueMutex*)ctx, state); } int32_t passport(void* p) { - State _state; + DolphinState _state; ValueMutex state_mutex; + dolphin_state_load(&_state); - osMessageQueueId_t event_queue = osMessageQueueNew(1, sizeof(AppEvent), NULL); + osMessageQueueId_t event_queue = osMessageQueueNew(2, sizeof(AppEvent), NULL); furi_check(event_queue); - if(!init_mutex(&state_mutex, &_state, sizeof(State))) { - printf("cannot create mutex\r\n"); + if(!init_mutex(&state_mutex, &_state, sizeof(DolphinState))) { + printf("[Passport] cannot create mutex\r\n"); return 0; } @@ -95,17 +100,15 @@ int32_t passport(void* p) { AppEvent event; while(1) { - State* state = (State*)acquire_mutex_block(&state_mutex); osStatus_t event_status = osMessageQueueGet(event_queue, &event, NULL, 25); if(event_status == osOK) { - if(event.type == EventTypeKey && event.value.input.type == InputTypeShort) { - release_mutex(&state_mutex, state); + if(event.type == EventTypeKey && event.value.input.type == InputTypeShort && + event.value.input.key == InputKeyBack) { break; } } view_port_update(view_port); - release_mutex(&state_mutex, state); } gui_remove_view_port(gui, view_port); diff --git a/applications/dolphin_scene/dolphin_emotes.h b/applications/dolphin/scenes/assets/emotes.h similarity index 100% rename from applications/dolphin_scene/dolphin_emotes.h rename to applications/dolphin/scenes/assets/emotes.h diff --git a/applications/dolphin_scene/items.c b/applications/dolphin/scenes/assets/items.c similarity index 89% rename from applications/dolphin_scene/items.c rename to applications/dolphin/scenes/assets/items.c index 3eb984e4..4426d3a3 100644 --- a/applications/dolphin_scene/items.c +++ b/applications/dolphin/scenes/assets/items.c @@ -1,6 +1,6 @@ -#include "dolphin_scene/items_i.h" #include #include "applications.h" +#include "items_i.h" const Item TV = { .layer = 7, @@ -64,6 +64,20 @@ static void dolphin_scene_start_app(SceneState* state, const FlipperApplication* furi_thread_start(state->scene_app_thread); } +const void scene_activate_item_callback(SceneState* state, Canvas* canvas) { + furi_assert(state); + furi_assert(canvas); + + const Item* near = is_nearby(state); + if(near && state->use_pending == true) { + state->action_timeout = near->timeout; + near->callback(canvas, state); + state->use_pending = false; + } else if(near) { + near->callback(canvas, state); + } +} + const Item* is_nearby(SceneState* state) { furi_assert(state); uint8_t item = 0; @@ -128,4 +142,4 @@ void pc_callback(Canvas* canvas, void* state) { if(s->use_pending) { dolphin_scene_start_app(s, &FLIPPER_SCENE_APPS[1]); } -} +} \ No newline at end of file diff --git a/applications/dolphin/scenes/assets/items.h b/applications/dolphin/scenes/assets/items.h new file mode 100644 index 00000000..7e929421 --- /dev/null +++ b/applications/dolphin/scenes/assets/items.h @@ -0,0 +1,8 @@ +#pragma once +#include "dolphin/scenes/scene.h" + +#define ITEMS_NUM 4 + +const Item* is_nearby(SceneState* state); +const Item** get_scene(SceneState* state); +const void scene_activate_item_callback(SceneState* state, Canvas* canvas); diff --git a/applications/dolphin_scene/items_i.h b/applications/dolphin/scenes/assets/items_i.h similarity index 88% rename from applications/dolphin_scene/items_i.h rename to applications/dolphin/scenes/assets/items_i.h index ac1850f8..e58256a9 100644 --- a/applications/dolphin_scene/items_i.h +++ b/applications/dolphin/scenes/assets/items_i.h @@ -1,5 +1,5 @@ #pragma once -#include "dolphin_scene/items.h" +#include "items.h" void smash_tv(Canvas* canvas, void* state); void draw_tv(Canvas* canvas, void* state); diff --git a/applications/dolphin_scene/engine.c b/applications/dolphin/scenes/scene.c similarity index 75% rename from applications/dolphin_scene/engine.c rename to applications/dolphin/scenes/scene.c index c9f5b983..d633d30c 100644 --- a/applications/dolphin_scene/engine.c +++ b/applications/dolphin/scenes/scene.c @@ -1,18 +1,43 @@ #include #include -#include "dolphin_scene/dolphin_scene.h" +#include "scene.h" static SceneAppGui* scene_app_gui = NULL; static ValueMutex* scene_state_mutex = NULL; -static void dolphin_engine_tick_callback(void* p) { +void dolphin_scene_redraw(Canvas* canvas, void* ctx) { + furi_assert(canvas); + furi_assert(ctx); + + SceneState* state = (SceneState*)acquire_mutex((ValueMutex*)ctx, 25); + if(state == NULL) return; // redraw fail + uint32_t t = xTaskGetTickCount(); + + canvas_clear(canvas); + dolphin_scene_render(state, canvas, t); + dolphin_scene_render_state(state, canvas); + release_mutex((ValueMutex*)ctx, state); +} + +void dolphin_scene_handle_input(SceneState* state, InputEvent* input) { + // printf("[kb] event: %02x %s\n", input->key, input->state ? "pressed" : "released"); + dolphin_scene_handle_user_input(state, input); +} + +void dolphin_scene_tick_handler(SceneState* state, uint32_t t, uint32_t dt) { + // printf("t: %d, dt: %d\n", t, dt); + dolphin_scene_coordinates(state, dt); + dolphin_scene_update_state(state, t, dt); +} + +static void scene_engine_tick_callback(void* p) { osMessageQueueId_t event_queue = p; AppEvent event; event.type = EventTypeTick; osMessageQueuePut(event_queue, (void*)&event, 0, 0); } -static void dolphin_engine_input_callback(InputEvent* input_event, void* ctx) { +static void scene_engine_input_callback(InputEvent* input_event, void* ctx) { osMessageQueueId_t event_queue = ctx; AppEvent event; event.type = EventTypeKey; @@ -31,7 +56,7 @@ void scene_alloc() { scene_app_gui->gui = furi_record_open("gui"); scene_app_gui->view_port = view_port_alloc(); scene_app_gui->timer = - osTimerNew(dolphin_engine_tick_callback, osTimerPeriodic, scene_app_gui->mqueue, NULL); + osTimerNew(scene_engine_tick_callback, osTimerPeriodic, scene_app_gui->mqueue, NULL); printf("scene_alloc: timer %p\r\n", scene_app_gui->timer); // Scene State SceneState* scene_state = furi_alloc(sizeof(SceneState)); @@ -47,7 +72,7 @@ void scene_alloc() { // Open GUI and register fullscreen view_port view_port_draw_callback_set(scene_app_gui->view_port, dolphin_scene_redraw, scene_state_mutex); view_port_input_callback_set( - scene_app_gui->view_port, dolphin_engine_input_callback, scene_app_gui->mqueue); + scene_app_gui->view_port, scene_engine_input_callback, scene_app_gui->mqueue); gui_add_view_port(scene_app_gui->gui, scene_app_gui->view_port, GuiLayerMain); view_port_enabled_set(scene_app_gui->view_port, true); printf("scene_alloc: complete\r\n"); @@ -75,7 +100,7 @@ void scene_free() { printf("scene_free: complete\r\n"); } -int32_t dolphin_scene(void* p) { +int32_t scene_app(void* p) { api_hal_power_insomnia_enter(); scene_alloc(); @@ -111,4 +136,4 @@ int32_t dolphin_scene(void* p) { scene_free(); api_hal_power_insomnia_exit(); return 0; -} +} \ No newline at end of file diff --git a/applications/dolphin_scene/dolphin_scene.h b/applications/dolphin/scenes/scene.h similarity index 91% rename from applications/dolphin_scene/dolphin_scene.h rename to applications/dolphin/scenes/scene.h index 348a76bb..df09fad1 100644 --- a/applications/dolphin_scene/dolphin_scene.h +++ b/applications/dolphin/scenes/scene.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #ifndef ARRSIZE @@ -23,8 +23,9 @@ // global #define SCALE 32 // screen -#define SCREEN_WIDTH 128 -#define SCREEN_HEIGHT 64 + +#define SCREEN_WIDTH GUI_DISPLAY_WIDTH +#define SCREEN_HEIGHT GUI_DISPLAY_HEIGHT #define BONDARIES_X_LEFT 40 #define BONDARIES_X_RIGHT 88 @@ -44,7 +45,6 @@ #define DOLPHIN_LAYER 6 #define PARALLAX_MOD 7 #define PARALLAX(layer) layer / PARALLAX_MOD - layer -#define ITEMS_NUM 4 #define DIALOG_PROGRESS 250 @@ -131,8 +131,8 @@ void dolphin_scene_render_dolphin(SceneState* state, Canvas* canvas); void dolphin_scene_handle_user_input(SceneState* state, InputEvent* input); void dolphin_scene_coordinates(SceneState* state, uint32_t dt); -void dolphin_scene_render_dolphin_state(SceneState* state, Canvas* canvas); -void dolphin_scene_update_dolphin_state(SceneState* state, uint32_t t, uint32_t dt); +void dolphin_scene_render_state(SceneState* state, Canvas* canvas); +void dolphin_scene_update_state(SceneState* state, uint32_t t, uint32_t dt); void dolphin_scene_redraw(Canvas* canvas, void* ctx); void dolphin_scene_tick_handler(SceneState* state, uint32_t t, uint32_t dt); diff --git a/applications/dolphin_scene/user.c b/applications/dolphin/scenes/scene_controls.c similarity index 60% rename from applications/dolphin_scene/user.c rename to applications/dolphin/scenes/scene_controls.c index d54e7469..ba3857b3 100644 --- a/applications/dolphin_scene/user.c +++ b/applications/dolphin/scenes/scene_controls.c @@ -1,46 +1,6 @@ #include #include -#include "dolphin_scene/dolphin_scene.h" - -void dolphin_scene_render_dolphin(SceneState* state, Canvas* canvas) { - furi_assert(state); - furi_assert(canvas); - - if(state->scene_zoom == SCENE_ZOOM) { - state->dolphin_gfx = I_DolphinExcited_64x63; - } else if(state->action == SLEEP && state->player_global.x == 154) { - state->dolphin_gfx = A_FX_Sitting_40x27; - state->dolphin_gfx_b = I_FX_SittingB_40x27; - } else if(state->action != INTERACT) { - if(state->player_v.x < 0 || state->player_flipped) { - if(state->player_anim == 0) { - state->dolphin_gfx = I_WalkL1_32x32; - state->dolphin_gfx_b = I_WalkLB1_32x32; - - } else { - state->dolphin_gfx = I_WalkL2_32x32; - state->dolphin_gfx_b = I_WalkLB2_32x32; - } - } else if(state->player_v.x > 0 || !state->player_flipped) { - if(state->player_anim == 0) { - state->dolphin_gfx = I_WalkR1_32x32; - state->dolphin_gfx_b = I_WalkRB1_32x32; - - } else { - state->dolphin_gfx = I_WalkR2_32x32; - state->dolphin_gfx_b = I_WalkRB2_32x32; - } - } - } - - // zoom handlers - canvas_set_bitmap_mode(canvas, true); - canvas_set_color(canvas, ColorWhite); - canvas_draw_icon_name(canvas, state->player.x, state->player.y, state->dolphin_gfx_b); - canvas_set_color(canvas, ColorBlack); - canvas_draw_icon_name(canvas, state->player.x, state->player.y, state->dolphin_gfx); - canvas_set_bitmap_mode(canvas, false); -} +#include "scene.h" void dolphin_scene_handle_user_input(SceneState* state, InputEvent* input) { furi_assert(state); diff --git a/applications/dolphin_scene/state.c b/applications/dolphin/scenes/scene_dolphin_state.c similarity index 78% rename from applications/dolphin_scene/state.c rename to applications/dolphin/scenes/scene_dolphin_state.c index 0e0680be..9acb87e9 100644 --- a/applications/dolphin_scene/state.c +++ b/applications/dolphin/scenes/scene_dolphin_state.c @@ -1,6 +1,6 @@ #include -#include "dolphin_scene/dolphin_scene.h" -#include "dolphin_scene/dolphin_emotes.h" +#include "scene.h" +#include "assets/emotes.h" static uint16_t roll_new(uint16_t prev, uint16_t max) { uint16_t val = 999; @@ -11,7 +11,7 @@ static uint16_t roll_new(uint16_t prev, uint16_t max) { return val; } -static void dolphin_actions_proceed(SceneState* state) { +static void scene_proceed_action(SceneState* state) { furi_assert(state); state->prev_action = state->action; @@ -21,7 +21,7 @@ static void dolphin_actions_proceed(SceneState* state) { state->action_timeout = default_timeout[state->action]; } -static void dolphin_go_to_poi(SceneState* state) { +static void scene_dolphin_go_to_poi(SceneState* state) { furi_assert(state); if(state->player_global.x < state->poi) { state->player_flipped = false; @@ -32,7 +32,7 @@ static void dolphin_go_to_poi(SceneState* state) { } } -static void action_handler(SceneState* state) { +static void scene_action_handler(SceneState* state) { furi_assert(state); if(state->action == MINDCONTROL && state->player_v.x != 0) { state->action_timeout = default_timeout[state->action]; @@ -48,23 +48,24 @@ static void action_handler(SceneState* state) { } } -void dolphin_scene_update_dolphin_state(SceneState* state, uint32_t t, uint32_t dt) { +void dolphin_scene_update_state(SceneState* state, uint32_t t, uint32_t dt) { furi_assert(state); - action_handler(state); + scene_action_handler(state); + UNUSED(dialogues_list); switch(state->action) { case WALK: if(state->player_global.x == state->poi) { state->player_v.x = 0; - dolphin_actions_proceed(state); + scene_proceed_action(state); } else { - dolphin_go_to_poi(state); + scene_dolphin_go_to_poi(state); } break; case EMOTE: state->player_flipped = false; if(state->action_timeout == 0) { - dolphin_actions_proceed(state); + scene_proceed_action(state); state->emote_id = roll_new(state->previous_emote, ARRSIZE(emotes_list)); break; } @@ -73,7 +74,7 @@ void dolphin_scene_update_dolphin_state(SceneState* state, uint32_t t, uint32_t if(state->prev_action == MINDCONTROL) { state->action = MINDCONTROL; } else { - dolphin_actions_proceed(state); + scene_proceed_action(state); } } break; @@ -81,21 +82,19 @@ void dolphin_scene_update_dolphin_state(SceneState* state, uint32_t t, uint32_t if(state->poi != 154) { // temp state->poi = 154; } else if(state->player_global.x != state->poi) { - dolphin_go_to_poi(state); + scene_dolphin_go_to_poi(state); } else { state->player_v.x = 0; if(state->action_timeout == 0) { state->poi = roll_new(state->player_global.x, WORLD_WIDTH / 4); - dolphin_actions_proceed(state); + scene_proceed_action(state); } break; } default: if(state->action_timeout == 0) { - dolphin_actions_proceed(state); + scene_proceed_action(state); } break; } - - UNUSED(dialogues_list); } diff --git a/applications/dolphin_scene/scene.c b/applications/dolphin/scenes/scene_gfx.c similarity index 66% rename from applications/dolphin_scene/scene.c rename to applications/dolphin/scenes/scene_gfx.c index cbe36f0c..f32b9fd7 100644 --- a/applications/dolphin_scene/scene.c +++ b/applications/dolphin/scenes/scene_gfx.c @@ -1,16 +1,12 @@ #include -#include "dolphin_scene/dolphin_scene.h" -#include "dolphin_scene/dolphin_emotes.h" -#include "dolphin_scene/items.h" +#include "scene.h" +#include "assets/emotes.h" +#include "assets/items.h" #include const char* action_str[] = {"Sleep", "Idle", "Walk", "Emote", "Use", "MC"}; -static bool item_screen_bounds(int32_t pos) { - return pos > -SCREEN_WIDTH && pos < (SCREEN_WIDTH * 2); -} - -static void draw_hint(SceneState* state, Canvas* canvas, bool glitching) { +static void scene_draw_hint(SceneState* state, Canvas* canvas, bool glitching) { furi_assert(state); furi_assert(canvas); char buf[32]; @@ -31,19 +27,19 @@ static void draw_hint(SceneState* state, Canvas* canvas, bool glitching) { } } -static void draw_current_emote(SceneState* state, Canvas* canvas) { +static void scene_draw_current_emote(SceneState* state, Canvas* canvas) { furi_assert(state); furi_assert(canvas); elements_multiline_text_framed(canvas, 80, 20, (char*)emotes_list[state->emote_id]); } -static void draw_sleep_emote(SceneState* state, Canvas* canvas) { +static void scene_draw_sleep_emote(SceneState* state, Canvas* canvas) { furi_assert(state); furi_assert(canvas); char dialog_str[] = "zZzZ..."; char buf[64]; - + // 2do - sofa x pos getter if(state->player_global.x == 154 && state->action_timeout % 100 < 30) { if(state->dialog_progress < strlen(dialog_str)) { if(state->action_timeout % 5 == 0) state->dialog_progress++; @@ -59,7 +55,7 @@ static void draw_sleep_emote(SceneState* state, Canvas* canvas) { } } -static void draw_dialog(SceneState* state, Canvas* canvas) { +static void scene_draw_dialog(SceneState* state, Canvas* canvas) { furi_assert(state); furi_assert(canvas); @@ -87,18 +83,47 @@ static void draw_idle_emote(SceneState* state, Canvas* canvas){ } */ -static void activate_item_callback(SceneState* state, Canvas* canvas) { +void dolphin_scene_render_dolphin(SceneState* state, Canvas* canvas) { furi_assert(state); furi_assert(canvas); - const Item* near = is_nearby(state); - if(near && state->use_pending == true) { - state->action_timeout = near->timeout; - near->callback(canvas, state); - state->use_pending = false; - } else if(near) { - near->callback(canvas, state); + if(state->scene_zoom == SCENE_ZOOM) { + state->dolphin_gfx = I_DolphinExcited_64x63; + } else if(state->action == SLEEP && state->player_global.x == 154) { // 2do - sofa x pos getter + state->dolphin_gfx = A_FX_Sitting_40x27; + state->dolphin_gfx_b = I_FX_SittingB_40x27; + } else if(state->action != INTERACT) { + if(state->player_v.x < 0 || state->player_flipped) { + if(state->player_anim == 0) { + state->dolphin_gfx = I_WalkL1_32x32; + state->dolphin_gfx_b = I_WalkLB1_32x32; + + } else { + state->dolphin_gfx = I_WalkL2_32x32; + state->dolphin_gfx_b = I_WalkLB2_32x32; + } + } else if(state->player_v.x > 0 || !state->player_flipped) { + if(state->player_anim == 0) { + state->dolphin_gfx = I_WalkR1_32x32; + state->dolphin_gfx_b = I_WalkRB1_32x32; + + } else { + state->dolphin_gfx = I_WalkR2_32x32; + state->dolphin_gfx_b = I_WalkRB2_32x32; + } + } } + + canvas_set_bitmap_mode(canvas, true); + canvas_set_color(canvas, ColorWhite); + canvas_draw_icon_name(canvas, state->player.x, state->player.y, state->dolphin_gfx_b); + canvas_set_color(canvas, ColorBlack); + canvas_draw_icon_name(canvas, state->player.x, state->player.y, state->dolphin_gfx); + canvas_set_bitmap_mode(canvas, false); +} + +static bool item_screen_bounds(int32_t pos) { + return pos > -SCREEN_WIDTH && pos < (SCREEN_WIDTH * 2); } void dolphin_scene_render(SceneState* state, Canvas* canvas, uint32_t t) { @@ -134,7 +159,7 @@ void dolphin_scene_render(SceneState* state, Canvas* canvas, uint32_t t) { } } -void dolphin_scene_render_dolphin_state(SceneState* state, Canvas* canvas) { +void dolphin_scene_render_state(SceneState* state, Canvas* canvas) { furi_assert(state); furi_assert(canvas); @@ -156,15 +181,15 @@ void dolphin_scene_render_dolphin_state(SceneState* state, Canvas* canvas) { } if(state->scene_zoom == SCENE_ZOOM) - draw_dialog(state, canvas); + scene_draw_dialog(state, canvas); else if(state->action == EMOTE) - draw_current_emote(state, canvas); + scene_draw_current_emote(state, canvas); else if(state->action == MINDCONTROL) - draw_hint(state, canvas, state->action_timeout > 45); + scene_draw_hint(state, canvas, state->action_timeout > 45); else if(state->action == INTERACT) - activate_item_callback(state, canvas); + scene_activate_item_callback(state, canvas); else if(state->action == SLEEP) - draw_sleep_emote(state, canvas); + scene_draw_sleep_emote(state, canvas); /* else if(state->action == IDLE) draw_idle_emote(state, canvas); diff --git a/applications/dolphin_scene/dolphin_scene.c b/applications/dolphin_scene/dolphin_scene.c deleted file mode 100644 index 97e94dc1..00000000 --- a/applications/dolphin_scene/dolphin_scene.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include "dolphin_scene/dolphin_scene.h" - -void dolphin_scene_redraw(Canvas* canvas, void* ctx) { - furi_assert(canvas); - furi_assert(ctx); - - SceneState* state = (SceneState*)acquire_mutex((ValueMutex*)ctx, 25); - if(state == NULL) return; // redraw fail - uint32_t t = xTaskGetTickCount(); - - canvas_clear(canvas); - - dolphin_scene_render(state, canvas, t); - - dolphin_scene_render_dolphin_state(state, canvas); - - release_mutex((ValueMutex*)ctx, state); -} - -void dolphin_scene_handle_input(SceneState* state, InputEvent* input) { - // printf("[kb] event: %02x %s\n", input->key, input->state ? "pressed" : "released"); - dolphin_scene_handle_user_input(state, input); -} - -void dolphin_scene_tick_handler(SceneState* state, uint32_t t, uint32_t dt) { - // printf("t: %d, dt: %d\n", t, dt); - - dolphin_scene_coordinates(state, dt); - dolphin_scene_update_dolphin_state(state, t, dt); -} diff --git a/applications/dolphin_scene/items.h b/applications/dolphin_scene/items.h deleted file mode 100644 index 08f91317..00000000 --- a/applications/dolphin_scene/items.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once -#include "dolphin_scene/dolphin_scene.h" - -const Item* is_nearby(SceneState* state); -const Item** get_scene(SceneState* state); \ No newline at end of file