game: update node section at once when starting/stopping mining

This commit is contained in:
Crypto City 2020-09-02 23:21:18 +00:00
parent aa288727bd
commit 9ccbef4810
2 changed files with 25 additions and 13 deletions

View File

@ -160,7 +160,8 @@ UIUrho3D::UIUrho3D(Context *ctx, const GameState *gameState):
smeltDialog(nullptr),
include_unmatched_trades_in_queued_commands(false),
compass_rotation_speed(0.0f),
selectMaterial(NULL)
selectMaterial(NULL),
update_mining(true)
{
auto root = ctx->GetSubsystem<UI>()->GetRoot();
auto* cache = ctx->GetSubsystem<ResourceCache>();
@ -698,6 +699,20 @@ void UIUrho3D::RemoveQueuedCommand(const std::string &txid)
tradeDialog->RemoveCancelledNonce(txid);
}
void UIUrho3D::UpdateMining(const std::shared_ptr<GameWallet> &w)
{
uint32_t sync_percent = 0, mining_hash_rate = 0;
w->get_node_status(sync_percent, mining_hash_rate);
std::string str = std::to_string(sync_percent) + "% synced";
str += " (" + std::to_string(gameState->top_height + 1) + ")";
if (mining_hash_rate)
str += ", mining at " + std::to_string(mining_hash_rate) + " H/s";
nodeStatusWidget->SetText(str.c_str());
startMiningContainer->SetValue(gameState->playerState.has_wallet && mining_hash_rate == 0);
stopMiningContainer->SetValue(mining_hash_rate != 0);
update_mining = false;
}
void UIUrho3D::Update(float timeStep, uint32_t mouse_x, uint32_t mouse_y, uint32_t sx0, uint32_t sy0, uint32_t sx1, uint32_t sy1, bool showingFlags, bool building, unsigned num_unread_chat_lines, bool highlight_chat, const std::shared_ptr<GameWallet> &w, const Vector3 &view_direction, const boost::optional<std::tuple<uint32_t, std::vector<uint16_t>, std::vector<std::vector<uint8_t>>>> &flagUnderConstruction)
{
const Map *map = &gameState->map;
@ -718,18 +733,10 @@ void UIUrho3D::Update(float timeStep, uint32_t mouse_x, uint32_t mouse_y, uint32
UpdateThermometer();
UpdateNewBlockNotification(timeStep);
m_mining_checker.do_call([this, &w](){
uint32_t sync_percent = 0, mining_hash_rate = 0;
w->get_node_status(sync_percent, mining_hash_rate);
std::string str = std::to_string(sync_percent) + "% synced";
str += " (" + std::to_string(gameState->top_height + 1) + ")";
if (mining_hash_rate)
str += ", mining at " + std::to_string(mining_hash_rate) + " H/s";
nodeStatusWidget->SetText(str.c_str());
startMiningContainer->SetValue(gameState->playerState.has_wallet && mining_hash_rate == 0);
stopMiningContainer->SetValue(mining_hash_rate != 0);
return true;
});
if (update_mining)
UpdateMining(w);
else
m_mining_checker.do_call([this, &w](){ UpdateMining(w); return true; });
if (selectMaterial)
selectMaterial->SetFocus(WIDGET_FOCUS_REASON_UNKNOWN);
@ -1575,12 +1582,14 @@ void UIUrho3D::HandleStartMining(StringHash eventType, VariantMap& eventData)
{
VariantMap noEventData;
SendEvent(E_CRYPTOCITY_START_MINING, noEventData);
update_mining = true;
}
void UIUrho3D::HandleStopMining(StringHash eventType, VariantMap& eventData)
{
VariantMap noEventData;
SendEvent(E_CRYPTOCITY_STOP_MINING, noEventData);
update_mining = true;
}
void UIUrho3D::HandleAddBlock(StringHash eventType, VariantMap& eventData)

View File

@ -230,6 +230,7 @@ private:
void UpdateThermometer();
void UpdateBuildOverview(const boost::optional<std::tuple<uint32_t, std::vector<uint16_t>, std::vector<std::vector<uint8_t>>>> &flagUnderConstruction);
void UpdateNewBlockNotification(float timeStep);
void UpdateMining(const std::shared_ptr<GameWallet> &w);
void HandleLoadWallet(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData);
void HandleNoWallet(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData);
@ -481,6 +482,8 @@ private:
UITBWindow *new_block_notification;
Urho3D::Timer new_block_timer;
bool update_mining;
};
#endif