From d61ce4e38c95e2bf58bc0e4e08175a0befcd8ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 26 Jun 2023 22:14:11 +0300 Subject: [PATCH] Remove BenchGfx --- .../command_line/BenchGfxCommmands.cpp | 30 ----- src/openrct2/command_line/CommandLine.hpp | 1 - src/openrct2/command_line/RootCommands.cpp | 1 - src/openrct2/interface/Screenshot.cpp | 123 ------------------ src/openrct2/interface/Screenshot.h | 1 - src/openrct2/libopenrct2.vcxproj | 1 - 6 files changed, 157 deletions(-) delete mode 100644 src/openrct2/command_line/BenchGfxCommmands.cpp diff --git a/src/openrct2/command_line/BenchGfxCommmands.cpp b/src/openrct2/command_line/BenchGfxCommmands.cpp deleted file mode 100644 index 439e6fbd58..0000000000 --- a/src/openrct2/command_line/BenchGfxCommmands.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2023 OpenRCT2 developers - * - * For a complete list of all authors, please refer to contributors.md - * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 - * - * OpenRCT2 is licensed under the GNU General Public License version 3. - *****************************************************************************/ - -#include "../interface/Screenshot.h" -#include "CommandLine.hpp" - -static exitcode_t HandleBenchGfx(CommandLineArgEnumerator* argEnumerator); - -const CommandLineCommand CommandLine::BenchGfxCommands[]{ - // Main commands - DefineCommand("", " [iterations count]", nullptr, HandleBenchGfx), CommandTableEnd -}; - -static exitcode_t HandleBenchGfx(CommandLineArgEnumerator* argEnumerator) -{ - const char** argv = const_cast(argEnumerator->GetArguments()) + argEnumerator->GetIndex(); - int32_t argc = argEnumerator->GetCount() - argEnumerator->GetIndex(); - int32_t result = CommandLineForGfxbench(argv, argc); - if (result < 0) - { - return EXITCODE_FAIL; - } - return EXITCODE_OK; -} diff --git a/src/openrct2/command_line/CommandLine.hpp b/src/openrct2/command_line/CommandLine.hpp index 0897cc12b1..f8d0d7f489 100644 --- a/src/openrct2/command_line/CommandLine.hpp +++ b/src/openrct2/command_line/CommandLine.hpp @@ -116,7 +116,6 @@ namespace CommandLine extern const CommandLineCommand RootCommands[]; extern const CommandLineCommand ScreenshotCommands[]; extern const CommandLineCommand SpriteCommands[]; - extern const CommandLineCommand BenchGfxCommands[]; extern const CommandLineCommand SimulateCommands[]; extern const CommandLineCommand ParkInfoCommands[]; diff --git a/src/openrct2/command_line/RootCommands.cpp b/src/openrct2/command_line/RootCommands.cpp index 1d404b22d3..d2d6335505 100644 --- a/src/openrct2/command_line/RootCommands.cpp +++ b/src/openrct2/command_line/RootCommands.cpp @@ -140,7 +140,6 @@ const CommandLineCommand CommandLine::RootCommands[] // Sub-commands DefineSubCommand("screenshot", CommandLine::ScreenshotCommands ), DefineSubCommand("sprite", CommandLine::SpriteCommands ), - DefineSubCommand("benchgfx", CommandLine::BenchGfxCommands ), DefineSubCommand("simulate", CommandLine::SimulateCommands ), DefineSubCommand("parkinfo", CommandLine::ParkInfoCommands ), CommandTableEnd diff --git a/src/openrct2/interface/Screenshot.cpp b/src/openrct2/interface/Screenshot.cpp index 24ec108206..c033df8473 100644 --- a/src/openrct2/interface/Screenshot.cpp +++ b/src/openrct2/interface/Screenshot.cpp @@ -390,129 +390,6 @@ void ScreenshotGiant() ReleaseDPI(dpi); } -// TODO: Move this at some point into a more appropriate place. -template static inline double MeasureFunctionTime(const FN& fn) -{ - const auto startTime = std::chrono::high_resolution_clock::now(); - fn(); - const auto endTime = std::chrono::high_resolution_clock::now(); - return std::chrono::duration(endTime - startTime).count(); -} - -static void BenchgfxRenderScreenshots(const char* inputPath, std::unique_ptr& context, uint32_t iterationCount) -{ - if (!context->LoadParkFromFile(inputPath)) - { - return; - } - - gIntroState = IntroState::None; - gScreenFlags = SCREEN_FLAGS_PLAYING; - - // Create Viewport and DPI for every rotation and zoom. - // We iterate from the default zoom level to the max zoomed out zoom level, then run GetGiantViewport once for each - // rotation. - constexpr int32_t NUM_ROTATIONS = 4; - constexpr auto NUM_ZOOM_LEVELS = static_cast(ZoomLevel::max()); - std::array dpis; - std::array viewports; - - for (ZoomLevel zoom{ 0 }; zoom < ZoomLevel::max(); zoom++) - { - int32_t zoomIndex{ static_cast(zoom) }; - for (int32_t rotation = 0; rotation < NUM_ROTATIONS; rotation++) - { - auto& viewport = viewports[zoomIndex * NUM_ZOOM_LEVELS + rotation]; - auto& dpi = dpis[zoomIndex * NUM_ZOOM_LEVELS + rotation]; - viewport = GetGiantViewport(rotation, zoom); - dpi = CreateDPI(viewport); - } - } - - const uint32_t totalRenderCount = iterationCount * NUM_ROTATIONS * NUM_ZOOM_LEVELS; - - try - { - double totalTime = 0.0; - - std::array zoomAverages; - - // Render at every zoom. - for (int32_t zoom = 0; zoom < NUM_ZOOM_LEVELS; zoom++) - { - double zoomLevelTime = 0.0; - - // Render at every rotation. - for (int32_t rotation = 0; rotation < NUM_ROTATIONS; rotation++) - { - // N iterations. - for (uint32_t i = 0; i < iterationCount; i++) - { - auto& dpi = dpis[zoom * NUM_ZOOM_LEVELS + rotation]; - auto& viewport = viewports[zoom * NUM_ZOOM_LEVELS + rotation]; - double elapsed = MeasureFunctionTime([&viewport, &dpi]() { RenderViewport(nullptr, viewport, dpi); }); - totalTime += elapsed; - zoomLevelTime += elapsed; - } - } - - zoomAverages[zoom] = zoomLevelTime / static_cast(NUM_ROTATIONS * iterationCount); - } - - const double average = totalTime / static_cast(totalRenderCount); - const auto engineStringId = DrawingEngineStringIds[EnumValue(DrawingEngine::Software)]; - const auto engineName = FormatStringID(engineStringId, nullptr); - std::printf("Engine: %s\n", engineName.c_str()); - std::printf("Render Count: %u\n", totalRenderCount); - for (ZoomLevel zoom{ 0 }; zoom < ZoomLevel::max(); zoom++) - { - int32_t zoomIndex{ static_cast(zoom) }; - const auto zoomAverage = zoomAverages[zoomIndex]; - std::printf("Zoom[%d] average: %.06fs, %.f FPS\n", zoomIndex, zoomAverage, 1.0 / zoomAverage); - } - std::printf("Total average: %.06fs, %.f FPS\n", average, 1.0 / average); - std::printf("Time: %.05fs\n", totalTime); - } - catch (const std::exception& e) - { - Console::Error::WriteLine("%s", e.what()); - } - - for (auto& dpi : dpis) - ReleaseDPI(dpi); -} - -int32_t CommandLineForGfxbench(const char** argv, int32_t argc) -{ - if (argc != 1 && argc != 2) - { - printf("Usage: openrct2 benchgfx []\n"); - return -1; - } - - int32_t iterationCount = 5; - if (argc == 2) - { - iterationCount = atoi(argv[1]); - } - - const char* inputPath = argv[0]; - - gOpenRCT2Headless = true; - - std::unique_ptr context(CreateContext()); - if (context->Initialise()) - { - DrawingEngineInit(); - - BenchgfxRenderScreenshots(inputPath, context, iterationCount); - - DrawingEngineDispose(); - } - - return 1; -} - static void ApplyOptions(const ScreenshotOptions* options, Viewport& viewport) { if (options->weather != WeatherType::Sunny && options->weather != WeatherType::Count) diff --git a/src/openrct2/interface/Screenshot.h b/src/openrct2/interface/Screenshot.h index 30eacdcded..ba6ab28de9 100644 --- a/src/openrct2/interface/Screenshot.h +++ b/src/openrct2/interface/Screenshot.h @@ -59,6 +59,5 @@ std::string ScreenshotDumpPNG32bpp(int32_t width, int32_t height, const void* pi void ScreenshotGiant(); int32_t CommandLineForScreenshot(const char** argv, int32_t argc, ScreenshotOptions* options); -int32_t CommandLineForGfxbench(const char** argv, int32_t argc); void CaptureImage(const CaptureOptions& options); diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index c6e016e532..ea555463ee 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -690,7 +690,6 @@ -