From 864c710a510be8e318023e34565209f9a24a3ac7 Mon Sep 17 00:00:00 2001 From: realtradam Date: Tue, 8 Feb 2022 03:12:31 -0500 Subject: move stuff to types.h --- src/core.c | 18 ++++++++---------- src/raylib.c | 49 ++----------------------------------------------- src/types.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 57 deletions(-) create mode 100644 src/types.c (limited to 'src') diff --git a/src/core.c b/src/core.c index e6b290f..96df1ae 100644 --- a/src/core.c +++ b/src/core.c @@ -1,13 +1,6 @@ -#include "raylib/core.h" - -const struct mrb_data_type Color_type = { - "Color", mrb_free -}; - -const struct mrb_data_type Rectangle_type = { - "Rectangle", mrb_free -}; - +#include "mruby-raylib/core.h" +#include "mruby-raylib/types.h" +#include /* * @overload init_window(width: 800, height: 600, title: "Hello World from Raylib!") * @param width [Integer] @@ -138,6 +131,11 @@ mrb_begin_scissor_mode(mrb_state* mrb, mrb_value self) { kw_values[1] = mrb_fixnum_value(y); kw_values[2] = mrb_fixnum_value(width); kw_values[3] = mrb_fixnum_value(height); + } else { + kw_values[0] = mrb_ensure_int_type(mrb, kw_values[0]); + kw_values[1] = mrb_ensure_int_type(mrb, kw_values[1]); + kw_values[2] = mrb_ensure_int_type(mrb, kw_values[2]); + kw_values[3] = mrb_ensure_int_type(mrb, kw_values[3]); } BeginScissorMode(mrb_fixnum(kw_values[0]), mrb_fixnum(kw_values[1]), mrb_fixnum(kw_values[2]), mrb_fixnum(kw_values[3])); return mrb_nil_value(); diff --git a/src/raylib.c b/src/raylib.c index dd69f96..56bdf96 100644 --- a/src/raylib.c +++ b/src/raylib.c @@ -1,12 +1,11 @@ +#include "mruby-raylib/types.h" +#include "mruby-raylib/core.h" #include -#include #include -#include #include #include #include #include -#include "raylib/core.h" #if defined(PLATFORM_WEB) #include #endif @@ -14,54 +13,10 @@ #if defined(PLATFORM_WEB) void execute_emscripten_block(void*); #endif -void helper_texture_free(mrb_state*, void*); -void helper_sound_free(mrb_state*, void*); -void helper_music_free(mrb_state*, void*); bool check_collision_circle_rec(mrb_state* mrb, mrb_value circle_obj, mrb_value rec_obj); -static const struct mrb_data_type Texture_type = { - "Texture", helper_texture_free -}; - -void -helper_texture_free(mrb_state* mrb, void*ptr) { - Texture *texture = (Texture*)ptr; - UnloadTexture(*texture); - mrb_free(mrb, ptr); -} - -static const struct mrb_data_type Sound_type = { - "Sound", helper_sound_free -}; - -void -helper_sound_free(mrb_state* mrb, void*ptr) { - Sound *sound = (Sound*)ptr; - UnloadSound(*sound); - mrb_free(mrb, ptr); -} - -static const struct mrb_data_type Vector2_type = { - "Vector2", mrb_free -}; - - -static const struct mrb_data_type NPatchInfo_type = { - "NPatchInfo", mrb_free -}; - -static const struct mrb_data_type Music_type = { - "Music", helper_music_free -}; - -void -helper_music_free(mrb_state* mrb, void*ptr) { - Music *music = (Music*)ptr; - UnloadMusicStream(*music); - mrb_free(mrb, ptr); -} static mrb_value diff --git a/src/types.c b/src/types.c new file mode 100644 index 0000000..c1b3e34 --- /dev/null +++ b/src/types.c @@ -0,0 +1,52 @@ +#include "mruby-raylib/types.h" +#include + +const struct mrb_data_type Color_type = { + "Color", mrb_free +}; + +const struct mrb_data_type Rectangle_type = { + "Rectangle", mrb_free +}; + +const struct mrb_data_type Texture_type = { + "Texture", helper_texture_free +}; + +void +helper_texture_free(mrb_state* mrb, void*ptr) { + Texture *texture = (Texture*)ptr; + UnloadTexture(*texture); + mrb_free(mrb, ptr); +} + +const struct mrb_data_type Sound_type = { + "Sound", helper_sound_free +}; + +void +helper_sound_free(mrb_state* mrb, void*ptr) { + Sound *sound = (Sound*)ptr; + UnloadSound(*sound); + mrb_free(mrb, ptr); +} + +const struct mrb_data_type Music_type = { + "Music", helper_music_free +}; + +void +helper_music_free(mrb_state* mrb, void*ptr) { + Music *music = (Music*)ptr; + UnloadMusicStream(*music); + mrb_free(mrb, ptr); +} + +const struct mrb_data_type Vector2_type = { + "Vector2", mrb_free +}; + +const struct mrb_data_type NPatchInfo_type = { + "NPatchInfo", mrb_free +}; + -- cgit v1.2.3