rgss 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.clang-format +6 -0
- data/.gitignore +167 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/Rakefile +9 -0
- data/ext/rgss/cglm-v0.7.9.tar.gz +0 -0
- data/ext/rgss/color.c +599 -0
- data/ext/rgss/entity.c +373 -0
- data/ext/rgss/extconf.rb +53 -0
- data/ext/rgss/font.c +135 -0
- data/ext/rgss/game.c +469 -0
- data/ext/rgss/game.h +99 -0
- data/ext/rgss/gl.c +3217 -0
- data/ext/rgss/glad.c +1140 -0
- data/ext/rgss/glad.h +2129 -0
- data/ext/rgss/glfw.c +1453 -0
- data/ext/rgss/graphics.c +324 -0
- data/ext/rgss/image.c +274 -0
- data/ext/rgss/input.c +745 -0
- data/ext/rgss/khrplatform.h +290 -0
- data/ext/rgss/mat4.c +279 -0
- data/ext/rgss/pax_global_header +1 -0
- data/ext/rgss/point.c +253 -0
- data/ext/rgss/rect.c +449 -0
- data/ext/rgss/rgss.c +56 -0
- data/ext/rgss/rgss.h +241 -0
- data/ext/rgss/stb_image.h +7762 -0
- data/ext/rgss/stb_image_write.h +1690 -0
- data/ext/rgss/stb_rect_pack.h +628 -0
- data/ext/rgss/stb_truetype.h +5011 -0
- data/ext/rgss/utf8.h +1652 -0
- data/ext/rgss/uthash.h +1133 -0
- data/ext/rgss/vec.c +114 -0
- data/ext/rgss/vec.h +192 -0
- data/ext/rgss/vec2.c +489 -0
- data/ext/rgss/vec3.c +751 -0
- data/ext/rgss/vec4.c +681 -0
- data/lib/rgss.rb +140 -0
- data/lib/rgss/batch.rb +57 -0
- data/lib/rgss/blend.rb +47 -0
- data/lib/rgss/game_object.rb +28 -0
- data/lib/rgss/plane.rb +95 -0
- data/lib/rgss/renderable.rb +158 -0
- data/lib/rgss/rgss.so +0 -0
- data/lib/rgss/shader.rb +94 -0
- data/lib/rgss/shaders/sprite-frag.glsl +40 -0
- data/lib/rgss/shaders/sprite-vert.glsl +17 -0
- data/lib/rgss/sprite.rb +139 -0
- data/lib/rgss/stubs/color.rb +318 -0
- data/lib/rgss/stubs/gl.rb +1999 -0
- data/lib/rgss/stubs/glfw.rb +626 -0
- data/lib/rgss/stubs/rect.rb +324 -0
- data/lib/rgss/stubs/rpg.rb +267 -0
- data/lib/rgss/stubs/tone.rb +65 -0
- data/lib/rgss/texture.rb +132 -0
- data/lib/rgss/tilemap.rb +116 -0
- data/lib/rgss/version.rb +3 -0
- data/lib/rgss/viewport.rb +67 -0
- data/rgss.gemspec +44 -0
- data/test.png +0 -0
- metadata +178 -0
data/ext/rgss/game.c
ADDED
@@ -0,0 +1,469 @@
|
|
1
|
+
|
2
|
+
#include "glad.h"
|
3
|
+
#include "game.h"
|
4
|
+
|
5
|
+
VALUE rb_mGame;
|
6
|
+
VALUE rb_mAudio;
|
7
|
+
|
8
|
+
#define RGSS_MAX_TPS 240.0
|
9
|
+
#define RGSS_MIN_TPS 1.0
|
10
|
+
#define RGSS_DEFAULT_TPS (1.0 / 30.0)
|
11
|
+
#define IVAR_TITLE "@title"
|
12
|
+
#define IVAR_ICON "@icon"
|
13
|
+
#define IVAR_CLOSING "@close_procs"
|
14
|
+
|
15
|
+
RGSS_Game RGSS_GAME;
|
16
|
+
|
17
|
+
static void RGSS_Game_ErrorCallback(int code, const char *message)
|
18
|
+
{
|
19
|
+
switch (code)
|
20
|
+
{
|
21
|
+
case GLFW_NO_ERROR: break;
|
22
|
+
case GLFW_NOT_INITIALIZED: rb_raise(rb_eRuntimeError, "Game has not been created");
|
23
|
+
case GLFW_NO_WINDOW_CONTEXT:
|
24
|
+
case GLFW_NO_CURRENT_CONTEXT: rb_raise(rb_eRuntimeError, "no OpenGL context current on calling thread");
|
25
|
+
case GLFW_INVALID_ENUM: rb_raise(rb_eArgError, "an invalid enum value was specified");
|
26
|
+
case GLFW_INVALID_VALUE: rb_raise(rb_eArgError, "an invalid argument was specified");
|
27
|
+
case GLFW_OUT_OF_MEMORY: rb_raise(rb_eNoMemError, "out of memory");
|
28
|
+
case GLFW_API_UNAVAILABLE:
|
29
|
+
case GLFW_VERSION_UNAVAILABLE: rb_raise(rb_eRuntimeError, "platform does not support OpenGL 3.3");
|
30
|
+
case GLFW_PLATFORM_ERROR:
|
31
|
+
case GLFW_FORMAT_UNAVAILABLE: rb_raise(rb_eRuntimeError, "%s", message);
|
32
|
+
default: rb_raise(rb_eRuntimeError, "%s", message);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
static inline void RGSS_Game_ParseOpt(VALUE opts, const char *name, int ifnone, int *result)
|
37
|
+
{
|
38
|
+
if (result == NULL)
|
39
|
+
return;
|
40
|
+
|
41
|
+
if (opts == Qnil)
|
42
|
+
*result = ifnone;
|
43
|
+
else
|
44
|
+
{
|
45
|
+
VALUE opt = rb_hash_aref(opts, STR2SYM(name));
|
46
|
+
*result = (opt == Qnil) ? ifnone : RTEST(opt);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
static void RGSS_Game_CloseCallback(GLFWwindow *window)
|
51
|
+
{
|
52
|
+
VALUE ary = rb_iv_get(rb_mGame, IVAR_CLOSING);
|
53
|
+
if (ary == Qnil)
|
54
|
+
return;
|
55
|
+
|
56
|
+
VALUE args = rb_ary_new();
|
57
|
+
long length = rb_array_len(ary);
|
58
|
+
for (long i = 0; i < length; i++)
|
59
|
+
{
|
60
|
+
rb_proc_call(rb_ary_entry(ary, i), args);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
static VALUE RGSS_Game_Handle(VALUE game)
|
65
|
+
{
|
66
|
+
return RGSS_GAME.window ? Data_Wrap_Struct(rb_cWindow, NULL, RUBY_NEVER_FREE, RGSS_GAME.window) : Qnil;
|
67
|
+
}
|
68
|
+
|
69
|
+
static VALUE RGSS_Game_GetTitle(VALUE game)
|
70
|
+
{
|
71
|
+
return rb_iv_get(game, IVAR_TITLE);
|
72
|
+
}
|
73
|
+
|
74
|
+
static VALUE RGSS_Game_SetTitle(VALUE game, VALUE title)
|
75
|
+
{
|
76
|
+
RGSS_ASSERT_GAME;
|
77
|
+
rb_iv_set(game, IVAR_TITLE, title);
|
78
|
+
glfwSetWindowTitle(RGSS_GAME.window, RTEST(title) ? StringValueCStr(title) : "");
|
79
|
+
return title;
|
80
|
+
}
|
81
|
+
|
82
|
+
static VALUE RGSS_Game_GetFullscreen(VALUE game)
|
83
|
+
{
|
84
|
+
RGSS_ASSERT_GAME;
|
85
|
+
GLFWmonitor *monitor = glfwGetWindowMonitor(RGSS_GAME.window);
|
86
|
+
return RB_BOOL(monitor != NULL);
|
87
|
+
}
|
88
|
+
|
89
|
+
static VALUE RGSS_Game_SetFullscreen(VALUE game, VALUE fullscreen)
|
90
|
+
{
|
91
|
+
RGSS_ASSERT_GAME;
|
92
|
+
GLFWmonitor *monitor = RTEST(fullscreen) ? glfwGetPrimaryMonitor() : NULL;
|
93
|
+
GLFWmonitor *game_monitor = glfwGetWindowMonitor(RGSS_GAME.window);
|
94
|
+
|
95
|
+
if (monitor != game_monitor)
|
96
|
+
{
|
97
|
+
int rect[4];
|
98
|
+
int rate = GLFW_DONT_CARE;
|
99
|
+
|
100
|
+
if (monitor)
|
101
|
+
{
|
102
|
+
glfwGetWindowPos(RGSS_GAME.window, &RGSS_GAME.rect[0], &RGSS_GAME.rect[1]);
|
103
|
+
glfwGetWindowSize(RGSS_GAME.window, &RGSS_GAME.rect[2], &RGSS_GAME.rect[3]);
|
104
|
+
|
105
|
+
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
106
|
+
rect[0] = 0;
|
107
|
+
rect[1] = 0;
|
108
|
+
rect[2] = mode->width;
|
109
|
+
rect[3] = mode->height;
|
110
|
+
rate = mode->refreshRate;
|
111
|
+
}
|
112
|
+
else
|
113
|
+
{
|
114
|
+
memcpy(rect, RGSS_GAME.rect, sizeof(int) * 4);
|
115
|
+
}
|
116
|
+
|
117
|
+
glfwSetWindowMonitor(RGSS_GAME.window, monitor, rect[0], rect[1], rect[2], rect[3], rate);
|
118
|
+
|
119
|
+
}
|
120
|
+
return fullscreen;
|
121
|
+
}
|
122
|
+
|
123
|
+
static VALUE RGSS_Game_Center(VALUE game)
|
124
|
+
{
|
125
|
+
if (RGSS_GAME.window == NULL)
|
126
|
+
return Qnil;
|
127
|
+
|
128
|
+
GLFWmonitor *monitor = glfwGetWindowMonitor(RGSS_GAME.window);
|
129
|
+
if (monitor != NULL)
|
130
|
+
return Qnil;
|
131
|
+
|
132
|
+
monitor = glfwGetPrimaryMonitor();
|
133
|
+
int sx, sy, sw, sh;
|
134
|
+
glfwGetMonitorWorkarea(monitor, &sx, &sy, &sw, &sh);
|
135
|
+
|
136
|
+
int ww, wh;
|
137
|
+
glfwGetWindowSize(RGSS_GAME.window, &ww, &wh);
|
138
|
+
|
139
|
+
int cx = sx + ((sw - ww) / 2);
|
140
|
+
int cy = sy + ((sh - wh) / 2);
|
141
|
+
glfwSetWindowPos(RGSS_GAME.window, cx, cy);
|
142
|
+
return Qnil;
|
143
|
+
}
|
144
|
+
|
145
|
+
static VALUE RGSS_Game_Create(int argc, VALUE *argv, VALUE game)
|
146
|
+
{
|
147
|
+
VALUE width, height, title, opts;
|
148
|
+
rb_scan_args(argc, argv, "21:", &width, &height, &title, &opts);
|
149
|
+
|
150
|
+
if (!glfwInit())
|
151
|
+
rb_raise(rb_eRuntimeError, "failed to initialize GLFW");
|
152
|
+
|
153
|
+
int w = NUM2INT(width);
|
154
|
+
int h = NUM2INT(height);
|
155
|
+
if (w < 1)
|
156
|
+
rb_raise(rb_eArgError, "width must be greater than 0");
|
157
|
+
if (h < 1)
|
158
|
+
rb_raise(rb_eArgError, "height must be greater than 0");
|
159
|
+
|
160
|
+
int resizable, fullscreen, vsync, topmost, decorated, visible, locked, debug;
|
161
|
+
RGSS_Game_ParseOpt(opts, "resizable", GLFW_FALSE, &resizable);
|
162
|
+
RGSS_Game_ParseOpt(opts, "fullscren", GLFW_FALSE, &fullscreen);
|
163
|
+
RGSS_Game_ParseOpt(opts, "vsync", GLFW_TRUE, &vsync);
|
164
|
+
RGSS_Game_ParseOpt(opts, "topmost", GLFW_FALSE, &topmost);
|
165
|
+
RGSS_Game_ParseOpt(opts, "decorated", GLFW_TRUE, &decorated);
|
166
|
+
RGSS_Game_ParseOpt(opts, "visible", GLFW_TRUE, &visible);
|
167
|
+
RGSS_Game_ParseOpt(opts, "locked", GLFW_FALSE, &locked);
|
168
|
+
RGSS_Game_ParseOpt(opts, "debug", GLFW_FALSE, &RGSS_GAME.debug);
|
169
|
+
|
170
|
+
glfwDefaultWindowHints();
|
171
|
+
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
|
172
|
+
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
173
|
+
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
174
|
+
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
175
|
+
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
176
|
+
glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
|
177
|
+
glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
|
178
|
+
glfwWindowHint(GLFW_DECORATED, decorated);
|
179
|
+
glfwWindowHint(GLFW_RESIZABLE, resizable);
|
180
|
+
glfwWindowHint(GLFW_FLOATING, topmost);
|
181
|
+
glfwWindowHint(GLFW_VISIBLE, visible);
|
182
|
+
if (RGSS_GAME.debug)
|
183
|
+
{
|
184
|
+
rb_gv_set("$DEBUG", Qtrue);
|
185
|
+
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, debug);
|
186
|
+
}
|
187
|
+
|
188
|
+
const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
189
|
+
glfwWindowHint(GLFW_RED_BITS, mode->redBits);
|
190
|
+
glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
|
191
|
+
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
|
192
|
+
|
193
|
+
rb_iv_set(game, IVAR_TITLE, title);
|
194
|
+
const char *str = RTEST(title) ? StringValueCStr(title) : "";
|
195
|
+
RGSS_GAME.window = glfwCreateWindow(w, h, str, NULL, NULL);
|
196
|
+
if (RGSS_GAME.window == NULL)
|
197
|
+
rb_raise(rb_eRuntimeError, "failed to create OpenGL context");
|
198
|
+
|
199
|
+
glfwMakeContextCurrent(RGSS_GAME.window);
|
200
|
+
if (!gladLoadGL())
|
201
|
+
{
|
202
|
+
GLADloadproc proc = (GLADloadproc) glfwGetProcAddress;
|
203
|
+
if (!gladLoadGLLoader(proc))
|
204
|
+
rb_raise(rb_eRuntimeError, "failed to link OpenGL");
|
205
|
+
}
|
206
|
+
|
207
|
+
if (fullscreen)
|
208
|
+
RGSS_Game_SetFullscreen(game, Qtrue);
|
209
|
+
if (locked)
|
210
|
+
glfwSetWindowAspectRatio(RGSS_GAME.window, w, h);
|
211
|
+
|
212
|
+
RGSS_Graphics_Init(RGSS_GAME.window, w, h, vsync);
|
213
|
+
RGSS_Input_Init(RGSS_GAME.window);
|
214
|
+
|
215
|
+
glfwSetWindowCloseCallback(RGSS_GAME.window, RGSS_Game_CloseCallback);
|
216
|
+
RGSS_Game_Center(game);
|
217
|
+
RGSS_GAME.speed = 1.0;
|
218
|
+
return Qnil;
|
219
|
+
}
|
220
|
+
|
221
|
+
static inline void RGSS_Game_UpdateTime(void)
|
222
|
+
{
|
223
|
+
if (RGSS_GAME.time.time_count < 1.0)
|
224
|
+
return;
|
225
|
+
|
226
|
+
RGSS_GAME.time.fps = RGSS_GAME.time.fps_count;
|
227
|
+
RGSS_GAME.time.fps_count = 0.0;
|
228
|
+
RGSS_GAME.time.ticks = RGSS_GAME.time.tick_count;
|
229
|
+
RGSS_GAME.time.tick_count = 0.0;
|
230
|
+
RGSS_GAME.time.time_count -= 1.0;
|
231
|
+
}
|
232
|
+
|
233
|
+
static inline double RGSS_Game_GetDelta(void)
|
234
|
+
{
|
235
|
+
double now = glfwGetTime();
|
236
|
+
double delta = now - RGSS_GAME.time.last;
|
237
|
+
RGSS_GAME.time.last = now;
|
238
|
+
RGSS_GAME.time.time_count += delta;
|
239
|
+
return delta;
|
240
|
+
}
|
241
|
+
|
242
|
+
static VALUE RGSS_Game_Main(int argc, VALUE *argv, VALUE game)
|
243
|
+
{
|
244
|
+
RGSS_ASSERT_GAME;
|
245
|
+
VALUE tps;
|
246
|
+
rb_scan_args(argc, argv, "01", &tps);
|
247
|
+
|
248
|
+
if (RTEST(tps))
|
249
|
+
RGSS_GAME.time.target_tps = 1.0 / NUM2DBL(tps);
|
250
|
+
if (RGSS_GAME.time.target_tps < 1.0)
|
251
|
+
RGSS_GAME.time.target_tps = RGSS_DEFAULT_TPS;
|
252
|
+
|
253
|
+
ID update = rb_intern("update");
|
254
|
+
double delta;
|
255
|
+
double accumulator = 0.0;
|
256
|
+
|
257
|
+
while (!glfwWindowShouldClose(RGSS_GAME.window))
|
258
|
+
{
|
259
|
+
delta = RGSS_Game_GetDelta();
|
260
|
+
accumulator = (accumulator + delta) * RGSS_GAME.speed;
|
261
|
+
|
262
|
+
while (accumulator >= RGSS_GAME.time.target_tps)
|
263
|
+
{
|
264
|
+
accumulator -= RGSS_GAME.time.target_tps;
|
265
|
+
|
266
|
+
// rb_funcall(game, update, 1, DBL2NUM(delta));
|
267
|
+
rb_funcall(game, update, 1, DBL2NUM(RGSS_GAME.time.target_tps));
|
268
|
+
RGSS_Input_Update();
|
269
|
+
RGSS_GAME.time.tick_count++;
|
270
|
+
RGSS_GAME.time.total_ticks++;
|
271
|
+
}
|
272
|
+
|
273
|
+
RGSS_Graphics_Render(accumulator / RGSS_GAME.time.target_tps);
|
274
|
+
glfwPollEvents();
|
275
|
+
RGSS_Game_UpdateTime();
|
276
|
+
}
|
277
|
+
|
278
|
+
return Qnil;
|
279
|
+
}
|
280
|
+
|
281
|
+
static VALUE RGSS_Game_GetSpeed(VALUE game)
|
282
|
+
{
|
283
|
+
return DBL2NUM(RGSS_GAME.window ? 0.0 : RGSS_GAME.speed);
|
284
|
+
}
|
285
|
+
|
286
|
+
static VALUE RGSS_Game_SetSpeed(VALUE game, VALUE speed)
|
287
|
+
{
|
288
|
+
RGSS_ASSERT_GAME;
|
289
|
+
RGSS_GAME.speed = RGSS_MAX(1.0, NUM2DBL(speed));
|
290
|
+
return speed;
|
291
|
+
}
|
292
|
+
|
293
|
+
static VALUE RGSS_Game_Close(int argc, VALUE *argv, VALUE game)
|
294
|
+
{
|
295
|
+
RGSS_ASSERT_GAME;
|
296
|
+
|
297
|
+
VALUE close;
|
298
|
+
rb_scan_args(argc, argv, "01", &close);
|
299
|
+
|
300
|
+
glfwSetWindowShouldClose(RGSS_GAME.window, argc > 0 ? RTEST(close) : GLFW_TRUE);
|
301
|
+
return Qnil;
|
302
|
+
}
|
303
|
+
|
304
|
+
static VALUE RGSS_Game_Terminate(VALUE game)
|
305
|
+
{
|
306
|
+
// TODO: Cleanup
|
307
|
+
glfwTerminate();
|
308
|
+
return Qnil;
|
309
|
+
}
|
310
|
+
|
311
|
+
static VALUE RGSS_Game_GetIcon(VALUE game)
|
312
|
+
{
|
313
|
+
return rb_iv_get(game, IVAR_ICON);
|
314
|
+
}
|
315
|
+
|
316
|
+
static VALUE RGSS_Game_SetIcon(VALUE game, VALUE image)
|
317
|
+
{
|
318
|
+
RGSS_ASSERT_GAME;
|
319
|
+
|
320
|
+
if (RTEST(image))
|
321
|
+
{
|
322
|
+
GLFWimage *img;
|
323
|
+
VALUE ivar;
|
324
|
+
|
325
|
+
if (RB_TYPE_P(image, T_STRING))
|
326
|
+
{
|
327
|
+
img = xmalloc(sizeof(GLFWimage));
|
328
|
+
RGSS_Image_Load(StringValueCStr(image), &img->width, &img->height, &img->pixels);
|
329
|
+
ivar = Data_Wrap_Struct(rb_cImage, NULL, RGSS_Image_Free, img);
|
330
|
+
}
|
331
|
+
else if (RB_TYPE_P(image, T_DATA))
|
332
|
+
{
|
333
|
+
img = DATA_PTR(image);
|
334
|
+
ivar = image;
|
335
|
+
}
|
336
|
+
else
|
337
|
+
{
|
338
|
+
rb_raise(rb_eTypeError, "%s is not an RGSS::Image, String, or NilClass", CLASS_NAME(image));
|
339
|
+
}
|
340
|
+
|
341
|
+
rb_iv_set(game, IVAR_ICON, ivar);
|
342
|
+
glfwSetWindowIcon(RGSS_GAME.window, 1, img);
|
343
|
+
}
|
344
|
+
else
|
345
|
+
{
|
346
|
+
rb_iv_set(game, IVAR_ICON, Qnil);
|
347
|
+
glfwSetWindowIcon(RGSS_GAME.window, 0, NULL);
|
348
|
+
}
|
349
|
+
return image;
|
350
|
+
}
|
351
|
+
|
352
|
+
static VALUE RGSS_Game_GetTicks(VALUE game)
|
353
|
+
{
|
354
|
+
return ULL2NUM(RGSS_GAME.window ? RGSS_GAME.time.total_ticks : 0);
|
355
|
+
}
|
356
|
+
|
357
|
+
static VALUE RGSS_Game_Focus(VALUE game)
|
358
|
+
{
|
359
|
+
if (RGSS_GAME.window)
|
360
|
+
glfwFocusWindow(RGSS_GAME.window);
|
361
|
+
return Qnil;
|
362
|
+
}
|
363
|
+
|
364
|
+
static VALUE RGSS_Game_RequestAttention(VALUE game)
|
365
|
+
{
|
366
|
+
if (RGSS_GAME.window)
|
367
|
+
glfwRequestWindowAttention(RGSS_GAME.window);
|
368
|
+
return Qnil;
|
369
|
+
}
|
370
|
+
|
371
|
+
static VALUE RGSS_Game_Minimize(VALUE game)
|
372
|
+
{
|
373
|
+
if (RGSS_GAME.window)
|
374
|
+
glfwIconifyWindow(RGSS_GAME.window);
|
375
|
+
return Qnil;
|
376
|
+
}
|
377
|
+
|
378
|
+
static VALUE RGSS_Game_Maximize(VALUE game)
|
379
|
+
{
|
380
|
+
if (RGSS_GAME.window)
|
381
|
+
glfwMaximizeWindow(RGSS_GAME.window);
|
382
|
+
return Qnil;
|
383
|
+
}
|
384
|
+
|
385
|
+
static VALUE RGSS_Game_IsMinimized(VALUE game)
|
386
|
+
{
|
387
|
+
return RGSS_GAME.window ? RB_BOOL(glfwGetWindowAttrib(RGSS_GAME.window, GLFW_ICONIFIED)) : Qnil;
|
388
|
+
}
|
389
|
+
|
390
|
+
static VALUE RGSS_Game_IsMaximized(VALUE game)
|
391
|
+
{
|
392
|
+
return RGSS_GAME.window ? RB_BOOL(glfwGetWindowAttrib(RGSS_GAME.window, GLFW_MAXIMIZED)) : Qnil;
|
393
|
+
}
|
394
|
+
|
395
|
+
static VALUE RGSS_Game_Restore(VALUE game)
|
396
|
+
{
|
397
|
+
if (RGSS_GAME.window)
|
398
|
+
glfwRestoreWindow(RGSS_GAME.window);
|
399
|
+
return Qnil;
|
400
|
+
}
|
401
|
+
|
402
|
+
static VALUE RGSS_Game_IsFocused(VALUE game)
|
403
|
+
{
|
404
|
+
return RGSS_GAME.window ? RB_BOOL(glfwGetWindowAttrib(RGSS_GAME.window, GLFW_FOCUSED)) : Qnil;
|
405
|
+
}
|
406
|
+
|
407
|
+
static VALUE RGSS_Game_IsTopmost(VALUE game)
|
408
|
+
{
|
409
|
+
return RGSS_GAME.window ? RB_BOOL(glfwGetWindowAttrib(RGSS_GAME.window, GLFW_FLOATING)) : Qnil;
|
410
|
+
}
|
411
|
+
|
412
|
+
static VALUE RGSS_Game_IsClosing(VALUE game)
|
413
|
+
{
|
414
|
+
return RGSS_GAME.window ? RB_BOOL(glfwWindowShouldClose(RGSS_GAME.window)) : Qnil;
|
415
|
+
}
|
416
|
+
|
417
|
+
static VALUE RGSS_Game_OnClose(VALUE game)
|
418
|
+
{
|
419
|
+
rb_need_block();
|
420
|
+
|
421
|
+
VALUE ary = rb_iv_get(game, IVAR_CLOSING);
|
422
|
+
if (ary == Qnil)
|
423
|
+
{
|
424
|
+
ary = rb_ary_new();
|
425
|
+
rb_iv_set(game, IVAR_CLOSING, ary);
|
426
|
+
}
|
427
|
+
|
428
|
+
rb_ary_push(ary, rb_block_proc());
|
429
|
+
return Qnil;
|
430
|
+
}
|
431
|
+
|
432
|
+
|
433
|
+
void RGSS_Init_Game(VALUE parent)
|
434
|
+
{
|
435
|
+
rb_mGame = rb_define_module_under(parent, "Game");
|
436
|
+
rb_mAudio = rb_define_module_under(parent, "Audio");
|
437
|
+
|
438
|
+
rb_define_singleton_methodm1(rb_mGame, "create", RGSS_Game_Create, -1);
|
439
|
+
rb_define_singleton_method0(rb_mGame, "terminate", RGSS_Game_Terminate, 0);
|
440
|
+
rb_define_singleton_methodm1(rb_mGame, "main", RGSS_Game_Main, -1);
|
441
|
+
rb_define_singleton_method0(rb_mGame, "window", RGSS_Game_Handle, 0);
|
442
|
+
rb_define_singleton_methodm1(rb_mGame, "close", RGSS_Game_Close, -1);
|
443
|
+
rb_define_singleton_method0(rb_mGame, "center", RGSS_Game_Center, 0);
|
444
|
+
|
445
|
+
rb_define_singleton_method0(rb_mGame, "fullscreen", RGSS_Game_GetFullscreen, 0);
|
446
|
+
rb_define_singleton_method1(rb_mGame, "fullscreen=", RGSS_Game_SetFullscreen, 1);
|
447
|
+
rb_define_singleton_method0(rb_mGame, "title", RGSS_Game_GetTitle, 0);
|
448
|
+
rb_define_singleton_method1(rb_mGame, "title=", RGSS_Game_SetTitle, 1);
|
449
|
+
rb_define_singleton_method0(rb_mGame, "icon", RGSS_Game_GetIcon, 0);
|
450
|
+
rb_define_singleton_method1(rb_mGame, "icon=", RGSS_Game_SetIcon, 1);
|
451
|
+
rb_define_singleton_method0(rb_mGame, "request_attention", RGSS_Game_RequestAttention, 0);
|
452
|
+
rb_define_singleton_method0(rb_mGame, "focus", RGSS_Game_Focus, 0);
|
453
|
+
rb_define_singleton_method0(rb_mGame, "minimize", RGSS_Game_Minimize, 0);
|
454
|
+
rb_define_singleton_method0(rb_mGame, "maximize", RGSS_Game_Maximize, 0);
|
455
|
+
rb_define_singleton_method0(rb_mGame, "restore", RGSS_Game_Restore, 0);
|
456
|
+
rb_define_singleton_method0(rb_mGame, "minimized?", RGSS_Game_IsMinimized, 0);
|
457
|
+
rb_define_singleton_method0(rb_mGame, "maximized?", RGSS_Game_IsMaximized, 0);
|
458
|
+
rb_define_singleton_method0(rb_mGame, "topmost?", RGSS_Game_IsTopmost, 0);
|
459
|
+
rb_define_singleton_method0(rb_mGame, "focused?", RGSS_Game_IsFocused, 0);
|
460
|
+
rb_define_singleton_method0(rb_mGame, "closing?", RGSS_Game_IsClosing, 0);
|
461
|
+
|
462
|
+
rb_define_singleton_method0(rb_mGame, "ticks", RGSS_Game_GetTicks, 0);
|
463
|
+
rb_define_singleton_method0(rb_mGame, "speed", RGSS_Game_GetSpeed, 0);
|
464
|
+
rb_define_singleton_method1(rb_mGame, "speed=", RGSS_Game_SetSpeed, 1);
|
465
|
+
|
466
|
+
rb_define_singleton_method0(rb_mGame, "on_close", RGSS_Game_OnClose, 0);
|
467
|
+
|
468
|
+
glfwSetErrorCallback(RGSS_Game_ErrorCallback);
|
469
|
+
}
|