summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTom Black <[email protected]>2019-01-06 01:54:30 -0800
committerTom Black <[email protected]>2019-01-06 01:54:30 -0800
commit19fe64de6fec783e32a2257ff04862b2d0a41572 (patch)
tree3a106a63013dc5f248baee4e85fa61cbc25ae74c
parentd39551a9f72acc928f7886956d8a3e5adedda181 (diff)
downloadruby2d-19fe64de6fec783e32a2257ff04862b2d0a41572.tar.gz
ruby2d-19fe64de6fec783e32a2257ff04862b2d0a41572.zip
Set diagnostics immediately
`set diagnostics: true` now calls the new `Window#ext_diagnostics` native extension function, which immediately calls `S2D_Diagnostics()`
-rw-r--r--ext/ruby2d/ruby2d.c24
-rw-r--r--lib/ruby2d/window.rb5
2 files changed, 23 insertions, 6 deletions
diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c
index 6df2a20..7970c56 100644
--- a/ext/ruby2d/ruby2d.c
+++ b/ext/ruby2d/ruby2d.c
@@ -964,6 +964,22 @@ static void render() {
/*
+ * Ruby2D::Window#ext_diagnostics
+ */
+#if MRUBY
+static R_VAL ruby2d_ext_diagnostics(mrb_state* mrb, R_VAL self) {
+ mrb_value enable;
+ mrb_get_args(mrb, "o", &enable);
+#else
+static R_VAL ruby2d_ext_diagnostics(R_VAL self, R_VAL enable) {
+#endif
+ // Set Simple 2D diagnostics
+ S2D_Diagnostics(r_test(enable));
+ return R_TRUE;
+}
+
+
+/*
* Ruby2D::Window#ext_get_display_dimensions
*/
#if MRUBY
@@ -1005,11 +1021,6 @@ static R_VAL ruby2d_window_ext_show(R_VAL self) {
#endif
ruby2d_window = self;
- // Set Simple 2D diagnostics
- if (r_test(r_iv_get(self, "@diagnostics"))) {
- S2D_Diagnostics(true);
- }
-
// Add controller mappings from file
r_funcall(self, "add_controller_mappings", 0);
@@ -1215,6 +1226,9 @@ void Init_ruby2d() {
// Ruby2D::Window
R_CLASS ruby2d_window_class = r_define_class(ruby2d_module, "Window");
+ // Ruby2D::Window#ext_diagnostics
+ r_define_method(ruby2d_window_class, "ext_diagnostics", ruby2d_ext_diagnostics, r_args_req(1));
+
// Ruby2D::Window#ext_get_display_dimensions
r_define_method(ruby2d_window_class, "ext_get_display_dimensions", ruby2d_window_ext_get_display_dimensions, r_args_none);
diff --git a/lib/ruby2d/window.rb b/lib/ruby2d/window.rb
index 9e8b462..dea4f26 100644
--- a/lib/ruby2d/window.rb
+++ b/lib/ruby2d/window.rb
@@ -208,7 +208,10 @@ module Ruby2D
@borderless = opts[:borderless] || @borderless
@fullscreen = opts[:fullscreen] || @fullscreen
@highdpi = opts[:highdpi] || @highdpi
- @diagnostics = opts[:diagnostics] || @diagnostics
+ unless opts[:diagnostics].nil?
+ @diagnostics = opts[:diagnostics]
+ ext_diagnostics(@diagnostics)
+ end
end
# Add an object to the window