unleashed-firmware/applications/dolphin_scene/dolphin_scene.h
its your bedtime d1f523687e
[FL-1090] Dolphin scenes (#402)
* dolphin scene draft wip
* gui/elements multiline framed text added
* zoom poc
* item callbacks
* engine tweaks
* move scenes out of services
* improve dolphin gfx selection
* glitch hints
* dialogue typewriter effect
* app loading from scenes app, small action changes, passport app(WIP)
* removed passport from main dolphin app, added statusbar
* small elements position fixes
* fix thread alloc, dolphin and dolphin_scene free functions, other minor issues
* sleep emote improvements
* Dolpin: fix memory leaks, variable namings and etc

Co-authored-by: gornekich <44112859+gornekich@users.noreply.github.com>
Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
Co-authored-by: あく <alleteam@gmail.com>
2021-04-13 21:06:25 +03:00

141 lines
3 KiB
C

#pragma once
#include <furi.h>
#include <gui/gui.h>
#include <u8g2/u8g2.h>
#ifndef ARRSIZE
#define ARRSIZE(arr) (sizeof(arr) / sizeof(arr[0]))
#endif
#ifndef MAX
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#endif
#ifndef MIN
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#endif
#ifndef CLAMP
#define CLAMP(x, upper, lower) (MIN(upper, MAX(x, lower)))
#endif
// global
#define SCALE 32
// screen
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define BONDARIES_X_LEFT 40
#define BONDARIES_X_RIGHT 88
// player
#define DOLPHIN_WIDTH 32
#define DOLPHIN_HEIGHT 32
#define DOLPHIN_CENTER (SCREEN_WIDTH / 2 - DOLPHIN_WIDTH / 2)
#define SPEED_X 2
#define ACTIONS_NUM 5
#define DOLPHIN_DEFAULT_Y 20
// world
#define WORLD_WIDTH 2048
#define WORLD_HEIGHT 64
#define LAYERS 8
#define SCENE_ZOOM 9
#define DOLPHIN_LAYER 6
#define PARALLAX_MOD 7
#define PARALLAX(layer) layer / PARALLAX_MOD - layer
#define ITEMS_NUM 4
#define DIALOG_PROGRESS 250
enum Actions { SLEEP = 0, IDLE, WALK, EMOTE, INTERACT, MINDCONTROL };
static const uint16_t default_timeout[] =
{[SLEEP] = 300, [IDLE] = 100, [WALK] = 100, [EMOTE] = 50, [INTERACT] = 10, [MINDCONTROL] = 50};
typedef enum {
EventTypeTick,
EventTypeKey,
} EventType;
typedef struct {
union {
InputEvent input;
} value;
EventType type;
} AppEvent;
typedef struct {
int32_t x;
int32_t y;
} Vec2;
typedef struct {
Gui* gui;
ViewPort* view_port;
ValueMutex* vm;
osTimerId_t* timer;
osMessageQueueId_t mqueue;
FuriThread* scene_app_thread;
} SceneAppGui;
typedef struct {
uint8_t layer;
uint16_t timeout;
int32_t x;
int32_t y;
IconName icon;
char action_name[16];
void (*draw)(Canvas* canvas, void* model);
void (*callback)(Canvas* canvas, void* model);
} Item;
typedef struct {
SceneAppGui ui;
///
Vec2 player;
Vec2 player_global;
Vec2 player_v;
Vec2 screen;
IconName dolphin_gfx;
IconName dolphin_gfx_b; // temp
bool player_flipped;
bool use_pending;
// dolphin_scene_debug
bool debug;
uint8_t player_anim;
uint8_t scene_id;
uint8_t emote_id;
uint8_t previous_emote;
uint8_t dialogue_id;
uint8_t previous_dialogue;
uint32_t action_timeout;
uint8_t poi;
uint8_t action;
uint8_t next_action;
uint8_t prev_action;
int8_t zoom_v;
uint8_t scene_zoom;
uint8_t dialog_progress;
} SceneState;
void dolphin_scene_render(SceneState* state, Canvas* canvas, uint32_t t);
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_redraw(Canvas* canvas, void* ctx);
void dolphin_scene_tick_handler(SceneState* state, uint32_t t, uint32_t dt);
void dolphin_scene_handle_input(SceneState* state, InputEvent* input);