ruby2d 0.9.4 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/ruby2d +1 -0
- data/{assets/linux/simple2d/src/simple2d.c → ext/ruby2d/common.c} +32 -32
- data/{assets/linux/simple2d/src → ext/ruby2d}/controllers.c +17 -17
- data/ext/ruby2d/extconf.rb +4 -34
- data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +75 -75
- data/{assets/linux/simple2d/src → ext/ruby2d}/gl2.c +20 -20
- data/{assets/linux/simple2d/src → ext/ruby2d}/gl3.c +29 -29
- data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +26 -26
- data/{assets/linux/simple2d/src → ext/ruby2d}/image.c +16 -16
- data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
- data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +17 -17
- data/ext/ruby2d/ruby2d.c +125 -126
- data/{assets/include/simple2d.h → ext/ruby2d/ruby2d.h} +207 -207
- data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
- data/{assets/linux/simple2d/src → ext/ruby2d}/sound.c +14 -14
- data/{assets/linux/simple2d/src → ext/ruby2d}/sprite.c +16 -16
- data/{assets/linux/simple2d/src → ext/ruby2d}/text.c +22 -22
- data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +61 -61
- data/lib/ruby2d/cli/build.rb +2 -7
- data/lib/ruby2d/version.rb +1 -1
- metadata +21 -26
- data/assets/linux/simple2d/Makefile +0 -260
- data/assets/linux/simple2d/bin/simple2d.sh +0 -1318
- data/assets/linux/simple2d/include/simple2d.h +0 -757
- data/assets/macos/lib/libsimple2d.a +0 -0
- data/assets/mingw/lib/libsimple2d.a +0 -0
@@ -1,30 +1,30 @@
|
|
1
1
|
// input.c
|
2
2
|
|
3
|
-
#include "
|
3
|
+
#include "ruby2d.h"
|
4
4
|
|
5
5
|
|
6
6
|
/*
|
7
7
|
* Get the mouse coordinates relative to the viewport
|
8
8
|
*/
|
9
|
-
void
|
9
|
+
void R2D_GetMouseOnViewport(R2D_Window *window, int wx, int wy, int *x, int *y) {
|
10
10
|
|
11
11
|
double scale; // viewport scale factor
|
12
12
|
int w, h; // width and height of scaled viewport
|
13
13
|
|
14
14
|
switch (window->viewport.mode) {
|
15
15
|
|
16
|
-
case
|
16
|
+
case R2D_FIXED: case R2D_EXPAND:
|
17
17
|
*x = wx / (window->orig_width / (double)window->viewport.width);
|
18
18
|
*y = wy / (window->orig_height / (double)window->viewport.height);
|
19
19
|
break;
|
20
20
|
|
21
|
-
case
|
22
|
-
|
21
|
+
case R2D_SCALE:
|
22
|
+
R2D_GL_GetViewportScale(window, &w, &h, &scale);
|
23
23
|
*x = wx * 1 / scale - (window->width - w) / (2.0 * scale);
|
24
24
|
*y = wy * 1 / scale - (window->height - h) / (2.0 * scale);
|
25
25
|
break;
|
26
26
|
|
27
|
-
case
|
27
|
+
case R2D_STRETCH:
|
28
28
|
*x = wx * window->viewport.width / (double)window->width;
|
29
29
|
*y = wy * window->viewport.height / (double)window->height;
|
30
30
|
break;
|
@@ -35,7 +35,7 @@ void S2D_GetMouseOnViewport(S2D_Window *window, int wx, int wy, int *x, int *y)
|
|
35
35
|
/*
|
36
36
|
* Show the cursor over the window
|
37
37
|
*/
|
38
|
-
void
|
38
|
+
void R2D_ShowCursor() {
|
39
39
|
SDL_ShowCursor(SDL_ENABLE);
|
40
40
|
}
|
41
41
|
|
@@ -43,6 +43,6 @@ void S2D_ShowCursor() {
|
|
43
43
|
/*
|
44
44
|
* Hide the cursor over the window
|
45
45
|
*/
|
46
|
-
void
|
46
|
+
void R2D_HideCursor() {
|
47
47
|
SDL_ShowCursor(SDL_DISABLE);
|
48
48
|
}
|
@@ -1,31 +1,31 @@
|
|
1
1
|
// music.c
|
2
2
|
|
3
|
-
#include "
|
3
|
+
#include "ruby2d.h"
|
4
4
|
|
5
5
|
|
6
6
|
/*
|
7
7
|
* Create the music
|
8
8
|
*/
|
9
|
-
|
10
|
-
|
9
|
+
R2D_Music *R2D_CreateMusic(const char *path) {
|
10
|
+
R2D_Init();
|
11
11
|
|
12
12
|
// Check if music file exists
|
13
|
-
if (!
|
14
|
-
|
13
|
+
if (!R2D_FileExists(path)) {
|
14
|
+
R2D_Error("R2D_CreateMusic", "Music file `%s` not found", path);
|
15
15
|
return NULL;
|
16
16
|
}
|
17
17
|
|
18
18
|
// Allocate the music structure
|
19
|
-
|
19
|
+
R2D_Music *mus = (R2D_Music *) malloc(sizeof(R2D_Music));
|
20
20
|
if (!mus) {
|
21
|
-
|
21
|
+
R2D_Error("R2D_CreateMusic", "Out of memory!");
|
22
22
|
return NULL;
|
23
23
|
}
|
24
24
|
|
25
25
|
// Load the music data from file
|
26
26
|
mus->data = Mix_LoadMUS(path);
|
27
27
|
if (!mus->data) {
|
28
|
-
|
28
|
+
R2D_Error("Mix_LoadMUS", Mix_GetError());
|
29
29
|
free(mus);
|
30
30
|
return NULL;
|
31
31
|
}
|
@@ -40,7 +40,7 @@ S2D_Music *S2D_CreateMusic(const char *path) {
|
|
40
40
|
/*
|
41
41
|
* Play the music
|
42
42
|
*/
|
43
|
-
void
|
43
|
+
void R2D_PlayMusic(R2D_Music *mus, bool loop) {
|
44
44
|
if (!mus) return;
|
45
45
|
|
46
46
|
// If looping, set to -1 times; else 0
|
@@ -49,7 +49,7 @@ void S2D_PlayMusic(S2D_Music *mus, bool loop) {
|
|
49
49
|
// times: 0 == once, -1 == forever
|
50
50
|
if (Mix_PlayMusic(mus->data, times) == -1) {
|
51
51
|
// No music for you
|
52
|
-
|
52
|
+
R2D_Error("R2D_PlayMusic", Mix_GetError());
|
53
53
|
}
|
54
54
|
}
|
55
55
|
|
@@ -57,7 +57,7 @@ void S2D_PlayMusic(S2D_Music *mus, bool loop) {
|
|
57
57
|
/*
|
58
58
|
* Pause the playing music
|
59
59
|
*/
|
60
|
-
void
|
60
|
+
void R2D_PauseMusic() {
|
61
61
|
Mix_PauseMusic();
|
62
62
|
}
|
63
63
|
|
@@ -65,7 +65,7 @@ void S2D_PauseMusic() {
|
|
65
65
|
/*
|
66
66
|
* Resume the current music
|
67
67
|
*/
|
68
|
-
void
|
68
|
+
void R2D_ResumeMusic() {
|
69
69
|
Mix_ResumeMusic();
|
70
70
|
}
|
71
71
|
|
@@ -73,7 +73,7 @@ void S2D_ResumeMusic() {
|
|
73
73
|
/*
|
74
74
|
* Stop the playing music; interrupts fader effects
|
75
75
|
*/
|
76
|
-
void
|
76
|
+
void R2D_StopMusic() {
|
77
77
|
Mix_HaltMusic();
|
78
78
|
}
|
79
79
|
|
@@ -81,7 +81,7 @@ void S2D_StopMusic() {
|
|
81
81
|
/*
|
82
82
|
* Get the music volume
|
83
83
|
*/
|
84
|
-
int
|
84
|
+
int R2D_GetMusicVolume() {
|
85
85
|
// Get music volume as percentage of maximum mix volume
|
86
86
|
return ceil(Mix_VolumeMusic(-1) * (100.0 / MIX_MAX_VOLUME));
|
87
87
|
}
|
@@ -90,7 +90,7 @@ int S2D_GetMusicVolume() {
|
|
90
90
|
/*
|
91
91
|
* Set the music volume a given percentage
|
92
92
|
*/
|
93
|
-
void
|
93
|
+
void R2D_SetMusicVolume(int volume) {
|
94
94
|
// Set volume to be a percentage of the maximum mix volume
|
95
95
|
Mix_VolumeMusic((volume / 100.0) * MIX_MAX_VOLUME);
|
96
96
|
}
|
@@ -99,7 +99,7 @@ void S2D_SetMusicVolume(int volume) {
|
|
99
99
|
/*
|
100
100
|
* Fade out the playing music
|
101
101
|
*/
|
102
|
-
void
|
102
|
+
void R2D_FadeOutMusic(int ms) {
|
103
103
|
Mix_FadeOutMusic(ms);
|
104
104
|
}
|
105
105
|
|
@@ -107,7 +107,7 @@ void S2D_FadeOutMusic(int ms) {
|
|
107
107
|
/*
|
108
108
|
* Free the music
|
109
109
|
*/
|
110
|
-
void
|
110
|
+
void R2D_FreeMusic(R2D_Music *mus) {
|
111
111
|
if (!mus) return;
|
112
112
|
Mix_FreeMusic(mus->data);
|
113
113
|
free(mus);
|
data/ext/ruby2d/ruby2d.c
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
// Native C extension for Ruby and MRuby
|
2
2
|
|
3
|
-
//
|
3
|
+
// Ruby 2D includes
|
4
4
|
#if RUBY2D_IOS_TVOS
|
5
|
-
#include <Simple2D/simple2d.h>
|
6
5
|
#else
|
7
|
-
#include <
|
6
|
+
#include <ruby2d.h>
|
8
7
|
#endif
|
9
8
|
|
10
9
|
// Ruby includes
|
@@ -100,11 +99,11 @@
|
|
100
99
|
static mrb_state *mrb;
|
101
100
|
#endif
|
102
101
|
|
103
|
-
// Ruby 2D window
|
102
|
+
// Ruby 2D interpreter window
|
104
103
|
static R_VAL ruby2d_window;
|
105
104
|
|
106
|
-
//
|
107
|
-
static
|
105
|
+
// Ruby 2D native window
|
106
|
+
static R2D_Window *window;
|
108
107
|
|
109
108
|
|
110
109
|
// Method signatures and structures for Ruby 2D classes
|
@@ -130,19 +129,19 @@ static S2D_Window *window;
|
|
130
129
|
"music", free_music
|
131
130
|
};
|
132
131
|
#else
|
133
|
-
static void free_image(
|
134
|
-
static void free_sprite(
|
135
|
-
static void free_text(
|
136
|
-
static void free_sound(
|
137
|
-
static void free_music(
|
132
|
+
static void free_image(R2D_Image *img);
|
133
|
+
static void free_sprite(R2D_Sprite *spr);
|
134
|
+
static void free_text(R2D_Text *txt);
|
135
|
+
static void free_sound(R2D_Sound *snd);
|
136
|
+
static void free_music(R2D_Music *mus);
|
138
137
|
#endif
|
139
138
|
|
140
139
|
|
141
140
|
/*
|
142
|
-
* Function pointer to free the
|
141
|
+
* Function pointer to free the Ruby 2D native window
|
143
142
|
*/
|
144
143
|
static void free_window() {
|
145
|
-
|
144
|
+
R2D_FreeWindow(window);
|
146
145
|
}
|
147
146
|
|
148
147
|
|
@@ -178,7 +177,7 @@ static R_VAL ruby2d_triangle_ext_render(R_VAL self) {
|
|
178
177
|
R_VAL c2 = r_iv_get(self, "@c2");
|
179
178
|
R_VAL c3 = r_iv_get(self, "@c3");
|
180
179
|
|
181
|
-
|
180
|
+
R2D_DrawTriangle(
|
182
181
|
NUM2DBL(r_iv_get(self, "@x1")),
|
183
182
|
NUM2DBL(r_iv_get(self, "@y1")),
|
184
183
|
NUM2DBL(r_iv_get(c1, "@r")),
|
@@ -218,7 +217,7 @@ static R_VAL ruby2d_quad_ext_render(R_VAL self) {
|
|
218
217
|
R_VAL c3 = r_iv_get(self, "@c3");
|
219
218
|
R_VAL c4 = r_iv_get(self, "@c4");
|
220
219
|
|
221
|
-
|
220
|
+
R2D_DrawQuad(
|
222
221
|
NUM2DBL(r_iv_get(self, "@x1")),
|
223
222
|
NUM2DBL(r_iv_get(self, "@y1")),
|
224
223
|
NUM2DBL(r_iv_get(c1, "@r")),
|
@@ -265,7 +264,7 @@ static R_VAL ruby2d_line_ext_render(R_VAL self) {
|
|
265
264
|
R_VAL c3 = r_iv_get(self, "@c3");
|
266
265
|
R_VAL c4 = r_iv_get(self, "@c4");
|
267
266
|
|
268
|
-
|
267
|
+
R2D_DrawLine(
|
269
268
|
NUM2DBL(r_iv_get(self, "@x1")),
|
270
269
|
NUM2DBL(r_iv_get(self, "@y1")),
|
271
270
|
NUM2DBL(r_iv_get(self, "@x2")),
|
@@ -307,7 +306,7 @@ static R_VAL ruby2d_circle_ext_render(R_VAL self) {
|
|
307
306
|
#endif
|
308
307
|
R_VAL c = r_iv_get(self, "@color");
|
309
308
|
|
310
|
-
|
309
|
+
R2D_DrawCircle(
|
311
310
|
NUM2DBL(r_iv_get(self, "@x")),
|
312
311
|
NUM2DBL(r_iv_get(self, "@y")),
|
313
312
|
NUM2DBL(r_iv_get(self, "@radius")),
|
@@ -333,7 +332,7 @@ static R_VAL ruby2d_image_ext_init(mrb_state* mrb, R_VAL self) {
|
|
333
332
|
#else
|
334
333
|
static R_VAL ruby2d_image_ext_init(R_VAL self, R_VAL path) {
|
335
334
|
#endif
|
336
|
-
|
335
|
+
R2D_Image *img = R2D_CreateImage(RSTRING_PTR(path));
|
337
336
|
if (!img) return R_FALSE;
|
338
337
|
|
339
338
|
// Get width and height from Ruby class. If set, use it, else choose the
|
@@ -356,8 +355,8 @@ static R_VAL ruby2d_image_ext_render(mrb_state* mrb, R_VAL self) {
|
|
356
355
|
#else
|
357
356
|
static R_VAL ruby2d_image_ext_render(R_VAL self) {
|
358
357
|
#endif
|
359
|
-
|
360
|
-
r_data_get_struct(self, "@data", &image_data_type,
|
358
|
+
R2D_Image *img;
|
359
|
+
r_data_get_struct(self, "@data", &image_data_type, R2D_Image, img);
|
361
360
|
|
362
361
|
img->x = NUM2DBL(r_iv_get(self, "@x"));
|
363
362
|
img->y = NUM2DBL(r_iv_get(self, "@y"));
|
@@ -367,7 +366,7 @@ static R_VAL ruby2d_image_ext_render(R_VAL self) {
|
|
367
366
|
if (r_test(w)) img->width = NUM2INT(w);
|
368
367
|
if (r_test(h)) img->height = NUM2INT(h);
|
369
368
|
|
370
|
-
|
369
|
+
R2D_RotateImage(img, NUM2DBL(r_iv_get(self, "@rotate")), R2D_CENTER);
|
371
370
|
|
372
371
|
R_VAL c = r_iv_get(self, "@color");
|
373
372
|
img->color.r = NUM2DBL(r_iv_get(c, "@r"));
|
@@ -375,7 +374,7 @@ static R_VAL ruby2d_image_ext_render(R_VAL self) {
|
|
375
374
|
img->color.b = NUM2DBL(r_iv_get(c, "@b"));
|
376
375
|
img->color.a = NUM2DBL(r_iv_get(c, "@a"));
|
377
376
|
|
378
|
-
|
377
|
+
R2D_DrawImage(img);
|
379
378
|
|
380
379
|
return R_NIL;
|
381
380
|
}
|
@@ -386,11 +385,11 @@ static R_VAL ruby2d_image_ext_render(R_VAL self) {
|
|
386
385
|
*/
|
387
386
|
#if MRUBY
|
388
387
|
static void free_image(mrb_state *mrb, void *p_) {
|
389
|
-
|
388
|
+
R2D_Image *img = (R2D_Image *)p_;
|
390
389
|
#else
|
391
|
-
static void free_image(
|
390
|
+
static void free_image(R2D_Image *img) {
|
392
391
|
#endif
|
393
|
-
|
392
|
+
R2D_FreeImage(img);
|
394
393
|
}
|
395
394
|
|
396
395
|
|
@@ -405,7 +404,7 @@ static R_VAL ruby2d_sprite_ext_init(mrb_state* mrb, R_VAL self) {
|
|
405
404
|
#else
|
406
405
|
static R_VAL ruby2d_sprite_ext_init(R_VAL self, R_VAL path) {
|
407
406
|
#endif
|
408
|
-
|
407
|
+
R2D_Sprite *spr = R2D_CreateSprite(RSTRING_PTR(path));
|
409
408
|
if (!spr) return R_FALSE;
|
410
409
|
|
411
410
|
r_iv_set(self, "@img_width" , INT2NUM(spr->width));
|
@@ -426,8 +425,8 @@ static R_VAL ruby2d_sprite_ext_render(R_VAL self) {
|
|
426
425
|
#endif
|
427
426
|
r_funcall(self, "update", 0);
|
428
427
|
|
429
|
-
|
430
|
-
r_data_get_struct(self, "@data", &sprite_data_type,
|
428
|
+
R2D_Sprite *spr;
|
429
|
+
r_data_get_struct(self, "@data", &sprite_data_type, R2D_Sprite, spr);
|
431
430
|
|
432
431
|
spr->x = NUM2DBL(r_iv_get(self, "@flip_x"));
|
433
432
|
spr->y = NUM2DBL(r_iv_get(self, "@flip_y"));
|
@@ -438,7 +437,7 @@ static R_VAL ruby2d_sprite_ext_render(R_VAL self) {
|
|
438
437
|
R_VAL h = r_iv_get(self, "@flip_height");
|
439
438
|
if (r_test(h)) spr->height = NUM2DBL(h);
|
440
439
|
|
441
|
-
|
440
|
+
R2D_RotateSprite(spr, NUM2DBL(r_iv_get(self, "@rotate")), R2D_CENTER);
|
442
441
|
|
443
442
|
R_VAL c = r_iv_get(self, "@color");
|
444
443
|
spr->color.r = NUM2DBL(r_iv_get(c, "@r"));
|
@@ -446,7 +445,7 @@ static R_VAL ruby2d_sprite_ext_render(R_VAL self) {
|
|
446
445
|
spr->color.b = NUM2DBL(r_iv_get(c, "@b"));
|
447
446
|
spr->color.a = NUM2DBL(r_iv_get(c, "@a"));
|
448
447
|
|
449
|
-
|
448
|
+
R2D_ClipSprite(
|
450
449
|
spr,
|
451
450
|
NUM2INT(r_iv_get(self, "@clip_x")),
|
452
451
|
NUM2INT(r_iv_get(self, "@clip_y")),
|
@@ -454,7 +453,7 @@ static R_VAL ruby2d_sprite_ext_render(R_VAL self) {
|
|
454
453
|
NUM2INT(r_iv_get(self, "@clip_height"))
|
455
454
|
);
|
456
455
|
|
457
|
-
|
456
|
+
R2D_DrawSprite(spr);
|
458
457
|
|
459
458
|
return R_NIL;
|
460
459
|
}
|
@@ -465,11 +464,11 @@ static R_VAL ruby2d_sprite_ext_render(R_VAL self) {
|
|
465
464
|
*/
|
466
465
|
#if MRUBY
|
467
466
|
static void free_sprite(mrb_state *mrb, void *p_) {
|
468
|
-
|
467
|
+
R2D_Sprite *spr = (R2D_Sprite *)p_;
|
469
468
|
#else
|
470
|
-
static void free_sprite(
|
469
|
+
static void free_sprite(R2D_Sprite *spr) {
|
471
470
|
#endif
|
472
|
-
|
471
|
+
R2D_FreeSprite(spr);
|
473
472
|
}
|
474
473
|
|
475
474
|
|
@@ -488,7 +487,7 @@ static R_VAL ruby2d_text_ext_init(R_VAL self) {
|
|
488
487
|
mrb_str_resize(mrb, s, RSTRING_LEN(s));
|
489
488
|
#endif
|
490
489
|
|
491
|
-
|
490
|
+
R2D_Text *txt = R2D_CreateText(
|
492
491
|
RSTRING_PTR(r_iv_get(self, "@font")),
|
493
492
|
RSTRING_PTR(r_iv_get(self, "@text")),
|
494
493
|
NUM2DBL(r_iv_get(self, "@size"))
|
@@ -513,10 +512,10 @@ static R_VAL ruby2d_text_ext_set(mrb_state* mrb, R_VAL self) {
|
|
513
512
|
#else
|
514
513
|
static R_VAL ruby2d_text_ext_set(R_VAL self, R_VAL text) {
|
515
514
|
#endif
|
516
|
-
|
517
|
-
r_data_get_struct(self, "@data", &text_data_type,
|
515
|
+
R2D_Text *txt;
|
516
|
+
r_data_get_struct(self, "@data", &text_data_type, R2D_Text, txt);
|
518
517
|
|
519
|
-
|
518
|
+
R2D_SetText(txt, RSTRING_PTR(text));
|
520
519
|
|
521
520
|
r_iv_set(self, "@width", INT2NUM(txt->width));
|
522
521
|
r_iv_set(self, "@height", INT2NUM(txt->height));
|
@@ -533,13 +532,13 @@ static R_VAL ruby2d_text_ext_render(mrb_state* mrb, R_VAL self) {
|
|
533
532
|
#else
|
534
533
|
static R_VAL ruby2d_text_ext_render(R_VAL self) {
|
535
534
|
#endif
|
536
|
-
|
537
|
-
r_data_get_struct(self, "@data", &text_data_type,
|
535
|
+
R2D_Text *txt;
|
536
|
+
r_data_get_struct(self, "@data", &text_data_type, R2D_Text, txt);
|
538
537
|
|
539
538
|
txt->x = NUM2DBL(r_iv_get(self, "@x"));
|
540
539
|
txt->y = NUM2DBL(r_iv_get(self, "@y"));
|
541
540
|
|
542
|
-
|
541
|
+
R2D_RotateText(txt, NUM2DBL(r_iv_get(self, "@rotate")), R2D_CENTER);
|
543
542
|
|
544
543
|
R_VAL c = r_iv_get(self, "@color");
|
545
544
|
txt->color.r = NUM2DBL(r_iv_get(c, "@r"));
|
@@ -547,7 +546,7 @@ static R_VAL ruby2d_text_ext_render(R_VAL self) {
|
|
547
546
|
txt->color.b = NUM2DBL(r_iv_get(c, "@b"));
|
548
547
|
txt->color.a = NUM2DBL(r_iv_get(c, "@a"));
|
549
548
|
|
550
|
-
|
549
|
+
R2D_DrawText(txt);
|
551
550
|
|
552
551
|
return R_NIL;
|
553
552
|
}
|
@@ -558,11 +557,11 @@ static R_VAL ruby2d_text_ext_render(R_VAL self) {
|
|
558
557
|
*/
|
559
558
|
#if MRUBY
|
560
559
|
static void free_text(mrb_state *mrb, void *p_) {
|
561
|
-
|
560
|
+
R2D_Text *txt = (R2D_Text *)p_;
|
562
561
|
#else
|
563
|
-
static void free_text(
|
562
|
+
static void free_text(R2D_Text *txt) {
|
564
563
|
#endif
|
565
|
-
|
564
|
+
R2D_FreeText(txt);
|
566
565
|
}
|
567
566
|
|
568
567
|
|
@@ -577,7 +576,7 @@ static R_VAL ruby2d_sound_ext_init(mrb_state* mrb, R_VAL self) {
|
|
577
576
|
#else
|
578
577
|
static R_VAL ruby2d_sound_ext_init(R_VAL self, R_VAL path) {
|
579
578
|
#endif
|
580
|
-
|
579
|
+
R2D_Sound *snd = R2D_CreateSound(RSTRING_PTR(path));
|
581
580
|
if (!snd) return R_FALSE;
|
582
581
|
r_iv_set(self, "@data", r_data_wrap_struct(sound, snd));
|
583
582
|
return R_TRUE;
|
@@ -592,9 +591,9 @@ static R_VAL ruby2d_sound_ext_play(mrb_state* mrb, R_VAL self) {
|
|
592
591
|
#else
|
593
592
|
static R_VAL ruby2d_sound_ext_play(R_VAL self) {
|
594
593
|
#endif
|
595
|
-
|
596
|
-
r_data_get_struct(self, "@data", &sound_data_type,
|
597
|
-
|
594
|
+
R2D_Sound *snd;
|
595
|
+
r_data_get_struct(self, "@data", &sound_data_type, R2D_Sound, snd);
|
596
|
+
R2D_PlaySound(snd);
|
598
597
|
return R_NIL;
|
599
598
|
}
|
600
599
|
|
@@ -604,11 +603,11 @@ static R_VAL ruby2d_sound_ext_play(R_VAL self) {
|
|
604
603
|
*/
|
605
604
|
#if MRUBY
|
606
605
|
static void free_sound(mrb_state *mrb, void *p_) {
|
607
|
-
|
606
|
+
R2D_Sound *snd = (R2D_Sound *)p_;
|
608
607
|
#else
|
609
|
-
static void free_sound(
|
608
|
+
static void free_sound(R2D_Sound *snd) {
|
610
609
|
#endif
|
611
|
-
|
610
|
+
R2D_FreeSound(snd);
|
612
611
|
}
|
613
612
|
|
614
613
|
|
@@ -623,7 +622,7 @@ static R_VAL ruby2d_music_ext_init(mrb_state* mrb, R_VAL self) {
|
|
623
622
|
#else
|
624
623
|
static R_VAL ruby2d_music_ext_init(R_VAL self, R_VAL path) {
|
625
624
|
#endif
|
626
|
-
|
625
|
+
R2D_Music *mus = R2D_CreateMusic(RSTRING_PTR(path));
|
627
626
|
if (!mus) return R_FALSE;
|
628
627
|
r_iv_set(self, "@data", r_data_wrap_struct(music, mus));
|
629
628
|
return R_TRUE;
|
@@ -638,9 +637,9 @@ static R_VAL ruby2d_music_ext_play(mrb_state* mrb, R_VAL self) {
|
|
638
637
|
#else
|
639
638
|
static R_VAL ruby2d_music_ext_play(R_VAL self) {
|
640
639
|
#endif
|
641
|
-
|
642
|
-
r_data_get_struct(self, "@data", &music_data_type,
|
643
|
-
|
640
|
+
R2D_Music *mus;
|
641
|
+
r_data_get_struct(self, "@data", &music_data_type, R2D_Music, mus);
|
642
|
+
R2D_PlayMusic(mus, r_test(r_iv_get(self, "@loop")));
|
644
643
|
return R_NIL;
|
645
644
|
}
|
646
645
|
|
@@ -653,7 +652,7 @@ static R_VAL ruby2d_music_ext_pause(mrb_state* mrb, R_VAL self) {
|
|
653
652
|
#else
|
654
653
|
static R_VAL ruby2d_music_ext_pause(R_VAL self) {
|
655
654
|
#endif
|
656
|
-
|
655
|
+
R2D_PauseMusic();
|
657
656
|
return R_NIL;
|
658
657
|
}
|
659
658
|
|
@@ -666,7 +665,7 @@ static R_VAL ruby2d_music_ext_resume(mrb_state* mrb, R_VAL self) {
|
|
666
665
|
#else
|
667
666
|
static R_VAL ruby2d_music_ext_resume(R_VAL self) {
|
668
667
|
#endif
|
669
|
-
|
668
|
+
R2D_ResumeMusic();
|
670
669
|
return R_NIL;
|
671
670
|
}
|
672
671
|
|
@@ -679,7 +678,7 @@ static R_VAL ruby2d_music_ext_stop(mrb_state* mrb, R_VAL self) {
|
|
679
678
|
#else
|
680
679
|
static R_VAL ruby2d_music_ext_stop(R_VAL self) {
|
681
680
|
#endif
|
682
|
-
|
681
|
+
R2D_StopMusic();
|
683
682
|
return R_NIL;
|
684
683
|
}
|
685
684
|
|
@@ -692,7 +691,7 @@ static R_VAL ruby2d_music_ext_get_volume(mrb_state* mrb, R_VAL self) {
|
|
692
691
|
#else
|
693
692
|
static R_VAL ruby2d_music_ext_get_volume(R_VAL self) {
|
694
693
|
#endif
|
695
|
-
return INT2NUM(
|
694
|
+
return INT2NUM(R2D_GetMusicVolume());
|
696
695
|
}
|
697
696
|
|
698
697
|
|
@@ -706,7 +705,7 @@ static R_VAL ruby2d_music_ext_set_volume(mrb_state* mrb, R_VAL self) {
|
|
706
705
|
#else
|
707
706
|
static R_VAL ruby2d_music_ext_set_volume(R_VAL self, R_VAL volume) {
|
708
707
|
#endif
|
709
|
-
|
708
|
+
R2D_SetMusicVolume(NUM2INT(volume));
|
710
709
|
return R_NIL;
|
711
710
|
}
|
712
711
|
|
@@ -721,7 +720,7 @@ static R_VAL ruby2d_music_ext_fadeout(mrb_state* mrb, R_VAL self) {
|
|
721
720
|
#else
|
722
721
|
static R_VAL ruby2d_music_ext_fadeout(R_VAL self, R_VAL ms) {
|
723
722
|
#endif
|
724
|
-
|
723
|
+
R2D_FadeOutMusic(NUM2INT(ms));
|
725
724
|
return R_NIL;
|
726
725
|
}
|
727
726
|
|
@@ -731,29 +730,29 @@ static R_VAL ruby2d_music_ext_fadeout(R_VAL self, R_VAL ms) {
|
|
731
730
|
*/
|
732
731
|
#if MRUBY
|
733
732
|
static void free_music(mrb_state *mrb, void *p_) {
|
734
|
-
|
733
|
+
R2D_Music *mus = (R2D_Music *)p_;
|
735
734
|
#else
|
736
|
-
static void free_music(
|
735
|
+
static void free_music(R2D_Music *mus) {
|
737
736
|
#endif
|
738
|
-
|
737
|
+
R2D_FreeMusic(mus);
|
739
738
|
}
|
740
739
|
|
741
740
|
|
742
741
|
/*
|
743
|
-
*
|
742
|
+
* Ruby 2D native `on_key` input callback function
|
744
743
|
*/
|
745
|
-
static void on_key(
|
744
|
+
static void on_key(R2D_Event e) {
|
746
745
|
|
747
746
|
R_VAL type;
|
748
747
|
|
749
748
|
switch (e.type) {
|
750
|
-
case
|
749
|
+
case R2D_KEY_DOWN:
|
751
750
|
type = r_char_to_sym("down");
|
752
751
|
break;
|
753
|
-
case
|
752
|
+
case R2D_KEY_HELD:
|
754
753
|
type = r_char_to_sym("held");
|
755
754
|
break;
|
756
|
-
case
|
755
|
+
case R2D_KEY_UP:
|
757
756
|
type = r_char_to_sym("up");
|
758
757
|
break;
|
759
758
|
}
|
@@ -763,48 +762,48 @@ static void on_key(S2D_Event e) {
|
|
763
762
|
|
764
763
|
|
765
764
|
/*
|
766
|
-
*
|
765
|
+
* Ruby 2D native `on_mouse` input callback function
|
767
766
|
*/
|
768
|
-
void on_mouse(
|
767
|
+
void on_mouse(R2D_Event e) {
|
769
768
|
|
770
769
|
R_VAL type = R_NIL; R_VAL button = R_NIL; R_VAL direction = R_NIL;
|
771
770
|
|
772
771
|
switch (e.type) {
|
773
|
-
case
|
772
|
+
case R2D_MOUSE_DOWN:
|
774
773
|
// type, button, x, y
|
775
774
|
type = r_char_to_sym("down");
|
776
775
|
break;
|
777
|
-
case
|
776
|
+
case R2D_MOUSE_UP:
|
778
777
|
// type, button, x, y
|
779
778
|
type = r_char_to_sym("up");
|
780
779
|
break;
|
781
|
-
case
|
780
|
+
case R2D_MOUSE_SCROLL:
|
782
781
|
// type, direction, delta_x, delta_y
|
783
782
|
type = r_char_to_sym("scroll");
|
784
|
-
direction = e.direction ==
|
783
|
+
direction = e.direction == R2D_MOUSE_SCROLL_NORMAL ?
|
785
784
|
r_char_to_sym("normal") : r_char_to_sym("inverted");
|
786
785
|
break;
|
787
|
-
case
|
786
|
+
case R2D_MOUSE_MOVE:
|
788
787
|
// type, x, y, delta_x, delta_y
|
789
788
|
type = r_char_to_sym("move");
|
790
789
|
break;
|
791
790
|
}
|
792
791
|
|
793
|
-
if (e.type ==
|
792
|
+
if (e.type == R2D_MOUSE_DOWN || e.type == R2D_MOUSE_UP) {
|
794
793
|
switch (e.button) {
|
795
|
-
case
|
794
|
+
case R2D_MOUSE_LEFT:
|
796
795
|
button = r_char_to_sym("left");
|
797
796
|
break;
|
798
|
-
case
|
797
|
+
case R2D_MOUSE_MIDDLE:
|
799
798
|
button = r_char_to_sym("middle");
|
800
799
|
break;
|
801
|
-
case
|
800
|
+
case R2D_MOUSE_RIGHT:
|
802
801
|
button = r_char_to_sym("right");
|
803
802
|
break;
|
804
|
-
case
|
803
|
+
case R2D_MOUSE_X1:
|
805
804
|
button = r_char_to_sym("x1");
|
806
805
|
break;
|
807
|
-
case
|
806
|
+
case R2D_MOUSE_X2:
|
808
807
|
button = r_char_to_sym("x2");
|
809
808
|
break;
|
810
809
|
}
|
@@ -818,88 +817,88 @@ void on_mouse(S2D_Event e) {
|
|
818
817
|
|
819
818
|
|
820
819
|
/*
|
821
|
-
*
|
820
|
+
* Ruby 2D native `on_controller` input callback function
|
822
821
|
*/
|
823
|
-
static void on_controller(
|
822
|
+
static void on_controller(R2D_Event e) {
|
824
823
|
|
825
824
|
R_VAL type = R_NIL; R_VAL axis = R_NIL; R_VAL button = R_NIL;
|
826
825
|
|
827
826
|
switch (e.type) {
|
828
|
-
case
|
827
|
+
case R2D_AXIS:
|
829
828
|
type = r_char_to_sym("axis");
|
830
829
|
switch (e.axis) {
|
831
|
-
case
|
830
|
+
case R2D_AXIS_LEFTX:
|
832
831
|
axis = r_char_to_sym("left_x");
|
833
832
|
break;
|
834
|
-
case
|
833
|
+
case R2D_AXIS_LEFTY:
|
835
834
|
axis = r_char_to_sym("left_y");
|
836
835
|
break;
|
837
|
-
case
|
836
|
+
case R2D_AXIS_RIGHTX:
|
838
837
|
axis = r_char_to_sym("right_x");
|
839
838
|
break;
|
840
|
-
case
|
839
|
+
case R2D_AXIS_RIGHTY:
|
841
840
|
axis = r_char_to_sym("right_y");
|
842
841
|
break;
|
843
|
-
case
|
842
|
+
case R2D_AXIS_TRIGGERLEFT:
|
844
843
|
axis = r_char_to_sym("trigger_left");
|
845
844
|
break;
|
846
|
-
case
|
845
|
+
case R2D_AXIS_TRIGGERRIGHT:
|
847
846
|
axis = r_char_to_sym("trigger_right");
|
848
847
|
break;
|
849
|
-
case
|
848
|
+
case R2D_AXIS_INVALID:
|
850
849
|
axis = r_char_to_sym("invalid");
|
851
850
|
break;
|
852
851
|
}
|
853
852
|
break;
|
854
|
-
case
|
855
|
-
type = e.type ==
|
853
|
+
case R2D_BUTTON_DOWN: case R2D_BUTTON_UP:
|
854
|
+
type = e.type == R2D_BUTTON_DOWN ? r_char_to_sym("button_down") : r_char_to_sym("button_up");
|
856
855
|
switch (e.button) {
|
857
|
-
case
|
856
|
+
case R2D_BUTTON_A:
|
858
857
|
button = r_char_to_sym("a");
|
859
858
|
break;
|
860
|
-
case
|
859
|
+
case R2D_BUTTON_B:
|
861
860
|
button = r_char_to_sym("b");
|
862
861
|
break;
|
863
|
-
case
|
862
|
+
case R2D_BUTTON_X:
|
864
863
|
button = r_char_to_sym("x");
|
865
864
|
break;
|
866
|
-
case
|
865
|
+
case R2D_BUTTON_Y:
|
867
866
|
button = r_char_to_sym("y");
|
868
867
|
break;
|
869
|
-
case
|
868
|
+
case R2D_BUTTON_BACK:
|
870
869
|
button = r_char_to_sym("back");
|
871
870
|
break;
|
872
|
-
case
|
871
|
+
case R2D_BUTTON_GUIDE:
|
873
872
|
button = r_char_to_sym("guide");
|
874
873
|
break;
|
875
|
-
case
|
874
|
+
case R2D_BUTTON_START:
|
876
875
|
button = r_char_to_sym("start");
|
877
876
|
break;
|
878
|
-
case
|
877
|
+
case R2D_BUTTON_LEFTSTICK:
|
879
878
|
button = r_char_to_sym("left_stick");
|
880
879
|
break;
|
881
|
-
case
|
880
|
+
case R2D_BUTTON_RIGHTSTICK:
|
882
881
|
button = r_char_to_sym("right_stick");
|
883
882
|
break;
|
884
|
-
case
|
883
|
+
case R2D_BUTTON_LEFTSHOULDER:
|
885
884
|
button = r_char_to_sym("left_shoulder");
|
886
885
|
break;
|
887
|
-
case
|
886
|
+
case R2D_BUTTON_RIGHTSHOULDER:
|
888
887
|
button = r_char_to_sym("right_shoulder");
|
889
888
|
break;
|
890
|
-
case
|
889
|
+
case R2D_BUTTON_DPAD_UP:
|
891
890
|
button = r_char_to_sym("up");
|
892
891
|
break;
|
893
|
-
case
|
892
|
+
case R2D_BUTTON_DPAD_DOWN:
|
894
893
|
button = r_char_to_sym("down");
|
895
894
|
break;
|
896
|
-
case
|
895
|
+
case R2D_BUTTON_DPAD_LEFT:
|
897
896
|
button = r_char_to_sym("left");
|
898
897
|
break;
|
899
|
-
case
|
898
|
+
case R2D_BUTTON_DPAD_RIGHT:
|
900
899
|
button = r_char_to_sym("right");
|
901
900
|
break;
|
902
|
-
case
|
901
|
+
case R2D_BUTTON_INVALID:
|
903
902
|
button = r_char_to_sym("invalid");
|
904
903
|
break;
|
905
904
|
}
|
@@ -914,7 +913,7 @@ static void on_controller(S2D_Event e) {
|
|
914
913
|
|
915
914
|
|
916
915
|
/*
|
917
|
-
*
|
916
|
+
* Ruby 2D native `update` callback function
|
918
917
|
*/
|
919
918
|
static void update() {
|
920
919
|
|
@@ -934,7 +933,7 @@ static void update() {
|
|
934
933
|
|
935
934
|
|
936
935
|
/*
|
937
|
-
*
|
936
|
+
* Ruby 2D native `render` callback function
|
938
937
|
*/
|
939
938
|
static void render() {
|
940
939
|
|
@@ -967,8 +966,8 @@ static R_VAL ruby2d_ext_diagnostics(mrb_state* mrb, R_VAL self) {
|
|
967
966
|
#else
|
968
967
|
static R_VAL ruby2d_ext_diagnostics(R_VAL self, R_VAL enable) {
|
969
968
|
#endif
|
970
|
-
// Set
|
971
|
-
|
969
|
+
// Set Ruby 2D native diagnostics
|
970
|
+
R2D_Diagnostics(r_test(enable));
|
972
971
|
return R_TRUE;
|
973
972
|
}
|
974
973
|
|
@@ -982,7 +981,7 @@ static R_VAL ruby2d_window_ext_get_display_dimensions(mrb_state* mrb, R_VAL self
|
|
982
981
|
static R_VAL ruby2d_window_ext_get_display_dimensions(R_VAL self) {
|
983
982
|
#endif
|
984
983
|
int w; int h;
|
985
|
-
|
984
|
+
R2D_GetDisplayDimensions(&w, &h);
|
986
985
|
r_iv_set(self, "@display_width" , INT2NUM(w));
|
987
986
|
r_iv_set(self, "@display_height", INT2NUM(h));
|
988
987
|
return R_NIL;
|
@@ -999,8 +998,8 @@ static R_VAL ruby2d_window_ext_add_controller_mappings(mrb_state* mrb, R_VAL sel
|
|
999
998
|
#else
|
1000
999
|
static R_VAL ruby2d_window_ext_add_controller_mappings(R_VAL self, R_VAL path) {
|
1001
1000
|
#endif
|
1002
|
-
|
1003
|
-
|
1001
|
+
R2D_Log(R2D_INFO, "Adding controller mappings from `%s`", RSTRING_PTR(path));
|
1002
|
+
R2D_AddControllerMappingsFromFile(RSTRING_PTR(path));
|
1004
1003
|
return R_NIL;
|
1005
1004
|
}
|
1006
1005
|
|
@@ -1032,16 +1031,16 @@ static R_VAL ruby2d_window_ext_show(R_VAL self) {
|
|
1032
1031
|
// Get window flags
|
1033
1032
|
int flags = 0;
|
1034
1033
|
if (r_test(r_iv_get(self, "@resizable"))) {
|
1035
|
-
flags = flags |
|
1034
|
+
flags = flags | R2D_RESIZABLE;
|
1036
1035
|
}
|
1037
1036
|
if (r_test(r_iv_get(self, "@borderless"))) {
|
1038
|
-
flags = flags |
|
1037
|
+
flags = flags | R2D_BORDERLESS;
|
1039
1038
|
}
|
1040
1039
|
if (r_test(r_iv_get(self, "@fullscreen"))) {
|
1041
|
-
flags = flags |
|
1040
|
+
flags = flags | R2D_FULLSCREEN;
|
1042
1041
|
}
|
1043
1042
|
if (r_test(r_iv_get(self, "@highdpi"))) {
|
1044
|
-
flags = flags |
|
1043
|
+
flags = flags | R2D_HIGHDPI;
|
1045
1044
|
}
|
1046
1045
|
|
1047
1046
|
// Check viewport size and set
|
@@ -1054,7 +1053,7 @@ static R_VAL ruby2d_window_ext_show(R_VAL self) {
|
|
1054
1053
|
|
1055
1054
|
// Create and show window
|
1056
1055
|
|
1057
|
-
window =
|
1056
|
+
window = R2D_CreateWindow(
|
1058
1057
|
title, width, height, update, render, flags
|
1059
1058
|
);
|
1060
1059
|
|
@@ -1066,7 +1065,7 @@ static R_VAL ruby2d_window_ext_show(R_VAL self) {
|
|
1066
1065
|
window->on_mouse = on_mouse;
|
1067
1066
|
window->on_controller = on_controller;
|
1068
1067
|
|
1069
|
-
|
1068
|
+
R2D_Show(window);
|
1070
1069
|
|
1071
1070
|
atexit(free_window);
|
1072
1071
|
return R_NIL;
|
@@ -1084,7 +1083,7 @@ static R_VAL ruby2d_ext_screenshot(mrb_state* mrb, R_VAL self) {
|
|
1084
1083
|
static R_VAL ruby2d_ext_screenshot(R_VAL self, R_VAL path) {
|
1085
1084
|
#endif
|
1086
1085
|
if (window) {
|
1087
|
-
|
1086
|
+
R2D_Screenshot(window, RSTRING_PTR(path));
|
1088
1087
|
return path;
|
1089
1088
|
} else {
|
1090
1089
|
return R_FALSE;
|
@@ -1096,7 +1095,7 @@ static R_VAL ruby2d_ext_screenshot(R_VAL self, R_VAL path) {
|
|
1096
1095
|
* Ruby2D::Window#ext_close
|
1097
1096
|
*/
|
1098
1097
|
static R_VAL ruby2d_window_ext_close() {
|
1099
|
-
|
1098
|
+
R2D_Close(window);
|
1100
1099
|
return R_NIL;
|
1101
1100
|
}
|
1102
1101
|
|