1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-22 23:33:04 +01:00

Use C++ types

This commit is contained in:
Hielke Morsink
2018-07-31 16:25:50 +02:00
committed by Ted John
parent c064614280
commit c37d7d859e
12 changed files with 66 additions and 64 deletions

View File

@@ -9,8 +9,10 @@
#pragma once #pragma once
#include <deque>
#include <openrct2/interface/InteractiveConsole.h> #include <openrct2/interface/InteractiveConsole.h>
#include <openrct2/world/Location.hpp> #include <openrct2/world/Location.hpp>
#include <string>
namespace OpenRCT2::Ui namespace OpenRCT2::Ui
{ {

View File

@@ -46,7 +46,7 @@ namespace OpenRCT2::Ui::Windows
static void window_custom_mouseup(rct_window * w, rct_widgetindex widgetIndex); static void window_custom_mouseup(rct_window * w, rct_widgetindex widgetIndex);
static void window_custom_mousedown(rct_window * w, rct_widgetindex widgetIndex, rct_widget * widget); static void window_custom_mousedown(rct_window * w, rct_widgetindex widgetIndex, rct_widget * widget);
static void window_custom_resize(rct_window * w); static void window_custom_resize(rct_window * w);
static void window_custom_dropdown(rct_window * w, rct_widgetindex widgetIndex, sint32 dropdownIndex); static void window_custom_dropdown(rct_window * w, rct_widgetindex widgetIndex, int32_t dropdownIndex);
static void window_custom_invalidate(rct_window * w); static void window_custom_invalidate(rct_window * w);
static void window_custom_paint(rct_window * w, rct_drawpixelinfo * dpi); static void window_custom_paint(rct_window * w, rct_drawpixelinfo * dpi);
@@ -86,13 +86,13 @@ namespace OpenRCT2::Ui::Windows
{ {
// Properties // Properties
std::string Type; std::string Type;
sint32 X{}; int32_t X{};
sint32 Y{}; int32_t Y{};
sint32 Width{}; int32_t Width{};
sint32 Height{}; int32_t Height{};
std::string Text; std::string Text;
std::vector<std::string> Items; std::vector<std::string> Items;
sint32 SelectedIndex{}; int32_t SelectedIndex{};
// Event handlers // Event handlers
DukValue OnClick; DukValue OnClick;
@@ -128,16 +128,16 @@ namespace OpenRCT2::Ui::Windows
struct CustomWindowDesc struct CustomWindowDesc
{ {
std::string Classification; std::string Classification;
std::optional<sint32> X; std::optional<int32_t> X;
std::optional<sint32> Y; std::optional<int32_t> Y;
sint32 Width; int32_t Width;
sint32 Height; int32_t Height;
std::optional<sint32> MinWidth; std::optional<int32_t> MinWidth;
std::optional<sint32> MinHeight; std::optional<int32_t> MinHeight;
std::optional<sint32> MaxWidth; std::optional<int32_t> MaxWidth;
std::optional<sint32> MaxHeight; std::optional<int32_t> MaxHeight;
std::string Title; std::string Title;
std::optional<sint32> Id; std::optional<int32_t> Id;
std::vector<CustomWidgetDesc> Widgets; std::vector<CustomWidgetDesc> Widgets;
CustomWindowDesc() = default; CustomWindowDesc() = default;
@@ -172,7 +172,7 @@ namespace OpenRCT2::Ui::Windows
return std::move(result); return std::move(result);
} }
static std::optional<sint32> GetOptionalInt(DukValue input) static std::optional<int32_t> GetOptionalInt(DukValue input)
{ {
return input.type() == DukValue::Type::NUMBER ? return input.type() == DukValue::Type::NUMBER ?
std::make_optional(input.as_int()) : std::make_optional(input.as_int()) :
@@ -232,7 +232,7 @@ namespace OpenRCT2::Ui::Windows
{ {
auto desc = CustomWindowDesc::FromDukValue(dukDesc); auto desc = CustomWindowDesc::FromDukValue(dukDesc);
uint16 windowFlags = 0; uint16_t windowFlags = 0;
if (desc.IsResizable()) if (desc.IsResizable())
{ {
windowFlags |= WF_RESIZABLE; windowFlags |= WF_RESIZABLE;
@@ -270,8 +270,8 @@ namespace OpenRCT2::Ui::Windows
{ {
window->min_width = desc.MinWidth.value_or(0); window->min_width = desc.MinWidth.value_or(0);
window->min_height = desc.MinHeight.value_or(0); window->min_height = desc.MinHeight.value_or(0);
window->max_width = desc.MaxWidth.value_or(std::numeric_limits<uint16>::max()); window->max_width = desc.MaxWidth.value_or(std::numeric_limits<uint16_t>::max());
window->max_height = desc.MaxHeight.value_or(std::numeric_limits<uint16>::max()); window->max_height = desc.MaxHeight.value_or(std::numeric_limits<uint16_t>::max());
} }
RefreshWidgets(window); RefreshWidgets(window);
window_init_scroll_widgets(window); window_init_scroll_widgets(window);
@@ -338,7 +338,7 @@ namespace OpenRCT2::Ui::Windows
for (size_t i = 0; i < numItems; i++) for (size_t i = 0; i < numItems; i++)
{ {
gDropdownItemsFormat[i] = STR_STRING; gDropdownItemsFormat[i] = STR_STRING;
set_format_arg_on((uint8*)&gDropdownItemsArgs[i], 0, const char *, items[i].c_str()); set_format_arg_on((uint8_t*)&gDropdownItemsArgs[i], 0, const char *, items[i].c_str());
} }
window_dropdown_show_text_custom_width( window_dropdown_show_text_custom_width(
w->x + widget->left, w->x + widget->left,
@@ -353,7 +353,7 @@ namespace OpenRCT2::Ui::Windows
} }
} }
static void window_custom_dropdown(rct_window * w, rct_widgetindex widgetIndex, sint32 dropdownIndex) static void window_custom_dropdown(rct_window * w, rct_widgetindex widgetIndex, int32_t dropdownIndex)
{ {
if (dropdownIndex == -1) if (dropdownIndex == -1)
return; return;

View File

@@ -39,11 +39,11 @@ namespace OpenRCT2::Scripting
{ {
} }
sint32 width_get() { return context_get_width(); } int32_t width_get() { return context_get_width(); }
sint32 height_get() { return context_get_height(); } int32_t height_get() { return context_get_height(); }
sint32 windows_get() int32_t windows_get()
{ {
return static_cast<sint32>(g_window_list.size()); return static_cast<int32_t>(g_window_list.size());
} }
std::shared_ptr<ScWindow> openWindow(DukValue desc) std::shared_ptr<ScWindow> openWindow(DukValue desc)
@@ -83,9 +83,9 @@ namespace OpenRCT2::Scripting
window_close_all(); window_close_all();
} }
std::shared_ptr<ScWindow> getWindow(sint32 index) std::shared_ptr<ScWindow> getWindow(int32_t index)
{ {
for (sint32 i = 0; i < g_window_list.size(); i++) for (int32_t i = 0; i < g_window_list.size(); i++)
{ {
if (i == index) if (i == index)
{ {

View File

@@ -34,20 +34,20 @@ namespace OpenRCT2::Scripting
{ {
} }
sint32 x_get() { return GetWindow()->x; } int32_t x_get() { return GetWindow()->x; }
void x_set(sint32 value) void x_set(int32_t value)
{ {
auto w = GetWindow(); auto w = GetWindow();
window_set_position(w, value, w->y); window_set_position(w, value, w->y);
} }
sint32 y_get() { return GetWindow()->y; } int32_t y_get() { return GetWindow()->y; }
void y_set(sint32 value) void y_set(int32_t value)
{ {
auto w = GetWindow(); auto w = GetWindow();
window_set_position(w, w->x, value); window_set_position(w, w->x, value);
} }
sint32 width_get() { return GetWindow()->width; } int32_t width_get() { return GetWindow()->width; }
sint32 height_get() { return GetWindow()->height; } int32_t height_get() { return GetWindow()->height; }
bool isSticky_get() bool isSticky_get()
{ {
auto flags = GetWindow()->flags; auto flags = GetWindow()->flags;

View File

@@ -64,7 +64,7 @@ struct widget_identifier
extern widget_identifier gCurrentTextBox; extern widget_identifier gCurrentTextBox;
using WidgetFlags = uint32; using WidgetFlags = uint32_t;
namespace WIDGET_FLAGS namespace WIDGET_FLAGS
{ {
const WidgetFlags TEXT_IS_STRING = 1 << 0; const WidgetFlags TEXT_IS_STRING = 1 << 0;

View File

@@ -35,7 +35,7 @@ HookEngine::HookEngine(ScriptExecutionInfo& execInfo) :
} }
} }
uint32 HookEngine::Subscribe(HOOK_TYPE type, std::shared_ptr<Plugin> owner, const DukValue &function) uint32_t HookEngine::Subscribe(HOOK_TYPE type, std::shared_ptr<Plugin> owner, const DukValue &function)
{ {
auto& hookList = GetHookList(type); auto& hookList = GetHookList(type);
auto cookie = _nextCookie++; auto cookie = _nextCookie++;
@@ -44,7 +44,7 @@ uint32 HookEngine::Subscribe(HOOK_TYPE type, std::shared_ptr<Plugin> owner, cons
return cookie; return cookie;
} }
void HookEngine::Unsubscribe(HOOK_TYPE type, uint32 cookie) void HookEngine::Unsubscribe(HOOK_TYPE type, uint32_t cookie)
{ {
auto& hookList = GetHookList(type); auto& hookList = GetHookList(type);
auto& hooks = hookList.Hooks; auto& hooks = hookList.Hooks;

View File

@@ -32,12 +32,12 @@ namespace OpenRCT2::Scripting
struct Hook struct Hook
{ {
uint32 Cookie; uint32_t Cookie;
std::shared_ptr<Plugin> Owner; std::shared_ptr<Plugin> Owner;
DukValue Function; DukValue Function;
Hook(); Hook();
Hook(uint32 cookie, std::shared_ptr<Plugin> owner, const DukValue &function) Hook(uint32_t cookie, std::shared_ptr<Plugin> owner, const DukValue &function)
: Cookie(cookie), : Cookie(cookie),
Owner(owner), Owner(owner),
Function(function) Function(function)
@@ -70,8 +70,8 @@ namespace OpenRCT2::Scripting
public: public:
HookEngine(ScriptExecutionInfo& execInfo); HookEngine(ScriptExecutionInfo& execInfo);
HookEngine(const HookEngine&) = delete; HookEngine(const HookEngine&) = delete;
uint32 Subscribe(HOOK_TYPE type, std::shared_ptr<Plugin> owner, const DukValue &function); uint32_t Subscribe(HOOK_TYPE type, std::shared_ptr<Plugin> owner, const DukValue &function);
void Unsubscribe(HOOK_TYPE type, uint32 cookie); void Unsubscribe(HOOK_TYPE type, uint32_t cookie);
void UnsubscribeAll(std::shared_ptr<const Plugin> owner); void UnsubscribeAll(std::shared_ptr<const Plugin> owner);
void Call(HOOK_TYPE type); void Call(HOOK_TYPE type);

View File

@@ -40,23 +40,23 @@ namespace OpenRCT2::Scripting
return DukValue::take_from_stack(ctx); return DukValue::take_from_stack(ctx);
} }
sint32 rides_get() int32_t rides_get()
{ {
return MAX_RIDES; return MAX_RIDES;
} }
sint32 things_get() int32_t things_get()
{ {
return MAX_SPRITES; return MAX_SPRITES;
} }
std::shared_ptr<ScTile> getTile(sint32 x, sint32 y) std::shared_ptr<ScTile> getTile(int32_t x, int32_t y)
{ {
auto firstElement = map_get_first_element_at(x, y); auto firstElement = map_get_first_element_at(x, y);
return std::make_shared<ScTile>(firstElement); return std::make_shared<ScTile>(firstElement);
} }
std::shared_ptr<ScThing> getThing(sint32 id) std::shared_ptr<ScThing> getThing(int32_t id)
{ {
if (id >= 0 && id < MAX_SPRITES) if (id >= 0 && id < MAX_SPRITES)
{ {

View File

@@ -31,8 +31,8 @@ namespace OpenRCT2::Scripting
context_broadcast_intent(&intent); context_broadcast_intent(&intent);
} }
sint32 rating_get() { return gParkRating; } int32_t rating_get() { return gParkRating; }
void rating_set(sint32 value) void rating_set(int32_t value)
{ {
gParkRating = std::min(std::max(0, value), 999); gParkRating = std::min(std::max(0, value), 999);
auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING); auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING);
@@ -59,7 +59,7 @@ namespace OpenRCT2::Scripting
{ {
try try
{ {
uint8 type = NEWS_ITEM_BLANK; uint8_t type = NEWS_ITEM_BLANK;
std::string text; std::string text;
if (message.type() == DukValue::Type::STRING) if (message.type() == DukValue::Type::STRING)
{ {
@@ -70,7 +70,7 @@ namespace OpenRCT2::Scripting
type = GetParkMessageType(message["type"].as_string()); type = GetParkMessageType(message["type"].as_string());
text = message["text"].as_string(); text = message["text"].as_string();
} }
news_item_add_to_queue_raw(type, text.c_str(), static_cast<uint32>(-1)); news_item_add_to_queue_raw(type, text.c_str(), static_cast<uint32_t>(-1));
} }
catch (const std::exception&) catch (const std::exception&)
{ {
@@ -87,7 +87,7 @@ namespace OpenRCT2::Scripting
} }
private: private:
uint8 GetParkMessageType(const std::string& key) uint8_t GetParkMessageType(const std::string& key)
{ {
static auto keys = { static auto keys = {
"attraction", "attraction",
@@ -99,7 +99,7 @@ namespace OpenRCT2::Scripting
"guests", "guests",
"award", "award",
"chart" }; "chart" };
uint8 i = 0; uint8_t i = 0;
for (const auto& k : keys) for (const auto& k : keys)
{ {
if (k == key) if (k == key)

View File

@@ -35,14 +35,14 @@ namespace OpenRCT2::Scripting
return "unknown"; return "unknown";
} }
sint32 x_get() { return _sprite->unknown.x; } int32_t x_get() { return _sprite->unknown.x; }
sint32 y_get() { return _sprite->unknown.y; } int32_t y_get() { return _sprite->unknown.y; }
sint32 z_get() { return _sprite->unknown.z; } int32_t z_get() { return _sprite->unknown.z; }
uint8 tshirtColour_get() { return _sprite->peep.tshirt_colour; } uint8_t tshirtColour_get() { return _sprite->peep.tshirt_colour; }
void tshirtColour_set(uint8 value) { _sprite->peep.tshirt_colour = value; } void tshirtColour_set(uint8_t value) { _sprite->peep.tshirt_colour = value; }
uint8 trousersColour_get() { return _sprite->peep.trousers_colour; } uint8_t trousersColour_get() { return _sprite->peep.trousers_colour; }
void trousersColour_set(uint8 value) { _sprite->peep.trousers_colour = value; } void trousersColour_set(uint8_t value) { _sprite->peep.trousers_colour = value; }
static void Register(duk_context * ctx) static void Register(duk_context * ctx)
{ {

View File

@@ -70,7 +70,7 @@ namespace OpenRCT2::Scripting
{ {
return _element->base_height; return _element->base_height;
} }
void baseHeight_set(uint8 newBaseHeight) void baseHeight_set(uint8_t newBaseHeight)
{ {
_element->base_height = newBaseHeight; _element->base_height = newBaseHeight;
} }
@@ -79,7 +79,7 @@ namespace OpenRCT2::Scripting
{ {
return _element->clearance_height; return _element->clearance_height;
} }
void clearanceHeight_set(uint8 newClearanceHeight) void clearanceHeight_set(uint8_t newClearanceHeight)
{ {
_element->clearance_height = newClearanceHeight; _element->clearance_height = newClearanceHeight;
} }
@@ -204,13 +204,13 @@ namespace OpenRCT2::Scripting
"broken"); "broken");
dukglue_register_property( dukglue_register_property(
ctx, ctx,
static_cast<uint8 (T::*)() const>(&ScTileElement::baseHeight_get), static_cast<uint8_t (T::*)() const>(&ScTileElement::baseHeight_get),
static_cast<void (T::*)(uint8)>(&ScTileElement::baseHeight_set), static_cast<void (T::*)(uint8_t)>(&ScTileElement::baseHeight_set),
"baseHeight"); "baseHeight");
dukglue_register_property( dukglue_register_property(
ctx, ctx,
static_cast<uint8 (T::*)() const>(&ScTileElement::clearanceHeight_get), static_cast<uint8_t (T::*)() const>(&ScTileElement::clearanceHeight_get),
static_cast<void (T::*)(uint8)>(&ScTileElement::clearanceHeight_set), static_cast<void (T::*)(uint8_t)>(&ScTileElement::clearanceHeight_set),
"clearanceHeight"); "clearanceHeight");
} }

View File

@@ -88,7 +88,7 @@ namespace OpenRCT2::Scripting
bool _initialised{}; bool _initialised{};
std::queue<std::tuple<std::promise<void>, std::string>> _evalQueue; std::queue<std::tuple<std::promise<void>, std::string>> _evalQueue;
std::vector<std::shared_ptr<Plugin>> _plugins; std::vector<std::shared_ptr<Plugin>> _plugins;
uint32 _lastHotReloadCheckTick{}; uint32_t _lastHotReloadCheckTick{};
HookEngine _hookEngine; HookEngine _hookEngine;
ScriptExecutionInfo _execInfo; ScriptExecutionInfo _execInfo;