forked from rosebudai/OpenRCT2-Web
Implement partial multicore rendering
This commit is contained in:
1 parent
521b78390f
commit
37c3809744
40 files changed
+196
-123
No files matched your search
@@ -3751,6 +3751,8 @@ STR_6301 :{SMALLFONT}{BLACK}Copy the selected object name to the clipboard.
|
||||
STR_6302 :{SMALLFONT}{BLACK}Copy the entire list of missing objects to the clipboard.
|
||||
STR_6303 :Downloading object ({COMMA16} / {COMMA16}): [{STRING}]
|
||||
STR_6304 :Open scenery picker
|
||||
STR_6305 :Multithreading
|
||||
STR_6306 :{SMALLFONT}{BLACK}Use multiple threads to render
|
||||
|
||||
#############
|
||||
# Scenarios #
|
||||
|
||||
@@ -30,6 +30,8 @@ TextureCache::~TextureCache()
|
||||
|
||||
void TextureCache::InvalidateImage(uint32_t image)
|
||||
{
|
||||
std::unique_lock lock(_mutex);
|
||||
|
||||
uint32_t index = _indexMap[image];
|
||||
if (index == UNUSED_INDEX)
|
||||
return;
|
||||
@@ -61,18 +63,28 @@ void TextureCache::InvalidateImage(uint32_t image)
|
||||
|
||||
BasicTextureInfo TextureCache::GetOrLoadImageTexture(uint32_t image)
|
||||
{
|
||||
uint32_t index;
|
||||
|
||||
image &= 0x7FFFF;
|
||||
|
||||
uint32_t index = _indexMap[image];
|
||||
if (index != UNUSED_INDEX)
|
||||
// Try to read cached texture first.
|
||||
{
|
||||
const auto& info = _textureCache[index];
|
||||
return {
|
||||
info.index,
|
||||
info.normalizedBounds,
|
||||
};
|
||||
std::shared_lock lock(_mutex);
|
||||
|
||||
index = _indexMap[image];
|
||||
if (index != UNUSED_INDEX)
|
||||
{
|
||||
const auto& info = _textureCache[index];
|
||||
return {
|
||||
info.index,
|
||||
info.normalizedBounds,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Load new texture.
|
||||
std::unique_lock lock(_mutex);
|
||||
|
||||
index = (uint32_t)_textureCache.size();
|
||||
|
||||
AtlasTextureInfo info = LoadImageTexture(image);
|
||||
@@ -87,18 +99,27 @@ BasicTextureInfo TextureCache::GetOrLoadGlyphTexture(uint32_t image, uint8_t* pa
|
||||
{
|
||||
GlyphId glyphId;
|
||||
glyphId.Image = image;
|
||||
std::copy_n(palette, sizeof(glyphId.Palette), (uint8_t*)&glyphId.Palette);
|
||||
|
||||
auto kvp = _glyphTextureMap.find(glyphId);
|
||||
if (kvp != _glyphTextureMap.end())
|
||||
// Try to read cached texture first.
|
||||
{
|
||||
const auto& info = kvp->second;
|
||||
return {
|
||||
info.index,
|
||||
info.normalizedBounds,
|
||||
};
|
||||
std::shared_lock lock(_mutex);
|
||||
|
||||
std::copy_n(palette, sizeof(glyphId.Palette), (uint8_t*)&glyphId.Palette);
|
||||
|
||||
auto kvp = _glyphTextureMap.find(glyphId);
|
||||
if (kvp != _glyphTextureMap.end())
|
||||
{
|
||||
const auto& info = kvp->second;
|
||||
return {
|
||||
info.index,
|
||||
info.normalizedBounds,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Load new texture.
|
||||
std::unique_lock lock(_mutex);
|
||||
|
||||
auto cacheInfo = LoadGlyphTexture(image, palette);
|
||||
auto it = _glyphTextureMap.insert(std::make_pair(glyphId, cacheInfo));
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <openrct2/common.h>
|
||||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
@@ -198,6 +199,7 @@ private:
|
||||
std::array<uint32_t, 0x7FFFF> _indexMap;
|
||||
|
||||
GLuint _paletteTexture = 0;
|
||||
std::shared_mutex _mutex;
|
||||
|
||||
public:
|
||||
TextureCache();
|
||||
|
||||
@@ -87,6 +87,7 @@ enum WINDOW_OPTIONS_WIDGET_IDX {
|
||||
WIDX_STEAM_OVERLAY_PAUSE,
|
||||
WIDX_UNCAP_FPS_CHECKBOX,
|
||||
WIDX_SHOW_FPS_CHECKBOX,
|
||||
WIDX_MULTITHREADING_CHECKBOX,
|
||||
WIDX_USE_VSYNC_CHECKBOX,
|
||||
WIDX_MINIMIZE_FOCUS_LOSS,
|
||||
|
||||
@@ -236,7 +237,8 @@ static rct_widget window_options_display_widgets[] = {
|
||||
{ WWT_CHECKBOX, 1, 25, 290, 144, 155, STR_STEAM_OVERLAY_PAUSE, STR_STEAM_OVERLAY_PAUSE_TIP }, // Pause on steam overlay
|
||||
{ WWT_CHECKBOX, 1, 11, 153, 161, 172, STR_UNCAP_FPS, STR_UNCAP_FPS_TIP }, // Uncap fps
|
||||
{ WWT_CHECKBOX, 1, 155, 290, 161, 172, STR_SHOW_FPS, STR_SHOW_FPS_TIP }, // Show fps
|
||||
{ WWT_CHECKBOX, 1, 11, 290, 176, 187, STR_USE_VSYNC, STR_USE_VSYNC_TIP }, // Use vsync
|
||||
{ WWT_CHECKBOX, 1, 155, 290, 176, 187, STR_MULTITHREADING, STR_MULTITHREADING_TIP }, // Multithreading
|
||||
{ WWT_CHECKBOX, 1, 11, 153, 176, 187, STR_USE_VSYNC, STR_USE_VSYNC_TIP }, // Use vsync
|
||||
{ WWT_CHECKBOX, 1, 11, 290, 191, 202, STR_MINIMISE_FULLSCREEN_ON_FOCUS_LOSS, STR_MINIMISE_FULLSCREEN_ON_FOCUS_LOSS_TIP }, // Minimise fullscreen focus loss
|
||||
{ WIDGETS_END },
|
||||
};
|
||||
@@ -522,6 +524,7 @@ static uint64_t window_options_page_enabled_widgets[] = {
|
||||
(1 << WIDX_UNCAP_FPS_CHECKBOX) |
|
||||
(1 << WIDX_USE_VSYNC_CHECKBOX) |
|
||||
(1 << WIDX_SHOW_FPS_CHECKBOX) |
|
||||
(1 << WIDX_MULTITHREADING_CHECKBOX) |
|
||||
(1 << WIDX_MINIMIZE_FOCUS_LOSS) |
|
||||
(1 << WIDX_STEAM_OVERLAY_PAUSE) |
|
||||
(1 << WIDX_SCALE) |
|
||||
@@ -693,6 +696,11 @@ static void window_options_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
||||
config_save_default();
|
||||
window_invalidate(w);
|
||||
break;
|
||||
case WIDX_MULTITHREADING_CHECKBOX:
|
||||
gConfigGeneral.multithreading ^= 1;
|
||||
config_save_default();
|
||||
window_invalidate(w);
|
||||
break;
|
||||
case WIDX_MINIMIZE_FOCUS_LOSS:
|
||||
gConfigGeneral.minimize_fullscreen_focus_loss ^= 1;
|
||||
platform_refresh_video(false);
|
||||
@@ -1711,6 +1719,7 @@ static void window_options_invalidate(rct_window* w)
|
||||
widget_set_checkbox_value(w, WIDX_UNCAP_FPS_CHECKBOX, gConfigGeneral.uncap_fps);
|
||||
widget_set_checkbox_value(w, WIDX_USE_VSYNC_CHECKBOX, gConfigGeneral.use_vsync);
|
||||
widget_set_checkbox_value(w, WIDX_SHOW_FPS_CHECKBOX, gConfigGeneral.show_fps);
|
||||
widget_set_checkbox_value(w, WIDX_MULTITHREADING_CHECKBOX, gConfigGeneral.multithreading);
|
||||
widget_set_checkbox_value(w, WIDX_MINIMIZE_FOCUS_LOSS, gConfigGeneral.minimize_fullscreen_focus_loss);
|
||||
widget_set_checkbox_value(w, WIDX_STEAM_OVERLAY_PAUSE, gConfigGeneral.steam_overlay_pause);
|
||||
|
||||
|
||||
@@ -195,6 +195,7 @@ namespace Config
|
||||
model->window_scale = reader->GetFloat("window_scale", platform_get_default_scale());
|
||||
model->scale_quality = reader->GetEnum<int32_t>("scale_quality", SCALE_QUALITY_SMOOTH_NN, Enum_ScaleQuality);
|
||||
model->show_fps = reader->GetBoolean("show_fps", false);
|
||||
model->multithreading = reader->GetBoolean("multithreading", true);
|
||||
model->trap_cursor = reader->GetBoolean("trap_cursor", false);
|
||||
model->auto_open_shops = reader->GetBoolean("auto_open_shops", false);
|
||||
model->scenario_select_mode = reader->GetInt32("scenario_select_mode", SCENARIO_SELECT_MODE_ORIGIN);
|
||||
@@ -268,6 +269,7 @@ namespace Config
|
||||
writer->WriteFloat("window_scale", model->window_scale);
|
||||
writer->WriteEnum<int32_t>("scale_quality", model->scale_quality, Enum_ScaleQuality);
|
||||
writer->WriteBoolean("show_fps", model->show_fps);
|
||||
writer->WriteBoolean("multithreading", model->multithreading);
|
||||
writer->WriteBoolean("trap_cursor", model->trap_cursor);
|
||||
writer->WriteBoolean("auto_open_shops", model->auto_open_shops);
|
||||
writer->WriteInt32("scenario_select_mode", model->scenario_select_mode);
|
||||
|
||||
@@ -32,6 +32,7 @@ struct GeneralConfiguration
|
||||
bool uncap_fps;
|
||||
bool use_vsync;
|
||||
bool show_fps;
|
||||
bool multithreading;
|
||||
bool minimize_fullscreen_focus_loss;
|
||||
|
||||
// Map rendering
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cassert>
|
||||
#include <condition_variable>
|
||||
@@ -45,9 +46,10 @@ private:
|
||||
typedef std::unique_lock<std::mutex> unique_lock;
|
||||
|
||||
public:
|
||||
JobPool()
|
||||
JobPool(size_t maxThreads = 255)
|
||||
{
|
||||
for (size_t n = 0; n < std::thread::hardware_concurrency(); n++)
|
||||
maxThreads = std::min<size_t>(maxThreads, std::thread::hardware_concurrency());
|
||||
for (size_t n = 0; n < maxThreads; n++)
|
||||
{
|
||||
_threads.emplace_back(&JobPool::ProcessQueue, this);
|
||||
}
|
||||
|
||||
@@ -1474,7 +1474,7 @@ int32_t scrolling_text_setup(paint_session* session, rct_string_id stringId, uin
|
||||
{
|
||||
assert(scrollingMode < MAX_SCROLLING_TEXT_MODES);
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
if (dpi->zoom_level != 0)
|
||||
return SPR_SCROLLING_TEXT_DEFAULT;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "../Input.h"
|
||||
#include "../OpenRCT2.h"
|
||||
#include "../config/Config.h"
|
||||
#include "../core/JobPool.hpp"
|
||||
#include "../drawing/Drawing.h"
|
||||
#include "../paint/Paint.h"
|
||||
#include "../peep/Staff.h"
|
||||
@@ -42,6 +43,7 @@ rct_viewport g_viewport_list[MAX_VIEWPORT_COUNT];
|
||||
rct_viewport* g_music_tracking_viewport;
|
||||
|
||||
static TileElement* _interaction_element = nullptr;
|
||||
static std::unique_ptr<JobPool> _paintJobs;
|
||||
|
||||
int16_t gSavedViewX;
|
||||
int16_t gSavedViewY;
|
||||
@@ -60,7 +62,6 @@ static int16_t _interactionMapX;
|
||||
static int16_t _interactionMapY;
|
||||
static uint16_t _unk9AC154;
|
||||
|
||||
static void viewport_paint_column(rct_drawpixelinfo* dpi, uint32_t viewFlags, std::vector<paint_session>* sessions);
|
||||
static void viewport_paint_weather_gloom(rct_drawpixelinfo* dpi);
|
||||
|
||||
/**
|
||||
@@ -833,6 +834,41 @@ void viewport_render(
|
||||
#endif
|
||||
}
|
||||
|
||||
static void viewport_fill_column(paint_session* session)
|
||||
{
|
||||
paint_session_generate(session);
|
||||
paint_session_arrange(session);
|
||||
}
|
||||
|
||||
static void viewport_paint_column(paint_session* session)
|
||||
{
|
||||
if (session->ViewFlags
|
||||
& (VIEWPORT_FLAG_HIDE_VERTICAL | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_CLIP_VIEW))
|
||||
{
|
||||
uint8_t colour = 10;
|
||||
if (session->ViewFlags & VIEWPORT_FLAG_INVISIBLE_SPRITES)
|
||||
{
|
||||
colour = 0;
|
||||
}
|
||||
gfx_clear(&session->DPI, colour);
|
||||
}
|
||||
|
||||
paint_draw_structs(session);
|
||||
|
||||
if (gConfigGeneral.render_weather_gloom && !gTrackDesignSaveMode && !(session->ViewFlags & VIEWPORT_FLAG_INVISIBLE_SPRITES)
|
||||
&& !(session->ViewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES))
|
||||
{
|
||||
viewport_paint_weather_gloom(&session->DPI);
|
||||
}
|
||||
|
||||
if (session->PSStringHead != nullptr)
|
||||
{
|
||||
paint_draw_money_structs(&session->DPI, session->PSStringHead);
|
||||
}
|
||||
|
||||
paint_session_free(session);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x00685CBF
|
||||
@@ -880,82 +916,65 @@ void viewport_paint(
|
||||
// this as well as the [x += 32] in the loop causes signed integer overflow -> undefined behaviour.
|
||||
int16_t rightBorder = dpi1.x + dpi1.width;
|
||||
|
||||
// Splits the area into 32 pixel columns and renders them
|
||||
int16_t start_x = floor2(dpi1.x, 32);
|
||||
if (sessions != nullptr)
|
||||
std::vector<paint_session*> columns;
|
||||
|
||||
bool useMultithreading = gConfigGeneral.multithreading;
|
||||
if (window_get_main() != nullptr && viewport != window_get_main()->viewport)
|
||||
useMultithreading = false;
|
||||
|
||||
if (useMultithreading == true && _paintJobs == nullptr)
|
||||
{
|
||||
sessions->reserve((rightBorder - start_x) / 32);
|
||||
_paintJobs = std::make_unique<JobPool>();
|
||||
}
|
||||
for (int16_t columnx = start_x; columnx < rightBorder; columnx += 32)
|
||||
else if (useMultithreading == false && _paintJobs != nullptr)
|
||||
{
|
||||
rct_drawpixelinfo dpi2 = dpi1;
|
||||
if (columnx >= dpi2.x)
|
||||
_paintJobs.reset();
|
||||
}
|
||||
|
||||
// Splits the area into 32 pixel columns and renders them
|
||||
size_t index = 0;
|
||||
for (x = floor2(dpi1.x, 32); x < rightBorder; x += 32, index++)
|
||||
{
|
||||
paint_session* session = paint_session_alloc(&dpi1, viewFlags);
|
||||
columns.push_back(session);
|
||||
|
||||
rct_drawpixelinfo& dpi2 = session->DPI;
|
||||
if (x >= dpi2.x)
|
||||
{
|
||||
int16_t leftPitch = columnx - dpi2.x;
|
||||
int16_t leftPitch = x - dpi2.x;
|
||||
dpi2.width -= leftPitch;
|
||||
dpi2.bits += leftPitch >> dpi2.zoom_level;
|
||||
dpi2.pitch += leftPitch >> dpi2.zoom_level;
|
||||
dpi2.x = columnx;
|
||||
dpi2.x = x;
|
||||
}
|
||||
|
||||
int16_t paintRight = dpi2.x + dpi2.width;
|
||||
if (paintRight >= columnx + 32)
|
||||
if (paintRight >= x + 32)
|
||||
{
|
||||
int16_t rightPitch = paintRight - columnx - 32;
|
||||
int16_t rightPitch = paintRight - x - 32;
|
||||
paintRight -= rightPitch;
|
||||
dpi2.pitch += rightPitch >> dpi2.zoom_level;
|
||||
}
|
||||
dpi2.width = paintRight - dpi2.x;
|
||||
|
||||
viewport_paint_column(&dpi2, viewFlags, sessions);
|
||||
}
|
||||
}
|
||||
|
||||
static void viewport_paint_column(rct_drawpixelinfo* dpi, uint32_t viewFlags, std::vector<paint_session>* sessions)
|
||||
{
|
||||
if (viewFlags
|
||||
& (VIEWPORT_FLAG_HIDE_VERTICAL | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_CLIP_VIEW))
|
||||
{
|
||||
uint8_t colour = 10;
|
||||
if (viewFlags & VIEWPORT_FLAG_INVISIBLE_SPRITES)
|
||||
if (useMultithreading)
|
||||
{
|
||||
colour = 0;
|
||||
_paintJobs->AddTask([session]() -> void { viewport_fill_column(session); });
|
||||
}
|
||||
gfx_clear(dpi, colour);
|
||||
}
|
||||
|
||||
paint_session* session = paint_session_alloc(dpi, viewFlags);
|
||||
paint_session_generate(session);
|
||||
// Perform a deep copy of the paint session, use relative offsets.
|
||||
// This is done to extract the session for benchmark.
|
||||
if (sessions != nullptr)
|
||||
{
|
||||
sessions->push_back(*session);
|
||||
paint_session* session_copy = &sessions->at(sessions->size() - 1);
|
||||
|
||||
// Mind the offset needs to be calculated against the original `session`, not `session_copy`
|
||||
for (auto& ps : session_copy->PaintStructs)
|
||||
else
|
||||
{
|
||||
ps.basic.next_quadrant_ps = (paint_struct*)(ps.basic.next_quadrant_ps ? int(ps.basic.next_quadrant_ps - &session->PaintStructs[0].basic) : std::size(session->PaintStructs));
|
||||
}
|
||||
for (auto& quad : session_copy->Quadrants)
|
||||
{
|
||||
quad = (paint_struct*)(quad ? int(quad - &session->PaintStructs[0].basic) : std::size(session->Quadrants));
|
||||
viewport_fill_column(session);
|
||||
}
|
||||
}
|
||||
paint_session_arrange(session);
|
||||
paint_draw_structs(session);
|
||||
paint_session_free(session);
|
||||
|
||||
if (gConfigGeneral.render_weather_gloom && !gTrackDesignSaveMode && !(viewFlags & VIEWPORT_FLAG_INVISIBLE_SPRITES)
|
||||
&& !(viewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES))
|
||||
if (useMultithreading)
|
||||
{
|
||||
viewport_paint_weather_gloom(dpi);
|
||||
_paintJobs->Join();
|
||||
}
|
||||
|
||||
if (session->PSStringHead != nullptr)
|
||||
for (auto&& column : columns)
|
||||
{
|
||||
paint_draw_money_structs(dpi, session->PSStringHead);
|
||||
viewport_paint_column(column);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1590,7 +1609,7 @@ static bool sub_679023(rct_drawpixelinfo* dpi, int32_t imageId, int32_t x, int32
|
||||
static void sub_68862C(paint_session* session)
|
||||
{
|
||||
paint_struct* ps = &session->PaintHead;
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
while ((ps = ps->next_quadrant_ps) != nullptr)
|
||||
{
|
||||
|
||||
@@ -35,9 +35,9 @@
|
||||
#include <iterator>
|
||||
#include <limits.h>
|
||||
|
||||
char gCommonStringFormatBuffer[512];
|
||||
uint8_t gCommonFormatArgs[80];
|
||||
uint8_t gMapTooltipFormatArgs[40];
|
||||
thread_local char gCommonStringFormatBuffer[512];
|
||||
thread_local uint8_t gCommonFormatArgs[80];
|
||||
thread_local uint8_t gMapTooltipFormatArgs[40];
|
||||
|
||||
#ifdef DEBUG
|
||||
// Set to true before a string format call to see details of the formatting.
|
||||
|
||||
@@ -74,9 +74,9 @@ extern const char real_name_initials[16];
|
||||
extern const char* real_names[1024];
|
||||
|
||||
extern utf8 gUserStrings[MAX_USER_STRINGS][USER_STRING_MAX_LENGTH];
|
||||
extern char gCommonStringFormatBuffer[512];
|
||||
extern uint8_t gCommonFormatArgs[80];
|
||||
extern uint8_t gMapTooltipFormatArgs[40];
|
||||
extern thread_local char gCommonStringFormatBuffer[512];
|
||||
extern thread_local uint8_t gCommonFormatArgs[80];
|
||||
extern thread_local uint8_t gMapTooltipFormatArgs[40];
|
||||
extern bool gDebugStringFormatting;
|
||||
|
||||
extern const rct_string_id SpeedNames[5];
|
||||
|
||||
@@ -3934,6 +3934,8 @@ enum
|
||||
STR_DOWNLOADING_OBJECTS = 6303,
|
||||
|
||||
STR_SHORTCUT_OPEN_SCENERY_PICKER = 6304,
|
||||
STR_MULTITHREADING = 6305,
|
||||
STR_MULTITHREADING_TIP = 6306,
|
||||
|
||||
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
|
||||
STR_COUNT = 32768
|
||||
|
||||
@@ -18,14 +18,15 @@
|
||||
#include "tile_element/Paint.TileElement.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
|
||||
// Globals for paint clipping
|
||||
uint8_t gClipHeight = 128; // Default to middle value
|
||||
LocationXY8 gClipSelectionA = { 0, 0 };
|
||||
LocationXY8 gClipSelectionB = { MAXIMUM_MAP_SIZE_TECHNICAL - 1, MAXIMUM_MAP_SIZE_TECHNICAL - 1 };
|
||||
|
||||
paint_session gPaintSession;
|
||||
static bool _paintSessionInUse;
|
||||
static std::vector<paint_session*> _freePaintSessions;
|
||||
|
||||
static constexpr const uint8_t BoundBoxDebugColours[] = {
|
||||
0, // NONE
|
||||
@@ -56,7 +57,7 @@ static uint32_t paint_ps_colourify_image(uint32_t imageId, uint8_t spriteType, u
|
||||
|
||||
static void paint_session_init(paint_session* session, rct_drawpixelinfo* dpi, uint32_t viewFlags)
|
||||
{
|
||||
session->DPI = dpi;
|
||||
session->DPI = *dpi;
|
||||
session->EndOfPaintStructArray = &session->PaintStructs[4000 - 1];
|
||||
session->NextFreePaintStruct = session->PaintStructs;
|
||||
session->LastRootPS = nullptr;
|
||||
@@ -132,7 +133,7 @@ static paint_struct* sub_9819_c(
|
||||
int32_t right = left + g1->width;
|
||||
int32_t top = bottom + g1->height;
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
if (right <= dpi->x)
|
||||
return nullptr;
|
||||
@@ -192,7 +193,7 @@ static paint_struct* sub_9819_c(
|
||||
*/
|
||||
void paint_session_generate(paint_session* session)
|
||||
{
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
LocationXY16 mapTile = { (int16_t)(dpi->x & 0xFFE0), (int16_t)((dpi->y - 16) & 0xFFE0) };
|
||||
|
||||
int16_t half_x = mapTile.x >> 1;
|
||||
@@ -458,7 +459,6 @@ void paint_session_arrange(paint_session* session)
|
||||
ps->next_quadrant_ps = nullptr;
|
||||
|
||||
uint32_t quadrantIndex = session->QuadrantBackIndex;
|
||||
const uint8_t rotation = get_current_rotation();
|
||||
if (quadrantIndex != UINT32_MAX)
|
||||
{
|
||||
do
|
||||
@@ -477,19 +477,19 @@ void paint_session_arrange(paint_session* session)
|
||||
} while (++quadrantIndex <= session->QuadrantFrontIndex);
|
||||
|
||||
paint_struct* ps_cache = paint_arrange_structs_helper(
|
||||
psHead, session->QuadrantBackIndex & 0xFFFF, PAINT_QUADRANT_FLAG_NEXT, rotation);
|
||||
psHead, session->QuadrantBackIndex & 0xFFFF, PAINT_QUADRANT_FLAG_NEXT, session->CurrentRotation);
|
||||
|
||||
quadrantIndex = session->QuadrantBackIndex;
|
||||
while (++quadrantIndex < session->QuadrantFrontIndex)
|
||||
{
|
||||
ps_cache = paint_arrange_structs_helper(ps_cache, quadrantIndex & 0xFFFF, 0, rotation);
|
||||
ps_cache = paint_arrange_structs_helper(ps_cache, quadrantIndex & 0xFFFF, 0, session->CurrentRotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void paint_draw_struct(paint_session* session, paint_struct* ps)
|
||||
{
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
int16_t x = ps->x;
|
||||
int16_t y = ps->y;
|
||||
@@ -732,10 +732,17 @@ static void draw_pixel_info_crop_by_zoom(rct_drawpixelinfo* dpi)
|
||||
|
||||
paint_session* paint_session_alloc(rct_drawpixelinfo* dpi, uint32_t viewFlags)
|
||||
{
|
||||
// Currently limited to just one session at a time
|
||||
assert(!_paintSessionInUse);
|
||||
_paintSessionInUse = true;
|
||||
paint_session* session = &gPaintSession;
|
||||
paint_session* session = nullptr;
|
||||
|
||||
if (_freePaintSessions.empty())
|
||||
{
|
||||
session = new paint_session();
|
||||
}
|
||||
else
|
||||
{
|
||||
session = _freePaintSessions[_freePaintSessions.size() - 1];
|
||||
_freePaintSessions.resize(_freePaintSessions.size() - 1);
|
||||
}
|
||||
|
||||
paint_session_init(session, dpi, viewFlags);
|
||||
return session;
|
||||
@@ -743,7 +750,7 @@ paint_session* paint_session_alloc(rct_drawpixelinfo* dpi, uint32_t viewFlags)
|
||||
|
||||
void paint_session_free([[maybe_unused]] paint_session* session)
|
||||
{
|
||||
_paintSessionInUse = false;
|
||||
_freePaintSessions.push_back(session);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -845,7 +852,7 @@ paint_struct* sub_98196C(
|
||||
int16_t right = left + g1Element->width;
|
||||
int16_t top = bottom + g1Element->height;
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
if (right <= dpi->x)
|
||||
return nullptr;
|
||||
|
||||
@@ -137,9 +137,15 @@ struct tunnel_entry
|
||||
#define MAX_PAINT_QUADRANTS 512
|
||||
#define TUNNEL_MAX_COUNT 65
|
||||
|
||||
struct paint_pending
|
||||
{
|
||||
rct_drawpixelinfo dpi;
|
||||
uint32_t viewFlags;
|
||||
};
|
||||
|
||||
struct paint_session
|
||||
{
|
||||
rct_drawpixelinfo* DPI;
|
||||
rct_drawpixelinfo DPI;
|
||||
paint_entry PaintStructs[4000];
|
||||
paint_struct* Quadrants[MAX_PAINT_QUADRANTS];
|
||||
paint_struct PaintHead;
|
||||
|
||||
@@ -69,7 +69,7 @@ void litter_paint(paint_session* session, const rct_litter* litter, int32_t imag
|
||||
{
|
||||
rct_drawpixelinfo* dpi;
|
||||
|
||||
dpi = session->DPI;
|
||||
dpi = &session->DPI;
|
||||
if (dpi->zoom_level != 0)
|
||||
return; // If zoomed at all no litter drawn
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ const uint32_t vehicle_particle_base_sprites[] = {
|
||||
*/
|
||||
void misc_paint(paint_session* session, const rct_sprite* misc, int32_t imageDirection)
|
||||
{
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
switch (misc->steam_particle.type)
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ void peep_paint(paint_session* session, const Peep* peep, int32_t imageDirection
|
||||
}
|
||||
#endif
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
if (dpi->zoom_level > 2)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -40,7 +40,7 @@ void sprite_paint_setup(paint_session* session, const uint16_t x, const uint16_t
|
||||
return;
|
||||
}
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
if (dpi->zoom_level > 2)
|
||||
{
|
||||
return;
|
||||
@@ -89,7 +89,7 @@ void sprite_paint_setup(paint_session* session, const uint16_t x, const uint16_t
|
||||
}
|
||||
}
|
||||
|
||||
dpi = session->DPI;
|
||||
dpi = &session->DPI;
|
||||
|
||||
if (dpi->y + dpi->height <= spr->generic.sprite_top || spr->generic.sprite_bottom <= dpi->y
|
||||
|| dpi->x + dpi->width <= spr->generic.sprite_left || spr->generic.sprite_right <= dpi->x)
|
||||
|
||||
@@ -34,7 +34,7 @@ const LocationXY16 BannerBoundBoxes[][2] = {
|
||||
void banner_paint(paint_session* session, uint8_t direction, int32_t height, const TileElement* tile_element)
|
||||
{
|
||||
uint16_t boundBoxOffsetX, boundBoxOffsetY, boundBoxOffsetZ;
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
session->InteractionType = VIEWPORT_INTERACTION_ITEM_BANNER;
|
||||
|
||||
|
||||
@@ -334,7 +334,7 @@ void entrance_paint(paint_session* session, uint8_t direction, int32_t height, c
|
||||
{
|
||||
session->InteractionType = VIEWPORT_INTERACTION_ITEM_LABEL;
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
if (session->ViewFlags & VIEWPORT_FLAG_PATH_HEIGHTS && dpi->zoom_level == 0)
|
||||
{
|
||||
|
||||
@@ -293,7 +293,7 @@ void large_scenery_paint(paint_session* session, uint8_t direction, uint16_t hei
|
||||
return;
|
||||
}
|
||||
}
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
if (dpi->zoom_level > 1)
|
||||
{
|
||||
large_scenery_paint_supports(session, direction, height, tileElement, dword_F4387C, tile);
|
||||
@@ -400,7 +400,7 @@ void large_scenery_paint(paint_session* session, uint8_t direction, uint16_t hei
|
||||
}
|
||||
return;
|
||||
}
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
if (dpi->zoom_level > 0)
|
||||
{
|
||||
large_scenery_paint_supports(session, direction, height, tileElement, dword_F4387C, tile);
|
||||
|
||||
@@ -682,7 +682,7 @@ static void sub_6A3F61(
|
||||
|
||||
// Probably drawing benches etc.
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
if (dpi->zoom_level <= 1)
|
||||
{
|
||||
|
||||
@@ -176,7 +176,7 @@ void scenery_paint(paint_session* session, uint8_t direction, int32_t height, co
|
||||
|
||||
if (scenery_small_entry_has_flag(entry, SMALL_SCENERY_FLAG_ANIMATED))
|
||||
{
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
if ((scenery_small_entry_has_flag(entry, SMALL_SCENERY_FLAG_VISIBLE_WHEN_ZOOMED)) || (dpi->zoom_level <= 1))
|
||||
{
|
||||
// 6E01A9:
|
||||
|
||||
@@ -907,7 +907,7 @@ static void viewport_surface_draw_water_side_top(
|
||||
*/
|
||||
void surface_paint(paint_session* session, uint8_t direction, uint16_t height, const TileElement* tileElement)
|
||||
{
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
session->InteractionType = VIEWPORT_INTERACTION_ITEM_TERRAIN;
|
||||
session->DidPassSurface = true;
|
||||
session->SurfaceElement = tileElement;
|
||||
|
||||
@@ -114,7 +114,7 @@ static void blank_tiles_paint(paint_session* session, int32_t x, int32_t y)
|
||||
dx -= 16;
|
||||
int32_t bx = dx + 32;
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
if (bx <= dpi->y)
|
||||
return;
|
||||
dx -= 20;
|
||||
@@ -136,7 +136,7 @@ bool gShowSupportSegmentHeights = false;
|
||||
*/
|
||||
static void sub_68B3FB(paint_session* session, int32_t x, int32_t y)
|
||||
{
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
if ((session->ViewFlags & VIEWPORT_FLAG_CLIP_VIEW))
|
||||
{
|
||||
|
||||
@@ -2164,7 +2164,7 @@ void track_paint(paint_session* session, uint8_t direction, int32_t height, cons
|
||||
return;
|
||||
}
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
if ((!gTrackDesignSaveMode || rideIndex == gTrackDesignSaveRideIndex)
|
||||
&& !(session->ViewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES))
|
||||
|
||||
@@ -915,7 +915,7 @@ static void vehicle_sprite_paint(
|
||||
{
|
||||
ps->tertiary_colour = vehicle->colours_extended;
|
||||
}
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
if (dpi->zoom_level < 2 && vehicle->num_peeps > 0 && vehicleEntry->no_seating_rows > 0)
|
||||
{
|
||||
baseImage_id += vehicleEntry->no_vehicle_images;
|
||||
|
||||
@@ -199,7 +199,7 @@ void vehicle_visual_virginia_reel(
|
||||
sub_98197C(
|
||||
session, image_id, 0, 0, bb->length_x, bb->length_y, bb->length_z, z, bb->offset_x, bb->offset_y, bb->offset_z + z);
|
||||
|
||||
if (session->DPI->zoom_level < 2 && vehicle->num_peeps > 0)
|
||||
if (session->DPI.zoom_level < 2 && vehicle->num_peeps > 0)
|
||||
{
|
||||
uint8_t riding_peep_sprites[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
for (int32_t i = 0; i < vehicle->num_peeps; i++)
|
||||
|
||||
@@ -62,7 +62,7 @@ static void paint_haunted_house_structure(
|
||||
session, imageId, xOffset, yOffset, boundBox.length_x, boundBox.length_y, 127, height, boundBox.offset_x,
|
||||
boundBox.offset_y, height);
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
if (dpi->zoom_level == 0 && frameNum != 0)
|
||||
{
|
||||
switch (direction)
|
||||
|
||||
@@ -71,7 +71,7 @@ static void paint_merry_go_round_structure(
|
||||
uint32_t imageId = (baseImageId + imageOffset) | imageColourFlags;
|
||||
sub_98197C(session, imageId, xOffset, yOffset, 24, 24, 48, height, xOffset + 16, yOffset + 16, height);
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
if (dpi->zoom_level == 0 && ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr)
|
||||
{
|
||||
for (int32_t peep = 0; peep <= 14; peep += 2)
|
||||
|
||||
@@ -1193,7 +1193,7 @@ void vehicle_visual_mini_golf_player(
|
||||
return;
|
||||
}
|
||||
|
||||
rct_drawpixelinfo* edi = session->DPI;
|
||||
rct_drawpixelinfo* edi = &session->DPI;
|
||||
if (edi->zoom_level >= 2)
|
||||
{
|
||||
return;
|
||||
@@ -1226,7 +1226,7 @@ void vehicle_visual_mini_golf_ball(
|
||||
return;
|
||||
}
|
||||
|
||||
rct_drawpixelinfo* edi = session->DPI;
|
||||
rct_drawpixelinfo* edi = &session->DPI;
|
||||
if (edi->zoom_level >= 1)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -121,7 +121,7 @@ static void spiral_slide_paint_tile_front(
|
||||
sub_98197C(session, image_id, 16, 16, 8, 16, 108, height, 8, 0, height + 3);
|
||||
}
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
if (dpi->zoom_level == 0 && ride->slide_in_use != 0)
|
||||
{
|
||||
uint8_t slide_progress = ride->spiral_slide_progress;
|
||||
|
||||
@@ -54,7 +54,7 @@ static void paint_enterprise_structure(
|
||||
uint32_t imageId = (baseImageId + imageOffset) | imageColourFlags;
|
||||
sub_98197C(session, imageId, xOffset, yOffset, 24, 24, 48, height, 0, 0, height);
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
if (dpi->zoom_level == 0 && imageOffset < 12 && ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr)
|
||||
{
|
||||
|
||||
@@ -47,7 +47,7 @@ void vehicle_visual_launched_freefall(
|
||||
sub_98197C(session, image_id, 0, 0, 16, 16, 41, z, -5, -5, z + 1);
|
||||
|
||||
// Draw peeps:
|
||||
if (session->DPI->zoom_level < 2)
|
||||
if (session->DPI.zoom_level < 2)
|
||||
{
|
||||
if (vehicle->num_peeps > 0)
|
||||
{
|
||||
|
||||
@@ -155,7 +155,7 @@ static void paint_magic_carpet_vehicle(
|
||||
bbOffset.x, bbOffset.y, bbOffset.z);
|
||||
|
||||
// Riders
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
if (dpi->zoom_level <= 1 && (ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK))
|
||||
{
|
||||
rct_vehicle* vehicle = get_first_vehicle(ride);
|
||||
|
||||
@@ -115,7 +115,7 @@ static void paint_pirate_ship_structure(
|
||||
session, imageId, xOffset, yOffset, bounds.length_x, bounds.length_y, 80, height, bounds.offset_x, bounds.offset_y,
|
||||
height);
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
if (dpi->zoom_level <= 1 && ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr)
|
||||
{
|
||||
|
||||
@@ -167,7 +167,7 @@ static void top_spin_paint_vehicle(
|
||||
session, image_id, (int8_t)seatCoords.x, (int8_t)seatCoords.y, lengthX, lengthY, 90, seatCoords.z, boundBoxOffsetX,
|
||||
boundBoxOffsetY, boundBoxOffsetZ);
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
if (dpi->zoom_level < 2 && vehicle != nullptr && vehicle->num_peeps != 0)
|
||||
{
|
||||
image_id = (seatImageId + (1 * 76))
|
||||
|
||||
@@ -58,7 +58,7 @@ static void paint_twist_structure(
|
||||
uint32_t imageId = (baseImageId + structureFrameNum) | imageColourFlags;
|
||||
sub_98197C(session, imageId, xOffset, yOffset, 24, 24, 48, height, xOffset + 16, yOffset + 16, height);
|
||||
|
||||
rct_drawpixelinfo* dpi = session->DPI;
|
||||
rct_drawpixelinfo* dpi = &session->DPI;
|
||||
|
||||
if (dpi->zoom_level < 1 && ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK && vehicle != nullptr)
|
||||
{
|
||||
|
||||
@@ -226,7 +226,7 @@ void vehicle_visual_river_rapids(
|
||||
sub_98197C(
|
||||
session, image_id, 0, 0, bb->length_x, bb->length_y, bb->length_z, z, bb->offset_x, bb->offset_y, bb->offset_z + z);
|
||||
|
||||
if (session->DPI->zoom_level < 2 && vehicle->num_peeps > 0)
|
||||
if (session->DPI.zoom_level < 2 && vehicle->num_peeps > 0)
|
||||
{
|
||||
// Draw peeps: (this particular vehicle doesn't sort them back to front like others so the back ones sometimes clip, but
|
||||
// that's how the original does it...)
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace TestPaint
|
||||
rct_drawpixelinfo dpi = {};
|
||||
dpi.zoom_level = 1;
|
||||
RCT2_Unk140E9A8 = &dpi;
|
||||
gPaintSession.DPI = &dpi;
|
||||
gPaintSession.DPI = dpi;
|
||||
|
||||
{
|
||||
Ride ride = {};
|
||||
|
||||
Reference in new issue
Block a user