aboutsummaryrefslogtreecommitdiff
path: root/plat.h
blob: 32f17f6135ec973fb40655170bb04413c109c00f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef plat_h
#define plat_h

#include "error.h"

struct Heap;

#ifdef assert
#undef assert
#endif

#ifdef DEBUG
#define assert(expr) \
	imp_assert( \
		expr, \
		#expr, \
		__FILE__, \
		__LINE__ \
	)
#else
#define assert(expr)
#endif

int imp_assert(
	int val,
	const char* expr,
	const char* file,
	int line
);

void print(const char* fmt, ...);
void print_err(const char* fmt, ...);
void print_war(const char* fmt, ...);
void pbreak(Error code);

typedef struct {
	int mpf;
	int fps;
	unsigned long pt, ct;
	unsigned long now, next;
} FPS;

void init_fps(FPS* f, int mpf);
void fps_begin(FPS* f);
void fps_end(FPS* f);
void fps_update(FPS* f);

typedef enum {
	btn_unknown,
	btn_left,
	btn_right,
	btn_up,
	btn_down,
	btn_shoot,
	btn_jump,
	btn_start,
	btn_count
} Btn;

typedef enum {
	btn_state_pressed       = 1 << 0,
	btn_state_just_pressed  = 1 << 1,
	btn_state_just_released = 1 << 2
} Key_State;

typedef struct App {
	int o, s;
	int fps;
	Error err;
	unsigned* fb;
	struct Heap* heap;
	unsigned char btn_states[btn_count];
} App;

App* new_app(struct Heap* mem, const char* n);
void deinit_app(App* a);
void app_begin(App* a);
void app_end(App* a);

void init_audio(void);
void deinit_audio(void);
void play_sound(int len);

int btn_pressed(const App* a, Btn btn);
int btn_just_pressed(const App* a, Btn btn);
int btn_just_released(const App* a, Btn btn);

#endif