Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement kUniverse #152

Closed
PhilouDS opened this issue Mar 30, 2024 · 18 comments
Closed

Enhancement kUniverse #152

PhilouDS opened this issue Mar 30, 2024 · 18 comments
Labels
enhancement New feature or request stale Issue has not seen activity for 60 days

Comments

@PhilouDS
Copy link
Contributor

Me again :)

I like the kUniverse structure from kOS.
https://ksp-kos.github.io/KOS/structures/misc/kuniverse.html

2 things in particular:

  • the possibility to quick save
  • the possibility to revert to launch.

I use the latter for gravity turn tests.

Any chance we can have this in kontrol System too? 😬

@untoldwind untoldwind added the enhancement New feature or request label Mar 31, 2024
@untoldwind
Copy link
Owner

untoldwind commented Mar 31, 2024

Looks like a lot of these functions are private.
It should be possible to trigger the corresponding event, but it might be hard to get a clean callback when the operation has finished (the load/save operations seem to run in their own coroutines).

Surprisingly enough: The underlying functions to reset the "Universe" to a previous state are public, so it actually might be easier to have own inScript-savepoints to revert to.

Edit: This is a bit more complicated than expected, I will move that to the next release.

@untoldwind
Copy link
Owner

Added experimental support for this in pre-release 0.5.7.7 (https://github.com/untoldwind/KontrolSystem2/releases/tag/v0.5.7.7)

Quick-Save seems to work pretty reliable:

use { Vessel } from ksp::vessel
use { CONSOLE, RED, WHITE } from ksp::console
use { sleep, wait_while, wait_until, current_time } from ksp::game
use { DEBUG, SAVE_LOAD_CONTROL } from ksp::debug

pub fn main_flight(vessel: Vessel) -> Result<Unit, string> = {
    CONSOLE.clear()

    SAVE_LOAD_CONTROL.quick_save()

    wait_while(fn() -> SAVE_LOAD_CONTROL.is_saving) // If waiting for completion is necessary

    CONSOLE.print_line("Done")
}

Similarly a Quick-Load can be triggered with:

use { Vessel } from ksp::vessel
use { CONSOLE, RED, WHITE } from ksp::console
use { sleep, wait_while, wait_until, current_time } from ksp::game
use { DEBUG, SAVE_LOAD_CONTROL } from ksp::debug

pub fn main_flight(vessel: Vessel) -> Result<Unit, string> = {
    CONSOLE.clear()

    SAVE_LOAD_CONTROL.quick_load()
}

But: This will implicitly terminate all running scripts, including the script that triggered the re-load.
This is probably a good thing, because all in-game references (like the reference to the active vessel) will become invalid anyway.

@PhilouDS
Copy link
Contributor Author

PhilouDS commented Apr 1, 2024

Thanks

@lefouvert
Copy link

lefouvert commented Apr 2, 2024

Out of curiosity, how bad would it be if a script would be able to «auto-load» himself at flight start/quick save load ?
Not from old references, of course, but from start, main_filght(vessel: Vessel, yapyapyap: Velociraptor)
Not an actual need, just an idea to play with.

@untoldwind
Copy link
Owner

I guess it would be preferable to be able to distinguished between started-by-user and re-started-due-to-reload somehow.
Unluckily there is a lot internal stuff happening during a reload (the loading screen is not just for show ;) ), so I still have to figure out how to ensure that the restart does not happen too early.

@lefouvert
Copy link

lefouvert commented Apr 2, 2024

I understand your struggles. If it can solace you, remember KSP2 itself is not able to load itself properly : I have a craft which at first load violently Krakenify the firsts seconds of flight until it goes boom and fall down in pieces.
Second load, everything is perfect, stable, etc.
I dont know if it's aerodynamics or vessel's parts joint which are not correctly loaded, but undoubtly, something is missing.
So be able to know when the Kontrol System layer is free to go had to be not so easy.

@PhilouDS
Copy link
Contributor Author

PhilouDS commented Apr 2, 2024

I guess it would be preferable to be able to distinguished between started-by-user and re-started-due-to-reload somehow. Unluckily there is a lot internal stuff happening during a reload (the loading screen is not just for show ;) ), so I still have to figure out how to ensure that the restart does not happen too early.

I think this was the problem with kOS when they created the boot file.

Booting when spawning to launchpad
When you first spawn a new vessel on the launchapd from the VAB (or when you spawn it to the runway from the SPH), kOS performs the following initial steps to get the boot file copied from archive to the ship:

Creates a folder called boot/ on the kOS computer’s local volume (1:/).

Copies the boot file from the archive’s boot/ folder to the local volume’s boot folder.

Important: NOW is the point where Kerbal Space Program saves the game for the purpose of being able to “revert to launch”.

kOS begins running that local copy of the boot file.

Please make note of when during those steps Kerbal Space Program saved the game for the sake of doing a revert to launch. If you edit the boot file on the archive, and then revert to launch, then your vessel will not have the newly edited boot file copied to it because it doesn’t go all the way back to do step 1 and 2 from the above list again. To force it to use the new version of the boot file you will either have to revert it all the way to the assembly building and re-launch it from there, or stop the boot file with ctrl-C and manually copy the new file and reboot.

It might be great to have a boot file like this in Kontrol System but, as lefouvert said, KSP2 is not reliable yet.

@untoldwind
Copy link
Owner

It been been a while since I have used kOS, but if I remember correctly there was a special part that had to be attached to a vessel, and one of the properties of that part was the boot-file to "auto-start" for the vessel.

So far I avoided messing around with the part-definitions of KSP2, but I think there is now a plugin that support patch-files similar to the ModuleManager in KSP1. So maybe it would be (at the very least) feasible to add a PartModule to (lets say) the control-parts where a start-script could be configured

@PhilouDS
Copy link
Contributor Author

PhilouDS commented Apr 2, 2024

Yes, you're right. The boot file needed to be loaded in the VAB from a special part.
In RP1, you don't need the kOS part since you have all the kOS action in the avionics. So it could be a good idea to use a PartModule to control-parts.

@lefouvert
Copy link

lefouvert commented Apr 2, 2024

As far I remember :
Special part on your ship
The part have a parameter to choose a specific file to boot on (file which have to be in a specific folder)
Thoses two are saved in craft savefile
As soon the inflight context is loaded, the selected bootscript start.
This boot script HAVE TO wait for a variable (ship.unpacked ?) to be sure all parts are fully loaded.
And there you go.

But since I haven't played since a while too, I maybe forgotten something.
However, I don't expect Kontrol System to be «KOs 2», even if it's heavily inspried from, and some features of KOs were usefull.

@PhilouDS
Copy link
Contributor Author

PhilouDS commented Apr 2, 2024

This boot script HAVE TO wait for a variable (ship.unpacked ?) to be sure all parts are fully loaded. And there you go.

It's not mandatory, the boot script doesn't need to wait for a variable.. BUT! because of what I shared in a previous message from the kOS documentation, the boot file is loaded before the craft is unpacked so you need to be cautious.

However, I don't expect Kontrol System to be «KOs 2», even if it's heavily inspried from, and some features of KOs were usefull.

You're right. to2 can't be a copy of kOS but I'm okay if we grab some piece of it to improve it 😇

@lefouvert
Copy link

Yup, it's not a mandatory, but as soon as you want to compute anything vessel related (The main purpose of the mod), if you don't wait, you WILL have unexpected result, if you don't just crash your script.

For me, it's as «the parachute is not a mandatory to experienced free fall when you jump from a plane». A true assertion. But I won't try twice.

@PhilouDS
Copy link
Contributor Author

PhilouDS commented Apr 7, 2024

@untoldwind May I ask for something more: the possibility to check if the vessel is recoverable and, if it is, to recover it (and thus, to end the script at the same time I suppose). Thank you very much.
🙏 😇

@untoldwind
Copy link
Owner

The callback in the ESC-menu of the game is "private", and it looks like there are some hard-coded conditions like: A vessel is only recoverable of it splashed or landed on Kerbin.
I think it should be possible to just re-implement these conditions in the addon, but there is a good chance that is might break with future releases of the game.

@untoldwind
Copy link
Owner

In 0.5.8.2 (https://github.com/untoldwind/KontrolSystem2/releases/tag/v0.5.8.2)
I added a try_recover_vessel to ksp::debug::SAVE_LOAD_CONTROL, which should do the same as pressing the button in the ESC-menu.

@PhilouDS
Copy link
Contributor Author

PhilouDS commented Apr 8, 2024

In 0.5.8.2 (https://github.com/untoldwind/KontrolSystem2/releases/tag/v0.5.8.2) I added a try_recover_vessel to ksp::debug::SAVE_LOAD_CONTROL, which should do the same as pressing the button in the ESC-menu.

I just finish to test it: it's perfect! thanks!

Copy link

github-actions bot commented Jun 8, 2024

This issue is stale because it has been open for 60 days with no activity.

@github-actions github-actions bot added the stale Issue has not seen activity for 60 days label Jun 8, 2024
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale Issue has not seen activity for 60 days
Projects
None yet
Development

No branches or pull requests

3 participants