disable mouse polling when window is inactive

pull/1/head
cosmonaut 2020-08-06 16:28:47 -07:00
parent 96b0990418
commit 2e3a331d13
2 changed files with 14 additions and 4 deletions

View File

@ -13,6 +13,13 @@ namespace KavTest.Engines
)] )]
public class InputEngine : Engine public class InputEngine : Engine
{ {
private Game Game { get; }
public InputEngine(Game game)
{
Game = game;
}
public override void Update(double dt) public override void Update(double dt)
{ {
var keyboardState = Keyboard.GetState(); var keyboardState = Keyboard.GetState();
@ -38,6 +45,8 @@ namespace KavTest.Engines
SendMessage(new MoveCameraMessage(new Vector3(5, 0, 0))); SendMessage(new MoveCameraMessage(new Vector3(5, 0, 0)));
} }
if (Game.IsActive)
{
if (SomeComponent<CameraComponent>()) if (SomeComponent<CameraComponent>())
{ {
var cameraEntity = ReadEntity<CameraComponent>(); var cameraEntity = ReadEntity<CameraComponent>();
@ -45,4 +54,5 @@ namespace KavTest.Engines
} }
} }
} }
}
} }

View File

@ -50,7 +50,7 @@ namespace KavTest
Smuggler.Importer.ImportGLB(GraphicsDevice, File.OpenRead("Content/rustysphere.glb")) Smuggler.Importer.ImportGLB(GraphicsDevice, File.OpenRead("Content/rustysphere.glb"))
); );
WorldBuilder.AddEngine(new InputEngine()); WorldBuilder.AddEngine(new InputEngine(this));
WorldBuilder.AddEngine(new AngularVelocityEngine()); WorldBuilder.AddEngine(new AngularVelocityEngine());
WorldBuilder.AddEngine(new MotionEngine()); WorldBuilder.AddEngine(new MotionEngine());
WorldBuilder.AddEngine(new CameraEngine()); WorldBuilder.AddEngine(new CameraEngine());