jamespicone

[1.1.3] BackgroundProcessing

Recommended Posts

It might be a while before I get it in fully-working state. There's two major problems I'm aware of right now:

- The solar panel revamp has meant that my old code for emulating solar panels in the background is very wrong. New solar panels are quite complicated and hard to emulate (part temperature matters now, and atmosphere alters charge rates as well). It'll be a while before those are at the same standard.

- Some of the new parts are implemented using ModuleGenerator with inputs (Fuel cells in particular). Previously, BackgroundProcessing ignored ModuleGenerators with inputs, because 1) there were no such parts in stock KSP, and 2) it wasn't clear to me how they were supposed to function. Now I've got a test case and I can fiddle a bit. That one should be much easier to implement than the solar panels.

I've had a bit of a break from KSP modding as well, so I've only started looking into this stuff again recently.

Share this post


Link to post
Share on other sites

Okay, I've been doing some fiddling.

Solar panels are much better in the source tree now. They are still not accurate, but they're nearly as good as they're likely to get. The big problem is part temperature - accurately emulating that would be extremely difficult. At the moment, I assume part temperatures are perfectly static once a vessel goes into the background. The implication is that if your part is warmer - or colder - than normal when you go into the background (Maybe you've just gone through re-entry, for example), then it'll produce different outputs to what it would have in the foreground. In particular, when something is orbiting presence or absence of direct sunlight would be a factor normally, and it isn't right now. In the future I might do this better - perhaps a very simple emulation of part temperature that handles the orbital case.

Fuel cells aren't implemented and aren't likely to be for the near future. ISRUs as well. The reason is because they use resources that have stage priority, and I don't want to do the work of accurately emulating stage-priority resources right now. Future work is likely to be either emulating stage priority, or emulating those resources only if you tell the config file that it's okay to have the weirdness associated with treating staged resources like they're whole-ship.

Also there's a config file now. Current options include:

- Whether or not solar panel orientation matters to solar power or not. This switch is present because there's some indication that vessel orientation during background might not be accurate, and I haven't tried to fix that yet, so you can turn it off.

- Whether temperature matters to solar power, for the reasons I gave above re: temperature being hard.

- Debug log level. Ranges from SILENT, to ERROR, to WARNING, to ALL at present. ERROR by default.

I haven't made a release yet, and likely won't for a little bit (I want to chase up a couple of other things, some stuff probably doesn't respect enable/disable state properly, although I've fixed the flowstate resource tank thing in source). When I do make a release, it won't be on KAN for a bit because I've changed a fair amount of stuff and want to shake out the bugs first.

Share this post


Link to post
Share on other sites

hello

Also there's a config file now. Current options include:

- Whether or not solar panel orientation matters to solar power or not.

Great!

On-rails vessel orientation is very weird (at least in 0.90).

And i love config files. Consider adding some switch to choose what (built-in) module can run in background? enableSolar, enableGenerator, enableCommand, enableFuelCell, enableISRU... It can be convenient (at this time, i modify your source to do that).

Thanks! Glad you continue to support this amazing mod.

ps: your source is still in google code? Be careful, it won't work anymore in august.

Edited by Merill

Share this post


Link to post
Share on other sites
hello

Great!

On-rails vessel orientation is very weird (at least in 0.90).

And i love config files. Consider adding some switch to choose what (built-in) module can run in background? enableSolar, enableGenerator, enableCommand, enableFuelCell, enableISRU... It can be convenient (at this time, i modify your source to do that).

Thanks! Glad you continue to support this amazing mod.

ps: your source is still in google code? Be careful, it won't work anymore in august.

Sure, that's an easy-enough feature to add.

I've moved the source over to BitBucket. I'll edit the first post at some point.

Share this post


Link to post
Share on other sites

Are there any caveats if i use this with ither mods that do things on non active vessels?

Like TAC LifeSupport consuming electricity in command pods or JDiminishingRTG (don't know exactly if the mod produces electricity in background)

Share this post


Link to post
Share on other sites

There can be interactions. Those interactions can be weird. Possibilities include things like resources being generated/consumed twice as fast, or only some resources being generated/consumed twice as fast, as the boring case.

The specific mods you've just mentioned: my quick scan of TAC Life Support suggests that it doesn't handle resources in unloaded vessels - only vessels you're not flying that are still close enough to be loaded. Background Processing only handles resources in vessels that are unloaded. There shouldn't be any direct problems caused by the overlap because of that, although some life support stuff probably won't consume in the background. I don't guarantee that, either - this is based on a cursory glance at the TAC source.

JDiminishingRTG, the post claims stuff updates on unfocused vessels, but I don't see where that happens with a cursory glance at the source - it's possible I'm missing it. Regardless, it uses its own ModuleDiminishingRTG class that my code doesn't know how to drive, so it's /probably/ okay, but the parts it replaces will be background-updated by its code, not mine.

Share this post


Link to post
Share on other sites

So Guys I've throwed this idea on the TACLS, basically its a proposition to make an API engine for background resource management with some life support support on it.

I've heard from TaranisElsu that he might be working on that but didn't quite understand if he liked it or what he wants to do.

Either way, this is very relevant to the idea of this mod specifically, so I thought to throw it in here too if anyone wants to.

By the way, jamespicone,the way you've described means TACLS will conflict with background processing, TAC tracks the resource usage for unloaded vessels and then apply the differences when loading it again.

I was under the impression that this mod only tracked the energy resource being consumed and produced, but if it tracks any resources then it will conflict with TACLS, but is a lot closer to my suggestion above.

Share this post


Link to post
Share on other sites
So Guys I've throwed this idea on the TACLS, basically its a proposition to make an API engine for background resource management with some life support support on it.

I've heard from TaranisElsu that he might be working on that but didn't quite understand if he liked it or what he wants to do.

Either way, this is very relevant to the idea of this mod specifically, so I thought to throw it in here too if anyone wants to.

By the way, jamespicone,the way you've described means TACLS will conflict with background processing, TAC tracks the resource usage for unloaded vessels and then apply the differences when loading it again.

I was under the impression that this mod only tracked the energy resource being consumed and produced, but if it tracks any resources then it will conflict with TACLS, but is a lot closer to my suggestion above.

After a more in-depth look, it looks like TAC LS does consume electricity over time in the background, and it's possible it does it on modules that Background Processing tracks usage for. So in conclusion, *probably* this interacts with TAC LS in such a way that command modules have doubled electricity consumption in the background, with one set of consumption delivered in one hit when the vessel is loaded.

This mod can track any resource, ultimately, but it's currently only setup to do electricity. Other mods using it can ask it to track other resources though - TaranisElsu could use BP to implement more direct background consumption of water/food/air/electricity as well as background generation of water/food/air/electricity.

Basic takeaway - what you're suggesting to TaranisElsu on the TAC LS thread is what this mod already does.

Share this post


Link to post
Share on other sites
After a more in-depth look, it looks like TAC LS does consume electricity over time in the background, and it's possible it does it on modules that Background Processing tracks usage for. So in conclusion, *probably* this interacts with TAC LS in such a way that command modules have doubled electricity consumption in the background, with one set of consumption delivered in one hit when the vessel is loaded.

I tested it yesterday and in my setup, the ressources added by TAC are consumed in background, while electricity is not.

Share this post


Link to post
Share on other sites

@jamespicone

Actually not, that's very good news that Background Processing is set in a way it can track any other resource. However it doesn't quite do what I suggested, which is adding the resource and consumption and production to kerbals themselves, as in a life-support system. All the while being being fully modular so others can tweak to their heart's desires. TACLS does the life-support bit, still not modular yet, but Taranis mentioned he wants to changes this.

@Voidi

That's because kerbals will consume a lot of power, but the mod doesn't actually track the resource generation (ie solar panels), there-for tracking power in the background was beyond its scope. Which technically means both could work together, but BP wouldn't keep track of what kerbals are consuming in power.

Either way, seems that this mod hasn't been update in a while, have the OP or someone mentioned about a planned update or future development?

Share this post


Link to post
Share on other sites
Actually not, that's very good news that Background Processing is set in a way it can track any other resource. However it doesn't quite do what I suggested, which is adding the resource and consumption and production to kerbals themselves, as in a life-support system. All the while being being fully modular so others can tweak to their heart's desires. TACLS does the life-support bit, still not modular yet, but Taranis mentioned he wants to changes this.

BP has hooks any mod can get into, without necessarily requiring BP is present. That is, TAC LS could be written so that if BP is present it's used, and if it isn't nothing happens, and TaranisElsu can just distribute the same file either way.

I don't currently perform processing for EVA kerbals though, so there's that.

Either way, seems that this mod hasn't been update in a while, have the OP or someone mentioned about a planned update or future development?

I should probably publish what's currently in the repository - if you're comfortable building from source what's currently in the repo improves solar panel behaviour in 1.0.

Share this post


Link to post
Share on other sites

At this time, i'm using the btsm version of your library (because it work). I didn't success to build a stable version two week ago from your repo.

I'm waiting a proper release cheerfully

And to make background processing working with eva kerbal, you need to add your partmodule(s) to the partPrefab from the partinfo with name "kerbalEVA".

As it's a part created at runtime, it must be add to it also at runtime.

Share this post


Link to post
Share on other sites

I've published an update for 1.02. I'd consider this one somewhat beta - I'm not sure if there are horrible problems I'm unaware of. Solar cells should behave much more accurately in this version, also there's a config file which allows setting which factors affect solar panel output and a fix for locked tanks draining (So BSTM's changed version is now out of date and unnecessary).

Fuel cells and ISRUs still won't work in the background, and I'm not certain what to do about them. Neither will resource extraction stuff.

Share this post


Link to post
Share on other sites

@jamespicone

Thats pretty good news, though I will not dare to install it into my current career game, as with RemoteTech installed I have some probes in orbit for communication which wouldn't last minutes with the power consumption of antennas and barely any generation with the radial smallish panels.

Anyway, would you consider in making a specific Life support mod, modular with what I've suggested in the TACLS thread, that works as well with this mod? ( I'm inquiring this because it isn't quite the scope for TACLS)

Share this post


Link to post
Share on other sites

Will this work with aircraft in flight?

IE: I put an aircraft in the air and use Pilot Assistant or MechJeb to set a heading and maintain an altitude. Will this allow me to switch away from the craft and do other things while it keeps flying?

Share this post


Link to post
Share on other sites
Will this work with aircraft in flight?

IE: I put an aircraft in the air and use Pilot Assistant or MechJeb to set a heading and maintain an altitude. Will this allow me to switch away from the craft and do other things while it keeps flying?

Short answer: no.

Long answer: This almost exclusively handles resource generation/consumption, not physics. If the game won't let you leave a vessel (because it's under power) this won't help.

Share this post


Link to post
Share on other sites

How much of a performance hit should you expect to get from using this mod if you have a decent sized satellite network or similar?

Share this post


Link to post
Share on other sites
How much of a performance hit should you expect to get from using this mod if you have a decent sized satellite network or similar?

I honestly don't know, and it would depend on how large 'decent' is and how many relevant partmodules are on it. I can say that I've never seen anyone complain about performance impacts. Try it yourself maybe?

Share this post


Link to post
Share on other sites

@jamespicone

Let me better elaborate on the proposition, and with that I also need a better understanding on how BP currently works.

How does resource tracking currently works? Does it just calculate average on consumption/production and then applies once the vessel is loaded again (like most life-support mods do) or does it continuously track whats happening on the vessel and applies the resource gains/losses?

Mods can instruct BackgroundProcessing that particular PartModule classes should be considered to produce or consume some resource at a given rate. They can also have BackgroundProcessing handle ModuleGenerator/ModuleDeployableSolarPanel/ModuleCommand that produces/consumes resources other than ElectricCharge. Finally, their background handling code can consume or produce any resource they please.

I'm trying to get better grasp on what it actually do, from the quote above I can understand it tracks several things like distance, position, shadow, for solar panels (which is quite something).

And it also gives to understand it can generally work with any other resource modders choose to. Though whats exactly is the problem with extraction/conversion?

Now to what I'm proposing, which may or may not be beyond the scope of the mod, or something you to do.

To also track requirements of resource production/consumption based off on kerbals, dynamically provided by a configuration file, such as:


Config file (database readable)
what kerbals consume
- resource1
- resource2
what kerbals produce
....

Technically is only to track those resources base off kerbals on unloaded vessels, seem like an easy enough task, as they technically wouldn't change by any other parameter like position, sun and stuff.

I'm only asking because I can't do it, I understand basic logic but null of actually programming. And of course I'd understand if that's not something you want to take on.

Cheers

Share this post


Link to post
Share on other sites
@jamespicone

Let me better elaborate on the proposition, and with that I also need a better understanding on how BP currently works.

How does resource tracking currently works? Does it just calculate average on consumption/production and then applies once the vessel is loaded again (like most life-support mods do) or does it continuously track whats happening on the vessel and applies the resource gains/losses?

Mods can instruct BackgroundProcessing that particular PartModule classes should be considered to produce or consume some resource at a given rate. They can also have BackgroundProcessing handle ModuleGenerator/ModuleDeployableSolarPanel/ModuleCommand that produces/consumes resources other than ElectricCharge. Finally, their background handling code can consume or produce any resource they please.

I'm trying to get better grasp on what it actually do, from the quote above I can understand it tracks several things like distance, position, shadow, for solar panels (which is quite something).

And it also gives to understand it can generally work with any other resource modders choose to. Though whats exactly is the problem with extraction/conversion?

Now to what I'm proposing, which may or may not be beyond the scope of the mod, or something you to do.

To also track requirements of resource production/consumption based off on kerbals, dynamically provided by a configuration file, such as:


Config file (database readable)
what kerbals consume
- resource1
- resource2
what kerbals produce
....

Technically is only to track those resources base off kerbals on unloaded vessels, seem like an easy enough task, as they technically wouldn't change by any other parameter like position, sun and stuff.

I'm only asking because I can't do it, I understand basic logic but null of actually programming. And of course I'd understand if that's not something you want to take on.

Cheers

How It Works:

At intervals (FixedUpdate to be precise - usually fractions of a second) BP scans all vessels. If it runs into a vessel that is a) unloaded and B) not currently known to it, it inspects the persistence information for that vessel - the ProtoVessel - to determine what Parts are in it, and what PartModules are in those parts. If those PartModules are ModuleDeployableSolarPanel (the module used for solar panels), ModuleGenerator (the module used for RTGs) or ModuleCommand (the module used for probe cores and command pods) that produce a resource BP has been instructed to care about (only ElectricCharge, by default), then it grabs a bunch of information from the module - the rate resource is generated/consumed, thermal efficiency curves, that kind of thing - and stores it. Finally, for every unloaded vessel that is present and known to BP, it adds/subtracts the amount of resources required by all the PartModules in the vessel that I've found in the current situation (so taking into account distance from sun, atmosphere, temperature, and shadowing for solar panels, for example).

Other mods can set themselves up so that BP calls a function for their PartModules if they're in unloaded vessels, and they can register a resource with BP so that if a ModuleGenerator produces it, BP will track it.

The problem with extraction/conversion is partially that I haven't looked into it yet, but also partially that LiquidFuel and Oxidiser are STAGE_PRIORITY resources that can only flow through certain kinds of connection, and I haven't written the code to emulate that behaviour yet (and I'm not sure it's sufficiently doable to do - I don't know how accessible part connection information is in unloaded vessels). I'm currently considering implementing handling for LiquidFuel and Oxidiser and just treating them the same as ElectricCharge - resources that just travel ship-wide without limitations - and providing a config file switch to turn off that behaviour if people understandably don't like it. Consider the way an engine can't consume fuel from a fuel tank it doesn't have a fuel line / connection to.

It would be moderately easy to have kerbals produce or consume resources in unloaded ModuleCommand parts, probably. I'm not sure how easy determining how many Kerbals are in a ModuleCommand is, and EVA handling isn't quite a thing BP does, but those are probably solvable. The bigger problem is that I don't want to implement full-blown life-support mechanics - kerbals dying when they run out of oxygen and the like - especially given that there are already perfectly good mods for handling this out there, like TAC LS. Resource flow is also a concern, given that oxygen should probably be treated like fuel - only flows between parts specifically attached for it.

If there's a way forward here, it's probably either me or TaranisElsu implementing BP support in TAC LS. TaranisElsu is aware of this mod, I'm pretty sure. I think I've briefly talked to him about it in IRC. I don't know what his opinion of my codebase or its utility is - I've briefly looked at TAC LS, and I don't think it'd be too hard to implement BP support, but I might be completely misunderstanding how he's implementing things. *shrug*. It's something I'll think about and I might talk to TaranisElsu about it, but no promises.

Share this post


Link to post
Share on other sites

It would be moderately easy to have kerbals produce or consume resources in unloaded ModuleCommand parts, probably. I'm not sure how easy determining how many Kerbals are in a ModuleCommand is, and EVA handling isn't quite a thing BP does, but those are probably solvable. The bigger problem is that I don't want to implement full-blown life-support mechanics - kerbals dying when they run out of oxygen and the like - especially given that there are already perfectly good mods for handling this out there, like TAC LS. Resource flow is also a concern, given that oxygen should probably be treated like fuel - only flows between parts specifically attached for it.

My fork of snacks! (wip, but working), working with backgroundProcessing :

github

the useful class is "SnackConsumer"

It kills kerbals in background. But before that happen, it display a warning message and stop the timewarp, to let a chance to enable a container, or other things.

It works with vessels and eva kerbals.

Share this post


Link to post
Share on other sites

@jamespicone

Just to clarify, it wasn't explicitly answered but I can infer that the resource variation is being calculated and applied continuously, correct?

I think you still misunderstand what I'm proposing, my aim was to enable kerbals as resource consumer entities, just like a command pod or solar panel, and then keep track of them.

And further more allowing full modular configuration, which resources are consumed/produced at which rate. But not a full blown life-support mod with parts and etc. Just the bare bones of functionality.

Why? By providing the functionality, it allows other mods to use a life-support tweaking to their liking, for example, it could be used both for full feature TACLS like, with several resources, or on a simplistic alternative, like the USILS or IFLS, even with BTSM.

Maybe it is beyond the scope of what Background Processing is, but it could be a complementary mod to serve together.

@Merill

And as a nice counter example, unlike snacks which does consumption based on meals instead of constant rate. Which by the way, I'm curious to how the meal based consumption worked with BP.

Share this post


Link to post
Share on other sites
@jamespicone

Just to clarify, it wasn't explicitly answered but I can infer that the resource variation is being calculated and applied continuously, correct?

I think you still misunderstand what I'm proposing, my aim was to enable kerbals as resource consumer entities, just like a command pod or solar panel, and then keep track of them.

And further more allowing full modular configuration, which resources are consumed/produced at which rate. But not a full blown life-support mod with parts and etc. Just the bare bones of functionality.

Why? By providing the functionality, it allows other mods to use a life-support tweaking to their liking, for example, it could be used both for full feature TACLS like, with several resources, or on a simplistic alternative, like the USILS or IFLS, even with BTSM.

Maybe it is beyond the scope of what Background Processing is, but it could be a complementary mod to serve together.

@Merill

And as a nice counter example, unlike snacks which does consumption based on meals instead of constant rate. Which by the way, I'm curious to how the meal based consumption worked with BP.

Yes, variation is calculated and applied continuously - if you leave a vessel in the shadow of a planet, when it's out of shadow it'll start receiving power.

"Just make Kerbals consume/produce resources" isn't an atomic action - looking into it briefly it looks like vessels have a list of crew attached to them, so I can just loop over that list and consume resources for each one, maybe. I'm not sure how EVA kerbals are handled. I don't know under what circumstances KSP will do something stupid with that list that makes it look like there's more or less crew than there should be - what happens when you go IVA for example? I don't think it's hard, as such, or even particularly tricky, just sufficiently annoying and out-of-scope that I don't want to do it. :P.

So far I've managed to make BP usable by other mods without them having an explicit reference to my assembly anywhere in their code - they can support it, and if it's there they get processing in the background, and if it's not you don't. Building life support in directly with some plugin-setup might compromise that, but I'll think about it.

Snacks doesn't appear to be using Background Processing the mod, although it does look like they're trying to do processing in the background for snacks.

Share this post


Link to post
Share on other sites

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.