1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-25 15:54:31 +01:00

Rename HOOK_TYPE and its members

This commit is contained in:
Gymnasiast
2025-03-26 12:16:47 +01:00
parent 867b69a0f6
commit eaaba9fbfb
12 changed files with 90 additions and 90 deletions

View File

@@ -18,42 +18,42 @@
using namespace OpenRCT2::Scripting;
static const EnumMap<HOOK_TYPE> HooksLookupTable({
{ "action.query", HOOK_TYPE::ACTION_QUERY },
{ "action.execute", HOOK_TYPE::ACTION_EXECUTE },
{ "interval.tick", HOOK_TYPE::INTERVAL_TICK },
{ "interval.day", HOOK_TYPE::INTERVAL_DAY },
{ "network.chat", HOOK_TYPE::NETWORK_CHAT },
{ "network.authenticate", HOOK_TYPE::NETWORK_AUTHENTICATE },
{ "network.join", HOOK_TYPE::NETWORK_JOIN },
{ "network.leave", HOOK_TYPE::NETWORK_LEAVE },
{ "ride.ratings.calculate", HOOK_TYPE::RIDE_RATINGS_CALCULATE },
{ "action.location", HOOK_TYPE::ACTION_LOCATION },
{ "guest.generation", HOOK_TYPE::GUEST_GENERATION },
{ "vehicle.crash", HOOK_TYPE::VEHICLE_CRASH },
{ "map.change", HOOK_TYPE::MAP_CHANGE },
{ "map.changed", HOOK_TYPE::MAP_CHANGED },
{ "map.save", HOOK_TYPE::MAP_SAVE },
{ "park.guest.softcap.calculate", HOOK_TYPE::PARK_CALCULATE_GUEST_CAP },
static const EnumMap<HookType> HooksLookupTable({
{ "action.query", HookType::actionQuery },
{ "action.execute", HookType::actionExecute },
{ "interval.tick", HookType::intervalTick },
{ "interval.day", HookType::intervalDay },
{ "network.chat", HookType::networkChat },
{ "network.authenticate", HookType::networkAuthenticate },
{ "network.join", HookType::networkJoin },
{ "network.leave", HookType::networkLeave },
{ "ride.ratings.calculate", HookType::rideRatingsCalculate },
{ "action.location", HookType::actionLocation },
{ "guest.generation", HookType::guestGeneration },
{ "vehicle.crash", HookType::vehicleCrash },
{ "map.change", HookType::mapChange },
{ "map.changed", HookType::mapChanged },
{ "map.save", HookType::mapSave },
{ "park.guest.softcap.calculate", HookType::parkCalculateGuestCap },
});
HOOK_TYPE OpenRCT2::Scripting::GetHookType(const std::string& name)
HookType OpenRCT2::Scripting::GetHookType(const std::string& name)
{
auto result = HooksLookupTable.find(name);
return (result != HooksLookupTable.end()) ? result->second : HOOK_TYPE::UNDEFINED;
return (result != HooksLookupTable.end()) ? result->second : HookType::notDefined;
}
HookEngine::HookEngine(ScriptEngine& scriptEngine)
: _scriptEngine(scriptEngine)
{
_hookMap.resize(NUM_HOOK_TYPES);
for (size_t i = 0; i < NUM_HOOK_TYPES; i++)
_hookMap.resize(NUM_HookTypeS);
for (size_t i = 0; i < NUM_HookTypeS; i++)
{
_hookMap[i].Type = static_cast<HOOK_TYPE>(i);
_hookMap[i].Type = static_cast<HookType>(i);
}
}
uint32_t HookEngine::Subscribe(HOOK_TYPE type, std::shared_ptr<Plugin> owner, const DukValue& function)
uint32_t HookEngine::Subscribe(HookType type, std::shared_ptr<Plugin> owner, const DukValue& function)
{
auto& hookList = GetHookList(type);
auto cookie = _nextCookie++;
@@ -61,7 +61,7 @@ uint32_t HookEngine::Subscribe(HOOK_TYPE type, std::shared_ptr<Plugin> owner, co
return cookie;
}
void HookEngine::Unsubscribe(HOOK_TYPE type, uint32_t cookie)
void HookEngine::Unsubscribe(HookType type, uint32_t cookie)
{
auto& hookList = GetHookList(type);
auto& hooks = hookList.Hooks;
@@ -94,22 +94,22 @@ void HookEngine::UnsubscribeAll()
}
}
bool HookEngine::HasSubscriptions(HOOK_TYPE type) const
bool HookEngine::HasSubscriptions(HookType type) const
{
auto& hookList = GetHookList(type);
return !hookList.Hooks.empty();
}
bool HookEngine::IsValidHookForPlugin(HOOK_TYPE type, Plugin& plugin) const
bool HookEngine::IsValidHookForPlugin(HookType type, Plugin& plugin) const
{
if (type == HOOK_TYPE::MAP_CHANGED && plugin.GetMetadata().Type != PluginType::Intransient)
if (type == HookType::mapChanged && plugin.GetMetadata().Type != PluginType::Intransient)
{
return false;
}
return true;
}
void HookEngine::Call(HOOK_TYPE type, bool isGameStateMutable)
void HookEngine::Call(HookType type, bool isGameStateMutable)
{
auto& hookList = GetHookList(type);
for (auto& hook : hookList.Hooks)
@@ -118,7 +118,7 @@ void HookEngine::Call(HOOK_TYPE type, bool isGameStateMutable)
}
}
void HookEngine::Call(HOOK_TYPE type, const DukValue& arg, bool isGameStateMutable)
void HookEngine::Call(HookType type, const DukValue& arg, bool isGameStateMutable)
{
auto& hookList = GetHookList(type);
for (auto& hook : hookList.Hooks)
@@ -128,7 +128,7 @@ void HookEngine::Call(HOOK_TYPE type, const DukValue& arg, bool isGameStateMutab
}
void HookEngine::Call(
HOOK_TYPE type, const std::initializer_list<std::pair<std::string_view, std::any>>& args, bool isGameStateMutable)
HookType type, const std::initializer_list<std::pair<std::string_view, std::any>>& args, bool isGameStateMutable)
{
auto& hookList = GetHookList(type);
for (auto& hook : hookList.Hooks)
@@ -162,13 +162,13 @@ void HookEngine::Call(
}
}
HookList& HookEngine::GetHookList(HOOK_TYPE type)
HookList& HookEngine::GetHookList(HookType type)
{
auto index = static_cast<size_t>(type);
return _hookMap[index];
}
const HookList& HookEngine::GetHookList(HOOK_TYPE type) const
const HookList& HookEngine::GetHookList(HookType type) const
{
auto index = static_cast<size_t>(type);
return _hookMap[index];

View File

@@ -25,29 +25,29 @@ namespace OpenRCT2::Scripting
class ScriptExecutionInfo;
class Plugin;
enum class HOOK_TYPE
enum class HookType
{
ACTION_QUERY,
ACTION_EXECUTE,
INTERVAL_TICK,
INTERVAL_DAY,
NETWORK_CHAT,
NETWORK_AUTHENTICATE,
NETWORK_JOIN,
NETWORK_LEAVE,
RIDE_RATINGS_CALCULATE,
ACTION_LOCATION,
GUEST_GENERATION,
VEHICLE_CRASH,
MAP_CHANGE,
MAP_CHANGED,
MAP_SAVE,
PARK_CALCULATE_GUEST_CAP,
COUNT,
UNDEFINED = -1,
actionQuery,
actionExecute,
intervalTick,
intervalDay,
networkChat,
networkAuthenticate,
networkJoin,
networkLeave,
rideRatingsCalculate,
actionLocation,
guestGeneration,
vehicleCrash,
mapChange,
mapChanged,
mapSave,
parkCalculateGuestCap,
count,
notDefined = -1,
};
constexpr size_t NUM_HOOK_TYPES = static_cast<size_t>(HOOK_TYPE::COUNT);
HOOK_TYPE GetHookType(const std::string& name);
constexpr size_t NUM_HookTypeS = static_cast<size_t>(HookType::count);
HookType GetHookType(const std::string& name);
struct Hook
{
@@ -66,7 +66,7 @@ namespace OpenRCT2::Scripting
struct HookList
{
HOOK_TYPE Type{};
HookType Type{};
std::vector<Hook> Hooks;
HookList() = default;
@@ -84,20 +84,20 @@ namespace OpenRCT2::Scripting
public:
HookEngine(ScriptEngine& scriptEngine);
HookEngine(const HookEngine&) = delete;
uint32_t Subscribe(HOOK_TYPE type, std::shared_ptr<Plugin> owner, const DukValue& function);
void Unsubscribe(HOOK_TYPE type, uint32_t cookie);
uint32_t Subscribe(HookType type, std::shared_ptr<Plugin> owner, const DukValue& function);
void Unsubscribe(HookType type, uint32_t cookie);
void UnsubscribeAll(std::shared_ptr<const Plugin> owner);
void UnsubscribeAll();
bool HasSubscriptions(HOOK_TYPE type) const;
bool IsValidHookForPlugin(HOOK_TYPE type, Plugin& plugin) const;
void Call(HOOK_TYPE type, bool isGameStateMutable);
void Call(HOOK_TYPE type, const DukValue& arg, bool isGameStateMutable);
bool HasSubscriptions(HookType type) const;
bool IsValidHookForPlugin(HookType type, Plugin& plugin) const;
void Call(HookType type, bool isGameStateMutable);
void Call(HookType type, const DukValue& arg, bool isGameStateMutable);
void Call(
HOOK_TYPE type, const std::initializer_list<std::pair<std::string_view, std::any>>& args, bool isGameStateMutable);
HookType type, const std::initializer_list<std::pair<std::string_view, std::any>>& args, bool isGameStateMutable);
private:
HookList& GetHookList(HOOK_TYPE type);
const HookList& GetHookList(HOOK_TYPE type) const;
HookList& GetHookList(HookType type);
const HookList& GetHookList(HookType type) const;
};
} // namespace OpenRCT2::Scripting

View File

@@ -1460,7 +1460,7 @@ void ScriptEngine::RunGameActionHooks(const GameAction& action, GameActions::Res
{
DukStackFrame frame(_context);
auto hookType = isExecute ? HOOK_TYPE::ACTION_EXECUTE : HOOK_TYPE::ACTION_QUERY;
auto hookType = isExecute ? HookType::actionExecute : HookType::actionQuery;
if (_hookEngine.HasSubscriptions(hookType))
{
DukObject obj(_context);

View File

@@ -273,7 +273,7 @@ namespace OpenRCT2::Scripting
__declspec(noinline)
#endif
std::shared_ptr<ScDisposable>
CreateSubscription(HOOK_TYPE hookType, const DukValue& callback)
CreateSubscription(HookType hookType, const DukValue& callback)
{
auto owner = _execInfo.GetCurrentPlugin();
auto cookie = _hookEngine.Subscribe(hookType, owner, callback);
@@ -286,7 +286,7 @@ namespace OpenRCT2::Scripting
auto ctx = scriptEngine.GetContext();
auto hookType = GetHookType(hook);
if (hookType == HOOK_TYPE::UNDEFINED)
if (hookType == HookType::notDefined)
{
duk_error(ctx, DUK_ERR_ERROR, "Unknown hook type");
}