Jump to content

Looking for the root internal part.


Recommended Posts

So I have an InternalModule that, to pool computing resources, wants to find other copies of itself in other props of the same IVA.

I know how to get a list of modules in an IVA prop, so that's done -- but how do I get the complete list of other IVA props?

Link to comment
Share on other sites

Thank you, that worked. :)

One other interesting question, though:

So assume I have multiple IVAs on that vessel, and both have instances of my module. They will, most probably, end up referring to one module's instance of that support class that is the reason for making this mess.

What exactly happens when the vessel separates into two? I imagine two new vessels will be freshly created, the old vessel will be destroyed, and my initialization will run again, but am I correct?

Link to comment
Share on other sites

Haven't used InternalModues yet, but just from looking at the API I think its a simple hierarchy... [Vessel-]Part can have an InternalModel, model can have multiple InternalProps, who themselves have InternalModules. Just like you have a Vessel>Parts>PartModule structure. So i would expect individual instances for each of the parts IVA, and them being transfered to another vessel just like a PartModule... in that case you would have to subscribe to a vessel modification event. Ofc thats just guess-work because of how their classes look and those similarity. Some documentation about it would be awesome... maybe you have the spare time to write down what you will find out?

Link to comment
Share on other sites

If I find out anything. :) Right now, I think I'll just put off the idea of sharing computing resources for later and come back to it in case it becomes a problem.

P.S. I do have an idea though.

Since I missed that Part has an internalModel reference, it's actually not too hard to limit my subclass sharing to a single IVA. I just need to:

  1. Loop through all parts and grab those which have internalModels.
  2. InternalModel has a list of props. Loop through that to get a list of InternalProps.
  3. Loop through those until the module finds itself. Now it knows which InternalModel is relevant and can only share the computing module per-pod.

That should be good enough and will prevent any potential problems on decoupling, since so far, you can't decouple pod furniture. :)

Edited by Mihara
P.S.
Link to comment
Share on other sites

And for the record, this solution seems to work:

Loop through parts of this vessel, find the parts with an internal, find self -- the part we found ourselves in is the part we want to look for neighbours in.


foreach (Part part in vessel.parts) {
Part currentpod = null;
if (part.internalModel != null) {
foreach (InternalProp prop in part.internalModel.props) {
MyInternalModuleClass myself = prop.FindModelComponent<MyInternalModuleClass> ();
if (myself != null && myself == this) {
currentpod = part;
break;
}
}
}
// This should leave us with a reference to the particular pod we're in at some point. From there...
if (currentpod != null) {
foreach (InternalProp prop in currentpod.internalModel.props) {
MyInternalModuleClass other = prop.FindModelComponent<MyInternalModuleClass> ();
if (other != null && other != this) {
//... Do whatever we wanted...
break;
}
}
}
}

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...