예제 #1
0
        private void WaitForGameState(EngineGameState target)
        {
            // Immediately returns if the engine is in the target state,
            // or if the engine has previously crashed.
            lock (_SyncRoot)
            {
                if (_IsInCrash)
                {
                    return;
                }
            }
            try
            {
                CheckStateIs(target, null);

                // If we get here, it means that the engine is in the target state.
                return;
            }
            catch (InvalidOperationException)
            {
                // The engine is performing a concurrent operation.
                // Let's keep on going.
            }

            // Sets up a manual reset event that is set when the engine state
            // changes to the target game state.
            System.Threading.ManualResetEvent resetEvent = new System.Threading.ManualResetEvent(false);
            PropertyChangedEventHandler       handler    = new PropertyChangedEventHandler((o, e) =>
            {
                if (e.PropertyName == "GameState")
                {
                    try
                    {
                        CheckStateIs(target, null);

                        // The engine is not in a concurrent game operation.
                        // Let's signal the event.
                        resetEvent.Set();
                    }
                    catch (InvalidOperationException)
                    {
                        // The engine is performing a concurrent operation.
                        // Let's wait some more.
                        return;
                    }
                }
            });

            PropertyChanged += handler;

            // Waits on the event.
            resetEvent.WaitOne();

            // Removes the handler.
            PropertyChanged -= handler;
        }
예제 #2
0
		/// <summary>
		/// Called when the state of the game engine has changed.
		/// </summary>
		/// <param name="oldState">State the engine had before the change occured.</param>
		/// <param name="newState">State the engine has now.</param>
		protected virtual void OnCoreGameStateChanged(EngineGameState oldState, EngineGameState newState)
		{

		} 
예제 #3
0
		private void WaitForGameState(EngineGameState target)
		{
			// Immediately returns if the engine is in the target state,
			// or if the engine has previously crashed.
			lock (_SyncRoot)
			{
				if (_IsInCrash)
				{
					return;
				}
			}
			try
			{
				CheckStateIs(target, null);
				
				// If we get here, it means that the engine is in the target state.
				return;
			}
			catch (InvalidOperationException)
			{
				// The engine is performing a concurrent operation.
				// Let's keep on going.
			}

			// Sets up a manual reset event that is set when the engine state
			// changes to the target game state.
			System.Threading.ManualResetEvent resetEvent = new System.Threading.ManualResetEvent(false);
			PropertyChangedEventHandler handler = new PropertyChangedEventHandler((o, e) =>
			{
				if (e.PropertyName == "GameState")
				{
					try
					{
						CheckStateIs(target, null);

						// The engine is not in a concurrent game operation.
						// Let's signal the event.
						resetEvent.Set();
					}
					catch (InvalidOperationException)
					{
						// The engine is performing a concurrent operation.
						// Let's wait some more.
						return;
					}
				}
			});
			PropertyChanged += handler;

			// Waits on the event.
			resetEvent.WaitOne();

			// Removes the handler.
			PropertyChanged -= handler;
		}
 /// <summary>
 /// Called when the state of the game engine has changed.
 /// </summary>
 /// <param name="oldState">State the engine had before the change occured.</param>
 /// <param name="newState">State the engine has now.</param>
 protected virtual void OnCoreGameStateChanged(EngineGameState oldState, EngineGameState newState)
 {
 }