Removed fixed timestep logic from GameScreen (redundant now because the logic is handled in GameMain)
This commit is contained in:
@@ -168,6 +168,7 @@
|
|||||||
<Compile Include="Source\Screens\BlurEffect.cs" />
|
<Compile Include="Source\Screens\BlurEffect.cs" />
|
||||||
<Compile Include="Source\Screens\NetLobbyVoting.cs" />
|
<Compile Include="Source\Screens\NetLobbyVoting.cs" />
|
||||||
<Compile Include="Source\Screens\ServerListScreen.cs" />
|
<Compile Include="Source\Screens\ServerListScreen.cs" />
|
||||||
|
<Compile Include="Source\Timing.cs" />
|
||||||
<Compile Include="Source\Utils\MTRandom.cs" />
|
<Compile Include="Source\Utils\MTRandom.cs" />
|
||||||
<Compile Include="Source\Utils\Rand.cs" />
|
<Compile Include="Source\Utils\Rand.cs" />
|
||||||
<Compile Include="Source\Events\PropertyTask.cs" />
|
<Compile Include="Source\Events\PropertyTask.cs" />
|
||||||
|
|||||||
@@ -127,9 +127,9 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void UpdateTransform(bool interpolate = true, bool clampPos = false)
|
public void UpdateTransform(bool interpolate = true, bool clampPos = false)
|
||||||
{
|
{
|
||||||
Vector2 interpolatedPosition = interpolate ? Physics.Interpolate(prevPosition, position) : position;
|
Vector2 interpolatedPosition = interpolate ? Timing.Interpolate(prevPosition, position) : position;
|
||||||
|
|
||||||
float interpolatedZoom = interpolate ? Physics.Interpolate(prevZoom, zoom) : zoom;
|
float interpolatedZoom = interpolate ? Timing.Interpolate(prevZoom, zoom) : zoom;
|
||||||
|
|
||||||
worldView.X = (int)(interpolatedPosition.X - worldView.Width / 2.0);
|
worldView.X = (int)(interpolatedPosition.X - worldView.Width / 2.0);
|
||||||
worldView.Y = (int)(interpolatedPosition.Y + worldView.Height / 2.0);
|
worldView.Y = (int)(interpolatedPosition.Y + worldView.Height / 2.0);
|
||||||
|
|||||||
@@ -127,9 +127,13 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spriteBatch.DrawString(GUI.LargeFont, loadText,
|
if (GUI.LargeFont!=null)
|
||||||
new Vector2(GameMain.GraphicsWidth/2.0f - GUI.LargeFont.MeasureString(loadText).X/2.0f, GameMain.GraphicsHeight*0.8f),
|
{
|
||||||
Color.White);
|
spriteBatch.DrawString(GUI.LargeFont, loadText,
|
||||||
|
new Vector2(GameMain.GraphicsWidth/2.0f - GUI.LargeFont.MeasureString(loadText).X/2.0f, GameMain.GraphicsHeight*0.8f),
|
||||||
|
Color.White);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ namespace Barotrauma
|
|||||||
private bool hasLoaded;
|
private bool hasLoaded;
|
||||||
|
|
||||||
private GameTime fixedTime;
|
private GameTime fixedTime;
|
||||||
private double updatesToMake;
|
|
||||||
|
|
||||||
//public static Random localRandom;
|
//public static Random localRandom;
|
||||||
//public static Random random;
|
//public static Random random;
|
||||||
@@ -142,7 +141,7 @@ namespace Barotrauma
|
|||||||
IsFixedTimeStep = false;
|
IsFixedTimeStep = false;
|
||||||
//TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 55);
|
//TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 55);
|
||||||
|
|
||||||
updatesToMake = 0.0;
|
Timing.Accumulator = 0.0f;
|
||||||
fixedTime = new GameTime();
|
fixedTime = new GameTime();
|
||||||
|
|
||||||
World = new World(new Vector2(0, -9.82f));
|
World = new World(new Vector2(0, -9.82f));
|
||||||
@@ -291,11 +290,9 @@ namespace Barotrauma
|
|||||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||||
protected override void Update(GameTime gameTime)
|
protected override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
double realDeltaTime = gameTime.ElapsedGameTime.TotalSeconds;
|
Timing.Accumulator += gameTime.ElapsedGameTime.TotalSeconds;
|
||||||
double deltaTime = 0.016;
|
|
||||||
updatesToMake += realDeltaTime;
|
|
||||||
|
|
||||||
while (updatesToMake > 0.0)
|
while (Timing.Accumulator >= Timing.Step)
|
||||||
{
|
{
|
||||||
fixedTime.IsRunningSlowly = gameTime.IsRunningSlowly;
|
fixedTime.IsRunningSlowly = gameTime.IsRunningSlowly;
|
||||||
TimeSpan addTime = new TimeSpan(0, 0, 0, 0, 16);
|
TimeSpan addTime = new TimeSpan(0, 0, 0, 0, 16);
|
||||||
@@ -303,39 +300,49 @@ namespace Barotrauma
|
|||||||
fixedTime.TotalGameTime.Add(addTime);
|
fixedTime.TotalGameTime.Add(addTime);
|
||||||
base.Update(fixedTime);
|
base.Update(fixedTime);
|
||||||
|
|
||||||
PlayerInput.Update(deltaTime);
|
PlayerInput.Update(Timing.Step);
|
||||||
|
|
||||||
bool paused = false;
|
bool paused = false;
|
||||||
|
|
||||||
if (hasLoaded && !titleScreenOpen)
|
if (titleScreenOpen)
|
||||||
|
{
|
||||||
|
if (TitleScreen.LoadState >= 100.0f &&
|
||||||
|
(!waitForKeyHit || PlayerInput.GetKeyboardState.GetPressedKeys().Length>0 || PlayerInput.LeftButtonClicked()))
|
||||||
|
{
|
||||||
|
titleScreenOpen = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (hasLoaded)
|
||||||
{
|
{
|
||||||
SoundPlayer.Update();
|
SoundPlayer.Update();
|
||||||
|
|
||||||
if (PlayerInput.KeyHit(Keys.Escape)) GUI.TogglePauseMenu();
|
if (PlayerInput.KeyHit(Keys.Escape)) GUI.TogglePauseMenu();
|
||||||
|
|
||||||
DebugConsole.Update(this, (float)deltaTime);
|
DebugConsole.Update(this, (float)Timing.Step);
|
||||||
|
|
||||||
paused = (DebugConsole.IsOpen || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) &&
|
paused = (DebugConsole.IsOpen || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) &&
|
||||||
(NetworkMember == null || !NetworkMember.GameStarted);
|
(NetworkMember == null || !NetworkMember.GameStarted);
|
||||||
|
|
||||||
if (!paused) Screen.Selected.Update(deltaTime);
|
if (!paused)
|
||||||
|
{
|
||||||
|
Screen.Selected.Update(Timing.Step);
|
||||||
|
}
|
||||||
|
|
||||||
if (NetworkMember != null)
|
if (NetworkMember != null)
|
||||||
{
|
{
|
||||||
NetworkMember.Update((float)deltaTime);
|
NetworkMember.Update((float)Timing.Step);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NetworkEvent.Events.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI.Update((float)deltaTime);
|
GUI.Update((float)Timing.Step);
|
||||||
}
|
}
|
||||||
|
|
||||||
CoroutineManager.Update((float)deltaTime, paused ? 0.0f : (float)deltaTime);
|
|
||||||
|
|
||||||
updatesToMake -= deltaTime;
|
CoroutineManager.Update((float)Timing.Step, paused ? 0.0f : (float)Timing.Step);
|
||||||
|
|
||||||
|
Timing.Accumulator -= Timing.Step;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timing.Alpha = Timing.Accumulator / Timing.Step;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -344,8 +351,6 @@ namespace Barotrauma
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void Draw(GameTime gameTime)
|
protected override void Draw(GameTime gameTime)
|
||||||
{
|
{
|
||||||
//renderTimer.Restart();
|
|
||||||
|
|
||||||
double deltaTime = gameTime.ElapsedGameTime.TotalSeconds;
|
double deltaTime = gameTime.ElapsedGameTime.TotalSeconds;
|
||||||
|
|
||||||
FrameCounter.Update(deltaTime);
|
FrameCounter.Update(deltaTime);
|
||||||
@@ -353,22 +358,11 @@ namespace Barotrauma
|
|||||||
if (titleScreenOpen)
|
if (titleScreenOpen)
|
||||||
{
|
{
|
||||||
TitleScreen.Draw(spriteBatch, GraphicsDevice, (float)deltaTime);
|
TitleScreen.Draw(spriteBatch, GraphicsDevice, (float)deltaTime);
|
||||||
if (TitleScreen.LoadState>=100.0f &&
|
|
||||||
(!waitForKeyHit || PlayerInput.GetKeyboardState.GetPressedKeys().Length>0 || PlayerInput.LeftButtonClicked()))
|
|
||||||
{
|
|
||||||
titleScreenOpen = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (hasLoaded)
|
else if (hasLoaded)
|
||||||
{
|
{
|
||||||
Screen.Selected.Draw(deltaTime, GraphicsDevice, spriteBatch);
|
Screen.Selected.Draw(deltaTime, GraphicsDevice, spriteBatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
//double elapsed = sw.Elapsed.TotalSeconds;
|
|
||||||
//if (elapsed < Physics.step)
|
|
||||||
//{
|
|
||||||
// System.Threading.Thread.Sleep((int)((Physics.step - elapsed) * 1000.0));
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool waitForKeyHit = true;
|
static bool waitForKeyHit = true;
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
public override void UpdateHUD(Character character)
|
public override void UpdateHUD(Character character)
|
||||||
{
|
{
|
||||||
GuiFrame.Update((float)Physics.step);
|
GuiFrame.Update((float)Timing.Step);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ToggleActive(GUIButton button, object obj)
|
private bool ToggleActive(GUIButton button, object obj)
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ namespace Barotrauma.Items.Components
|
|||||||
activateButton.Enabled = CanBeFabricated(targetItem, character);
|
activateButton.Enabled = CanBeFabricated(targetItem, character);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiFrame.Update((float)Physics.step);
|
GuiFrame.Update((float)Timing.Step);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CanBeFabricated(FabricableItem fabricableItem, Character user)
|
private bool CanBeFabricated(FabricableItem fabricableItem, Character user)
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case "trigger_in":
|
case "trigger_in":
|
||||||
item.Use((float)Physics.step, null);
|
item.Use((float)Timing.Step, null);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (frame == null) return;
|
if (frame == null) return;
|
||||||
|
|
||||||
frame.Update((float)Physics.step);
|
frame.Update((float)Timing.Step);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -923,7 +923,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
editingHUD.Draw(spriteBatch);
|
editingHUD.Draw(spriteBatch);
|
||||||
editingHUD.Update((float)Physics.step);
|
editingHUD.Update((float)Timing.Step);
|
||||||
|
|
||||||
if (!prefab.IsLinkable) return;
|
if (!prefab.IsLinkable) return;
|
||||||
|
|
||||||
@@ -951,7 +951,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (editingHUD.Rect.Height > 60)
|
if (editingHUD.Rect.Height > 60)
|
||||||
{
|
{
|
||||||
editingHUD.Update((float)Physics.step);
|
editingHUD.Update((float)Timing.Step);
|
||||||
editingHUD.Draw(spriteBatch);
|
editingHUD.Draw(spriteBatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,8 +156,8 @@ namespace Barotrauma
|
|||||||
editingHUD = CreateEditingHUD();
|
editingHUD = CreateEditingHUD();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
editingHUD.Update(0.016f);
|
||||||
editingHUD.Draw(spriteBatch);
|
editingHUD.Draw(spriteBatch);
|
||||||
editingHUD.Update((float)Physics.step);
|
|
||||||
|
|
||||||
if (!PlayerInput.LeftButtonClicked() || !PlayerInput.KeyDown(Keys.Space)) return;
|
if (!PlayerInput.LeftButtonClicked() || !PlayerInput.KeyDown(Keys.Space)) return;
|
||||||
|
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void UpdateTransform()
|
public void UpdateTransform()
|
||||||
{
|
{
|
||||||
DrawPosition = Physics.Interpolate(prevPosition, Position);
|
DrawPosition = Timing.Interpolate(prevPosition, Position);
|
||||||
}
|
}
|
||||||
|
|
||||||
//math/physics stuff ----------------------------------------------------
|
//math/physics stuff ----------------------------------------------------
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ namespace Barotrauma
|
|||||||
editingHUD = CreateEditingHUD();
|
editingHUD = CreateEditingHUD();
|
||||||
}
|
}
|
||||||
|
|
||||||
editingHUD.Update((float)Physics.step);
|
editingHUD.Update((float)Timing.Step);
|
||||||
editingHUD.Draw(spriteBatch);
|
editingHUD.Draw(spriteBatch);
|
||||||
|
|
||||||
if (!PlayerInput.LeftButtonClicked()) return;
|
if (!PlayerInput.LeftButtonClicked()) return;
|
||||||
|
|||||||
@@ -304,8 +304,6 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
if (gameStarted)
|
if (gameStarted)
|
||||||
{
|
{
|
||||||
//inGameHUD.Update((float)Physics.step);
|
|
||||||
|
|
||||||
if (respawnManager != null) respawnManager.Update(deltaTime);
|
if (respawnManager != null) respawnManager.Update(deltaTime);
|
||||||
|
|
||||||
bool isCrewDead =
|
bool isCrewDead =
|
||||||
|
|||||||
@@ -301,8 +301,8 @@ namespace Barotrauma.Particles
|
|||||||
|
|
||||||
public void UpdateDrawPos()
|
public void UpdateDrawPos()
|
||||||
{
|
{
|
||||||
drawPosition = Physics.Interpolate(prevPosition, position);
|
drawPosition = Timing.Interpolate(prevPosition, position);
|
||||||
drawRotation = Physics.Interpolate(prevRotation, rotation);
|
drawRotation = Timing.Interpolate(prevRotation, rotation);
|
||||||
|
|
||||||
prevPosition = position;
|
prevPosition = position;
|
||||||
prevRotation = rotation;
|
prevRotation = rotation;
|
||||||
|
|||||||
@@ -20,33 +20,6 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public static float DisplayToRealWorldRatio = 1.0f / 80.0f;
|
public static float DisplayToRealWorldRatio = 1.0f / 80.0f;
|
||||||
|
|
||||||
public static double accumulator;
|
|
||||||
public static double step = 1.0/60.0;
|
|
||||||
|
|
||||||
public const float DisplayToSimRation = 100.0f;
|
public const float DisplayToSimRation = 100.0f;
|
||||||
|
|
||||||
public static double Alpha
|
|
||||||
{
|
|
||||||
get { return alpha; }
|
|
||||||
set { alpha = Math.Min(Math.Max(value, 0.0), 1.0); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double Interpolate(double previous, double current)
|
|
||||||
{
|
|
||||||
return current * alpha + previous * (1.0 - alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float Interpolate(float previous, float current)
|
|
||||||
{
|
|
||||||
return current * (float)alpha + previous * (1.0f - (float)alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector2 Interpolate(Vector2 previous, Vector2 current)
|
|
||||||
{
|
|
||||||
return new Vector2(
|
|
||||||
Interpolate(previous.X, current.X),
|
|
||||||
Interpolate(previous.Y, current.Y));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -330,10 +330,10 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void UpdateDrawPosition()
|
public void UpdateDrawPosition()
|
||||||
{
|
{
|
||||||
drawPosition = Physics.Interpolate(prevPosition, body.Position) - offsetFromTargetPos;
|
drawPosition = Timing.Interpolate(prevPosition, body.Position) - offsetFromTargetPos;
|
||||||
drawPosition = ConvertUnits.ToDisplayUnits(drawPosition);
|
drawPosition = ConvertUnits.ToDisplayUnits(drawPosition);
|
||||||
|
|
||||||
drawRotation = Physics.Interpolate(prevRotation, body.Rotation);
|
drawRotation = Timing.Interpolate(prevRotation, body.Rotation);
|
||||||
|
|
||||||
if (offsetFromTargetPos == Vector2.Zero) return;
|
if (offsetFromTargetPos == Vector2.Zero) return;
|
||||||
|
|
||||||
@@ -370,7 +370,7 @@ namespace Barotrauma
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void SmoothRotate(float targetRotation, float force = 10.0f)
|
public void SmoothRotate(float targetRotation, float force = 10.0f)
|
||||||
{
|
{
|
||||||
float nextAngle = body.Rotation + body.AngularVelocity * (float)Physics.step;
|
float nextAngle = body.Rotation + body.AngularVelocity * (float)Timing.Step;
|
||||||
|
|
||||||
float angle = MathUtils.GetShortestAngle(nextAngle, targetRotation);
|
float angle = MathUtils.GetShortestAngle(nextAngle, targetRotation);
|
||||||
|
|
||||||
|
|||||||
@@ -98,26 +98,15 @@ namespace Barotrauma
|
|||||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||||
public override void Update(double deltaTime)
|
public override void Update(double deltaTime)
|
||||||
{
|
{
|
||||||
Physics.accumulator += deltaTime;
|
|
||||||
//cam.Zoom += Math.Sign(PlayerInput.GetMouseState.ScrollWheelValue - PlayerInput.GetOldMouseState.ScrollWheelValue)*0.1f;
|
|
||||||
|
|
||||||
cam.MoveCamera((float)deltaTime);
|
cam.MoveCamera((float)deltaTime);
|
||||||
|
|
||||||
if (physicsEnabled)
|
if (physicsEnabled)
|
||||||
{
|
{
|
||||||
Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 4);
|
Character.UpdateAnimAll((float)deltaTime);
|
||||||
while (Physics.accumulator >= Physics.step)
|
|
||||||
{
|
|
||||||
Character.UpdateAnimAll((float)Physics.step * 1000.0f);
|
|
||||||
|
|
||||||
Ragdoll.UpdateAll(cam, (float)Physics.step);
|
Ragdoll.UpdateAll(cam, (float)deltaTime);
|
||||||
|
|
||||||
GameMain.World.Step((float)Physics.step);
|
GameMain.World.Step((float)deltaTime);
|
||||||
|
|
||||||
Physics.accumulator -= Physics.step;
|
|
||||||
}
|
|
||||||
|
|
||||||
Physics.Alpha = Physics.accumulator / Physics.step;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,9 +91,6 @@ namespace Barotrauma
|
|||||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||||
public override void Update(double deltaTime)
|
public override void Update(double deltaTime)
|
||||||
{
|
{
|
||||||
//the accumulator code is based on this article:
|
|
||||||
//http://gafferongames.com/game-physics/fix-your-timestep/
|
|
||||||
Physics.accumulator += deltaTime;
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null)
|
if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null)
|
||||||
@@ -112,8 +109,6 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (Level.Loaded != null) Level.Loaded.Update((float)deltaTime);
|
if (Level.Loaded != null) Level.Loaded.Update((float)deltaTime);
|
||||||
|
|
||||||
Character.UpdateAll(cam, (float)deltaTime);
|
|
||||||
|
|
||||||
if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null)
|
if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null)
|
||||||
{
|
{
|
||||||
if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem)
|
if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem)
|
||||||
@@ -121,55 +116,42 @@ namespace Barotrauma
|
|||||||
Character.Controlled.SelectedConstruction.UpdateHUD(Character.Controlled);
|
Character.Controlled.SelectedConstruction.UpdateHUD(Character.Controlled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Character.UpdateAll(cam, (float)deltaTime);
|
||||||
|
|
||||||
Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 6);
|
BackgroundCreatureManager.Update(cam, (float)deltaTime);
|
||||||
//Physics.accumulator = Physics.step;
|
|
||||||
while (Physics.accumulator >= Physics.step)
|
GameMain.ParticleManager.Update((float)deltaTime);
|
||||||
|
|
||||||
|
StatusEffect.UpdateAll((float)deltaTime);
|
||||||
|
|
||||||
|
if (Character.Controlled != null && Lights.LightManager.ViewTarget != null)
|
||||||
{
|
{
|
||||||
BackgroundCreatureManager.Update(cam, (float)Physics.step);
|
cam.TargetPos = Lights.LightManager.ViewTarget.WorldPosition;
|
||||||
|
}
|
||||||
|
cam.MoveCamera((float)deltaTime);
|
||||||
|
|
||||||
GameMain.ParticleManager.Update((float)Physics.step);
|
foreach (Submarine sub in Submarine.Loaded)
|
||||||
|
{
|
||||||
StatusEffect.UpdateAll((float)Physics.step);
|
sub.SetPrevTransform(sub.Position);
|
||||||
|
|
||||||
if (Character.Controlled != null && Lights.LightManager.ViewTarget != null)
|
|
||||||
{
|
|
||||||
cam.TargetPos = Lights.LightManager.ViewTarget.WorldPosition;
|
|
||||||
//Lights.LightManager.ViewPos = Character.Controlled.WorldPosition;
|
|
||||||
}
|
|
||||||
cam.MoveCamera((float)Physics.step);
|
|
||||||
|
|
||||||
foreach (Submarine sub in Submarine.Loaded)
|
|
||||||
{
|
|
||||||
sub.SetPrevTransform(sub.Position);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (PhysicsBody pb in PhysicsBody.list)
|
|
||||||
{
|
|
||||||
pb.SetPrevTransform(pb.SimPosition, pb.Rotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
MapEntity.UpdateAll(cam, (float)Physics.step);
|
|
||||||
|
|
||||||
Character.UpdateAnimAll((float)Physics.step);
|
|
||||||
|
|
||||||
Ragdoll.UpdateAll(cam, (float)Physics.step);
|
|
||||||
|
|
||||||
foreach (Submarine sub in Submarine.Loaded)
|
|
||||||
{
|
|
||||||
sub.Update((float)Physics.step);
|
|
||||||
}
|
|
||||||
|
|
||||||
GameMain.World.Step((float)Physics.step);
|
|
||||||
|
|
||||||
//Level.AfterWorldStep();
|
|
||||||
|
|
||||||
Physics.accumulator -= Physics.step;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (PhysicsBody pb in PhysicsBody.list)
|
||||||
|
{
|
||||||
|
pb.SetPrevTransform(pb.SimPosition, pb.Rotation);
|
||||||
|
}
|
||||||
|
|
||||||
Physics.Alpha = Physics.accumulator / Physics.step;
|
MapEntity.UpdateAll(cam, (float)deltaTime);
|
||||||
|
|
||||||
|
Character.UpdateAnimAll((float)deltaTime);
|
||||||
|
|
||||||
|
Ragdoll.UpdateAll(cam, (float)deltaTime);
|
||||||
|
|
||||||
|
foreach (Submarine sub in Submarine.Loaded)
|
||||||
|
{
|
||||||
|
sub.Update((float)deltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
GameMain.World.Step((float)deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
|
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Barotrauma
|
||||||
|
{
|
||||||
|
static class Timing
|
||||||
|
{
|
||||||
|
private static double alpha;
|
||||||
|
|
||||||
|
public static double Accumulator;
|
||||||
|
public static double Step = 1.0 / 60.0;
|
||||||
|
|
||||||
|
public static double Alpha
|
||||||
|
{
|
||||||
|
get { return alpha; }
|
||||||
|
set { alpha = Math.Min(Math.Max(value, 0.0), 1.0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double Interpolate(double previous, double current)
|
||||||
|
{
|
||||||
|
return current * alpha + previous * (1.0 - alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float Interpolate(float previous, float current)
|
||||||
|
{
|
||||||
|
return current * (float)alpha + previous * (1.0f - (float)alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector2 Interpolate(Vector2 previous, Vector2 current)
|
||||||
|
{
|
||||||
|
return new Vector2(
|
||||||
|
Interpolate(previous.X, current.X),
|
||||||
|
Interpolate(previous.Y, current.Y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user