Skip to content

Commit

Permalink
Update Windows build steps
Browse files Browse the repository at this point in the history
Fix ridk build
Class/Modules under Rl module
  • Loading branch information
Nathan-MV committed Jul 19, 2024
1 parent 5228af3 commit 2da8798
Show file tree
Hide file tree
Showing 38 changed files with 107 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI Extension
name: Ruby Extension

on:
workflow_dispatch:
Expand Down
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,44 @@ cd raylib-cruby-extension
git submodule update --init --recursive
```

- Install Dependencies
- Windows
- Install Ruby 3.3 with Devkit. Then, open PowerShell as Administrator and use the command bellow to set the execution policy, so that you can use ridk.
```
bundle install --with compile
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
```

- Raylib Dependencies (Ubuntu)
- Ubuntu
```
sudo apt install cmake ninja-build ruby-devel libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev libwayland-dev libxkbcommon-dev
```

- Raylib Dependencies (Fedora)
- Fedora
```
sudo dnf install cmake ninja-build ruby-devel alsa-lib-devel mesa-libGL-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel libatomic wayland-devel libxkbcommon-devel wayland-protocols-devel
```

- Raylib Dependencies (Arch Linux)
- Arch Linux
```
sudo pacman -S cmake ninja ruby alsa-lib mesa libx11 libxrandr libxi libxcursor libxinerama
```

- Compile (Ruby Extension)
- Install Ruby Gems
```
bundle install --with compile
```

- Ruby Extension - Windows
```
ridk exec rake
```

- Ruby Extension - Linux
```
rake
```

- Compile (Binary)
Note: Require CMake, Ninja and Ruby 3.3 (Currently the Windows binary does not work, help is appreciated)
- Binary
- On Windows it require CMake, Ninja, Ruby 3.3 with Devkit, Visual Studio Build Tools with Desktop Development for C++ (I only reached that part, help is appreciated)
```
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE:STRING=Release
cmake --build build --config Release --target all
Expand Down
12 changes: 8 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@

require "bundler/gem_tasks"
require "rubocop/rake_task"
require "rake/extensiontask"
require "fileutils"

RuboCop::RakeTask.new

require "rake/extensiontask"

task :clean_raylib do
sh "make clean -C third_party/raylib/src"
FileUtils.rm_rf Dir.glob('third_party/raylib/src/*.o')
end

# Task to compile Raylib
# PLATFORM=PLATFORM_DESKTOP_SDL
# PLATFORM=PLATFORM_DESKTOP_RGFW
# USE_WAYLAND_DISPLAY=TRUE
task :compile_raylib do
sh "make PLATFORM=PLATFORM_DESKTOP -C third_party/raylib/src"
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
sh "mingw32-make PLATFORM=PLATFORM_DESKTOP -C third_party/raylib/src"
else
sh "make PLATFORM=PLATFORM_DESKTOP -C third_party/raylib/src"
end
end

# Compile Raygui task and create static library
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static VALUE rb_color_initialize(int argc, VALUE *argv, VALUE self) {
// RLAPI int GetPixelDataSize(int width, int height, int format); // Get pixel data size in bytes for certain format

extern "C" void initializeColor() {
rb_cColor = rb_define_class("Color", rb_cObject);
rb_cColor = rb_define_class_under(rb_mRl, "Color", rb_cObject);
rb_define_alloc_func(rb_cColor, rb_object_alloc<Color>);

rb_define_method(rb_cColor, "initialize", rb_color_initialize, -1);
Expand Down
16 changes: 1 addition & 15 deletions ext/rubyraylib/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,10 @@ static VALUE rb_begin_drawing(VALUE self) {
// BLEND_CUSTOM_SEPARATE // Blend textures using custom rgb/alpha separate src/dst factors (use rlSetBlendFactorsSeparate())
// } BlendMode;

// Draw text using font and additional parameters
static VALUE rb_draw_text(VALUE self, VALUE text, VALUE posX, VALUE posY, VALUE fontSize, VALUE color) {
const char *txt = StringValueCStr(text);
int x = NUM2INT(posX);
int y = NUM2INT(posY);
int size = NUM2INT(fontSize);
Color *col = get_color(color);

RayDrawText(txt, x, y, size, *col);

return Qnil;
}

// Initializes the Draw module and defines its functions
extern "C" void initializeDraw(void) {
VALUE rb_cDraw = rb_define_module("Draw");
VALUE rb_cDraw = rb_define_module_under(rb_mRl, "Draw");

rb_define_module_function(rb_cDraw, "begin", rb_begin_drawing, 0);
rb_define_module_function(rb_cDraw, "clear", rb_clear_background, 1);
rb_define_module_function(rb_cDraw, "text", rb_draw_text, 5);
}
2 changes: 1 addition & 1 deletion ext/rubyraylib/ease.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RB_EASE(rb_ease_elastic, EaseElastic)

// Initializes the Ease module and defines its functions
extern "C" void initializeEase() {
VALUE rb_cEase = rb_define_module("Ease");
VALUE rb_cEase = rb_define_module_under(rb_mRl, "Ease");

rb_define_module_function(rb_cEase, "linear", rb_ease_linear, 5);
rb_define_module_function(rb_cEase, "sine", rb_ease_sine, 5);
Expand Down
23 changes: 0 additions & 23 deletions ext/rubyraylib/font.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions ext/rubyraylib/font.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion ext/rubyraylib/gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RB_METHOD_INT_ARG_STR(rb_set_gamepad_mappings, SetGamepadMappings)
RB_METHOD_ARG_INT_FLOAT_2(rb_set_gamepad_vibration, SetGamepadVibration)

extern "C" void initializeGamepad() {
VALUE rb_mGamepad = rb_define_module_under(rb_mInput, "Gamepad");
VALUE rb_mGamepad = rb_define_module_under(rb_mRl, "Gamepad");

rb_define_module_function(rb_mGamepad, "available?", rb_gamepad_available, 1);
rb_define_module_function(rb_mGamepad, "name", rb_gamepad_name, 1);
Expand Down
1 change: 0 additions & 1 deletion ext/rubyraylib/gamepad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "ruby_values.hpp"
#include "raylib_values.hpp"
#include "input.hpp"

extern "C" void initializeGamepad();

Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/gestures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RB_METHOD_VEC2(rb_get_gesture_pinch_vector, GetGesturePinchVector)
RB_METHOD_FLOAT(rb_get_gesture_pinch_angle, GetGesturePinchAngle)

extern "C" void initializeGestures() {
VALUE rb_mGestures = rb_define_module_under(rb_mInput, "Gestures");
VALUE rb_mGestures = rb_define_module_under(rb_mRl, "Gestures");

rb_define_module_function(rb_mGestures, "enabled=", rb_set_gestures_enabled, 1);
rb_define_module_function(rb_mGestures, "detected?", rb_gesture_detected, 1);
Expand Down
1 change: 0 additions & 1 deletion ext/rubyraylib/gestures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "ruby_values.hpp"
#include "raylib_values.hpp"
#include "input.hpp"

extern "C" void initializeGestures();

Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static VALUE rb_gui_label_button(VALUE self, VALUE bounds, VALUE text) {

// Initializes the GUI module and defines its functions
extern "C" void initializeGui() {
VALUE rb_cGui = rb_define_module("GUI");
VALUE rb_cGui = rb_define_module_under(rb_mRl, "GUI");

rb_define_module_function(rb_cGui, "label", rb_gui_label, 2);
rb_define_module_function(rb_cGui, "label_button", rb_gui_label_button, 2);
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static VALUE rb_unload_image(VALUE self) {
// } TextureWrap;

extern "C" void initializeImage() {
rb_cImage = rb_define_class("Image", rb_cObject);
rb_cImage = rb_define_class_under(rb_mRl, "Image", rb_cObject);
rb_define_alloc_func(rb_cImage, rb_image_alloc<Image>);

rb_define_method(rb_cImage, "initialize", rb_image_initialize, 1);
Expand Down
7 changes: 0 additions & 7 deletions ext/rubyraylib/input.cpp

This file was deleted.

10 changes: 0 additions & 10 deletions ext/rubyraylib/input.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion ext/rubyraylib/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RB_METHOD_INT(rb_get_char_pressed, GetCharPressed)
RB_METHOD_ARG_INT(rb_set_exit_key, SetExitKey)

extern "C" void initializeKeyboard() {
VALUE rb_mKeyboard = rb_define_module_under(rb_mInput, "Keyboard");
VALUE rb_mKeyboard = rb_define_module_under(rb_mRl, "Keyboard");

rb_define_module_function(rb_mKeyboard, "pressed?", rb_key_pressed, 1);
rb_define_module_function(rb_mKeyboard, "repeat?", rb_key_pressed_repeat, 1);
Expand Down
1 change: 0 additions & 1 deletion ext/rubyraylib/keyboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "ruby_values.hpp"
#include "raylib_values.hpp"
#include "input.hpp"

extern "C" void initializeKeyboard();

Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RB_METHOD_VEC2(rb_get_mouse_wheel_move_v, GetMouseWheelMoveV)
RB_METHOD_ARG_INT(rb_set_mouse_cursor, SetMouseCursor)

extern "C" void initializeMouse() {
VALUE rb_mMouse = rb_define_module_under(rb_mInput, "Mouse");
VALUE rb_mMouse = rb_define_module_under(rb_mRl, "Mouse");

rb_define_module_function(rb_mMouse, "button_pressed?", rb_mouse_button_pressed, 1);
rb_define_module_function(rb_mMouse, "button_down?", rb_mouse_button_down, 1);
Expand Down
1 change: 0 additions & 1 deletion ext/rubyraylib/mouse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "ruby_values.hpp"
#include "raylib_values.hpp"
#include "input.hpp"

extern "C" void initializeMouse();

Expand Down
5 changes: 5 additions & 0 deletions ext/rubyraylib/raylib_values.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "raylib_values.hpp"

VALUE rb_mRl;

extern "C" void initializeRaylib() { rb_mRl = rb_define_module("Rl"); }
4 changes: 4 additions & 0 deletions ext/rubyraylib/raylib_values.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
#include <rlgl.h>
#include "raygui.h"
#include "reasings.h"
#include "ruby_values.hpp"

extern "C" void initializeRaylib();
extern VALUE rb_mRl;

#endif // RAYLIB_VALUES_H
2 changes: 1 addition & 1 deletion ext/rubyraylib/rect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static VALUE rb_draw_rectangle_rec(VALUE self, VALUE color) {
}

extern "C" void initializeRect() {
rb_cRect = rb_define_class("Rect", rb_cObject);
rb_cRect = rb_define_class_under(rb_mRl, "Rect", rb_cObject);
rb_define_alloc_func(rb_cRect, rb_object_alloc<RayRectangle>);

rb_define_method(rb_cRect, "initialize", rb_rect_initialize, 4);
Expand Down
3 changes: 2 additions & 1 deletion ext/rubyraylib/rubyraylib.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#include "rubyraylib.hpp"

RUBY_FUNC_EXPORTED void Init_rubyraylib(void) {
initializeRaylib();
initializeKernel();

// Modules
initializeWindow();
initializeInput();
initializeKeyboard();
initializeMouse();
initializeGamepad();
initializeTouch();
initializeGestures();
initializeDraw();
initializeShapes();
initializeText();

// Classes
initializeColor();
Expand Down
1 change: 1 addition & 0 deletions ext/rubyraylib/rubyraylib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "gestures.hpp"
#include "texture_atlas.hpp"
#include "shapes.hpp"
#include "text.hpp"

extern "C" {
void Init_rubyraylib(void);
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/shapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static VALUE rb_draw_rectangle_v(VALUE self, VALUE position, VALUE size, VALUE c
// RLAPI RayRectangle GetCollisionRec(RayRectangle rec1, RayRectangle rec2); // Get collision rectangle for two rectangles collision

extern "C" void initializeShapes(void) {
VALUE rb_mShapes = rb_define_module("Shapes");
VALUE rb_mShapes = rb_define_module_under(rb_mRl, "Shapes");

rb_define_module_function(rb_mShapes, "rect", rb_draw_rectangle, 5);
rb_define_module_function(rb_mShapes, "rect_v", rb_draw_rectangle_v, 3);
Expand Down
45 changes: 44 additions & 1 deletion ext/rubyraylib/text.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
#include "text.hpp"

//------------------------------------------------------------------------------------
// Font Loading and Text Drawing Functions (Module: text)
//------------------------------------------------------------------------------------

// Font loading/unloading functions
// RLAPI Font GetFontDefault(void); // Get the default Font
// RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM)
// RLAPI Font LoadFontEx(const char *fileName, int fontSize, int *codepoints, int codepointCount); // Load font from file with extended parameters, use NULL for codepoints and 0 for codepointCount to load the default character set
// RLAPI Font LoadFontFromImage(Image image, Color key, int firstChar); // Load font from Image (XNA style)
// RLAPI Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, int *codepoints, int codepointCount); // Load font from memory buffer, fileType refers to extension: i.e. '.ttf'
// RLAPI bool IsFontReady(Font font); // Check if a font is ready
// RLAPI GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSize, int *codepoints, int codepointCount, int type); // Load font data for further use
// RLAPI Image GenImageFontAtlas(const GlyphInfo *glyphs, RayRectangle **glyphRecs, int glyphCount, int fontSize, int padding, int packMethod); // Generate image font atlas using chars info
// RLAPI void UnloadFontData(GlyphInfo *glyphs, int glyphCount); // Unload font chars info data (RAM)
// RLAPI void UnloadFont(Font font); // Unload font from GPU memory (VRAM)
// RLAPI bool ExportFontAsCode(Font font, const char *fileName); // Export font as code file, returns true on success

// Text drawing functions
// RLAPI void DrawFPS(int posX, int posY); // Draw current FPS
// RLAPI void RayDrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font)
static VALUE rb_draw_text(VALUE self, VALUE text, VALUE posX, VALUE posY,
VALUE fontSize, VALUE color) {
const char *txt = StringValueCStr(text);
int x = NUM2INT(posX);
int y = NUM2INT(posY);
int size = NUM2INT(fontSize);
Color *col = get_color(color);

RayDrawText(txt, x, y, size, *col);

return self;
}
// RLAPI void RayDrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters
// RLAPI void DrawTextPro(Font font, const char *text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint); // Draw text using Font and pro parameters (rotation)
// RLAPI void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSize, Color tint); // Draw one character (codepoint)
Expand Down Expand Up @@ -46,3 +76,16 @@

// RLAPI int TextToInteger(const char *text); // Get integer value from text (negative values not supported)
// RLAPI float TextToFloat(const char *text); // Get float value from text (negative values not supported)

// Font type, defines generation method
// typedef enum {
// FONT_DEFAULT = 0, // Default font generation, anti-aliased
// FONT_BITMAP, // Bitmap font generation, no anti-aliasing
// FONT_SDF // SDF font generation, requires external shader
// } FontType;

extern "C" void initializeText(void) {
VALUE rb_mText = rb_define_module_under(rb_mRl, "Text");

rb_define_module_function(rb_mText, "draw", rb_draw_text, 5);
}
2 changes: 1 addition & 1 deletion ext/rubyraylib/text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#include "raylib_values.hpp"
#include "ruby_values.hpp"

// extern "C" void initializeText();
extern "C" void initializeText();

#endif // TEXT_H
Loading

0 comments on commit 2da8798

Please sign in to comment.