From d8ec229ec6f31b88f8aed3c652cf01d535217b29 Mon Sep 17 00:00:00 2001 From: Cyp Date: Fri, 22 Oct 2010 18:38:58 +0200 Subject: [PATCH] Use ModeQueue and ModeImmediate instead of maybeDeleteTemplateFromProduction and reallyDeleteTemplateFromProduction. --- src/design.c | 4 ++-- src/droid.c | 24 +++++++----------------- src/droid.h | 3 +-- src/multiplay.c | 4 ++-- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/design.c b/src/design.c index 322e0811a..cd4bc8f7c 100644 --- a/src/design.c +++ b/src/design.c @@ -4121,7 +4121,7 @@ void intProcessDesign(UDWORD id) // Delete the template. //before deleting the template, need to make sure not being used in production - deleteTemplateFromProduction(psTempl, (UBYTE)selectedPlayer); + deleteTemplateFromProduction(psTempl, selectedPlayer, ModeQueue); free(psTempl); /* get previous template and set as current */ @@ -4653,7 +4653,7 @@ static BOOL saveTemplate(void) newTemplate = false; /*ANY change to the template affect the production - even if the template is changed and then changed back again!*/ - deleteTemplateFromProduction(psTempl, (UBYTE)selectedPlayer); + deleteTemplateFromProduction(psTempl, selectedPlayer, ModeQueue); SendDestroyTemplate(psTempl); sCurrDesign.multiPlayerID = generateNewObjectId(); } diff --git a/src/droid.c b/src/droid.c index cc78010e5..8cf57313d 100644 --- a/src/droid.c +++ b/src/droid.c @@ -4539,7 +4539,7 @@ BOOL checkValidWeaponForProp(DROID_TEMPLATE *psTemplate) } /*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; 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 if (psTemplate->multiPlayerID == ((DROID_TEMPLATE *)psFactory->psSubject)->multiPlayerID) { - if (really) + if (mode == ModeImmediate) { syncDebugStructure(psStruct, '<'); syncDebug("Clearing production"); @@ -4625,14 +4625,14 @@ static void maybeDeleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE } 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."); - *template = *(DROID_TEMPLATE *)psFactory->psSubject; - template->pName = NULL; - template->psNext = NULL; + *oldTemplate = *(DROID_TEMPLATE *)psFactory->psSubject; + oldTemplate->pName = 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. // diff --git a/src/droid.h b/src/droid.h index 60463c4a4..1e96f8c49 100644 --- a/src/droid.h +++ b/src/droid.h @@ -373,8 +373,7 @@ extern BOOL checkValidWeaponForProp(DROID_TEMPLATE *psTemplate); extern const char *getDroidNameForRank(UDWORD rank); /*called when a Template is deleted in the Design screen*/ -extern void deleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE player); -extern void reallyDeleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE player); +extern void deleteTemplateFromProduction(DROID_TEMPLATE *psTemplate, UBYTE player, QUEUE_MODE mode); // Select a droid and do any necessary housekeeping. extern void SelectDroid(DROID *psDroid); diff --git a/src/multiplay.c b/src/multiplay.c index 193132d87..a1d1e251e 100644 --- a/src/multiplay.c +++ b/src/multiplay.c @@ -1589,14 +1589,14 @@ static BOOL recvDestroyTemplate(NETQUEUE queue) // Delete the template. //before deleting the template, need to make sure not being used in production - reallyDeleteTemplateFromProduction(psTempl, player); + deleteTemplateFromProduction(psTempl, player, ModeImmediate); free(psTempl); } else { DROID_TEMPLATE aaargh; 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."); }