Skip to content

Commit

Permalink
Fixed FinaleInterpreter stack popping problem which resulted in the g…
Browse files Browse the repository at this point in the history
…ame not returning to the expected state if a "local" script is above an "overlay" at the time.

Fixed FIPage background color and alpha not set when applying a Material for the first time by a FinaleInterpreter.
Clean up.
  • Loading branch information
danij-deng committed Jul 29, 2010
1 parent 5290525 commit 3b06917
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 80 deletions.
1 change: 1 addition & 0 deletions doomsday/engine/portable/include/fi_main.h
Expand Up @@ -73,6 +73,7 @@ void FIPage_RunTic(fi_page_t* page);
fi_object_t* FIPage_AddObject(fi_page_t* page, fi_object_t* obj);
fi_object_t* FIPage_RemoveObject(fi_page_t* page, fi_object_t* obj);
boolean FIPage_HasObject(fi_page_t* page, fi_object_t* obj);
struct material_s* FIPage_Background(fi_page_t* page);

void FIPage_SetBackground(fi_page_t* page, struct material_s* mat);
void FIPage_SetBackgroundColor(fi_page_t* page, float red, float green, float blue, int steps);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/finaleinterpreter.h
Expand Up @@ -57,9 +57,9 @@ typedef struct finaleinterpreter_t {
finale_mode_t mode;
struct finaleinterpreter_flags_s {
char stopped:1;
char can_skip:1;
char suspended:1;
char paused:1;
char can_skip:1;
char eat_events:1; // Script will eat all input events.
char show_menu:1;
} flags;
Expand Down
74 changes: 25 additions & 49 deletions doomsday/engine/portable/src/fi_main.c
Expand Up @@ -133,8 +133,7 @@ static fi_page_t* pagesRemove(fi_page_t* p)
}
else
{
Z_Free(pages);
pages = 0;
Z_Free(pages); pages = 0;
numPages = 0;
}
}
Expand Down Expand Up @@ -241,8 +240,7 @@ static fi_object_t* objectsRemove(fi_object_collection_t* c, fi_object_t* obj)
}
else
{
Z_Free(c->vector);
c->vector = 0;
Z_Free(c->vector); c->vector = 0;
c->num = 0;
}
}
Expand Down Expand Up @@ -367,33 +365,20 @@ static fi_state_t* stackPush(fi_scriptid_t id)

static boolean stackPop(void)
{
fi_state_t* s = stackTop();

if(!s)
{
#ifdef _DEBUG
Con_Printf("InFine: Attempt to pop empty stack\n");
#endif
return false;
}

P_DestroyFinaleInterpreter(s->interpreter);

// Should we go back to NULL?
if(finaleStackSize > 1)
{ // Return to previous state.
finaleStack = Z_Realloc(finaleStack, sizeof(*finaleStack) * --finaleStackSize, PU_STATIC);
s = stackTop();
s->flags.active = true;
FinaleInterpreter_Resume(s->interpreter);
}
else
if(!(finaleStackSize > 1))
{
Z_Free(finaleStack); finaleStack = 0;
finaleStackSize = 0;
return 0;
}

return finaleStackSize != 0;
// Return to previous state.
finaleStack = Z_Realloc(finaleStack, sizeof(*finaleStack) * --finaleStackSize, PU_STATIC);
{fi_state_t* s = stackTop();
s->flags.active = true;
FinaleInterpreter_Resume(s->interpreter);}
return true;
}

/**
Expand All @@ -403,23 +388,7 @@ static void scriptTerminate(fi_state_t* s)
{
if(!s->flags.active)
return;
if(!FinaleInterpreter_CanSkip(s->interpreter))
return;

// Should we go back to NULL?
if(finaleStackSize > 1)
{ // Return to previous state.
finaleStack = Z_Realloc(finaleStack, sizeof(*finaleStack) * --finaleStackSize, PU_STATIC);
{fi_state_t* s2 = stackTop();
s2->flags.active = true;
FinaleInterpreter_Resume(s2->interpreter);}
}
else
{
Z_Free(finaleStack); finaleStack = 0;
finaleStackSize = 0;
}

s->flags.active = false;
P_DestroyFinaleInterpreter(s->interpreter);
}

Expand All @@ -446,7 +415,11 @@ static void doReset(void)
return;

// Pop all the states.
while(stackPop());
while((s = stackTop()))
{
scriptTerminate(s);
stackPop();
}
}
}

Expand Down Expand Up @@ -596,8 +569,7 @@ void P_DestroyText(fidata_text_t* text)
assert(text);
if(text->text)
{ // Free the memory allocated for the text string.
Z_Free(text->text);
text->text = NULL;
Z_Free(text->text); text->text = 0;
}
// Call parent destructor.
FIObject_Destructor((fi_object_t*)text);
Expand Down Expand Up @@ -780,8 +752,8 @@ void FI_ScriptTerminate(void)
}
if((s = stackTop()) && s->flags.active)
{
FinaleInterpreter_AllowSkip(s->interpreter, true);
scriptTerminate(s);
stackPop();
}
}

Expand Down Expand Up @@ -897,6 +869,12 @@ fi_object_t* FIPage_RemoveObject(fi_page_t* p, fi_object_t* obj)
return obj;
}

material_t* FIPage_Background(fi_page_t* p)
{
if(!p) Con_Error("FIPage_Background: Invalid page.");
return p->bgMaterial;
}

void FIPage_SetBackground(fi_page_t* p, material_t* mat)
{
if(!p) Con_Error("FIPage_SetBackground: Invalid page.");
Expand Down Expand Up @@ -970,10 +948,8 @@ void FI_Ticker(timespan_t ticLength)

if(FinaleInterpreter_RunTic(s->interpreter))
{ // The script has ended!
if(!s->flags.active)
return;

scriptTerminate(s);
stackPop();
}
}}
}
Expand Down
60 changes: 30 additions & 30 deletions doomsday/engine/portable/src/finaleinterpreter.c
Expand Up @@ -724,20 +724,6 @@ static fi_object_t* getObject(finaleinterpreter_t* fi, fi_obtype_e type, const c
}
}

static void demoEnds(finaleinterpreter_t* fi)
{
if(!fi->flags.suspended)
return;

// Restore the InFine state.
fi->flags.suspended = false;
if(fi->cmdExecuted)
{
FIPage_MakeVisible(fi->_page, true);
}
gx.FI_DemoEnds();
}

static void clearEventHandlers(finaleinterpreter_t* fi)
{
if(fi->numEventHandlers)
Expand Down Expand Up @@ -778,7 +764,6 @@ static fi_handler_t* findEventHandler(finaleinterpreter_t* fi, const ddevent_t*

static fi_handler_t* createEventHandler(finaleinterpreter_t* fi, const ddevent_t* ev, const char* marker)
{
// First, try to find an existing handler.
fi_handler_t* h;
fi->eventHandlers = Z_Realloc(fi->eventHandlers, sizeof(*h) * ++fi->numEventHandlers, PU_STATIC);
h = &fi->eventHandlers[fi->numEventHandlers-1];
Expand Down Expand Up @@ -890,10 +875,10 @@ void FinaleInterpreter_LoadScript(finaleinterpreter_t* fi, finale_mode_t mode,
memcpy(fi->script, script, size);
fi->script[size] = '\0';
fi->cp = fi->script; // Init cursor.
fi->flags.show_menu = true; // Enabled by default.
fi->flags.suspended = false;
fi->flags.can_skip = true; // By default skipping is enabled.
fi->flags.paused = false;
fi->flags.show_menu = true; // Enabled by default.
fi->flags.can_skip = true; // By default skipping is enabled.

fi->cmdExecuted = false; // Nothing is drawn until a cmd has been executed.
fi->skipping = false;
Expand Down Expand Up @@ -949,15 +934,23 @@ void FinaleInterpreter_ReleaseScript(finaleinterpreter_t* fi)
void FinaleInterpreter_Resume(finaleinterpreter_t* fi)
{
assert(fi);
if(!fi->flags.suspended)
return;
fi->flags.suspended = false;
// Do we need to unhide any pages?
if(!fi->cmdExecuted || fi->flags.suspended)
return; // No.
FIPage_MakeVisible(fi->_page, true);
if(fi->cmdExecuted)
{
FIPage_MakeVisible(fi->_page, true);
}
}

void FinaleInterpreter_Suspend(finaleinterpreter_t* fi)
{
assert(fi);
if(fi->flags.suspended)
return;
fi->flags.suspended = true;
// While suspended, all pages will be hidden.
FIPage_MakeVisible(fi->_page, false);
}

Expand Down Expand Up @@ -1109,7 +1102,7 @@ int FinaleInterpreter_Responder(finaleinterpreter_t* fi, ddevent_t* ev)
return false;

if(fi->flags.suspended)
return false; // Busy playing a demo.
return false;

// During the first ~second disallow all events/skipping.
if(fi->timer < 20)
Expand Down Expand Up @@ -1157,6 +1150,14 @@ void FI_SetClientsideDefaultState(void* data)
memcpy(&defaultState, data, sizeof(FINALE_SCRIPT_EXTRADATA_SIZE));
}

static void changePageBackground(fi_page_t* p, material_t* mat)
{
// If the page does not yet have a background set we must setup the color+alpha.
if(mat && !FIPage_Background(p))
FIPage_SetBackgroundColorAndAlpha(p, 1, 1, 1, 1, 0);
FIPage_SetBackground(p, mat);
}

DEFFC(Do)
{
// This command is called even when (cond)skipping.
Expand All @@ -1176,17 +1177,17 @@ DEFFC(End)

DEFFC(BGFlat)
{
FIPage_SetBackground(fi->_page, Materials_ToMaterial(Materials_CheckNumForName(ops[0].data.cstring, MN_FLATS)));
changePageBackground(fi->_page, Materials_ToMaterial(Materials_CheckNumForName(ops[0].data.cstring, MN_FLATS)));
}

DEFFC(BGTexture)
{
FIPage_SetBackground(fi->_page, Materials_ToMaterial(Materials_CheckNumForName(ops[0].data.cstring, MN_TEXTURES)));
changePageBackground(fi->_page, Materials_ToMaterial(Materials_CheckNumForName(ops[0].data.cstring, MN_TEXTURES)));
}

DEFFC(NoBGMaterial)
{
FIPage_SetBackground(fi->_page, NULL);
changePageBackground(fi->_page, 0);
}

DEFFC(InTime)
Expand Down Expand Up @@ -2030,15 +2031,14 @@ DEFFC(TextScale)

DEFFC(PlayDemo)
{
// Mark the current state as suspended, so we know to resume it when the demo ends.
fi->flags.suspended = true;
FIPage_MakeVisible(fi->_page, false);
// While playing a demo we suspend command interpretation.
FinaleInterpreter_Suspend(fi);

// The only argument is the demo file name.
// Start playing the demo.
// Start the demo.
if(!Con_Executef(CMDS_DDAY, true, "playdemo \"%s\"", ops[0].data.cstring))
{ // Demo playback failed. Here we go again...
demoEnds(fi);
FinaleInterpreter_Resume(fi);
gx.FI_DemoEnds();
}
}

Expand Down

0 comments on commit 3b06917

Please sign in to comment.