Skip to content

Commit

Permalink
Use ModeQueue and ModeImmediate instead of maybeDeleteTemplateFromPro…
Browse files Browse the repository at this point in the history
…duction and reallyDeleteTemplateFromProduction.
  • Loading branch information
Cyp committed Oct 22, 2010
1 parent fcdba75 commit d8ec229
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/design.c
Expand Up @@ -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 */
Expand Down Expand Up @@ -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();
}
Expand Down
24 changes: 7 additions & 17 deletions src/droid.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -4625,31 +4625,21 @@ 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;
}
}
}
}
}
}

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.
//
Expand Down
3 changes: 1 addition & 2 deletions src/droid.h
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/multiplay.c
Expand Up @@ -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.");
}

Expand Down

0 comments on commit d8ec229

Please sign in to comment.