Skip to content

Commit b3e7bba

Browse files
committed
add timescale feature
1 parent b545e9b commit b3e7bba

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

FEZ.FEZUG.mm.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<Compile Include="Features\Allow3DRotation.cs" />
8888
<Compile Include="Features\GetTrileInfo.cs" />
8989
<Compile Include="Features\InvisibleTrilesDraw.cs" />
90+
<Compile Include="Features\Timescaler.cs" />
9091
<Compile Include="Helpers\DrawingTools.cs" />
9192
<Compile Include="Features\IFezugFeature.cs" />
9293
<Compile Include="Features\ItemCountSet.cs" />

Features/Timescaler.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using FezEngine.Services;
2+
using FezEngine.Tools;
3+
using FEZUG.Features.Console;
4+
using Microsoft.Xna.Framework;
5+
using Microsoft.Xna.Framework.Audio;
6+
using System;
7+
using System.Collections;
8+
using System.Collections.Generic;
9+
using System.Globalization;
10+
using System.Linq;
11+
using System.Reflection;
12+
using System.Text;
13+
using System.Threading.Tasks;
14+
15+
namespace FEZUG.Features
16+
{
17+
internal class Timescaler : IFezugCommand
18+
{
19+
public static float Timescale = 1.0f;
20+
21+
public string Name => "timescale";
22+
23+
public string HelpText => "timescale <value> - changes game's simulation scale";
24+
25+
[ServiceDependency]
26+
public ISoundManager SoundManager { private get; set; }
27+
28+
public List<string> Autocomplete(string[] args)
29+
{
30+
string timescaleStr = Timescale.ToString("0.000", CultureInfo.InvariantCulture);
31+
if (timescaleStr.StartsWith(args[0])) return new List<string> { timescaleStr };
32+
return null;
33+
}
34+
35+
public bool Execute(string[] args)
36+
{
37+
if (args.Length != 1)
38+
{
39+
FezugConsole.Print($"Incorrect number of parameters: '{args.Length}'", FezugConsole.OutputType.Warning);
40+
return false;
41+
}
42+
43+
if (!float.TryParse(args[0], NumberStyles.Number, CultureInfo.InvariantCulture, out float timescale))
44+
{
45+
FezugConsole.Print($"Incorrect timescale: '{args[0]}'", FezugConsole.OutputType.Warning);
46+
return false;
47+
}
48+
49+
Timescale = timescale;
50+
51+
FezugConsole.Print($"Timescale has been set to {Timescale.ToString("0.000", CultureInfo.InvariantCulture)}");
52+
53+
return true;
54+
}
55+
}
56+
}

Patches/Fez.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
using FEZUG;
55
using FEZUG.Features;
66
using Microsoft.Xna.Framework;
7+
using System;
8+
using System.Diagnostics;
79

810
namespace FezGame
911
{
1012
public class patch_Fez : Fez
1113
{
14+
private double timescaledGameTime;
15+
private double timescaledElapsedTime;
16+
1217
public Fezug Fezug;
1318

1419
protected extern void orig_Initialize();
@@ -21,6 +26,33 @@ protected override void Initialize()
2126
ServiceHelper.AddComponent(Fezug = new Fezug(this));
2227
ServiceHelper.AddComponent(Fezug.Rendering);
2328
Logger.Log("FEZUG", "FEZUG initialized!");
29+
30+
timescaledGameTime = 0.0f;
31+
}
32+
33+
protected extern void orig_Update(GameTime gameTime);
34+
protected override void Update(GameTime gameTime)
35+
{
36+
if(gameTime.TotalGameTime.Ticks == 0)
37+
{
38+
timescaledGameTime = 0.0f;
39+
}
40+
timescaledElapsedTime = gameTime.ElapsedGameTime.TotalSeconds * Timescaler.Timescale;
41+
timescaledGameTime += timescaledElapsedTime;
42+
43+
orig_Update(new GameTime(
44+
TimeSpan.FromSeconds(timescaledGameTime),
45+
TimeSpan.FromSeconds(timescaledElapsedTime)
46+
));
47+
}
48+
49+
protected extern void orig_Draw(GameTime gameTime);
50+
protected override void Draw(GameTime gameTime)
51+
{
52+
orig_Draw(new GameTime(
53+
TimeSpan.FromSeconds(timescaledGameTime),
54+
TimeSpan.FromSeconds(timescaledElapsedTime)
55+
));
2456
}
2557
}
2658
}

0 commit comments

Comments
 (0)