Add force sync frames.
This commit is contained in:
@@ -54,8 +54,8 @@ namespace Cryville.Crtr {
|
||||
static bool disableGC = true;
|
||||
static float clippingDist = 1f;
|
||||
static float renderDist = 6f;
|
||||
static float renderStep = 0.05f;
|
||||
public static float actualRenderStep = 0f;
|
||||
static double renderStep = 0.05;
|
||||
public static double actualRenderStep = 0;
|
||||
static bool autoRenderStep = false;
|
||||
public static float soundOffset = 0;
|
||||
static float startOffset = 0;
|
||||
@@ -111,7 +111,7 @@ namespace Cryville.Crtr {
|
||||
|
||||
bool texloaddone;
|
||||
diag::Stopwatch texloadtimer = new diag::Stopwatch();
|
||||
bool firstFrame;
|
||||
int forceSyncFrames;
|
||||
double atime0;
|
||||
void Update() {
|
||||
if (started) GameUpdate();
|
||||
@@ -123,10 +123,18 @@ namespace Cryville.Crtr {
|
||||
try {
|
||||
if (Screen.width != screenSize.x || Screen.height != screenSize.y)
|
||||
throw new InvalidOperationException("Window resized while playing");
|
||||
float dt = firstFrame
|
||||
? 1f / Application.targetFrameRate
|
||||
: Time.deltaTime;
|
||||
firstFrame = false;
|
||||
double dt, step;
|
||||
if (forceSyncFrames != 0) {
|
||||
forceSyncFrames--;
|
||||
double target = Game.AudioClient.Position - atime0;
|
||||
dt = target - cbus.Time;
|
||||
step = autoRenderStep ? 1f / Application.targetFrameRate : renderStep;
|
||||
inputProxy.SyncTime(target);
|
||||
}
|
||||
else {
|
||||
dt = Time.deltaTime;
|
||||
step = autoRenderStep ? Time.smoothDeltaTime : renderStep;
|
||||
}
|
||||
inputProxy.ForceTick();
|
||||
cbus.ForwardByTime(dt);
|
||||
bbus.ForwardByTime(dt);
|
||||
@@ -135,10 +143,6 @@ namespace Cryville.Crtr {
|
||||
bbus.CopyTo(2, tbus);
|
||||
bbus.CopyTo(3, nbus);
|
||||
UnityEngine.Profiling.Profiler.EndSample();
|
||||
float step = autoRenderStep ? ( firstFrame
|
||||
? 1f / Application.targetFrameRate
|
||||
: Time.smoothDeltaTime
|
||||
) : renderStep;
|
||||
actualRenderStep = step;
|
||||
|
||||
nbus.ForwardStepByTime(clippingDist, step);
|
||||
@@ -250,14 +254,15 @@ namespace Cryville.Crtr {
|
||||
status.text = sttext;
|
||||
}
|
||||
void OnCameraPostRender(Camera cam) {
|
||||
if (!started) return;
|
||||
if (!logEnabled) return;
|
||||
if (started) timetext = string.Format(
|
||||
"\nSTime: {0:R}\nATime: {1:R}\nITime: {2:R}",
|
||||
timetext = string.Format(
|
||||
"\nSTime: {0:R}s {3}\ndATime: {1:+0.0ms;-0.0ms;0} {3}\ndITime: {2:+0.0ms;-0.0ms;0} {3}",
|
||||
cbus.Time,
|
||||
Game.AudioClient.Position - atime0,
|
||||
inputProxy.GetTimestampAverage()
|
||||
(Game.AudioClient.Position - atime0 - cbus.Time) * 1e3,
|
||||
(inputProxy.GetTimestampAverage() - cbus.Time) * 1e3,
|
||||
forceSyncFrames != 0 ? "(force sync)" : ""
|
||||
);
|
||||
else timetext = string.Empty;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -309,7 +314,7 @@ namespace Cryville.Crtr {
|
||||
autoRenderStep = renderStep == 0;
|
||||
soundOffset = Settings.Default.SoundOffset;
|
||||
startOffset = Settings.Default.StartOffset;
|
||||
firstFrame = true;
|
||||
forceSyncFrames= Settings.Default.ForceSyncFrames;
|
||||
texloaddone = false;
|
||||
Game.NetworkTaskWorker.SuspendBackgroundTasks();
|
||||
Game.AudioSession = Game.AudioSequencer.NewSession();
|
||||
|
@@ -232,8 +232,7 @@ namespace Cryville.Crtr {
|
||||
public void SyncTime(double time) {
|
||||
foreach (var s in _sproxies.Keys) {
|
||||
var h = s.Handler;
|
||||
if (!_timeOrigins.ContainsKey(h))
|
||||
_timeOrigins.Add(h, h.GetCurrentTimestamp() - time);
|
||||
_timeOrigins[h] = h.GetCurrentTimestamp() - time;
|
||||
}
|
||||
}
|
||||
public void ForceTick() {
|
||||
|
@@ -34,6 +34,17 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
[Category("gameplay")]
|
||||
[Range(-1, 5)]
|
||||
public int ForceSyncFrames {
|
||||
get {
|
||||
return PlayerPrefs.GetInt("ForceSyncFrames", 5);
|
||||
}
|
||||
set {
|
||||
PlayerPrefs.SetInt("ForceSyncFrames", value);
|
||||
}
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
[Category("data")]
|
||||
[Description("The directory where the game files are stored.")]
|
||||
|
Reference in New Issue
Block a user