ruby2d 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/assets/README.md +7 -8
  3. data/assets/Rakefile +85 -0
  4. data/assets/include/SDL2/SDL.h +4 -1
  5. data/assets/include/SDL2/SDL_assert.h +3 -1
  6. data/assets/include/SDL2/SDL_atomic.h +20 -2
  7. data/assets/include/SDL2/SDL_audio.h +47 -14
  8. data/assets/include/SDL2/SDL_bits.h +10 -1
  9. data/assets/include/SDL2/SDL_blendmode.h +10 -7
  10. data/assets/include/SDL2/SDL_clipboard.h +1 -1
  11. data/assets/include/SDL2/SDL_config.h +24 -390
  12. data/assets/include/SDL2/SDL_config_android.h +182 -0
  13. data/assets/include/SDL2/SDL_config_iphoneos.h +207 -0
  14. data/assets/include/SDL2/SDL_config_macosx.h +266 -0
  15. data/assets/include/SDL2/SDL_config_minimal.h +85 -0
  16. data/assets/include/SDL2/SDL_config_os2.h +188 -0
  17. data/assets/include/SDL2/SDL_config_pandora.h +135 -0
  18. data/assets/include/SDL2/SDL_config_psp.h +165 -0
  19. data/assets/include/SDL2/SDL_config_windows.h +288 -0
  20. data/assets/include/SDL2/SDL_config_winrt.h +243 -0
  21. data/assets/include/SDL2/SDL_config_wiz.h +149 -0
  22. data/assets/include/SDL2/SDL_copying.h +20 -0
  23. data/assets/include/SDL2/SDL_cpuinfo.h +119 -8
  24. data/assets/include/SDL2/SDL_egl.h +4 -1
  25. data/assets/include/SDL2/SDL_endian.h +6 -3
  26. data/assets/include/SDL2/SDL_error.h +38 -2
  27. data/assets/include/SDL2/SDL_events.h +67 -28
  28. data/assets/include/SDL2/SDL_filesystem.h +1 -1
  29. data/assets/include/SDL2/SDL_gamecontroller.h +160 -9
  30. data/assets/include/SDL2/SDL_gesture.h +1 -1
  31. data/assets/include/SDL2/SDL_haptic.h +10 -1
  32. data/assets/include/SDL2/SDL_hints.h +460 -17
  33. data/assets/include/SDL2/SDL_image.h +2 -2
  34. data/assets/include/SDL2/SDL_joystick.h +115 -24
  35. data/assets/include/SDL2/SDL_keyboard.h +1 -1
  36. data/assets/include/SDL2/SDL_keycode.h +11 -9
  37. data/assets/include/SDL2/SDL_loadso.h +1 -1
  38. data/assets/include/SDL2/SDL_locale.h +101 -0
  39. data/assets/include/SDL2/SDL_log.h +3 -3
  40. data/assets/include/SDL2/SDL_main.h +28 -16
  41. data/assets/include/SDL2/SDL_messagebox.h +6 -4
  42. data/assets/include/SDL2/SDL_metal.h +117 -0
  43. data/assets/include/SDL2/SDL_misc.h +75 -0
  44. data/assets/include/SDL2/SDL_mouse.h +1 -1
  45. data/assets/include/SDL2/SDL_mutex.h +1 -1
  46. data/assets/include/SDL2/SDL_name.h +1 -1
  47. data/assets/include/SDL2/SDL_opengl.h +1 -1
  48. data/assets/include/SDL2/SDL_opengl_glext.h +3 -0
  49. data/assets/include/SDL2/SDL_opengles.h +1 -1
  50. data/assets/include/SDL2/SDL_opengles2.h +1 -1
  51. data/assets/include/SDL2/SDL_pixels.h +27 -18
  52. data/assets/include/SDL2/SDL_platform.h +1 -1
  53. data/assets/include/SDL2/SDL_power.h +1 -1
  54. data/assets/include/SDL2/SDL_quit.h +1 -1
  55. data/assets/include/SDL2/SDL_rect.h +29 -3
  56. data/assets/include/SDL2/SDL_render.h +230 -3
  57. data/assets/include/SDL2/SDL_revision.h +2 -2
  58. data/assets/include/SDL2/SDL_rwops.h +51 -22
  59. data/assets/include/SDL2/SDL_scancode.h +2 -2
  60. data/assets/include/SDL2/SDL_sensor.h +28 -12
  61. data/assets/include/SDL2/SDL_shape.h +1 -1
  62. data/assets/include/SDL2/SDL_stdinc.h +44 -4
  63. data/assets/include/SDL2/SDL_surface.h +12 -2
  64. data/assets/include/SDL2/SDL_system.h +50 -4
  65. data/assets/include/SDL2/SDL_syswm.h +39 -9
  66. data/assets/include/SDL2/SDL_test.h +1 -1
  67. data/assets/include/SDL2/SDL_test_assert.h +1 -1
  68. data/assets/include/SDL2/SDL_test_common.h +32 -2
  69. data/assets/include/SDL2/SDL_test_compare.h +1 -1
  70. data/assets/include/SDL2/SDL_test_crc32.h +1 -1
  71. data/assets/include/SDL2/SDL_test_font.h +1 -1
  72. data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
  73. data/assets/include/SDL2/SDL_test_harness.h +1 -1
  74. data/assets/include/SDL2/SDL_test_images.h +1 -1
  75. data/assets/include/SDL2/SDL_test_log.h +1 -1
  76. data/assets/include/SDL2/SDL_test_md5.h +1 -1
  77. data/assets/include/SDL2/SDL_test_memory.h +3 -3
  78. data/assets/include/SDL2/SDL_test_random.h +1 -1
  79. data/assets/include/SDL2/SDL_thread.h +34 -11
  80. data/assets/include/SDL2/SDL_timer.h +1 -1
  81. data/assets/include/SDL2/SDL_touch.h +17 -1
  82. data/assets/include/SDL2/SDL_types.h +1 -1
  83. data/assets/include/SDL2/SDL_version.h +2 -2
  84. data/assets/include/SDL2/SDL_video.h +11 -5
  85. data/assets/include/SDL2/SDL_vulkan.h +9 -11
  86. data/assets/include/SDL2/begin_code.h +8 -9
  87. data/assets/include/SDL2/close_code.h +4 -1
  88. data/assets/macos/lib/libFLAC.a +0 -0
  89. data/assets/macos/lib/libSDL2.a +0 -0
  90. data/assets/macos/lib/libSDL2_image.a +0 -0
  91. data/assets/macos/lib/libSDL2_mixer.a +0 -0
  92. data/assets/macos/lib/libSDL2_ttf.a +0 -0
  93. data/assets/macos/lib/libfreetype.a +0 -0
  94. data/assets/macos/lib/libjpeg.a +0 -0
  95. data/assets/macos/lib/libmpg123.a +0 -0
  96. data/assets/macos/lib/libogg.a +0 -0
  97. data/assets/macos/lib/libpng16.a +0 -0
  98. data/assets/macos/lib/libtiff.a +0 -0
  99. data/assets/macos/lib/libvorbis.a +0 -0
  100. data/assets/macos/lib/libvorbisfile.a +0 -0
  101. data/assets/macos/lib/libwebp.a +0 -0
  102. data/assets/mingw/bin/SDL2.dll +0 -0
  103. data/assets/mingw/bin/SDL2_image.dll +0 -0
  104. data/assets/mingw/bin/libpng16-16.dll +0 -0
  105. data/assets/mingw/bin/libtiff-5.dll +0 -0
  106. data/assets/mingw/bin/libwebp-7.dll +0 -0
  107. data/assets/mingw/lib/libSDL2.a +0 -0
  108. data/assets/mingw/lib/libSDL2.dll.a +0 -0
  109. data/assets/mingw/lib/libSDL2_image.a +0 -0
  110. data/assets/mingw/lib/libSDL2_image.dll.a +0 -0
  111. data/assets/mingw/lib/libSDL2_test.a +0 -0
  112. data/assets/mingw/lib/libSDL2main.a +0 -0
  113. data/bin/ruby2d +2 -1
  114. data/{assets/linux/simple2d/src/simple2d.c → ext/ruby2d/common.c} +32 -32
  115. data/{assets/linux/simple2d/src → ext/ruby2d}/controllers.c +17 -17
  116. data/ext/ruby2d/extconf.rb +6 -36
  117. data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +106 -85
  118. data/{assets/linux/simple2d/src → ext/ruby2d}/gl2.c +35 -20
  119. data/{assets/linux/simple2d/src → ext/ruby2d}/gl3.c +146 -58
  120. data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +41 -26
  121. data/{assets/linux/simple2d/src → ext/ruby2d}/image.c +16 -16
  122. data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
  123. data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +30 -17
  124. data/ext/ruby2d/ruby2d.c +427 -290
  125. data/ext/ruby2d/ruby2d.h +789 -0
  126. data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
  127. data/ext/ruby2d/sound.c +118 -0
  128. data/{assets/linux/simple2d/src → ext/ruby2d}/sprite.c +16 -16
  129. data/{assets/linux/simple2d/src → ext/ruby2d}/text.c +22 -22
  130. data/ext/ruby2d/tileset.c +30 -0
  131. data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +71 -60
  132. data/lib/ruby2d.rb +5 -2
  133. data/lib/ruby2d/circle.rb +18 -2
  134. data/lib/ruby2d/cli/build.rb +3 -8
  135. data/lib/ruby2d/cli/colorize.rb +10 -0
  136. data/lib/ruby2d/dsl.rb +16 -9
  137. data/lib/ruby2d/entity.rb +17 -0
  138. data/lib/ruby2d/font.rb +4 -3
  139. data/lib/ruby2d/image.rb +24 -1
  140. data/lib/ruby2d/line.rb +20 -0
  141. data/lib/ruby2d/music.rb +5 -0
  142. data/lib/ruby2d/pixel.rb +17 -0
  143. data/lib/ruby2d/quad.rb +18 -0
  144. data/lib/ruby2d/rectangle.rb +11 -2
  145. data/lib/ruby2d/renderable.rb +4 -8
  146. data/lib/ruby2d/sound.rb +5 -0
  147. data/lib/ruby2d/sprite.rb +35 -3
  148. data/lib/ruby2d/square.rb +9 -0
  149. data/lib/ruby2d/text.rb +22 -1
  150. data/lib/ruby2d/tileset.rb +69 -0
  151. data/lib/ruby2d/triangle.rb +16 -0
  152. data/lib/ruby2d/version.rb +1 -1
  153. data/lib/ruby2d/window.rb +249 -22
  154. metadata +41 -27
  155. data/assets/include/simple2d.h +0 -735
  156. data/assets/linux/simple2d/Makefile +0 -250
  157. data/assets/linux/simple2d/bin/simple2d.sh +0 -1249
  158. data/assets/linux/simple2d/include/simple2d.h +0 -735
  159. data/assets/linux/simple2d/src/sound.c +0 -56
  160. data/assets/macos/lib/libsimple2d.a +0 -0
  161. data/assets/mingw/lib/libsimple2d.a +0 -0
  162. data/lib/ruby2d/colorize.rb +0 -10
@@ -1,31 +1,31 @@
1
1
  // image.c
2
2
 
3
- #include "../include/simple2d.h"
3
+ #include "ruby2d.h"
4
4
 
5
5
 
6
6
  /*
7
7
  * Create an image, given a file path
8
8
  */
9
- S2D_Image *S2D_CreateImage(const char *path) {
10
- S2D_Init();
9
+ R2D_Image *R2D_CreateImage(const char *path) {
10
+ R2D_Init();
11
11
 
12
12
  // Check if image file exists
13
- if (!S2D_FileExists(path)) {
14
- S2D_Error("S2D_CreateImage", "Image file `%s` not found", path);
13
+ if (!R2D_FileExists(path)) {
14
+ R2D_Error("R2D_CreateImage", "Image file `%s` not found", path);
15
15
  return NULL;
16
16
  }
17
17
 
18
18
  // Allocate the image structure
19
- S2D_Image *img = (S2D_Image *) malloc(sizeof(S2D_Image));
19
+ R2D_Image *img = (R2D_Image *) malloc(sizeof(R2D_Image));
20
20
  if (!img) {
21
- S2D_Error("S2D_CreateImage", "Out of memory!");
21
+ R2D_Error("R2D_CreateImage", "Out of memory!");
22
22
  return NULL;
23
23
  }
24
24
 
25
25
  // Load image from file as SDL_Surface
26
26
  img->surface = IMG_Load(path);
27
27
  if (!img->surface) {
28
- S2D_Error("IMG_Load", IMG_GetError());
28
+ R2D_Error("IMG_Load", IMG_GetError());
29
29
  free(img);
30
30
  return NULL;
31
31
  }
@@ -35,7 +35,7 @@ S2D_Image *S2D_CreateImage(const char *path) {
35
35
  img->surface->format->BitsPerPixel / 4;
36
36
 
37
37
  if (bits_per_color < 8) {
38
- S2D_Log(S2D_WARN, "`%s` has less than 8 bits per color and will likely not render correctly", path, bits_per_color);
38
+ R2D_Log(R2D_WARN, "`%s` has less than 8 bits per color and will likely not render correctly", path, bits_per_color);
39
39
  }
40
40
 
41
41
  // Initialize values
@@ -99,9 +99,9 @@ S2D_Image *S2D_CreateImage(const char *path) {
99
99
  /*
100
100
  * Rotate an image
101
101
  */
102
- void S2D_RotateImage(S2D_Image *img, GLfloat angle, int position) {
102
+ void R2D_RotateImage(R2D_Image *img, GLfloat angle, int position) {
103
103
 
104
- S2D_GL_Point p = S2D_GetRectRotationPoint(
104
+ R2D_GL_Point p = R2D_GetRectRotationPoint(
105
105
  img->x, img->y, img->width, img->height, position
106
106
  );
107
107
 
@@ -114,25 +114,25 @@ void S2D_RotateImage(S2D_Image *img, GLfloat angle, int position) {
114
114
  /*
115
115
  * Draw an image
116
116
  */
117
- void S2D_DrawImage(S2D_Image *img) {
117
+ void R2D_DrawImage(R2D_Image *img) {
118
118
  if (!img) return;
119
119
 
120
120
  if (img->texture_id == 0) {
121
- S2D_GL_CreateTexture(&img->texture_id, img->format,
121
+ R2D_GL_CreateTexture(&img->texture_id, img->format,
122
122
  img->orig_width, img->orig_height,
123
123
  img->surface->pixels, GL_NEAREST);
124
124
  SDL_FreeSurface(img->surface);
125
125
  }
126
126
 
127
- S2D_GL_DrawImage(img);
127
+ R2D_GL_DrawImage(img);
128
128
  }
129
129
 
130
130
 
131
131
  /*
132
132
  * Free an image
133
133
  */
134
- void S2D_FreeImage(S2D_Image *img) {
134
+ void R2D_FreeImage(R2D_Image *img) {
135
135
  if (!img) return;
136
- S2D_GL_FreeTexture(&img->texture_id);
136
+ R2D_GL_FreeTexture(&img->texture_id);
137
137
  free(img);
138
138
  }
@@ -1,30 +1,30 @@
1
1
  // input.c
2
2
 
3
- #include "../include/simple2d.h"
3
+ #include "ruby2d.h"
4
4
 
5
5
 
6
6
  /*
7
7
  * Get the mouse coordinates relative to the viewport
8
8
  */
9
- void S2D_GetMouseOnViewport(S2D_Window *window, int wx, int wy, int *x, int *y) {
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 S2D_FIXED: case S2D_EXPAND:
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 S2D_SCALE:
22
- S2D_GL_GetViewportScale(window, &w, &h, &scale);
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 S2D_STRETCH:
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 S2D_ShowCursor() {
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 S2D_HideCursor() {
46
+ void R2D_HideCursor() {
47
47
  SDL_ShowCursor(SDL_DISABLE);
48
48
  }
@@ -1,31 +1,31 @@
1
1
  // music.c
2
2
 
3
- #include "../include/simple2d.h"
3
+ #include "ruby2d.h"
4
4
 
5
5
 
6
6
  /*
7
7
  * Create the music
8
8
  */
9
- S2D_Music *S2D_CreateMusic(const char *path) {
10
- S2D_Init();
9
+ R2D_Music *R2D_CreateMusic(const char *path) {
10
+ R2D_Init();
11
11
 
12
12
  // Check if music file exists
13
- if (!S2D_FileExists(path)) {
14
- S2D_Error("S2D_CreateMusic", "Music file `%s` not found", path);
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
- S2D_Music *mus = (S2D_Music *) malloc(sizeof(S2D_Music));
19
+ R2D_Music *mus = (R2D_Music *) malloc(sizeof(R2D_Music));
20
20
  if (!mus) {
21
- S2D_Error("S2D_CreateMusic", "Out of memory!");
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
- S2D_Error("Mix_LoadMUS", Mix_GetError());
28
+ R2D_Error("Mix_LoadMUS", Mix_GetError());
29
29
  free(mus);
30
30
  return NULL;
31
31
  }
@@ -33,6 +33,11 @@ S2D_Music *S2D_CreateMusic(const char *path) {
33
33
  // Initialize values
34
34
  mus->path = path;
35
35
 
36
+ // Calculate the length of music by creating a temporary R2D_Sound object
37
+ R2D_Sound *snd = R2D_CreateSound(path);
38
+ mus->length = R2D_GetSoundLength(snd);
39
+ R2D_FreeSound(snd);
40
+
36
41
  return mus;
37
42
  }
38
43
 
@@ -40,7 +45,7 @@ S2D_Music *S2D_CreateMusic(const char *path) {
40
45
  /*
41
46
  * Play the music
42
47
  */
43
- void S2D_PlayMusic(S2D_Music *mus, bool loop) {
48
+ void R2D_PlayMusic(R2D_Music *mus, bool loop) {
44
49
  if (!mus) return;
45
50
 
46
51
  // If looping, set to -1 times; else 0
@@ -49,7 +54,7 @@ void S2D_PlayMusic(S2D_Music *mus, bool loop) {
49
54
  // times: 0 == once, -1 == forever
50
55
  if (Mix_PlayMusic(mus->data, times) == -1) {
51
56
  // No music for you
52
- S2D_Error("S2D_PlayMusic", Mix_GetError());
57
+ R2D_Error("R2D_PlayMusic", Mix_GetError());
53
58
  }
54
59
  }
55
60
 
@@ -57,7 +62,7 @@ void S2D_PlayMusic(S2D_Music *mus, bool loop) {
57
62
  /*
58
63
  * Pause the playing music
59
64
  */
60
- void S2D_PauseMusic() {
65
+ void R2D_PauseMusic() {
61
66
  Mix_PauseMusic();
62
67
  }
63
68
 
@@ -65,7 +70,7 @@ void S2D_PauseMusic() {
65
70
  /*
66
71
  * Resume the current music
67
72
  */
68
- void S2D_ResumeMusic() {
73
+ void R2D_ResumeMusic() {
69
74
  Mix_ResumeMusic();
70
75
  }
71
76
 
@@ -73,7 +78,7 @@ void S2D_ResumeMusic() {
73
78
  /*
74
79
  * Stop the playing music; interrupts fader effects
75
80
  */
76
- void S2D_StopMusic() {
81
+ void R2D_StopMusic() {
77
82
  Mix_HaltMusic();
78
83
  }
79
84
 
@@ -81,7 +86,7 @@ void S2D_StopMusic() {
81
86
  /*
82
87
  * Get the music volume
83
88
  */
84
- int S2D_GetMusicVolume() {
89
+ int R2D_GetMusicVolume() {
85
90
  // Get music volume as percentage of maximum mix volume
86
91
  return ceil(Mix_VolumeMusic(-1) * (100.0 / MIX_MAX_VOLUME));
87
92
  }
@@ -90,7 +95,7 @@ int S2D_GetMusicVolume() {
90
95
  /*
91
96
  * Set the music volume a given percentage
92
97
  */
93
- void S2D_SetMusicVolume(int volume) {
98
+ void R2D_SetMusicVolume(int volume) {
94
99
  // Set volume to be a percentage of the maximum mix volume
95
100
  Mix_VolumeMusic((volume / 100.0) * MIX_MAX_VOLUME);
96
101
  }
@@ -99,15 +104,23 @@ void S2D_SetMusicVolume(int volume) {
99
104
  /*
100
105
  * Fade out the playing music
101
106
  */
102
- void S2D_FadeOutMusic(int ms) {
107
+ void R2D_FadeOutMusic(int ms) {
103
108
  Mix_FadeOutMusic(ms);
104
109
  }
105
110
 
106
111
 
112
+ /*
113
+ * Get the length of the music in seconds
114
+ */
115
+ int R2D_GetMusicLength(R2D_Music *mus) {
116
+ return mus->length;
117
+ }
118
+
119
+
107
120
  /*
108
121
  * Free the music
109
122
  */
110
- void S2D_FreeMusic(S2D_Music *mus) {
123
+ void R2D_FreeMusic(R2D_Music *mus) {
111
124
  if (!mus) return;
112
125
  Mix_FreeMusic(mus->data);
113
126
  free(mus);
data/ext/ruby2d/ruby2d.c CHANGED
@@ -1,10 +1,9 @@
1
1
  // Native C extension for Ruby and MRuby
2
2
 
3
- // Simple 2D includes
3
+ // Ruby 2D includes
4
4
  #if RUBY2D_IOS_TVOS
5
- #include <Simple2D/simple2d.h>
6
5
  #else
7
- #include <simple2d.h>
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
- // Simple 2D window
107
- static S2D_Window *window;
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(S2D_Image *img);
134
- static void free_sprite(S2D_Sprite *spr);
135
- static void free_text(S2D_Text *txt);
136
- static void free_sound(S2D_Sound *snd);
137
- static void free_music(S2D_Music *mus);
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 Simple 2D window
141
+ * Function pointer to free the Ruby 2D native window
143
142
  */
144
143
  static void free_window() {
145
- S2D_FreeWindow(window);
144
+ R2D_FreeWindow(window);
146
145
  }
147
146
 
148
147
 
@@ -167,38 +166,45 @@ static R_VAL ruby2d_ext_base_path(R_VAL self) {
167
166
 
168
167
 
169
168
  /*
170
- * Ruby2D::Triangle#ext_render
169
+ * Ruby2D::Pixel#self.ext_draw
171
170
  */
172
171
  #if MRUBY
173
- static R_VAL ruby2d_triangle_ext_render(mrb_state* mrb, R_VAL self) {
172
+ static R_VAL ruby2d_pixel_ext_draw(mrb_state* mrb, R_VAL self) {
173
+ mrb_value a;
174
+ mrb_get_args(mrb, "o", &a);
174
175
  #else
175
- static R_VAL ruby2d_triangle_ext_render(R_VAL self) {
176
+ static R_VAL ruby2d_pixel_ext_draw(R_VAL self, R_VAL a) {
176
177
  #endif
177
- R_VAL c1 = r_iv_get(self, "@c1");
178
- R_VAL c2 = r_iv_get(self, "@c2");
179
- R_VAL c3 = r_iv_get(self, "@c3");
180
-
181
- S2D_DrawTriangle(
182
- NUM2DBL(r_iv_get(self, "@x1")),
183
- NUM2DBL(r_iv_get(self, "@y1")),
184
- NUM2DBL(r_iv_get(c1, "@r")),
185
- NUM2DBL(r_iv_get(c1, "@g")),
186
- NUM2DBL(r_iv_get(c1, "@b")),
187
- NUM2DBL(r_iv_get(c1, "@a")),
188
-
189
- NUM2DBL(r_iv_get(self, "@x2")),
190
- NUM2DBL(r_iv_get(self, "@y2")),
191
- NUM2DBL(r_iv_get(c2, "@r")),
192
- NUM2DBL(r_iv_get(c2, "@g")),
193
- NUM2DBL(r_iv_get(c2, "@b")),
194
- NUM2DBL(r_iv_get(c2, "@a")),
195
-
196
- NUM2DBL(r_iv_get(self, "@x3")),
197
- NUM2DBL(r_iv_get(self, "@y3")),
198
- NUM2DBL(r_iv_get(c3, "@r")),
199
- NUM2DBL(r_iv_get(c3, "@g")),
200
- NUM2DBL(r_iv_get(c3, "@b")),
201
- NUM2DBL(r_iv_get(c3, "@a"))
178
+ // `a` is the array representing the pixel
179
+
180
+ R2D_DrawQuad(
181
+ NUM2DBL(r_ary_entry(a, 0)), // x1
182
+ NUM2DBL(r_ary_entry(a, 1)), // y1
183
+ NUM2DBL(r_ary_entry(a, 8)), // color
184
+ NUM2DBL(r_ary_entry(a, 9)), // color
185
+ NUM2DBL(r_ary_entry(a, 10)), // color
186
+ NUM2DBL(r_ary_entry(a, 11)), // color
187
+
188
+ NUM2DBL(r_ary_entry(a, 2)), // x2
189
+ NUM2DBL(r_ary_entry(a, 3)), // y2
190
+ NUM2DBL(r_ary_entry(a, 8)), // color
191
+ NUM2DBL(r_ary_entry(a, 9)), // color
192
+ NUM2DBL(r_ary_entry(a, 10)), // color
193
+ NUM2DBL(r_ary_entry(a, 11)), // color
194
+
195
+ NUM2DBL(r_ary_entry(a, 4)), // x3
196
+ NUM2DBL(r_ary_entry(a, 5)), // y3
197
+ NUM2DBL(r_ary_entry(a, 8)), // color
198
+ NUM2DBL(r_ary_entry(a, 9)), // color
199
+ NUM2DBL(r_ary_entry(a, 10)), // color
200
+ NUM2DBL(r_ary_entry(a, 11)), // color
201
+
202
+ NUM2DBL(r_ary_entry(a, 6)), // x4
203
+ NUM2DBL(r_ary_entry(a, 7)), // y4
204
+ NUM2DBL(r_ary_entry(a, 8)), // color
205
+ NUM2DBL(r_ary_entry(a, 9)), // color
206
+ NUM2DBL(r_ary_entry(a, 10)), // color
207
+ NUM2DBL(r_ary_entry(a, 11)) // color
202
208
  );
203
209
 
204
210
  return R_NIL;
@@ -206,46 +212,38 @@ static R_VAL ruby2d_triangle_ext_render(R_VAL self) {
206
212
 
207
213
 
208
214
  /*
209
- * Ruby2D::Quad#ext_render
215
+ * Ruby2D::Triangle#self.ext_draw
210
216
  */
211
217
  #if MRUBY
212
- static R_VAL ruby2d_quad_ext_render(mrb_state* mrb, R_VAL self) {
218
+ static R_VAL ruby2d_triangle_ext_draw(mrb_state* mrb, R_VAL self) {
219
+ mrb_value a;
220
+ mrb_get_args(mrb, "o", &a);
213
221
  #else
214
- static R_VAL ruby2d_quad_ext_render(R_VAL self) {
222
+ static R_VAL ruby2d_triangle_ext_draw(R_VAL self, R_VAL a) {
215
223
  #endif
216
- R_VAL c1 = r_iv_get(self, "@c1");
217
- R_VAL c2 = r_iv_get(self, "@c2");
218
- R_VAL c3 = r_iv_get(self, "@c3");
219
- R_VAL c4 = r_iv_get(self, "@c4");
220
-
221
- S2D_DrawQuad(
222
- NUM2DBL(r_iv_get(self, "@x1")),
223
- NUM2DBL(r_iv_get(self, "@y1")),
224
- NUM2DBL(r_iv_get(c1, "@r")),
225
- NUM2DBL(r_iv_get(c1, "@g")),
226
- NUM2DBL(r_iv_get(c1, "@b")),
227
- NUM2DBL(r_iv_get(c1, "@a")),
228
-
229
- NUM2DBL(r_iv_get(self, "@x2")),
230
- NUM2DBL(r_iv_get(self, "@y2")),
231
- NUM2DBL(r_iv_get(c2, "@r")),
232
- NUM2DBL(r_iv_get(c2, "@g")),
233
- NUM2DBL(r_iv_get(c2, "@b")),
234
- NUM2DBL(r_iv_get(c2, "@a")),
235
-
236
- NUM2DBL(r_iv_get(self, "@x3")),
237
- NUM2DBL(r_iv_get(self, "@y3")),
238
- NUM2DBL(r_iv_get(c3, "@r")),
239
- NUM2DBL(r_iv_get(c3, "@g")),
240
- NUM2DBL(r_iv_get(c3, "@b")),
241
- NUM2DBL(r_iv_get(c3, "@a")),
242
-
243
- NUM2DBL(r_iv_get(self, "@x4")),
244
- NUM2DBL(r_iv_get(self, "@y4")),
245
- NUM2DBL(r_iv_get(c4, "@r")),
246
- NUM2DBL(r_iv_get(c4, "@g")),
247
- NUM2DBL(r_iv_get(c4, "@b")),
248
- NUM2DBL(r_iv_get(c4, "@a"))
224
+ // `a` is the array representing the triangle
225
+
226
+ R2D_DrawTriangle(
227
+ NUM2DBL(r_ary_entry(a, 0)), // x1
228
+ NUM2DBL(r_ary_entry(a, 1)), // y1
229
+ NUM2DBL(r_ary_entry(a, 2)), // c1 red
230
+ NUM2DBL(r_ary_entry(a, 3)), // c1 green
231
+ NUM2DBL(r_ary_entry(a, 4)), // c1 blue
232
+ NUM2DBL(r_ary_entry(a, 5)), // c1 alpha
233
+
234
+ NUM2DBL(r_ary_entry(a, 6)), // x2
235
+ NUM2DBL(r_ary_entry(a, 7)), // y2
236
+ NUM2DBL(r_ary_entry(a, 8)), // c2 red
237
+ NUM2DBL(r_ary_entry(a, 9)), // c2 green
238
+ NUM2DBL(r_ary_entry(a, 10)), // c2 blue
239
+ NUM2DBL(r_ary_entry(a, 11)), // c2 alpha
240
+
241
+ NUM2DBL(r_ary_entry(a, 12)), // x3
242
+ NUM2DBL(r_ary_entry(a, 13)), // y3
243
+ NUM2DBL(r_ary_entry(a, 14)), // c3 red
244
+ NUM2DBL(r_ary_entry(a, 15)), // c3 green
245
+ NUM2DBL(r_ary_entry(a, 16)), // c3 blue
246
+ NUM2DBL(r_ary_entry(a, 17)) // c3 alpha
249
247
  );
250
248
 
251
249
  return R_NIL;
@@ -253,44 +251,45 @@ static R_VAL ruby2d_quad_ext_render(R_VAL self) {
253
251
 
254
252
 
255
253
  /*
256
- * Ruby2D::Line#ext_render
254
+ * Ruby2D::Quad#self.ext_draw
257
255
  */
258
256
  #if MRUBY
259
- static R_VAL ruby2d_line_ext_render(mrb_state* mrb, R_VAL self) {
257
+ static R_VAL ruby2d_quad_ext_draw(mrb_state* mrb, R_VAL self) {
258
+ mrb_value a;
259
+ mrb_get_args(mrb, "o", &a);
260
260
  #else
261
- static R_VAL ruby2d_line_ext_render(R_VAL self) {
261
+ static R_VAL ruby2d_quad_ext_draw(R_VAL self, R_VAL a) {
262
262
  #endif
263
- R_VAL c1 = r_iv_get(self, "@c1");
264
- R_VAL c2 = r_iv_get(self, "@c2");
265
- R_VAL c3 = r_iv_get(self, "@c3");
266
- R_VAL c4 = r_iv_get(self, "@c4");
267
-
268
- S2D_DrawLine(
269
- NUM2DBL(r_iv_get(self, "@x1")),
270
- NUM2DBL(r_iv_get(self, "@y1")),
271
- NUM2DBL(r_iv_get(self, "@x2")),
272
- NUM2DBL(r_iv_get(self, "@y2")),
273
- NUM2DBL(r_iv_get(self, "@width")),
274
-
275
- NUM2DBL(r_iv_get(c1, "@r")),
276
- NUM2DBL(r_iv_get(c1, "@g")),
277
- NUM2DBL(r_iv_get(c1, "@b")),
278
- NUM2DBL(r_iv_get(c1, "@a")),
279
-
280
- NUM2DBL(r_iv_get(c2, "@r")),
281
- NUM2DBL(r_iv_get(c2, "@g")),
282
- NUM2DBL(r_iv_get(c2, "@b")),
283
- NUM2DBL(r_iv_get(c2, "@a")),
284
-
285
- NUM2DBL(r_iv_get(c3, "@r")),
286
- NUM2DBL(r_iv_get(c3, "@g")),
287
- NUM2DBL(r_iv_get(c3, "@b")),
288
- NUM2DBL(r_iv_get(c3, "@a")),
289
-
290
- NUM2DBL(r_iv_get(c4, "@r")),
291
- NUM2DBL(r_iv_get(c4, "@g")),
292
- NUM2DBL(r_iv_get(c4, "@b")),
293
- NUM2DBL(r_iv_get(c4, "@a"))
263
+ // `a` is the array representing the quad
264
+
265
+ R2D_DrawQuad(
266
+ NUM2DBL(r_ary_entry(a, 0)), // x1
267
+ NUM2DBL(r_ary_entry(a, 1)), // y1
268
+ NUM2DBL(r_ary_entry(a, 2)), // c1 red
269
+ NUM2DBL(r_ary_entry(a, 3)), // c1 green
270
+ NUM2DBL(r_ary_entry(a, 4)), // c1 blue
271
+ NUM2DBL(r_ary_entry(a, 5)), // c1 alpha
272
+
273
+ NUM2DBL(r_ary_entry(a, 6)), // x2
274
+ NUM2DBL(r_ary_entry(a, 7)), // y2
275
+ NUM2DBL(r_ary_entry(a, 8)), // c2 red
276
+ NUM2DBL(r_ary_entry(a, 9)), // c2 green
277
+ NUM2DBL(r_ary_entry(a, 10)), // c2 blue
278
+ NUM2DBL(r_ary_entry(a, 11)), // c2 alpha
279
+
280
+ NUM2DBL(r_ary_entry(a, 12)), // x3
281
+ NUM2DBL(r_ary_entry(a, 13)), // y3
282
+ NUM2DBL(r_ary_entry(a, 14)), // c3 red
283
+ NUM2DBL(r_ary_entry(a, 15)), // c3 green
284
+ NUM2DBL(r_ary_entry(a, 16)), // c3 blue
285
+ NUM2DBL(r_ary_entry(a, 17)), // c3 alpha
286
+
287
+ NUM2DBL(r_ary_entry(a, 18)), // x4
288
+ NUM2DBL(r_ary_entry(a, 19)), // y4
289
+ NUM2DBL(r_ary_entry(a, 20)), // c4 red
290
+ NUM2DBL(r_ary_entry(a, 21)), // c4 green
291
+ NUM2DBL(r_ary_entry(a, 22)), // c4 blue
292
+ NUM2DBL(r_ary_entry(a, 23)) // c4 alpha
294
293
  );
295
294
 
296
295
  return R_NIL;
@@ -298,24 +297,70 @@ static R_VAL ruby2d_line_ext_render(R_VAL self) {
298
297
 
299
298
 
300
299
  /*
301
- * Ruby2D::Circle#ext_render
300
+ * Ruby2D::Line#self.ext_draw
302
301
  */
303
302
  #if MRUBY
304
- static R_VAL ruby2d_circle_ext_render(mrb_state* mrb, R_VAL self) {
303
+ static R_VAL ruby2d_line_ext_draw(mrb_state* mrb, R_VAL self) {
304
+ mrb_value a;
305
+ mrb_get_args(mrb, "o", &a);
305
306
  #else
306
- static R_VAL ruby2d_circle_ext_render(R_VAL self) {
307
+ static R_VAL ruby2d_line_ext_draw(R_VAL self, R_VAL a) {
307
308
  #endif
308
- R_VAL c = r_iv_get(self, "@color");
309
-
310
- S2D_DrawCircle(
311
- NUM2DBL(r_iv_get(self, "@x")),
312
- NUM2DBL(r_iv_get(self, "@y")),
313
- NUM2DBL(r_iv_get(self, "@radius")),
314
- NUM2DBL(r_iv_get(self, "@sectors")),
315
- NUM2DBL(r_iv_get(c, "@r")),
316
- NUM2DBL(r_iv_get(c, "@g")),
317
- NUM2DBL(r_iv_get(c, "@b")),
318
- NUM2DBL(r_iv_get(c, "@a"))
309
+ // `a` is the array representing the line
310
+
311
+ R2D_DrawLine(
312
+ NUM2DBL(r_ary_entry(a, 0)), // x1
313
+ NUM2DBL(r_ary_entry(a, 1)), // y1
314
+ NUM2DBL(r_ary_entry(a, 2)), // x2
315
+ NUM2DBL(r_ary_entry(a, 3)), // y2
316
+ NUM2DBL(r_ary_entry(a, 4)), // width
317
+
318
+ NUM2DBL(r_ary_entry(a, 5)), // c1 red
319
+ NUM2DBL(r_ary_entry(a, 6)), // c1 green
320
+ NUM2DBL(r_ary_entry(a, 7)), // c1 blue
321
+ NUM2DBL(r_ary_entry(a, 8)), // c1 alpha
322
+
323
+ NUM2DBL(r_ary_entry(a, 9)), // c2 red
324
+ NUM2DBL(r_ary_entry(a, 10)), // c2 green
325
+ NUM2DBL(r_ary_entry(a, 11)), // c2 blue
326
+ NUM2DBL(r_ary_entry(a, 12)), // c2 alpha
327
+
328
+ NUM2DBL(r_ary_entry(a, 13)), // c3 red
329
+ NUM2DBL(r_ary_entry(a, 14)), // c3 green
330
+ NUM2DBL(r_ary_entry(a, 15)), // c3 blue
331
+ NUM2DBL(r_ary_entry(a, 16)), // c3 alpha
332
+
333
+ NUM2DBL(r_ary_entry(a, 17)), // c4 red
334
+ NUM2DBL(r_ary_entry(a, 18)), // c4 green
335
+ NUM2DBL(r_ary_entry(a, 19)), // c4 blue
336
+ NUM2DBL(r_ary_entry(a, 20)) // c4 alpha
337
+ );
338
+
339
+ return R_NIL;
340
+ }
341
+
342
+
343
+ /*
344
+ * Ruby2D::Circle#self.ext_draw
345
+ */
346
+ #if MRUBY
347
+ static R_VAL ruby2d_circle_ext_draw(mrb_state* mrb, R_VAL self) {
348
+ mrb_value a;
349
+ mrb_get_args(mrb, "o", &a);
350
+ #else
351
+ static R_VAL ruby2d_circle_ext_draw(R_VAL self, R_VAL a) {
352
+ #endif
353
+ // `a` is the array representing the circle
354
+
355
+ R2D_DrawCircle(
356
+ NUM2DBL(r_ary_entry(a, 0)), // x
357
+ NUM2DBL(r_ary_entry(a, 1)), // y
358
+ NUM2DBL(r_ary_entry(a, 2)), // radius
359
+ NUM2DBL(r_ary_entry(a, 3)), // sectors
360
+ NUM2DBL(r_ary_entry(a, 4)), // red
361
+ NUM2DBL(r_ary_entry(a, 5)), // green
362
+ NUM2DBL(r_ary_entry(a, 6)), // blue
363
+ NUM2DBL(r_ary_entry(a, 7)) // alpha
319
364
  );
320
365
 
321
366
  return R_NIL;
@@ -333,7 +378,7 @@ static R_VAL ruby2d_image_ext_init(mrb_state* mrb, R_VAL self) {
333
378
  #else
334
379
  static R_VAL ruby2d_image_ext_init(R_VAL self, R_VAL path) {
335
380
  #endif
336
- S2D_Image *img = S2D_CreateImage(RSTRING_PTR(path));
381
+ R2D_Image *img = R2D_CreateImage(RSTRING_PTR(path));
337
382
  if (!img) return R_FALSE;
338
383
 
339
384
  // Get width and height from Ruby class. If set, use it, else choose the
@@ -349,34 +394,36 @@ static R_VAL ruby2d_image_ext_init(R_VAL self, R_VAL path) {
349
394
 
350
395
 
351
396
  /*
352
- * Ruby2D::Image#ext_render
397
+ * Ruby2D::Image#self.ext_draw
353
398
  */
354
399
  #if MRUBY
355
- static R_VAL ruby2d_image_ext_render(mrb_state* mrb, R_VAL self) {
400
+ static R_VAL ruby2d_image_ext_draw(mrb_state* mrb, R_VAL self) {
401
+ mrb_value a;
402
+ mrb_get_args(mrb, "o", &a);
356
403
  #else
357
- static R_VAL ruby2d_image_ext_render(R_VAL self) {
404
+ static R_VAL ruby2d_image_ext_draw(R_VAL self, R_VAL a) {
358
405
  #endif
359
- S2D_Image *img;
360
- r_data_get_struct(self, "@data", &image_data_type, S2D_Image, img);
406
+ // `a` is the array representing the image
361
407
 
362
- img->x = NUM2DBL(r_iv_get(self, "@x"));
363
- img->y = NUM2DBL(r_iv_get(self, "@y"));
408
+ R2D_Image *img;
409
+ r_data_get_struct(r_ary_entry(a, 0), "@data", &image_data_type, R2D_Image, img);
364
410
 
365
- R_VAL w = r_iv_get(self, "@width");
366
- R_VAL h = r_iv_get(self, "@height");
411
+ img->x = NUM2DBL(r_ary_entry(a, 1));
412
+ img->y = NUM2DBL(r_ary_entry(a, 2));
413
+
414
+ R_VAL w = r_ary_entry(a, 3);
415
+ R_VAL h = r_ary_entry(a, 4);
367
416
  if (r_test(w)) img->width = NUM2INT(w);
368
417
  if (r_test(h)) img->height = NUM2INT(h);
369
418
 
370
- S2D_RotateImage(img, NUM2DBL(r_iv_get(self, "@rotate")), S2D_CENTER);
419
+ R2D_RotateImage(img, NUM2DBL(r_ary_entry(a, 5)), R2D_CENTER);
371
420
 
372
- R_VAL c = r_iv_get(self, "@color");
373
- img->color.r = NUM2DBL(r_iv_get(c, "@r"));
374
- img->color.g = NUM2DBL(r_iv_get(c, "@g"));
375
- img->color.b = NUM2DBL(r_iv_get(c, "@b"));
376
- img->color.a = NUM2DBL(r_iv_get(c, "@a"));
377
-
378
- S2D_DrawImage(img);
421
+ img->color.r = NUM2DBL(r_ary_entry(a, 6));
422
+ img->color.g = NUM2DBL(r_ary_entry(a, 7));
423
+ img->color.b = NUM2DBL(r_ary_entry(a, 8));
424
+ img->color.a = NUM2DBL(r_ary_entry(a, 9));
379
425
 
426
+ R2D_DrawImage(img);
380
427
  return R_NIL;
381
428
  }
382
429
 
@@ -386,11 +433,11 @@ static R_VAL ruby2d_image_ext_render(R_VAL self) {
386
433
  */
387
434
  #if MRUBY
388
435
  static void free_image(mrb_state *mrb, void *p_) {
389
- S2D_Image *img = (S2D_Image *)p_;
436
+ R2D_Image *img = (R2D_Image *)p_;
390
437
  #else
391
- static void free_image(S2D_Image *img) {
438
+ static void free_image(R2D_Image *img) {
392
439
  #endif
393
- S2D_FreeImage(img);
440
+ R2D_FreeImage(img);
394
441
  }
395
442
 
396
443
 
@@ -405,7 +452,7 @@ static R_VAL ruby2d_sprite_ext_init(mrb_state* mrb, R_VAL self) {
405
452
  #else
406
453
  static R_VAL ruby2d_sprite_ext_init(R_VAL self, R_VAL path) {
407
454
  #endif
408
- S2D_Sprite *spr = S2D_CreateSprite(RSTRING_PTR(path));
455
+ R2D_Sprite *spr = R2D_CreateSprite(RSTRING_PTR(path));
409
456
  if (!spr) return R_FALSE;
410
457
 
411
458
  r_iv_set(self, "@img_width" , INT2NUM(spr->width));
@@ -417,45 +464,45 @@ static R_VAL ruby2d_sprite_ext_init(R_VAL self, R_VAL path) {
417
464
 
418
465
 
419
466
  /*
420
- * Ruby2D::Sprite#ext_render
467
+ * Ruby2D::Sprite#ext_draw
421
468
  */
422
469
  #if MRUBY
423
- static R_VAL ruby2d_sprite_ext_render(mrb_state* mrb, R_VAL self) {
470
+ static R_VAL ruby2d_sprite_ext_draw(mrb_state* mrb, R_VAL self) {
471
+ mrb_value a;
472
+ mrb_get_args(mrb, "o", &a);
424
473
  #else
425
- static R_VAL ruby2d_sprite_ext_render(R_VAL self) {
474
+ static R_VAL ruby2d_sprite_ext_draw(R_VAL self, R_VAL a) {
426
475
  #endif
427
- r_funcall(self, "update", 0);
476
+ // `a` is the array representing the sprite
428
477
 
429
- S2D_Sprite *spr;
430
- r_data_get_struct(self, "@data", &sprite_data_type, S2D_Sprite, spr);
478
+ R2D_Sprite *spr;
479
+ r_data_get_struct(r_ary_entry(a, 0), "@data", &sprite_data_type, R2D_Sprite, spr);
431
480
 
432
- spr->x = NUM2DBL(r_iv_get(self, "@flip_x"));
433
- spr->y = NUM2DBL(r_iv_get(self, "@flip_y"));
481
+ spr->x = NUM2DBL(r_ary_entry(a, 1));
482
+ spr->y = NUM2DBL(r_ary_entry(a, 2));
434
483
 
435
- R_VAL w = r_iv_get(self, "@flip_width");
484
+ R_VAL w = r_ary_entry(a, 3);
436
485
  if (r_test(w)) spr->width = NUM2DBL(w);
437
486
 
438
- R_VAL h = r_iv_get(self, "@flip_height");
487
+ R_VAL h = r_ary_entry(a, 4);
439
488
  if (r_test(h)) spr->height = NUM2DBL(h);
440
489
 
441
- S2D_RotateSprite(spr, NUM2DBL(r_iv_get(self, "@rotate")), S2D_CENTER);
442
-
443
- R_VAL c = r_iv_get(self, "@color");
444
- spr->color.r = NUM2DBL(r_iv_get(c, "@r"));
445
- spr->color.g = NUM2DBL(r_iv_get(c, "@g"));
446
- spr->color.b = NUM2DBL(r_iv_get(c, "@b"));
447
- spr->color.a = NUM2DBL(r_iv_get(c, "@a"));
490
+ R2D_RotateSprite(spr, NUM2DBL(r_ary_entry(a, 5)), R2D_CENTER);
448
491
 
449
- S2D_ClipSprite(
492
+ R2D_ClipSprite(
450
493
  spr,
451
- NUM2INT(r_iv_get(self, "@clip_x")),
452
- NUM2INT(r_iv_get(self, "@clip_y")),
453
- NUM2INT(r_iv_get(self, "@clip_width")),
454
- NUM2INT(r_iv_get(self, "@clip_height"))
494
+ NUM2INT(r_ary_entry(a, 6)),
495
+ NUM2INT(r_ary_entry(a, 7)),
496
+ NUM2INT(r_ary_entry(a, 8)),
497
+ NUM2INT(r_ary_entry(a, 9))
455
498
  );
456
499
 
457
- S2D_DrawSprite(spr);
500
+ spr->color.r = NUM2DBL(r_ary_entry(a, 10));
501
+ spr->color.g = NUM2DBL(r_ary_entry(a, 11));
502
+ spr->color.b = NUM2DBL(r_ary_entry(a, 12));
503
+ spr->color.a = NUM2DBL(r_ary_entry(a, 13));
458
504
 
505
+ R2D_DrawSprite(spr);
459
506
  return R_NIL;
460
507
  }
461
508
 
@@ -465,11 +512,55 @@ static R_VAL ruby2d_sprite_ext_render(R_VAL self) {
465
512
  */
466
513
  #if MRUBY
467
514
  static void free_sprite(mrb_state *mrb, void *p_) {
468
- S2D_Sprite *spr = (S2D_Sprite *)p_;
515
+ R2D_Sprite *spr = (R2D_Sprite *)p_;
469
516
  #else
470
- static void free_sprite(S2D_Sprite *spr) {
517
+ static void free_sprite(R2D_Sprite *spr) {
471
518
  #endif
472
- S2D_FreeSprite(spr);
519
+ R2D_FreeSprite(spr);
520
+ }
521
+
522
+
523
+ /*
524
+ * Ruby2D::Tileset#ext_init
525
+ * Initialize tileset data
526
+ */
527
+ static R_VAL ruby2d_tileset_ext_init(R_VAL self, R_VAL path) {
528
+ R2D_Image *img = R2D_CreateImage(RSTRING_PTR(path));
529
+ if (!img) return R_FALSE;
530
+
531
+ // Get width and height from Ruby class. If set, use it, else choose the
532
+ // native dimensions of the image.
533
+ R_VAL w = r_iv_get(self, "@width");
534
+ R_VAL h = r_iv_get(self, "@height");
535
+ r_iv_set(self, "@width" , r_test(w) ? w : INT2NUM(img->width));
536
+ r_iv_set(self, "@height", r_test(h) ? h : INT2NUM(img->height));
537
+ r_iv_set(self, "@data", r_data_wrap_struct(image, img));
538
+
539
+ return R_TRUE;
540
+ }
541
+
542
+
543
+ /*
544
+ * Ruby2D::Tileset#ext_draw
545
+ * Draws a single tile, will be called once per individual tile to draw
546
+ */
547
+ static R_VAL ruby2d_tileset_ext_draw(R_VAL self, R_VAL a) {
548
+ // `a` is the array representing the tileset
549
+
550
+ R2D_Image *img;
551
+ r_data_get_struct(r_ary_entry(a, 0), "@data", &image_data_type, R2D_Image, img);
552
+
553
+ int tw = NUM2INT(r_ary_entry(a, 1));
554
+ int th = NUM2INT(r_ary_entry(a, 2));
555
+ int padding = NUM2INT(r_ary_entry(a, 3));
556
+ int spacing = NUM2INT(r_ary_entry(a, 4));
557
+ int tx = NUM2INT(r_ary_entry(a, 5));
558
+ int ty = NUM2INT(r_ary_entry(a, 6));
559
+ int x = NUM2INT(r_ary_entry(a, 7));
560
+ int y = NUM2INT(r_ary_entry(a, 8));
561
+
562
+ R2D_DrawTile(img, tw, th, padding, spacing, tx, ty, x, y);
563
+ return R_NIL;
473
564
  }
474
565
 
475
566
 
@@ -488,7 +579,7 @@ static R_VAL ruby2d_text_ext_init(R_VAL self) {
488
579
  mrb_str_resize(mrb, s, RSTRING_LEN(s));
489
580
  #endif
490
581
 
491
- S2D_Text *txt = S2D_CreateText(
582
+ R2D_Text *txt = R2D_CreateText(
492
583
  RSTRING_PTR(r_iv_get(self, "@font")),
493
584
  RSTRING_PTR(r_iv_get(self, "@text")),
494
585
  NUM2DBL(r_iv_get(self, "@size"))
@@ -513,10 +604,10 @@ static R_VAL ruby2d_text_ext_set(mrb_state* mrb, R_VAL self) {
513
604
  #else
514
605
  static R_VAL ruby2d_text_ext_set(R_VAL self, R_VAL text) {
515
606
  #endif
516
- S2D_Text *txt;
517
- r_data_get_struct(self, "@data", &text_data_type, S2D_Text, txt);
607
+ R2D_Text *txt;
608
+ r_data_get_struct(self, "@data", &text_data_type, R2D_Text, txt);
518
609
 
519
- S2D_SetText(txt, RSTRING_PTR(text));
610
+ R2D_SetText(txt, RSTRING_PTR(text));
520
611
 
521
612
  r_iv_set(self, "@width", INT2NUM(txt->width));
522
613
  r_iv_set(self, "@height", INT2NUM(txt->height));
@@ -526,29 +617,31 @@ static R_VAL ruby2d_text_ext_set(R_VAL self, R_VAL text) {
526
617
 
527
618
 
528
619
  /*
529
- * Ruby2D::Text#ext_render
620
+ * Ruby2D::Text#self.ext_draw
530
621
  */
531
622
  #if MRUBY
532
- static R_VAL ruby2d_text_ext_render(mrb_state* mrb, R_VAL self) {
623
+ static R_VAL ruby2d_text_ext_draw(mrb_state* mrb, R_VAL self) {
624
+ mrb_value a;
625
+ mrb_get_args(mrb, "o", &a);
533
626
  #else
534
- static R_VAL ruby2d_text_ext_render(R_VAL self) {
627
+ static R_VAL ruby2d_text_ext_draw(R_VAL self, R_VAL a) {
535
628
  #endif
536
- S2D_Text *txt;
537
- r_data_get_struct(self, "@data", &text_data_type, S2D_Text, txt);
629
+ // `a` is the array representing the text
538
630
 
539
- txt->x = NUM2DBL(r_iv_get(self, "@x"));
540
- txt->y = NUM2DBL(r_iv_get(self, "@y"));
631
+ R2D_Text *txt;
632
+ r_data_get_struct(r_ary_entry(a, 0), "@data", &text_data_type, R2D_Text, txt);
541
633
 
542
- S2D_RotateText(txt, NUM2DBL(r_iv_get(self, "@rotate")), S2D_CENTER);
634
+ txt->x = NUM2DBL(r_ary_entry(a, 1));
635
+ txt->y = NUM2DBL(r_ary_entry(a, 2));
543
636
 
544
- R_VAL c = r_iv_get(self, "@color");
545
- txt->color.r = NUM2DBL(r_iv_get(c, "@r"));
546
- txt->color.g = NUM2DBL(r_iv_get(c, "@g"));
547
- txt->color.b = NUM2DBL(r_iv_get(c, "@b"));
548
- txt->color.a = NUM2DBL(r_iv_get(c, "@a"));
637
+ R2D_RotateText(txt, NUM2DBL(r_ary_entry(a, 3)), R2D_CENTER);
549
638
 
550
- S2D_DrawText(txt);
639
+ txt->color.r = NUM2DBL(r_ary_entry(a, 4));
640
+ txt->color.g = NUM2DBL(r_ary_entry(a, 5));
641
+ txt->color.b = NUM2DBL(r_ary_entry(a, 6));
642
+ txt->color.a = NUM2DBL(r_ary_entry(a, 7));
551
643
 
644
+ R2D_DrawText(txt);
552
645
  return R_NIL;
553
646
  }
554
647
 
@@ -558,11 +651,11 @@ static R_VAL ruby2d_text_ext_render(R_VAL self) {
558
651
  */
559
652
  #if MRUBY
560
653
  static void free_text(mrb_state *mrb, void *p_) {
561
- S2D_Text *txt = (S2D_Text *)p_;
654
+ R2D_Text *txt = (R2D_Text *)p_;
562
655
  #else
563
- static void free_text(S2D_Text *txt) {
656
+ static void free_text(R2D_Text *txt) {
564
657
  #endif
565
- S2D_FreeText(txt);
658
+ R2D_FreeText(txt);
566
659
  }
567
660
 
568
661
 
@@ -577,7 +670,7 @@ static R_VAL ruby2d_sound_ext_init(mrb_state* mrb, R_VAL self) {
577
670
  #else
578
671
  static R_VAL ruby2d_sound_ext_init(R_VAL self, R_VAL path) {
579
672
  #endif
580
- S2D_Sound *snd = S2D_CreateSound(RSTRING_PTR(path));
673
+ R2D_Sound *snd = R2D_CreateSound(RSTRING_PTR(path));
581
674
  if (!snd) return R_FALSE;
582
675
  r_iv_set(self, "@data", r_data_wrap_struct(sound, snd));
583
676
  return R_TRUE;
@@ -592,23 +685,33 @@ static R_VAL ruby2d_sound_ext_play(mrb_state* mrb, R_VAL self) {
592
685
  #else
593
686
  static R_VAL ruby2d_sound_ext_play(R_VAL self) {
594
687
  #endif
595
- S2D_Sound *snd;
596
- r_data_get_struct(self, "@data", &sound_data_type, S2D_Sound, snd);
597
- S2D_PlaySound(snd);
688
+ R2D_Sound *snd;
689
+ r_data_get_struct(self, "@data", &sound_data_type, R2D_Sound, snd);
690
+ R2D_PlaySound(snd);
598
691
  return R_NIL;
599
692
  }
600
693
 
601
694
 
695
+ /*
696
+ * Ruby2D::Sound#ext_length
697
+ */
698
+ static R_VAL ruby2d_sound_ext_length(R_VAL self) {
699
+ R2D_Sound *snd;
700
+ r_data_get_struct(self, "@data", &sound_data_type, R2D_Sound, snd);
701
+ return INT2NUM(R2D_GetSoundLength(snd));
702
+ }
703
+
704
+
602
705
  /*
603
706
  * Free sound structure attached to Ruby 2D `Sound` class
604
707
  */
605
708
  #if MRUBY
606
709
  static void free_sound(mrb_state *mrb, void *p_) {
607
- S2D_Sound *snd = (S2D_Sound *)p_;
710
+ R2D_Sound *snd = (R2D_Sound *)p_;
608
711
  #else
609
- static void free_sound(S2D_Sound *snd) {
712
+ static void free_sound(R2D_Sound *snd) {
610
713
  #endif
611
- S2D_FreeSound(snd);
714
+ R2D_FreeSound(snd);
612
715
  }
613
716
 
614
717
 
@@ -623,7 +726,7 @@ static R_VAL ruby2d_music_ext_init(mrb_state* mrb, R_VAL self) {
623
726
  #else
624
727
  static R_VAL ruby2d_music_ext_init(R_VAL self, R_VAL path) {
625
728
  #endif
626
- S2D_Music *mus = S2D_CreateMusic(RSTRING_PTR(path));
729
+ R2D_Music *mus = R2D_CreateMusic(RSTRING_PTR(path));
627
730
  if (!mus) return R_FALSE;
628
731
  r_iv_set(self, "@data", r_data_wrap_struct(music, mus));
629
732
  return R_TRUE;
@@ -638,9 +741,9 @@ static R_VAL ruby2d_music_ext_play(mrb_state* mrb, R_VAL self) {
638
741
  #else
639
742
  static R_VAL ruby2d_music_ext_play(R_VAL self) {
640
743
  #endif
641
- S2D_Music *mus;
642
- r_data_get_struct(self, "@data", &music_data_type, S2D_Music, mus);
643
- S2D_PlayMusic(mus, r_test(r_iv_get(self, "@loop")));
744
+ R2D_Music *mus;
745
+ r_data_get_struct(self, "@data", &music_data_type, R2D_Music, mus);
746
+ R2D_PlayMusic(mus, r_test(r_iv_get(self, "@loop")));
644
747
  return R_NIL;
645
748
  }
646
749
 
@@ -653,7 +756,7 @@ static R_VAL ruby2d_music_ext_pause(mrb_state* mrb, R_VAL self) {
653
756
  #else
654
757
  static R_VAL ruby2d_music_ext_pause(R_VAL self) {
655
758
  #endif
656
- S2D_PauseMusic();
759
+ R2D_PauseMusic();
657
760
  return R_NIL;
658
761
  }
659
762
 
@@ -666,7 +769,7 @@ static R_VAL ruby2d_music_ext_resume(mrb_state* mrb, R_VAL self) {
666
769
  #else
667
770
  static R_VAL ruby2d_music_ext_resume(R_VAL self) {
668
771
  #endif
669
- S2D_ResumeMusic();
772
+ R2D_ResumeMusic();
670
773
  return R_NIL;
671
774
  }
672
775
 
@@ -679,7 +782,7 @@ static R_VAL ruby2d_music_ext_stop(mrb_state* mrb, R_VAL self) {
679
782
  #else
680
783
  static R_VAL ruby2d_music_ext_stop(R_VAL self) {
681
784
  #endif
682
- S2D_StopMusic();
785
+ R2D_StopMusic();
683
786
  return R_NIL;
684
787
  }
685
788
 
@@ -692,7 +795,7 @@ static R_VAL ruby2d_music_ext_get_volume(mrb_state* mrb, R_VAL self) {
692
795
  #else
693
796
  static R_VAL ruby2d_music_ext_get_volume(R_VAL self) {
694
797
  #endif
695
- return INT2NUM(S2D_GetMusicVolume());
798
+ return INT2NUM(R2D_GetMusicVolume());
696
799
  }
697
800
 
698
801
 
@@ -706,7 +809,7 @@ static R_VAL ruby2d_music_ext_set_volume(mrb_state* mrb, R_VAL self) {
706
809
  #else
707
810
  static R_VAL ruby2d_music_ext_set_volume(R_VAL self, R_VAL volume) {
708
811
  #endif
709
- S2D_SetMusicVolume(NUM2INT(volume));
812
+ R2D_SetMusicVolume(NUM2INT(volume));
710
813
  return R_NIL;
711
814
  }
712
815
 
@@ -721,39 +824,49 @@ static R_VAL ruby2d_music_ext_fadeout(mrb_state* mrb, R_VAL self) {
721
824
  #else
722
825
  static R_VAL ruby2d_music_ext_fadeout(R_VAL self, R_VAL ms) {
723
826
  #endif
724
- S2D_FadeOutMusic(NUM2INT(ms));
827
+ R2D_FadeOutMusic(NUM2INT(ms));
725
828
  return R_NIL;
726
829
  }
727
830
 
728
831
 
832
+ /*
833
+ * Ruby2D::Music#ext_length
834
+ */
835
+ static R_VAL ruby2d_music_ext_length(R_VAL self) {
836
+ R2D_Music *ms;
837
+ r_data_get_struct(self, "@data", &music_data_type, R2D_Music, ms);
838
+ return INT2NUM(R2D_GetMusicLength(ms));
839
+ }
840
+
841
+
729
842
  /*
730
843
  * Free music structure attached to Ruby 2D `Music` class
731
844
  */
732
845
  #if MRUBY
733
846
  static void free_music(mrb_state *mrb, void *p_) {
734
- S2D_Music *mus = (S2D_Music *)p_;
847
+ R2D_Music *mus = (R2D_Music *)p_;
735
848
  #else
736
- static void free_music(S2D_Music *mus) {
849
+ static void free_music(R2D_Music *mus) {
737
850
  #endif
738
- S2D_FreeMusic(mus);
851
+ R2D_FreeMusic(mus);
739
852
  }
740
853
 
741
854
 
742
855
  /*
743
- * Simple 2D `on_key` input callback function
856
+ * Ruby 2D native `on_key` input callback function
744
857
  */
745
- static void on_key(S2D_Event e) {
858
+ static void on_key(R2D_Event e) {
746
859
 
747
860
  R_VAL type;
748
861
 
749
862
  switch (e.type) {
750
- case S2D_KEY_DOWN:
863
+ case R2D_KEY_DOWN:
751
864
  type = r_char_to_sym("down");
752
865
  break;
753
- case S2D_KEY_HELD:
866
+ case R2D_KEY_HELD:
754
867
  type = r_char_to_sym("held");
755
868
  break;
756
- case S2D_KEY_UP:
869
+ case R2D_KEY_UP:
757
870
  type = r_char_to_sym("up");
758
871
  break;
759
872
  }
@@ -763,48 +876,48 @@ static void on_key(S2D_Event e) {
763
876
 
764
877
 
765
878
  /*
766
- * Simple 2D `on_mouse` input callback function
879
+ * Ruby 2D native `on_mouse` input callback function
767
880
  */
768
- void on_mouse(S2D_Event e) {
881
+ void on_mouse(R2D_Event e) {
769
882
 
770
883
  R_VAL type = R_NIL; R_VAL button = R_NIL; R_VAL direction = R_NIL;
771
884
 
772
885
  switch (e.type) {
773
- case S2D_MOUSE_DOWN:
886
+ case R2D_MOUSE_DOWN:
774
887
  // type, button, x, y
775
888
  type = r_char_to_sym("down");
776
889
  break;
777
- case S2D_MOUSE_UP:
890
+ case R2D_MOUSE_UP:
778
891
  // type, button, x, y
779
892
  type = r_char_to_sym("up");
780
893
  break;
781
- case S2D_MOUSE_SCROLL:
894
+ case R2D_MOUSE_SCROLL:
782
895
  // type, direction, delta_x, delta_y
783
896
  type = r_char_to_sym("scroll");
784
- direction = e.direction == S2D_MOUSE_SCROLL_NORMAL ?
897
+ direction = e.direction == R2D_MOUSE_SCROLL_NORMAL ?
785
898
  r_char_to_sym("normal") : r_char_to_sym("inverted");
786
899
  break;
787
- case S2D_MOUSE_MOVE:
900
+ case R2D_MOUSE_MOVE:
788
901
  // type, x, y, delta_x, delta_y
789
902
  type = r_char_to_sym("move");
790
903
  break;
791
904
  }
792
905
 
793
- if (e.type == S2D_MOUSE_DOWN || e.type == S2D_MOUSE_UP) {
906
+ if (e.type == R2D_MOUSE_DOWN || e.type == R2D_MOUSE_UP) {
794
907
  switch (e.button) {
795
- case S2D_MOUSE_LEFT:
908
+ case R2D_MOUSE_LEFT:
796
909
  button = r_char_to_sym("left");
797
910
  break;
798
- case S2D_MOUSE_MIDDLE:
911
+ case R2D_MOUSE_MIDDLE:
799
912
  button = r_char_to_sym("middle");
800
913
  break;
801
- case S2D_MOUSE_RIGHT:
914
+ case R2D_MOUSE_RIGHT:
802
915
  button = r_char_to_sym("right");
803
916
  break;
804
- case S2D_MOUSE_X1:
917
+ case R2D_MOUSE_X1:
805
918
  button = r_char_to_sym("x1");
806
919
  break;
807
- case S2D_MOUSE_X2:
920
+ case R2D_MOUSE_X2:
808
921
  button = r_char_to_sym("x2");
809
922
  break;
810
923
  }
@@ -818,88 +931,88 @@ void on_mouse(S2D_Event e) {
818
931
 
819
932
 
820
933
  /*
821
- * Simple 2D `on_controller` input callback function
934
+ * Ruby 2D native `on_controller` input callback function
822
935
  */
823
- static void on_controller(S2D_Event e) {
936
+ static void on_controller(R2D_Event e) {
824
937
 
825
938
  R_VAL type = R_NIL; R_VAL axis = R_NIL; R_VAL button = R_NIL;
826
939
 
827
940
  switch (e.type) {
828
- case S2D_AXIS:
941
+ case R2D_AXIS:
829
942
  type = r_char_to_sym("axis");
830
943
  switch (e.axis) {
831
- case S2D_AXIS_LEFTX:
944
+ case R2D_AXIS_LEFTX:
832
945
  axis = r_char_to_sym("left_x");
833
946
  break;
834
- case S2D_AXIS_LEFTY:
947
+ case R2D_AXIS_LEFTY:
835
948
  axis = r_char_to_sym("left_y");
836
949
  break;
837
- case S2D_AXIS_RIGHTX:
950
+ case R2D_AXIS_RIGHTX:
838
951
  axis = r_char_to_sym("right_x");
839
952
  break;
840
- case S2D_AXIS_RIGHTY:
953
+ case R2D_AXIS_RIGHTY:
841
954
  axis = r_char_to_sym("right_y");
842
955
  break;
843
- case S2D_AXIS_TRIGGERLEFT:
956
+ case R2D_AXIS_TRIGGERLEFT:
844
957
  axis = r_char_to_sym("trigger_left");
845
958
  break;
846
- case S2D_AXIS_TRIGGERRIGHT:
959
+ case R2D_AXIS_TRIGGERRIGHT:
847
960
  axis = r_char_to_sym("trigger_right");
848
961
  break;
849
- case S2D_AXIS_INVALID:
962
+ case R2D_AXIS_INVALID:
850
963
  axis = r_char_to_sym("invalid");
851
964
  break;
852
965
  }
853
966
  break;
854
- case S2D_BUTTON_DOWN: case S2D_BUTTON_UP:
855
- type = e.type == S2D_BUTTON_DOWN ? r_char_to_sym("button_down") : r_char_to_sym("button_up");
967
+ case R2D_BUTTON_DOWN: case R2D_BUTTON_UP:
968
+ type = e.type == R2D_BUTTON_DOWN ? r_char_to_sym("button_down") : r_char_to_sym("button_up");
856
969
  switch (e.button) {
857
- case S2D_BUTTON_A:
970
+ case R2D_BUTTON_A:
858
971
  button = r_char_to_sym("a");
859
972
  break;
860
- case S2D_BUTTON_B:
973
+ case R2D_BUTTON_B:
861
974
  button = r_char_to_sym("b");
862
975
  break;
863
- case S2D_BUTTON_X:
976
+ case R2D_BUTTON_X:
864
977
  button = r_char_to_sym("x");
865
978
  break;
866
- case S2D_BUTTON_Y:
979
+ case R2D_BUTTON_Y:
867
980
  button = r_char_to_sym("y");
868
981
  break;
869
- case S2D_BUTTON_BACK:
982
+ case R2D_BUTTON_BACK:
870
983
  button = r_char_to_sym("back");
871
984
  break;
872
- case S2D_BUTTON_GUIDE:
985
+ case R2D_BUTTON_GUIDE:
873
986
  button = r_char_to_sym("guide");
874
987
  break;
875
- case S2D_BUTTON_START:
988
+ case R2D_BUTTON_START:
876
989
  button = r_char_to_sym("start");
877
990
  break;
878
- case S2D_BUTTON_LEFTSTICK:
991
+ case R2D_BUTTON_LEFTSTICK:
879
992
  button = r_char_to_sym("left_stick");
880
993
  break;
881
- case S2D_BUTTON_RIGHTSTICK:
994
+ case R2D_BUTTON_RIGHTSTICK:
882
995
  button = r_char_to_sym("right_stick");
883
996
  break;
884
- case S2D_BUTTON_LEFTSHOULDER:
997
+ case R2D_BUTTON_LEFTSHOULDER:
885
998
  button = r_char_to_sym("left_shoulder");
886
999
  break;
887
- case S2D_BUTTON_RIGHTSHOULDER:
1000
+ case R2D_BUTTON_RIGHTSHOULDER:
888
1001
  button = r_char_to_sym("right_shoulder");
889
1002
  break;
890
- case S2D_BUTTON_DPAD_UP:
1003
+ case R2D_BUTTON_DPAD_UP:
891
1004
  button = r_char_to_sym("up");
892
1005
  break;
893
- case S2D_BUTTON_DPAD_DOWN:
1006
+ case R2D_BUTTON_DPAD_DOWN:
894
1007
  button = r_char_to_sym("down");
895
1008
  break;
896
- case S2D_BUTTON_DPAD_LEFT:
1009
+ case R2D_BUTTON_DPAD_LEFT:
897
1010
  button = r_char_to_sym("left");
898
1011
  break;
899
- case S2D_BUTTON_DPAD_RIGHT:
1012
+ case R2D_BUTTON_DPAD_RIGHT:
900
1013
  button = r_char_to_sym("right");
901
1014
  break;
902
- case S2D_BUTTON_INVALID:
1015
+ case R2D_BUTTON_INVALID:
903
1016
  button = r_char_to_sym("invalid");
904
1017
  break;
905
1018
  }
@@ -914,7 +1027,7 @@ static void on_controller(S2D_Event e) {
914
1027
 
915
1028
 
916
1029
  /*
917
- * Simple 2D `update` callback function
1030
+ * Ruby 2D native `update` callback function
918
1031
  */
919
1032
  static void update() {
920
1033
 
@@ -934,7 +1047,7 @@ static void update() {
934
1047
 
935
1048
 
936
1049
  /*
937
- * Simple 2D `render` callback function
1050
+ * Ruby 2D native `render` callback function
938
1051
  */
939
1052
  static void render() {
940
1053
 
@@ -952,8 +1065,11 @@ static void render() {
952
1065
  // Switch on each object type
953
1066
  for (int i = 0; i < num_objects; ++i) {
954
1067
  R_VAL el = r_ary_entry(objects, i);
955
- r_funcall(el, "ext_render", 0);
1068
+ r_funcall(el, "render", 0); // call the object's `render` function
956
1069
  }
1070
+
1071
+ // Call render proc, `window.render`
1072
+ r_funcall(ruby2d_window, "render_callback", 0);
957
1073
  }
958
1074
 
959
1075
 
@@ -967,8 +1083,8 @@ static R_VAL ruby2d_ext_diagnostics(mrb_state* mrb, R_VAL self) {
967
1083
  #else
968
1084
  static R_VAL ruby2d_ext_diagnostics(R_VAL self, R_VAL enable) {
969
1085
  #endif
970
- // Set Simple 2D diagnostics
971
- S2D_Diagnostics(r_test(enable));
1086
+ // Set Ruby 2D native diagnostics
1087
+ R2D_Diagnostics(r_test(enable));
972
1088
  return R_TRUE;
973
1089
  }
974
1090
 
@@ -982,7 +1098,7 @@ static R_VAL ruby2d_window_ext_get_display_dimensions(mrb_state* mrb, R_VAL self
982
1098
  static R_VAL ruby2d_window_ext_get_display_dimensions(R_VAL self) {
983
1099
  #endif
984
1100
  int w; int h;
985
- S2D_GetDisplayDimensions(&w, &h);
1101
+ R2D_GetDisplayDimensions(&w, &h);
986
1102
  r_iv_set(self, "@display_width" , INT2NUM(w));
987
1103
  r_iv_set(self, "@display_height", INT2NUM(h));
988
1104
  return R_NIL;
@@ -999,8 +1115,8 @@ static R_VAL ruby2d_window_ext_add_controller_mappings(mrb_state* mrb, R_VAL sel
999
1115
  #else
1000
1116
  static R_VAL ruby2d_window_ext_add_controller_mappings(R_VAL self, R_VAL path) {
1001
1117
  #endif
1002
- S2D_Log(S2D_INFO, "Adding controller mappings from `%s`", RSTRING_PTR(path));
1003
- S2D_AddControllerMappingsFromFile(RSTRING_PTR(path));
1118
+ R2D_Log(R2D_INFO, "Adding controller mappings from `%s`", RSTRING_PTR(path));
1119
+ R2D_AddControllerMappingsFromFile(RSTRING_PTR(path));
1004
1120
  return R_NIL;
1005
1121
  }
1006
1122
 
@@ -1032,16 +1148,16 @@ static R_VAL ruby2d_window_ext_show(R_VAL self) {
1032
1148
  // Get window flags
1033
1149
  int flags = 0;
1034
1150
  if (r_test(r_iv_get(self, "@resizable"))) {
1035
- flags = flags | S2D_RESIZABLE;
1151
+ flags = flags | R2D_RESIZABLE;
1036
1152
  }
1037
1153
  if (r_test(r_iv_get(self, "@borderless"))) {
1038
- flags = flags | S2D_BORDERLESS;
1154
+ flags = flags | R2D_BORDERLESS;
1039
1155
  }
1040
1156
  if (r_test(r_iv_get(self, "@fullscreen"))) {
1041
- flags = flags | S2D_FULLSCREEN;
1157
+ flags = flags | R2D_FULLSCREEN;
1042
1158
  }
1043
1159
  if (r_test(r_iv_get(self, "@highdpi"))) {
1044
- flags = flags | S2D_HIGHDPI;
1160
+ flags = flags | R2D_HIGHDPI;
1045
1161
  }
1046
1162
 
1047
1163
  // Check viewport size and set
@@ -1054,7 +1170,7 @@ static R_VAL ruby2d_window_ext_show(R_VAL self) {
1054
1170
 
1055
1171
  // Create and show window
1056
1172
 
1057
- window = S2D_CreateWindow(
1173
+ window = R2D_CreateWindow(
1058
1174
  title, width, height, update, render, flags
1059
1175
  );
1060
1176
 
@@ -1066,7 +1182,7 @@ static R_VAL ruby2d_window_ext_show(R_VAL self) {
1066
1182
  window->on_mouse = on_mouse;
1067
1183
  window->on_controller = on_controller;
1068
1184
 
1069
- S2D_Show(window);
1185
+ R2D_Show(window);
1070
1186
 
1071
1187
  atexit(free_window);
1072
1188
  return R_NIL;
@@ -1084,7 +1200,7 @@ static R_VAL ruby2d_ext_screenshot(mrb_state* mrb, R_VAL self) {
1084
1200
  static R_VAL ruby2d_ext_screenshot(R_VAL self, R_VAL path) {
1085
1201
  #endif
1086
1202
  if (window) {
1087
- S2D_Screenshot(window, RSTRING_PTR(path));
1203
+ R2D_Screenshot(window, RSTRING_PTR(path));
1088
1204
  return path;
1089
1205
  } else {
1090
1206
  return R_FALSE;
@@ -1096,7 +1212,7 @@ static R_VAL ruby2d_ext_screenshot(R_VAL self, R_VAL path) {
1096
1212
  * Ruby2D::Window#ext_close
1097
1213
  */
1098
1214
  static R_VAL ruby2d_window_ext_close() {
1099
- S2D_Close(window);
1215
+ R2D_Close(window);
1100
1216
  return R_NIL;
1101
1217
  }
1102
1218
 
@@ -1126,29 +1242,35 @@ void Init_ruby2d() {
1126
1242
  // Ruby2D#self.ext_base_path
1127
1243
  r_define_class_method(ruby2d_module, "ext_base_path", ruby2d_ext_base_path, r_args_none);
1128
1244
 
1245
+ // Ruby2D::Pixel
1246
+ R_CLASS ruby2d_pixel_class = r_define_class(ruby2d_module, "Pixel");
1247
+
1248
+ // Ruby2D::Pixel#self.ext_draw
1249
+ r_define_class_method(ruby2d_pixel_class, "ext_draw", ruby2d_pixel_ext_draw, r_args_req(1));
1250
+
1129
1251
  // Ruby2D::Triangle
1130
1252
  R_CLASS ruby2d_triangle_class = r_define_class(ruby2d_module, "Triangle");
1131
1253
 
1132
- // Ruby2D::Triangle#ext_render
1133
- r_define_method(ruby2d_triangle_class, "ext_render", ruby2d_triangle_ext_render, r_args_none);
1254
+ // Ruby2D::Triangle#self.ext_draw
1255
+ r_define_class_method(ruby2d_triangle_class, "ext_draw", ruby2d_triangle_ext_draw, r_args_req(1));
1134
1256
 
1135
1257
  // Ruby2D::Quad
1136
1258
  R_CLASS ruby2d_quad_class = r_define_class(ruby2d_module, "Quad");
1137
1259
 
1138
- // Ruby2D::Quad#ext_render
1139
- r_define_method(ruby2d_quad_class, "ext_render", ruby2d_quad_ext_render, r_args_none);
1260
+ // Ruby2D::Quad#self.ext_draw
1261
+ r_define_class_method(ruby2d_quad_class, "ext_draw", ruby2d_quad_ext_draw, r_args_req(1));
1140
1262
 
1141
1263
  // Ruby2D::Line
1142
1264
  R_CLASS ruby2d_line_class = r_define_class(ruby2d_module, "Line");
1143
1265
 
1144
- // Ruby2D::Line#ext_render
1145
- r_define_method(ruby2d_line_class, "ext_render", ruby2d_line_ext_render, r_args_none);
1266
+ // Ruby2D::Line#self.ext_draw
1267
+ r_define_class_method(ruby2d_line_class, "ext_draw", ruby2d_line_ext_draw, r_args_req(1));
1146
1268
 
1147
1269
  // Ruby2D::Circle
1148
1270
  R_CLASS ruby2d_circle_class = r_define_class(ruby2d_module, "Circle");
1149
1271
 
1150
- // Ruby2D::Circle#ext_render
1151
- r_define_method(ruby2d_circle_class, "ext_render", ruby2d_circle_ext_render, r_args_none);
1272
+ // Ruby2D::Circle#self.ext_draw
1273
+ r_define_class_method(ruby2d_circle_class, "ext_draw", ruby2d_circle_ext_draw, r_args_req(1));
1152
1274
 
1153
1275
  // Ruby2D::Image
1154
1276
  R_CLASS ruby2d_image_class = r_define_class(ruby2d_module, "Image");
@@ -1156,8 +1278,8 @@ void Init_ruby2d() {
1156
1278
  // Ruby2D::Image#ext_init
1157
1279
  r_define_method(ruby2d_image_class, "ext_init", ruby2d_image_ext_init, r_args_req(1));
1158
1280
 
1159
- // Ruby2D::Image#ext_render
1160
- r_define_method(ruby2d_image_class, "ext_render", ruby2d_image_ext_render, r_args_none);
1281
+ // Ruby2D::Image#self.ext_draw
1282
+ r_define_class_method(ruby2d_image_class, "ext_draw", ruby2d_image_ext_draw, r_args_req(1));
1161
1283
 
1162
1284
  // Ruby2D::Sprite
1163
1285
  R_CLASS ruby2d_sprite_class = r_define_class(ruby2d_module, "Sprite");
@@ -1165,8 +1287,17 @@ void Init_ruby2d() {
1165
1287
  // Ruby2D::Sprite#ext_init
1166
1288
  r_define_method(ruby2d_sprite_class, "ext_init", ruby2d_sprite_ext_init, r_args_req(1));
1167
1289
 
1168
- // Ruby2D::Sprite#ext_render
1169
- r_define_method(ruby2d_sprite_class, "ext_render", ruby2d_sprite_ext_render, r_args_none);
1290
+ // Ruby2D::Sprite#self.ext_draw
1291
+ r_define_class_method(ruby2d_sprite_class, "ext_draw", ruby2d_sprite_ext_draw, r_args_req(1));
1292
+
1293
+ // Ruby2D::Tileset
1294
+ R_CLASS ruby2d_tileset_class = r_define_class(ruby2d_module, "Tileset");
1295
+
1296
+ // Ruby2D::Tileset#ext_init
1297
+ r_define_method(ruby2d_tileset_class, "ext_init", ruby2d_tileset_ext_init, r_args_req(1));
1298
+
1299
+ // Ruby2D::Tileset#self.ext_draw
1300
+ r_define_class_method(ruby2d_tileset_class, "ext_draw", ruby2d_tileset_ext_draw, r_args_req(1));
1170
1301
 
1171
1302
  // Ruby2D::Text
1172
1303
  R_CLASS ruby2d_text_class = r_define_class(ruby2d_module, "Text");
@@ -1177,8 +1308,8 @@ void Init_ruby2d() {
1177
1308
  // Ruby2D::Text#ext_set
1178
1309
  r_define_method(ruby2d_text_class, "ext_set", ruby2d_text_ext_set, r_args_req(1));
1179
1310
 
1180
- // Ruby2D::Text#ext_render
1181
- r_define_method(ruby2d_text_class, "ext_render", ruby2d_text_ext_render, r_args_none);
1311
+ // Ruby2D::Text#self.ext_draw
1312
+ r_define_class_method(ruby2d_text_class, "ext_draw", ruby2d_text_ext_draw, r_args_req(1));
1182
1313
 
1183
1314
  // Ruby2D::Sound
1184
1315
  R_CLASS ruby2d_sound_class = r_define_class(ruby2d_module, "Sound");
@@ -1189,6 +1320,9 @@ void Init_ruby2d() {
1189
1320
  // Ruby2D::Sound#ext_play
1190
1321
  r_define_method(ruby2d_sound_class, "ext_play", ruby2d_sound_ext_play, r_args_none);
1191
1322
 
1323
+ // Ruby2D::Sound#ext_length
1324
+ r_define_method(ruby2d_sound_class, "ext_length", ruby2d_sound_ext_length, r_args_none);
1325
+
1192
1326
  // Ruby2D::Music
1193
1327
  R_CLASS ruby2d_music_class = r_define_class(ruby2d_module, "Music");
1194
1328
 
@@ -1216,6 +1350,9 @@ void Init_ruby2d() {
1216
1350
  // Ruby2D::Music#ext_fadeout
1217
1351
  r_define_method(ruby2d_music_class, "ext_fadeout", ruby2d_music_ext_fadeout, r_args_req(1));
1218
1352
 
1353
+ // Ruby2D::Music#ext_length
1354
+ r_define_method(ruby2d_music_class, "ext_length", ruby2d_music_ext_length, r_args_none);
1355
+
1219
1356
  // Ruby2D::Window
1220
1357
  R_CLASS ruby2d_window_class = r_define_class(ruby2d_module, "Window");
1221
1358