From c9094cd4d4cc0d0d6e9927d9b61aa1d141ce17b6 Mon Sep 17 00:00:00 2001 From: Paul Sladen Date: Tue, 14 Apr 2009 06:11:41 +0300 Subject: [PATCH] * Add "/fps" to benchmark rendering over first 1 kilometre --- debian/changelog | 3 ++- openBVE/OpenBve/Game.cs | 10 ++++++++++ openBVE/OpenBve/Loading.cs | 2 ++ openBVE/OpenBve/MainLoop.cs | 8 ++++++++ openBVE/OpenBve/Program.cs | 13 ++++++++++++- 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 78e1329..1eef402 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ openbve (1.0.2.0-0ubuntu1sladen1) unreleased; urgency=low - + * Add "/fps" to benchmark rendering over first 1 kilometre + -- Paul Sladen Mon, 13 Apr 2009 23:33:10 +0000 openbve (1.0.2.0-0ubuntu1) jaunty; urgency=low diff --git a/openBVE/OpenBve/Game.cs b/openBVE/OpenBve/Game.cs index 3b615ab..8b25def 100644 --- a/openBVE/OpenBve/Game.cs +++ b/openBVE/OpenBve/Game.cs @@ -967,6 +967,16 @@ namespace OpenBve { internal abstract void Trigger(TrainManager.Train Train); } + // manic driver for benchmarking + internal class HeavyFootAI : GeneralAI { + internal override void Trigger(TrainManager.Train Train) { + TrainManager.UnapplyEmergencyBrake(Train); + TrainManager.ApplyAirBrakeHandle(Train, TrainManager.AirBrakeHandleState.Release); + TrainManager.ApplyReverser(Train, 1, false); + TrainManager.ApplyNotch(Train, 1, true, -1, true); + } + } + // simplistic human driver internal class SimplisticHumanDriverAI : GeneralAI { private double TimeLastProcessed; diff --git a/openBVE/OpenBve/Loading.cs b/openBVE/OpenBve/Loading.cs index 12c24f4..431ea36 100644 --- a/openBVE/OpenBve/Loading.cs +++ b/openBVE/OpenBve/Loading.cs @@ -277,6 +277,8 @@ namespace OpenBve { // configure ai / timetable if (k == TrainManager.PlayerTrain.TrainIndex) { TrainManager.Trains[k].PretrainAheadTimetable = 0.0; + if (Program.Benchmark) + TrainManager.Trains[k].AI = new Game.HeavyFootAI(); } else if (TrainManager.Trains[k].IsBogusTrain) { TrainManager.Trains[k].AI = new Game.BogusPretrainAI(TrainManager.Trains[k]); } else { diff --git a/openBVE/OpenBve/MainLoop.cs b/openBVE/OpenBve/MainLoop.cs index 64d9f55..3b343bb 100644 --- a/openBVE/OpenBve/MainLoop.cs +++ b/openBVE/OpenBve/MainLoop.cs @@ -9,6 +9,8 @@ namespace OpenBve { //// declarations internal static bool LimitFramerate = false; private static bool Quit = false; + public static int ReallyTotalFramesElapsed = 0; + public static double ReallyTotalSeconds = 1.0; //// -------------------------------- @@ -74,6 +76,8 @@ namespace OpenBve { TotalTimeElapsedForInfo += TimeElapsed; TotalTimeElapsedForSectionUpdate += TimeElapsed; TotalFramesElapsed++; + ReallyTotalFramesElapsed++; + ReallyTotalSeconds += TimeElapsed; if (TotalTimeElapsedForSectionUpdate >= 1.0) { if (Game.Sections.Length != 0) { Game.UpdateSection(Game.Sections.Length - 1); @@ -148,6 +152,10 @@ namespace OpenBve { TextureManager.Update(TimeElapsed); SoundManager.Update(TimeElapsed); Game.UpdateBlackBox(); + // Timed sprint for benchmarking + if (Program.Benchmark & (TrainManager.PlayerTrain.Cars[0].FrontAxle.Follower.TrackPosition >= 1000.0)) { + Quit = true; + } // pause/menu while (Game.CurrentInterface != Game.InterfaceType.Normal) { ProcessEvents(); diff --git a/openBVE/OpenBve/Program.cs b/openBVE/OpenBve/Program.cs index 8696ec8..3f65e38 100644 --- a/openBVE/OpenBve/Program.cs +++ b/openBVE/OpenBve/Program.cs @@ -12,6 +12,7 @@ namespace OpenBve { internal static Platform CurrentPlatform = Platform.Windows; internal static bool CurrentlyRunOnMono = false; internal static bool UseFilesystemHierarchyStandard = false; + public static bool Benchmark = false; //// main [STAThread] @@ -57,6 +58,13 @@ namespace OpenBve { #endif // deinitialize + if(Program.Benchmark) + Console.Error.WriteLine("Frames: {0}, Time: {1:.#} s, Distance: {2:.#} m, fps: {3:.##}/s", + MainLoop.ReallyTotalFramesElapsed, + MainLoop.ReallyTotalSeconds, + TrainManager.PlayerTrain.Cars[0].FrontAxle.Follower.TrackPosition, + MainLoop.ReallyTotalFramesElapsed/MainLoop.ReallyTotalSeconds); + // leave full-screen mode, to reduce risk of leaving a mess // if something during shutdown crashes/hangs if(Interface.CurrentOptions.FullscreenMode) { @@ -153,7 +161,10 @@ namespace OpenBve { break; } } - } + } else if (Args[i].Equals("/fps", StringComparison.OrdinalIgnoreCase)) { + Console.Error.WriteLine("Benchmarking engaged, will print FPS on exit"); + Benchmark = true; + } } // train provided if (Result.TrainFolder != null) { -- 1.6.0.4