vala language bindings

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply
aanderse
Posts: 155
Joined: Sun Aug 10, 2008 2:02 pm
Location: Canada

vala language bindings

Post by aanderse »

vala is a fairly new (high level) language (modeled after c# syntax) which was built primarily for glib/gobject (and gtk2) development (mostly) on the gnome platform. It is a neat idea where the code is not compiled to assembly or anything... it's compiled into pure c code (usually leveraging the glib/gobject library) and then compiled into a binary from there. The neat part is that there is no extra libraries (aside from glib/gobject), run times, or virtual machines - you can compile your (processed) vala code with just a c compiler!

see http://live.gnome.org/Vala for more details.

anyways, a feature of vala that makes it very nice for irrlicht is that vala objects use reference counting (not garbage collection) and can actually leverage an objects existing reference counting system (sort of like boost::intrusive_ptr). Since vala runs off c code (and not c++) i had to make c bindings for irrlicht (like the irrlicht dot net project did) and then from there i created the vala bindings. there vala bindings are not an additional layer, though, as the bindings are used by the compiler to generate functions/code from the c bindings (hence the generated c code doesn't have any extra function overhead other than the c binding overhead).

this is just a fun project to mess around with and see how it works out. i just posted here in the off chance that anyone else would actually be interested (but seeing as the dot net bindings died, i assume not). these bindings are nowhere near complete (very early stages).

obligatory (yet in this case completely useless) screenshot:
http://imagebin.ca/view/Mf3Y4Y.html

and (very poorly commented, possibly somewhat confusing, but working) code:

Code: Select all


int main (string[] args)
{
    Irr.Device device = new Irr.Device (Irr.Video.DriverType.OPENGL);
    if (device == null)
        return 1;

    // haven't looked into wchar_t support yet
    device.set_window_caption ("Irrlicht running through Vala Code!");

    /*
     * weak is a keyword in the vala
     * the function get_mesh in Irr.Scene.SceneManager is declared as: public weak AnimatedMesh get_mesh (string filename);
     *
     * a weak reference is returned which is meant to indicate that grab() has not been called on the object
     * if you wish to grab() the object then you should use the following variable declaration: Irr.Scene.AnimatedMesh mesh = ...
     * if you don't wish to grab() the object then you should use this declaration instead: weak Irr.Scene.AnimatedMesh mesh = ...
     *
     * with vala, in the case of irrlicht bindings weak indicates that grab() will NOT be called
     * if you create a variable that is not weak and set it to a weak variable then the compiler will attempt to call grab() on the variable
     *
     * ... just think boost::shared_ptr
     * (boost::weak_ptr isn't the same though as weak references aren't informed when the object is destroyed!)
     */
    weak Irr.Scene.AnimatedMesh mesh = device.get_scene_manager().get_mesh ("sydney.md2");
    if (mesh == null)
        return 1;

    // still working out some details with constructors for structs
    Irr.Core.Vector3 zero = {0, 0, 0};
    Irr.Core.Vector3 one = {1, 1, 1};

    weak Irr.Scene.SceneNode node = device.get_scene_manager().add_animated_mesh_scene_node (mesh, null, -1, zero, zero, one, false);
    if (node != null) {
        node.set_material_flag (Irr.Video.MaterialFlag.LIGHTING, false);
        node.set_material_texture (0, device.get_video_driver().get_texture ("sydney.bmp"));
    }

    Irr.Core.Vector3 pos = {0, 30, -40};
    Irr.Core.Vector3 look_at = {0, 5, 0};
    device.get_scene_manager().add_camera_scene_node (null, pos, look_at);

    while (device.run () == true) {
        device.get_video_driver().begin_scene (true, true);
        device.get_scene_manager().draw_all ();
        device.get_video_driver().end_scene ();
    }

    /*
     * if you want to destroy the irrlicht device manually you could do that here,
     * otherwise when the device goes out of scope it will automatically call ->drop()
     */
    device = null;

    return 0;
}
Stamper
Posts: 1
Joined: Fri May 10, 2013 11:47 am
Location: Kiev, UA

Re: vala language bindings

Post by Stamper »

Is it alive? Unfortunately, screenshot link is broken now.
aanderse
Posts: 155
Joined: Sun Aug 10, 2008 2:02 pm
Location: Canada

Re: vala language bindings

Post by aanderse »

hey sorry for the bad news but these bindings were never completed and haven't been updated for subsequent versions of irrlicht
Post Reply