Skip to content

Commit

Permalink
1.28.1 hotfix for issue #146
Browse files Browse the repository at this point in the history
  • Loading branch information
gotmachine committed May 10, 2023
1 parent e0070b3 commit 1ff0ac1
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 110 deletions.
2 changes: 1 addition & 1 deletion GameData/KSPCommunityFixes/KSPCommunityFixes.version
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"NAME": "KSPCommunityFixes",
"URL": "https://raw.githubusercontent.com/KSPModdingLibs/KSPCommunityFixes/master/GameData/KSPCommunityFixes/KSPCommunityFixes.version",
"DOWNLOAD": "https://github.com/KSPModdingLibs/KSPCommunityFixes/releases",
"VERSION": {"MAJOR": 1, "MINOR": 28, "PATCH": 0, "BUILD": 0},
"VERSION": {"MAJOR": 1, "MINOR": 28, "PATCH": 1, "BUILD": 0},
"KSP_VERSION": {"MAJOR": 1, "MINOR": 12, "PATCH": 5},
"KSP_VERSION_MIN": {"MAJOR": 1, "MINOR": 8, "PATCH": 0},
"KSP_VERSION_MAX": {"MAJOR": 1, "MINOR": 12, "PATCH": 5}
Expand Down
6 changes: 3 additions & 3 deletions KSPCommunityFixes/BugFixes/RoboticsDrift.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private static bool BaseServo_RecurseCoordUpdate_Prefix(BaseServo __instance, Pa

if (!servoInfos.TryGetValue(p, out ServoInfo servoInfo))
{
Debug.LogWarning($"[RoboticsDrift] Servo info not found for {__instance.GetType()} on {p}, drift correction won't be applied !");
Debug.LogWarning($"[RoboticsDrift] Servo info not found for {__instance.AssemblyQualifiedName()} on {p}, drift correction won't be applied !");
return true;
}

Expand Down Expand Up @@ -195,7 +195,7 @@ private static void BaseServo_ModifyLocked_Prefix(BaseServo __instance)
{
if (!servoInfos.TryGetValue(__instance.part, out ServoInfo servoInfo))
{
Debug.LogWarning($"[RoboticsDrift] Servo info not found for {__instance.GetType()} on {__instance.part}, drift correction won't be applied !");
Debug.LogWarning($"[RoboticsDrift] Servo info not found for {__instance.AssemblyQualifiedName()} on {__instance.part}, drift correction won't be applied !");
return;
}

Expand All @@ -210,7 +210,7 @@ private static void BaseServo_OnPartPack_Prefix(BaseServo __instance)
{
if (!servoInfos.TryGetValue(__instance.part, out ServoInfo servoInfo))
{
Debug.LogWarning($"[RoboticsDrift] Servo info not found for {__instance.GetType()} on {__instance.part}, drift correction won't be applied !");
Debug.LogWarning($"[RoboticsDrift] Servo info not found for {__instance.AssemblyQualifiedName()} on {__instance.part}, drift correction won't be applied !");
return;
}

Expand Down
1 change: 1 addition & 0 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<Compile Include="Library\Collections\Deque.cs" />
<Compile Include="Library\Extensions.cs" />
<Compile Include="Library\LocalizationUtils.cs" />
<Compile Include="Library\ObjectPool.cs" />
<Compile Include="Modding\ModUpgradePipeline.cs" />
<Compile Include="Performance\AsteroidAndCometDrillCache.cs" />
<Compile Include="BugFixes\DoubleCurvePreserveTangents.cs" />
Expand Down
9 changes: 9 additions & 0 deletions KSPCommunityFixes/Library/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,14 @@ public static Vector3 MultiplyVector(this Matrix4x4 m, float x, float y, float z
m.m10 * x + m.m11 * y + m.m12 * z,
m.m20 * x + m.m21 * y + m.m22 * z);
}

/// <summary>
/// Get an assembly qualified type name in the "assemblyName:typeName" format
/// </summary>
public static string AssemblyQualifiedName(this object obj)
{
Type type = obj.GetType();
return $"{type.Assembly.GetName().Name}:{type.Name}";
}
}
}
78 changes: 78 additions & 0 deletions KSPCommunityFixes/Library/ObjectPool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace KSPCommunityFixes.Library
{
internal class SimpleObjectPool<T> where T : class, new()
{
private readonly Stack<T> _stack = new Stack<T>();

public T Get()
{
if (!_stack.TryPop(out T pooledObject))
pooledObject = new T();

return pooledObject;
}

public void Release(T pooledObject)
{
_stack.Push(pooledObject);
}
}

internal class ListPool<T>
{
private readonly Stack<List<T>> _stack = new Stack<List<T>>();

public List<T> Get()
{
if (!_stack.TryPop(out List<T> pooledList))
pooledList = new List<T>();

return pooledList;
}

public void Release(List<T> pooledList)
{
pooledList.Clear();
_stack.Push(pooledList);
}
}

internal class ObjectPool<T> where T : class, new()
{
private readonly Stack<T> _stack = new Stack<T>();
private readonly Action<T> _onInstantiate;
private readonly Action<T> _onRelease;

public ObjectPool(Action<T> onInstantiate = null, Action<T> onRelease = null)
{
_onInstantiate = onInstantiate;
_onRelease = onRelease;
}

public T Get()
{
if (!_stack.TryPop(out T pooledObject))
{
pooledObject = new T();
_onInstantiate?.Invoke(pooledObject);
}

return pooledObject;
}

public void Release(T pooledObject)
{
_onRelease?.Invoke(pooledObject);
_stack.Push(pooledObject);
}
}


}
4 changes: 2 additions & 2 deletions KSPCommunityFixes/Modding/PersistentIConfigNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public bool Read(Value value, object host, int attribIndex)
{
if (attribIndex >= attribs.Length)
{
Debug.LogError($"[KSPCommunityFixes] Tried to read value `{value.name} = {value.value}` for field {fieldInfo.Name}, index was {attribIndex} but only {attribs.Length} [Persistent] attributes on that field on host object of type {host.GetType().Name}."
Debug.LogError($"[KSPCommunityFixes] Tried to read value `{value.name} = {value.value}` for field {fieldInfo.Name}, index was {attribIndex} but only {attribs.Length} [Persistent] attributes on that field on host object of type {host.AssemblyQualifiedName()}."
+ "\nThis is probably because the value was specified twice in the config. Making that assumption and clamping.");
attribIndex = 0;
}
Expand Down Expand Up @@ -264,7 +264,7 @@ public bool Read(ConfigNode node, object host, int attribIndex)
{
if (attribIndex >= attribs.Length)
{
Debug.LogError($"[KSPCommunityFixes] Tried to read node `{node.name}` for field {fieldInfo.Name}, index was {attribIndex} but only {attribs.Length} [Persistent] attributes on that field on host object of type {host.GetType().Name}."
Debug.LogError($"[KSPCommunityFixes] Tried to read node `{node.name}` for field {fieldInfo.Name}, index was {attribIndex} but only {attribs.Length} [Persistent] attributes on that field on host object of type {host.AssemblyQualifiedName()}."
+ "\nThis is probably because the node was specified twice in the config. Making that assumption and clamping.");
attribIndex = 0;
}
Expand Down
Loading

0 comments on commit 1ff0ac1

Please sign in to comment.