public static void Unload() { Unloading = true; #if CLIENT Sound.OnGameEnd(); if (GameMain.LightManager != null) { GameMain.LightManager.ClearLights(); } #endif foreach (Submarine sub in loaded) { sub.Remove(); } loaded.Clear(); visibleEntities = null; if (GameMain.GameScreen.Cam != null) { GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; } RemoveAll(); if (Item.ItemList.Count > 0) { List <Item> items = new List <Item>(Item.ItemList); foreach (Item item in items) { DebugConsole.ThrowError("Error while unloading submarines - item \"" + item.Name + "\" not removed"); try { item.Remove(); } catch (Exception e) { DebugConsole.ThrowError("Error while removing \"" + item.Name + "\"!", e); } } Item.ItemList.Clear(); } Ragdoll.RemoveAll(); PhysicsBody.RemoveAll(); GameMain.World.Clear(); Unloading = false; }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> public override void Update(double deltaTime) { cam.MoveCamera((float)deltaTime); if (physicsEnabled) { Character.UpdateAnimAll((float)deltaTime); Ragdoll.UpdateAll((float)deltaTime, cam); GameMain.World.Step((float)deltaTime); } }
public static List <Limb> AttachHuskAppendage(Character character, Ragdoll ragdoll = null) { var huskDoc = XMLExtensions.TryLoadXml(Character.GetConfigFile("humanhusk")); string pathToAppendage = huskDoc.Root.Element("huskappendage").GetAttributeString("path", string.Empty); XDocument doc = XMLExtensions.TryLoadXml(pathToAppendage); if (doc == null || doc.Root == null) { return(null); } if (ragdoll == null) { ragdoll = character.AnimController; } if (ragdoll.Dir < 1.0f) { ragdoll.Flip(); } var huskAppendages = new List <Limb>(); var limbElements = doc.Root.Elements("limb").ToDictionary(e => e.GetAttributeString("id", null), e => e); foreach (var jointElement in doc.Root.Elements("joint")) { if (limbElements.TryGetValue(jointElement.GetAttributeString("limb2", null), out XElement limbElement)) { JointParams jointParams = new JointParams(jointElement, ragdoll.RagdollParams); Limb attachLimb = ragdoll.Limbs[jointParams.Limb1]; Limb huskAppendage = new Limb(ragdoll, character, new LimbParams(limbElement, ragdoll.RagdollParams)); huskAppendage.body.Submarine = character.Submarine; huskAppendage.body.SetTransform(attachLimb.SimPosition, attachLimb.Rotation); ragdoll.AddLimb(huskAppendage); ragdoll.AddJoint(jointParams); huskAppendages.Add(huskAppendage); } } return(huskAppendages); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> public override void Update(double deltaTime) { #if CLIENT if (Character.Spied != null) { if ((PlayerInput.KeyDown(InputType.Up) || PlayerInput.KeyDown(InputType.Down) || PlayerInput.KeyDown(InputType.Left) || PlayerInput.KeyDown(InputType.Right)) && !DebugConsole.IsOpen) { if (GameMain.NetworkMember != null && !GameMain.NetworkMember.chatMsgBox.Selected) { if (Character.Controlled != null) { cam.Position = Character.Controlled.WorldPosition; } else { cam.Position = Character.Spied.WorldPosition; } Character.Spied = null; cam.UpdateTransform(true); } } } #endif #if DEBUG && CLIENT if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null && !DebugConsole.IsOpen && GUIComponent.KeyboardDispatcher.Subscriber == null) { /* * var closestSub = Submarine.FindClosest(cam.WorldViewCenter); * if (closestSub == null) closestSub = GameMain.GameSession.Submarine; * * Vector2 targetMovement = Vector2.Zero; * if (PlayerInput.KeyDown(Keys.I)) targetMovement.Y += 1.0f; * if (PlayerInput.KeyDown(Keys.K)) targetMovement.Y -= 1.0f; * if (PlayerInput.KeyDown(Keys.J)) targetMovement.X -= 1.0f; * if (PlayerInput.KeyDown(Keys.L)) targetMovement.X += 1.0f; * * if (targetMovement != Vector2.Zero) * closestSub.ApplyForce(targetMovement * closestSub.SubBody.Body.Mass * 100.0f); */ } #endif #if CLIENT GameMain.NilModProfiler.SWMapEntityUpdate.Start(); #endif foreach (MapEntity e in MapEntity.mapEntityList) { e.IsHighlighted = false; } #if CLIENT GameMain.NilModProfiler.SWMapEntityUpdate.Stop(); if (GameMain.GameSession != null) { GameMain.NilModProfiler.SWGameSessionUpdate.Start(); GameMain.GameSession.Update((float)deltaTime); GameMain.NilModProfiler.RecordGameSessionUpdate(); } GameMain.NilModProfiler.SWParticleManager.Start(); GameMain.ParticleManager.Update((float)deltaTime); GameMain.NilModProfiler.RecordParticleManager(); GameMain.NilModProfiler.SWLightManager.Start(); GameMain.LightManager.Update((float)deltaTime); GameMain.NilModProfiler.RecordLightManager(); #endif if (Level.Loaded != null) { #if CLIENT GameMain.NilModProfiler.SWLevelUpdate.Start(); #endif Level.Loaded.Update((float)deltaTime, cam); #if CLIENT GameMain.NilModProfiler.RecordLevelUpdate(); #endif } #if CLIENT if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null && Character.Controlled.CanInteractWith(Character.Controlled.SelectedConstruction)) { Character.Controlled.SelectedConstruction.UpdateHUD(cam, Character.Controlled); } GameMain.NilModProfiler.SWCharacterUpdate.Start(); #endif Character.UpdateAll((float)deltaTime, cam); #if CLIENT //NilMod spy Code if (Character.Spied != null) { Character.ViewSpied((float)deltaTime, Cam, true); Lights.LightManager.ViewTarget = Character.Spied; CharacterHUD.Update((float)deltaTime, Character.Spied); foreach (HUDProgressBar progressBar in Character.Spied.HUDProgressBars.Values) { progressBar.Update((float)deltaTime); } foreach (var pb in Character.Spied.HUDProgressBars) { if (pb.Value.FadeTimer <= 0.0f) { Character.Spied.HUDProgressBars.Remove(pb.Key); } } } GameMain.NilModProfiler.SWCharacterUpdate.Stop(); GameMain.NilModProfiler.RecordCharacterUpdate(); GameMain.NilModProfiler.SWStatusEffect.Start(); #endif StatusEffect.UpdateAll((float)deltaTime); #if CLIENT GameMain.NilModProfiler.RecordStatusEffect(); if ((Character.Controlled != null && Lights.LightManager.ViewTarget != null) || (Character.Spied != null && Lights.LightManager.ViewTarget != null)) { cam.TargetPos = Lights.LightManager.ViewTarget.WorldPosition; } #endif cam.MoveCamera((float)deltaTime); #if CLIENT GameMain.NilModProfiler.SWSetTransforms.Start(); #endif foreach (Submarine sub in Submarine.Loaded) { sub.SetPrevTransform(sub.Position); } foreach (PhysicsBody pb in PhysicsBody.List) { pb.SetPrevTransform(pb.SimPosition, pb.Rotation); } #if CLIENT GameMain.NilModProfiler.RecordSetTransforms(); GameMain.NilModProfiler.SWMapEntityUpdate.Start(); #endif MapEntity.UpdateAll((float)deltaTime, cam); #if CLIENT GameMain.NilModProfiler.RecordMapEntityUpdate(); GameMain.NilModProfiler.SWCharacterAnimUpdate.Start(); #endif Character.UpdateAnimAll((float)deltaTime); #if CLIENT GameMain.NilModProfiler.RecordCharacterAnimUpdate(); GameMain.NilModProfiler.SWRagdollUpdate.Start(); #endif Ragdoll.UpdateAll((float)deltaTime, cam); #if CLIENT GameMain.NilModProfiler.RecordRagdollUpdate(); GameMain.NilModProfiler.SWSubmarineUpdate.Start(); #endif foreach (Submarine sub in Submarine.Loaded) { sub.Update((float)deltaTime); } #if CLIENT GameMain.NilModProfiler.RecordSubmarineUpdate(); GameMain.NilModProfiler.SWCharacterUpdate.Start(); #endif #if CLIENT GameMain.NilModProfiler.RecordCharacterUpdate(); GameMain.NilModProfiler.SWPhysicsWorldStep.Start(); #endif GameMain.World.Step((float)deltaTime); #if CLIENT GameMain.NilModProfiler.RecordPhysicsWorldStep(); if (!PlayerInput.LeftButtonHeld()) { Inventory.draggingSlot = null; Inventory.draggingItem = null; } #endif }
public Limb(Ragdoll ragdoll, Character character, LimbParams limbParams) { this.ragdoll = ragdoll; this.character = character; this.limbParams = limbParams; wearingItems = new List <WearableSprite>(); dir = Direction.Right; body = new PhysicsBody(limbParams); type = limbParams.Type; if (limbParams.IgnoreCollisions) { body.CollisionCategories = Category.None; body.CollidesWith = Category.None; ignoreCollisions = true; } else { //limbs don't collide with each other body.CollisionCategories = Physics.CollisionCharacter; body.CollidesWith = Physics.CollisionAll & ~Physics.CollisionCharacter & ~Physics.CollisionItem & ~Physics.CollisionItemBlocking; } body.UserData = this; pullJoint = new FixedMouseJoint(body.FarseerBody, ConvertUnits.ToSimUnits(limbParams.PullPos * Scale)) { Enabled = false, MaxForce = ((type == LimbType.LeftHand || type == LimbType.RightHand) ? 400.0f : 150.0f) * body.Mass }; GameMain.World.AddJoint(pullJoint); var element = limbParams.Element; if (element.Attribute("mouthpos") != null) { MouthPos = ConvertUnits.ToSimUnits(element.GetAttributeVector2("mouthpos", Vector2.Zero)); } body.BodyType = BodyType.Dynamic; body.FarseerBody.AngularDamping = LimbAngularDamping; damageModifiers = new List <DamageModifier>(); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "attack": attack = new Attack(subElement, (character == null ? "null" : character.Name) + ", limb " + type); if (attack.DamageRange <= 0) { switch (body.BodyShape) { case PhysicsBody.Shape.Circle: attack.DamageRange = body.radius; break; case PhysicsBody.Shape.Capsule: attack.DamageRange = body.height / 2 + body.radius; break; case PhysicsBody.Shape.Rectangle: attack.DamageRange = new Vector2(body.width / 2.0f, body.height / 2.0f).Length(); break; } attack.DamageRange = ConvertUnits.ToDisplayUnits(attack.DamageRange); } break; case "damagemodifier": damageModifiers.Add(new DamageModifier(subElement, character.Name)); break; } } SerializableProperties = SerializableProperty.GetProperties(this); InitProjSpecific(element); }
public LimbJoint(Limb limbA, Limb limbB, JointParams jointParams, Ragdoll ragdoll) : this(limbA, limbB, Vector2.One, Vector2.One) { this.jointParams = jointParams; this.ragdoll = ragdoll; LoadParams(); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> public override void Update(double deltaTime) { #if DEBUG if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null && !DebugConsole.IsOpen) { var closestSub = Submarine.FindClosest(cam.WorldViewCenter); if (closestSub == null) { closestSub = GameMain.GameSession.Submarine; } Vector2 targetMovement = Vector2.Zero; if (PlayerInput.KeyDown(Keys.I)) { targetMovement.Y += 1.0f; } if (PlayerInput.KeyDown(Keys.K)) { targetMovement.Y -= 1.0f; } if (PlayerInput.KeyDown(Keys.J)) { targetMovement.X -= 1.0f; } if (PlayerInput.KeyDown(Keys.L)) { targetMovement.X += 1.0f; } if (targetMovement != Vector2.Zero) { closestSub.ApplyForce(targetMovement * closestSub.SubBody.Body.Mass * 100.0f); } } #endif foreach (MapEntity e in MapEntity.mapEntityList) { e.IsHighlighted = false; } if (GameMain.GameSession != null) { GameMain.GameSession.Update((float)deltaTime); } if (Level.Loaded != null) { Level.Loaded.Update((float)deltaTime); } if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null) { if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem) { Character.Controlled.SelectedConstruction.UpdateHUD(cam, Character.Controlled); } } Character.UpdateAll(cam, (float)deltaTime); BackgroundCreatureManager.Update(cam, (float)deltaTime); GameMain.ParticleManager.Update((float)deltaTime); StatusEffect.UpdateAll((float)deltaTime); if (Character.Controlled != null && Lights.LightManager.ViewTarget != null) { cam.TargetPos = Lights.LightManager.ViewTarget.WorldPosition; } GameMain.LightManager.Update((float)deltaTime); cam.MoveCamera((float)deltaTime); 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)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); if (!PlayerInput.LeftButtonHeld()) { Inventory.draggingSlot = null; Inventory.draggingItem = null; } }
public static List <Limb> AttachHuskAppendage(Character character, string afflictionIdentifier, XElement appendageDefinition = null, Ragdoll ragdoll = null) { var appendage = new List <Limb>(); if (!(AfflictionPrefab.List.FirstOrDefault(ap => ap.Identifier == afflictionIdentifier) is AfflictionPrefabHusk matchingAffliction)) { DebugConsole.ThrowError($"Could not find an affliction of type 'huskinfection' that matches the affliction '{afflictionIdentifier}'!"); return(appendage); } string nonhuskedSpeciesName = GetNonHuskedSpeciesName(character.SpeciesName, matchingAffliction); string huskedSpeciesName = GetHuskedSpeciesName(nonhuskedSpeciesName, matchingAffliction); string filePath = Character.GetConfigFilePath(huskedSpeciesName); if (!Character.TryGetConfigFile(filePath, out XDocument huskDoc)) { DebugConsole.ThrowError($"Error in '{filePath}': Failed to load the config file for the husk infected species with the species name '{huskedSpeciesName}'!"); return(appendage); } var mainElement = huskDoc.Root.IsOverride() ? huskDoc.Root.FirstElement() : huskDoc.Root; var element = appendageDefinition; if (element == null) { element = mainElement.GetChildElements("huskappendage").FirstOrDefault(e => e.GetAttributeString("affliction", string.Empty).Equals(afflictionIdentifier)); } if (element == null) { DebugConsole.ThrowError($"Error in '{filePath}': Failed to find a huskappendage that matches the affliction with an identifier '{afflictionIdentifier}'!"); return(appendage); } string pathToAppendage = element.GetAttributeString("path", string.Empty); XDocument doc = XMLExtensions.TryLoadXml(pathToAppendage); if (doc == null) { return(appendage); } if (ragdoll == null) { ragdoll = character.AnimController; } if (ragdoll.Dir < 1.0f) { ragdoll.Flip(); } var limbElements = doc.Root.Elements("limb").ToDictionary(e => e.GetAttributeString("id", null), e => e); foreach (var jointElement in doc.Root.Elements("joint")) { if (limbElements.TryGetValue(jointElement.GetAttributeString("limb2", null), out XElement limbElement)) { var jointParams = new RagdollParams.JointParams(jointElement, ragdoll.RagdollParams); Limb attachLimb = null; if (matchingAffliction.AttachLimbId > -1) { attachLimb = ragdoll.Limbs.FirstOrDefault(l => l.Params.ID == matchingAffliction.AttachLimbId); } else if (matchingAffliction.AttachLimbName != null) { attachLimb = ragdoll.Limbs.FirstOrDefault(l => l.Name == matchingAffliction.AttachLimbName); } else if (matchingAffliction.AttachLimbType != LimbType.None) { attachLimb = ragdoll.Limbs.FirstOrDefault(l => l.type == matchingAffliction.AttachLimbType); } if (attachLimb == null) { DebugConsole.Log("Attachment limb not defined in the affliction prefab or no matching limb could be found. Using the appendage definition as it is."); attachLimb = ragdoll.Limbs.FirstOrDefault(l => l.Params.ID == jointParams.Limb1); } if (attachLimb != null) { jointParams.Limb1 = attachLimb.Params.ID; var appendageLimbParams = new RagdollParams.LimbParams(limbElement, ragdoll.RagdollParams) { // Ensure that we have a valid id for the new limb ID = ragdoll.Limbs.Length }; jointParams.Limb2 = appendageLimbParams.ID; Limb huskAppendage = new Limb(ragdoll, character, appendageLimbParams); huskAppendage.body.Submarine = character.Submarine; huskAppendage.body.SetTransform(attachLimb.SimPosition, attachLimb.Rotation); ragdoll.AddLimb(huskAppendage); ragdoll.AddJoint(jointParams); appendage.Add(huskAppendage); } else { DebugConsole.ThrowError("Attachment limb not found!"); } } } return(appendage); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> public override void Update(double deltaTime) { #if RUN_PHYSICS_IN_SEPARATE_THREAD physicsTime += deltaTime; lock (updateLock) { #endif #if DEBUG && CLIENT if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null && !DebugConsole.IsOpen && GUI.KeyboardDispatcher.Subscriber == null) { var closestSub = Submarine.FindClosest(cam.WorldViewCenter); if (closestSub == null) { closestSub = GameMain.GameSession.Submarine; } Vector2 targetMovement = Vector2.Zero; if (PlayerInput.KeyDown(Keys.I)) { targetMovement.Y += 1.0f; } if (PlayerInput.KeyDown(Keys.K)) { targetMovement.Y -= 1.0f; } if (PlayerInput.KeyDown(Keys.J)) { targetMovement.X -= 1.0f; } if (PlayerInput.KeyDown(Keys.L)) { targetMovement.X += 1.0f; } if (targetMovement != Vector2.Zero) { closestSub.ApplyForce(targetMovement * closestSub.SubBody.Body.Mass * 100.0f); } } #endif GameTime += deltaTime; foreach (PhysicsBody body in PhysicsBody.List) { if (body.Enabled) { body.Update(); } } foreach (MapEntity e in MapEntity.mapEntityList) { e.IsHighlighted = false; } if (GameMain.GameSession != null) { GameMain.GameSession.Update((float)deltaTime); } #if CLIENT var sw = new System.Diagnostics.Stopwatch(); sw.Start(); GameMain.ParticleManager.Update((float)deltaTime); sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("ParticleUpdate", sw.ElapsedTicks); sw.Restart(); if (Level.Loaded != null) { Level.Loaded.Update((float)deltaTime, cam); } sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("LevelUpdate", sw.ElapsedTicks); if (Character.Controlled != null) { if (Character.Controlled.SelectedConstruction != null && Character.Controlled.CanInteractWith(Character.Controlled.SelectedConstruction)) { Character.Controlled.SelectedConstruction.UpdateHUD(cam, Character.Controlled, (float)deltaTime); } if (Character.Controlled.Inventory != null) { foreach (Item item in Character.Controlled.Inventory.Items) { if (item == null) { continue; } if (Character.Controlled.HasEquippedItem(item)) { item.UpdateHUD(cam, Character.Controlled, (float)deltaTime); } } } } sw.Restart(); Character.UpdateAll((float)deltaTime, cam); #elif SERVER if (Level.Loaded != null) { Level.Loaded.Update((float)deltaTime, Camera.Instance); } Character.UpdateAll((float)deltaTime, Camera.Instance); #endif #if CLIENT sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("CharacterUpdate", sw.ElapsedTicks); sw.Restart(); #endif StatusEffect.UpdateAll((float)deltaTime); #if CLIENT sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("StatusEffectUpdate", sw.ElapsedTicks); sw.Restart(); if (Character.Controlled != null && Lights.LightManager.ViewTarget != null) { Vector2 targetPos = Lights.LightManager.ViewTarget.DrawPosition; if (Lights.LightManager.ViewTarget == Character.Controlled && (CharacterHealth.OpenHealthWindow != null || CrewManager.IsCommandInterfaceOpen)) { Vector2 screenTargetPos = new Vector2(0.0f, GameMain.GraphicsHeight * 0.5f); if (CrewManager.IsCommandInterfaceOpen) { screenTargetPos.X = GameMain.GraphicsWidth * 0.5f; } else { screenTargetPos = CharacterHealth.OpenHealthWindow.Alignment == Alignment.Left ? new Vector2(GameMain.GraphicsWidth * 0.75f, GameMain.GraphicsHeight * 0.5f) : new Vector2(GameMain.GraphicsWidth * 0.25f, GameMain.GraphicsHeight * 0.5f); } Vector2 screenOffset = screenTargetPos - new Vector2(GameMain.GraphicsWidth / 2, GameMain.GraphicsHeight / 2); screenOffset.Y = -screenOffset.Y; targetPos -= screenOffset / cam.Zoom; } cam.TargetPos = targetPos; } cam.MoveCamera((float)deltaTime); #endif foreach (Submarine sub in Submarine.Loaded) { sub.SetPrevTransform(sub.Position); } foreach (PhysicsBody body in PhysicsBody.List) { if (body.Enabled) { body.SetPrevTransform(body.SimPosition, body.Rotation); } } #if CLIENT MapEntity.UpdateAll((float)deltaTime, cam); #elif SERVER MapEntity.UpdateAll((float)deltaTime, Camera.Instance); #endif #if CLIENT sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("MapEntityUpdate", sw.ElapsedTicks); sw.Restart(); #endif Character.UpdateAnimAll((float)deltaTime); #if CLIENT Ragdoll.UpdateAll((float)deltaTime, cam); #elif SERVER Ragdoll.UpdateAll((float)deltaTime, Camera.Instance); #endif #if CLIENT sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("AnimUpdate", sw.ElapsedTicks); sw.Restart(); #endif foreach (Submarine sub in Submarine.Loaded) { sub.Update((float)deltaTime); } #if CLIENT sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("SubmarineUpdate", sw.ElapsedTicks); sw.Restart(); #endif #if !RUN_PHYSICS_IN_SEPARATE_THREAD try { GameMain.World.Step((float)Timing.Step); } catch (WorldLockedException e) { string errorMsg = "Attempted to modify the state of the physics simulation while a time step was running."; DebugConsole.ThrowError(errorMsg, e); GameAnalyticsManager.AddErrorEventOnce("GameScreen.Update:WorldLockedException" + e.Message, GameAnalyticsSDK.Net.EGAErrorSeverity.Critical, errorMsg); } #endif #if CLIENT sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("Physics", sw.ElapsedTicks); #endif #if CLIENT if (!PlayerInput.PrimaryMouseButtonHeld()) { Inventory.draggingSlot = null; Inventory.draggingItem = null; } #endif #if RUN_PHYSICS_IN_SEPARATE_THREAD } #endif }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> public override void Update(double deltaTime) { #if DEBUG && CLIENT if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null && !DebugConsole.IsOpen && GUI.KeyboardDispatcher.Subscriber == null) { var closestSub = Submarine.FindClosest(cam.WorldViewCenter); if (closestSub == null) { closestSub = GameMain.GameSession.Submarine; } Vector2 targetMovement = Vector2.Zero; if (PlayerInput.KeyDown(Keys.I)) { targetMovement.Y += 1.0f; } if (PlayerInput.KeyDown(Keys.K)) { targetMovement.Y -= 1.0f; } if (PlayerInput.KeyDown(Keys.J)) { targetMovement.X -= 1.0f; } if (PlayerInput.KeyDown(Keys.L)) { targetMovement.X += 1.0f; } if (targetMovement != Vector2.Zero) { closestSub.ApplyForce(targetMovement * closestSub.SubBody.Body.Mass * 100.0f); } } #endif foreach (PhysicsBody body in PhysicsBody.List) { body.Update((float)deltaTime); } foreach (MapEntity e in MapEntity.mapEntityList) { e.IsHighlighted = false; } if (GameMain.GameSession != null) { GameMain.GameSession.Update((float)deltaTime); } #if CLIENT var sw = new System.Diagnostics.Stopwatch(); sw.Start(); GameMain.ParticleManager.Update((float)deltaTime); sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("ParticleUpdate", sw.ElapsedTicks); sw.Restart(); GameMain.LightManager.Update((float)deltaTime); sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("LightUpdate", sw.ElapsedTicks); sw.Restart(); #endif if (Level.Loaded != null) { Level.Loaded.Update((float)deltaTime, cam); } #if CLIENT sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("LevelUpdate", sw.ElapsedTicks); if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null && Character.Controlled.CanInteractWith(Character.Controlled.SelectedConstruction)) { Character.Controlled.SelectedConstruction.UpdateHUD(cam, Character.Controlled, (float)deltaTime); } sw.Restart(); #endif Character.UpdateAll((float)deltaTime, cam); #if CLIENT sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("CharacterUpdate", sw.ElapsedTicks); sw.Restart(); #endif StatusEffect.UpdateAll((float)deltaTime); #if CLIENT sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("StatusEffectUpdate", sw.ElapsedTicks); sw.Restart(); if (Character.Controlled != null && Lights.LightManager.ViewTarget != null) { Vector2 targetPos = Lights.LightManager.ViewTarget.DrawPosition; if (Lights.LightManager.ViewTarget == Character.Controlled && CharacterHealth.OpenHealthWindow != null) { Vector2 screenTargetPos = CharacterHealth.OpenHealthWindow.Alignment == Alignment.Left ? new Vector2(GameMain.GraphicsWidth * 0.75f, GameMain.GraphicsHeight * 0.5f) : new Vector2(GameMain.GraphicsWidth * 0.25f, GameMain.GraphicsHeight * 0.5f); Vector2 screenOffset = screenTargetPos - new Vector2(GameMain.GraphicsWidth / 2, GameMain.GraphicsHeight / 2); screenOffset.Y = -screenOffset.Y; targetPos -= screenOffset / cam.Zoom; } cam.TargetPos = targetPos; } #endif cam.MoveCamera((float)deltaTime); foreach (Submarine sub in Submarine.Loaded) { sub.SetPrevTransform(sub.Position); } foreach (PhysicsBody pb in PhysicsBody.List) { pb.SetPrevTransform(pb.SimPosition, pb.Rotation); } MapEntity.UpdateAll((float)deltaTime, cam); #if CLIENT sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("MapEntityUpdate", sw.ElapsedTicks); sw.Restart(); #endif Character.UpdateAnimAll((float)deltaTime); Ragdoll.UpdateAll((float)deltaTime, cam); #if CLIENT sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("AnimUpdate", sw.ElapsedTicks); sw.Restart(); #endif foreach (Submarine sub in Submarine.Loaded) { sub.Update((float)deltaTime); } #if CLIENT sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("SubmarineUpdate", sw.ElapsedTicks); sw.Restart(); #endif GameMain.World.Step((float)deltaTime); #if CLIENT sw.Stop(); GameMain.PerformanceCounter.AddElapsedTicks("Physics", sw.ElapsedTicks); #endif #if CLIENT if (!PlayerInput.LeftButtonHeld()) { Inventory.draggingSlot = null; Inventory.draggingItem = null; } #endif }