Hi,
I tried hard and long, but I don't get to a point. So here is a longer description of my problem, the interesting outtakes of code and some questions about API.
I want to implement saving and loading from scenario file for the status od my MFD. I put some work into splitting properties to vessel- and MFD-topics for the purpose of having two of my MFDs open at same time (left and right) and each displaying different pages.
This is my MFD class:
For saving now I do:
This is quite easy and it works. Having two HoverMFD it will write to scenario:
The code to load a scenario file:
This works quite well if having only one HoverMFD. But when left and right are HoverMFD and should display different pages is does NOT work (one state is loaded, other ignored)
Since these scenario funtions are implemented I also noticed in my tests, that sometimes after scenario loading the pointers to my data instances point to somewhere. Since my MFD displays vessel class and name I then read "Brighton Beach" ore whatever and of course AP doesn't react to my settings since it is not a vessel at all...
1. important question for me is: In what order do things happen? I thought it should be:
As MFD developer I had to learn that my MFD is created quite often (switching vessels, go out / inside cockpit etc.). But of course there has to be an instance of HoverMFD : public MFD2 before data is loaded!?
That MFD instance would have my data instance created:
These Get() fuctions maintain two lists (vessels and MFDs), search for the given vessel pointer and that UINT mfd ID. If found that data will be used because it was created by earlier creations of the same MFD. If not found they create a proper data instance:
So I thought while within ReadStatus I can rely on an existing MFD and MfdData instance. And I think that's proven by my only one MFD attempts. But I'm irritated and put that into question, so:
2. important question: Is writing into data instances like "ss >> mfdData->page" allowed within ReadStatus?
3. important question: What's about that MFD ID? I thought it vessel dependent (some have more than left and right) and left MFD has always the same ID (maybe 0).
4. important question: Of course each scenario section (BEGIN_MFD Left / BEGIN_MFD Right) is loaded separately and for each an own instance of MFD is created (and then followed by my data instance creation)?
I hope someone is deep into MFD topics and can help me
Greetings
Mythos
I tried hard and long, but I don't get to a point. So here is a longer description of my problem, the interesting outtakes of code and some questions about API.
I want to implement saving and loading from scenario file for the status od my MFD. I put some work into splitting properties to vessel- and MFD-topics for the purpose of having two of my MFDs open at same time (left and right) and each displaying different pages.
This is my MFD class:
PHP:
class HoverMFD: public MFD2 {
public:
HoverMFD (DWORD w, DWORD h, VESSEL *vessel, UINT mfd);
...
void ReadStatus (FILEHANDLE scn);
void WriteStatus (FILEHANDLE scn) const;
//The data instance the MFD is linked to
MfdData *mfdData;
For saving now I do:
PHP:
void HoverMFD::WriteStatus (FILEHANDLE scn) const {
oapiWriteScenario_int (scn, "PAGE", mfdData->page);
This is quite easy and it works. Having two HoverMFD it will write to scenario:
Code:
BEGIN_MFD Left
TYPE User
MODE HoverMFD
PAGE 1
END_MFD
BEGIN_MFD Right
TYPE User
MODE HoverMFD
PAGE 2
END_MFD
The code to load a scenario file:
PHP:
void HoverMFD::ReadStatus (FILEHANDLE scn) {
char *line;
while (oapiReadScenario_nextline (scn, line)) {
std::istringstream ss;
ss.str(line);
std::string id;
if ( ss >> id ) {
if ( id == "PAGE" )
ss >> mfdData->page;
This works quite well if having only one HoverMFD. But when left and right are HoverMFD and should display different pages is does NOT work (one state is loaded, other ignored)
Since these scenario funtions are implemented I also noticed in my tests, that sometimes after scenario loading the pointers to my data instances point to somewhere. Since my MFD displays vessel class and name I then read "Brighton Beach" ore whatever and of course AP doesn't react to my settings since it is not a vessel at all...
1. important question for me is: In what order do things happen? I thought it should be:
- all vessels are created from scenario
- vessel stuff is loaded from scenario
- all MFDs for active vessel are created
- MFD stuff is loaded from scenario
As MFD developer I had to learn that my MFD is created quite often (switching vessels, go out / inside cockpit etc.). But of course there has to be an instance of HoverMFD : public MFD2 before data is loaded!?
That MFD instance would have my data instance created:
PHP:
HoverMFD::HoverMFD (DWORD w, DWORD h, VESSEL *vessel, UINT mfd)
: MFD2 (w, h, vessel) {
// Link to the correspondig data instance
mfdData = g_HoverModule->mfdList->Get ( vessel, mfd, g_HoverModule->vesselList->Get(vessel) );
These Get() fuctions maintain two lists (vessels and MFDs), search for the given vessel pointer and that UINT mfd ID. If found that data will be used because it was created by earlier creations of the same MFD. If not found they create a proper data instance:
PHP:
MfdData *MfdList::Get(VESSEL *vessel, UINT mfdID, VesselData *vd) {
// searching ...
if (!result) {
// nothing found
result = new MfdData(vessel, mfdID, vd); }
return result;
So I thought while within ReadStatus I can rely on an existing MFD and MfdData instance. And I think that's proven by my only one MFD attempts. But I'm irritated and put that into question, so:
2. important question: Is writing into data instances like "ss >> mfdData->page" allowed within ReadStatus?
3. important question: What's about that MFD ID? I thought it vessel dependent (some have more than left and right) and left MFD has always the same ID (maybe 0).
4. important question: Of course each scenario section (BEGIN_MFD Left / BEGIN_MFD Right) is loaded separately and for each an own instance of MFD is created (and then followed by my data instance creation)?
I hope someone is deep into MFD topics and can help me
Greetings
Mythos