-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestlib.h
142 lines (112 loc) · 3.25 KB
/
testlib.h
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef TEST_H
#define TEST_H
/** conventions:
*
* Things that happen on the renderer thread are prefixed with
* renderer_
*
* Things that allocate from the per frame memory allocator are
* prefixed with frame_
*
* Functions that deal with objects are prefixed with objectname_
*/
#define MAX_NUM_CLOCKS 20
#define MAX_NUM_IMAGES 40
#define MAX_NUM_COMMANDS 60
#include <pthread.h>
#include <stdint.h>
#include "threadlib.h"
#include "memory.h"
#include "listlib.h"
#include "audio.h"
/* allocators */
extern ThreadBarrier render_barrier;
extern FixedAllocator clock_allocator;
extern FixedAllocator image_resource_allocator;
extern StackAllocator frame_allocator;
extern FixedAllocator command_allocator;
extern Queue render_queue;
extern uint32_t screen_width;
extern uint32_t screen_height;
/* initialize the internal allocators for the library. Must be called
before other functions */
void lib_init();
/* shuts down the renderer and frees memory. Must be called before
termination */
void lib_shutdown();
void begin_frame();
void end_frame();
typedef struct InputState_ {
int quit_requested;
float updown;
float leftright;
int action1;
} *InputState;
/* exported by test.scm */
void scm_init();
void step(int, InputState);
void terminate();
void resources_released();
/* provided by system specific lib */
void native_init();
InputState frame_inputstate();
long time_millis();
void sleep_millis(long millis);
/* exported by testlib.c */
typedef struct Clock_ {
long cycles; /* msecs */
float time_scale;
int paused;
} *Clock;
Clock clock_make();
void clock_free(Clock clock);
float clock_update(Clock clock, float delta); /* time in seconds */
long clock_time(Clock clock); /* time in cycles */
float clock_cycles_to_seconds(long cycles);
long clock_seconds_to_cycles(float seconds);
typedef struct ImageResource_ {
struct LLNode_ node;
int w, h;
unsigned int texture;
int channels;
unsigned char* data; /* shortlived, internal */
} *ImageResource;
ImageResource image_load(char * file);
int image_width(ImageResource resource);
int image_height(ImageResource resource);
void images_free();
typedef struct Sprite_ {
ImageResource resource;
float angle;
float originX;
float originY;
float displayX;
float displayY;
float w, h;
float u0, u1, v0, v1;
} *Sprite;
Sprite frame_make_sprite();
typedef struct SpriteList_ {
struct LLNode_ node;
Sprite sprite;
} *SpriteList;
SpriteList frame_spritelist_append(SpriteList list, Sprite sprite);
void spritelist_enqueue_for_screen(SpriteList list);
typedef void (*CommandFunction)(void*);
typedef struct Command_ {
struct DLLNode_ node;
CommandFunction function;
void *data;
} *Command;
Command command_make(CommandFunction function, void* data);
void command_free(Command command);
#define command_dequeue(queue) (Command)dequeue(queue)
void command_async(Queue queue, CommandFunction function, void* data);
void command_sync(Queue queue, ThreadBarrier b,
CommandFunction function, void* data);
#define renderer_enqueue(function, data) \
command_async(render_queue, (CommandFunction)function, (void*)data)
#define renderer_enqueue_sync(function, data) \
command_sync(render_queue, render_barrier, \
(CommandFunction)function, (void*)data)
#endif