From 0037e5206ea545ea8a63772d343b5956f9bd1795 Mon Sep 17 00:00:00 2001 From: Thomas Otto Date: Sat, 20 Apr 2024 16:25:13 +0200 Subject: [PATCH 1/2] Fix a vexing parse --- Descent3/hud.h | 3 +++ Descent3/multisafe.cpp | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Descent3/hud.h b/Descent3/hud.h index ecf13d97..123cf3db 100644 --- a/Descent3/hud.h +++ b/Descent3/hud.h @@ -542,6 +542,9 @@ void FreeHUDItem(int item); // Updates the customtext2 item, if there is one void UpdateCustomtext2HUDItem(char *text); +// Returns the item number if there's a customtext2 item, else -1 +int FindCustomtext2HUDItem(); + // resets hud void ResetHUD(); diff --git a/Descent3/multisafe.cpp b/Descent3/multisafe.cpp index 04997e5e..48139e23 100644 --- a/Descent3/multisafe.cpp +++ b/Descent3/multisafe.cpp @@ -2099,7 +2099,6 @@ void msafe_CallFunction(ubyte type, msafe_struct *mstruct) { break; } case MSAFE_MISC_UPDATE_HUD_ITEM: - int FindCustomtext2HUDItem(); // If item not added yet, add it now if (FindCustomtext2HUDItem() == -1) { tHUDItem huditem; From bd0122e5afe750efe8868ff3716bdf816e3df34e Mon Sep 17 00:00:00 2001 From: Thomas Otto Date: Sat, 20 Apr 2024 16:20:45 +0200 Subject: [PATCH 2/2] Use PInfo* instead of void* This avoids a lot of casts back to this (and ever only this) type. --- netgames/dmfc/dmfcbase.cpp | 12 ++++++------ netgames/dmfc/dmfcclient.cpp | 4 ++-- netgames/dmfc/dmfcprecord.cpp | 13 ++++++------- netgames/includes/DMFC.h | 6 ++++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/netgames/dmfc/dmfcbase.cpp b/netgames/dmfc/dmfcbase.cpp index bf4f970c..057bd844 100644 --- a/netgames/dmfc/dmfcbase.cpp +++ b/netgames/dmfc/dmfcbase.cpp @@ -2168,7 +2168,7 @@ PInfo *DMFCBase::FindPInfo(int pnum) { player_record *pr = GetPlayerRecordByPnum(pnum); if (!pr) return NULL; - return (PInfo *)pr->pinfo; + return pr->pinfo; } // DMFCBase::UpdatePInfo @@ -2226,7 +2226,7 @@ void DMFCBase::ResetPInfo(void) { for (int i = 0; i < MAX_PLAYER_RECORDS; i++) { player_record *pr = GetPlayerRecord(i); if (pr && pr->pinfo) { - ((PInfo *)pr->pinfo)->ResetAll(); + pr->pinfo->ResetAll(); } } } @@ -2344,7 +2344,7 @@ bool DMFCBase::FindPInfoStatFirst(int slot, tPInfoStat *stat) { if (!pr || pr->state == STATE_EMPTY || !pr->pinfo) return false; - killer = ((PInfo *)pr->pinfo)->GetFirstKiller(); + killer = pr->pinfo->GetFirstKiller(); victim = NULL; if (!killer) { @@ -2412,7 +2412,7 @@ bool DMFCBase::FindPInfoStatNext(tPInfoStat *stat) { if (!pr || pr->state == STATE_EMPTY || !pr->pinfo) return false; - killer = ((PInfo *)pr->pinfo)->GetNextKiller(); + killer = pr->pinfo->GetNextKiller(); victim = NULL; if (!killer) { @@ -2446,7 +2446,7 @@ bool DMFCBase::FindPInfoStatNext(tPInfoStat *stat) { deaths = 0; dpr = GetPlayerRecord(killer->slot); if (dpr && dpr->state != STATE_EMPTY && dpr->pinfo) { - victim = ((PInfo *)dpr->pinfo)->GetKillerInfo(slot); + victim = dpr->pinfo->GetKillerInfo(slot); } if (victim) @@ -3379,7 +3379,7 @@ void DMFCBase::CheckPInfo() { tPKillerInfo *node; ASSERT(pr->pinfo != NULL); - node = ((PInfo *)pr->pinfo)->GetFirstKiller(); + node = pr->pinfo->GetFirstKiller(); while (node) { ASSERT(node->slot >= 0 && node->slot < 64); diff --git a/netgames/dmfc/dmfcclient.cpp b/netgames/dmfc/dmfcclient.cpp index 221f1e83..ffe5f708 100644 --- a/netgames/dmfc/dmfcclient.cpp +++ b/netgames/dmfc/dmfcclient.cpp @@ -608,7 +608,7 @@ void DMFCBase::OnPlayerEntersObserver(int pnum, object *piggy) { mprintf((0, "Player %d entering observermode %s\n", pnum, (piggy) ? "Piggyback" : "Roam")); player_record *pr = PRec_GetPRecordByPnum(pnum); if (pr && pr->state == STATE_INGAME) { - PInfo *pi = (PInfo *)pr->pinfo; + PInfo *pi = pr->pinfo; ASSERT(pi != NULL); pi->EnterObserverMode(); } else { @@ -623,7 +623,7 @@ void DMFCBase::OnPlayerExitsObserver(int pnum) { mprintf((0, "Player %d leaving observer mode\n", pnum)); player_record *pr = PRec_GetPRecordByPnum(pnum); if (pr && pr->state == STATE_INGAME) { - PInfo *pi = (PInfo *)pr->pinfo; + PInfo *pi = pr->pinfo; ASSERT(pi != NULL); pi->ExitObserverMode(); } else { diff --git a/netgames/dmfc/dmfcprecord.cpp b/netgames/dmfc/dmfcprecord.cpp index c2ee2f26..9e5ecb4f 100644 --- a/netgames/dmfc/dmfcprecord.cpp +++ b/netgames/dmfc/dmfcprecord.cpp @@ -295,7 +295,7 @@ int PRec_GetFreeSlot(void) { // go through all the records and remove this guy as a victim for (int p = 0; p < MAX_PLAYER_RECORDS; p++) { if ((p != old_player) && (Player_records[p].pinfo)) { - ((PInfo *)Player_records[p].pinfo)->RemoveKiller(old_player); + Player_records[p].pinfo->RemoveKiller(old_player); } } @@ -417,7 +417,7 @@ void PRec_LevelReset(void) { stat->deaths[DSTAT_LEVEL] = 0; stat->suicides[DSTAT_LEVEL] = 0; if (Player_records[i].pinfo) - ((PInfo *)Player_records[i].pinfo)->ResetAll(); + Player_records[i].pinfo->ResetAll(); } } @@ -488,7 +488,7 @@ void PRec_SendPRecToPlayer(int pnum) { callsignlen = strlen(Player_records[i].callsign); if (Player_records[i].pinfo) - pinfo_size = ((PInfo *)Player_records[i].pinfo)->GetSizeOfData(); + pinfo_size = Player_records[i].pinfo->GetSizeOfData(); else pinfo_size = 0; @@ -540,7 +540,7 @@ void PRec_SendPRecToPlayer(int pnum) { // PInfo stuff MultiAddInt(pinfo_size, data, &count); if (pinfo_size > 0) { - ((PInfo *)Player_records[i].pinfo)->PackData(&data[count]); + Player_records[i].pinfo->PackData(&data[count]); count += pinfo_size; } @@ -610,7 +610,6 @@ void PRec_ReceivePRecFromServer(ubyte *data) { if (pr->pinfo) { delete pr->pinfo; - pr->pinfo = NULL; } pr->pinfo = new PInfo(slot); @@ -618,11 +617,11 @@ void PRec_ReceivePRecFromServer(ubyte *data) { pinfo_size = MultiGetInt(data, &count); if (pinfo_size > 0) { if (pr->pinfo) - ((PInfo *)pr->pinfo)->UnpackData(&data[count], pinfo_size); + pr->pinfo->UnpackData(&data[count], pinfo_size); count += pinfo_size; } else { if (pr->pinfo) - ((PInfo *)pr->pinfo)->ResetAll(); + pr->pinfo->ResetAll(); } if (pr->pnum != 255) { diff --git a/netgames/includes/DMFC.h b/netgames/includes/DMFC.h index ce88762b..0e0c7b02 100644 --- a/netgames/includes/DMFC.h +++ b/netgames/includes/DMFC.h @@ -569,6 +569,8 @@ typedef struct { int kills[2], deaths[2], suicides[2]; } t_dstat; +struct PInfo; + typedef struct { slot_state state; // state of this slot char callsign[MAX_CALLSIGN_SIZE]; // Player's callsign @@ -584,8 +586,8 @@ typedef struct { void *user_info; // Multiplayer Mod user defined struct pointer int user_info_size; // Size of user_info; - sbyte team; // The player's team (for when they reconnect) - void *pinfo; // Pointer to player info (who killed whom) + sbyte team; // The player's team (for when they reconnect) + PInfo *pinfo; // Pointer to player info (who killed whom) } player_record; #define MIF_INCLUDENONE \