1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Convert g_window_list to a std::vector

This commit is contained in:
Ted John
2018-06-16 02:14:59 +01:00
parent a716b4aa28
commit 0f6138f8b6
9 changed files with 472 additions and 437 deletions

View File

@@ -273,10 +273,9 @@ public:
sint32 top = dpi->y;
sint32 bottom = top + dpi->height;
rct_window * newWindow = gWindowNextSlot;
for (rct_window * w = g_window_list; w < newWindow; w++)
for (auto& w : g_window_list)
{
DrawRainWindow(rainDrawer, w, left, right, top, bottom, drawFunc);
DrawRainWindow(rainDrawer, &w, left, right, top, bottom, drawFunc);
}
}
@@ -773,11 +772,10 @@ private:
sint16 bottom,
DrawRainFunc drawFunc)
{
rct_window * newWindow = gWindowNextSlot;
rct_window * w = original_w + 1; // Start from second window
for (; ; w++)
rct_window * w{};
for (auto i = window_get_index(original_w) + 1; ; i++)
{
if (w >= newWindow)
if (i >= g_window_list.size())
{
// Loop ended, draw rain for original_w
auto vp = original_w->viewport;
@@ -797,6 +795,7 @@ private:
return;
}
w = &g_window_list[i];
if (right <= w->x || bottom <= w->y)
{
continue;

View File

@@ -505,11 +505,11 @@ public:
rct_window* GetOwner(const rct_viewport* viewport) override
{
for (auto w = g_window_list; w < gWindowNextSlot; w++)
for (auto& w : g_window_list)
{
if (w->viewport == viewport)
if (w.viewport == viewport)
{
return w;
return &w;
}
}
return nullptr;

View File

@@ -106,9 +106,9 @@ static void input_update_tooltip(rct_window * w, rct_widgetindex widgetIndex, si
*/
void game_handle_input()
{
for (rct_window * w = g_window_list; w < gWindowNextSlot; w++)
for (auto& w : g_window_list)
{
window_event_unknown_07_call(w);
window_event_unknown_07_call(&w);
}
invalidate_all_windows_after_input();
@@ -135,9 +135,9 @@ void game_handle_input()
process_mouse_tool(x, y);
}
for (rct_window * w = g_window_list; w < gWindowNextSlot; w++)
for (auto& w : g_window_list)
{
window_event_unknown_08_call(w);
window_event_unknown_08_call(&w);
}
}

View File

@@ -865,9 +865,9 @@ rct_string_id theme_desc_get_name(rct_windowclass wc)
void colour_scheme_update_all()
{
for (rct_window *w = g_window_list; w < gWindowNextSlot; w++)
for (auto& w : g_window_list)
{
colour_scheme_update(w);
colour_scheme_update(&w);
}
}

View File

@@ -26,21 +26,19 @@ using namespace OpenRCT2;
// The amount of pixels to scroll per wheel click
constexpr sint32 WINDOW_SCROLL_PIXELS = 17;
#define RCT2_NEW_WINDOW (gWindowNextSlot)
#define RCT2_LAST_WINDOW (gWindowNextSlot - 1)
static sint32 _previousAbsoluteWheel = 0;
static bool window_fits_between_others(sint32 x, sint32 y, sint32 width, sint32 height)
{
for (rct_window *w = g_window_list; w < RCT2_LAST_WINDOW; w++) {
if (w->flags & WF_STICK_TO_BACK)
for (auto& w : g_window_list)
{
if (w.flags & WF_STICK_TO_BACK)
continue;
if (x + width <= w->x) continue;
if (x >= w->x + w->width) continue;
if (y + height <= w->y) continue;
if (y >= w->y + w->height) continue;
if (x + width <= w.x) continue;
if (x >= w.x + w.width) continue;
if (y + height <= w.y) continue;
if (y >= w.y + w.height) continue;
return false;
}
@@ -76,37 +74,44 @@ rct_window *window_create(sint32 x, sint32 y, sint32 width, sint32 height, rct_w
{
// Check if there are any window slots left
// include WINDOW_LIMIT_RESERVED for items such as the main viewport and toolbars to not appear to be counted.
if (RCT2_NEW_WINDOW >= &(g_window_list[gConfigGeneral.window_limit + WINDOW_LIMIT_RESERVED])) {
rct_window *w = nullptr;
if (g_window_list.size() >= gConfigGeneral.window_limit + WINDOW_LIMIT_RESERVED)
{
// Close least recently used window
for (w = g_window_list; w < RCT2_NEW_WINDOW; w++)
if (!(w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT | WF_NO_AUTO_CLOSE)))
break;
window_close(w);
}
rct_window *w = RCT2_NEW_WINDOW;
// Flags
if (flags & WF_STICK_TO_BACK) {
for (; w >= g_window_list + 1; w--) {
if ((w - 1)->flags & WF_STICK_TO_FRONT)
continue;
if ((w - 1)->flags & WF_STICK_TO_BACK)
for (auto& w : g_window_list)
{
if (!(w.flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT | WF_NO_AUTO_CLOSE)))
{
window_close(&w);
break;
}
}
else if (!(flags & WF_STICK_TO_FRONT)) {
for (; w >= g_window_list + 1; w--) {
if (!((w - 1)->flags & WF_STICK_TO_FRONT))
}
// Find right position to insert new window
auto dstIndex = g_window_list.size();
if (flags & WF_STICK_TO_BACK)
{
for (size_t i = 0; i < g_window_list.size(); i++)
{
if (!(g_window_list[i].flags & WF_STICK_TO_BACK))
{
dstIndex = i;
}
}
}
else if (!(flags & WF_STICK_TO_FRONT))
{
for (size_t i = g_window_list.size(); i > 0; i--)
{
if (!(g_window_list[i - 1].flags & WF_STICK_TO_FRONT))
{
dstIndex = i;
break;
}
}
}
// Move w to new window slot
if (w != RCT2_NEW_WINDOW)
*RCT2_NEW_WINDOW = *w;
auto w = &(*(g_window_list.insert(g_window_list.begin() + dstIndex, rct_window{})));
// Setup window
w->classification = cls;
@@ -144,7 +149,6 @@ rct_window *window_create(sint32 x, sint32 y, sint32 width, sint32 height, rct_w
w->selected_tab = 0;
w->var_4AE = 0;
w->viewport_smart_follow_sprite = SPRITE_INDEX_NULL;
RCT2_NEW_WINDOW++;
colour_scheme_update(w);
window_invalidate(w);
@@ -194,75 +198,78 @@ rct_window *window_create_auto_pos(sint32 width, sint32 height, rct_window_event
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
// Place window next to another
for (rct_window *w = g_window_list; w < RCT2_LAST_WINDOW; w++) {
if (w->flags & WF_STICK_TO_BACK)
for (auto& w : g_window_list)
{
if (w.flags & WF_STICK_TO_BACK)
continue;
x = w->x + w->width + 2;
y = w->y;
x = w.x + w.width + 2;
y = w.y;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
x = w->x - w->width - 2;
y = w->y;
x = w.x - w.width - 2;
y = w.y;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
x = w->x;
y = w->y + w->height + 2;
x = w.x;
y = w.y + w.height + 2;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
x = w->x;
y = w->y - w->height - 2;
x = w.x;
y = w.y - w.height - 2;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
x = w->x + w->width + 2;
y = w->y - w->height - 2;
x = w.x + w.width + 2;
y = w.y - w.height - 2;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
x = w->x - w->width - 2;
y = w->y - w->height - 2;
x = w.x - w.width - 2;
y = w.y - w.height - 2;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
x = w->x + w->width + 2;
y = w->y + w->height + 2;
x = w.x + w.width + 2;
y = w.y + w.height + 2;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
x = w->x - w->width - 2;
y = w->y + w->height + 2;
x = w.x - w.width - 2;
y = w.y + w.height + 2;
if (window_fits_within_space(x, y, width, height)) goto foundSpace;
}
// Overlap
for (rct_window *w = g_window_list; w < RCT2_LAST_WINDOW; w++) {
if (w->flags & WF_STICK_TO_BACK)
for (auto& w : g_window_list)
{
if (w.flags & WF_STICK_TO_BACK)
continue;
x = w->x + w->width + 2;
y = w->y;
x = w.x + w.width + 2;
y = w.y;
if (window_fits_on_screen(x, y, width, height)) goto foundSpace;
x = w->x - w->width - 2;
y = w->y;
x = w.x - w.width - 2;
y = w.y;
if (window_fits_on_screen(x, y, width, height)) goto foundSpace;
x = w->x;
y = w->y + w->height + 2;
x = w.x;
y = w.y + w.height + 2;
if (window_fits_on_screen(x, y, width, height)) goto foundSpace;
x = w->x;
y = w->y - w->height - 2;
x = w.x;
y = w.y - w.height - 2;
if (window_fits_on_screen(x, y, width, height)) goto foundSpace;
}
// Cascade
x = 0;
y = 30;
for (rct_window *w = g_window_list; w < RCT2_LAST_WINDOW; w++) {
if (x != w->x || y != w->y)
continue;
for (auto& w : g_window_list)
{
if (x == w.x && y == w.y)
{
x += 5;
y += 5;
}
}
// Clamp to inside the screen
foundSpace:
@@ -622,9 +629,10 @@ static void window_invalidate_pressed_image_buttons(rct_window *w)
*/
void invalidate_all_windows_after_input()
{
for (rct_window *w = RCT2_LAST_WINDOW; w >= g_window_list; w--) {
window_update_scroll_widgets(w);
window_invalidate_pressed_image_buttons(w);
window_event_resize_call(w);
for (auto& w : g_window_list)
{
window_update_scroll_widgets(&w);
window_invalidate_pressed_image_buttons(&w);
window_event_resize_call(&w);
}
}

View File

@@ -238,15 +238,20 @@ void viewport_adjust_for_map_height(sint16* x, sint16* y, sint16 *z)
static void viewport_redraw_after_shift(rct_drawpixelinfo *dpi, rct_window *window, rct_viewport *viewport, sint32 x, sint32 y)
{
// sub-divide by intersecting windows
if (window < gWindowNextSlot)
if (window != nullptr)
{
// skip current window and non-intersecting windows
if (viewport == window->viewport ||
viewport->x + viewport->width <= window->x ||
viewport->x >= window->x + window->width ||
viewport->y + viewport->height <= window->y ||
viewport->y >= window->y + window->height){
viewport_redraw_after_shift(dpi, window + 1, viewport, x, y);
viewport->y >= window->y + window->height)
{
auto nextWindowIndex = window_get_index(window) + 1;
auto nextWindow = nextWindowIndex >= g_window_list.size() ?
nullptr :
&g_window_list[nextWindowIndex];
viewport_redraw_after_shift(dpi, nextWindow, viewport, x, y);
return;
}
@@ -355,12 +360,11 @@ static void viewport_redraw_after_shift(rct_drawpixelinfo *dpi, rct_window *wind
}
}
static void viewport_shift_pixels(rct_drawpixelinfo *dpi, rct_window* w, rct_viewport* viewport, sint16 x_diff, sint16 y_diff)
static void viewport_shift_pixels(rct_drawpixelinfo *dpi, rct_window* window, rct_viewport* viewport, sint16 x_diff, sint16 y_diff)
{
rct_window* orignal_w = w;
sint32 left = 0, right = 0, top = 0, bottom = 0;
for (; w < gWindowNextSlot; w++){
for (auto i = window_get_index(window); i < g_window_list.size(); i++)
{
auto w = &g_window_list[i];
if (!(w->flags & WF_TRANSPARENT)) continue;
if (w->viewport == viewport) continue;
@@ -370,10 +374,10 @@ static void viewport_shift_pixels(rct_drawpixelinfo *dpi, rct_window* w, rct_vie
if (viewport->y + viewport->height <= w->y)continue;
if (w->y + w->height <= viewport->y) continue;
left = w->x;
right = w->x + w->width;
top = w->y;
bottom = w->y + w->height;
auto left = w->x;
auto right = w->x + w->width;
auto top = w->y;
auto bottom = w->y + w->height;
if (left < viewport->x)left = viewport->x;
if (right > viewport->x + viewport->width) right = viewport->x + viewport->width;
@@ -387,8 +391,7 @@ static void viewport_shift_pixels(rct_drawpixelinfo *dpi, rct_window* w, rct_vie
window_draw_all(dpi, left, top, right, bottom);
}
w = orignal_w;
viewport_redraw_after_shift(dpi, w, viewport, x_diff, y_diff);
viewport_redraw_after_shift(dpi, window, viewport, x_diff, y_diff);
}
static void viewport_move(sint16 x, sint16 y, rct_window* w, rct_viewport* viewport)

File diff suppressed because it is too large Load Diff

View File

@@ -528,8 +528,6 @@ using close_callback = void (*)();
#define WINDOW_LIMIT_MAX 64
#define WINDOW_LIMIT_RESERVED 4 // Used to reserve room for the main viewport, toolbars, etc.
extern rct_window * gWindowFirst;
extern rct_window * gWindowNextSlot;
extern rct_window * gWindowAudioExclusive;
extern uint16 gWindowUpdateTicks;
@@ -539,6 +537,7 @@ extern colour_t gCurrentWindowColours[4];
extern bool gDisableErrorWindowSound;
size_t window_get_index(const rct_window* w);
void window_dispatch_update_all();
void window_update_all_viewports();
void window_update_all();

View File

@@ -7,9 +7,9 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#ifndef _WINDOW2_H_
#define _WINDOW2_H_
#pragma once
#include <vector>
#include "Window.h"
struct rct_research_item;
@@ -96,6 +96,4 @@ struct rct_window {
};
// rct2: 0x01420078
extern rct_window g_window_list[WINDOW_LIMIT_MAX + WINDOW_LIMIT_RESERVED];
#endif
extern std::vector<rct_window> g_window_list;