Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GameBase" /> class.
        /// </summary>
        protected GameBase()
        {
            // Internals
            Log                      = GlobalLogger.GetLogger(GetType().GetTypeInfo().Name);
            updateTime               = new GameTime();
            drawTime                 = new GameTime();
            playTimer                = new TimerTick();
            updateTimer              = new TimerTick();
            totalUpdateTime          = new TimeSpan();
            timer                    = new TimerTick();
            IsFixedTimeStep          = false;
            maximumElapsedTime       = TimeSpan.FromMilliseconds(500.0);
            lastUpdateCount          = new int[4];
            nextLastUpdateCountIndex = 0;
            TargetElapsedTime        = defaultTimeSpan; // default empty timespan, will be set on window create if not set elsewhere

            TreatNotFocusedLikeMinimized = true;
            DrawEvenMinimized            = false;
            WindowMinimumUpdateRate      = new ThreadThrottler(defaultTimeSpan);                                  // will be set when window gets created with window's refresh rate
            MinimizedMinimumUpdateRate   = new ThreadThrottler(TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 15)); // by default 15 updates per second while minimized

            // Calculate the updateCountAverageSlowLimit (assuming moving average is >=3 )
            // Example for a moving average of 4:
            // updateCountAverageSlowLimit = (2 * 2 + (4 - 2)) / 4 = 1.5f
            const int BadUpdateCountTime = 2; // number of bad frame (a bad frame is a frame that has at least 2 updates)
            var       maxLastCount       = 2 * Math.Min(BadUpdateCountTime, lastUpdateCount.Length);

            updateCountAverageSlowLimit = (float)(maxLastCount + (lastUpdateCount.Length - maxLastCount)) / lastUpdateCount.Length;

            // Externals
            Services = new ServiceRegistry(true);

            // Database file provider
            Services.AddService <IDatabaseFileProviderService>(new DatabaseFileProviderService(null));

            LaunchParameters = new LaunchParameters();
            GameSystems      = new GameSystemCollection(Services);
            Services.AddService <IGameSystemCollection>(GameSystems);

            // Create Platform
            gamePlatform                = GamePlatform.Create(this);
            gamePlatform.Activated     += GamePlatform_Activated;
            gamePlatform.Deactivated   += GamePlatform_Deactivated;
            gamePlatform.Exiting       += GamePlatform_Exiting;
            gamePlatform.WindowCreated += GamePlatformOnWindowCreated;

            // Setup registry
            Services.AddService <IGame>(this);
            Services.AddService <IGraphicsDeviceFactory>(gamePlatform);
            Services.AddService <IGamePlatform>(gamePlatform);

            IsActive = true;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GameBase" /> class.
        /// </summary>
        protected GameBase()
        {
            // Internals
            Log                      = GlobalLogger.GetLogger(GetType().GetTypeInfo().Name);
            updateTime               = new GameTime();
            drawTime                 = new GameTime();
            playTimer                = new TimerTick();
            updateTimer              = new TimerTick();
            totalUpdateTime          = new TimeSpan();
            timer                    = new TimerTick();
            IsFixedTimeStep          = false;
            maximumElapsedTime       = TimeSpan.FromMilliseconds(500.0);
            TargetElapsedTime        = TimeSpan.FromTicks(10000000 / 60); // target elapsed time is by default 60Hz
            lastUpdateCount          = new int[4];
            nextLastUpdateCountIndex = 0;

            // Calculate the updateCountAverageSlowLimit (assuming moving average is >=3 )
            // Example for a moving average of 4:
            // updateCountAverageSlowLimit = (2 * 2 + (4 - 2)) / 4 = 1.5f
            const int BadUpdateCountTime = 2; // number of bad frame (a bad frame is a frame that has at least 2 updates)
            var       maxLastCount       = 2 * Math.Min(BadUpdateCountTime, lastUpdateCount.Length);

            updateCountAverageSlowLimit = (float)(maxLastCount + (lastUpdateCount.Length - maxLastCount)) / lastUpdateCount.Length;

            // Externals
            Services = new ServiceRegistry();

            // Database file provider
            Services.AddService <IDatabaseFileProviderService>(new DatabaseFileProviderService(null));

            LaunchParameters = new LaunchParameters();
            GameSystems      = new GameSystemCollection(Services);
            Services.AddService <IGameSystemCollection>(GameSystems);

            // Create Platform
            gamePlatform                = GamePlatform.Create(this);
            gamePlatform.Activated     += GamePlatform_Activated;
            gamePlatform.Deactivated   += GamePlatform_Deactivated;
            gamePlatform.Exiting       += GamePlatform_Exiting;
            gamePlatform.WindowCreated += GamePlatformOnWindowCreated;

            // Setup registry
            Services.AddService <IGame>(this);
            Services.AddService <IGraphicsDeviceFactory>(gamePlatform);
            Services.AddService <IGamePlatform>(gamePlatform);

            IsActive = true;
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GameBase" /> class.
        /// </summary>
        protected GameBase()
        {
            // Internals
            Log                = GlobalLogger.GetLogger(GetType().GetTypeInfo().Name);
            UpdateTime         = new GameTime();
            DrawTime           = new GameTime();
            autoTickTimer      = new TimerTick();
            IsFixedTimeStep    = false;
            maximumElapsedTime = TimeSpan.FromMilliseconds(500.0);
            TargetElapsedTime  = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 60); // target elapsed time is by default 60Hz

            TreatNotFocusedLikeMinimized = true;
            WindowMinimumUpdateRate      = new ThreadThrottler(TimeSpan.FromSeconds(0d));
            MinimizedMinimumUpdateRate   = new ThreadThrottler(TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 15)); // by default 15 updates per second while minimized

            isMouseVisible = true;

            // Externals
            Services = new ServiceRegistry();

            // Database file provider
            Services.AddService <IDatabaseFileProviderService>(new DatabaseFileProviderService(null));

            LaunchParameters = new LaunchParameters();
            GameSystems      = new GameSystemCollection(Services);
            Services.AddService <IGameSystemCollection>(GameSystems);

            // Create Platform
            gamePlatform                = GamePlatform.Create(this);
            gamePlatform.Activated     += GamePlatform_Activated;
            gamePlatform.Deactivated   += GamePlatform_Deactivated;
            gamePlatform.Exiting       += GamePlatform_Exiting;
            gamePlatform.WindowCreated += GamePlatformOnWindowCreated;

            // Setup registry
            Services.AddService <IGame>(this);
            Services.AddService <IGraphicsDeviceFactory>(gamePlatform);
            Services.AddService <IGamePlatform>(gamePlatform);

            IsActive = true;
        }