jackalcooper

jackalcooper

I am working on a Elixir project compiling Elixir to native code: GitHub - beaver-lodge/charms: NIF, in Elixir, for Elixir · GitHub
To further drive the development of this project. I want to create a game engine binding for Elixir to collect the requirements for the FFI capability of Charms.
Some criteria I can think of:

  • it is in C or Zig, for the simplicity
  • the artifacts of the engine itself should be small. ideally smaller the Erlang runtime (to justify it is being embedded)
  • ideally it is 3D, but if it is super simple 2D is also fine
  • it doesn’t have very special C macro or extended grammar/preprocessing (like Unreal C++)
  • it has good UI framework (so we got a native UI library for Elixir as bonus)

the reason I ask is that I was thinking Godot is going to support embed mode by the end of 2024 but looks like progress has been stalled recently(I might be wrong).

Showing Posts 1 to 4

andyleclair

andyleclair

You could do something simple like raylib. There are some existing projects integrating with it. There are also idiomatic Zig bindings!

infinityfye

infinityfye

Charms looks like a very cool project, I’ll be keeping a closer eye on it.

For a game engine, I think Sokol matches what you are looking for. It’s not exactly a game engine rather than a collection of STB-style (header only) libraries. They are (1) cross platform, and (2) fairly easy to understand and port.
It’s not a complete game engine in the sense that it has a physics engine, or PBR rendering, etc…

Another one that I had explored recently is Gunslinger It has some basic physics utilities as well.

LTheGreats

LTheGreats

The biggest problem with embedding a game engine in the BEAM is that preexisting ones, even embeddable ones, generally have preexisting assumptions about the runtime of your application that don’t mesh too well with BEAM’s. Especially since platforms like macOS (last time I checked) require the main thread to be the only windowing thread. It might make the most sense to have a port that handles windowing and draw calls and convince that with NIFs that do related computations in the BEAM.

jackalcooper

jackalcooper OP

So this doesn’t work

defmodule WinRaylib do
  use Charms

  defbind init_window_wrapper() :: i32()

  defm init_window(env) :: i32() do
    init_window_wrapper()
  end

  def dynamic_libraries() do
    so = Path.join(System.tmp_dir!(), "raylib_test.so")

    {_, 0} =
      System.cmd("cc", [
        "-shared",
        "-fPIC",
        "-o",
        so,
        "test/support/raylib_test.c",
        "-I/opt/homebrew/include",
        "-L/opt/homebrew/lib",
        "-lraylib"
      ])

    [so]
  end
end
#include "raylib.h"

int _mlir_ciface_Elixir$RaylibTest$ScreenWidthTest$init_window_wrapper() {
    int width, height;
    if (GetScreenWidth() > 0 && GetScreenHeight() > 0) {
        width = GetScreenWidth();
        height = GetScreenHeight();
    } else {
        width = 800;
        height = 600;
    }
    const char *title = "Test Window";
    TraceLog(LOG_INFO, "Initializing window: %dx%d, title: %s", width, height, title);
    InitWindow(width, height, title);
    TraceLog(LOG_INFO, "Window initialized - IsWindowReady: %d", IsWindowReady());

    if (IsWindowReady()) {
        TraceLog(LOG_INFO, "Entering window loop");
        // Keep window open until ESC pressed
        while (!WindowShouldClose()) {
            TraceLog(LOG_DEBUG, "Window loop iteration");
            BeginDrawing();
            ClearBackground(RAYWHITE);
            DrawText("Test Window Open", 20, 20, 20, DARKGRAY);
            EndDrawing();
        }
    }

    return IsWindowReady();
}

void close_window(void) {
    CloseWindow();
}
Running ExUnit with seed: 20931, max_cases: 16

.........................................INFO: Initializing window: 800x600, title: Test Window
INFO: Initializing raylib 5.5
INFO: Platform backend: DESKTOP (GLFW)
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
maennchen
:warning: Security advisory: Decimal DoS vulnerability A vulnerability has been published for decimal where very large exponents can cau...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews