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
#include <deque>
#include <openrct2/interface/InteractiveConsole.h>
#include <openrct2/world/Location.hpp>
#include <string>
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_mousedown(rct_window * w, rct_widgetindex widgetIndex, rct_widget * widget);
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_paint(rct_window * w, rct_drawpixelinfo * dpi);
@ -86,13 +86,13 @@ namespace OpenRCT2::Ui::Windows
{
// Properties
std::string Type;
sint32 X{};
sint32 Y{};
sint32 Width{};
sint32 Height{};
int32_t X{};
int32_t Y{};
int32_t Width{};
int32_t Height{};
std::string Text;
std::vector<std::string> Items;
sint32 SelectedIndex{};
int32_t SelectedIndex{};
// Event handlers
DukValue OnClick;
@ -128,16 +128,16 @@ namespace OpenRCT2::Ui::Windows
struct CustomWindowDesc
{
std::string Classification;
std::optional<sint32> X;
std::optional<sint32> Y;
sint32 Width;
sint32 Height;
std::optional<sint32> MinWidth;
std::optional<sint32> MinHeight;
std::optional<sint32> MaxWidth;
std::optional<sint32> MaxHeight;
std::optional<int32_t> X;
std::optional<int32_t> Y;
int32_t Width;
int32_t Height;
std::optional<int32_t> MinWidth;
std::optional<int32_t> MinHeight;
std::optional<int32_t> MaxWidth;
std::optional<int32_t> MaxHeight;
std::string Title;
std::optional<sint32> Id;
std::optional<int32_t> Id;
std::vector<CustomWidgetDesc> Widgets;
CustomWindowDesc() = default;
@ -172,7 +172,7 @@ namespace OpenRCT2::Ui::Windows
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 ?
std::make_optional(input.as_int()) :
@ -232,7 +232,7 @@ namespace OpenRCT2::Ui::Windows
{
auto desc = CustomWindowDesc::FromDukValue(dukDesc);
uint16 windowFlags = 0;
uint16_t windowFlags = 0;
if (desc.IsResizable())
{
windowFlags |= WF_RESIZABLE;
@ -270,8 +270,8 @@ namespace OpenRCT2::Ui::Windows
{
window->min_width = desc.MinWidth.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_height = desc.MaxHeight.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_t>::max());
}
RefreshWidgets(window);
window_init_scroll_widgets(window);
@ -338,7 +338,7 @@ namespace OpenRCT2::Ui::Windows
for (size_t i = 0; i < numItems; i++)
{
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(
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)
return;

View File

@ -39,11 +39,11 @@ namespace OpenRCT2::Scripting
{
}
sint32 width_get() { return context_get_width(); }
sint32 height_get() { return context_get_height(); }
sint32 windows_get()
int32_t width_get() { return context_get_width(); }
int32_t height_get() { return context_get_height(); }
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)
@ -83,9 +83,9 @@ namespace OpenRCT2::Scripting
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)
{

View File

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

View File

@ -64,7 +64,7 @@ struct widget_identifier
extern widget_identifier gCurrentTextBox;
using WidgetFlags = uint32;
using WidgetFlags = uint32_t;
namespace WIDGET_FLAGS
{
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 cookie = _nextCookie++;
@ -44,7 +44,7 @@ uint32 HookEngine::Subscribe(HOOK_TYPE type, std::shared_ptr<Plugin> owner, cons
return cookie;
}
void HookEngine::Unsubscribe(HOOK_TYPE type, uint32 cookie)
void HookEngine::Unsubscribe(HOOK_TYPE type, uint32_t cookie)
{
auto& hookList = GetHookList(type);
auto& hooks = hookList.Hooks;

View File

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

View File

@ -40,23 +40,23 @@ namespace OpenRCT2::Scripting
return DukValue::take_from_stack(ctx);
}
sint32 rides_get()
int32_t rides_get()
{
return MAX_RIDES;
}
sint32 things_get()
int32_t things_get()
{
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);
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)
{

View File

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

View File

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

View File

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

View File

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