"Headless" server-side mode?

Is there a way of compiling openfl in a “headless” mode for running as a dedicated server?

So the ability to compile and run an openfl native app minus graphics, sounds and input.

A lot of my general code is still dependent on some openfl niceities like openfl.Assets, openfl.utils.* and openfl.geom.* etc but I have branching code depending on whether it’s running as a dedicated server, or with a visual frontend.

Ideally I’d like that branching to be compile-time with something like…

#unless headless
    render_scene();
#end

(and of course for execution to be possible on a box without a gui)

So in the case of a headless build the missing apis would never be linked against. (I would presume they would either be missing, throw exceptions, or be non-functional in a headless build?)

If the answer is a definite no, then I suppose I could look at simply forking and cutting those bits out of openfl (and lime?), or perhaps separating the bits I need, but that sounds possibly a little bit awkward (and cruel :/)

1 Like

That’s what Lime is for, right?

Lime provides its own asset handling, geometry classes, utility classes, etc. The difference is that graphics are optional.

If we run without a window, then I think that OpenGL calls would fail, so it would not be possible to strictly run OpenFL as-is in a headless mode.

On the other hand, I do use OpenFL and Lime functions from things like the command-line tools, there are ways to include it directly. However, if you want, the cleanest route may be to use Lime, or perhaps to use OpenFL “next” but to override the Application class so that you can disable the default create() method which generates a window.

I have not extensively tested Lime without a window, but the idea is that this would be supported. Things like lime.Assets, lime.math.* and other classes should not need the window at all to work. Interested to hear how we can help :slight_smile:

Also, if you wanted to toy with something that’s a little automatic, you might look adding #if !headless to the Lime Application class where it creates a new Window, it’s possible everything would work, as-is, you just wouldn’t get render events or update events, but maybe that’s alright.

The other method is illustrated by the Lime tools, which include Lime (and could include OpenFL as well) but are strictly CLI, and not a windowed application