summaryrefslogtreecommitdiff
path: root/src/screen.h
blob: 423af7ef23aebb3e5b7a2861906fe936e6e11d3a (plain)
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
#pragma once

#define _XOPEN_SOURCE   600
#define _POSIX_C_SOURCE 200112L
// #define _POSIX_C_SOURCE 200809L
#include <stdint.h>
#include <stdbool.h>
#include <pthread.h>

typedef struct {
    uint16_t width;
    uint16_t height;
    uint8_t image_count; // amount of frames in flight
    uint8_t image_front; // image being drawn to screen
    uint8_t image_recent; // last image that finished drawing
    uint8_t image_current; // current image being drawn
    pthread_mutex_t lock;
    uint32_t** images;
} Swapchain;

void swapchain_next(Swapchain* swapchain);
void swapchain_submit(Swapchain* swapchain);

struct Screen {
    Swapchain swapchain;
    float delta;
    void* internal;
};

#define Screen struct Screen

#define KEY_W       17
#define KEY_A       30
#define KEY_S       31
#define KEY_D       32
#define KEY_UP      103
#define KEY_DOWN    108
#define KEY_LEFT    105
#define KEY_RIGHT   106
#define KEY_MINUS   12
#define KEY_EQUALS  13
#define KEY_ESC     1

void init_screen(Screen* screen, uint16_t width, uint16_t height, const char* title);
bool poll_screen(Screen* screen);
void free_screen(Screen* screen);

bool key_pressed(int keycode);
bool key_down(int keycode);