summaryrefslogtreecommitdiff
path: root/plat.h
blob: 419d7fedf7cd3fdbbdb098e07265b09c9bd5bb57 (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
#ifndef plat_h
#define plat_h

#include "error.h"
#include "memory.h"
#include "render.h"

#ifdef assert
#undef assert
#endif

#define assert(expr) \
	imp_assert( \
		expr, \
		#expr, \
		__FILE__, \
		__LINE__ \
	)

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 File File;

typedef enum {
	file_flags_write       = 1 << 0,
	file_flags_read        = 1 << 1,
	file_flags_read_write  = 1 << 2,
	file_flags_create      = 1 << 3
} File_Flags;

typedef enum {
	file_whence_begin,
	file_whence_end,
	file_whence_cur
} File_Whence;

File* file_open(const char* name, File_Flags flags);
void file_close(File* file);
void file_read(File* file, void* buffer, int size);
void file_write(File* file, const void* buffer, int size);
void file_seek(File* file, int offset, File_Whence whence);
int file_size(File* file);
int file_exists(const char* name);

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 struct {
	int w, h, s, o, mpf;
	int fps;
	int mx, my;
	Error err;
	Colour* fb;
	Heap* heap;
} App;

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

#endif