Advanced Question How to prevent saving vessel to scenario?

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
I'm creating a vessel with oapiCreateVesselEx during simulation, which won't be deleted until simulation end. How to prevent saving it to scenario file on simulation end, or when oapiSaveScenario is called? Exporting empty clbkSaveState callback leaves empty entry of that vessel in scenario file.

BTW. Another thing I'd like to know is how to hide a non-focusable vessel from camera input? I tried to create a vessel with empty name, but it's still listed in Ships list for camera target, and it's still saved to scenario file (they, and multiple times, but camera targets only the first from the list, and scenario file is unusable until it's cleared from those vessels).

Are there some ways of creating vessels on runtime, other than oapiCreateVessel / oapiCreateVesselEx with created earlier vessel configuration file? Vessel class constructor needs an object handle of vessel, so I don't think it can be called explicitly.
 

Bj

Addon Developer
Addon Developer
Donator
Joined
Oct 16, 2007
Messages
1,886
Reaction score
11
Points
0
Location
USA-WA
Website
www.orbiter-forum.com
I'm creating a vessel with oapiCreateVesselEx during simulation, which won't be deleted until simulation end. How to prevent saving it to scenario file on simulation end, or when oapiSaveScenario is called? Exporting empty clbkSaveState callback leaves empty entry of that vessel in scenario file.

Well the best method I can think of is to (inside the destructor/cleanup of the vessel) actually open the scenario and remove that bit of text that you don't want. Though others might have better methods.


Are there some ways of creating vessels on runtime, other than oapiCreateVessel / oapiCreateVesselEx with created earlier vessel configuration file? Vessel class constructor needs an object handle of vessel, so I don't think it can be called explicitly.

Probably not, because orbiter needs to handle that vessel


BTW. Another thing I'd like to know is how to hide a non-focusable vessel from camera input? I tried to create a vessel with empty name, but it's still listed in Ships list for camera target, and it's still saved to scenario file (they, and multiple times, but camera targets only the first from the list, and scenario file is unusable until it's cleared from those vessels).

In the config file of the vessel write;

EnableFocus = false

No idea how to not enable camera input by code though, other than calling oapiSetFocusObject every time focus changes to that vessel.
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
In the config file of the vessel write;

EnableFocus = false

That only prevents focusing the vessel, but camera can still target it.
 

Bj

Addon Developer
Addon Developer
Donator
Joined
Oct 16, 2007
Messages
1,886
Reaction score
11
Points
0
Location
USA-WA
Website
www.orbiter-forum.com
That only prevents focusing the vessel, but camera can still target it.

Oh right sorry

So your probably going to need to call oapiCameraTarget when the camera target changes to check to see if its the vessel you want to 'ignore', then oapiSetFocusObject to the last vessel that had focus before the user switched the camera target. I think if you change the focus object then the camera auto-switches to that.

Other than that, wouldn't have a clue, good luck :cheers:
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
So, I've finally found a way to do what I want, but it's Orbiter version dependent, and involves direct editing of count of vessels in Orbiter's memory (decrementing the count), just after creating a new vessel, which needs to be hidden from camera targeting and be not saved to scenario. After doing this, those vessels are still enumerated on object list, but not on vessel list, and they are neither saved to scenario file, nor listed as a ship on camera target list.

I need to check yet, which callbacks are called, and which other aren't, when vessel is on list of objects, but not on list of vessels.

Now, I can build a code with predefined pointers to memory locations for known versions of Orbiter, or my code could be also analyzing oapiGetVesselCount to get exact memory address of vessels' count, if version of Orbiter is different from those known by my module.

I think this is the simplest and the fastest way for achieving what I wanted.
 

Hielor

Defender of Truth
Donator
Beta Tester
Joined
May 30, 2008
Messages
5,580
Reaction score
2
Points
0
So, I've finally found a way to do what I want, but it's Orbiter version dependent, and involves direct editing of count of vessels in Orbiter's memory (decrementing the count), just after creating a new vessel, which needs to be hidden from camera targeting and be not saved to scenario. After doing this, those vessels are still enumerated on object list, but not on vessel list, and they are neither saved to scenario file, nor listed as a ship on camera target list.

I need to check yet, which callbacks are called, and which other aren't, when vessel is on list of objects, but not on list of vessels.

Now, I can build a code with predefined pointers to memory locations for known versions of Orbiter, or my code could be also analyzing oapiGetVesselCount to get exact memory address of vessels' count, if version of Orbiter is different from those known by my module.

I think this is the simplest and the fastest way for achieving what I wanted.

So what happens if someone else creates a vessel after you've messed up the counter that way?

Or what about all the addons out there which rely on that counter to be correct in order to loop over all vessels in the scenario? They'll find the vessel you're hiding, but not the vessel that someone else created afterwards...

This sounds like a really bad idea.

As for not saving to a scenario file--would it be possible to detect when the simulation is ending and delete the vessel before it gets saved?
 

computerex

Addon Developer
Addon Developer
Joined
Oct 16, 2007
Messages
1,282
Reaction score
17
Points
0
Location
Florida
Modifying the memory for something like this is bound to cause trouble. The fastest, easiest, and simplest solution is to simply check for the existence of the vessel at simulation start and simulation end, then delete it there. It may be possible that there is a callback that you have access to that gets called before the scenario state is saved when the simulation is ending. But if that is not possible checking for the vessel at the start should be sufficient imho. Use oapiCameraTarget and oapiCameraAttach for the camera.
 
Last edited:

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
So what happens if someone else creates a vessel after you've messed up the counter that way?
Next vessel's object handle (pointer) replaces the object handle of vessel which was at the end of list and was hidden by decrementing the counter, and all following vessels are handled by Orbiter as they should be.

Or what about all the addons out there which rely on that counter to be correct in order to loop over all vessels in the scenario? They'll find the vessel you're hiding, but not the vessel that someone else created afterwards...
I don't want my vessel to be listed by other add-ons, and following vessels are listed. If one wants to list my vessel, may use oapiGetObjectCount, oapiGetObjectByIndex and oapiGetObjectType.

As for not saving to a scenario file--would it be possible to detect when the simulation is ending and delete the vessel before it gets saved?
And how to detect oapiSaveScenario which may be called at any point of simulation. And deleting vessel before that would be also bad, because the vessel wouldn't be present in simulation afterwards. I don't want to delete this vessel. Let the simulation do this.

This sounds like a really bad idea.
I'll decide after further testing, whether it's bad or good, but first tests show it works fine (I need to check yet which callbacks for the vessel I prevented from calling, after hiding the vessel).

---------- Post added at 23:25 ---------- Previous post was at 23:21 ----------

Modifying the memory for something like this is bound to cause trouble.
I have some experience with direct modifying the memory of process from a DLL used by this process (For Morrowind Graphics Extender it worked and still works).
 
Last edited:
Top