1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 07:43:01 +01:00

Use ExecuteNested/QueryNested instead of passing a parameter.

This commit is contained in:
Matt
2019-02-15 16:32:11 +01:00
parent 16e371c792
commit 00be865ff1
5 changed files with 48 additions and 21 deletions

View File

@@ -155,8 +155,8 @@ private:
auto footpathRemoveAction = FootpathRemoveAction(x * 32, y * 32, tileElement->base_height);
footpathRemoveAction.SetFlags(GetFlags());
auto res = executing ? GameActions::Execute(&footpathRemoveAction, false)
: GameActions::Query(&footpathRemoveAction, false);
auto res = executing ? GameActions::ExecuteNested(&footpathRemoveAction)
: GameActions::QueryNested(&footpathRemoveAction);
if (res->Error != GA_ERROR::OK)
return MONEY32_UNDEFINED;
@@ -173,8 +173,8 @@ private:
tileElement->AsSmallScenery()->GetEntryIndex());
removeSceneryAction.SetFlags(GetFlags());
auto res = executing ? GameActions::Execute(&removeSceneryAction, false)
: GameActions::Query(&removeSceneryAction, false);
auto res = executing ? GameActions::ExecuteNested(&removeSceneryAction)
: GameActions::QueryNested(&removeSceneryAction);
if (res->Error != GA_ERROR::OK)
return MONEY32_UNDEFINED;
@@ -190,8 +190,8 @@ private:
auto wallRemoveAction = WallRemoveAction(wallLocation);
wallRemoveAction.SetFlags(GetFlags());
auto res = executing ? GameActions::Execute(&wallRemoveAction, false)
: GameActions::Query(&wallRemoveAction, false);
auto res = executing ? GameActions::ExecuteNested(&wallRemoveAction)
: GameActions::QueryNested(&wallRemoveAction);
if (res->Error != GA_ERROR::OK)
return MONEY32_UNDEFINED;
@@ -208,8 +208,8 @@ private:
tileElement->AsLargeScenery()->GetSequenceIndex());
removeSceneryAction.SetFlags(GetFlags() | GAME_COMMAND_FLAG_PATH_SCENERY);
auto res = executing ? GameActions::Execute(&removeSceneryAction, false)
: GameActions::Query(&removeSceneryAction, false);
auto res = executing ? GameActions::ExecuteNested(&removeSceneryAction)
: GameActions::QueryNested(&removeSceneryAction);
if (res->Error != GA_ERROR::OK)
return MONEY32_UNDEFINED;

View File

@@ -137,7 +137,7 @@ namespace GameActions
return false;
}
GameActionResult::Ptr Query(const GameAction* action, bool topLevel /* = true */)
static GameActionResult::Ptr QueryInternal(const GameAction* action, bool topLevel)
{
Guard::ArgumentNotNull(action);
@@ -156,7 +156,7 @@ namespace GameActions
auto result = action->Query();
// Only top level actions affect the command position.
if (topLevel == true)
if (topLevel)
{
gCommandPosition.x = result->Position.x;
gCommandPosition.y = result->Position.y;
@@ -175,6 +175,16 @@ namespace GameActions
return result;
}
GameActionResult::Ptr Query(const GameAction* action)
{
return QueryInternal(action, true);
}
GameActionResult::Ptr QueryNested(const GameAction* action)
{
return QueryInternal(action, false);
}
static const char* GetRealm()
{
if (network_get_mode() == NETWORK_MODE_CLIENT)
@@ -227,7 +237,7 @@ namespace GameActions
network_append_server_log(text);
}
GameActionResult::Ptr Execute(const GameAction* action, bool topLevel /* = true */)
static GameActionResult::Ptr ExecuteInternal(const GameAction* action, bool topLevel)
{
Guard::ArgumentNotNull(action);
@@ -251,7 +261,7 @@ namespace GameActions
}
}
GameActionResult::Ptr result = Query(action, topLevel);
GameActionResult::Ptr result = Query(action);
if (result->Error == GA_ERROR::OK)
{
if (topLevel)
@@ -364,4 +374,14 @@ namespace GameActions
return result;
}
GameActionResult::Ptr Execute(const GameAction* action)
{
return ExecuteInternal(action, true);
}
GameActionResult::Ptr ExecuteNested(const GameAction* action)
{
return ExecuteInternal(action, false);
}
} // namespace GameActions

View File

@@ -244,8 +244,15 @@ namespace GameActions
bool IsValidId(uint32_t id);
GameAction::Ptr Create(uint32_t id);
GameAction::Ptr Clone(const GameAction* action);
GameActionResult::Ptr Query(const GameAction* action, bool topLevel = true);
GameActionResult::Ptr Execute(const GameAction* action, bool topLevel = true);
// This should be used if a round trip is to be expected.
GameActionResult::Ptr Query(const GameAction* action);
GameActionResult::Ptr Execute(const GameAction* action);
// This should be used from within game actions.
GameActionResult::Ptr QueryNested(const GameAction* action);
GameActionResult::Ptr ExecuteNested(const GameAction* action);
GameActionFactory Register(uint32_t id, GameActionFactory action);
template<typename T> static GameActionFactory Register()

View File

@@ -264,7 +264,7 @@ private:
auto setMazeTrack = MazeSetTrackAction(x, y, z, false, direction, _rideIndex, GC_SET_MAZE_TRACK_FILL);
setMazeTrack.SetFlags(GetFlags());
auto execRes = GameActions::Execute(&setMazeTrack, false);
auto execRes = GameActions::ExecuteNested(&setMazeTrack);
if (execRes->Error == GA_ERROR::OK)
{
return execRes->Cost;

View File

@@ -1330,8 +1330,8 @@ static money32 lower_land(
auto landSetHeightAction = LandSetHeightAction({ x_coord, y_coord }, height, newSlope);
landSetHeightAction.SetFlags(flags);
auto res = (flags & GAME_COMMAND_FLAG_APPLY) ? GameActions::Execute(&landSetHeightAction, false)
: GameActions::Query(&landSetHeightAction, false);
auto res = (flags & GAME_COMMAND_FLAG_APPLY) ? GameActions::ExecuteNested(&landSetHeightAction)
: GameActions::QueryNested(&landSetHeightAction);
if (res->Error != GA_ERROR::OK)
{
return MONEY32_UNDEFINED;
@@ -1583,8 +1583,8 @@ static money32 smooth_land_tile(
auto landSetHeightAction = LandSetHeightAction({ x, y }, targetBaseZ, slope);
landSetHeightAction.SetFlags(flags);
auto res = (flags & GAME_COMMAND_FLAG_APPLY) ? GameActions::Execute(&landSetHeightAction, false)
: GameActions::Query(&landSetHeightAction, false);
auto res = (flags & GAME_COMMAND_FLAG_APPLY) ? GameActions::ExecuteNested(&landSetHeightAction)
: GameActions::QueryNested(&landSetHeightAction);
if (res->Error == GA_ERROR::OK)
{
@@ -1730,8 +1730,8 @@ static money32 smooth_land_row_by_edge(
}
auto landSetHeightAction = LandSetHeightAction({ x, y }, targetBaseZ, slope);
landSetHeightAction.SetFlags(flags);
auto res = (flags & GAME_COMMAND_FLAG_APPLY) ? GameActions::Execute(&landSetHeightAction, false)
: GameActions::Query(&landSetHeightAction, false);
auto res = (flags & GAME_COMMAND_FLAG_APPLY) ? GameActions::ExecuteNested(&landSetHeightAction)
: GameActions::QueryNested(&landSetHeightAction);
if (res->Error == GA_ERROR::OK)
{
totalCost += res->Cost;