3 using Microsoft.Xna.Framework;
4 using System.Threading;
5 using FarseerPhysics.Dynamics;
8 using Microsoft.Xna.Framework.Input;
15 private object updateLock =
new object();
16 private double physicsTime;
19 private readonly
Camera cam;
42 cam.Translate(
new Vector2(-10.0f, 50.0f));
54 cam.UpdateTransform(
true);
59 cam.UpdateTransform(
true);
66 #if RUN_PHYSICS_IN_SEPARATE_THREAD
67 var physicsThread =
new Thread(ExecutePhysics)
69 Name =
"Physics thread",
72 physicsThread.Start();
80 var config = GameSettings.CurrentConfig;
81 config.CrewMenuOpen =
CrewManager.PreferCrewMenuOpen;
82 config.ChatOpen =
ChatBox.PreferChatBoxOpen;
83 GameSettings.SetCurrentConfig(config);
84 GameSettings.SaveCurrentConfig();
85 GameMain.SoundManager.SetCategoryMuffle(
"default",
false);
90 DebugConsole.DeactivateCheats();
99 public override void Update(
double deltaTime)
101 #if RUN_PHYSICS_IN_SEPARATE_THREAD
102 physicsTime += deltaTime;
109 if (
GameMain.
GameSession !=
null && !DebugConsole.IsOpen && GUI.KeyboardDispatcher.Subscriber ==
null)
115 Vector2 targetMovement = Vector2.Zero;
116 if (PlayerInput.KeyDown(Keys.I)) { targetMovement.Y += 1.0f; }
117 if (PlayerInput.KeyDown(Keys.K)) { targetMovement.Y -= 1.0f; }
118 if (PlayerInput.KeyDown(Keys.J)) { targetMovement.X -= 1.0f; }
119 if (PlayerInput.KeyDown(Keys.L)) { targetMovement.X += 1.0f; }
121 if (targetMovement != Vector2.Zero)
130 GameMain.LightManager?.Update((
float)deltaTime);
142 var sw =
new System.Diagnostics.Stopwatch();
150 GameMain.PerformanceCounter.AddElapsedTicks(
"Update:GameSession", sw.ElapsedTicks);
153 GameMain.ParticleManager.Update((
float)deltaTime);
156 GameMain.PerformanceCounter.AddElapsedTicks(
"Update:Particles", sw.ElapsedTicks);
162 GameMain.PerformanceCounter.AddElapsedTicks(
"Update:Level", sw.ElapsedTicks);
166 if (controlled.SelectedItem !=
null && controlled.CanInteractWith(controlled.SelectedItem))
168 controlled.SelectedItem.UpdateHUD(cam, controlled, (
float)deltaTime);
170 if (controlled.Inventory !=
null)
172 foreach (
Item item
in controlled.Inventory.AllItems)
174 if (controlled.HasEquippedItem(item))
176 item.UpdateHUD(cam, controlled, (
float)deltaTime);
193 GameMain.PerformanceCounter.AddElapsedTicks(
"Update:Character", sw.ElapsedTicks);
201 GameMain.PerformanceCounter.AddElapsedTicks(
"Update:StatusEffects", sw.ElapsedTicks);
207 Vector2 targetPos = Lights.LightManager.ViewTarget.WorldPosition;
211 Vector2 screenTargetPos =
new Vector2(
GameMain.GraphicsWidth,
GameMain.GraphicsHeight) * 0.5f;
214 screenTargetPos.X =
GameMain.GraphicsWidth * (
CharacterHealth.OpenHealthWindow.Alignment == Alignment.Left ? 0.6f : 0.4f);
218 screenTargetPos.Y =
GameMain.GraphicsHeight * 0.4f;
220 Vector2 screenOffset = screenTargetPos -
new Vector2(
GameMain.GraphicsWidth / 2,
GameMain.GraphicsHeight / 2);
221 screenOffset.Y = -screenOffset.Y;
222 targetPos -= screenOffset / cam.Zoom;
224 cam.TargetPos = targetPos;
227 cam.MoveCamera((
float)deltaTime, allowZoom: GUI.MouseOn ==
null && !
Inventory.IsMouseOnInventory);
253 GameMain.PerformanceCounter.AddElapsedTicks(
"Update:MapEntity", sw.ElapsedTicks);
266 GameMain.PerformanceCounter.AddElapsedTicks(
"Update:Ragdolls", sw.ElapsedTicks);
272 sub.
Update((
float)deltaTime);
277 GameMain.PerformanceCounter.AddElapsedTicks(
"Update:Submarine", sw.ElapsedTicks);
281 #if !RUN_PHYSICS_IN_SEPARATE_THREAD
286 catch (WorldLockedException e)
288 string errorMsg =
"Attempted to modify the state of the physics simulation while a time step was running.";
289 DebugConsole.ThrowError(errorMsg, e);
290 GameAnalyticsManager.AddErrorEventOnce(
"GameScreen.Update:WorldLockedException" + e.Message, GameAnalyticsManager.ErrorSeverity.Critical, errorMsg);
297 GameMain.PerformanceCounter.AddElapsedTicks(
"Update:Physics", sw.ElapsedTicks);
299 UpdateProjSpecific(deltaTime);
301 #if RUN_PHYSICS_IN_SEPARATE_THREAD
306 partial
void UpdateProjSpecific(
double deltaTime);
308 private void ExecutePhysics()
312 while (physicsTime >= Timing.Step)
317 physicsTime -= Timing.Step;
static void UpdateAnimAll(float deltaTime)
static Character Controlled
static void UpdateAll(float deltaTime, Camera cam)
Triggers a "conversation popup" with text and support for different branching options.
Responsible for keeping track of the characters in the player crew, saving and loading their orders,...
virtual Vector2 WorldPosition
static GameSession GameSession
override void Update(double deltaTime)
Allows the game to run logic such as updating the world, checking for collisions, gathering input,...
void Update(float deltaTime)
void Update(float deltaTime, Camera cam)
static void UpdateAll(float deltaTime, Camera cam)
Call Update() on every object in Entity.list
static void ClearHighlightedEntities()
void SetPrevTransform(Vector2 simPosition, float rotation)
static List< PhysicsBody > List
static void UpdateAll(float deltaTime, Camera cam)
StatusEffects can be used to execute various kinds of effects: modifying the state of some entity in ...
static void UpdateAll(float deltaTime)
readonly PhysicsBody Body
void SetPrevTransform(Vector2 position)
override Vector2? WorldPosition
static Submarine MainSub
Note that this can be null in some situations, e.g. editors and missions that don't load a submarine.
void Update(float deltaTime)
static List< Submarine > Loaded
void ApplyForce(Vector2 force)
override Vector2? Position
static Submarine FindClosest(Vector2 worldPosition, bool ignoreOutposts=false, bool ignoreOutsideLevel=true, bool ignoreRespawnShuttle=false, CharacterTeamType? teamType=null)
If has value, the sub must match the team type.