Skip to content

Commit

Permalink
Update Debug Not Included, Fast Track and Decor Reimagined for U44-53…
Browse files Browse the repository at this point in the history
…5211.
  • Loading branch information
peterhaneve committed Dec 10, 2022
1 parent 487a488 commit 563a363
Show file tree
Hide file tree
Showing 17 changed files with 694 additions and 252 deletions.
4 changes: 2 additions & 2 deletions DebugNotIncluded/DebugNotIncluded.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Debug Not Included</AssemblyTitle>
<FileVersion>2.5.0.0</FileVersion>
<FileVersion>2.6.0.0</FileVersion>
<RootNamespace>PeterHan.DebugNotIncluded</RootNamespace>
<Description>Aids with mod debugging and management. Not intended to be a production mod manager.</Description>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<LastWorkingBuild>526233</LastWorkingBuild>
<LastWorkingBuild>534889</LastWorkingBuild>
<Platforms>Vanilla;Mergedown</Platforms>
</PropertyGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion DebugNotIncluded/DebugNotIncludedPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public sealed class DebugNotIncludedPatches : UserMod2 {
[PLibMethod(RunAt.AfterLayerableLoad)]
internal static void AfterModsLoad() {
// Input manager is not set up until this time
KInputHandler.Add(Global.Instance.GetInputManager().GetDefaultController(),
KInputHandler.Add(Global.GetInputManager().GetDefaultController(),
new UISnapshotHandler(), 1024);
}

Expand Down
4 changes: 2 additions & 2 deletions DecorReimagined/DecorReimagined.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Decor Reimagined</AssemblyTitle>
<FileVersion>4.8.0.0</FileVersion>
<FileVersion>4.9.0.0</FileVersion>
<RootNamespace>ReimaginationTeam.DecorRework</RootNamespace>
<Description>Reworks decor, making an attractive colony a better colony.</Description>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<CopyPreview>true</CopyPreview>
<LastWorkingBuild>526233</LastWorkingBuild>
<LastWorkingBuild>534889</LastWorkingBuild>
<Platforms>Vanilla;Mergedown</Platforms>
</PropertyGroup>
<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions DecorReimagined/DecorReimaginedOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ public void ApplyToSculpture(GameObject obj) {
var statuses = Db.Get().ArtableStatuses;
foreach (var stage in Db.GetArtableStages().GetPrefabStages(obj.PrefabID())) {
var artLevel = stage.statusItem;
if (artLevel == statuses.Ugly)
if (artLevel == statuses.LookingUgly)
stage.decor = CrudeArtDecor;
else if (artLevel == statuses.Okay)
else if (artLevel == statuses.LookingOkay)
stage.decor = QuaintArtDecor;
else if (artLevel == statuses.Great)
else if (artLevel == statuses.LookingGreat)
// Good1, Good2, Good3
stage.decor = MasterpieceArtDecor;
else if (artLevel == statuses.Ready)
else if (artLevel == statuses.AwaitingArting)
stage.decor = DefaultArtDecor;
}
}
Expand Down
35 changes: 30 additions & 5 deletions DecorReimagined/DecorReimaginedPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,12 @@ public static class IceSculptureConfig_DoPostConfigureComplete_Patch {
/// Applied after DoPostConfigureComplete runs.
/// </summary>
internal static void Postfix(GameObject go) {
Options?.ApplyToSculpture(go);
try {
Options?.ApplyToSculpture(go);
} catch (MemberAccessException e) {
PUtil.LogWarning("Unable to patch Ice Sculptures:");
PUtil.LogExcWarn(e);
}
}
}

Expand Down Expand Up @@ -362,7 +367,12 @@ public static class MarbleSculptureConfig_DoPostConfigureComplete_Patch {
/// Applied after DoPostConfigureComplete runs.
/// </summary>
internal static void Postfix(GameObject go) {
Options?.ApplyToSculpture(go);
try {
Options?.ApplyToSculpture(go);
} catch (MemberAccessException e) {
PUtil.LogWarning("Unable to patch Marble Sculptures:");
PUtil.LogExcWarn(e);
}
}
}

Expand All @@ -376,7 +386,12 @@ public static class MetalSculptureConfig_DoPostConfigureComplete_Patch {
/// Applied after DoPostConfigureComplete runs.
/// </summary>
internal static void Postfix(GameObject go) {
Options?.ApplyToSculpture(go);
try {
Options?.ApplyToSculpture(go);
} catch (MemberAccessException e) {
PUtil.LogWarning("Unable to patch Metal Sculptures:");
PUtil.LogExcWarn(e);
}
}
}

Expand Down Expand Up @@ -415,7 +430,12 @@ public static class SculptureConfig_DoPostConfigureComplete_Patch {
/// Applied after DoPostConfigureComplete runs.
/// </summary>
internal static void Postfix(GameObject go) {
Options?.ApplyToSculpture(go);
try {
Options?.ApplyToSculpture(go);
} catch (MemberAccessException e) {
PUtil.LogWarning("Unable to patch Large Sculptures:");
PUtil.LogExcWarn(e);
}
}
}

Expand All @@ -429,7 +449,12 @@ public static class SmallSculptureConfig_DoPostConfigureComplete_Patch {
/// Applied after DoPostConfigureComplete runs.
/// </summary>
internal static void Postfix(GameObject go) {
Options?.ApplyToSculpture(go);
try {
Options?.ApplyToSculpture(go);
} catch (MemberAccessException e) {
PUtil.LogWarning("Unable to patch Small Sculptures:");
PUtil.LogExcWarn(e);
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions FastTrack/FastTrack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Fast Track</AssemblyTitle>
<FileVersion>0.9.18.0</FileVersion>
<FileVersion>0.10.0.0</FileVersion>
<RootNamespace>PeterHan.FastTrack</RootNamespace>
<Description>Optimizes Oxygen Not Included to improve performance.</Description>
<AssemblyVersion>0.9.10.0</AssemblyVersion>
<LastWorkingBuild>526233</LastWorkingBuild>
<AssemblyVersion>0.10.0.0</AssemblyVersion>
<LastWorkingBuild>534889</LastWorkingBuild>
<Platforms>Vanilla;Mergedown</Platforms>
<Optimize>true</Optimize>
<UsePublicized>true</UsePublicized>
Expand Down
8 changes: 6 additions & 2 deletions FastTrack/FastTrackMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ internal static void AfterDbInit() {
GamePatches.BackgroundRoomProber.Init();
if (options.ThreatOvercrowding)
CritterPatches.OvercrowdingMonitor_UpdateState_Patch.InitTagBits();
if (options.RadiationOpts)
GamePatches.FastProtonCollider.Init();
if (options.SensorOpts)
SensorPatches.SensorPatches.Init();
if (options.AnimOpts)
Expand Down Expand Up @@ -166,6 +164,8 @@ internal static void OnEndGame() {
GamePatches.SolidTransferArmUpdater.DestroyInstance();
if (options.PickupOpts || options.FastUpdatePickups)
PathPatches.DeferredTriggers.DestroyInstance();
if (options.RadiationOpts)
GamePatches.FastProtonCollider.Cleanup();
if (options.AsyncPathProbe)
PathPatches.PathProbeJobManager.DestroyInstance();
GamePatches.AchievementPatches.DestroyInstance();
Expand Down Expand Up @@ -244,13 +244,17 @@ internal static void OnStartGame() {
PathPatches.PathProbeJobManager.CreateInstance();
if (options.CachePaths)
PathPatches.PathCacher.Init();
if (options.FastReachability)
SensorPatches.FastGroupProber.Init();
if (options.SideScreenOpts) {
UIPatches.AdditionalDetailsPanelWrapper.Init();
UIPatches.DetailsPanelWrapper.Init();
UIPatches.VitalsPanelWrapper.Init();
}
if (options.PickupOpts || options.FastUpdatePickups)
PathPatches.DeferredTriggers.CreateInstance();
if (options.RadiationOpts)
GamePatches.FastProtonCollider.Init();
if (inst != null) {
var go = inst.gameObject;
go.AddOrGet<AsyncJobManager>();
Expand Down
23 changes: 20 additions & 3 deletions FastTrack/GamePatches/ConcurrentHandleVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ namespace PeterHan.FastTrack.GamePatches {
/// A faster and thread safe version of KCompactedVector.
/// </summary>
public sealed class ConcurrentHandleVector<T> : ICollection<T> {
public int Count => lookup.Count;

/// <summary>
/// Allows modification of the base collection.
/// </summary>
public IDictionary<int, T> BackingDictionary => lookup;

public int Count => lookup.Count;

public bool IsReadOnly => false;

public T this[HandleVector<int>.Handle handle] {
Expand Down Expand Up @@ -147,7 +150,21 @@ IEnumerator IEnumerable.GetEnumerator() {
}

public bool Remove(T item) {
throw new NotImplementedException();
bool removed = false;
// This is a best effort method, it may go very poorly
if (item == null) {
// Look for null
foreach (var pair in lookup)
if (pair.Value == null && (removed = lookup.TryRemove(pair.Key, out _)))
break;
} else {
var ec = EqualityComparer<T>.Default;
foreach (var pair in lookup)
if (ec.Equals(item, pair.Value) && (removed = lookup.TryRemove(pair.Key,
out _)))
break;
}
return removed;
}

/// <summary>
Expand Down
95 changes: 51 additions & 44 deletions FastTrack/GamePatches/FastProtonCollider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ namespace PeterHan.FastTrack.GamePatches {
[SkipSaveFileSerialization]
public sealed class FastProtonCollider : KMonoBehaviour {
/// <summary>
/// The tag bits that will prevent collision.
/// The tags that will prevent collision.
/// </summary>
private static TagBits COLLIDE_IGNORE;
private static readonly Tag[] COLLIDE_IGNORE = {
GameTags.Dead, GameTags.Dying
};

/// <summary>
/// The tag bits with which to collide.
/// The tags with which to collide.
/// </summary>
private static TagBits COLLIDE_WITH;
private static readonly Tag[] COLLIDE_WITH = {
GameTags.Creature, GameTags.Minion
};

/// <summary>
/// Could not find a const for this in game...
Expand All @@ -45,27 +49,39 @@ public sealed class FastProtonCollider : KMonoBehaviour {
/// Or this one...
/// </summary>
public const int DISEASE_PER_CELL = 5;

/// <summary>
/// The scene partitioner layer name to use.
/// Cleans up the collision mask layer.
/// </summary>
internal const string RADBOLTS = nameof(HighEnergyParticle);

internal static void Cleanup() {
hepLayer.Dispose();
}

/// <summary>
/// The layer used for colliding ~~beams~~ radbolts.
/// Checks to see if a radbolt is colliding with another object.
/// </summary>
internal static ScenePartitionerLayer hepLayer;
/// <param name="pos">The position of the radbolt.</param>
/// <param name="other">The location of the other object.</param>
/// <returns>true if they are colliding, or false otherwise.</returns>
private static bool CollidesWith(Vector3 pos, Vector3 other) {
Vector2 difference = pos - other;
return difference.sqrMagnitude <= HighEnergyParticleConfig.
PARTICLE_COLLISION_SIZE * HighEnergyParticleConfig.PARTICLE_COLLISION_SIZE;
}

/// <summary>
/// Initializes the tag masks used for collision.
/// Initializes the collision mask layer.
/// </summary>
internal static void Init() {
COLLIDE_WITH.SetTag(GameTags.Creature);
COLLIDE_WITH.SetTag(GameTags.Minion);
COLLIDE_IGNORE.SetTag(GameTags.Dead);
COLLIDE_IGNORE.SetTag(GameTags.Dying);
hepLayer = new ThreadsafePartitionerLayer("Radbolts", Grid.WidthInCells, Grid.
HeightInCells);
}

/// <summary>
/// The layer used for colliding ~~beams~~ radbolts.
/// </summary>
internal static ThreadsafePartitionerLayer hepLayer;

#pragma warning disable IDE0044
#pragma warning disable CS0649
// These fields are automatically populated by KMonoBehaviour
Expand All @@ -87,7 +103,7 @@ internal static void Init() {
/// <summary>
/// The partitioner entry into the radbolt collision layer.
/// </summary>
private HandleVector<int>.Handle partitionerEntry;
private ThreadsafePartitionerEntry partitionerEntry;

/// <summary>
/// The port that could capture this radbolt if it passes close enough.
Expand All @@ -101,7 +117,7 @@ internal static void Init() {

internal FastProtonCollider() {
cachedCell = Grid.InvalidCell;
partitionerEntry = HandleVector<int>.InvalidHandle;
partitionerEntry = null;
port = null;
}

Expand Down Expand Up @@ -158,7 +174,7 @@ private bool CheckLivingCollision(GameObject item) {
// Is it a creature/Duplicant and not already dead?
bool collided = false;
if (item != null && item.TryGetComponent(out KPrefabID prefabID) && prefabID.
HasAnyTags(ref COLLIDE_WITH) && !prefabID.HasAnyTags(ref COLLIDE_IGNORE) &&
HasAnyTags(COLLIDE_WITH) && !prefabID.HasAnyTags(COLLIDE_IGNORE) &&
item.TryGetComponent(out Health hp) && !hp.IsDefeated()) {
collided = true;
hp.Damage(DAMAGE_ON_HIT);
Expand Down Expand Up @@ -198,13 +214,15 @@ private void CheckLivingCollision(int cell) {
/// <param name="pos">The exact position of this radbolt.</param>
/// <returns>Whether the radbolt collided with another radbolt.</returns>
private bool CheckRadboltCollision(int cell, Vector3 pos) {
var hits = ListPool<ScenePartitionerEntry, FastProtonCollider>.Allocate();
var hits = ListPool<ThreadsafePartitionerEntry, FastProtonCollider>.Allocate();
Grid.CellToXY(cell, out int x, out int y);
GameScenePartitioner.Instance.GatherEntries(x - 1, y - 1, 3, 3, hepLayer, hits);
hepLayer.Gather(hits, x - 1, y - 1, 3, 3);
if (hits.Count > 0)
PUtil.LogWarning(hits.Join(","));
int n = hits.Count;
bool collided = false;
for (int i = 0; i < n && !collided; i++)
if (hits[i].obj is HighEnergyParticle otherHEP && otherHEP != null &&
if (hits[i].data is HighEnergyParticle otherHEP && otherHEP != null &&
otherHEP != hep && otherHEP.isCollideable && CollidesWith(pos,
otherHEP.transform.position)) {
hep.payload += otherHEP.payload;
Expand Down Expand Up @@ -234,35 +252,25 @@ private bool CheckSolidTileCollision(int cell) {
return collided;
}

/// <summary>
/// Checks to see if this radbolt is colliding with another object.
/// </summary>
/// <param name="pos">The position of this radbolt.</param>
/// <param name="other">The location of the other object.</param>
/// <returns>true if they are colliding, or false otherwise.</returns>
private bool CollidesWith(Vector3 pos, Vector3 other) {
Vector2 difference = pos - other;
return difference.sqrMagnitude <= HighEnergyParticleConfig.
PARTICLE_COLLISION_SIZE * HighEnergyParticleConfig.PARTICLE_COLLISION_SIZE;
}

/// <summary>
/// Creates the scene partitioner entry for this collider.
/// </summary>
/// <param name="cell">The current cell of this radbolt.</param>
private void CreatePartitioner(int cell) {
var gsp = GameScenePartitioner.Instance;
if (gsp != null && hepLayer != null)
partitionerEntry = gsp.Add(nameof(HighEnergyParticle), hep, cell, hepLayer,
null);
if (hepLayer != null) {
Grid.CellToXY(cell, out int x, out int y);
partitionerEntry = hepLayer.Add(x, y, hep, null);
}
}

/// <summary>
/// Destroys the scene partitioner entry for this collider.
/// </summary>
private void DestroyPartitioner() {
if (partitionerEntry.IsValid())
GameScenePartitioner.Instance.Free(ref partitionerEntry);
if (partitionerEntry != null) {
partitionerEntry.Dispose();
partitionerEntry = null;
}
}

/// <summary>
Expand Down Expand Up @@ -290,11 +298,10 @@ public void MovingUpdate(float dt) {
SimMessages.ModifyDiseaseOnCell(newCell, diseaseIndex,
DISEASE_PER_CELL);
payload -= HighEnergyParticleConfig.PER_CELL_FALLOFF;
if (partitionerEntry.IsValid())
// GSP had to be valid for the entry to exist in the first place
GameScenePartitioner.Instance.UpdatePosition(partitionerEntry,
newCell);
else
if (partitionerEntry != null) {
Grid.CellToXY(cell, out int x, out int y);
partitionerEntry.UpdatePosition(x, y);
} else
CreatePartitioner(newCell);
}
if (payload <= 0.0f)
Expand Down
Loading

0 comments on commit 563a363

Please sign in to comment.