1
0
Fork 0

DBG: simplify scriptinternalcmd and make scriptload a blocking call

This commit is contained in:
mrexodia 2017-03-12 04:45:18 +01:00
parent 595244bb29
commit 0b70d9b391
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
1 changed files with 35 additions and 37 deletions

View File

@ -386,44 +386,39 @@ static bool scriptinternalbranch(SCRIPTBRANCHTYPE type) //determine if we should
static bool scriptinternalcmd()
{
bool bContinue = true;
try // failed when scriptIp is bad
{
LINEMAPENTRY cur = linemap.at(scriptIp - 1);
if(cur.type == linecommand)
{
switch(scriptinternalcmdexec(cur.u.command))
{
case STATUS_CONTINUE:
break;
case STATUS_ERROR:
bContinue = false;
GuiScriptError(scriptIp, GuiTranslateText(QT_TRANSLATE_NOOP("DBG", "Error executing command!")));
break;
case STATUS_EXIT:
bContinue = false;
scriptIp = scriptinternalstep(0);
GuiScriptSetIp(scriptIp);
break;
case STATUS_PAUSE:
bContinue = false; //stop running the script
scriptIp = scriptinternalstep(scriptIp);
GuiScriptSetIp(scriptIp);
break;
}
}
else if(cur.type == linebranch)
{
if(cur.u.branch.type == scriptcall) //calls have a special meaning
scriptstack.push_back(scriptIp);
if(scriptinternalbranch(cur.u.branch.type))
scriptIp = scriptlabelfind(cur.u.branch.branchlabel);
}
return bContinue;
}
catch(std::out_of_range &)
{
if(size_t(scriptIp - 1) >= linemap.size())
return false;
LINEMAPENTRY cur = linemap.at(scriptIp - 1);
if(cur.type == linecommand)
{
switch(scriptinternalcmdexec(cur.u.command))
{
case STATUS_CONTINUE:
break;
case STATUS_ERROR:
bContinue = false;
GuiScriptError(scriptIp, GuiTranslateText(QT_TRANSLATE_NOOP("DBG", "Error executing command!")));
break;
case STATUS_EXIT:
bContinue = false;
scriptIp = scriptinternalstep(0);
GuiScriptSetIp(scriptIp);
break;
case STATUS_PAUSE:
bContinue = false; //stop running the script
scriptIp = scriptinternalstep(scriptIp);
GuiScriptSetIp(scriptIp);
break;
}
}
else if(cur.type == linebranch)
{
if(cur.u.branch.type == scriptcall) //calls have a special meaning
scriptstack.push_back(scriptIp);
if(scriptinternalbranch(cur.u.branch.type))
scriptIp = scriptlabelfind(cur.u.branch.branchlabel);
}
return bContinue;
}
DWORD WINAPI scriptRunSync(void* arg)
@ -500,7 +495,10 @@ void scriptload(const char* filename)
{
static char filename_[MAX_PATH] = "";
strcpy_s(filename_, filename);
CloseHandle(CreateThread(0, 0, scriptLoadSync, filename_, 0, 0));
auto hThread = CreateThread(nullptr, 0, scriptLoadSync, filename_, 0, nullptr);
while(WaitForSingleObject(hThread, 100) == WAIT_TIMEOUT)
GuiProcessEvents();
CloseHandle(hThread);
}
void scriptunload()