jackalcooper

jackalcooper

Any game engine good for being embedded in Elixir?

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).

First Post!

andyleclair

andyleclair

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

Most Liked

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.

Last Post!

jackalcooper

jackalcooper

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)

Where Next?

Popular in Discussions Top

AstonJ
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
mbenatti
Following https://github.com/tbrand/which_is_the_fastest |> https://raw.githubusercontent.com/tbrand/which_is_the_fastest/master/imgs...
New
AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
rower687
Hi all, I’ve been reading a lot about the “let it crash” term and how supervising processes and the whole messaging passing make an elixi...
New
Fl4m3Ph03n1x
Background This question comes mainly from my ignorance. Today is Black Friday, one of my favorite days of the year to buy books. One boo...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

Other popular topics Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement