public void Update(IGameTimeService gameTime) { if (WindowList.Count != 0) { for (int i = 0; i < WindowList.Count; i++) { WindowList[i].Update(new Vector2(ViewportWidth, ViewportHeight)); } } }
public override void Update(IGameTimeService gameTime) { _lastGameTime = gameTime; if (Ship.IsLocalSim) { Simulate(gameTime); } _coroutineManager.Update(gameTime); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected sealed override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); if (!Directory.Exists("cfg")) { Directory.CreateDirectory("cfg"); } if (!Directory.Exists("addons")) { Directory.CreateDirectory("addons"); } ComponentCache.RegisterComponents(); HeaderCache.RegisterHeaders(); NetworkMethodCache.RegisterSendables(); TileTypeCache.RegisterTileTypes(); ServiceLocator.RegisterService(Content); ServiceLocator.RegisterService(spriteBatch); ServiceLocator.RegisterService(graphics); ServiceLocator.RegisterImplementations(); DefineImplementations(); ServiceLocator.RegisterServices(); GameState.RegisterStates(); ServiceLocator.Get <IPerformanceProfiler>().StartSession(false); for (var i = 0; i < 1000; i++) { //var world = new ObjectFactory<ThreeTierWorld>().Make(1, 1); } var time = ServiceLocator.Get <IPerformanceProfiler>().StopSession(); Debug.WriteLine(time.TotalTime.Milliseconds); ServiceLocator.Get <IPropertyService>().Load("app"); SteamCallback.Create(); LuaContext.LoadAddons(); Window.TextInput += ServiceLocator.Get <ITextInputService>().Execute; camera = ServiceLocator.Get <ICamera>(); input = ServiceLocator.Get <IInput>(); gameTimeService = ServiceLocator.Get <IGameTimeService>(); stateService = ServiceLocator.Get <IStateService>(); client = ServiceLocator.Get <IClient>(); LoadGameContent(); }
public void Update(IGameTimeService gameTime) { for (int i = 0; i < Warpholes.Count; i++) { Warpholes[i].Update(gameTime); if (_particleManager != null) { _particleManager.TriggerEffect(ConvertUnits.ToDisplayUnits(Warpholes[i].body.Position), ParticleEffectType.WarpHoleEffect, 1); } } }
private void _sendTimeSync(IGameTimeService gameTime) { var data = new MessageTimeSync(); data.TimeMS = gameTime.TotalMilliseconds; NetOutgoingMessage outMessage = _clientManager.Client.CreateMessage(); data.WriteToLidgrenMessage_ToServer(MessageTypes.TimeGet, outMessage); _clientManager.Client.SendMessage(outMessage, _clientManager.CurrentSlaveConnection, NetDeliveryMethod.UnreliableSequenced); _clientManager.LastSentServerTimeSync = gameTime.TotalMilliseconds; }
void _weaponPressed(int slot, IGameTimeService gameTime, Ship playerShip, PlayerPilot playerPilot) { if (playerShip.GetWeapon(slot) is IChargable) { ((IChargable)(playerShip.GetWeapon(slot))).Charge(gameTime.ElapsedMilliseconds); playerShip.GetWeapon(slot).IsBeingHeld = true; } else { playerShip.TryFireWeapon(gameTime, slot); } playerPilot.HoldingPosition = false; }
public override void Simulate(IGameTimeService gameTime) { if (CurrentTarget == null || !CurrentTarget.IsBodyValid) { _findTarget(_targetRange); } else { AIHelper.TurnTowardPosition(_missile.Rotation, _missile.CurrentTurnRate, _missile.Position, CurrentTarget.Position, gameTime.ElapsedMilliseconds, 1f); } _missile.ThrustForward(); }
public override void Update(IGameTimeService gameTime) { base.Update(gameTime); float liveTime = (float)TimeKeeper.MsSinceInitialization - _creationTime; //Keeping it simple, linear decrease in velocity to 0 if (liveTime / _lifetime < _zeroFraction) { float newX = _initialVelocity.X + ((-(1 / _zeroFraction) * _initialVelocity.X / (float)_lifetime) * liveTime);; float newY = _initialVelocity.Y + ((-(1 / _zeroFraction) * _initialVelocity.Y / (float)_lifetime) * liveTime);; LinearVelocity = new Vector2(newX, newY); } }
public override void Update(IGameTimeService gameTime) { var target = GetTarget(); if ((Ship.Position - target).Length() < Tolerance && Ship.LinearVelocity.Length() <= .1) { // Tolerance is randomized so all ships don't move to the same location // Should probably move tolerance outside of this loop so that it isn't set on every iteration if ((Ship.Position - target).Length() < 3f && Ship.LinearVelocity.Length() > .1f) { // Ship is within range of the destination, start slowing down //StopShip(_lastGameTime); } } Done = true; }
public virtual void Update(IGameTimeService gameTime) { // Performance & Time Variables oneSecondTimer += gameTime.ElapsedMilliseconds; // Timer variable totalIterations++; // Amount of times Update has been called if (oneSecondTimer > 1000) // If 1000ms has passed, set performance variables and reset. { ups = iterationsPerSecond; // Updates per second fps = fpsIteration; iterationsPerSecond = totalIterations; totalIterations = 0; oneSecondTimer = 0; fpsIteration = 0; } }
public void Update(IGameTimeService gameTime) { base.Update(gameTime); #if DEBUG if (KeyboardManager.LeaveToPlanet.IsBindTapped()) { ConsoleManager.WriteLine("Sending leave to planet request...", ConsoleMessageType.Notification); LeaveToPlanet(); } else if (KeyboardManager.LeaveToSpace.IsBindTapped()) { ConsoleManager.WriteLine("Sending leave to space request...", ConsoleMessageType.Notification); LeaveToSpace(); } #endif }
public void Update(IGameTimeService gameTime) { // Maybe do some nifty type detection here // float values are total seconds // bool value of false should halt coroutine execution // int value skips x number of frames var routine = _routines.Current as Routine; if (routine == null || routine.Done) { Step(); } else { routine.Update(gameTime); } }
/// <summary> /// Steps the world. /// </summary> public void Update(IGameTimeService gameTime) { if (_isUpdating) { Console.WriteLine("Already updating!"); } _isUpdating = true; try { World.Step(Math.Min((float)gameTime.ElapsedMilliseconds * 0.001f, (1f / 30f))); } catch (Exception e) { Console.WriteLine("WTF bro?"); } _isUpdating = false; }
public override void Update(IGameTimeService gameTime) { ViewModel.Update(gameTime); _gameUserInterface.Update(gameTime); if (!IsLoaded) { return; } var interfaceJson = LowercaseContractResolver.SerializeObject(ViewModel.CurrentGlobalGameInterfaceState); WebLayer.CallJavascriptFunctionAsync( "UpdateGameInterface", interfaceJson ); }
public override void Update(IGameTimeService gameTime) { base.Update(gameTime); if ((TimeKeeper.MsSinceInitialization - _blinkOffset) % (_blinkOffDuration + _blinkOnDuration) > _blinkOffDuration) { Texture = _blinkOnTex; } else { Texture = _blinkOffTex; } if (_isTriggered && TimeKeeper.MsSinceInitialization - _triggerTime > _fuseDelay) { Weapon.Fire_LocalOrigin(Rotation, 0, false); } }
public void Update(IGameTimeService gameTime) { toRemove.Clear(); foreach (var kvp in _objectsToSimulate) { if (!kvp.Value.IsBodyValid) { toRemove.Add(kvp.Value); continue; } kvp.Value.Simulate(gameTime); } // This is probably a bad idea and I'll get rid of it later. foreach (ISimulatable s in toRemove) { _objectsToSimulate.Remove(s.Id); } }
public override void Update(IGameTimeService gameTime) { //if (!_enumerator.MoveNext()) //{ // Done = true; //} //var result = _enumerator.Current.ResultType; //switch (result) //{ // case CoroutineResultType.Wait: // case CoroutineResultType.Done: // break; // default: // throw new ArgumentOutOfRangeException(); //} }
public static PositionUpdateData GetPositionUpdate(this Ship s, IGameTimeService gameTime) { var boosting = s.ThrustStatusForServer || s.Thrusting; return(new PositionUpdateData( PositionUpdateTargetType.Ship, s.Id, s.Position.X, s.Position.Y, s.Rotation, s.LinearVelocity.X, s.LinearVelocity.Y, s.AngularVelocity, s.Shields.CurrentShields, s.CurrentHealth, boosting, gameTime.TotalMilliseconds )); }
public override void Update(IGameTimeService gameTime) { // Kill projectile if it has been on the screen for its lifetime base.Update(gameTime); numRecursiveCalls = 0; double diff = TimeKeeper.MsSinceInitialization - _lastTimeStamp; // If the projectile is still around, update it futurePos = Position + (float)(TimeKeeper.MsSinceInitialization - _lastTimeStamp) * LinearVelocity; CheckCollisions(); Position = futurePos; _lastTimeStamp = (float)TimeKeeper.MsSinceInitialization; }
public void Update(IGameTimeService gameTime) { try { foreach (var kvp in _shipList) { kvp.Value.Update(gameTime); } } catch (Exception e) { ConsoleManager.WriteLine(e); } _checkKeys(gameTime); if (SendPositionUpdates && gameTime.TotalMilliseconds - _lastPositionUpdateTime > _positionUpdateInterval) { _sendPositionUpdates(gameTime); } }
public override void Simulate(IGameTimeService gameTime) { if (CurrentTarget == null || !CurrentTarget.IsBodyValid) { _findTarget(_targetRange); //_missile.ThrustForward(); } else { //Rotate the missile so that it is thrusting and pointing in the correct direction //AIHelper.TurnTowardPosition(ref newRotation, _missile.CurrentTurnRate, _missile.Position, CurrentTarget.Position, (float)gameTime.ElapsedMilliseconds, 0.001f); //Get corrective acceleration //Lower knav (last argument) to reduce effectiveness of correction Vector2 correctiveAccel = AIHelper.PNav(_missile.Position, _missile.LinearVelocity, CurrentTarget.Position, CurrentTarget.LinearVelocity, 6f); _missile.CorrectVelocity(correctiveAccel); //_missile.ThrustForward(); } _missile.ThrustForward(); }
public void Simulate(IGameTimeService gameTime) { _currentTurnRate = Stats.BaseTurnRate + (float)Math.Pow(Math.E, (gameTime.TotalMilliseconds - _creationTime) / 1000f - 1f);//e^(x-2)/2, function I pulled out of my ass, missile turns faster and faster as it ages if (Body.LinearVelocity.Length() >= Stats.BaseSpeed) { Body.LinearDamping = Stats.SpeedDampValue; } else { Body.LinearDamping = .0001f; } _pilot.Simulate(gameTime); if (_pilot.CurrentTarget != null && (Body.Position - _pilot.CurrentTarget.Position).Length() < .1f) { Terminate(); } }
/// <summary> /// Applies thrust in the direction opposite to linear velocity to slow the ship to a stop /// </summary> public void StopShip(IGameTimeService gameTime) { if (Ship.LinearVelocity.Length() == 0) { Ship.Thrusting = false; return; } else if (Ship.LinearVelocity.Length() < .05) { Ship.LinearVelocity = new Vector2(0, 0); Ship.Thrusting = false; return; } if (!TurnTowardPosition(Ship.Position - Ship.LinearVelocity, gameTime, .01f)) { Ship.Thrust(ThrustTypes.Forward); Ship.Thrusting = true; } }
public void Update(IGameTimeService gameTime) { Camera.Pos = ConvertUnits.ToDisplayUnits(_clientShipManager.PlayerShip.Position); Camera.UpdateCameraShake(); // Todo: See if zooming in space is broken, if it is, then finish refactoring RotationalCamera away. //Temporary fix for now, it was broken. if (MouseManager.ScrolledUp || GamepadManager.ZoomIn.IsBindTapped()) { ConsoleManager.WriteLine("Warning: Implement UI Zoom using ChangeZoom container."); Camera.Zoom += .1f; } if (MouseManager.ScrolledDown || GamepadManager.ZoomOut.IsBindTapped()) { ConsoleManager.WriteLine("Warning: Implement UI Zoom using ChangeZoom container."); Camera.Zoom -= .1f; } if (_spaceViewModel.StructurePlacementModeEnabled) { if (MouseManager.RightButtonPressed) { // Cancel with right click _spaceViewModel.StructurePlacementModeEnabled = false; } } if (_clientShipManager.PlayerShip != null) { var shipDifference = _oldPosition - ConvertUnits.ToDisplayUnits(_clientShipManager.PlayerShip.Position); _background.Update(_clientShipManager.PlayerShip.Position, shipDifference); _spaceObjectManager.Update(gameTime, _clientShipManager.PlayerShip != null && _clientShipManager.PlayerShip.EnterMode); _oldPosition = ConvertUnits.ToDisplayUnits(_clientShipManager.PlayerShip.Position); } }
public void Update(IGameTimeService gameTime) { if (StateContainer == null)//Currently should only be possible if first update is called after initialization before GameStateManager sets the state container { return; } switch (StateContainer.CurrentAreaType) { case GameStateType.Space: case GameStateType.Planet: { var stateContainer = StateContainer as PlayableUIStateManagerContainer; // Don't think this should be possible, but adding it just in case if (stateContainer.PlayerShipManager.PlayerShip == null) { throw new Exception("Inconsistent UI State. Bailing out!"); } CurrentGlobalGameInterfaceState = new GlobalGameInterfaceState( new StatBarDisplayState( UpdateShipStatDisplayState(stateContainer.PlayerShipManager.PlayerShip), UpdateWeaponsStatDisplayState(stateContainer.PlayerShipManager.PlayerShip) ) ); break; } default: { //???Not sure what the plan is from here CurrentGlobalGameInterfaceState = null; break; } } }
public void Update(IGameTimeService gameTime) { _activeState.StateWillUpdate(gameTime); // Update current state foreach (var updatable in _activeState.AsynchronousUpdateList) { // Async, but not awaited, order shouldn't matter. updatable.Update(gameTime); } // Update current state foreach (var updatable in _activeState.SynchronousUpdateList) { updatable.Update(gameTime); } // Update view state foreach (var updatable in _activeState.ViewUpdateList) { updatable.Update(gameTime); } _nextWebView.Update(gameTime); _globalGameWebLayer.Update(gameTime); _activeState.StateDidUpdate(gameTime); // If there is a pending state change, call setState until NextState sets status to Active if (_pendingStateChange) { SetState(_nextState.StateType); } #if DEBUG Debugging.Update(); #endif }
public override void Update(IGameTimeService gameTime) { #if ADMIN foreach (GravityObject g in _gravityObjects) // Testing stuff { g.Gravitate(_clientShipManager._shipList.Values, _clientShipManager.PlayerShip); } #endif foreach (var s in Structures) { switch (s.StructureType) { case StructureTypes.LaserTurret: ((Turret)s).Update(gameTime); break; default: s.Update(gameTime); break; } } //switch (State) //{ // case GameStates.updating: // break; // case GameStates.transitional: // _bus.Publish(new MChangeStateMessage(GameStates.Port)); // break; //} _lastTimeStamp = gameTime.TotalMilliseconds; }
public bool TryFireWeapon(IGameTimeService gameTime, int slot) { if (_weapons.Count <= slot) { ConsoleManager.WriteLine("Error: invalid slot passed to TryFireWeapon.", ConsoleMessageType.Error); return(false); } if (!_weapons[slot].CanFire()) { return(false); } byte charge = 0; if (_weapons[slot] is IChargable) { charge = ((IChargable)_weapons[slot]).CurrentPctCharge; } _weapons[slot].Fire_LocalOrigin(Rotation, charge, true); _weapons[slot].WaitingForFireResponse = true; #if ADMIN if (Debugging.DisableNetworking) { _weapons[slot].WaitingForFireResponse = false; } #endif _weapons[slot].TimeOfWaitStart = gameTime.TotalMilliseconds; return(true); }
/// <summary> /// Sends a position update to the server. /// </summary> /// <param name="currentAreaId"></param> /// <param name="shipsToSend"></param> /// <param name="sendingPlayerId">Null if sent from simulator, otherwise must be sent so that a client is not forwarded its own position updates</param> public void SendPositionUpdate(IGameTimeService gameTime, int currentAreaId, IEnumerable <Ship> shipsToSend, int?sendingPlayerId = null) { if (shipsToSend == null || shipsToSend.Count() == 0) { return; } var positionUpdateData = new MessagePositionUpdateData(sendingPlayerId, currentAreaId); //PositionUpdateData playerShipData = new PositionUpdateData(ClientShipManager.PlayerShip.Id, ClientShipManager.PlayerShip.Position.X, ClientShipManager.PlayerShip.Position.Y, ClientShipManager.PlayerShip.Rotated, ClientShipManager.PlayerShip.LinearVelocity.X, ClientShipManager.PlayerShip.LinearVelocity.Y, ClientShipManager.PlayerShip.AngularVelocity, ClientShipManager.PlayerShip.Shields.CurrentShields, ClientShipManager.PlayerShip.CurrentHealth, ClientShipManager.PlayerShip.ThrustStatusForServer); //data.UpdateDataObjects.Add(playerShipData); //ClientShipManager.PlayerShip.ThrustStatusForServer = false; var positionUpdates = shipsToSend.Where(s => s.IsBodyValid && s.SendPositionUpdates).Select(s => { s.ThrustStatusForServer = false; return(s.GetPositionUpdate(gameTime)); }); positionUpdateData.UpdateDataObjects.AddRange(positionUpdates); _messenger.SendMessageToServer(MessageTypes.PositionUpdateData, positionUpdateData); }
public override void Simulate(IGameTimeService gameTime) { if (!IsBodyValid) { return; } Weapon.Update(gameTime); DelayTime += gameTime.ElapsedMilliseconds; // Used for Loading. #region Logic if (logicState != LogicStates.Resting && (CurrentTarget == null || !CurrentTarget.IsBodyValid)) { CurrentTarget = null; logicState = LogicStates.SearchingForTarget; } switch (logicState) { case LogicStates.Resting: if (PotentialTargets.Count > 0) { logicState = LogicStates.SearchingForTarget; } break; case LogicStates.SearchingForTarget: FindTarget(); if (CurrentTarget != null) { logicState = LogicStates.TurningTowardTarget; } break; case LogicStates.TurningTowardTarget: if (!CurrentTarget.IsBodyValid) { PotentialTargets.Remove(CurrentTarget.Id); CurrentTarget = null; logicState = LogicStates.Resting; break; } if (gameTime.TotalMilliseconds - _lastTargetCheckTime > 200) //Retargets closest item 5 times per second //Retargeting is expensive, if turrets lag this needs to be rethought { _lastTargetCheckTime = (float)gameTime.TotalMilliseconds; CurrentTarget = null; logicState = LogicStates.Resting; break; } if (Vector2.Distance(CurrentTarget.Position, Position) > turretRange) { CurrentTarget = null; logicState = LogicStates.Resting; break; } var result = AIHelper.TurnTowardPosition(Rotation, rotationSpeed, Position, CurrentTarget.Position, gameTime.ElapsedMilliseconds, AimTolerance); Rotation = result.Rotation; if (!result.Rotated) { if (Weapon.CanFire()) { Weapon.TimeOfWaitStart = gameTime.TotalMilliseconds; Weapon.Fire_LocalOrigin(Rotation, 0, true); Weapon.WaitingForFireResponse = true; } } break; } #endregion OldTime += gameTime.ElapsedMilliseconds; // Updates Time since Last Action }