From: Mario Date: Thu, 3 Dec 2020 09:31:43 +0000 (+1000) Subject: Don't attempt to render the itemstats panel at all if there is no inventory entity... X-Git-Tag: xonotic-v0.8.5~588^2~8 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c9d5ab52170d46da02286bf2d57b55cb05515f63;p=xonotic%2Fxonotic-data.pk3dir.git Don't attempt to render the itemstats panel at all if there is no inventory entity on the client, clear the inventory storage entity when detaching PlayerState, fixes inventory mismatch when switching between observer and a spectated player --- diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index a9f1a67bc..ad923c5dd 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -1667,7 +1667,7 @@ bool Scoreboard_ItemStats_WouldDraw(float ypos) { if (MUTATOR_CALLHOOK(DrawScoreboardItemStats)) return false; - if (!autocvar_hud_panel_scoreboard_itemstats || warmup_stage || ypos > 0.91 * vid_conheight) + if (!autocvar_hud_panel_scoreboard_itemstats || !g_inventory || warmup_stage || ypos > 0.91 * vid_conheight) return false; if (time < scoreboard_time + autocvar_hud_panel_scoreboard_itemstats_showdelay diff --git a/qcsrc/common/items/inventory.qh b/qcsrc/common/items/inventory.qh index 87c85198d..3ffa6c003 100644 --- a/qcsrc/common/items/inventory.qh +++ b/qcsrc/common/items/inventory.qh @@ -38,10 +38,17 @@ STATIC_INIT(Inventory) #ifdef CSQC Inventory g_inventory; +void Inventory_remove(entity this) +{ + if(g_inventory == this) + g_inventory = NULL; +} + NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew) { make_pure(this); g_inventory = this; + this.entremove = Inventory_remove; const int majorBits = Readbits(Inventory_groups_major); for (int i = 0; i < Inventory_groups_major; ++i) { if (!(majorBits & BIT(i))) { @@ -137,5 +144,13 @@ void Inventory_delete(entity e) { delete(e.inventory); } void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; } void InventoryStorage_attach(entity e) { e.inventory_store = NEW(Inventory); e.inventory_store.drawonlytoclient = e; } -void InventoryStorage_detach(entity e) { delete(e.inventory_store); } +void InventoryStorage_delete(entity e) { delete(e.inventory_store); } +void InventoryStorage_clear(entity e) +{ + // we don't need to network the changes, that is done when the inventory is detached + FOREACH(Items, true, { + .int fld = inv_items[it.m_id]; + e.inventory_store.(fld) = 0; + }); +} #endif diff --git a/qcsrc/common/state.qc b/qcsrc/common/state.qc index 7a5979e2b..406003efc 100644 --- a/qcsrc/common/state.qc +++ b/qcsrc/common/state.qc @@ -5,7 +5,8 @@ void Inventory_new(PlayerState this); void Inventory_delete(entity this); void InventoryStorage_attach(PlayerState this); -void InventoryStorage_detach(PlayerState this); +void InventoryStorage_delete(PlayerState this); +void InventoryStorage_clear(PlayerState this); void PlayerState_attach(entity this) { @@ -22,6 +23,7 @@ void PlayerState_detach(entity this) PlayerState ps = PS(this); if (!ps) return; // initial connect PS(this) = NULL; + InventoryStorage_clear(this); if (ps.m_client != this) return; // don't own state, spectator ps.ps_push(ps, this); @@ -74,7 +76,7 @@ void ClientState_detach(entity this) W_HitPlotClose(this); ClientData_Detach(this); entcs_detach(this); - InventoryStorage_detach(this); + InventoryStorage_delete(this); delete(CS(this)); this._cs = NULL;