mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Rework profile deletion
- O(n) instead of O(4n) - Actually free the sacrificed profile's memory - Don't hop to profile 1 after deleting a later profile, to reduce the % of footguns/losing your place in the list.
This commit is contained in:
parent
c77f9fa558
commit
b0c9fccd2d
2 changed files with 32 additions and 15 deletions
|
|
@ -5518,8 +5518,8 @@ static void M_EraseProfileResponse(INT32 choice)
|
|||
F_StartIntro();
|
||||
M_ClearMenus(true);
|
||||
}
|
||||
else
|
||||
optionsmenu.eraseprofilen = 1;
|
||||
else if (optionsmenu.eraseprofilen > PR_GetNumProfiles()-1)
|
||||
optionsmenu.eraseprofilen--;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,34 +96,47 @@ profile_t* PR_GetProfile(INT32 num)
|
|||
|
||||
boolean PR_DeleteProfile(INT32 num)
|
||||
{
|
||||
UINT8 i, j;
|
||||
UINT8 i;
|
||||
profile_t* sacrifice;
|
||||
|
||||
if (num <= 0 || num > numprofiles)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
sacrifice = profilesList[num];
|
||||
|
||||
// If we're deleting inbetween profiles, move everything.
|
||||
if (num < numprofiles)
|
||||
{
|
||||
for (i = num; i < numprofiles-1; i++)
|
||||
{
|
||||
profilesList[i] = profilesList[i+1];
|
||||
}
|
||||
|
||||
// Make sure to move cv_lastprofile values as well
|
||||
for (j = 0; j < MAXSPLITSCREENPLAYERS; j++)
|
||||
// Make sure to move cv_lastprofile values as well!
|
||||
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
||||
{
|
||||
INT32 profileset = cv_lastprofile[i].value;
|
||||
|
||||
if (profileset < num)
|
||||
{
|
||||
if (cv_lastprofile[j].value == num)
|
||||
{
|
||||
// If we were on the deleted profile, default back to guest.
|
||||
CV_StealthSetValue(&cv_lastprofile[j], PROFILE_GUEST);
|
||||
}
|
||||
else if (cv_lastprofile[j].value == i+1)
|
||||
{
|
||||
// Otherwise, shift our lastprofile number down to match the new order.
|
||||
CV_StealthSetValue(&cv_lastprofile[j], cv_lastprofile[j].value-1);
|
||||
}
|
||||
// Not affected.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (profileset > num)
|
||||
{
|
||||
// Shift our lastprofile number down to match the new order.
|
||||
profileset--;
|
||||
}
|
||||
else
|
||||
{
|
||||
// There's no hope for it. If we were on the deleted profile, default back to guest.
|
||||
profileset = PROFILE_GUEST;
|
||||
}
|
||||
|
||||
CV_StealthSetValue(&cv_lastprofile[i], profileset);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -132,6 +145,10 @@ boolean PR_DeleteProfile(INT32 num)
|
|||
numprofiles--;
|
||||
|
||||
PR_SaveProfiles();
|
||||
|
||||
// Finally, clear up our memory!
|
||||
Z_Free(sacrifice);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue