Fix apm and average apm display
This commit is contained in:
@@ -27,11 +27,13 @@ namespace citymania {
|
||||
typedef std::function<bool(bool)> CommandCallback;
|
||||
|
||||
extern bool _no_estimate_command;
|
||||
extern bool _automatic_command;
|
||||
extern CommandCallback _current_callback;
|
||||
|
||||
class Command {
|
||||
public:
|
||||
bool no_estimate_flag = false;
|
||||
bool automatic_flag = false;
|
||||
CompanyID company = INVALID_COMPANY;
|
||||
StringID error = (StringID)0;
|
||||
CommandCallback callback = nullptr;
|
||||
@@ -49,10 +51,12 @@ public:
|
||||
if (this->company != INVALID_COMPANY)
|
||||
_current_company = company;
|
||||
_no_estimate_command = this->no_estimate_flag;
|
||||
_automatic_command = this->automatic_flag;
|
||||
_current_callback = this->callback;
|
||||
bool res = this->_post(reinterpret_cast<::CommandCallback *>(reinterpret_cast<void(*)()>(callback)));
|
||||
_current_company = company_backup;
|
||||
_no_estimate_command = false;
|
||||
_automatic_command = false;
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -83,6 +87,13 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
Command &set_auto() {
|
||||
// Doesn't count for apm
|
||||
this->automatic_flag = true;
|
||||
this->no_estimate_flag = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Command &as_company(CompanyID company) {
|
||||
this->company = company;
|
||||
return *this;
|
||||
|
||||
@@ -20,6 +20,7 @@ std::map<size_t, std::pair<uint32, std::vector<CommandCallback>>> _command_callb
|
||||
std::queue<std::pair<size_t, uint32>> _command_sent;
|
||||
CommandCallback _current_callback = nullptr;
|
||||
bool _no_estimate_command = false;
|
||||
bool _automatic_command = false;
|
||||
|
||||
template <typename T, int MaxLen>
|
||||
class SumLast {
|
||||
|
||||
@@ -28,6 +28,7 @@ struct RailStationGUISettings {
|
||||
byte station_count; ///< Number of custom stations (if newstations is \c true )
|
||||
};
|
||||
extern RailStationGUISettings _railstation; ///< Settings of the station builder GUI
|
||||
extern bool _generating_world;
|
||||
|
||||
namespace citymania {
|
||||
|
||||
@@ -51,6 +52,7 @@ static void PurgeLastActions() {
|
||||
}
|
||||
|
||||
void CountEffectiveAction() {
|
||||
if (_generating_world) return;
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if (!_first_effective_tick) _first_effective_tick = now;
|
||||
_effective_actions++;
|
||||
@@ -69,7 +71,7 @@ std::pair<uint32, uint32> GetEPM() {
|
||||
if (!_first_effective_tick) return std::make_pair(0, 0);
|
||||
PurgeLastActions();
|
||||
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - *_first_effective_tick).count();
|
||||
if (ms == 0) return std::make_pair(0, 0);
|
||||
if (ms < 1000) return std::make_pair(0, _last_actions.size());
|
||||
return std::make_pair(_effective_actions * 60000 / ms,
|
||||
_last_actions.size());
|
||||
}
|
||||
|
||||
@@ -1360,16 +1360,17 @@ bool AirportBuildTool::RemoveHandler::Execute(TileArea area) {
|
||||
|
||||
// SizedPlacementHandler
|
||||
up<Command> AirportBuildTool::SizedPlacementHandler::GetCommand(TileIndex tile, StationID to_join) {
|
||||
// STR_ERROR_CAN_T_BUILD_AIRPORT_HERE,
|
||||
byte airport_type = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->GetIndex();
|
||||
byte layout = _selected_airport_layout;
|
||||
return make_up<cmd::BuildAirport>(
|
||||
auto cmd = make_up<cmd::BuildAirport>(
|
||||
tile,
|
||||
airport_type,
|
||||
layout,
|
||||
StationBuildTool::station_to_join,
|
||||
true
|
||||
);
|
||||
cmd->with_error(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE);
|
||||
return cmd;
|
||||
}
|
||||
|
||||
bool AirportBuildTool::SizedPlacementHandler::Execute(TileIndex tile) {
|
||||
|
||||
@@ -245,8 +245,6 @@ void CommandHelperBase::InternalPostResult(const CommandCost &res, TileIndex til
|
||||
int x = TileX(tile) * TILE_SIZE;
|
||||
int y = TileY(tile) * TILE_SIZE;
|
||||
|
||||
// FIXME if (!(cmd & CMD_NO_ESTIMATE) && my_cmd) citymania::CountEffectiveAction();
|
||||
|
||||
if (res.Failed()) {
|
||||
/* Only show the error when it's for us. */
|
||||
if (estimate_only || (IsLocalCompany() && err_message != 0 && my_cmd)) {
|
||||
|
||||
@@ -24,7 +24,9 @@ extern uint32 _frame_counter;
|
||||
struct CommandPacket;
|
||||
namespace citymania {
|
||||
extern CommandCost _command_execute_cost;
|
||||
extern bool _automatic_command;
|
||||
void ExecuteCurrentCallback(const CommandCost &cost);
|
||||
void CountEffectiveAction();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -314,6 +316,7 @@ protected:
|
||||
Tret res = Execute(err_message, reinterpret_cast<CommandCallback *>(callback), my_cmd, estimate_only, network_command, tile, args);
|
||||
InternalPostResult(ExtractCommandCost(res), tile, estimate_only, only_sending, err_message, my_cmd);
|
||||
citymania::_command_execute_cost = ExtractCommandCost(res);
|
||||
if (!estimate_only && !only_sending && !citymania::_automatic_command && my_cmd) citymania::CountEffectiveAction();
|
||||
|
||||
if (!estimate_only && !only_sending && callback != nullptr) {
|
||||
if constexpr (std::is_same_v<Tcallback, CommandCallback>) {
|
||||
|
||||
@@ -1650,7 +1650,7 @@ public:
|
||||
if (feeder_mod == FeederOrderMod::LOAD) {
|
||||
if (citymania::cmd::InsertOrder(this->vehicle->tile, this->vehicle->index, 1, cmd)
|
||||
.with_error(STR_ERROR_CAN_T_INSERT_NEW_ORDER)
|
||||
.no_estimate()
|
||||
.set_auto()
|
||||
.post()) {
|
||||
citymania::cmd::DeleteOrder(this->vehicle->tile, this->vehicle->index, 0)
|
||||
.with_error(STR_ERROR_CAN_T_DELETE_THIS_ORDER)
|
||||
@@ -1661,7 +1661,7 @@ public:
|
||||
} else if (feeder_mod == FeederOrderMod::UNLOAD) { // still flushes the whole order table
|
||||
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()
|
||||
.set_auto()
|
||||
.post()) {
|
||||
citymania::cmd::DeleteOrder(this->vehicle->tile, this->vehicle->index, this->vehicle->GetNumOrders() + (int)_networking - 2)
|
||||
.with_error(STR_ERROR_CAN_T_DELETE_THIS_ORDER)
|
||||
|
||||
@@ -243,7 +243,7 @@ struct StatusBarWindow : Window {
|
||||
this->SetWidgetDirty(WID_S_LEFT);
|
||||
}};
|
||||
|
||||
TimeoutTimer<TimerWindow> cm_epm_interval = {std::chrono::seconds(1), [this]() {
|
||||
IntervalTimer<TimerWindow> cm_epm_interval = {std::chrono::seconds(1), [this](uint) {
|
||||
this->SetWidgetDirty(CM_WID_S_APM);
|
||||
}};
|
||||
};
|
||||
|
||||
@@ -970,7 +970,7 @@ static void DoRegularFunding(Town *t)
|
||||
} else if (TimerGameTick::counter - t->last_funding < Ticks::TOWN_GROWTH_TICKS) return;
|
||||
|
||||
citymania::cmd::DoTownAction(t->xy, t->index, HK_FUND)
|
||||
.no_estimate()
|
||||
.set_auto()
|
||||
.as_company(_local_company)
|
||||
.post();
|
||||
t->last_funding = TimerGameTick::counter;
|
||||
@@ -1007,7 +1007,7 @@ static void DoRegularAdvertising(Town *t) {
|
||||
|
||||
auto prev_rating = t->ad_ref_goods_entry->rating;
|
||||
citymania::cmd::DoTownAction(t->xy, t->index, HK_LADVERT)
|
||||
.no_estimate()
|
||||
.set_auto()
|
||||
.as_company(_local_company)
|
||||
.with_callback([=] (bool res) -> bool {
|
||||
if (res && prev_rating == t->ad_ref_goods_entry->rating) {
|
||||
|
||||
Reference in New Issue
Block a user