From 633f774b0c554e6c916ff3d3a73886e7285322a1 Mon Sep 17 00:00:00 2001 From: realtradam Date: Sun, 9 Jan 2022 22:38:34 -0500 Subject: . --- mrblib/example.rb | 1 + src/example.c | 58 ++++++++++++++++++++++++++++++++----------------------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/mrblib/example.rb b/mrblib/example.rb index 8460b32..60f14e6 100644 --- a/mrblib/example.rb +++ b/mrblib/example.rb @@ -3,3 +3,4 @@ class Test puts "yes it does" end end +CRubyExtension.c_method diff --git a/src/example.c b/src/example.c index ff6a32f..140d032 100644 --- a/src/example.c +++ b/src/example.c @@ -2,55 +2,65 @@ #include #include #include +#if defined(PLATFORM_WEB) +#include +#endif const int screenWidth = 800; const int screenHeight = 450; +void UpdateDrawFrame(void); // Update and Draw one frame static mrb_value mrb_c_method(mrb_state *mrb, mrb_value self) { - //mrb_ensure_string_type(mrb, self); - //printf("%s: A C Extension\n", mrb_str_to_cstr(mrb, self)); // Initialization //-------------------------------------------------------------------------------------- - InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); - SetTargetFPS(60); // Set our game to run at 60 frames-per-second +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- - Texture2D texture = LoadTexture("assets/HYPERS.png"); - struct Vector2 position = { 0, 0 }; - // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { - // Update - //---------------------------------------------------------------------------------- - // TODO: Update your variables here - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawTextureEx(texture, position, 0.0f, 4.0f, WHITE); - - DrawText("HYPERS!", 500, 50, 20, RED); - - EndDrawing(); - //---------------------------------------------------------------------------------- + UpdateDrawFrame(); } +#endif // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- + return self; } + +//---------------------------------------------------------------------------------- +// Module Functions Definition +//---------------------------------------------------------------------------------- +void UpdateDrawFrame(void) +{ + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- +} + void mrb_my_silly_extension_gem_init(mrb_state* mrb) { struct RClass *class_cextension = mrb_define_module(mrb, "CRubyExtension"); -- cgit v1.2.3