Use ModeQueue and ModeImmediate instead of maybeDeleteTemplateFromProduction and reallyDeleteTemplateFromProduction.

master
Cyp 2010-10-22 18:38:58 +02:00
parent fcdba754c4
commit d8ec229ec6
4 changed files with 12 additions and 23 deletions

View File

@ -4121,7 +4121,7 @@ void intProcessDesign(UDWORD id)
// Delete the template. // Delete the template.
//before deleting the template, need to make sure not being used in production //before deleting the template, need to make sure not being used in production
deleteTemplateFromProduction(psTempl, (UBYTE)selectedPlayer); deleteTemplateFromProduction(psTempl, selectedPlayer, ModeQueue);
free(psTempl); free(psTempl);
/* get previous template and set as current */ /* get previous template and set as current */
@ -4653,7 +4653,7 @@ static BOOL saveTemplate(void)
newTemplate = false; newTemplate = false;
/*ANY change to the template affect the production - even if the /*ANY change to the template affect the production - even if the
template is changed and then changed back again!*/ template is changed and then changed back again!*/
deleteTemplateFromProduction(psTempl, (UBYTE)selectedPlayer); deleteTemplateFromProduction(psTempl, selectedPlayer, ModeQueue);
SendDestroyTemplate(psTempl); SendDestroyTemplate(psTempl);
sCurrDesign.multiPlayerID = generateNewObjectId(); sCurrDesign.multiPlayerID = generateNewObjectId();
} }

View File

@ -4539,7 +4539,7 @@ BOOL checkValidWeaponForProp(DROID_TEMPLATE *psTemplate)
} }
/*called when a Template is deleted in the Design screen*/ /*called when a Template is deleted in the Design screen*/
static void maybeDeleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE player, bool really) void deleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE player, QUEUE_MODE mode)
{ {
STRUCTURE *psStruct; STRUCTURE *psStruct;
UDWORD inc, i; UDWORD inc, i;
@ -4588,7 +4588,7 @@ static void maybeDeleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE
// check not being built in the factory for the template player // check not being built in the factory for the template player
if (psTemplate->multiPlayerID == ((DROID_TEMPLATE *)psFactory->psSubject)->multiPlayerID) if (psTemplate->multiPlayerID == ((DROID_TEMPLATE *)psFactory->psSubject)->multiPlayerID)
{ {
if (really) if (mode == ModeImmediate)
{ {
syncDebugStructure(psStruct, '<'); syncDebugStructure(psStruct, '<');
syncDebug("Clearing production"); syncDebug("Clearing production");
@ -4625,14 +4625,14 @@ static void maybeDeleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE
} }
else else
{ {
DROID_TEMPLATE *template = (DROID_TEMPLATE *)malloc(sizeof(DROID_TEMPLATE)); DROID_TEMPLATE *oldTemplate = (DROID_TEMPLATE *)malloc(sizeof(DROID_TEMPLATE));
debug(LOG_ERROR, "TODO: Fix this memory leak when deleting templates."); debug(LOG_ERROR, "TODO: Fix this memory leak when deleting templates.");
*template = *(DROID_TEMPLATE *)psFactory->psSubject; *oldTemplate = *(DROID_TEMPLATE *)psFactory->psSubject;
template->pName = NULL; oldTemplate->pName = NULL;
template->psNext = NULL; oldTemplate->psNext = NULL;
psFactory->psSubject = (BASE_STATS *)template; psFactory->psSubject = (BASE_STATS *)oldTemplate;
} }
} }
} }
@ -4640,16 +4640,6 @@ static void maybeDeleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE
} }
} }
void deleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE player)
{
maybeDeleteTemplateFromProduction(psTemplate, player, false);
}
void reallyDeleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE player)
{
maybeDeleteTemplateFromProduction(psTemplate, player, true);
}
// Select a droid and do any necessary housekeeping. // Select a droid and do any necessary housekeeping.
// //

View File

@ -373,8 +373,7 @@ extern BOOL checkValidWeaponForProp(DROID_TEMPLATE *psTemplate);
extern const char *getDroidNameForRank(UDWORD rank); extern const char *getDroidNameForRank(UDWORD rank);
/*called when a Template is deleted in the Design screen*/ /*called when a Template is deleted in the Design screen*/
extern void deleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE player); extern void deleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE player, QUEUE_MODE mode);
extern void reallyDeleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE player);
// Select a droid and do any necessary housekeeping. // Select a droid and do any necessary housekeeping.
extern void SelectDroid(DROID *psDroid); extern void SelectDroid(DROID *psDroid);

View File

@ -1589,14 +1589,14 @@ static BOOL recvDestroyTemplate(NETQUEUE queue)
// Delete the template. // Delete the template.
//before deleting the template, need to make sure not being used in production //before deleting the template, need to make sure not being used in production
reallyDeleteTemplateFromProduction(psTempl, player); deleteTemplateFromProduction(psTempl, player, ModeImmediate);
free(psTempl); free(psTempl);
} }
else else
{ {
DROID_TEMPLATE aaargh; DROID_TEMPLATE aaargh;
aaargh.multiPlayerID = templateID; aaargh.multiPlayerID = templateID;
reallyDeleteTemplateFromProduction(&aaargh, player); deleteTemplateFromProduction(&aaargh, player, ModeImmediate);
debug(LOG_ERROR, "TODO: Rewrite the whole interface, so it's possible to change the code without spaghetti dependencies causing problems everywhere, and without resorting to ugly hacks."); debug(LOG_ERROR, "TODO: Rewrite the whole interface, so it's possible to change the code without spaghetti dependencies causing problems everywhere, and without resorting to ugly hacks.");
} }