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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
/*
* Copyright 2011-2017 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
#ifndef ENTRY_H_HEADER_GUARD
#define ENTRY_H_HEADER_GUARD
#include "dbg.h"
#include <bx/bx.h>
#include <bx/string.h>
namespace bx { struct FileReaderI; struct FileWriterI; struct AllocatorI; }
extern "C" int _main_(int _argc, char** _argv);
#define ENTRY_WINDOW_FLAG_NONE UINT32_C(0x00000000)
#define ENTRY_WINDOW_FLAG_ASPECT_RATIO UINT32_C(0x00000001)
#define ENTRY_WINDOW_FLAG_FRAME UINT32_C(0x00000002)
#ifndef ENTRY_CONFIG_IMPLEMENT_MAIN
# define ENTRY_CONFIG_IMPLEMENT_MAIN 0
#endif // ENTRY_CONFIG_IMPLEMENT_MAIN
#if ENTRY_CONFIG_IMPLEMENT_MAIN
#define ENTRY_IMPLEMENT_MAIN(_app, _name, _description) \
int _main_(int _argc, char** _argv) \
{ \
_app app(_name, _description); \
return entry::runApp(&app, _argc, _argv); \
}
#else
#define ENTRY_IMPLEMENT_MAIN(_app, _name, _description) \
_app s_ ## _app ## App(_name, _description)
#endif // ENTRY_CONFIG_IMPLEMENT_MAIN
namespace entry
{
struct WindowHandle { uint16_t idx; };
inline bool isValid(WindowHandle _handle) { return UINT16_MAX != _handle.idx; }
struct GamepadHandle { uint16_t idx; };
inline bool isValid(GamepadHandle _handle) { return UINT16_MAX != _handle.idx; }
struct MouseButton
{
enum Enum
{
None,
Left,
Middle,
Right,
Count
};
};
struct GamepadAxis
{
enum Enum
{
LeftX,
LeftY,
LeftZ,
RightX,
RightY,
RightZ,
Count
};
};
struct Modifier
{
enum Enum
{
None = 0,
LeftAlt = 0x01,
RightAlt = 0x02,
LeftCtrl = 0x04,
RightCtrl = 0x08,
LeftShift = 0x10,
RightShift = 0x20,
LeftMeta = 0x40,
RightMeta = 0x80,
};
};
struct Key
{
enum Enum
{
None = 0,
Esc,
Return,
Tab,
Space,
Backspace,
Up,
Down,
Left,
Right,
Insert,
Delete,
Home,
End,
PageUp,
PageDown,
Print,
Plus,
Minus,
LeftBracket,
RightBracket,
Semicolon,
Quote,
Comma,
Period,
Slash,
Backslash,
Tilde,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
NumPad0,
NumPad1,
NumPad2,
NumPad3,
NumPad4,
NumPad5,
NumPad6,
NumPad7,
NumPad8,
NumPad9,
Key0,
Key1,
Key2,
Key3,
Key4,
Key5,
Key6,
Key7,
Key8,
Key9,
KeyA,
KeyB,
KeyC,
KeyD,
KeyE,
KeyF,
KeyG,
KeyH,
KeyI,
KeyJ,
KeyK,
KeyL,
KeyM,
KeyN,
KeyO,
KeyP,
KeyQ,
KeyR,
KeyS,
KeyT,
KeyU,
KeyV,
KeyW,
KeyX,
KeyY,
KeyZ,
GamepadA,
GamepadB,
GamepadX,
GamepadY,
GamepadThumbL,
GamepadThumbR,
GamepadShoulderL,
GamepadShoulderR,
GamepadUp,
GamepadDown,
GamepadLeft,
GamepadRight,
GamepadBack,
GamepadStart,
GamepadGuide,
Count
};
};
struct Suspend
{
enum Enum
{
WillSuspend,
DidSuspend,
WillResume,
DidResume,
Count
};
};
const char* getName(Key::Enum _key);
struct MouseState
{
MouseState()
: m_mx(0)
, m_my(0)
, m_mz(0)
{
for (uint32_t ii = 0; ii < entry::MouseButton::Count; ++ii)
{
m_buttons[ii] = entry::MouseButton::None;
}
}
int32_t m_mx;
int32_t m_my;
int32_t m_mz;
uint8_t m_buttons[entry::MouseButton::Count];
};
struct GamepadState
{
GamepadState()
{
bx::memSet(m_axis, 0, sizeof(m_axis) );
}
int32_t m_axis[entry::GamepadAxis::Count];
};
bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse = NULL);
bx::FileReaderI* getFileReader();
bx::FileWriterI* getFileWriter();
bx::AllocatorI* getAllocator();
WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags = ENTRY_WINDOW_FLAG_NONE, const char* _title = "");
void destroyWindow(WindowHandle _handle);
void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y);
void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height);
void setWindowTitle(WindowHandle _handle, const char* _title);
void toggleWindowFrame(WindowHandle _handle);
void toggleFullscreen(WindowHandle _handle);
void setMouseLock(WindowHandle _handle, bool _lock);
void setCurrentDir(const char* _dir);
struct WindowState
{
WindowState()
: m_width(0)
, m_height(0)
, m_nwh(NULL)
{
m_handle.idx = UINT16_MAX;
}
WindowHandle m_handle;
uint32_t m_width;
uint32_t m_height;
MouseState m_mouse;
void* m_nwh;
};
bool processWindowEvents(WindowState& _state, uint32_t& _debug, uint32_t& _reset);
class BX_NO_VTABLE AppI
{
public:
///
AppI(const char* _name, const char* _description);
///
virtual ~AppI() = 0;
///
virtual void init(int32_t _argc, const char* const* _argv, uint32_t _width, uint32_t _height) = 0;
///
virtual int shutdown() = 0;
///
virtual bool update() = 0;
///
const char* getName() const;
///
const char* getDescription() const;
///
AppI* getNext();
AppI* m_next;
private:
const char* m_name;
const char* m_description;
};
///
AppI* getFirstApp();
///
uint32_t getNumApps();
///
int runApp(AppI* _app, int _argc, const char* const* _argv);
} // namespace entry
#endif // ENTRY_H_HEADER_GUARD
|