Skip to content

Commit

Permalink
Potential fix for the Gimbal/CoM problem
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbian committed Jul 2, 2015
1 parent f983e7e commit 6cdaa6a
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 66 deletions.
54 changes: 54 additions & 0 deletions MFIManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace ModularFlightIntegrator
{

[KSPAddon(KSPAddon.Startup.EveryScene, false)]
public class MFIManager: MonoBehaviour
{
private void Start()
{
string msg = "MFIManager Start " + HighLogic.LoadedScene + ". Current modules coVesselModule : \n";

foreach (var vesselModuleWrapper in VesselModuleManager.GetModules(false, false))
{
msg += " " + vesselModuleWrapper.type.ToString() + " active=" + vesselModuleWrapper.active + " order=" + vesselModuleWrapper.order + "\n";
}
print(msg);

VesselModuleManager.RemoveModuleOfType(typeof(FlightIntegrator));
//VesselModuleManager.SetWrapperActive(typeof(ModularFI.ModularFlightIntegrator), false);
//VesselModuleManager.SetWrapperActive(typeof(FlightIntegrator), false);

msg = "MFIManager Start Post RemoveModuleOfType. Current modules coVesselModule : \n";
foreach (var vesselModuleWrapper in VesselModuleManager.GetModules(false, false))
{
msg += " " + vesselModuleWrapper.type.ToString() + " active=" + vesselModuleWrapper.active + " order=" + vesselModuleWrapper.order + "\n";
}
print(msg);


// TODO : clear the event ?
GameEvents.onVesselLoaded.Add(OnVesselLoad);
}

private void OnVesselLoad(Vessel v)
{
print("OnVesselLoad");
VesselModuleManager.RemoveModulesFromVessel(v);
VesselModuleManager.AddModulesToVessel(v);

string msg = "OnVesselLoad. Vessel Component : \n";
foreach (var c in v.gameObject.GetComponents(typeof(Component)))
{
msg += " " + c.GetType() + "\n";
}
print(msg);
}

}
}
155 changes: 90 additions & 65 deletions ModularFlightIntegrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,16 @@ public bool WasMachConvectionEnabled
// Awake fire when getting to the Flight Scene, not sooner
protected void Awake()
{

string msg = "Awake. Current modules coVesselModule : \n";
VesselModuleManager.RemoveModuleOfType(typeof(FlightIntegrator));

foreach (var vesselModuleWrapper in VesselModuleManager.GetModules(false, false))
{
msg += " " + vesselModuleWrapper.type.ToString() + " active=" + vesselModuleWrapper.active + " order=" + vesselModuleWrapper.order + "\n";
}
print(msg);

//VesselModuleManager.RemoveModuleOfType(typeof(FlightIntegrator));
msg = "Awake Post Remove. Current modules coVesselModule : \n";
foreach (var vesselModuleWrapper in VesselModuleManager.GetModules(false, false))
{
msg += " " + vesselModuleWrapper.type.ToString() + " active=" + vesselModuleWrapper.active + " order=" + vesselModuleWrapper.order + "\n";
Expand All @@ -145,68 +152,86 @@ protected override void Start()
{
base.Start();
string msg;
if (!started)
{
msg = "Initial start; FlightIntegrator cleanup: \n";
if (vessel)
{
FlightIntegrator[] integrators = vessel.GetComponents<FlightIntegrator>();
for (int i = 0; i < integrators.Length; i++)
{
FlightIntegrator fi = integrators[i];
if (fi == null)
continue;
msg += " " + fi.GetType().ToString() + "\n";
if (fi != this)
GameObject.Destroy(fi);
}
}
print(msg);
started = true;
}


msg = "Start. Current modules coVesselModule : \n";
foreach (var vesselModuleWrapper in VesselModuleManager.GetModules(false, false))
{
msg += " " + vesselModuleWrapper.type.ToString() + " active=" + vesselModuleWrapper.active + " order=" + vesselModuleWrapper.order + "\n";
}
print(msg);

//if (!started)
//{
// msg = "Initial start; FlightIntegrator cleanup: \n";
// if (vessel)
// {
// FlightIntegrator[] integrators = vessel.GetComponents<FlightIntegrator>();
// for (int i = 0; i < integrators.Length; i++)
// {
// FlightIntegrator fi = integrators[i];
// if (fi == null)
// continue;
// msg += " " + fi.GetType().ToString() + "\n";
// if (fi != this)
// {
// msg += "Destroying " + fi.GetType() + "\n";
// Destroy(fi);
// }
// }
// }
// print(msg);
// started = true;
//}
//msg = "Start Post Destroy. Current modules coVesselModule : \n";
//foreach (var vesselModuleWrapper in VesselModuleManager.GetModules(false, false))
//{
// msg += " " + vesselModuleWrapper.type.ToString() + " active=" + vesselModuleWrapper.active + " order=" + vesselModuleWrapper.order + "\n";
//}
//print(msg);


msg = "Start. Vessel Component : \n";
foreach (var c in vessel.gameObject.GetComponents(typeof(Component)))
{
msg += " " + c.GetType() + "\n";
}
print(msg);
}

protected override void OnDestroy()
{
//print("OnDestroy");
base.OnDestroy();
}

protected override void HookVesselEvents()
{
//print("HookVesselEvents");
base.HookVesselEvents();
}

protected override void UnhookVesselEvents()
{
//print("UnhookVesselEvents");
base.UnhookVesselEvents();
}

//protected override void OnDestroy()
//{
// //print("OnDestroy");
// base.OnDestroy();
//}
//
//protected override void HookVesselEvents()
//{
// //print("HookVesselEvents");
// base.HookVesselEvents();
//}
//
//protected override void UnhookVesselEvents()
//{
// //print("UnhookVesselEvents");
// base.UnhookVesselEvents();
//}
//
protected override void FixedUpdate()
{
// print("FixedUpdate");

// Update vessel values

// UpdateThermodynamics

// Copy values to part

// UpdateOcclusion

// Integrate Root part

// IntegratePhysicalObjects

base.FixedUpdate();
}

Expand Down Expand Up @@ -628,25 +653,25 @@ public void BaseFIUpdateRadiation(PartThermalData ptd)
base.UpdateRadiation(ptd);
}

protected override double CalculateDragValue_Spherical(Part part)
{
return base.CalculateDragValue_Spherical(part);
}

protected override double CalculateDragValue_Cylindrical(Part part)
{
return base.CalculateDragValue_Cylindrical(part);
}

protected override double CalculateDragValue_Conic(Part part)
{
return base.CalculateDragValue_Conic(part);
}

protected override double CalculateDragValue_Cube(Part part)
{
return base.CalculateDragValue_Cube(part);
}
//protected override double CalculateDragValue_Spherical(Part part)
//{
// return base.CalculateDragValue_Spherical(part);
//}
//
//protected override double CalculateDragValue_Cylindrical(Part part)
//{
// return base.CalculateDragValue_Cylindrical(part);
//}
//
//protected override double CalculateDragValue_Conic(Part part)
//{
// return base.CalculateDragValue_Conic(part);
//}
//
//protected override double CalculateDragValue_Cube(Part part)
//{
// return base.CalculateDragValue_Cube(part);
//}

private static doublePartDelegate calculateAerodynamicAreaOverride;

Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]


Expand Down

0 comments on commit 6cdaa6a

Please sign in to comment.