Jump to content

[WIP] Kerbal Joint Reinforcement - Next


Rudolf Meier

Recommended Posts

Kerbal Joint Reinforcement - Next

Finally a new version of Kerbal Joint Reinforcement is available. It is not just an update to the classic Kerbal Joint Reinforcement or a continuation. The code has been rewritten in major parts.

The Main Goals Were

for users

  • Make the joints realistically stable. Not too strong, not too weak. So that the main character of the game is unchanged. (it tries only to fix what is not correct and not to over-correct something)
  • Offer extra modes for stronger and extra strong joints. (those are as strong as in other KJR versions, but not so realistic anymore)
  • Provide an options menu inside the default game difficulty settings to select the desired joint strength and if and how many additional joints should be used to reinforce a vessel. (no need to modify config files anymore, you can control everything from the normal settings of the game)
  • To improve the performance over older versions.
  • Eliminate phantom forces. The mod builds the extra joints in a completely new way. Instead of just building a joint and try to keep every part in the place where it is right now, it builds the joints according to the original construction plans of the ship and tries to keep the parts "where the should be". (this stops parts from drifting away)
  • Additionally there is a version with a gui which can make all joints visible. This helps in finding problems with either the ship construction or a variety of bugs (like the undocking bug, some procedural fairing anomalies and autostrut problems).

for modders

  • Modders can make their mod compatible with KJRn by simply following the steps described later. KJRn doesn't have to know the mod in advance.
  • In case of problems the version with gui can also be very useful for modding.

 

How To Use It

In contrary to other or older KJR versions, KJR Next is no longer just reinforcing everything as much as possible. Many players have complained, that this is simply cheating and makes even most unrealistic constructions fly. That's why there are now different levels of reinforcement.

You can now select the desired reinforcement level from the menu in the "Game Difficulty" settings.

For realistic joints, it is recommended to select "Reinforce weak attach nodes" and "Strengthen not correctly working joints". Sometimes this is not enough and vessels still start to oscillate anyway. In such cases, select the "Stiffen vessels further" and leave the "Extra Joint Level" at the lowest setting.

If you want stronger joints (at the same level as older KJR versions, but still with improved behavior), you can select stronger "Extra Joint Level" settings. This way you can have the same behavior of KJR Next as before.

Spoiler

options_menu.png

 

How To Get It

this mod is CKAN-Indexed-green.svg (only release versions)

Download: https://github.com/meirumeiru/Kerbal-Joint-Reinforcement/releases

Source: https://github.com/meirumeiru/Kerbal-Joint-Reinforcement

License: GPL-3.0

Kerbal Joint Reinforcement - Next

 

Info For Developers

Spoiler

What To Do

To make your mod compatible with KJRn, you have to do implement IJointLockState.

1) Every part that can move (like e.g. the Infernal Robotics servos) need to implement IJointLockState. The only function to implement is "bool IsJointUnlocked()". Simply return true when your joint can move and false when it cannot.

2) If your joint can change its ability from "locked" to "unlocked" and back, you can simply call GameEvents.onRoboticPartLockChanging.Fire(part, 'bool if locked') and GameEvents.onRoboticPartLockChanged.Fire(part, 'bool if locked') or you can call "KJRManager.CycleAllAutoStrut(vessel)" to inform KJRn that it should rebuild the extra joints/struts (and, depending on your returns, maybe also establish one accross your part). KJRn is only listening to onRoboticPartLockChanging, not to onRoboticPartLockChanged !!

 

If you have a mod/part that is a moving part but you cannot implement IJointLockState in one of its modules, then you can also use the "KJRExcluded" module. Simply add this to the cfg file of your part.

MODULE
{
	name = KJRExcluded
}

 

Code examples

//////////////////////////////
// code for 1.7.2 and later

// before chaning the lock state (KJRn is listening to this event)
GameEvents.onRoboticPartLockChanging.Fire(part, servoIsLocked);

// this is needed for autostrut compatibility
vessel.CycleAllAutoStrut();

// ... modify your lock state here

// after chaning the lock state
GameEvents.onRoboticPartLockChanged.Fire(part, servoIsLocked);


//////////////////////////////
// code for earlier than 1.7.2 or if you want to call KJRn explicitly

Type KJRManagerType = null;
System.Reflection.MethodInfo KJRManagerCycleAllAutoStrutMethod = null
  
AssemblyLoader.loadedAssemblies.TypeOperation (t => { if(t.FullName == "KerbalJointReinforcement.KJRManager") { KJRManagerType = t; } });

if(KJRManagerType != null)
	KJRManagerCycleAllAutoStrutMethod = KJRManagerType.GetMethod("CycleAllAutoStrut");

if(KJRManagerCycleAllAutoStrutMethod != null)
		KJRManagerCycleAllAutoStrutMethod.Invoke(null, new object[] { vessel });

 

 

Edited by Rudolf Meier
Link to comment
Share on other sites

Could you add the ModuleDockRotate and ModuleNodeRotate exemptions to your config.xml? They both extend ModuleBaseRotate, so if the exemption logic handles extensions you just have to add ModuleBaseRotate.

I know I can file a pull request, but I've been coding all the afternoon... :P

Link to comment
Share on other sites

55 minutes ago, peteletroll said:

Could you add the ModuleDockRotate and ModuleNodeRotate exemptions to your config.xml? They both extend ModuleBaseRotate, so if the exemption logic handles extensions you just have to add ModuleBaseRotate.

I know I can file a pull request, but I've been coding all the afternoon... :P

I will post information about how this has to be done. But there will be no exceptions like those you know from early KJR versions.

Link to comment
Share on other sites

A couple very technical questions:

1) Are extra KJR joints implemented as PartJoint or ConfigurableJoint?

2) In the case of NodeRotate parts, the PartModule that controls the PartJoint motion, and that implements IJointLockState, can be either on the Host or Target part of the PartJoint instance. So, in this vessel structure:

vessel root Part <- PartJoint <- part <- PartJoint <- ... <- target Part <- moving PartJoint <- host Part <- PartJoint <- ...

will both target Part and host Part need a IsJointUnlocked() that returns true, or one of them is enough, and which one?

... I hope I made myself clear...

... more questions...

3) Does KerbalJointReinforcement.KJRManager.CycleAllAutoStrut() call stock Vessel.CycleAllAutoStrut(), or do I have to call it myself right before, or after?

4) Where and when exactly do I have to call AssemblyLoader.loadedAssemblies.TypeOperation()?

Link to comment
Share on other sites

1 hour ago, peteletroll said:

1) Are extra KJR joints implemented as PartJoint or ConfigurableJoint?

ConfigurableJoint... I think the launch-clamp reinforcement uses FixedJoint at the moment. But in general it's ConfigurableJoint and I think that is what it will be always in the future.

1 hour ago, peteletroll said:

2) In the case of NodeRotate parts, the PartModule that controls the PartJoint motion, and that implements IJointLockState, can be either on the Host or Target part of the PartJoint instance. So, in this vessel structure:

vessel root Part <- PartJoint <- part <- PartJoint <- ... <- target Part <- moving PartJoint <- host Part <- PartJoint <- ...

will both target Part and host Part need a IsJointUnlocked() that returns true, or one of them is enough, and which one?

*um*... depends.

KJRn is doing it correctly and you only need to implement it on the moving Part.

But the autostruts of KSP have a bug (https://bugs.kerbalspaceprogram.com/issues/18356). Sometimes you need to do more to work around it. Or, simply don't use autostruts and use KJRn.

1 hour ago, peteletroll said:

3) Does KerbalJointReinforcement.KJRManager.CycleAllAutoStrut() call stock Vessel.CycleAllAutoStrut(), or do I have to call it myself right before, or after?

No, it does not call it. It doesn't matter if you call it before or after. I think most users won't use KJRn and autostruts together anyway.

1 hour ago, peteletroll said:

4) Where and when exactly do I have to call AssemblyLoader.loadedAssemblies.TypeOperation()?

Whenever you want. You can also do it in an initialization function (e.g. in the OnAwake).

Edited by Rudolf Meier
Link to comment
Share on other sites

May I install/uninstall KJRn whenever I want without affecting my saved games?

8 minutes ago, Rudolf Meier said:

KJRn is doing it correctly and you only need to implement it on the moving Part.

Is the moving part the host Part or the target Part? That is, the part farther from or closer to the root Part?

(sorry for being such a nitpick...)

Edited by peteletroll
Link to comment
Share on other sites

8 minutes ago, peteletroll said:

May I install/uninstall KJRn whenever I want without affecting my saved games?

yes

8 minutes ago, peteletroll said:

Is the moving part the host Part or the target Part? That is, the part farther from or closer to the root Part?

It's the part you are building. So, for Infernal Robotics for example it's the servo itself. If a part moves, then it moves itself. Often the static part of such constructs are just "illusions" ... like meshes that are not moved or are moved in the opposite direction so that the appear to be static.

Link to comment
Share on other sites

1 minute ago, Rudolf Meier said:

It's the part you are building.

OK, there's a basic difference between Infernal Robotics and DockRotate/NodeRotate: DR acts directly on the PartJoints between different parts. So, there's no "moving part", but there's a "moving joint between two parts". If a part's IsJointUnlocked() returns true, what are the KJRn joints that get disabled? 

Link to comment
Share on other sites

5 minutes ago, peteletroll said:

OK, there's a basic difference between Infernal Robotics and DockRotate/NodeRotate: DR acts directly on the PartJoints between different parts. So, there's no "moving part", but there's a "moving joint between two parts". If a part's IsJointUnlocked() returns true, what are the KJRn joints that get disabled? 

KJRn is building additional joints to a part from it's children, but never from it's parent and also not between the parents and the children of such a part.

Link to comment
Share on other sites

There is one concern with upcoming DLC. It would be hard to expect that SQUAD would check for KJRn existance and make a proper function calls before/after moving parts. That would probably need to be hardcoded within KJRn, to detect stock robotic movable parts and handle joints as necesasry.

I would not recommend to re-introduce XML config file for this, it would be clumsy to maintain on the long run as it was the case with original KJR code.

Link to comment
Share on other sites

On ‎5‎/‎7‎/‎2019 at 8:28 PM, Rudolf Meier said:

I'm working on solutions for that already since last year... I will show the first implementation for this soon... :) 

the way these guys messed up the situation really rips my nerves

Edit: "these guys" -> Squad / the makers of KSP // "the situation" -> how KSP works internally

Edited by Rudolf Meier
Link to comment
Share on other sites

6 hours ago, Rudolf Meier said:

the way these guys messed up the situation really rips my nerves

Who?

 

Also a question. Does offsetting parts from there initial attach location affect joint strength? Thanks!

Edited by Svm420
Link to comment
Share on other sites

7 hours ago, Svm420 said:

Who?

Squad :) ... they are loading parts and ships in a way that is super difficult to understand. It seems to be a constant load and reload, compile and recompile ... They are sort of shooting events on a system and try to solve them all "somehow" ... there is no defined order of execution. If something takes longer to load this time, it's done like this, otherwise completely different and in the end we hope that the result ist still correct... that's ... super difficult to follow.

Link to comment
Share on other sites

7 hours ago, Svm420 said:

Also a question. Does offsetting parts from there initial attach location affect joint strength? Thanks!

Short: I don't think so.

Longer: I would say yes... as far as I understand the systems behind it and still remember what I read about it, I would say, that it is affecting it. But only because of the angle between the different joints. ... I guess that this can affect the solver. But just a tiny bit...

... in the end, I guess, until we have measured this, we don't know it. :)

And... measuring... I'm working on that, so that we get more data.

Link to comment
Share on other sites

18 minutes ago, Rudolf Meier said:

And... measuring... I'm working on that, so that we get more data.

Speaking of data ... Does latest release include KJR autostrut visualisation, if so, how to enable it ? Stock debug menu only shows stock autostruts.
Haven't encountered any issues yet, though not being playing much either.

Link to comment
Share on other sites

30 minutes ago, kcs123 said:

Speaking of data ... Does latest release include KJR autostrut visualisation, if so, how to enable it ? Stock debug menu only shows stock autostruts.
Haven't encountered any issues yet, though not being playing much either.

Yes, it does...

First you can only see the different joints, in a next version I'm planning to colorize the joints according to their instability. Like this it would be (in flight) possible to see which joint was the one that had the biggest deformation.

Edited by Rudolf Meier
Link to comment
Share on other sites

1 hour ago, Rudolf Meier said:

Yes, it does...

First you can only see the different joints, in a next version I'm planning to colorize the joints according to their instability. Like this it would be (in flight) possible to see which joint was the one that had the biggest deformation. 

How to enable visualisation ? Does it require some changes in config file or it is in some hidden menu ?

Link to comment
Share on other sites

Alright, I put in the development build and tested it out.

The stutter happens on all craft. Even with the development build having all options turned off, it still stutters.

If I uninstall KJRn, the stuttering goes away. I'm wondering if it's memory related. I'm not quite full, but 10/12GB of ram being used.

I did see an error when loading a certain craft.

"Vessel SENTINEL was not loaded because it had the following parts missing: KJRAutoStrutHelper"

I've never installed Autostrut, I've got all the options currently disabled.

Which seems to happen upon exiting a vessel, not entering. It loads in the new vessel, but complains about the previous vessel not loading, but it did load.

Edited by Paadwyn
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...