Jump to content

[0.25] Kerbal Warp Drive! Procedural systems from a seed you choose! v1.1.0, 16 Nov.


English Mobster

Recommended Posts

I'm very excited about this ambitious mod. What always stopped me getting Krag's PF was what I had read about the RAM requirements. Am I right in thinking that, because this is adjusting the existing Kerbol system, rather than generating a bunch of new planets, the RAM usage should not be too high?

If RAM is manageable I will definitely give this a go.

That is correct! At the moment, I'm not generating any new planets. If I ever do generate any planets, I will maintain a "lite" version which doesn't have the planet generation, specifically for that purpose.

Furthermore, all calculations are only done when you jump. I do write to the hard drive in the next update, which might slow down some absolutely ANCIENT computers, but the size of the files are so small 99.99% of people won't even notice. Even if copying over the persistence files did tax your computer, it would only happen when you jump -- between jumps, KSP will act as normal.

One more thing: Should I put in time dilation effects, or should I leave travel to and from instantaneous? It would have to be somewhat toned down from "reality" (so no 100-year absences from Kerbin), but if time dilation is included it would mean more time would pass in other solar systems while you travel there than the time it takes you to get there.

If it were included, it would likely be on the scale of months to years. I'm a bit hesitant about it, since I know it'll probably screw with times set up with Kerbal Alarm Clock and stuff, but it would depend on how "realistic" you guys want this to be.

Link to comment
Share on other sites

Thanks for confirming the RAM thing. I will create a new KSP folder and give this a go.

My thoughts on time dilation are that it should be an aim for the future, but because of how many implications it is bound to have on other stuff (like KAC), maybe look to introduce it when this is all closer to completion? In line with everything else in KSP it would have to be toned down I think.

Link to comment
Share on other sites

I had a brief look at this last night, and it worked very well. I warped a couple of times, and each new system generated immediately and looked good. Here's an icy world in a low solar orbit :P

6nzfD6l.png

One issue I ran into was being unable to right-click focus on certain planets and moons on the map screen. I could focus on some but not others; couldn't work out a pattern but I will try again when I have more time.

Another problem was, after warping to a new system, I clicked revert flight, back to the VAB. The next ship I launched appeared directly in orbit around the new system's star, without going to the launchpad or runway first, and I couldn't activate or do anything to the ship. Like when you're time warping. I had crew and power, but had no options in right click menus to activate things; this included the warp option, so I was effectively stuck in this new system, as I could not bring up the 'return to kerbol' button. I reverted flight and tried this a couple more times, with the same result every time. Maybe a temporary solution is to always remember to warp back to Kerbol before reverting flight.

Aside from these niggles, I was very impressed. Warp is practically instantaneous, and there was no appreciable increase in RAM use. So, this is looking good :)

Link to comment
Share on other sites

This is so cool. Literally thought about coding something similar myself, but I found this instead.

That's good because I barely know how to code.

If you ever manage to get procedural generated planets to work as well... I would be so happy.

Link to comment
Share on other sites

yeah, revert button's gonna crash the game, especially if it has flightstate data that conflicts with current seed.

That would be up to English Mobster, to take the revert save for kerbol prime, and rename it and stash it away somewhere, and do the same for each different system you visit, so they all have individual revert 'type' saves.

or...

...just jump back to kerbol prime before revertings ;)

Edited by bigbadben
Link to comment
Share on other sites

I had a brief look at this last night, and it worked very well. I warped a couple of times, and each new system generated immediately and looked good. Here's an icy world in a low solar orbit :P

<snip>

One issue I ran into was being unable to right-click focus on certain planets and moons on the map screen. I could focus on some but not others; couldn't work out a pattern but I will try again when I have more time.

Another problem was, after warping to a new system, I clicked revert flight, back to the VAB. The next ship I launched appeared directly in orbit around the new system's star, without going to the launchpad or runway first, and I couldn't activate or do anything to the ship. Like when you're time warping. I had crew and power, but had no options in right click menus to activate things; this included the warp option, so I was effectively stuck in this new system, as I could not bring up the 'return to kerbol' button. I reverted flight and tried this a couple more times, with the same result every time. Maybe a temporary solution is to always remember to warp back to Kerbol before reverting flight.

Aside from these niggles, I was very impressed. Warp is practically instantaneous, and there was no appreciable increase in RAM use. So, this is looking good :)

That last bit is indeed a known bug -- I think it's fixed now, but I'm not entirely sure. In any event, you can always restart KSP itself and everything will be a-okay again.

As for your first question -- does the map view keep zooming further and further out until you hit tab to focus a planet? I'm not sure if that's a bug I'm introducing in the next version, or if it's in the stable version.

This is so cool. Literally thought about coding something similar myself, but I found this instead.

That's good because I barely know how to code.

If you ever manage to get procedural generated planets to work as well... I would be so happy.

I'm taking a look at procedural planets. It looks like KSP has some sort of noise generator built-in, which I can likely repurpose to generate planet terrain. There's also a PQS class which I think handlles terrain generation and many, many different options for it. I honestly have no clue what it does, but I'll keep looking at other mods that modify terrain to see how they do it and imitate what they have done.

In any event, it will probably be a lot of work. Doable, but a lot of work.

yeah, revert button's gonna crash the game, especially if it has flightstate data that conflicts with current seed.

That would be up to English Mobster, to take the revert save for kerbol prime, and rename it and stash it away somewhere, and do the same for each different system you visit, so they all have individual revert 'type' saves.

or...

...just jump back to kerbol prime before revertings ;)

I do actually have a solution to this. I have finally gotten persistence to work properly!

I've reverse-engineered the Autosave/Quicksave functionality, and I think I have a general idea of what it does. What little documentation is out there was very helpful, but I still had to do a lot of experimentation before I figured out basically how it works. But now I have successfully generated persistence files local to each system! A sattelite in orbit around Duna will no longer be in that orbit once you warp to another system, but when you warp back to Kerbol it will still be there!

Here's basically a breakdown of how it works:

1. Take the active vessel and remove it from the list of vessels. This makes sure that we don't get cached before warping, thus preventing duplicate ships.

2. Create a new "blank" FlightState. This will automatically populate the ProtoVessels used in the persisitence file using our list of vessels. Since we just removed our active vessel from that list, this will effectively be a list of inactive vessels -- vessels which will be remaining behind when we warp.

3. Save the game, using GamePersistence.SaveGame(). I specify the filename to be <lastseed>_persistent.sfs. This is going to be the last "snapshot" of the system we are leaving.

4. Get a list of all vessels except our active vessel and destroy each one. You need to call Game.DestroyVessel() on each one in addition to Vessel.DestroyVesselComponents (). Note that this will not kill crew, and even if it did we've already saved our game.

5. Travel to the new system!

6. If we do not have a persistence file already for the new system, simply give ourselves another new FlightState. Honestly, I'm not sure if this part is necessary, strictly speaking, but I'm too afraid of breaking things again to play around with it.

7. If we do have a persistence file already for this system, DO NOT USE THE REGULAR "LOAD" FUNCTIONS. I tried for ages getting them to work, and the only thing I managed to accomplish was deleting all my crafts and turning my active vessel into an asteroid somehow. Instead, we want to selectively load just the crafts from the persistence file.

8. To do this, we get the full directory to the persistence file we want to load. Rather than using GamePersistence.Load(), create a new ConfigNode and pass it the full path to the persistence file. It will read all the lines in the persistence file for you and automatically generate a tree of nodes.

9. Now, we need the root node. If you look in any persistence file, you'll see things in ALL CAPS. These are the names of a new node. To get to our FlightState, we have to navigate first to the GAME node and then to the FLIGHTSTATE node.

10. Create a new instance of the FlightState class and pass in the FlightState node and a reference to the current game. This will generate the ProtoVessels for you, but it won't actually load them into the game itself (that part drove me crazy because I thought it simply wasn't reading my persistence file correctly).

11. Iterate over all the ProtoVessels in the FlightState you just created and load them manually with ProtoVessel.Load().

12. Update the game's FlightState with your most recent FlightState.

13. Now that all the vessels are loaded in, you can add your active vessel back to the vessel list.

14. I make sure at this point that the camera is still focused on the active vessel -- I'm pretty sure that's redundant at this point, but better safe than sorry.

15. Save the game over the old persistent.sfs file. Now the persistence file is completely localized to your present system!

At the moment I don't revert back to Kerbol when you go to KSC. That will probably come next. The big problem with that is managing the tracking station -- when I tried to bring the tracking station into all of this I managed to break everything. I do plan to have some way of managing it, but at the moment I have no clue what form that would take. I don't think I can add pretty new buttons to the tracking station, so it would have to be an ugly GUI window somewhere. Any ideas as to how the tracking station should be handled?

Link to comment
Share on other sites

As for your first question -- does the map view keep zooming further and further out until you hit tab to focus a planet? I'm not sure if that's a bug I'm introducing in the next version, or if it's in the stable version.

Actually I didn't try tabbing around (i will test later). This was just when I right clicked on planets, then clicked to focus view, and nothing happened. I remained focused elsewhere. I really only had a couple of mins to look at this, so I'll try to be more thorough later and report back

I do actually have a solution to this. I have finally gotten persistence to work properly!

This sounds like a very good solution to a tricky problem :)

Link to comment
Share on other sites

congrats on cracking the persistant issue.

Personally, I figure just dump it for now. Any modern tracking system cannot see beyond our solar system, anyways. They have a few extrasolar planets identified, but nothing like the info for Sol system. It keeps in line with the exploration mechanic of your mod, and creates less headaches for you.

Link to comment
Share on other sites

Time for some more explaining of what I'm up to.

Right now, I'm working on making things revert properly when you return to KSC. Rather than returning to the KSC equivalent in the system you jumped to, as it is currently, you return to the KSC of the Kerbol system. The first step here involved decoupling the Warp logic from the Hyperdrive PartModule itself, which was fairly easy. Reverting to Kerbin was easy as well, as I was able to repurpose a lot of code in the newly-decoupled warp drive. However, for some reason when I went to KSC everything in orbit went screwy. Part of the time I was able to attribute the issue to simply not having an active vessel, but the problems resulting from that have cascaded and resulted in all sorts of fun issues.

I usually had one of a few problems:

  • Object that warped away was still saved to Kerbol when I came back to KSC
  • Object that warped away was removed from Kerbol, but didn't get saved to its new system upon returning to KSC
  • All spacecraft in orbit around Kerbol were randomly deleted
  • All spacecraft in orbit around Kerbol got randomly duplicated (in the exact same positions they were, leading to massive explosions)

I've been slowly killing these problems, one-by-one, but it seems one of the other problems pops up every time I fix something. I believed I understood how persistence works (and I still think I have the general gist of it). However, I'm getting very inconsistent results with saving and loading, which doesn't make sense to me.

The first bug listed was an easy fix -- remove the active vessel from FlightGlobals.Vessels, rebuild the ProtoVessel cache (by creating a new FlightState), save, delete everything in FlightGlobals.Vessels, create another FlightState, add the active vessel back again, and save once more. However, while the first save worked fine (removing our active vessel from Kerbol orbit), the second didn't save any vessel at all. Creating a FlightState seems to populate FlightState.protoVessels with all vessels in FlightGlobals.Vessels -- or so I thought. However, although it creates a perfectly good persistence file, the second save doesn't add any vessels to the flight state and I don't know why.

I did fix that issue at one point. However, when I did so I would somehow wipe all of Kerbol's craft every time I jumped for no apparent reason. Finally, I managed to successfully create a "snapshot" of Kerbin every time I jumped, but when I returned all the craft would be duplicated for no reason. I only load the craft once, and they are only listed once in the file I'm loading from. All the print statements I use whenever I create a new craft get printed exactly once. However, every single craft got duplicated for no apparent reason.

I fixed that issue by scanning all the vessels in FlightGlobals every time we entered the Tracking Station or flight mode and deleting any vessel which had a duplicate ID. However, doing this caused the same issue I mentioned earlier where crafts that warp away from Kerbol don't get saved to their new system. It's not that I'm deleting them -- right now I am literally saving every single vessel in the system by using Unity's Object.FindObjectsOfType<T> function. However, for some strange reason the active vessel simply isn't being saved to the FlightState, even though the FlightState says it should be saved. Here's what I get in my FlightState:

	FLIGHTSTATE
{
version = 0.25.0
UT = 3105575.30545282
activeVessel = 0
mapViewFiltering = -1026
}

This should have VESSEL tags on the inside, but for some reason it doesn't and it's driving me nuts. I'm going to keep punching away at it and seeing if I can fix the problem, but I have to reverse-engineer the entire vessel activate/deactivate logic in order to work out what's going on (since I believe we can't decompile the KSP source and look at it under the EULA).

This is probably a bit of a confusing post if you don't have any experience with programming or knowledge of how KSP works, and I apologize for that. It's a bit frustrating throwing code at the wall and seeing what sticks, but once I do have something working, I'll see if I can simplify things down a bit and share my knowledge with the community at large to help others playing around with persistence.

Hopefully I'll get this resolved in the next couple of days and I can move on to other things. A lot of the randomization has been revamped, and I'd like to randomize the radii of planets to give more obvious SOIs.

I'm thinking about adding in some ModuleManager support for Interstellar, but I want to keep ModuleManager optional if I can to reduce dependencies. I'll have to see what happens if I reference ModuleManager without having the mod installed -- if it's possible for me to recover from the error, I'll probably implement something involving ModuleManager and Interstellar. However, if the error is not recoverable (although I don't know why that would be the case), it would have to be Interstellar implementing stuff from this mod.

Edited by English Mobster
Link to comment
Share on other sites

So I have a question.

Do vessels persist in your alternate solar systems? For example, If I left a probe in orbit around a planet, then warped a mother ship back to kerbol, what happens to the probe left behind? Does it just poof with the system in question?

Because the potential here could be ridiculous for extra-kerbolar colonies.

Link to comment
Share on other sites

So I have a question.

Do vessels persist in your alternate solar systems? For example, If I left a probe in orbit around a planet, then warped a mother ship back to kerbol, what happens to the probe left behind? Does it just poof with the system in question?

Because the potential here could be ridiculous for extra-kerbolar colonies.

In the currently-released version, things don't persist like that, no. They persist, but they persist across all systems -- they never go away. This was mainly because I wanted to make sure I was protecting people's save data.

In the next update, however, they will do exactly what you described. That's what I'm working on at the moment. I hope to have it ready by Monday, but no promises.

Edited by English Mobster
Link to comment
Share on other sites

This should have VESSEL tags on the inside, but for some reason it doesn't and it's driving me nuts. I'm going to keep punching away at it and seeing if I can fix the problem, but I have to reverse-engineer the entire vessel activate/deactivate logic in order to work out what's going on (since I believe we can't decompile the KSP source and look at it under the EULA).

This is a long shot, but it sounds like your issue is with ConfigNodes which are pretty notoriously fickle. Here's something that I discovered:

You cannot serialize an object to a ConfigNode unless it contains a zero-parameter constructor (or no constructors at all). So if the VESSEL is your own object and it has its own custom constructors, try adding in one with zero parameters and see if that helps.

Link to comment
Share on other sites

This is a long shot, but it sounds like your issue is with ConfigNodes which are pretty notoriously fickle. Here's something that I discovered:

You cannot serialize an object to a ConfigNode unless it contains a zero-parameter constructor (or no constructors at all). So if the VESSEL is your own object and it has its own custom constructors, try adding in one with zero parameters and see if that helps.

See, the thing is this is the actual Vessel class (or rather, ProtoVessel) that KSP generates when a persistence file is saved. It's part of the stock game and not a class I've created.

I've actually narrowed down what the issue is. I originally saved a "snapshot" of the last-generated world the moment the KSC scene loaded (in the Awake() method, for those of you who know Unity). That appears to be before KSP loads in the vessels -- so I was taking a snapshot of a game with no vessels (hence the empty space where vessels should be).

If I move it to Start(), I get the vessels -- but now I'm saving the vessels from Kerbin again. I'm trying to work out when exactly KSP loads the vessels into the KSC scene so I can reliably manipulate it. I'm considering making a class which has a log of every vessel we've ever saved and keeps track of what seed each vessel is in, deleting the vessels that aren't in the right seed. I've also got to seriously clean up my code, as all this experimentation and reverse-engineering has made everything messy.

Ideally, I'd like to save a snapshot when the flight scene gets unloaded, as opposed to saving one after KSC is loaded. I'm a bit worried about writing to file as the scene closes, however, since I have no control over what gets deleted when. I could try to save a snapshot when half the scene has already been deleted, for example. I'm going to poke around a bit and see if there's anything I can hook into that's called before OnDestroy(), but I'm not sure there is.

Edited by English Mobster
Link to comment
Share on other sites

If I move it to Start(), I get the vessels -- but now I'm saving the vessels from Kerbin again. I'm trying to work out when exactly KSP loads the vessels into the KSC scene so I can reliably manipulate it.

You might be looking for OnVesselCreate() which is called every scene load for each vessel in the world.

The addon I am working on has been all event tracking so I've been mucking with the order of events as well!

Link to comment
Share on other sites

I have some great news! I've done it! Everything seems to be working A-OK now.

Whenever you launch to other star systems, your last system is cached. If the system you are launching to already exists, then the other system's vessels are loaded.

This is mostly due to 2 handy GameEvents (thanks, OverloadUT and Joshwoo69!): onGamePause() and onGameSceneLoadRequested(). Whenever you pause the game or switch scenes, I save the current system to disk. This means when we load the next scene we can just reload Kerbol without needing to worry about saving the last system. Since KSP shouldn't require many resources while paused, I figured it couldn't hurt to save the game when we pause. The redundant onGameSceneLoadRequested() is in there just to make sure I cover the event of a rapid unplanned disassembly in-flight, where the player doesn't necessarily need to open the pause menu.

I want to make sure that this release is fairly stable before, well, releasing it. I've already found a bug which killed all my orbital velocity and sent me crashing into the sun, and I'd rather not repeat it. I also want to make sure my save recovery system works in the event that the game crashes. There is also a bug right now with how far out moons orbit planets -- I tried calculating them using Hill Spheres, and the result was much too large. I also have an issue with orbital periods -- moons presently make a full rotation around their parent every minute or so.

Both of these should be easy fixes. Once I'm happy with the results and kill any remaining bugs, I'll release it to you all. The next version has a lot of improvements, both visible and internal.

Keep in mind that the planetary RNG system has changed a bit internally, so if you've grown attached to a seed it's going to be completely different when you load the next version. I'm going to try and minimize this effect happening on every release, but if I tweak any random variable or add in any new random stuff it's going to throw off everything just due to the nature of things.

Edited by English Mobster
Link to comment
Share on other sites

This mod is becoming more and more mature !

I see a great future ahead.

v1.0 was nice to test around with. The version you are about to release goes further.

Congratulations Mob, I support your project.

(in case you didn't notice, I made some advertisement using my sig..shhh)

Link to comment
Share on other sites

Does this break clouds?

What does it do to asteroids?

Kethane?

ORS?

Asteroids: Cleared when you warp. New asteroids will be generated around the system you jump to. Jumping back to your original system will restore your original asteroids. Think of them as very heavy space stations, since that's how the game sees them. :P

Kethane/ORS: Have not tested them yet, to be honest. In theory, they should be unaffected by the warp, since as far as Kethane is concerned an alternate Kerbin is still Kerbin. Kethane doesn't care (or at least it shouldn't care) what Kerbin's orbit is, what Kerbin is named, what its atmosphere is like, etc. All it cares about is that Kerbin is identified as Kerbin. This should also apply to ORS. Is Real Solar System compatible with Kethane/ORS? If it is, this mod should be, too.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...