Skip to content

Commit

Permalink
v3.8.2 test version
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Sep 10, 2023
1 parent 41b6de5 commit 93ff802
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
Binary file modified 1.4/Assemblies/AchtungMod.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</li>
</modDependencies>
<packageId>brrainz.achtung</packageId>
<modVersion>3.8.1.0</modVersion>
<modVersion>3.8.2.0</modVersion>
<steamAppId>730936602</steamAppId>
<url>https://github.com/pardeike/Achtung2</url>
<description>Command your colonists like a boss!
Expand Down
2 changes: 1 addition & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>net.pardeike.rimworld.mod.achtung</identifier>
<version>3.8.1.0</version>
<version>3.8.2.0</version>
<targetVersions>
<li>1.0.0</li>
<li>1.1.0</li>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ModName>Achtung</ModName>
<ModFileName>Achtung</ModFileName>
<Repository>https://github.com/pardeike/Achtung2</Repository>
<ModVersion>3.8.1.0</ModVersion>
<ModVersion>3.8.2.0</ModVersion>
<ProjectGuid>{8BD5A28F-96C4-43B4-907F-600AA0162F84}</ProjectGuid>
</PropertyGroup>

Expand Down
49 changes: 35 additions & 14 deletions Source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,42 @@ public override void DoSettingsWindowContents(Rect inRect)
public override string SettingsCategory() => "Achtung!";
}

[HarmonyPatch(typeof(CameraDriver))]
[HarmonyPatch(nameof(CameraDriver.Update))]
static class Root_Play_Update_Patch
{
public static bool isDragging = false;

public static void Prefix(Vector3 ___rootPos, out Vector3 __state)
{
__state = ___rootPos;
}

public static void Postfix(Vector3 ___rootPos, Vector3 __state)
{
isDragging = ___rootPos != __state;
}
}

[HarmonyPatch(typeof(Game))]
[HarmonyPatch(nameof(Game.UpdatePlay))]
static class Game_UpdatePlay_Patch
{
static float deadline;
const float maxFrameTime = 1.0f / 60;
static int counter = 0;
static readonly IEnumerator it = Looper();
const float maxDeltaTime = 0.03f;
const int iterations = 5000;

static IEnumerator Looper()
{
while (true)
{
var jobs = ForcedWork.Instance.PrimaryForcedJobs();
var n = jobs.Length;
if (n > 0)
foreach (var job in jobs)
{
var job = jobs[++counter % n];
var map = job?.pawn?.Map;
IEnumerator it;
if (map != null)
{
it = job.ExpandThingTargets(map);
var it = job.ExpandThingTargets(map);
while (it.MoveNext())
yield return null;

Expand All @@ -100,18 +113,26 @@ static IEnumerator Looper()
else
yield return null;
}
else
if (jobs.Length == 0)
yield return null;
}
}

public static void Prefix() => deadline = Time.realtimeSinceStartup + maxFrameTime;

public static void Postfix()
{
if (Current.ProgramState == ProgramState.Playing)
while (Time.realtimeSinceStartup < deadline)
it.MoveNext();
if (Current.ProgramState != ProgramState.Playing)
return;
var camera = Find.CameraDriver;
if (Root_Play_Update_Patch.isDragging)
return;
var s1 = (int)(camera.rootSize * 1000);
var s2 = (int)(camera.desiredSize * 1000);
if (s1 != s2)
return;

var n = (maxDeltaTime - Time.deltaTime) * iterations;
for (var i = 0; i < n; i++)
it.MoveNext();
}
}

Expand Down

0 comments on commit 93ff802

Please sign in to comment.