Fix tile command argument compile errors

This commit is contained in:
dP
2023-04-11 01:00:28 +04:00
parent e97cd95660
commit fa2fa80931
12 changed files with 411 additions and 458 deletions

View File

@@ -74,7 +74,21 @@ This is usable for any OpenTTD servers
== CHANGELOG ==
*** ??? ***
*** 13.1 (10 Apr 2022) ***
- Show building preview when funding industries.
- Show industry production on the minimap on high zoom levels in IMBA mode.
- Added two more zoom levels to the minimap.
- Improved performance of the UI for about 20% (ported from JGRPP).
- Show cargo and industry type IDs in industry chains window in developer mode.
- Added cmgamestats console command to show the total number of vehicles in the game.
- Added a server lag counter in the status bar (when show APM is enabled).
- Improved how regular advertisement tracks stations.
- Fixed crash when moving station blueprint outside the map area.
- Fixed crash in polyrail terraforming mode (#15)
- Fixed clients overlay
- Fixed shaded trees and graph background settings not being available in multiplayer.
*** 13.0 (21 Feb 2023) ***
- Added a hotkey to switch industry layouts when funding (MMB by default).
- Fixed crash when no graphics were installed.
- Fixed company selection when clicking in online players window.

View File

@@ -121,14 +121,14 @@ def parse_commands():
result_type = None
args = [RX_ARG.fullmatch(x).group('type', 'name') for x in args_str.split(', ')]
args = args[1:] # flags
first_tile_arg = (args[0][0].strip() == 'TileIndex')
if first_tile_arg:
args = args[1:]
for i, (at, an) in enumerate(args):
at = at.strip()
if at in GLOBAL_TYPES:
at = '::' + at
args[i] = (at, an)
do_args = args[:]
if 'CMD_LOCATION' in flags:
args = [('TileIndex', 'location')] + args
print(cid, constant, category, args)
callback_args = 'CommandCost' if result_type is None else f'CommandCost, {result_type}'
callback_type = f'std::function<void ({callback_args})>'
@@ -151,7 +151,7 @@ def parse_commands():
'flags': flags,
'default_run_as': default_run_as,
'args': args,
'first_tile_arg': first_tile_arg,
'do_args': do_args,
'returns': returns,
'result_type': result_type,
'callback_type': callback_type,
@@ -190,8 +190,8 @@ static size_t FindCallbackIndex(::CommandCallback *callback) {
}
template <Commands Tcmd, size_t Tcb, typename... Targs>
bool _DoPost(StringID err_msg, TileIndex tile, Targs... args) {
return ::Command<Tcmd>::Post(err_msg, std::get<Tcb>(_callback_tuple), tile, std::forward<Targs>(args)...);
bool _DoPost(StringID err_msg, Targs... args) {
return ::Command<Tcmd>::Post(err_msg, std::get<Tcb>(_callback_tuple), std::forward<Targs>(args)...);
}
template <Commands Tcmd, size_t Tcb, typename... Targs>
constexpr auto MakeCallback() noexcept {
@@ -210,7 +210,7 @@ constexpr auto MakeCallback() noexcept {
template <Commands Tcmd, typename... Targs, size_t... i>
inline constexpr auto MakeDispatchTableHelper(std::index_sequence<i...>) noexcept
{
return std::array<bool (*)(StringID err_msg, TileIndex tile, Targs...), sizeof...(i)>{MakeCallback<Tcmd, i, Targs...>()... };
return std::array<bool (*)(StringID err_msg, Targs...), sizeof...(i)>{MakeCallback<Tcmd, i, Targs...>()... };
}
template <Commands Tcmd, typename... Targs>
@@ -261,12 +261,6 @@ def run():
else:
f.write(f' {name}({args_list}) {{}}\n')
if cmd.get('first_tile_arg'):
separator = ', ' if args_list else ''
f.write(
f' {name}(TileIndex tile{separator}{args_list})\n'
f' :Command{{tile}}{separator}{args_init} {{}}\n'
)
f.write(
f' ~{name}() override {{}}\n'
f'\n'
@@ -313,13 +307,7 @@ def run():
this_args_list = ', '.join(f'this->{an}' for _, an in cmd['args'])
args_list = ', '.join(f'{an}' for _, an in cmd['args'])
args_type_list = ', '.join(f'{at}' for at, an in cmd['args'])
test_args_list = args_list
if cmd.get('first_tile_arg'):
if args_list:
test_args_list = f'this->tile, ' + args_list
else:
test_args_list = f'this->tile'
test_args_list = ', '.join(f'{an}' for _, an in cmd['do_args'])
cost_getter = '' if cmd['result_type'] is None else 'std::get<0>'
sep_args_list = sep_args_type_list = sep_this_args_list = ''
if args_list:
@@ -330,7 +318,7 @@ def run():
f'Commands {name}::get_command() {{ return {constant}; }}\n'
f'static constexpr auto _{name}_dispatch = MakeDispatchTable<{constant}{sep_args_type_list}>();\n'
f'bool {name}::_post(::CommandCallback *callback) {{\n'
f' return _{name}_dispatch[FindCallbackIndex(callback)](this->error, this->tile{sep_this_args_list});\n'
f' return _{name}_dispatch[FindCallbackIndex(callback)](this->error{sep_this_args_list});\n'
'}\n'
f'CommandCost {name}::_do(DoCommandFlag flags) {{\n'
f' return {cost_getter}(::Command<{constant}>::Do(flags, {test_args_list}));\n'

View File

@@ -60,7 +60,7 @@ void ExecuteFakeCommands(Date date, DateFract date_fract) {
while (!_fake_commands.empty() && !DatePredate(date, date_fract, _fake_commands.front().date, _fake_commands.front().date_fract)) {
auto &x = _fake_commands.front();
fprintf(stderr, "Executing command: %s(%u) company=%u tile=%u ... ", GetCommandName(x.cp.cmd), x.cp.cmd, x.cp.company, (uint)x.cp.tile);
fprintf(stderr, "Executing command: %s(%u) company=%u ... ", GetCommandName(x.cp.cmd), x.cp.cmd, x.cp.company);
if (x.res == 0) {
fprintf(stderr, "REJECTED\n");
_fake_commands.pop();
@@ -166,7 +166,7 @@ void load_replay_commands(const std::string &filename, std::function<void(const
auto bs = BitIStream(data);
auto version = bs.ReadBytes(2);
if (version != 1) {
if (version != 2) {
error_func(fmt::format("Unsupported log file version {}", version));
return;
}
@@ -189,11 +189,10 @@ void load_replay_commands(const std::string &filename, std::function<void(const
fk.cp.company = (Owner)bs.ReadBytes(1);
fk.client_id = bs.ReadBytes(2);
fk.cp.cmd = (Commands)bs.ReadBytes(2);
fk.cp.tile = bs.ReadBytes(4);
fk.cp.data = bs.ReadData();
fk.cp.callback = nullptr;
_fake_commands.push(fk);
error_func(fmt::format("Command {}({}) company={} client={} tile={}", GetCommandName(fk.cp.cmd), fk.cp.cmd, fk.cp.company, fk.client_id, fk.cp.tile));
error_func(fmt::format("Command {}({}) company={} client={} tile={}", GetCommandName(fk.cp.cmd), fk.cp.cmd, fk.cp.company, fk.client_id));
}
}
catch (BitIStreamUnexpectedEnd &) {

View File

@@ -31,14 +31,12 @@ extern CommandCallback _current_callback;
class Command {
public:
TileIndex tile = 0;
bool no_estimate_flag = false;
CompanyID company = INVALID_COMPANY;
StringID error = (StringID)0;
CommandCallback callback = nullptr;
Command() {}
Command(TileIndex tile) :tile{tile} {}
virtual ~Command() {}
virtual bool _post(::CommandCallback *callback)=0;
@@ -74,11 +72,6 @@ public:
return this->call(DC_NONE);
}
Command &with_tile(TileIndex tile) {
this->tile = tile;
return *this;
}
Command &with_error(StringID error) {
this->error = error;
return *this;

View File

@@ -89,9 +89,9 @@ namespace std {
} // namespace std
namespace citymania {
size_t GetCommandHash(Commands cmd, CompanyID company_id, StringID err_msg, ::CommandCallback callback, TileIndex tile, const CommandDataBuffer &data) {
size_t GetCommandHash(Commands cmd, CompanyID company_id, StringID err_msg, ::CommandCallback callback, const CommandDataBuffer &data) {
size_t res = 0;
hash_combine(res, cmd, (uint16)company_id, err_msg, callback, (uint32)tile, data);
hash_combine(res, cmd, (uint16)company_id, err_msg, callback, data);
return res;
}
@@ -105,7 +105,7 @@ void ExecuteCurrentCallback(const CommandCost &cost) {
void BeforeNetworkCommandExecution(const CommandPacket* cp) {
if (!cp->my_cmd) return;
size_t hash = GetCommandHash(cp->cmd, cp->company, cp->err_msg, cp->callback, cp->tile, cp->data);
size_t hash = GetCommandHash(cp->cmd, cp->company, cp->err_msg, cp->callback, cp->data);
Debug(misc, 5, "CM BeforeNetworkCommandExecution: cmd={} hash={}", cp->cmd, hash);
while (!_callback_queue.empty() && _callback_queue.front().hash != hash) {
Debug(misc, 0, "CM Dismissing command from callback queue: hash={}", _callback_queue.front().hash);
@@ -128,7 +128,7 @@ void AfterNetworkCommandExecution(const CommandPacket* cp) {
}
void AddCommandCallback(const CommandPacket *cp) {
size_t hash = GetCommandHash(cp->cmd, cp->company, cp->err_msg, cp->callback, cp->tile, cp->data);
size_t hash = GetCommandHash(cp->cmd, cp->company, cp->err_msg, cp->callback, cp->data);
Debug(misc, 5, "CM Added callback: cmd={} hash={}", cp->cmd, hash);
_callback_queue.emplace(hash, _current_callback);
_current_callback = nullptr;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -332,7 +332,7 @@ void NetworkExecuteLocalCommandQueue()
if (_frame_counter > cp->frame) {
/* If we reach here, it means for whatever reason, we've already executed
* past the command we need to execute. */
error("[net] Trying to execute a packet in the past! (frame=%u cmd_frame=%u cmd=%u tile=%u)", (uint)_frame_counter, (uint)cp->frame, (uint)cp->cmd, (uint)cp->tile);
error("[net] Trying to execute a packet in the past! (frame=%u cmd_frame=%u cmd=%u)", (uint)_frame_counter, (uint)cp->frame, (uint)cp->cmd);
}
/* We can execute this command */
@@ -554,7 +554,7 @@ void UnpackNetworkCommand(const CommandPacket* cp)
{
citymania::BeforeNetworkCommandExecution(cp);
auto args = EndianBufferReader::ToValue<typename CommandTraits<Tcmd>::Args>(cp->data);
Debug(misc, 5, "UnpackNetworkCommand cmd={} my={} tile={}", GetCommandName(cp->cmd), cp->my_cmd, cp->tile);
Debug(misc, 5, "UnpackNetworkCommand cmd={} my={}", GetCommandName(cp->cmd), cp->my_cmd);
Command<Tcmd>::PostFromNet(cp->err_msg, std::get<Tcb>(_callback_tuple), cp->my_cmd, args);
citymania::AfterNetworkCommandExecution(cp);
}

View File

@@ -816,10 +816,10 @@ private:
if (this->vehicle->GetNumOrders() <= 1) return;
citymania::cmd::SkipToOrder(
this->vehicle->tile,
this->vehicle->index,
citymania::_fn_mod ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()))
.with_error(citymania::_fn_mod ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER)
.with_tile(this->vehicle->tile)
.no_estimate()
.post();
}
@@ -1587,33 +1587,28 @@ public:
if (feeder_mod != FeederOrderMod::NONE) {
if (feeder_mod == FeederOrderMod::LOAD) {
if (citymania::cmd::InsertOrder(this->vehicle->index, 1, cmd)
.with_tile(this->vehicle->tile)
if (citymania::cmd::InsertOrder(this->vehicle->tile, this->vehicle->index, 1, cmd)
.with_error(STR_ERROR_CAN_T_INSERT_NEW_ORDER)
.no_estimate()
.post()) {
citymania::cmd::DeleteOrder(this->vehicle->index, 0)
.with_tile(this->vehicle->tile)
citymania::cmd::DeleteOrder(this->vehicle->tile, this->vehicle->index, 0)
.with_error(STR_ERROR_CAN_T_DELETE_THIS_ORDER)
.no_estimate()
.post();
}
} else if (feeder_mod == FeederOrderMod::UNLOAD) { // still flushes the whole order table
if (citymania::cmd::InsertOrder(this->vehicle->index, this->vehicle->GetNumOrders(), cmd)
.with_tile(this->vehicle->tile)
if (citymania::cmd::InsertOrder(this->vehicle->tile, this->vehicle->index, this->vehicle->GetNumOrders(), cmd)
.with_error(STR_ERROR_CAN_T_INSERT_NEW_ORDER)
.no_estimate()
.post()) {
citymania::cmd::DeleteOrder(this->vehicle->index, this->vehicle->GetNumOrders() + (int)_networking - 2)
.with_tile(this->vehicle->tile)
citymania::cmd::DeleteOrder(this->vehicle->tile, this->vehicle->index, this->vehicle->GetNumOrders() + (int)_networking - 2)
.with_error(STR_ERROR_CAN_T_DELETE_THIS_ORDER)
.no_estimate()
.post();
}
}
} else if (citymania::cmd::InsertOrder(this->vehicle->index, this->OrderGetSel(), cmd)
.with_tile(this->vehicle->tile)
} else if (citymania::cmd::InsertOrder(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), cmd)
.with_error(STR_ERROR_CAN_T_INSERT_NEW_ORDER)
.no_estimate()
.post()) {

View File

@@ -2231,8 +2231,7 @@ struct MainToolbarWindow : Window {
break;
case CM_CBF_BUILD_HQ:
if(citymania::cmd::BuildObject(OBJECT_HQ, 0)
.with_tile(tile)
if(citymania::cmd::BuildObject(tile, OBJECT_HQ, 0)
.with_error(STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS)
.post()) {
ResetObjectToPlace();

View File

@@ -919,8 +919,7 @@ static void DoRegularFunding(Town *t)
if (UINT32_MAX - t->last_funding + _tick_counter < TOWN_GROWTH_TICKS) return;
} else if (_tick_counter - t->last_funding < TOWN_GROWTH_TICKS) return;
citymania::cmd::DoTownAction(t->index, HK_FUND)
.with_tile(t->xy)
citymania::cmd::DoTownAction(t->xy, t->index, HK_FUND)
.no_estimate()
.as_company(_local_company)
.post();
@@ -957,8 +956,7 @@ static void DoRegularAdvertising(Town *t) {
t->last_advertisement = _tick_counter;
auto prev_rating = t->ad_ref_goods_entry->rating;
citymania::cmd::DoTownAction(t->index, HK_LADVERT)
.with_tile(t->xy)
citymania::cmd::DoTownAction(t->xy, t->index, HK_LADVERT)
.no_estimate()
.as_company(_local_company)
.with_callback([=] (bool res) -> bool {

View File

@@ -61,8 +61,7 @@ static void DrawExtraTownInfo (Rect &r, Town *town, uint line, bool show_house_s
bool TownExecuteAction(const Town *town, uint action){
if(!(action == HK_STATUE && HasBit(town->statues, _current_company))){ //don't built statue when there is one
return citymania::cmd::DoTownAction(town->index, action)
.with_tile(town->xy)
return citymania::cmd::DoTownAction(town->xy, town->index, action)
.with_error(STR_ERROR_CAN_T_DO_THIS)
.post();
}