From 269673e3aa40923337f2cde1d7744a5cf5fc0615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 29 Jan 2022 05:29:08 -0800 Subject: [PATCH] Profiler update (#16463) * Add more functions to be profiled * Add isEnabled method to Profiler scripting interface * Bump up scripting version * Apply review suggestions --- distribution/openrct2.d.ts | 1 + src/openrct2/Context.cpp | 8 +++++++ src/openrct2/entity/Balloon.cpp | 3 +++ src/openrct2/entity/Duck.cpp | 3 +++ src/openrct2/entity/Fountain.cpp | 3 +++ src/openrct2/entity/Litter.cpp | 3 +++ src/openrct2/entity/MoneyEffect.cpp | 3 +++ src/openrct2/entity/Particle.cpp | 11 ++++++++++ src/openrct2/entity/Peep.cpp | 8 +++++++ src/openrct2/interface/Viewport.cpp | 16 ++++++++++++++ src/openrct2/management/Award.cpp | 3 +++ src/openrct2/management/Finance.cpp | 7 +++++++ src/openrct2/management/Marketing.cpp | 3 +++ src/openrct2/paint/Paint.Entity.cpp | 3 +++ src/openrct2/paint/Paint.cpp | 2 ++ src/openrct2/paint/Painter.cpp | 7 +++++++ src/openrct2/paint/VirtualFloor.cpp | 5 +++++ .../paint/tile_element/Paint.Banner.cpp | 5 +++++ .../paint/tile_element/Paint.Entrance.cpp | 17 +++++++++++++++ .../paint/tile_element/Paint.LargeScenery.cpp | 11 ++++++++++ .../paint/tile_element/Paint.Path.cpp | 14 +++++++++++++ .../paint/tile_element/Paint.SmallScenery.cpp | 5 +++++ .../paint/tile_element/Paint.Surface.cpp | 21 +++++++++++++++++++ .../paint/tile_element/Paint.TileElement.cpp | 5 +++++ .../paint/tile_element/Paint.Wall.cpp | 13 ++++++++++++ src/openrct2/peep/GuestPathfinding.cpp | 5 +++++ src/openrct2/scripting/ScriptEngine.h | 2 +- .../scripting/bindings/game/ScProfiler.hpp | 6 ++++++ 28 files changed, 192 insertions(+), 1 deletion(-) diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index 9186ae1cbc..0c3f09c198 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -2705,6 +2705,7 @@ declare global { start(): void; stop(): void; reset(): void; + readonly enabled: boolean; } interface ProfiledFunction { diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 165b76d412..6ae4812c41 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -976,6 +976,8 @@ namespace OpenRCT2 */ void RunGameLoop() { + PROFILED_FUNCTION(); + log_verbose("begin openrct2 loop"); _finished = false; @@ -998,6 +1000,8 @@ namespace OpenRCT2 void RunFrame() { + PROFILED_FUNCTION(); + const auto deltaTime = _timer.GetElapsedTimeAndRestart().count(); // Make sure we catch the state change and reset it. @@ -1042,6 +1046,8 @@ namespace OpenRCT2 void RunFixedFrame(float deltaTime) { + PROFILED_FUNCTION(); + _uiContext->ProcessMessages(); if (_ticksAccumulator < GAME_UPDATE_TIME_MS) @@ -1069,6 +1075,8 @@ namespace OpenRCT2 void RunVariableFrame(float deltaTime) { + PROFILED_FUNCTION(); + const bool shouldDraw = ShouldDraw(); auto& tweener = EntityTweener::Get(); diff --git a/src/openrct2/entity/Balloon.cpp b/src/openrct2/entity/Balloon.cpp index e4ff7b530f..c5cc3403e9 100644 --- a/src/openrct2/entity/Balloon.cpp +++ b/src/openrct2/entity/Balloon.cpp @@ -14,6 +14,7 @@ #include "../core/DataSerialiser.h" #include "../network/network.h" #include "../paint/Paint.h" +#include "../profiling/Profiling.h" #include "../scenario/Scenario.h" #include "../util/Util.h" #include "EntityRegistry.h" @@ -110,6 +111,8 @@ void Balloon::Serialise(DataSerialiser& stream) void Balloon::Paint(paint_session& session, int32_t imageDirection) const { + PROFILED_FUNCTION(); + uint32_t imageId = 22651 + (frame & 7); if (popped != 0) { diff --git a/src/openrct2/entity/Duck.cpp b/src/openrct2/entity/Duck.cpp index 22f76498d7..96558c7317 100644 --- a/src/openrct2/entity/Duck.cpp +++ b/src/openrct2/entity/Duck.cpp @@ -13,6 +13,7 @@ #include "../core/DataSerialiser.h" #include "../localisation/Date.h" #include "../paint/Paint.h" +#include "../profiling/Profiling.h" #include "../scenario/Scenario.h" #include "../sprites.h" #include "../world/Surface.h" @@ -366,6 +367,8 @@ void Duck::Serialise(DataSerialiser& stream) void Duck::Paint(paint_session& session, int32_t imageDirection) const { + PROFILED_FUNCTION(); + rct_drawpixelinfo& dpi = session.DPI; if (dpi.zoom_level > ZoomLevel{ 1 }) return; diff --git a/src/openrct2/entity/Fountain.cpp b/src/openrct2/entity/Fountain.cpp index 4539394d09..27552ca7d6 100644 --- a/src/openrct2/entity/Fountain.cpp +++ b/src/openrct2/entity/Fountain.cpp @@ -12,6 +12,7 @@ #include "../Game.h" #include "../core/DataSerialiser.h" #include "../paint/Paint.h" +#include "../profiling/Profiling.h" #include "../scenario/Scenario.h" #include "../world/Footpath.h" #include "../world/Map.h" @@ -396,6 +397,8 @@ void JumpingFountain::Serialise(DataSerialiser& stream) void JumpingFountain::Paint(paint_session& session, int32_t imageDirection) const { + PROFILED_FUNCTION(); + // TODO: Move into sprites.h constexpr uint32_t JumpingFountainSnowBaseImage = 23037; constexpr uint32_t JumpingFountainWaterBaseImage = 22973; diff --git a/src/openrct2/entity/Litter.cpp b/src/openrct2/entity/Litter.cpp index fe549cc3d6..24ce4bb753 100644 --- a/src/openrct2/entity/Litter.cpp +++ b/src/openrct2/entity/Litter.cpp @@ -5,6 +5,7 @@ #include "../core/DataSerialiser.h" #include "../localisation/StringIds.h" #include "../paint/Paint.h" +#include "../profiling/Profiling.h" #include "../sprites.h" #include "../world/Map.h" #include "EntityList.h" @@ -171,6 +172,8 @@ static constexpr const LitterSprite _litterSprites[] = { void Litter::Paint(paint_session& session, int32_t imageDirection) const { + PROFILED_FUNCTION(); + rct_drawpixelinfo& dpi = session.DPI; if (dpi.zoom_level > ZoomLevel{ 0 }) return; // If zoomed at all no litter drawn diff --git a/src/openrct2/entity/MoneyEffect.cpp b/src/openrct2/entity/MoneyEffect.cpp index 6faa8cbfc3..83b92171cd 100644 --- a/src/openrct2/entity/MoneyEffect.cpp +++ b/src/openrct2/entity/MoneyEffect.cpp @@ -16,6 +16,7 @@ #include "../localisation/Localisation.h" #include "../network/network.h" #include "../paint/Paint.h" +#include "../profiling/Profiling.h" #include "../world/Map.h" #include "EntityRegistry.h" @@ -168,6 +169,8 @@ void MoneyEffect::Serialise(DataSerialiser& stream) void MoneyEffect::Paint(paint_session& session, int32_t imageDirection) const { + PROFILED_FUNCTION(); + rct_drawpixelinfo& dpi = session.DPI; if (dpi.zoom_level > ZoomLevel{ 0 }) { diff --git a/src/openrct2/entity/Particle.cpp b/src/openrct2/entity/Particle.cpp index 606a440825..0b206afa4d 100644 --- a/src/openrct2/entity/Particle.cpp +++ b/src/openrct2/entity/Particle.cpp @@ -11,6 +11,7 @@ #include "../audio/audio.h" #include "../core/DataSerialiser.h" #include "../paint/Paint.h" +#include "../profiling/Profiling.h" #include "../scenario/Scenario.h" #include "EntityRegistry.h" @@ -151,6 +152,8 @@ void VehicleCrashParticle::Serialise(DataSerialiser& stream) void VehicleCrashParticle::Paint(paint_session& session, int32_t imageDirection) const { + PROFILED_FUNCTION(); + rct_drawpixelinfo& dpi = session.DPI; if (dpi.zoom_level > ZoomLevel{ 0 }) { @@ -201,6 +204,8 @@ void CrashSplashParticle::Serialise(DataSerialiser& stream) void CrashSplashParticle::Paint(paint_session& session, int32_t imageDirection) const { + PROFILED_FUNCTION(); + // TODO: Create constant in sprites.h uint32_t imageId = 22927 + (frame / 256); PaintAddImageAsParent(session, imageId, { 0, 0, z }, { 1, 1, 0 }); @@ -258,6 +263,8 @@ void SteamParticle::Serialise(DataSerialiser& stream) void SteamParticle::Paint(paint_session& session, int32_t imageDirection) const { + PROFILED_FUNCTION(); + // TODO: Create constant in sprites.h uint32_t imageId = 22637 + (frame / 256); PaintAddImageAsParent(session, imageId, { 0, 0, z }, { 1, 1, 0 }); @@ -302,6 +309,8 @@ void ExplosionCloud::Serialise(DataSerialiser& stream) void ExplosionCloud::Paint(paint_session& session, int32_t imageDirection) const { + PROFILED_FUNCTION(); + uint32_t imageId = 22878 + (frame / 256); PaintAddImageAsParent(session, imageId, { 0, 0, z }, { 1, 1, 0 }); } @@ -345,6 +354,8 @@ void ExplosionFlare::Serialise(DataSerialiser& stream) void ExplosionFlare::Paint(paint_session& session, int32_t imageDirection) const { + PROFILED_FUNCTION(); + // TODO: Create constant in sprites.h uint32_t imageId = 22896 + (frame / 256); PaintAddImageAsParent(session, imageId, { 0, 0, z }, { 1, 1, 0 }); diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 4f0a7f7bcd..b1f052babe 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -251,6 +251,8 @@ void peep_update_all() */ static void peep_128_tick_update(Peep* peep, int32_t index) { + PROFILED_FUNCTION(); + auto* guest = peep->As(); if (guest != nullptr) { @@ -272,6 +274,8 @@ static void peep_128_tick_update(Peep* peep, int32_t index) */ bool Peep::CheckForPath() { + PROFILED_FUNCTION(); + PathCheckOptimisation++; if ((PathCheckOptimisation & 0xF) != (sprite_index & 0xF)) { @@ -397,6 +401,8 @@ std::optional Peep::UpdateAction() */ std::optional Peep::UpdateAction(int16_t& xy_distance) { + PROFILED_FUNCTION(); + _unk_F1AEF0 = ActionSpriteImageOffset; if (Action == PeepActionType::Idle) { @@ -2686,6 +2692,8 @@ void Peep::Serialise(DataSerialiser& stream) void Peep::Paint(paint_session& session, int32_t imageDirection) const { + PROFILED_FUNCTION(); + #ifdef __ENABLE_LIGHTFX__ if (lightfx_is_available()) { diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index eac7bc4f33..861af34857 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -900,6 +900,8 @@ static void record_session( static void viewport_fill_column( paint_session& session, std::vector* recorded_sessions, size_t record_index) { + PROFILED_FUNCTION(); + PaintSessionGenerate(session); if (recorded_sessions != nullptr) { @@ -910,6 +912,8 @@ static void viewport_fill_column( static void viewport_paint_column(paint_session& session) { + PROFILED_FUNCTION(); + if (session.ViewFlags & (VIEWPORT_FLAG_HIDE_VERTICAL | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_CLIP_VIEW) @@ -1365,6 +1369,8 @@ static bool PSSpriteTypeIsInFilter(paint_struct* ps, uint16_t filter) static bool is_pixel_present_bmp( uint32_t imageType, const rct_g1_element* g1, const uint8_t* index, const PaletteMap& paletteMap) { + PROFILED_FUNCTION(); + // Probably used to check for corruption if (!(g1->flags & G1_FLAG_BMP)) { @@ -1389,6 +1395,8 @@ static bool is_pixel_present_bmp( */ static bool is_pixel_present_rle(const uint8_t* esi, int32_t x_start_point, int32_t y_start_point, int32_t round) { + PROFILED_FUNCTION(); + uint32_t start_offset = esi[y_start_point * 2] | (esi[y_start_point * 2 + 1] << 8); const uint8_t* ebx = esi + start_offset; @@ -1482,6 +1490,8 @@ static bool is_pixel_present_rle(const uint8_t* esi, int32_t x_start_point, int3 static bool is_sprite_interacted_with_palette_set( rct_drawpixelinfo* dpi, ImageId imageId, const ScreenCoordsXY& coords, const PaletteMap& paletteMap) { + PROFILED_FUNCTION(); + const rct_g1_element* g1 = gfx_get_g1_element(imageId); if (g1 == nullptr) { @@ -1626,6 +1636,8 @@ static bool is_sprite_interacted_with_palette_set( static bool is_sprite_interacted_with(rct_drawpixelinfo* dpi, ImageId imageId, const ScreenCoordsXY& coords) { + PROFILED_FUNCTION(); + auto paletteMap = PaletteMap::GetDefault(); if (imageId.HasPrimary() || imageId.IsRemap()) { @@ -1657,6 +1669,8 @@ static bool is_sprite_interacted_with(rct_drawpixelinfo* dpi, ImageId imageId, c */ InteractionInfo set_interaction_info_from_paint_session(paint_session* session, uint16_t filter) { + PROFILED_FUNCTION(); + paint_struct* ps = &session->PaintHead; rct_drawpixelinfo* dpi = &session->DPI; InteractionInfo info{}; @@ -1755,6 +1769,8 @@ InteractionInfo get_map_coordinates_from_pos_window(rct_window* window, const Sc */ void viewport_invalidate(const rct_viewport* viewport, const ScreenRect& screenRect) { + PROFILED_FUNCTION(); + // if unknown viewport visibility, use the containing window to discover the status if (viewport->visibility == VisibilityCache::Unknown) { diff --git a/src/openrct2/management/Award.cpp b/src/openrct2/management/Award.cpp index d18690bda5..56f412ca17 100644 --- a/src/openrct2/management/Award.cpp +++ b/src/openrct2/management/Award.cpp @@ -14,6 +14,7 @@ #include "../interface/Window.h" #include "../localisation/Localisation.h" #include "../localisation/StringIds.h" +#include "../profiling/Profiling.h" #include "../ride/Ride.h" #include "../ride/RideData.h" #include "../scenario/Scenario.h" @@ -602,6 +603,8 @@ void award_reset() */ void award_update_all() { + PROFILED_FUNCTION(); + // Only add new awards if park is open if (gParkFlags & PARK_FLAGS_PARK_OPEN) { diff --git a/src/openrct2/management/Finance.cpp b/src/openrct2/management/Finance.cpp index 6f23a84040..7791dda8ed 100644 --- a/src/openrct2/management/Finance.cpp +++ b/src/openrct2/management/Finance.cpp @@ -17,6 +17,7 @@ #include "../interface/Window.h" #include "../localisation/Date.h" #include "../localisation/Localisation.h" +#include "../profiling/Profiling.h" #include "../ride/Ride.h" #include "../scenario/Scenario.h" #include "../util/Util.h" @@ -105,6 +106,8 @@ void finance_payment(money32 amount, ExpenditureType type) */ void finance_pay_wages() { + PROFILED_FUNCTION(); + if (gParkFlags & PARK_FLAGS_NO_MONEY) { return; @@ -157,6 +160,8 @@ void finance_pay_interest() */ void finance_pay_ride_upkeep() { + PROFILED_FUNCTION(); + for (auto& ride : GetRideManager()) { if (!(ride.lifecycle_flags & RIDE_LIFECYCLE_EVER_BEEN_OPENED)) @@ -233,6 +238,8 @@ void finance_init() */ void finance_update_daily_profit() { + PROFILED_FUNCTION(); + gCurrentProfit = 7 * gCurrentExpenditure; gCurrentExpenditure = 0; // Reset daily expenditure diff --git a/src/openrct2/management/Marketing.cpp b/src/openrct2/management/Marketing.cpp index ed84c9c8c6..adb8a0dd11 100644 --- a/src/openrct2/management/Marketing.cpp +++ b/src/openrct2/management/Marketing.cpp @@ -16,6 +16,7 @@ #include "../interface/Window.h" #include "../localisation/Formatter.h" #include "../localisation/Localisation.h" +#include "../profiling/Profiling.h" #include "../ride/Ride.h" #include "../ride/RideData.h" #include "../ride/ShopItem.h" @@ -97,6 +98,8 @@ static void marketing_raise_finished_notification(const MarketingCampaign& campa */ void marketing_update() { + PROFILED_FUNCTION(); + if (gCheatsNeverendingMarketing) return; diff --git a/src/openrct2/paint/Paint.Entity.cpp b/src/openrct2/paint/Paint.Entity.cpp index aaf786f6f8..d8681e85f5 100644 --- a/src/openrct2/paint/Paint.Entity.cpp +++ b/src/openrct2/paint/Paint.Entity.cpp @@ -20,6 +20,7 @@ #include "../entity/Particle.h" #include "../entity/Staff.h" #include "../interface/Viewport.h" +#include "../profiling/Profiling.h" #include "../ride/RideData.h" #include "../ride/TrackDesign.h" #include "../ride/Vehicle.h" @@ -35,6 +36,8 @@ */ void EntityPaintSetup(paint_session& session, const CoordsXY& pos) { + PROFILED_FUNCTION(); + if (!map_is_location_valid(pos)) { return; diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 7598f39dfb..267e7e04e1 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -529,6 +529,8 @@ static void PaintDrawStruct(paint_session& session, paint_struct* ps) */ void PaintDrawStructs(paint_session& session) { + PROFILED_FUNCTION(); + paint_struct* ps = &session.PaintHead; for (ps = ps->next_quadrant_ps; ps != nullptr;) diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index f831f9cb56..1615c7bf55 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -22,6 +22,7 @@ #include "../localisation/Formatting.h" #include "../localisation/Language.h" #include "../paint/Paint.h" +#include "../profiling/Profiling.h" #include "../title/TitleScreen.h" #include "../ui/UiContext.h" @@ -37,6 +38,8 @@ Painter::Painter(const std::shared_ptr& uiContext) void Painter::Paint(IDrawingEngine& de) { + PROFILED_FUNCTION(); + auto dpi = de.GetDrawingPixelInfo(); if (gIntroState != IntroState::None) { @@ -130,6 +133,8 @@ void Painter::MeasureFPS() paint_session* Painter::CreateSession(rct_drawpixelinfo* dpi, uint32_t viewFlags) { + PROFILED_FUNCTION(); + paint_session* session = nullptr; if (_freePaintSessions.empty() == false) @@ -167,6 +172,8 @@ paint_session* Painter::CreateSession(rct_drawpixelinfo* dpi, uint32_t viewFlags void Painter::ReleaseSession(paint_session* session) { + PROFILED_FUNCTION(); + session->PaintEntryChain.Clear(); _freePaintSessions.push_back(session); } diff --git a/src/openrct2/paint/VirtualFloor.cpp b/src/openrct2/paint/VirtualFloor.cpp index a92f04ece2..0ae25c522f 100644 --- a/src/openrct2/paint/VirtualFloor.cpp +++ b/src/openrct2/paint/VirtualFloor.cpp @@ -13,6 +13,7 @@ #include "../Input.h" #include "../config/Config.h" #include "../interface/Viewport.h" +#include "../profiling/Profiling.h" #include "../sprites.h" #include "../util/Util.h" #include "../world/Location.hpp" @@ -98,6 +99,8 @@ void virtual_floor_disable() void virtual_floor_invalidate() { + PROFILED_FUNCTION(); + // First, let's figure out how big our selection is. CoordsXY min_position = { std::numeric_limits::max(), std::numeric_limits::max() }; CoordsXY max_position = { std::numeric_limits::lowest(), std::numeric_limits::lowest() }; @@ -291,6 +294,8 @@ static void virtual_floor_get_tile_properties( void virtual_floor_paint(paint_session& session) { + PROFILED_FUNCTION(); + static constexpr const CoordsXY scenery_half_tile_offsets[4] = { { -COORDS_XY_STEP, 0 }, { 0, COORDS_XY_STEP }, diff --git a/src/openrct2/paint/tile_element/Paint.Banner.cpp b/src/openrct2/paint/tile_element/Paint.Banner.cpp index 16ff95624a..226abf278a 100644 --- a/src/openrct2/paint/tile_element/Paint.Banner.cpp +++ b/src/openrct2/paint/tile_element/Paint.Banner.cpp @@ -14,6 +14,7 @@ #include "../../interface/Viewport.h" #include "../../localisation/Formatter.h" #include "../../localisation/Localisation.h" +#include "../../profiling/Profiling.h" #include "../../ride/TrackDesign.h" #include "../../sprites.h" #include "../../world/Banner.h" @@ -34,6 +35,8 @@ static void PaintBannerScrollingText( paint_session& session, const BannerSceneryEntry& bannerEntry, Banner& banner, const BannerElement& bannerElement, Direction direction, int32_t height, const CoordsXYZ& bbOffset) { + PROFILED_FUNCTION(); + // If text on hidden direction or ghost direction = direction_reverse(direction) - 1; if (direction >= 2 || (bannerElement.IsGhost())) @@ -66,6 +69,8 @@ static void PaintBannerScrollingText( void PaintBanner(paint_session& session, uint8_t direction, int32_t height, const BannerElement& bannerElement) { + PROFILED_FUNCTION(); + if (session.DPI.zoom_level > ZoomLevel{ 1 } || gTrackDesignSaveMode || (session.ViewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES)) return; diff --git a/src/openrct2/paint/tile_element/Paint.Entrance.cpp b/src/openrct2/paint/tile_element/Paint.Entrance.cpp index 95178915eb..b6220288f2 100644 --- a/src/openrct2/paint/tile_element/Paint.Entrance.cpp +++ b/src/openrct2/paint/tile_element/Paint.Entrance.cpp @@ -20,6 +20,7 @@ #include "../../object/EntranceObject.h" #include "../../object/ObjectManager.h" #include "../../object/StationObject.h" +#include "../../profiling/Profiling.h" #include "../../ride/RideData.h" #include "../../ride/TrackDesign.h" #include "../../world/Banner.h" @@ -36,6 +37,8 @@ static void PaintRideEntranceExitScrollingText( paint_session& session, const EntranceElement& entranceEl, const StationObject& stationObj, Direction direction, int32_t height) { + PROFILED_FUNCTION(); + if (stationObj.ScrollingMode == SCROLLING_MODE_NONE) return; @@ -77,6 +80,8 @@ static void PaintRideEntranceExitScrollingText( static void PaintRideEntranceExitLightEffects(paint_session& session, int32_t height, const EntranceElement& entranceEl) { #ifdef __ENABLE_LIGHTFX__ + PROFILED_FUNCTION(); + if (lightfx_is_available()) { if (entranceEl.GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE) @@ -105,6 +110,8 @@ static void PaintRideEntranceExitLightEffects(paint_session& session, int32_t he static void PaintRideEntranceExit(paint_session& session, uint8_t direction, int32_t height, const EntranceElement& entranceEl) { + PROFILED_FUNCTION(); + auto rideIndex = entranceEl.GetRideIndex(); if ((gTrackDesignSaveMode || (session.ViewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES)) && (rideIndex != gTrackDesignSaveRideIndex)) @@ -203,6 +210,8 @@ static void PaintRideEntranceExit(paint_session& session, uint8_t direction, int static void PaintParkEntranceScrollingText( paint_session& session, const EntranceObject& entrance, Direction direction, int32_t height) { + PROFILED_FUNCTION(); + if ((direction + 1) & (1 << 1)) return; @@ -245,6 +254,8 @@ static void PaintParkEntranceScrollingText( static void PaintParkEntranceLightEffects(paint_session& session) { #ifdef __ENABLE_LIGHTFX__ + PROFILED_FUNCTION(); + if (lightfx_is_available()) { lightfx_add_3d_light_magic_from_drawing_tile(session.MapPosition, 0, 0, 155, LightType::Lantern3); @@ -254,6 +265,8 @@ static void PaintParkEntranceLightEffects(paint_session& session) static void PaintParkEntrance(paint_session& session, uint8_t direction, int32_t height, const EntranceElement& entranceEl) { + PROFILED_FUNCTION(); + if (gTrackDesignSaveMode || (session.ViewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES)) return; @@ -325,6 +338,8 @@ static void PaintParkEntrance(paint_session& session, uint8_t direction, int32_t static void PaintHeightMarkers(paint_session& session, const EntranceElement& entranceEl, int32_t height) { + PROFILED_FUNCTION(); + if (PaintShouldShowHeightMarkers(session, VIEWPORT_FLAG_PATH_HEIGHTS)) { if (entranceEl.GetDirections() & 0xF) @@ -342,6 +357,8 @@ static void PaintHeightMarkers(paint_session& session, const EntranceElement& en void PaintEntrance(paint_session& session, uint8_t direction, int32_t height, const EntranceElement& entranceElement) { + PROFILED_FUNCTION(); + session.InteractionType = ViewportInteractionItem::Label; PaintHeightMarkers(session, entranceElement, height); diff --git a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp index 87414496e1..10f7414d9b 100644 --- a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp +++ b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp @@ -17,6 +17,7 @@ #include "../../localisation/Formatter.h" #include "../../localisation/Localisation.h" #include "../../object/LargeSceneryObject.h" +#include "../../profiling/Profiling.h" #include "../../ride/Ride.h" #include "../../ride/TrackDesign.h" #include "../../util/Util.h" @@ -60,6 +61,8 @@ static void PaintLargeScenerySupports( paint_session& session, uint8_t direction, uint16_t height, const LargeSceneryElement& tileElement, ImageId imageTemplate, const rct_large_scenery_tile& tile) { + PROFILED_FUNCTION(); + if (tile.flags & LARGE_SCENERY_TILE_FLAG_NO_SUPPORTS) return; @@ -110,6 +113,8 @@ static void PaintLargeScenery3DTextLine( paint_session& session, const LargeSceneryEntry& sceneryEntry, const LargeSceneryText& text, std::string_view line, ImageId imageTemplate, Direction direction, int32_t offsetY) { + PROFILED_FUNCTION(); + line = LargeSceneryCalculateDisplayText(text, line, false); auto width = text.MeasureWidth(line); auto offsetX = text.offset[(direction & 1)].x; @@ -184,6 +189,8 @@ static void PaintLargeScenery3DText( paint_session& session, const LargeSceneryEntry& sceneryEntry, const rct_large_scenery_tile& tile, const LargeSceneryElement& tileElement, uint8_t direction, uint16_t height, bool isGhost) { + PROFILED_FUNCTION(); + if (sceneryEntry.tiles[1].x_offset != -1) { auto sequenceDirection = (tileElement.GetSequenceIndex() - 1) & 3; @@ -296,6 +303,8 @@ static void PaintLargeSceneryScrollingText( paint_session& session, const LargeSceneryEntry& sceneryEntry, const LargeSceneryElement& tileElement, uint8_t direction, uint16_t height, const CoordsXYZ& bbOffset, bool isGhost) { + PROFILED_FUNCTION(); + auto textColour = isGhost ? static_cast(COLOUR_GREY) : tileElement.GetSecondaryColour(); auto textPaletteIndex = direction == 0 ? ColourMapA[textColour].mid_dark : ColourMapA[textColour].light; @@ -325,6 +334,8 @@ static void PaintLargeSceneryScrollingText( void PaintLargeScenery(paint_session& session, uint8_t direction, uint16_t height, const LargeSceneryElement& tileElement) { + PROFILED_FUNCTION(); + if (session.ViewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES) return; diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 5269e3bd11..38ff6bb0e2 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -25,6 +25,7 @@ #include "../../object/FootpathSurfaceObject.h" #include "../../object/ObjectList.h" #include "../../object/ObjectManager.h" +#include "../../profiling/Profiling.h" #include "../../ride/Ride.h" #include "../../ride/Track.h" #include "../../ride/TrackDesign.h" @@ -290,6 +291,8 @@ static void sub_6A4101( paint_session& session, const PathElement& pathElement, uint16_t height, uint32_t connectedEdges, bool hasSupports, const FootpathPaintInfo& pathPaintInfo, ImageId imageTemplate) { + PROFILED_FUNCTION(); + auto imageId = imageTemplate.WithIndex(pathPaintInfo.RailingsImageId); if (pathElement.IsQueue()) { @@ -719,6 +722,7 @@ static void sub_6A3F61( // esp: [ esi, ???, 000] // Probably drawing benches etc. + PROFILED_FUNCTION(); rct_drawpixelinfo* dpi = &session.DPI; @@ -936,6 +940,8 @@ static void PaintPatrolAreas(paint_session& session, const PathElement& pathEl) static void PaintHeightMarkers(paint_session& session, const PathElement& pathEl) { + PROFILED_FUNCTION(); + if (PaintShouldShowHeightMarkers(session, VIEWPORT_FLAG_PATH_HEIGHTS)) { uint16_t heightMarkerBaseZ = pathEl.GetBaseZ() + 3; @@ -956,6 +962,8 @@ static void PaintHeightMarkers(paint_session& session, const PathElement& pathEl static void PaintLampLightEffects(paint_session& session, const PathElement& pathEl, uint16_t height) { #ifdef __ENABLE_LIGHTFX__ + PROFILED_FUNCTION(); + if (lightfx_is_available()) { if (pathEl.HasAddition() && !(pathEl.IsBroken())) @@ -990,6 +998,8 @@ static void PaintLampLightEffects(paint_session& session, const PathElement& pat */ void PaintPath(paint_session& session, uint16_t height, const PathElement& tileElement) { + PROFILED_FUNCTION(); + session.InteractionType = ViewportInteractionItem::Footpath; ImageId imageTemplate, sceneryImageTemplate; @@ -1061,6 +1071,8 @@ void path_paint_box_support( paint_session& session, const PathElement& pathElement, int32_t height, const FootpathPaintInfo& pathPaintInfo, bool hasSupports, ImageId imageTemplate, ImageId sceneryImageTemplate) { + PROFILED_FUNCTION(); + // Rol edges around rotation uint8_t edges = ((pathElement.GetEdges() << session.CurrentRotation) & 0xF) | (((pathElement.GetEdges()) << session.CurrentRotation) >> 4); @@ -1196,6 +1208,8 @@ void path_paint_pole_support( paint_session& session, const PathElement& pathElement, int16_t height, const FootpathPaintInfo& pathPaintInfo, bool hasSupports, ImageId imageTemplate, ImageId sceneryImageTemplate) { + PROFILED_FUNCTION(); + // Rol edges around rotation uint8_t edges = ((pathElement.GetEdges() << session.CurrentRotation) & 0xF) | (((pathElement.GetEdges()) << session.CurrentRotation) >> 4); diff --git a/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp b/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp index 4d8b8bbb1b..b47cf74b3d 100644 --- a/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp +++ b/src/openrct2/paint/tile_element/Paint.SmallScenery.cpp @@ -13,6 +13,7 @@ #include "../../config/Config.h" #include "../../interface/Viewport.h" #include "../../localisation/Date.h" +#include "../../profiling/Profiling.h" #include "../../ride/TrackDesign.h" #include "../../util/Util.h" #include "../../world/Map.h" @@ -33,6 +34,8 @@ static void PaintSmallScenerySupports( paint_session& session, const SmallSceneryEntry& sceneryEntry, const SmallSceneryElement& sceneryElement, Direction direction, int32_t height, ImageId imageTemplate) { + PROFILED_FUNCTION(); + if (!sceneryElement.NeedsSupports()) return; @@ -106,6 +109,8 @@ static void SetSupportHeights( */ void PaintSmallScenery(paint_session& session, uint8_t direction, int32_t height, const SmallSceneryElement& sceneryElement) { + PROFILED_FUNCTION(); + if (session.ViewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES) { return; diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index 772f630655..92c83d4911 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -25,6 +25,7 @@ #include "../../object/TerrainEdgeObject.h" #include "../../object/TerrainSurfaceObject.h" #include "../../paint/Paint.h" +#include "../../profiling/Profiling.h" #include "../../ride/TrackDesign.h" #include "../../sprites.h" #include "../../world/Surface.h" @@ -303,6 +304,8 @@ static constexpr const tile_surface_boundary_data _tileSurfaceBoundaries[4] = { static const TerrainSurfaceObject* get_surface_object(size_t index) { + PROFILED_FUNCTION(); + TerrainSurfaceObject* result{}; auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); auto obj = objMgr.GetLoadedObject(ObjectType::TerrainSurface, index); @@ -317,6 +320,8 @@ static ImageId get_surface_image( const paint_session& session, ObjectEntryIndex index, int32_t offset, uint8_t rotation, int32_t grassLength, bool grid, bool underground) { + PROFILED_FUNCTION(); + ImageId image; auto obj = get_surface_object(index); if (obj != nullptr) @@ -333,6 +338,8 @@ static ImageId get_surface_image( static ImageId get_surface_pattern(uint8_t index, int32_t offset) { + PROFILED_FUNCTION(); + ImageId image; auto obj = get_surface_object(index); if (obj != nullptr) @@ -348,6 +355,8 @@ static ImageId get_surface_pattern(uint8_t index, int32_t offset) static bool surface_should_smooth_self(uint8_t index) { + PROFILED_FUNCTION(); + auto obj = get_surface_object(index); if (obj != nullptr) { @@ -358,6 +367,8 @@ static bool surface_should_smooth_self(uint8_t index) static bool surface_should_smooth(uint8_t index) { + PROFILED_FUNCTION(); + auto obj = get_surface_object(index); if (obj != nullptr) { @@ -398,6 +409,8 @@ static ImageId get_edge_image(uint8_t index, uint8_t type) static ImageId get_tunnel_image(ObjectEntryIndex index, uint8_t type, edge_t edge) { + PROFILED_FUNCTION(); + static constexpr uint32_t offsets[TUNNEL_TYPE_COUNT] = { 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 36, 48, 60, 72, 76, 80, 84, 88, 92, 96, 100 }; @@ -436,6 +449,8 @@ static uint8_t viewport_surface_paint_setup_get_relative_slope(const SurfaceElem static void viewport_surface_smoothen_edge( paint_session& session, enum edge_t edge, struct tile_descriptor self, struct tile_descriptor neighbour) { + PROFILED_FUNCTION(); + if (neighbour.tile_element == nullptr) return; @@ -555,6 +570,8 @@ static void viewport_surface_draw_tile_side_bottom( paint_session& session, enum edge_t edge, uint16_t height, uint8_t edgeStyle, struct tile_descriptor self, struct tile_descriptor neighbour, bool isWater) { + PROFILED_FUNCTION(); + // From big Z to tiny Z height /= COORDS_Z_PER_TINY_Z; int16_t cornerHeight1, neighbourCornerHeight1, cornerHeight2, neighbourCornerHeight2; @@ -769,6 +786,8 @@ static void viewport_surface_draw_tile_side_top( paint_session& session, enum edge_t edge, uint16_t height, uint8_t terrain, struct tile_descriptor self, struct tile_descriptor neighbour, bool isWater) { + PROFILED_FUNCTION(); + // From big Z to tiny Z height /= COORDS_Z_PER_TINY_Z; @@ -955,6 +974,8 @@ static std::pair surface_get_height_above_water( */ void PaintSurface(paint_session& session, uint8_t direction, uint16_t height, const SurfaceElement& tileElement) { + PROFILED_FUNCTION(); + rct_drawpixelinfo* dpi = &session.DPI; session.InteractionType = ViewportInteractionItem::Terrain; session.DidPassSurface = true; diff --git a/src/openrct2/paint/tile_element/Paint.TileElement.cpp b/src/openrct2/paint/tile_element/Paint.TileElement.cpp index c0f05ad240..38c9ed9fcf 100644 --- a/src/openrct2/paint/tile_element/Paint.TileElement.cpp +++ b/src/openrct2/paint/tile_element/Paint.TileElement.cpp @@ -16,6 +16,7 @@ #include "../../drawing/Drawing.h" #include "../../interface/Viewport.h" #include "../../localisation/Localisation.h" +#include "../../profiling/Profiling.h" #include "../../ride/RideData.h" #include "../../ride/TrackData.h" #include "../../ride/TrackPaint.h" @@ -49,6 +50,8 @@ const int32_t SEGMENTS_ALL = SEGMENT_B4 | SEGMENT_B8 | SEGMENT_BC | SEGMENT_C0 | */ void tile_element_paint_setup(paint_session& session, const CoordsXY& mapCoords, bool isTrackPiecePreview) { + PROFILED_FUNCTION(); + if (!map_is_edge(mapCoords)) { paint_util_set_segment_support_height(session, SEGMENTS_ALL, 0xFFFF, 0); @@ -116,6 +119,8 @@ bool gShowSupportSegmentHeights = false; */ static void PaintTileElementBase(paint_session& session, const CoordsXY& origCoords) { + PROFILED_FUNCTION(); + CoordsXY coords = origCoords; rct_drawpixelinfo* dpi = &session.DPI; diff --git a/src/openrct2/paint/tile_element/Paint.Wall.cpp b/src/openrct2/paint/tile_element/Paint.Wall.cpp index 740abd1374..a67c5cc341 100644 --- a/src/openrct2/paint/tile_element/Paint.Wall.cpp +++ b/src/openrct2/paint/tile_element/Paint.Wall.cpp @@ -16,6 +16,7 @@ #include "../../interface/Colour.h" #include "../../interface/Viewport.h" #include "../../localisation/Localisation.h" +#include "../../profiling/Profiling.h" #include "../../ride/Track.h" #include "../../ride/TrackDesign.h" #include "../../world/Banner.h" @@ -48,6 +49,8 @@ static void PaintWallDoor( paint_session& session, const WallSceneryEntry& wallEntry, ImageId imageId, CoordsXYZ offset, CoordsXYZ bbLengthR1, CoordsXYZ bbOffsetR1, CoordsXYZ bbLengthR2, CoordsXYZ bbOffsetR2, CoordsXYZ bbLengthL, CoordsXYZ bbOffsetL) { + PROFILED_FUNCTION(); + auto newImageId0 = imageId; auto newImageId1 = imageId.WithIndexOffset(1); if (wallEntry.flags & WALL_SCENERY_IS_DOUBLE_SIDED) @@ -66,6 +69,8 @@ static void PaintWallDoor( paint_session& session, const WallSceneryEntry& wallEntry, const WallElement& wallElement, ImageId imageTemplate, Direction direction, int32_t height) { + PROFILED_FUNCTION(); + auto bbHeight = wallEntry.height * 8 - 2; auto animationFrame = wallElement.GetAnimationFrame(); @@ -151,6 +156,8 @@ static void PaintWallWall( paint_session& session, const WallSceneryEntry& wallEntry, ImageId imageTemplate, uint32_t imageOffset, CoordsXYZ offset, CoordsXYZ bounds, CoordsXYZ boundsOffset, bool isGhost) { + PROFILED_FUNCTION(); + auto frameNum = (wallEntry.flags2 & WALL_SCENERY_2_ANIMATED) ? (gCurrentTicks & 7) * 2 : 0; auto imageIndex = wallEntry.image + imageOffset + frameNum; PaintAddImageAsParent(session, imageTemplate.WithIndex(imageIndex), offset, bounds, boundsOffset); @@ -165,6 +172,8 @@ static void PaintWallScrollingText( paint_session& session, const WallSceneryEntry& wallEntry, const WallElement& wallElement, Direction direction, int32_t height, const CoordsXYZ& boundsOffset, bool isGhost) { + PROFILED_FUNCTION(); + if (direction != 0 && direction != 3) return; @@ -205,6 +214,8 @@ static void PaintWallWall( paint_session& session, const WallSceneryEntry& wallEntry, const WallElement& wallElement, ImageId imageTemplate, Direction direction, int32_t height, bool isGhost) { + PROFILED_FUNCTION(); + uint8_t bbHeight = wallEntry.height * 8 - 2; ImageIndex imageOffset = 0; CoordsXYZ offset, bounds, boundsOffset; @@ -313,6 +324,8 @@ static void PaintWallWall( void PaintWall(paint_session& session, uint8_t direction, int32_t height, const WallElement& wallElement) { + PROFILED_FUNCTION(); + auto* wallEntry = wallElement.GetEntry(); if (wallEntry == nullptr) { diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index b1e61e23ce..97b59a1d4c 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -12,6 +12,7 @@ #include "../core/Guard.hpp" #include "../entity/Guest.h" #include "../entity/Staff.h" +#include "../profiling/Profiling.h" #include "../ride/RideData.h" #include "../ride/Station.h" #include "../ride/Track.h" @@ -528,6 +529,8 @@ static uint8_t peep_pathfind_get_max_number_junctions(Peep* peep) */ static bool path_is_thin_junction(PathElement* path, const TileCoordsXYZ& loc) { + PROFILED_FUNCTION(); + uint8_t edges = path->GetEdges(); int32_t test_edge = bitscanforward(edges); @@ -1261,6 +1264,8 @@ static void peep_pathfind_heuristic_search( */ Direction peep_pathfind_choose_direction(const TileCoordsXYZ& loc, Peep* peep) { + PROFILED_FUNCTION(); + // The max number of thin junctions searched - a per-search-path limit. _peepPathFindMaxJunctions = peep_pathfind_get_max_number_junctions(peep); diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h index b64cb6f84a..c37d2c9db7 100644 --- a/src/openrct2/scripting/ScriptEngine.h +++ b/src/openrct2/scripting/ScriptEngine.h @@ -46,7 +46,7 @@ namespace OpenRCT2 namespace OpenRCT2::Scripting { - static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 42; + static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 43; // Versions marking breaking changes. static constexpr int32_t API_VERSION_33_PEEP_DEPRECATION = 33; diff --git a/src/openrct2/scripting/bindings/game/ScProfiler.hpp b/src/openrct2/scripting/bindings/game/ScProfiler.hpp index 1f176d8a86..ae97634251 100644 --- a/src/openrct2/scripting/bindings/game/ScProfiler.hpp +++ b/src/openrct2/scripting/bindings/game/ScProfiler.hpp @@ -84,6 +84,11 @@ namespace OpenRCT2::Scripting OpenRCT2::Profiling::ResetData(); } + bool enabled_get() const + { + return OpenRCT2::Profiling::IsEnabled(); + } + public: static void Register(duk_context* ctx) { @@ -91,6 +96,7 @@ namespace OpenRCT2::Scripting dukglue_register_method(ctx, &ScProfiler::start, "start"); dukglue_register_method(ctx, &ScProfiler::stop, "stop"); dukglue_register_method(ctx, &ScProfiler::reset, "reset"); + dukglue_register_property(ctx, &ScProfiler::enabled_get, nullptr, "enabled"); } }; } // namespace OpenRCT2::Scripting