I know it's possible query the current mode of a given MFD, but is it possible to get the actual instance of the MFD class using Orbiter's API?
I know it's possible query the current mode of a given MFD, but is it possible to get the actual instance of the MFD class using Orbiter's API?
void Update (HDC hDC)
void InvalidateDisplay ()
void InvalidateButtons ()
void Title (HDC hDC, const char *title)
HPEN SelectDefaultPen (HDC hDC, DWORD i)
HFONT SelectDefaultFont (HDC hDC, DWORD i)
bool ConsumeKeyBuffered (DWORD key)
bool ConsumeKeyImmediate (char *kstate)
bool ConsumeButton (int bt, int event)
char *ButtonLabel (int bt)
int ButtonMenu (const MFDBUTTONMENU **menu)
void WriteStatus (FILEHANDLE scn)
void ReadStatus (FILEHANDLE scn)
void StoreStatus ()
void RecallStatus ()
If you just need that functionality for a specific MFD implementation, and you're writing that yourself, it should be possible to make it work by having a static member in the MFD class keeping track of created instances and vessels they are assigned to.
He already mentioned that he wants to get the instance from the vessel code side, not from the MFD one.
I know, maybe I was a bit unclear:
If you need to get the instance of a specific implementation you have the code of, you can arrange for that by the MFD tracking created instances and offering a static accessor to retrieve them. Whether from the vessel or from somewhere else wouldn't matter that much at this point.
How exactly would I go about sending the instance pointer via clbkGeneric?
It is best practice to store data objects for each vessel (or vessel/MFD combination) inside the MFD code, so user input survives cockpit view switches.
This is why I wanted the MFD instance in the first place, to get at the data objects. I'm not at my dev PC right now, but I'll try the "clbkGeneric" method later tonight and get back to you.
So if I have this right - you have an MFD that needs to manipulate / display / HUD display strings from vessels or other addins, right? Like a Syslog MFD
// Something has happened that gadget thinks the player should know about.
gadget::event()
{
I have a message!
Is there an instance of "gadget mfd" active?
if (yes)
{
add my message to the MFD's message queue.
}
else
{
do something else.
}
}
# HG changeset patch
# User Face
# Date 1477597543 -7200
# Thu Oct 27 21:45:43 2016 +0200
# Node ID 4d780663f29d57eba46aef4a54b0dceb54ee8ca8
# Parent 7cbfabd57c4566b0a30e3049d4b9e6c5bb21cc1f
adding logger to stock ShuttleA code
diff --git a/Orbitersdk/samples/ShuttleA/ShuttleA.cpp b/Orbitersdk/samples/ShuttleA/ShuttleA.cpp
--- a/Orbitersdk/samples/ShuttleA/ShuttleA.cpp
+++ b/Orbitersdk/samples/ShuttleA/ShuttleA.cpp
@@ -74,6 +74,7 @@
for (i = 0; i < 6; i++) {
cargo_open[i]=0; //not opened. not jettisoned
cargo_arm_status = 0; //not armed
+ logger=NULL;
}
}
@@ -1626,6 +1627,10 @@
if (!down) return 0; // only process keydown events
if (Playback()) return 0; // don't allow manual user input during a playback
+ char text[20];
+ sprintf(text, "key %d", key);
+ if (logger) logger->Log(text);
+
if (KEYMOD_SHIFT (kstate)) {
} else if (KEYMOD_CONTROL (kstate)) {
switch (key) {
@@ -2222,6 +2227,13 @@
return false;
};
+int ShuttleA::clbkGeneric(int msgid, int prm, void *context)
+{
+ if (msgid!=0x1337) return 0;
+ if (prm!=0) return 0;
+ logger=(Logger *)context;
+}
+
// ==============================================================
// API callback interface
// ==============================================================
diff --git a/Orbitersdk/samples/ShuttleA/ShuttleA.h b/Orbitersdk/samples/ShuttleA/ShuttleA.h
--- a/Orbitersdk/samples/ShuttleA/ShuttleA.h
+++ b/Orbitersdk/samples/ShuttleA/ShuttleA.h
@@ -12,6 +12,7 @@
#define __SHUTTLEA_H
#include "orbitersdk.h"
+#include "Logger.h"
// ==========================================================
// Some vessel class caps
@@ -135,8 +136,10 @@
bool clbkLoadVC (int id);
bool clbkVCRedrawEvent (int id, int event, SURFHANDLE surf);
bool clbkVCMouseEvent (int id, int event, VECTOR3 &p);
+ int clbkGeneric(int msgid, int prm, void *context);
private:
+ Logger *logger;
void DefineAnimations ();
bool ToggleGrapple (int grapple);
double payload_mass;