private void UpdateTimer() { if (WindowsHelper.IsInDesignMode) { return; } if (_gameTimer == null) { if (AssociatedObject.IsLoaded) { var editor = EditorHelper.GetEditor(AssociatedObject).ThrowIfMissing(); _gameTimer = editor.Services.GetInstance <IGameTimer>().ThrowIfMissing(); _gameExtension = editor.Extensions.OfType <GameExtension>().FirstOrDefault().ThrowIfMissing(); } else { AssociatedObject.Loaded += (s, e) => UpdateTimer(); return; } } // Start/stop timer based on current state. var view = AssociatedObject; if (view != null && view.IsFocused && IsEnabled) { _gameExtension.GameLoopNewFrame += OnTick; } else { _gameExtension.GameLoopNewFrame -= OnTick; } }
public override void Execute() { //If we're not the first context, we need to shut down the AudioListener //This is one way to do it, but there is no "right" way if (context != Context.firstContext) { } //MonoBehaviours can only be injected after they've been instantiated manually. //Here we create the main GameLoop, attaching it to the ContextView. //Attach the GameLoop MonoBehaviour to the contextView... contextView.AddComponent <GameLoop>(); IGameTimer timer = contextView.GetComponent <GameLoop>(); //...then bind it for injection injectionBinder.Bind <IGameTimer>().ToValue(timer); GameObject go = new GameObject(); go.name = "Scoreboard"; go.AddComponent <ScoreboardView>(); go.transform.parent = contextView.transform; }
IGameTimer setupTimer(float maxTime, float timeStep) { GameObject timerObject = new GameObject(); timer = timerObject.AddComponent <MonoTimer>(); return(timer.Setup(maxTime, timeStep)); }
/// <summary> /// 回收 /// 在执行End事件后,会自动调用 /// </summary> /// <param name="_timer"></param> public void Recover(IGameTimer _timer) { if (null != _timer) { cachePool.Recover((HKTimer)_timer); } }
public override void Execute() { //If we're not the first context, we need to shut down the AudioListener //This is one way to do it, but there is no "right" way if (context != Context.firstContext) { #pragma warning disable CS0618 // Type or member is obsolete AudioListener[] audioListeners = Camera.FindSceneObjectsOfType(typeof(AudioListener)) as AudioListener[]; #pragma warning restore CS0618 // Type or member is obsolete int aa = audioListeners.Length; for (int a = 1; a < aa; a++) { audioListeners[a].enabled = false; } } //MonoBehaviours can only be injected after they've been instantiated manually. //Here we create the main GameLoop, attaching it to the ContextView. //Attach the GameLoop MonoBehaviour to the contextView... contextView.AddComponent <GameLoop>(); IGameTimer timer = contextView.GetComponent <GameLoop>(); //...then bind it for injection injectionBinder.Bind <IGameTimer>().ToValue(timer); GameObject go = new GameObject(); go.name = "Scoreboard"; go.AddComponent <ScoreboardView>(); go.transform.parent = contextView.transform; }
public override void Execute() { contextView.AddComponent <GameLoop>(); IGameTimer timer = contextView.GetComponent <GameLoop>(); injectionBinder.Bind <IGameTimer>().ToValue(timer); }
public override void Execute() { IGameTimer timer = contextView.AddComponent <GameLoop>(); injectionBinder.Bind <IGameTimer>().ToValue(timer); Debug.Log("InitBaseDataCommand Execute"); }
public CommandIntake(Func <JsonDocument, PointsEvent> eventsFactory, Func <int> maxPointsPerAction, IGameTimer gameTimer, IEventWriter <PointsEvent> pointsEventWriter, PlayerCache playerCache, PlayerStorage playerStorage) { _eventsFactory = eventsFactory; _maxPointsPerAction = maxPointsPerAction; _gameTimer = gameTimer; _pointsEventWriter = pointsEventWriter; _playerCache = playerCache; _playerStorage = playerStorage; }
private void RemoveGameLoop() { Editor.Services.Unregister(typeof(IGameTimer)); _timer.Stop(); _timer = null; ComponentDispatcher.ThreadIdle -= OnApplicationIdle; CompositionTarget.Rendering -= OnCompositionTargetRendering; _clock.Stop(); _clock = null; }
/// <summary> /// Konstruktor klasy /// </summary> static GameEngine() { //Tworzy obiekt GameTimera GameTimer = new GameTimer(); ActionList = new ActionList(); GameTimer.OnTick += GameTimer_OnTick; Enabled = false; // Określa wstępną częstotliwość zegara GameTimer.Interval = 1; }
/// <summary> /// Called when the <see cref="Behavior{T}"/> is about to detach from the /// <see cref="Behavior{T}.AssociatedObject"/>. /// </summary> /// <remarks> /// When this method is called, detaching can not be canceled. The /// <see cref="Behavior{T}.AssociatedObject"/> is still set. /// </remarks> protected override void OnDetaching() { AssociatedObject.GotFocus -= OnFocusChanged; AssociatedObject.LostFocus -= OnFocusChanged; AssociatedObject.MouseDown -= OnMouseDown; AssociatedObject.KeyDown -= OnKeyDown; base.OnDetaching(); UpdateTimer(); _gameTimer = null; }
public Engine(IDisplay display, /*IMainMenu menu, */ IMap map, IPlayerTank playerTank, IEnvironmentFactory environmentFactory, ICollision collision, IKeyboardWraper keyboard, IGameTimer timer, IGameSettings gameSettings, IData data) { //this.menu = menu; this.map = map ?? throw new NoMapException(); this.playerTank = playerTank ?? throw new ArgumentNullException(); this.environmentFactory = environmentFactory ?? throw new ArgumentNullException(); this.collision = collision ?? throw new ArgumentNullException(); this.keyboard = keyboard ?? throw new ArgumentNullException(); this.timer = timer ?? throw new ArgumentNullException(); this.gameSettings = gameSettings ?? throw new ArgumentNullException(); this.data = data; this.display = display ?? throw new ArgumentNullException(); }
public InGameViewModel(INavigationService navigation, IGame game, IGameDimensions gameDimensions, IGameTimer timer, IDispatcher dispatcher, IArtworkRequester requester) { Column1 = new ObservableCollection<Tile>(); Column2 = new ObservableCollection<Tile>(); Column3 = new ObservableCollection<Tile>(); Column4 = new ObservableCollection<Tile>(); Column5 = new ObservableCollection<Tile>(); Column6 = new ObservableCollection<Tile>(); Column7 = new ObservableCollection<Tile>(); Column8 = new ObservableCollection<Tile>(); Column9 = new ObservableCollection<Tile>(); var modelColumn1 = new ObservableCollection<Tile>(); var modelColumn2 = new ObservableCollection<Tile>(); var modelColumn3 = new ObservableCollection<Tile>(); var modelColumn4 = new ObservableCollection<Tile>(); var modelColumn5 = new ObservableCollection<Tile>(); var modelColumn6 = new ObservableCollection<Tile>(); var modelColumn7 = new ObservableCollection<Tile>(); var modelColumn8 = new ObservableCollection<Tile>(); var modelColumn9 = new ObservableCollection<Tile>(); Columns.Add(Column1); Columns.Add(Column2); Columns.Add(Column3); Columns.Add(Column4); Columns.Add(Column5); Columns.Add(Column6); Columns.Add(Column7); Columns.Add(Column8); Columns.Add(Column9); _modelColumns.Add(modelColumn1); _modelColumns.Add(modelColumn2); _modelColumns.Add(modelColumn3); _modelColumns.Add(modelColumn4); _modelColumns.Add(modelColumn5); _modelColumns.Add(modelColumn6); _modelColumns.Add(modelColumn7); _modelColumns.Add(modelColumn8); _modelColumns.Add(modelColumn9); _navigationService = navigation; _game = game; _gameDimensions = gameDimensions; _timer = timer; _dispatcher = dispatcher; _requester = requester; _dropStep = _gameDimensions.GameHeight / Game.NumberStepsToDrop; }
public PPTimer(float maxTime, float timeStep, bool autoStopAtZero = true) { this.maxTime = maxTime; this.timeStep = timeStep; this.timer = setupTimer(maxTime, timeStep); if (autoStopAtZero) { this.timer.SubscribeToTimeUp(Stop); this.timer.SubscribeToTimeUp(delegate { SetTimeRemaining(0, checkForEvents: false); }); } }
private void AddGameLoop() { _clock = new HighPrecisionClock(); _clock.Start(); CompositionTarget.Rendering += OnCompositionTargetRendering; ComponentDispatcher.ThreadIdle += OnApplicationIdle; // The FixedStepTimer reads the clock and triggers the game loop at 60 Hz. _timer = new FixedStepTimer(_clock) { StepSize = new TimeSpan(166667), // ~60 Hz //StepSize = new TimeSpan(333333), // ~30 Hz AccumulateTimeSteps = false, }; // The VariableStepTimer reads the clock and triggers the game loop as often // as possible. //_timer = new VariableStepTimer(_clock); _timer.TimeChanged += (s, e) => GameLoop(e.DeltaTime); _timer.Start(); Editor.Services.Register(typeof(IGameTimer), null, _timer); }
//-------------------------------------------------------------- #region Creation & Cleanup //-------------------------------------------------------------- public MyGame() { Lock = new object(); // ----- Service Container // MyGame uses a ServiceContainer, which is a simple service locator and // Inversion of Control (IoC) container. (The ServiceContainer can be // replaced by any other container that implements System.IServiceProvider.) _serviceContainer = new ServiceContainer(); ServiceLocator.SetLocatorProvider(() => _serviceContainer); _serviceContainer.Register(typeof(MyGame), null, this); // ----- Storage // Create a "virtual file system" for reading game assets. _titleStorage = new TitleStorage("Content"); _assetsStorage = new ZipStorage(_titleStorage, "Content.zip"); _digitalRuneStorage = new ZipStorage(_titleStorage, "DigitalRune.zip"); _vfsStorage = new VfsStorage(); _vfsStorage.MountInfos.Add(new VfsMountInfo(_assetsStorage, null)); _vfsStorage.MountInfos.Add(new VfsMountInfo(_digitalRuneStorage, null)); // ----- Content _contentManager = new StorageContentManager(ServiceLocator.Current, _vfsStorage); _serviceContainer.Register(typeof(ContentManager), null, _contentManager); // ----- Graphics // Create Direct3D 11 device. var presentationParameters = new PresentationParameters { BackBufferWidth = 1, BackBufferHeight = 1, // Do not associate graphics device with any window. DeviceWindowHandle = IntPtr.Zero, }; var graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.HiDef, presentationParameters); // An IGraphicsDeviceService is required by the MonoGame/XNA content manager. _serviceContainer.Register(typeof(IGraphicsDeviceService), null, new DummyGraphicsDeviceManager(graphicsDevice)); // Get DXGIOutput to call WaitForVerticalBlank() in the game loop. using (var dxgiFactory = new SharpDX.DXGI.Factory1()) using (var dxgiAdapter = dxgiFactory.GetAdapter1(0)) _dxgiOutput = dxgiAdapter.GetOutput(0); // Create and register the graphics manager. _graphicsManager = new GraphicsManager(graphicsDevice, _contentManager); _serviceContainer.Register(typeof(IGraphicsService), null, _graphicsManager); // ----- Timing // The game loop runs in a parallel thread to keep the UI thread responsive. // To measure the time that has passed, we use a HighPrecisionClock. _clock = new HighPrecisionClock(); _clock.Start(); _gameLoopTask = ThreadPool.RunAsync(GameLoopTaskAction, WorkItemPriority.High, WorkItemOptions.TimeSliced) .AsTask(); // The FixedStepTimer reads the clock and triggers the game loop at 60 Hz. //_timer = new FixedStepTimer(_clock) //{ // StepSize = new TimeSpan(166667), // ~60 Hz // AccumulateTimeSteps = false, //}; // The VariableStepTimer reads the clock and triggers the game loop as often as possible. _timer = new VariableStepTimer(_clock); _timer.TimeChanged += (s, e) => GameLoop(e.DeltaTime); _timer.Start(); CoreApplication.Suspending += OnCoreApplicationSuspending; // DirectX buffers only a limit amount of Present calls per frame which is controlled by // the MaximumFrameLatency property. The default value is usually 3. If the application // uses more SwapChainPresentationTargets we must increase this property. //var d3dDevice = (SharpDX.Direct3D11.Device)_graphicsManager.GraphicsDevice.Handle; //using (var dxgiDevice2 = d3dDevice.QueryInterface<SharpDX.DXGI.Device2>()) // dxgiDevice2.MaximumFrameLatency = numberOfSwapChainPanels; }
public MyGame() { // ----- Service Container // The MyGame uses a ServiceContainer, which is a simple service locator // and Inversion of Control (IoC) container. (The ServiceContainer can be // replaced by any other container that implements System.IServiceProvider.) _serviceContainer = new ServiceContainer(); ServiceLocator.SetLocatorProvider(() => _serviceContainer); // ----- Storage // Create a "virtual file system" for reading game assets. var titleStorage = new TitleStorage("Content"); var assetsStorage = new ZipStorage(titleStorage, "Content.zip"); var digitalRuneStorage = new ZipStorage(titleStorage, "DigitalRune.zip"); var vfsStorage = new VfsStorage(); vfsStorage.MountInfos.Add(new VfsMountInfo(titleStorage, null)); vfsStorage.MountInfos.Add(new VfsMountInfo(assetsStorage, null)); vfsStorage.MountInfos.Add(new VfsMountInfo(digitalRuneStorage, null)); // ----- Content _contentManager = new StorageContentManager(ServiceLocator.Current, vfsStorage); _serviceContainer.Register(typeof(ContentManager), null, _contentManager); // ----- Graphics // Create Direct3D 11 device. var presentationParameters = new PresentationParameters { BackBufferWidth = 1, BackBufferHeight = 1, // Do not associate graphics device with any window. DeviceWindowHandle = IntPtr.Zero, }; var graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.HiDef, presentationParameters); // An IGraphicsDeviceService is required by the MonoGame/XNA content manager. _serviceContainer.Register(typeof(IGraphicsDeviceService), null, new DummyGraphicsDeviceManager(graphicsDevice)); // Create and register the graphics manager. _graphicsManager = new GraphicsManager(graphicsDevice, _contentManager); _serviceContainer.Register(typeof(IGraphicsService), null, _graphicsManager); // ----- Timing // We can use the CompositionTarget.Rendering event to trigger our game loop. // The CompositionTarget.Rendering event is raised once per frame by WPF. // To measure the time that has passed, we use a HighPrecisionClock. _clock = new HighPrecisionClock(); _clock.Start(); CompositionTarget.Rendering += (s, e) => _clock.Update(); // The FixedStepTimer reads the clock and triggers the game loop at 60 Hz. //_timer = new FixedStepTimer(_clock) //{ // StepSize = new TimeSpan(166667), // ~60 Hz // AccumulateTimeSteps = false, //}; // The VariableStepTimer reads the clock and triggers the game loop as often // as possible. _timer = new VariableStepTimer(_clock); _timer.TimeChanged += (s, e) => GameLoop(e.DeltaTime); _timer.Start(); }
private TimeService() { GameTimer = new GameTimer(); PauseTimer = new GameTimer(); }
//-------------------------------------------------------------- public MyGame() { Lock = new object(); // ----- Service Container // MyGame uses a ServiceContainer, which is a simple service locator and // Inversion of Control (IoC) container. (The ServiceContainer can be // replaced by any other container that implements System.IServiceProvider.) _serviceContainer = new ServiceContainer(); ServiceLocator.SetLocatorProvider(() => _serviceContainer); _serviceContainer.Register(typeof(MyGame), null, this); // ----- Storage // Create a "virtual file system" for reading game assets. _titleStorage = new TitleStorage("Content"); _assetsStorage = new ZipStorage(_titleStorage, "Content.zip"); _digitalRuneStorage = new ZipStorage(_titleStorage, "DigitalRune.zip"); _vfsStorage = new VfsStorage(); _vfsStorage.MountInfos.Add(new VfsMountInfo(_assetsStorage, null)); _vfsStorage.MountInfos.Add(new VfsMountInfo(_digitalRuneStorage, null)); // ----- Content _contentManager = new StorageContentManager(ServiceLocator.Current, _vfsStorage); _serviceContainer.Register(typeof(ContentManager), null, _contentManager); // ----- Graphics // Create Direct3D 11 device. var presentationParameters = new PresentationParameters { BackBufferWidth = 1, BackBufferHeight = 1, // Do not associate graphics device with any window. DeviceWindowHandle = IntPtr.Zero, }; var graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.HiDef, presentationParameters); // An IGraphicsDeviceService is required by the MonoGame/XNA content manager. _serviceContainer.Register(typeof(IGraphicsDeviceService), null, new DummyGraphicsDeviceManager(graphicsDevice)); // Get DXGIOutput to call WaitForVerticalBlank() in the game loop. using (var dxgiFactory = new SharpDX.DXGI.Factory1()) using (var dxgiAdapter = dxgiFactory.GetAdapter1(0)) _dxgiOutput = dxgiAdapter.GetOutput(0); // Create and register the graphics manager. _graphicsManager = new GraphicsManager(graphicsDevice, _contentManager); _serviceContainer.Register(typeof(IGraphicsService), null, _graphicsManager); // ----- Timing // The game loop runs in a parallel thread to keep the UI thread responsive. // To measure the time that has passed, we use a HighPrecisionClock. _clock = new HighPrecisionClock(); _clock.Start(); _gameLoopTask = ThreadPool.RunAsync(GameLoopTaskAction, WorkItemPriority.High, WorkItemOptions.TimeSliced) .AsTask(); // The FixedStepTimer reads the clock and triggers the game loop at 60 Hz. //_timer = new FixedStepTimer(_clock) //{ // StepSize = new TimeSpan(166667), // ~60 Hz // AccumulateTimeSteps = false, //}; // The VariableStepTimer reads the clock and triggers the game loop as often as possible. _timer = new VariableStepTimer(_clock); _timer.TimeChanged += (s, e) => GameLoop(e.DeltaTime); _timer.Start(); CoreApplication.Suspending += OnCoreApplicationSuspending; // DirectX buffers only a limit amount of Present calls per frame which is controlled by // the MaximumFrameLatency property. The default value is usually 3. If the application // uses more SwapChainPresentationTargets we must increase this property. //var d3dDevice = (SharpDX.Direct3D11.Device)_graphicsManager.GraphicsDevice.Handle; //using (var dxgiDevice2 = d3dDevice.QueryInterface<SharpDX.DXGI.Device2>()) // dxgiDevice2.MaximumFrameLatency = numberOfSwapChainPanels; }
public static void SetDefaults(IPainter <TColor> painter, IGameTimer gameTimer, IMouseLocator mouseLocator, ICameraLocator cameraLocator) { Painter = painter; MouseLocator = mouseLocator; CameraLocator = cameraLocator; }
public EnemyTank(int row, int col, Direction direction, IMap map, IPlayerTank playerTank, IEnvironmentFactory environmentFactory, ICollision collision, IGameTimer gameTimer) : base(row, col, direction, map, environmentFactory, collision) { this.Color = ConsoleColor.Red; this.playerTank = playerTank; this.gameTimer = gameTimer ?? throw new ArgumentNullException(); }
public Game(IServerQueueManager serverQueueManager, IGameTimer gameTimer) { this.serverQueueManager = serverQueueManager; this.gameTimer = gameTimer; }
public QueryIntake(IGameTimer gameTimer) { _gameTimer = gameTimer; }