mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-14 11:32:56 +01:00
Remove benchmark code from game logic
This commit is contained in:
@@ -250,19 +250,10 @@ void GameState::Tick()
|
|||||||
gDoSingleUpdate = false;
|
gDoSingleUpdate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameState::UpdateLogic(LogicTimings* timings)
|
void GameState::UpdateLogic()
|
||||||
{
|
{
|
||||||
PROFILED_FUNCTION();
|
PROFILED_FUNCTION();
|
||||||
|
|
||||||
auto start_time = std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
auto report_time = [timings, start_time](LogicTimePart part) {
|
|
||||||
if (timings != nullptr)
|
|
||||||
{
|
|
||||||
timings->TimingInfo[part][timings->CurrentIdx] = std::chrono::high_resolution_clock::now() - start_time;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
gInUpdateCode = true;
|
gInUpdateCode = true;
|
||||||
|
|
||||||
gScreenAge++;
|
gScreenAge++;
|
||||||
@@ -272,7 +263,6 @@ void GameState::UpdateLogic(LogicTimings* timings)
|
|||||||
GetContext()->GetReplayManager()->Update();
|
GetContext()->GetReplayManager()->Update();
|
||||||
|
|
||||||
NetworkUpdate();
|
NetworkUpdate();
|
||||||
report_time(LogicTimePart::NetworkUpdate);
|
|
||||||
|
|
||||||
if (NetworkGetMode() == NETWORK_MODE_SERVER)
|
if (NetworkGetMode() == NETWORK_MODE_SERVER)
|
||||||
{
|
{
|
||||||
@@ -316,51 +306,33 @@ void GameState::UpdateLogic(LogicTimings* timings)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
_date.Update();
|
_date.Update();
|
||||||
report_time(LogicTimePart::Date);
|
|
||||||
|
|
||||||
ScenarioUpdate();
|
ScenarioUpdate();
|
||||||
report_time(LogicTimePart::Scenario);
|
|
||||||
ClimateUpdate();
|
ClimateUpdate();
|
||||||
report_time(LogicTimePart::Climate);
|
|
||||||
MapUpdateTiles();
|
MapUpdateTiles();
|
||||||
report_time(LogicTimePart::MapTiles);
|
|
||||||
// Temporarily remove provisional paths to prevent peep from interacting with them
|
// Temporarily remove provisional paths to prevent peep from interacting with them
|
||||||
MapRemoveProvisionalElements();
|
MapRemoveProvisionalElements();
|
||||||
report_time(LogicTimePart::MapStashProvisionalElements);
|
|
||||||
MapUpdatePathWideFlags();
|
MapUpdatePathWideFlags();
|
||||||
report_time(LogicTimePart::MapPathWideFlags);
|
|
||||||
PeepUpdateAll();
|
PeepUpdateAll();
|
||||||
report_time(LogicTimePart::Peep);
|
|
||||||
MapRestoreProvisionalElements();
|
MapRestoreProvisionalElements();
|
||||||
report_time(LogicTimePart::MapRestoreProvisionalElements);
|
|
||||||
VehicleUpdateAll();
|
VehicleUpdateAll();
|
||||||
report_time(LogicTimePart::Vehicle);
|
|
||||||
UpdateAllMiscEntities();
|
UpdateAllMiscEntities();
|
||||||
report_time(LogicTimePart::Misc);
|
|
||||||
Ride::UpdateAll();
|
Ride::UpdateAll();
|
||||||
report_time(LogicTimePart::Ride);
|
|
||||||
|
|
||||||
if (!(gScreenFlags & SCREEN_FLAGS_EDITOR))
|
if (!(gScreenFlags & SCREEN_FLAGS_EDITOR))
|
||||||
{
|
{
|
||||||
_park->Update(_date);
|
_park->Update(_date);
|
||||||
}
|
}
|
||||||
report_time(LogicTimePart::Park);
|
|
||||||
|
|
||||||
ResearchUpdate();
|
ResearchUpdate();
|
||||||
report_time(LogicTimePart::Research);
|
|
||||||
RideRatingsUpdateAll();
|
RideRatingsUpdateAll();
|
||||||
report_time(LogicTimePart::RideRatings);
|
|
||||||
RideMeasurementsUpdate();
|
RideMeasurementsUpdate();
|
||||||
report_time(LogicTimePart::RideMeasurments);
|
|
||||||
News::UpdateCurrentItem();
|
News::UpdateCurrentItem();
|
||||||
report_time(LogicTimePart::News);
|
|
||||||
|
|
||||||
MapAnimationInvalidateAll();
|
MapAnimationInvalidateAll();
|
||||||
report_time(LogicTimePart::MapAnimation);
|
|
||||||
VehicleSoundsUpdate();
|
VehicleSoundsUpdate();
|
||||||
PeepUpdateCrowdNoise();
|
PeepUpdateCrowdNoise();
|
||||||
ClimateUpdateSound();
|
ClimateUpdateSound();
|
||||||
report_time(LogicTimePart::Sounds);
|
|
||||||
EditorOpenWindowsForCurrentStep();
|
EditorOpenWindowsForCurrentStep();
|
||||||
|
|
||||||
// Update windows
|
// Update windows
|
||||||
@@ -373,11 +345,9 @@ void GameState::UpdateLogic(LogicTimings* timings)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GameActions::ProcessQueue();
|
GameActions::ProcessQueue();
|
||||||
report_time(LogicTimePart::GameActions);
|
|
||||||
|
|
||||||
NetworkProcessPending();
|
NetworkProcessPending();
|
||||||
NetworkFlush();
|
NetworkFlush();
|
||||||
report_time(LogicTimePart::NetworkFlush);
|
|
||||||
|
|
||||||
gCurrentTicks++;
|
gCurrentTicks++;
|
||||||
gSavedAge++;
|
gSavedAge++;
|
||||||
@@ -390,14 +360,8 @@ void GameState::UpdateLogic(LogicTimings* timings)
|
|||||||
{
|
{
|
||||||
hookEngine.Call(HOOK_TYPE::INTERVAL_DAY, true);
|
hookEngine.Call(HOOK_TYPE::INTERVAL_DAY, true);
|
||||||
}
|
}
|
||||||
report_time(LogicTimePart::Scripts);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (timings != nullptr)
|
|
||||||
{
|
|
||||||
timings->CurrentIdx = (timings->CurrentIdx + 1) % LOGIC_UPDATE_MEASUREMENTS_COUNT;
|
|
||||||
}
|
|
||||||
|
|
||||||
gInUpdateCode = false;
|
gInUpdateCode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,46 +21,6 @@ namespace OpenRCT2
|
|||||||
{
|
{
|
||||||
class Park;
|
class Park;
|
||||||
|
|
||||||
// Information regarding various pieces of logic update
|
|
||||||
enum class LogicTimePart
|
|
||||||
{
|
|
||||||
NetworkUpdate,
|
|
||||||
Date,
|
|
||||||
Scenario,
|
|
||||||
Climate,
|
|
||||||
MapTiles,
|
|
||||||
MapStashProvisionalElements,
|
|
||||||
MapPathWideFlags,
|
|
||||||
Peep,
|
|
||||||
MapRestoreProvisionalElements,
|
|
||||||
Vehicle,
|
|
||||||
Misc,
|
|
||||||
Ride,
|
|
||||||
Park,
|
|
||||||
Research,
|
|
||||||
RideRatings,
|
|
||||||
RideMeasurments,
|
|
||||||
News,
|
|
||||||
MapAnimation,
|
|
||||||
Sounds,
|
|
||||||
GameActions,
|
|
||||||
NetworkFlush,
|
|
||||||
Scripts,
|
|
||||||
};
|
|
||||||
|
|
||||||
// ~6.5s at 40Hz
|
|
||||||
constexpr size_t LOGIC_UPDATE_MEASUREMENTS_COUNT = 256;
|
|
||||||
|
|
||||||
// In order not to cause allocations, collect multiple samples into single pre-allocated struct
|
|
||||||
using LogicTimingInfo = std::unordered_map<
|
|
||||||
LogicTimePart, std::array<std::chrono::duration<double>, LOGIC_UPDATE_MEASUREMENTS_COUNT>>;
|
|
||||||
|
|
||||||
struct LogicTimings
|
|
||||||
{
|
|
||||||
LogicTimingInfo TimingInfo;
|
|
||||||
size_t CurrentIdx{};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to update the state of the map and park.
|
* Class to update the state of the map and park.
|
||||||
*/
|
*/
|
||||||
@@ -85,7 +45,7 @@ namespace OpenRCT2
|
|||||||
|
|
||||||
void InitAll(const TileCoordsXY& mapSize);
|
void InitAll(const TileCoordsXY& mapSize);
|
||||||
void Tick();
|
void Tick();
|
||||||
void UpdateLogic(LogicTimings* timings = nullptr);
|
void UpdateLogic();
|
||||||
void SetDate(Date newDate);
|
void SetDate(Date newDate);
|
||||||
void ResetDate();
|
void ResetDate();
|
||||||
|
|
||||||
|
|||||||
@@ -1,160 +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 "CommandLine.hpp"
|
|
||||||
|
|
||||||
#ifdef USE_BENCHMARK
|
|
||||||
|
|
||||||
# include "../Context.h"
|
|
||||||
# include "../GameState.h"
|
|
||||||
# include "../OpenRCT2.h"
|
|
||||||
# include "../core/File.h"
|
|
||||||
# include "../platform/Platform.h"
|
|
||||||
|
|
||||||
# include <benchmark/benchmark.h>
|
|
||||||
# include <cstdint>
|
|
||||||
# include <iterator>
|
|
||||||
# include <numeric>
|
|
||||||
# include <vector>
|
|
||||||
|
|
||||||
using namespace OpenRCT2;
|
|
||||||
|
|
||||||
static void BM_update(benchmark::State& state, const std::string& filename)
|
|
||||||
{
|
|
||||||
std::unique_ptr<IContext> context(CreateContext());
|
|
||||||
if (context->Initialise())
|
|
||||||
{
|
|
||||||
if (!filename.empty() && !context->LoadParkFromFile(filename))
|
|
||||||
{
|
|
||||||
state.SkipWithError("Failed to load file!");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<LogicTimings> timings(1);
|
|
||||||
timings.reserve(100);
|
|
||||||
int currentTimingIdx = 0;
|
|
||||||
for (auto _ : state)
|
|
||||||
{
|
|
||||||
if (timings[currentTimingIdx].CurrentIdx == (LOGIC_UPDATE_MEASUREMENTS_COUNT - 1))
|
|
||||||
{
|
|
||||||
timings.resize(timings.size() + 1);
|
|
||||||
currentTimingIdx++;
|
|
||||||
}
|
|
||||||
LogicTimings* timingToUse = &timings[currentTimingIdx];
|
|
||||||
context->GetGameState()->UpdateLogic(timingToUse);
|
|
||||||
}
|
|
||||||
state.SetItemsProcessed(state.iterations());
|
|
||||||
auto accumulator = [timings](LogicTimePart part) -> double {
|
|
||||||
std::chrono::duration<double> timesum;
|
|
||||||
for (const auto& timing : timings)
|
|
||||||
{
|
|
||||||
timesum = std::accumulate(
|
|
||||||
timing.TimingInfo.at(part).begin(), timing.TimingInfo.at(part).end(), std::chrono::duration<double>());
|
|
||||||
}
|
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(timesum).count();
|
|
||||||
};
|
|
||||||
state.counters["NetworkUpdateAcc_ms"] = accumulator(LogicTimePart::NetworkUpdate);
|
|
||||||
state.counters["DateAcc_ms"] = accumulator(LogicTimePart::Date);
|
|
||||||
state.counters["ScenarioAcc_ms"] = accumulator(LogicTimePart::Scenario);
|
|
||||||
state.counters["ClimateAcc_ms"] = accumulator(LogicTimePart::Climate);
|
|
||||||
state.counters["MapTilesAcc_ms"] = accumulator(LogicTimePart::MapTiles);
|
|
||||||
state.counters["MapStashProvisionalElementsAcc_ms"] = accumulator(LogicTimePart::MapStashProvisionalElements);
|
|
||||||
state.counters["MapPathWideFlagsAcc_ms"] = accumulator(LogicTimePart::MapPathWideFlags);
|
|
||||||
state.counters["PeepAcc_ms"] = accumulator(LogicTimePart::Peep);
|
|
||||||
state.counters["MapRestoreProvisionalElementsAcc_ms"] = accumulator(LogicTimePart::MapRestoreProvisionalElements);
|
|
||||||
state.counters["VehicleAcc_ms"] = accumulator(LogicTimePart::Vehicle);
|
|
||||||
state.counters["MiscAcc_ms"] = accumulator(LogicTimePart::Misc);
|
|
||||||
state.counters["RideAcc_ms"] = accumulator(LogicTimePart::Ride);
|
|
||||||
state.counters["ParkAcc_ms"] = accumulator(LogicTimePart::Park);
|
|
||||||
state.counters["ResearchAcc_ms"] = accumulator(LogicTimePart::Research);
|
|
||||||
state.counters["RideRatingsAcc_ms"] = accumulator(LogicTimePart::RideRatings);
|
|
||||||
state.counters["RideMeasurmentsAcc_ms"] = accumulator(LogicTimePart::RideMeasurments);
|
|
||||||
state.counters["NewsAcc_ms"] = accumulator(LogicTimePart::News);
|
|
||||||
state.counters["MapAnimationAcc_ms"] = accumulator(LogicTimePart::MapAnimation);
|
|
||||||
state.counters["SoundsAcc_ms"] = accumulator(LogicTimePart::Sounds);
|
|
||||||
state.counters["GameActionsAcc_ms"] = accumulator(LogicTimePart::GameActions);
|
|
||||||
state.counters["NetworkFlushAcc_ms"] = accumulator(LogicTimePart::NetworkFlush);
|
|
||||||
state.counters["ScriptsAcc_ms"] = accumulator(LogicTimePart::Scripts);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
state.SkipWithError("Context initialization failed.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int CommandLineForBenchSpriteSort(int argc, const char* const* argv)
|
|
||||||
{
|
|
||||||
// Add a baseline test on an empty park
|
|
||||||
benchmark::RegisterBenchmark("baseline", BM_update, std::string{});
|
|
||||||
|
|
||||||
// Google benchmark does stuff to argv. It doesn't modify the pointees,
|
|
||||||
// but it wants to reorder the pointers, so present a copy of them.
|
|
||||||
std::vector<char*> argv_for_benchmark;
|
|
||||||
|
|
||||||
// argv[0] is expected to contain the binary name. It's only for logging purposes, don't bother.
|
|
||||||
argv_for_benchmark.push_back(nullptr);
|
|
||||||
|
|
||||||
// Extract file names from argument list. If there is no such file, consider it benchmark option.
|
|
||||||
for (int i = 0; i < argc; i++)
|
|
||||||
{
|
|
||||||
if (File::Exists(argv[i]))
|
|
||||||
{
|
|
||||||
// Register benchmark for sv6 if valid
|
|
||||||
benchmark::RegisterBenchmark(argv[i], BM_update, argv[i]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
argv_for_benchmark.push_back(const_cast<char*>(argv[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Update argc with all the changes made
|
|
||||||
argc = static_cast<int>(argv_for_benchmark.size());
|
|
||||||
::benchmark::Initialize(&argc, &argv_for_benchmark[0]);
|
|
||||||
if (::benchmark::ReportUnrecognizedArguments(argc, &argv_for_benchmark[0]))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
gOpenRCT2Headless = true;
|
|
||||||
|
|
||||||
::benchmark::RunSpecifiedBenchmarks();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static exitcode_t HandleBenchUpdate(CommandLineArgEnumerator* argEnumerator)
|
|
||||||
{
|
|
||||||
const char* const* argv = static_cast<const char* const*>(argEnumerator->GetArguments()) + argEnumerator->GetIndex();
|
|
||||||
int32_t argc = argEnumerator->GetCount() - argEnumerator->GetIndex();
|
|
||||||
int32_t result = CommandLineForBenchSpriteSort(argc, argv);
|
|
||||||
if (result < 0)
|
|
||||||
{
|
|
||||||
return EXITCODE_FAIL;
|
|
||||||
}
|
|
||||||
return EXITCODE_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
static exitcode_t HandleBenchUpdate(CommandLineArgEnumerator* argEnumerator)
|
|
||||||
{
|
|
||||||
LOG_ERROR("Sorry, Google benchmark not enabled in this build");
|
|
||||||
return EXITCODE_FAIL;
|
|
||||||
}
|
|
||||||
#endif // USE_BENCHMARK
|
|
||||||
|
|
||||||
const CommandLineCommand CommandLine::BenchUpdateCommands[]{
|
|
||||||
#ifdef USE_BENCHMARK
|
|
||||||
DefineCommand(
|
|
||||||
"",
|
|
||||||
"<file>... [--benchmark_list_tests={true|false}] [--benchmark_filter=<regex>] [--benchmark_min_time=<min_time>] "
|
|
||||||
"[--benchmark_repetitions=<num_repetitions>] [--benchmark_report_aggregates_only={true|false}] "
|
|
||||||
"[--benchmark_format=<console|json|csv>] [--benchmark_out=<filename>] [--benchmark_out_format=<json|console|csv>] "
|
|
||||||
"[--benchmark_color={auto|true|false}] [--benchmark_counters_tabular={true|false}] [--v=<verbosity>]",
|
|
||||||
nullptr, HandleBenchUpdate),
|
|
||||||
CommandTableEnd
|
|
||||||
#else
|
|
||||||
DefineCommand("", "*** SORRY NOT ENABLED IN THIS BUILD ***", nullptr, HandleBenchUpdate), CommandTableEnd
|
|
||||||
#endif // USE_BENCHMARK
|
|
||||||
};
|
|
||||||
@@ -117,7 +117,6 @@ namespace CommandLine
|
|||||||
extern const CommandLineCommand ScreenshotCommands[];
|
extern const CommandLineCommand ScreenshotCommands[];
|
||||||
extern const CommandLineCommand SpriteCommands[];
|
extern const CommandLineCommand SpriteCommands[];
|
||||||
extern const CommandLineCommand BenchGfxCommands[];
|
extern const CommandLineCommand BenchGfxCommands[];
|
||||||
extern const CommandLineCommand BenchUpdateCommands[];
|
|
||||||
extern const CommandLineCommand SimulateCommands[];
|
extern const CommandLineCommand SimulateCommands[];
|
||||||
extern const CommandLineCommand ParkInfoCommands[];
|
extern const CommandLineCommand ParkInfoCommands[];
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,6 @@ const CommandLineCommand CommandLine::RootCommands[]
|
|||||||
DefineSubCommand("screenshot", CommandLine::ScreenshotCommands ),
|
DefineSubCommand("screenshot", CommandLine::ScreenshotCommands ),
|
||||||
DefineSubCommand("sprite", CommandLine::SpriteCommands ),
|
DefineSubCommand("sprite", CommandLine::SpriteCommands ),
|
||||||
DefineSubCommand("benchgfx", CommandLine::BenchGfxCommands ),
|
DefineSubCommand("benchgfx", CommandLine::BenchGfxCommands ),
|
||||||
DefineSubCommand("benchsimulate", CommandLine::BenchUpdateCommands ),
|
|
||||||
DefineSubCommand("simulate", CommandLine::SimulateCommands ),
|
DefineSubCommand("simulate", CommandLine::SimulateCommands ),
|
||||||
DefineSubCommand("parkinfo", CommandLine::ParkInfoCommands ),
|
DefineSubCommand("parkinfo", CommandLine::ParkInfoCommands ),
|
||||||
CommandTableEnd
|
CommandTableEnd
|
||||||
|
|||||||
@@ -691,7 +691,6 @@
|
|||||||
<ClCompile Include="Cheats.cpp" />
|
<ClCompile Include="Cheats.cpp" />
|
||||||
<ClCompile Include="CommandLineSprite.cpp" />
|
<ClCompile Include="CommandLineSprite.cpp" />
|
||||||
<ClCompile Include="command_line\BenchGfxCommmands.cpp" />
|
<ClCompile Include="command_line\BenchGfxCommmands.cpp" />
|
||||||
<ClCompile Include="command_line/BenchUpdate.cpp" />
|
|
||||||
<ClCompile Include="command_line\CommandLine.cpp" />
|
<ClCompile Include="command_line\CommandLine.cpp" />
|
||||||
<ClCompile Include="command_line\ConvertCommand.cpp" />
|
<ClCompile Include="command_line\ConvertCommand.cpp" />
|
||||||
<ClCompile Include="command_line\ParkInfoCommands.cpp" />
|
<ClCompile Include="command_line\ParkInfoCommands.cpp" />
|
||||||
|
|||||||
Reference in New Issue
Block a user