Skip to content

Commit

Permalink
3.8.3 RC1
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Sep 17, 2023
1 parent 568c328 commit 5598552
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 67 deletions.
Binary file modified 1.4/Assemblies/AchtungMod.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions Source/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public bool HandleEvents()
if (Achtung.Settings.forceCommandMenuMode == CommandMenuMode.Delayed
&& longPressThreshold > -1
&& Event.current.rawType == EventType.Layout
&& Environment.TickCount > longPressThreshold
&& Tools.EnvTicks() > longPressThreshold
&& suppressMenu == false)
{
longPressThreshold = -1;
Expand All @@ -421,7 +421,7 @@ public bool HandleEvents()
case EventType.MouseDown:
if (Event.current.button == (int)Button.right)
suppressMenu = false;
longPressThreshold = Event.current.button == (int)Button.right ? Environment.TickCount + Achtung.Settings.menuDelay : -1;
longPressThreshold = Event.current.button == (int)Button.right ? Tools.EnvTicks() + Achtung.Settings.menuDelay : -1;
runOriginal = MouseDown(pos, Event.current.button, false);
MouseDrag(pos);
break;
Expand Down
75 changes: 50 additions & 25 deletions Source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,45 @@ public static void Postfix(Vector3 ___rootPos, Vector3 __state)
}
}

[HarmonyPatch(typeof(LetterStack))]
[HarmonyPatch(nameof(LetterStack.LettersOnGUI))]
static class LetterStack_LettersOnGUI_Patch
{
static void Prefix(ref float baseY)
{
if (Prefs.DevMode == false)
return;

const float rowHeight = 26f;
const float spacing = 4f;
var num = (float)UI.screenWidth - 200f;
var rect = new Rect(num, baseY + 10f - rowHeight, 193f - 2 * (spacing + rowHeight), rowHeight);
baseY -= rowHeight;
Text.Anchor = TextAnchor.MiddleRight;
Widgets.Label(rect, $"{Game_UpdatePlay_Patch.fps} (min {Game_UpdatePlay_Patch.minFps}) {Game_UpdatePlay_Patch.iterations}");
rect.xMin = rect.xMax + spacing;
rect.width = rowHeight;
if (Widgets.ButtonText(rect, "+"))
Game_UpdatePlay_Patch.minFps++;
rect.x += rowHeight + spacing;
if (Widgets.ButtonText(rect, "-"))
Game_UpdatePlay_Patch.minFps--;
Text.Anchor = TextAnchor.UpperLeft;
}
}

[HarmonyPatch(typeof(Game))]
[HarmonyPatch(nameof(Game.UpdatePlay))]
static class Game_UpdatePlay_Patch
{
static readonly IEnumerator it = Looper();

// static readonly TimeSlice timeSlicer = new(3f, 0, 1000000, () => it.MoveNext());

const int iterations = 5000;
const int minTfpsLimit = 2;
static float maxDeltaTime = 0.04f;
static int prevFrames = 0, tfps = 6;
static int prevTenthSecond = -1;
public static int minFps = 30;
public static int iterations = 0;
static int prevFrames = 0;
public static int fps = 0;
public static int[] fpsSlots = new int[10];
static int previousN = -1;

static IEnumerator Looper()
{
Expand Down Expand Up @@ -150,30 +176,26 @@ public static void Postfix()
return;
var s1 = (int)(camera.rootSize * 1000);
var s2 = (int)(camera.desiredSize * 1000);
if (s1 != s2)
if (Math.Abs(s1 - s2) > 1) // can be 59999/60000 when completely zoomed out
return;

// timeSlicer.Execute();

var tenthSecond = (Environment.TickCount / 100) % 100;
var n = (Tools.EnvTicks() / 100) % 10;
prevFrames++;
if (prevTenthSecond != tenthSecond)
if (previousN != n)
{
prevTenthSecond = tenthSecond;
tfps = prevFrames;
previousN = n;
var old = fpsSlots[n];
fpsSlots[n] = prevFrames;
fps = fps - old + prevFrames;
prevFrames = 0;
}
if (tfps >= minTfpsLimit + 1)
maxDeltaTime += 0.001f;
else if (tfps == minTfpsLimit)
maxDeltaTime -= 0.001f;
else if (tfps < minTfpsLimit)
maxDeltaTime = 0.04f;

var n = (maxDeltaTime - Time.deltaTime) * iterations;
if (n == 0)
Log.Warning($"tfps = {tfps}");
for (var i = 0; i < n; i++)

if (fps < minFps)
iterations = 0;
else
iterations++;

for (var i = 0; i < iterations; i++)
it.MoveNext();
}
}
Expand Down Expand Up @@ -438,12 +460,15 @@ public static void Postfix(IntVec3 c, Pawn forPawn, ref bool __result)
return;
}

// for now, this takes way too much cpu so we disable it and hope for the best
/*
if (__result == true)
{
// ignore any forced work cells if colonist is not forced
if (forcedWork.NonForcedShouldIgnore(map, c))
__result = false;
}
*/
}
}

Expand Down
40 changes: 0 additions & 40 deletions Source/TimeSlice.cs

This file was deleted.

6 changes: 6 additions & 0 deletions Source/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,5 +726,11 @@ public static IEnumerable<MethodBase> GetLatestMethod(Type type, params string[]
}
}
}

public static int EnvTicks()
{
var n = Environment.TickCount;
return n >= 0 ? n : -n;
}
}
}

0 comments on commit 5598552

Please sign in to comment.