Project Orbiter API for MingW

nbcfrosty

Well-known member
Joined
Jun 16, 2023
Messages
255
Reaction score
279
Points
78
Location
US
Hey all. I created a C wrapper for a substantial portion of the Orbiter API. Currently all the oapi calls and the VESSEL calls are covered. Included is an oapi.dll that wraps the Orbiter API, and a header-only oapi_mingw.h library that does the dynamic linking.

All this so we can build with mingw32 like this:
Code:
g++ -shared -o mingw-plugin.dll main.cpp -I"..\..\..\include"

some example code:
Code:
#define STRICT
#define ORBITER_MODULE
#include "../oapi_mingw.h"
bool init = false;
OrbiterAPIWrapper* orbiterAPI = nullptr;
DLLCLBK void opcPreStep(double simt, double simdt, double mjd)
{
    if (!init)
    {
        init = true;
        orbiterAPI = new OrbiterAPIWrapper();
    }
    if (orbiterAPI->ready)
    {
        auto v = orbiterAPI->oapiGetFocusInterface();
        sprintf(orbiterAPI->oapiDebugString(), "hello from mingwwwwww %.2f!!! %d %s", simt, orbiterAPI->oapiGetVesselCount(), orbiterAPI->GetName(v));
        if (simt > 5) {
            orbiterAPI->SetThrusterGroupLevel_type(v, THGROUP_MAIN, 1);
        }
    }
}
DLLCLBK void ExitModule(HINSTANCE hDLL)
{
    if (orbiterAPI)
    {
        delete orbiterAPI;
        orbiterAPI = nullptr;
    }
    init = false;
}

Orbiter loads the g++ produced dlls perfectly fine.

I am a C/C++ noob, so looking for feedback if this is even a good idea. I'd imagine now that Orbiter is open source one can probably recompile the orbitersdk libs for mingw, but that seems like a much harder thing to do.

edit:

I am using mingw32 downloaded from here:

winlibs-i686-posix-dwarf-gcc-14.1.0-llvm-18.1.5-mingw-w64ucrt-11.0.1-r1.7z
 

Attachments

Last edited:
No love for mingw, huh? I created implementations for the oapi functions, passing through to the wrapper functions. This allows users of this API to use the oapi functions directly instead of going through the wrapper.

Unfortunately in my test for creating a vessel module, I get a crash if I define an ovcInit. Maybe it's better to take the same route as ScriptMFD and ScriptVessel, and create a VESSEL wrapper to ovcInit in a msvc compiled wrapper module.

Having a stand alone compiler for orbiter modules that can be distributed easily like a zip addon could be really beneficial imo.
 
Maybe some more information for the uninitiated?
Having a stand alone compiler for orbiter modules that can be distributed easily like a zip addon could be really beneficial imo.
This sounds interesting. How would one use it?
 
Maybe some more information for the uninitiated?

This sounds interesting. How would one use it?

1. You can download the ming32 compiler zip here: https://github.com/brechtsanders/wi...14.1.0-llvm-18.1.5-mingw-w64ucrt-11.0.1-r1.7z

Let's say you extract it in C:\ming32
Add C:\mingw32\bin to your PATH environment variable. Instructions for adding to PATH in case you need them.

2. Now you can download and extract the zip file I attached in my post above to an Orbiter2016 root install.

You should now be able to run: Orbitersdk\Samples\mingw\mingw-orbiter-plugin\build.bat this will compile the main.cpp file into an Orbiter plugin DLL that can be loaded through modules tab.
 
So it's (among other things) an open source visual studio compiler alternative trimmed for easy use with Orbiter?
This is surely of interest for those finding it difficult to setup a compiling enviroment (something that has put me off in the past)?
Coding is a little over my time budget currently but appears to be the only way to go for extensive Orbiter addons and I will hopefully eventually move in that direction.
Would it be possible to setup a demo for a vessel dll, maybe with the dg.cpp?
Orbitersdk\Samples\mingw\mingw-orbiter-plugin\build.bat
I'll test and give you feedback
 
(win10, Orb2016) Created variable path and installed, bat compiled and created a .dll in modules\plugin, .dll loaded in orbiter.
I get a HELLO from ming and the main thrusters are locked to full thrust.
I tried it with Loadmfd2.cpp and Shuttlepb.cpp but no results. If I can compile vessels etc. like this that would be awesome and would look at coding something (maybe with the help of chatgpt ;)).
 
Thanks for testing @Buck Rogers! Currently in the above dll only oapi calls + VESSEL calls are covered so I wouldn't expect ShuttlePB/loadmfd to work JUST YET. But yea that's the idea. I wanted to get opinions on whether this is a good idea or a bad idea.
 
I wanted to get opinions on whether this is a good idea or a bad idea.
Get's my thumbs up.(y)
Feedback might be slow until it's already working.
What could the possible down sides be? (are the .dlls independant?).
I would be very interested in testing the next iteration:)
 
Back
Top