1014 lines
34 KiB
C++
1014 lines
34 KiB
C++
#include <windows.h>
|
|
#include <process.h>
|
|
#include "SCENE.H"
|
|
|
|
//#pragma optimize("",off)
|
|
static WORLD *pBaseWorld = NULL;
|
|
extern void DRawTEXT_Soft(u8 *pTEXT,u32 *pBase,u32 X, u32 Y, s32 Pitch , u32 Height , u32 Color , u32 X2 , u32 Y2);
|
|
#define LUA_HOOKMASK (LUA_MASKLINE|LUA_MASKCALL|LUA_MASKRET|(1 << LUA_HOOKTAILRET)|(1 << LUA_HOOKCOUNT))
|
|
void LDRS_HOOK(lua_State *L, lua_Debug *ar);
|
|
static s32 DClicDetection;
|
|
|
|
|
|
void AddLuaFileInLDS(char *SourceFile,void *USRP)
|
|
{
|
|
struct LLUA_DBG_STATE_* pLDS = (struct LLUA_DBG_STATE_*)USRP;
|
|
UnicID ID;
|
|
if (pLDS->FileNameDicos.IsExist(SourceFile) == -1)
|
|
{
|
|
strcpy(pLDS->AllScriptFileName[pLDS->MaxFile],SourceFile);
|
|
strlwr(pLDS->AllScriptFileName[pLDS->MaxFile]);
|
|
pLDS->FileNameDicos.GetUnic(&ID,(SourceFile));
|
|
pLDS->FileNameDicos.mpst_Dico[ID].AssociatedValue = pLDS->MaxFile;
|
|
|
|
if (pLDS->FileNameDicos.IsExist(SourceFile) != -1)
|
|
{
|
|
pLDS->MaxFile++;
|
|
}
|
|
}
|
|
}
|
|
void CreatePlds(WORLD *psc)
|
|
{
|
|
if (!psc->pLDS)
|
|
{
|
|
psc->pLDS = (LLUA_DBG_STATE*)CC_malloc(sizeof(LLUA_DBG_STATE));
|
|
memset(psc->pLDS,0,sizeof(LLUA_DBG_STATE));
|
|
|
|
pBaseWorld = psc;
|
|
|
|
lua_sethook(psc->luaScriptTable[psc->currentScript], LDRS_HOOK, LUA_HOOKMASK, 1);
|
|
psc->pLDS->FileNameDicos.Init();
|
|
for (int Counter = 0 ; Counter < psc->currentScript + 1; Counter++)
|
|
AddLuaFileInLDS((char *)psc->ScriptNameStack[Counter], (void*)psc->pLDS);
|
|
psc->luaLoaddedFilesDICO.EnumWords(AddLuaFileInLDS,(void*)psc->pLDS);
|
|
|
|
|
|
//
|
|
//strcpy(pLDS->AllScriptFileName[pLDS->CurrentFile],ScriptNameStack[currentScript]);
|
|
psc->pLDS->LastLineNumber = -1;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void APP_BreakPoint(WORLD *psc, lua_State *L)
|
|
{
|
|
if ((psc->SkipFunctions & SKIP_NODEBUG) && (psc->pLDS))
|
|
{
|
|
psc->pLDS->DeubgTraceMode = 1;
|
|
return;
|
|
}
|
|
psc->SkipFunctions |= SKIP_NODEBUG;
|
|
psc->DI->LayerOperation(0,6,1,0.0f,0.0f);
|
|
CreatePlds(psc);
|
|
psc->DI->LayerOperation(20,6,0xffffffff,0.0f,0.0f); // Restore current image
|
|
if (psc->pLDS) psc->pLDS->DeubgTraceMode = 1;
|
|
psc->LUA_DEBUG();
|
|
psc->DI->LayerOperation(20,6,0xffffffff,0.0f,0.0f); // Restore current image
|
|
}
|
|
|
|
void WORLD::DRawTEXT_BackFull(u8 *pTEXT,u8 *pTEXTHDR,s32 X, s32 Y, u32 CF, u32 CB)
|
|
{
|
|
char TEXTDEF[4096];
|
|
char *PL1,*PL2;
|
|
s32 SizeX,SizeY,MAXX;
|
|
s32 TAB = 0;
|
|
/* Copy */
|
|
SizeX=SizeY=MAXX=0;
|
|
PL1 = TEXTDEF;
|
|
if (pTEXTHDR) SizeX = strlen((char*)pTEXTHDR);
|
|
while (*pTEXT && (PL1 < TEXTDEF + sizeof(TEXTDEF) - 16))
|
|
{
|
|
MAXX++;
|
|
*(PL1) = *(pTEXT++);
|
|
if (*(PL1) == '{') TAB += 3;
|
|
if (*(PL1) == '}') TAB -= 3;
|
|
if (TAB < 0) TAB = 0;//XSize,YSize
|
|
if ((*(PL1) == '{') || (*(PL1) == ',') || (MAXX + TAB > XSize / 16))
|
|
{
|
|
*(++PL1) = '\n';
|
|
}
|
|
|
|
if (*PL1 == '\n')
|
|
{
|
|
for (int i = 0 ; i < TAB && (PL1 < TEXTDEF + sizeof(TEXTDEF) - 16); i++) *(++PL1) = ' ';
|
|
SizeY++;
|
|
if (MAXX + TAB> SizeX) SizeX = MAXX+ TAB;
|
|
MAXX = 0;
|
|
}
|
|
PL1++;
|
|
}
|
|
if (MAXX + TAB > SizeX) SizeX = MAXX+ TAB;
|
|
SizeX += 3;
|
|
*PL1 = 0;
|
|
SizeY++;
|
|
SizeX *= 8;
|
|
SizeY *= 16;
|
|
if (X + SizeX > XSize) X = XSize-SizeX;
|
|
if (Y - SizeY < 0) Y = SizeY;
|
|
|
|
//DrawQuadFull(pMap,X-2, Y + 16 - SizeY, X+SizeX + 2,Y + 16 +3,CB);
|
|
//DRawTEXT_Soft((u8*)TEXTDEF ,(u32*)pMap->BASE,X, Y, pMap->PITCH, pMap->SY, 0 , 0 , 0);
|
|
DI->SetCurrentColor(CB);
|
|
DI->DrawQuad(-1,X-2, X+SizeX + 2,YSize - (Y+16) , YSize - (Y+16 -SizeY));
|
|
DI->SetCurrentColor(0xffffffff);
|
|
DI->DrawText((u8*)TEXTDEF ,X, Y, 1,1,0xff000000,0);
|
|
|
|
|
|
if (pTEXTHDR)
|
|
{
|
|
Y += 16;
|
|
DI->SetCurrentColor(0);
|
|
DI->DrawQuad(-1,X-2, X+SizeX + 2,YSize - (Y+16) , YSize - (Y+16 -16));
|
|
DI->SetCurrentColor(0xffffffff);
|
|
DI->DrawText((u8*)pTEXTHDR,X, Y, 1,1,0xff000080,0);
|
|
|
|
//DrawQuadFull(pMap,X-2, Y + 16 - 16, X+SizeX + 2,Y + 16 +3,0);
|
|
//DRawTEXT_Soft((u8*)pTEXTHDR ,(u32*)pMap->BASE,X, Y, pMap->PITCH, pMap->SY, 0x800000, 0 , 0);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WORLD::LUA_DEBUG_CLEAN()
|
|
{
|
|
if (pLDS)
|
|
{
|
|
if (pLDS->CompleteFile)
|
|
CC_free(pLDS->CompleteFile);
|
|
if (pLDS->LinePasses)
|
|
CC_free(pLDS->LinePasses);
|
|
if (pLDS->TotalLinePasses)
|
|
CC_free(pLDS->TotalLinePasses);
|
|
if (pLDS->LineMs)
|
|
CC_free(pLDS->LineMs);
|
|
if (pLDS->LineMsOld)
|
|
CC_free(pLDS->LineMsOld);
|
|
if (pLDS->LineMsSort1)
|
|
CC_free(pLDS->LineMsSort1);
|
|
if (pLDS->LineMsSort2)
|
|
CC_free(pLDS->LineMsSort2);
|
|
|
|
u32 Counter = 256;
|
|
while (Counter--)
|
|
if (pLDS->LineBreaks[Counter])
|
|
{
|
|
CC_free(pLDS->LineBreaks[Counter]);
|
|
pLDS->LineBreaks[Counter] = NULL;
|
|
}
|
|
|
|
pLDS->FileNameDicos.Destroy();
|
|
CC_free(pLDS);
|
|
}
|
|
pLDS = NULL;
|
|
LUA_DEBUG_Flags = 0;
|
|
if (luaScriptTable[currentScript])
|
|
lua_sethook(luaScriptTable[currentScript], NULL, 0, 0);
|
|
pBaseWorld = NULL;
|
|
}
|
|
void LDRS_HOOK(lua_State *L, lua_Debug *ar)
|
|
{
|
|
if (pBaseWorld) pBaseWorld->LUA_DEBUG_RASTER_START(L,ar);
|
|
}
|
|
|
|
int QSORT_HOOK(const void *B1, const void *B2)
|
|
{
|
|
if (pBaseWorld && pBaseWorld->pLDS)
|
|
{
|
|
if (pBaseWorld->pLDS->LineMs[*(u32 *)B1] > pBaseWorld->pLDS->LineMs[*(u32 *)B2])
|
|
return -1;
|
|
else
|
|
if (pBaseWorld->pLDS->LineMs[*(u32 *)B1] == pBaseWorld->pLDS->LineMs[*(u32 *)B2])
|
|
return 0;
|
|
else
|
|
return 1;
|
|
}
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
|
|
void WORLD::LUA_DEBUG_RASTER_START(lua_State *L, lua_Debug *ar)
|
|
{
|
|
|
|
char SourceFile[2048];
|
|
static u32 LastLineNumber;
|
|
static char LastSourceFile[2048] = "";
|
|
lua_getinfo(L, "S", ar);
|
|
strcpy(SourceFile,ar->source + 1);
|
|
strlwr(SourceFile);
|
|
if (strcmp("[c]",SourceFile) == 0) return;
|
|
if (!pLDS) return;
|
|
|
|
/* CallStack */
|
|
if (ar->event == LUA_HOOKCALL)
|
|
{
|
|
AddLuaFileInLDS(SourceFile,pLDS);
|
|
if (pLDS->CurrentDepth > 200) pLDS->CurrentDepth = 200;
|
|
sprintf(pLDS->CallStack[pLDS->CurrentDepth],"%s:%d",LastSourceFile,LastLineNumber);
|
|
pLDS->CurrentDepth++;
|
|
}
|
|
if (ar->event == LUA_HOOKCOUNT)
|
|
ar->event = LUA_HOOKCOUNT;
|
|
if ((ar->event == LUA_HOOKRET) ||
|
|
(ar->event == LUA_HOOKTAILRET))
|
|
{
|
|
if (pLDS->CurrentDepth) pLDS->CurrentDepth--;
|
|
}
|
|
//if (ar->event == LUA_HOOKCOUNT)
|
|
if (strcmp(LastSourceFile,SourceFile) != 0)
|
|
ar->event = ar->event;
|
|
strcpy(LastSourceFile,SourceFile);
|
|
|
|
if ((ar->event == LUA_HOOKLINE) /*&& (pLDS->CurrentDepth < pLDS->MaxDepth == 0 ? 200000 : pLDS->MaxDepth)*/)
|
|
{
|
|
LastLineNumber = ar->currentline;
|
|
/*
|
|
if (pLDS->FileNameDicos.IsExist(SourceFile) == -1)
|
|
{
|
|
strcpy(pLDS->AllScriptFileName[pLDS->MaxFile],SourceFile);
|
|
UnicID ID;
|
|
pLDS->FileNameDicos.GetUnic(&ID,(SourceFile));
|
|
if (pLDS->FileNameDicos.IsExist(SourceFile) != -1)
|
|
{
|
|
pLDS->MaxFile++;
|
|
}
|
|
|
|
}
|
|
*/
|
|
u32 NewFile = pLDS->CurrentFile;
|
|
if ((strcmp(SourceFile,pLDS->AllScriptFileName[pLDS->CurrentFile]) != 0))
|
|
{
|
|
if (pLDS->FileNameDicos.IsExist(SourceFile) != -1)
|
|
{
|
|
UnicID ID;
|
|
pLDS->FileNameDicos.GetUnic(&ID,(SourceFile));
|
|
NewFile = pLDS->FileNameDicos.mpst_Dico[ID].AssociatedValue;
|
|
}
|
|
}
|
|
|
|
if ((pLDS->MaxDepth==0) || (pLDS->MaxDepth >= pLDS->CurrentDepth) ||
|
|
(pLDS->LineBreaks[NewFile] && (pLDS->LineBreaks[NewFile][ar->currentline - 1] != 0)))
|
|
{
|
|
if (((pLDS->LineBreaks[NewFile] && (pLDS->LineBreaks[NewFile][ar->currentline - 1] != 0)) || (pLDS->DeubgTraceMode))
|
|
&& (NewFile != pLDS->CurrentFile))
|
|
{
|
|
pLDS->CurrentFile = NewFile;
|
|
if (pLDS->CompleteFile) CC_free(pLDS->CompleteFile);
|
|
pLDS->CompleteFile = NULL;
|
|
LUA_DEBUG_SET_NewFile();
|
|
}
|
|
|
|
|
|
if ((ar->currentline < pLDS->ulNumberOfLine) && (strcmp(SourceFile,pLDS->AllScriptFileName[pLDS->CurrentFile]) == 0))
|
|
{
|
|
if (pLDS->LastLineNumber != -1)
|
|
if (pLDS->LastLineNumber < pLDS->ulNumberOfLine)
|
|
{
|
|
pLDS->LineMsOld[pLDS->LastLineNumber - 1] += (float)(timeGetTime() - pLDS->GetTim);
|
|
}
|
|
|
|
pLDS->LastLineNumber = ar->currentline;
|
|
pLDS->GetTim = timeGetTime();
|
|
pLDS->LinePasses[ar->currentline - 1 ]++;
|
|
pLDS->TotalLinePasses[ar->currentline - 1 ]++;
|
|
|
|
|
|
|
|
//int listvars (lua_State *L, int level)
|
|
int level = 0;
|
|
|
|
if ((pLDS->LineBreaks[pLDS->CurrentFile] && (pLDS->LineBreaks[pLDS->CurrentFile][ar->currentline - 1] != 0)) || (pLDS->DeubgTraceMode))
|
|
{
|
|
pLDS->LastKeyIn = 0;
|
|
pLDS->DeubgTraceMode = 2;
|
|
DI->LayerOperation(0,7,1,0.0f,0.0f);
|
|
do {
|
|
int SaveViewport[4];
|
|
DI->GetViewport(&SaveViewport[0],&SaveViewport[1],&SaveViewport[2],&SaveViewport[3]);
|
|
|
|
MSG msg;
|
|
extern HWND hWnd; // DIRTY CODE !!
|
|
while (PeekMessage(&msg, hWnd, 0, 0 ,PM_REMOVE) )
|
|
{
|
|
TranslateMessage(&msg);
|
|
DispatchMessage(&msg);
|
|
}
|
|
pLDS->HasHooked = 1;
|
|
|
|
pLDS->LastLineNumber = ar->currentline;
|
|
|
|
DI->RectifyTextOrigin = 0;
|
|
DI->ClearZ();
|
|
DI->SetQuadRot(0,NULL,NULL);
|
|
ResetMaterialOverload();
|
|
|
|
|
|
RS Nullmlml;
|
|
GLOB_SetDefaultRS(&Nullmlml);
|
|
DI->SetRS(&Nullmlml,-1);
|
|
if (bDrawConsole) DrawConsole();
|
|
DI->SetViewport(0,0,XSize,YSize);
|
|
DI->FORCE_RENDER_FLAG = 0;
|
|
|
|
if (1)
|
|
{
|
|
int after ,before = lua_gettop(L);
|
|
lua_Debug ar;
|
|
memset(&ar,0,sizeof(ar));
|
|
int i;
|
|
lua_sethook(L, NULL, 0, 0);
|
|
char *pRevisitedNameSRC,*pRevisitedName,RevisitedName[8192];
|
|
const char *name;
|
|
pLDS->LocalFound = 0;
|
|
if (lua_getstack(L, level, &ar) == 0)
|
|
return ; // failure: no such level in the stack
|
|
i = 1;
|
|
pRevisitedNameSRC = pLDS->DEBUG_TOTEST;
|
|
memset(RevisitedName, 0, sizeof(RevisitedName));
|
|
strcpy(RevisitedName,pLDS->DEBUG_TOTEST);
|
|
|
|
pRevisitedNameSRC = RevisitedName;
|
|
for (pRevisitedName = pRevisitedNameSRC;
|
|
*pRevisitedName && (*pRevisitedName != '.');
|
|
*(pRevisitedName++));
|
|
*(pRevisitedName) = 0;
|
|
|
|
int nbLevel;
|
|
while ((name = lua_getlocal(L, &ar, i++)) != NULL)
|
|
{
|
|
nbLevel = 1;
|
|
if (name[0] != '(')
|
|
{
|
|
if (strcmp(name, pRevisitedNameSRC) == 0)
|
|
{
|
|
int TableToString(lua_State *L, int tableIndex);
|
|
while (*(pRevisitedName+1))
|
|
{
|
|
pRevisitedNameSRC = ++pRevisitedName;
|
|
for (pRevisitedName = pRevisitedNameSRC;
|
|
*pRevisitedName && (*pRevisitedName != '.');
|
|
*(pRevisitedName++));
|
|
*(pRevisitedName) = 0;
|
|
|
|
lua_pushstring(L, pRevisitedNameSRC);
|
|
lua_gettable(L,-2);
|
|
nbLevel++;
|
|
}
|
|
TableToString(L, -1);
|
|
nbLevel++;
|
|
char *pString;
|
|
pString = (char*)lua_tostring(L,-1);
|
|
if (strlen(pString) > 8000)
|
|
pLDS->LocalFound = 0;
|
|
else
|
|
{
|
|
sprintf(pLDS->DEBUG_TEXT,"%s = %s",pLDS->DEBUG_TOTEST, pString);
|
|
pLDS->LocalFound = 1;//*/
|
|
}
|
|
}
|
|
|
|
}
|
|
lua_pop(L, lua_gettop(L) - before); // remove variable value
|
|
}
|
|
|
|
if (pLDS->DEBUG_TOTEST[0] && !pLDS->LocalFound)
|
|
{
|
|
sprintf(pLDS->DEBUG_TEXT,"return TableToString(%s)",pLDS->DEBUG_TOTEST);
|
|
if (!luaL_dostring(L,pLDS->DEBUG_TEXT))
|
|
sprintf(pLDS->DEBUG_TEXT,"%s = %s",pLDS->DEBUG_TOTEST,lua_tostring(L,-1));
|
|
else
|
|
pLDS->DEBUG_TEXT[0] = 0;
|
|
lua_pop(L,1);
|
|
}
|
|
lua_sethook(L, LDRS_HOOK, LUA_HOOKMASK, 1);
|
|
}//*/
|
|
|
|
|
|
LUA_DEBUG();
|
|
if (!pLDS)
|
|
{
|
|
lua_sethook(L, NULL, 0, 0);
|
|
return;
|
|
}
|
|
|
|
|
|
if (SkipFunctions & SKIP_NOMOSAIC)
|
|
{
|
|
|
|
Mosaique();
|
|
}
|
|
RenderFlip();
|
|
GLOB_SetDefaultRS(&Nullmlml);
|
|
DI->SetRS(&Nullmlml,-1);
|
|
if (bDrawConsole) DrawConsole();
|
|
DI->SetViewport(0,0,XSize,YSize);
|
|
DI->FORCE_RENDER_FLAG = 0;
|
|
|
|
DI->SetViewport(SaveViewport[0],SaveViewport[1],SaveViewport[2],SaveViewport[3]);
|
|
if ((pLDS->LastKeyIn < VK_F5) || (pLDS->LastKeyIn > VK_F12))
|
|
pLDS->LastKeyIn = 0;
|
|
} while (!pLDS->LastKeyIn);
|
|
|
|
DI->LayerOperation(20,7,0xffffffff,0.0f,0.0f);
|
|
pLDS->DeubgTraceMode = 0;
|
|
pLDS->MaxDepth = 0;
|
|
if (pLDS->LastKeyIn == VK_F10) {pLDS->DeubgTraceMode = 2;pLDS->MaxDepth = pLDS->CurrentDepth;};
|
|
if ((pLDS->LastKeyIn == VK_F11) && GetAsyncKeyState(VK_SHIFT)) pLDS->LastKeyIn = VK_F12;
|
|
if (pLDS->LastKeyIn == VK_F12)
|
|
{
|
|
pLDS->DeubgTraceMode = 2;pLDS->MaxDepth = pLDS->CurrentDepth-1;
|
|
};
|
|
if (pLDS->LastKeyIn == VK_F11) {pLDS->DeubgTraceMode = 2;};
|
|
}
|
|
|
|
|
|
if (pLDS->LineToDebug == ar->currentline - 1)
|
|
{
|
|
lua_Debug ar;
|
|
int i;
|
|
int after ,before = lua_gettop(L);
|
|
|
|
|
|
|
|
DI->LayerOperation(0,7,1,0.0f,0.0f);
|
|
pLDS->HasHooked = 1;
|
|
lua_sethook(L, NULL, 0, 0);
|
|
|
|
char *pRevisitedNameSRC,*pRevisitedName,RevisitedName[8192];
|
|
const char *name;
|
|
pLDS->LocalFound = 0;
|
|
if (lua_getstack(L, level, &ar) == 0)
|
|
return ; // failure: no such level in the stack
|
|
i = 1;
|
|
pRevisitedNameSRC = pLDS->DEBUG_TOTEST;
|
|
memset(RevisitedName, 0, sizeof(RevisitedName));
|
|
strcpy(RevisitedName,pLDS->DEBUG_TOTEST);
|
|
|
|
pRevisitedNameSRC = RevisitedName;
|
|
for (pRevisitedName = pRevisitedNameSRC;
|
|
*pRevisitedName && (*pRevisitedName != '.');
|
|
*(pRevisitedName++));
|
|
*(pRevisitedName) = 0;
|
|
|
|
while ((name = lua_getlocal(L, &ar, i++)) != NULL)
|
|
{
|
|
int nbLevel = 1;
|
|
if (name[0] != '(')
|
|
{
|
|
if (strcmp(name, pRevisitedNameSRC) == 0)
|
|
{
|
|
int TableToString(lua_State *L, int tableIndex);
|
|
while (*(pRevisitedName+1))
|
|
{
|
|
pRevisitedNameSRC = ++pRevisitedName;
|
|
for (pRevisitedName = pRevisitedNameSRC;
|
|
*pRevisitedName && (*pRevisitedName != '.');
|
|
*(pRevisitedName++));
|
|
*(pRevisitedName) = 0;
|
|
|
|
lua_pushstring(L, pRevisitedNameSRC);
|
|
lua_gettable(L,-2);
|
|
nbLevel++;
|
|
}
|
|
TableToString(L, -1);
|
|
nbLevel++;
|
|
if (strlen(lua_tostring(L,-1)) > 8000)
|
|
pLDS->LocalFound = 0;
|
|
else
|
|
{
|
|
sprintf(pLDS->DEBUG_TEXT,"%s = %s",pLDS->DEBUG_TOTEST, lua_tostring(L,-1));
|
|
pLDS->LocalFound = 1;
|
|
}
|
|
}
|
|
|
|
}
|
|
lua_pop(L, lua_gettop(L) - before); // remove variable value
|
|
|
|
}
|
|
if (pLDS->DEBUG_TOTEST[0] && !pLDS->LocalFound)
|
|
{
|
|
sprintf(pLDS->DEBUG_TEXT,"return TableToString(%s)",pLDS->DEBUG_TOTEST);
|
|
if (!luaL_dostring(L,pLDS->DEBUG_TEXT))
|
|
sprintf(pLDS->DEBUG_TEXT,"%s = %s",pLDS->DEBUG_TOTEST,lua_tostring(L,-1));
|
|
else
|
|
pLDS->DEBUG_TEXT[0] = 0;
|
|
lua_pop(L,1);
|
|
}//*/
|
|
lua_sethook(L, LDRS_HOOK, LUA_HOOKMASK, 1);
|
|
}//*/
|
|
}
|
|
}
|
|
}
|
|
}
|
|
u32 IsNameChar(char X)
|
|
{
|
|
if ((X >= 'A') && (X <= 'Z')) return 1;
|
|
if ((X >= 'a') && (X <= 'z')) return 1;
|
|
if ((X >= '0') && (X <= '9')) return 1;
|
|
if (X == '_') return 1;
|
|
return 0;
|
|
}
|
|
void WORLD::LUA_DEBUG_RASTER_STOP()
|
|
{
|
|
if (pLDS)
|
|
{
|
|
pLDS->LastLineNumber = -1;
|
|
}
|
|
}
|
|
void WORLD::LUA_DEBUG_SET_NewFile()
|
|
{
|
|
if (!pLDS->CompleteFile)
|
|
{
|
|
u32 Fl;
|
|
Fl = GetFileLenght((char*)pLDS->AllScriptFileName[pLDS->CurrentFile]) + 4;
|
|
if (Fl)
|
|
{
|
|
FILE *F;
|
|
F = CC_fopen(pLDS->AllScriptFileName[pLDS->CurrentFile],"rb");
|
|
if (F)
|
|
{
|
|
pLDS-> CompleteFile = (char*)CC_malloc(Fl+1);
|
|
memset(pLDS -> CompleteFile ,0,Fl);
|
|
pLDS-> CompleteFile[0] = ' ';
|
|
fread(pLDS-> CompleteFile+1, 1 , Fl , F);
|
|
|
|
int i, j;
|
|
for (i=0, j=0 ; i < Fl-1; pLDS-> CompleteFile[j++] = pLDS-> CompleteFile[i++])
|
|
if (pLDS-> CompleteFile[i] == '\r')
|
|
{
|
|
if (pLDS-> CompleteFile[i+1] == '\n') i++;
|
|
else pLDS-> CompleteFile[i] = '\n';
|
|
}
|
|
pLDS-> CompleteFile[j] = 0;
|
|
CC_fclose(F);
|
|
}
|
|
|
|
pLDS->ulNumberOfLine = 0;
|
|
if (pLDS-> CompleteFile)
|
|
{
|
|
for (int i = 0 ; i < Fl ; i++)
|
|
{
|
|
if (pLDS-> CompleteFile[i] == '\n') pLDS->ulNumberOfLine++;
|
|
}
|
|
if (!pLDS->LinePasses) pLDS->LinePasses = (u32 *) CC_malloc((pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
else pLDS->LinePasses = (u32 *) CC_realloc(pLDS->LinePasses, (pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
memset(pLDS->LinePasses, 0, (pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
|
|
if (!pLDS->TotalLinePasses) pLDS->TotalLinePasses = (u32 *) CC_malloc((pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
else pLDS->TotalLinePasses = (u32 *) CC_realloc(pLDS->TotalLinePasses, (pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
memset(pLDS->TotalLinePasses, 0, (pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
|
|
|
|
|
|
if (!pLDS->LineMs) pLDS->LineMs = (float *) CC_malloc((pLDS->ulNumberOfLine + 1)*sizeof(float));
|
|
else pLDS->LineMs = (float *) CC_realloc(pLDS->LineMs, (pLDS->ulNumberOfLine + 1)*sizeof(float));
|
|
memset(pLDS->LineMs, 0, (pLDS->ulNumberOfLine + 1)*sizeof(float));
|
|
|
|
if (!pLDS->LineMsOld) pLDS->LineMsOld = (float *) CC_malloc((pLDS->ulNumberOfLine + 1)*sizeof(float));
|
|
else pLDS->LineMsOld = (float *) CC_realloc(pLDS->LineMsOld, (pLDS->ulNumberOfLine + 1)*sizeof(float));
|
|
memset(pLDS->LineMsOld, 0, (pLDS->ulNumberOfLine + 1)*sizeof(float));
|
|
|
|
if (!pLDS->LineMsSort1) pLDS->LineMsSort1 = (u32 *) CC_malloc((pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
else pLDS->LineMsSort1 = (u32 *) CC_realloc(pLDS->LineMsSort1, (pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
memset(pLDS->LineMsSort1, 0, (pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
|
|
if (!pLDS->LineMsSort2) pLDS->LineMsSort2 = (u32 *) CC_malloc((pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
else pLDS->LineMsSort2 = (u32 *) CC_realloc(pLDS->LineMsSort2, (pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
memset(pLDS->LineMsSort2, 0, (pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
|
|
if (!pLDS->LineBreaks[pLDS->CurrentFile])
|
|
{
|
|
pLDS->LineBreaks[pLDS->CurrentFile] = (u32 *) CC_malloc((pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
memset(pLDS->LineBreaks[pLDS->CurrentFile], 0, (pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
}
|
|
/* else
|
|
{
|
|
pLDS->LineBreaks[pLDS->CurrentFile] = (u32 *) CC_realloc(pLDS->LineBreaks[pLDS->CurrentFile], (pLDS->ulNumberOfLine + 1)*sizeof(u32));
|
|
pLDS->LineBreaks[pLDS->CurrentFile][pLDS->ulNumberOfLine] = 0;
|
|
}*/
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
void WORLD::LUA_DEBUG()
|
|
{
|
|
|
|
if ((SkipFunctions &
|
|
SKIP_NODEBUG) && (luaScriptTable[currentScript]))
|
|
{
|
|
static u32 LastMB;
|
|
LastMB ^= GetAsyncKeyState(VK_MBUTTON);
|
|
LastMB &= GetAsyncKeyState(VK_MBUTTON);
|
|
|
|
CreatePlds(this);
|
|
|
|
if (pLDS && pLDS->DeubgTraceMode) DI->LayerOperation(20,7,0xffffffff,0.0f,0.0f); // Restore current image
|
|
if (!LUA_DEBUG_Flags)
|
|
{
|
|
|
|
DI->AfterEffect(12,0,0.2f,0.2f,0.2f,0,0);
|
|
|
|
//DI->AfterEffect(0,0,0.01f,0.0f);
|
|
}
|
|
|
|
|
|
u32 NumberOfDisplayLines = FrameBufferResult.SY / 16 - 10 ;
|
|
/*
|
|
if ((MouseY > NumberOfDisplayLines * 16 - 16) && (MouseY < NumberOfDisplayLines * 16) && MouseButton)
|
|
{
|
|
pLDS->CurrentFile++;
|
|
if (pLDS->CurrentFile >= pLDS->MaxFile) pLDS->CurrentFile = 0;
|
|
MouseButton = 0;
|
|
if (pLDS->CompleteFile) CC_free(pLDS->CompleteFile);
|
|
pLDS->CompleteFile = NULL;
|
|
}
|
|
*/
|
|
|
|
|
|
LUA_DEBUG_SET_NewFile();
|
|
|
|
char TEXT1[2048];
|
|
char TEXT[2048];
|
|
#define LineCountW 8*10
|
|
|
|
if (pLDS && pLDS->CompleteFile)
|
|
{
|
|
if (pLDS->DeubgTraceMode==2)
|
|
{
|
|
if (pLDS->LastLineNumber -1 < LUA_DEBUG_BaseDisplay)
|
|
LUA_DEBUG_BaseDisplay = pLDS->LastLineNumber -1;
|
|
if (pLDS->LastLineNumber +1 > LUA_DEBUG_BaseDisplay + NumberOfDisplayLines)
|
|
LUA_DEBUG_BaseDisplay = pLDS->LastLineNumber +1 - NumberOfDisplayLines;
|
|
pLDS->DeubgTraceMode = 1;
|
|
}
|
|
if (LUA_DEBUG_BaseDisplay < -15) LUA_DEBUG_BaseDisplay = pLDS->ulNumberOfLine - NumberOfDisplayLines;
|
|
if (LUA_DEBUG_BaseDisplay > pLDS->ulNumberOfLine - NumberOfDisplayLines + 15) LUA_DEBUG_BaseDisplay = 0;
|
|
if (LUA_DEBUG_BaseDisplay < 0) LUA_DEBUG_BaseDisplay = 0;
|
|
if (LUA_DEBUG_BaseDisplay > pLDS->ulNumberOfLine - NumberOfDisplayLines ) LUA_DEBUG_BaseDisplay = pLDS->ulNumberOfLine - NumberOfDisplayLines;
|
|
|
|
|
|
s32 ulNumberOfLines = 0;
|
|
s32 LocalMouseY = FrameBufferResult.SY - MouseY- 16;
|
|
s32 KBase = FrameBufferResult.SY - 16 + LUA_DEBUG_BaseDisplay * 16;
|
|
char *pTextParser,*pTextParserLAST;
|
|
pTextParser = pLDS-> CompleteFile;
|
|
|
|
|
|
if (!pLDS->DeubgTraceMode)
|
|
{
|
|
for (int i = 0 ; i < pLDS->ulNumberOfLine ; i ++ )
|
|
pLDS->LineMs[i] = pLDS->LineMs[i] * 0.95f + pLDS->LineMsOld[i]*0.05f;
|
|
}
|
|
for (int i = 0 ; i < pLDS->ulNumberOfLine ; i ++ )
|
|
pLDS->LineMsSort1[i] = i;
|
|
qsort(pLDS->LineMsSort1,pLDS->ulNumberOfLine,sizeof(float),QSORT_HOOK);
|
|
for (int i = 0 ; i < pLDS->ulNumberOfLine ; i ++ )
|
|
pLDS->LineMsSort2[pLDS->LineMsSort1[i]] = i;
|
|
|
|
|
|
while (*pTextParser)
|
|
{
|
|
char SaveL;
|
|
pTextParserLAST = pTextParser + 1;
|
|
while (*pTextParserLAST && (*pTextParserLAST != '\n') )
|
|
{
|
|
pTextParserLAST++;
|
|
}
|
|
|
|
SaveL = *pTextParserLAST;
|
|
|
|
|
|
*pTextParserLAST = 0;
|
|
|
|
if (pLDS->DeubgTraceMode && (pLDS->LastLineNumber -1 == ulNumberOfLines))
|
|
{
|
|
DI->SetClipping(0, KBase - ulNumberOfLines * 16, XSize, 16);
|
|
DI->AfterEffect(12,0,0.0,0.0,0.0,0,0); // MUL
|
|
DI->AfterEffect(11,0,0.4,0.1,0.2,0,0); // ADD
|
|
DI->SetClipping(0, 0, XSize, YSize);
|
|
if (pLDS->LastKeyIn == VK_F9)
|
|
{
|
|
pLDS->LastKeyIn = 0;
|
|
pLDS->LineBreaks[pLDS->CurrentFile][ulNumberOfLines] ^= 1;
|
|
}
|
|
}
|
|
|
|
u32 Color = 0xffffffff;
|
|
char *LP = pTextParser + 1;
|
|
while ((*LP == 32) || (*LP == '\t')) LP++;
|
|
if ((*LP == '-') && (*(LP+1) == '-')) Color = 0xff00ff00;
|
|
|
|
|
|
{
|
|
memset(TEXT1 ,0,sizeof(TEXT1 ));
|
|
sprintf(TEXT1 , "%5d %s",ulNumberOfLines + 1,pTextParser + 1);
|
|
TEXT1[((FrameBufferResult.SX - LineCountW * 2)>>3) - 4] = '.';
|
|
TEXT1[((FrameBufferResult.SX - LineCountW * 2)>>3) - 3] = '.';
|
|
TEXT1[((FrameBufferResult.SX - LineCountW * 2)>>3) - 2] = '.';
|
|
TEXT1[((FrameBufferResult.SX - LineCountW * 2)>>3) - 1] = 0;
|
|
if (pLDS->LinePasses[ulNumberOfLines] == 0)
|
|
{
|
|
u32 Color2 = Color & 0xfcfcfc;
|
|
Color2 >>= 2;
|
|
Color &= 0xfcfcfc;
|
|
Color >>= 1;
|
|
Color += Color2;
|
|
Color |= 0xff000000;
|
|
|
|
}
|
|
int deltaKBase = KBase - 16*((int)ulNumberOfLines);
|
|
int deltaFrame = (int)FrameBufferResult.SY - 16*((int)NumberOfDisplayLines);
|
|
if (deltaKBase < (int)FrameBufferResult.SY && deltaKBase > deltaFrame)
|
|
{
|
|
if ((FrameBufferResult.SY - MouseY > KBase - ulNumberOfLines * 16) && (FrameBufferResult.SY - MouseY < KBase - ulNumberOfLines * 16 + 16))
|
|
{
|
|
if (!LUA_DEBUG_Flags)
|
|
{
|
|
pLDS->LineToDebug = ulNumberOfLines;
|
|
if ((LastMB) || (pLDS->LastKeyIn == VK_F9))
|
|
{
|
|
pLDS->LineBreaks[pLDS->CurrentFile][ulNumberOfLines] ^= 1;
|
|
pLDS->LastKeyIn = 0;
|
|
}
|
|
}
|
|
}
|
|
if (pLDS->LineBreaks[pLDS->CurrentFile][ulNumberOfLines] != 0) Color &= 0xff0000ff;
|
|
|
|
if (!LUA_DEBUG_Flags)
|
|
{
|
|
DI->DrawText((u8*)TEXT1 ,0, KBase - ulNumberOfLines * 16, 1.0f,1.0f,Color ,0);
|
|
//DRawTEXT_Soft((u8*)TEXT1 ,(u32*)FrameBufferResult.BASE,0, KBase - ulNumberOfLines * 16, FrameBufferResult.PITCH, FrameBufferResult.SY, Color , 0 , 0);
|
|
sprintf(TEXT , " %2.1f ms",pLDS->LineMs[ulNumberOfLines]);
|
|
DI->DrawText((u8*)TEXT ,FrameBufferResult.SX - LineCountW*2, KBase - ulNumberOfLines * 16, 1.0f,1.0f,Color ,0);
|
|
//DRawTEXT_Soft((u8*)TEXT ,(u32*)FrameBufferResult.BASE,FrameBufferResult.SX - LineCountW*2, KBase - ulNumberOfLines * 16, FrameBufferResult.PITCH, FrameBufferResult.SY, Color,0,0);
|
|
if (pLDS->TotalLinePasses[ulNumberOfLines]<1000)
|
|
sprintf(TEXT , "%7d/%d ",pLDS->LinePasses[ulNumberOfLines],pLDS->TotalLinePasses[ulNumberOfLines]);
|
|
else
|
|
sprintf(TEXT , "%7d/%dK ",pLDS->LinePasses[ulNumberOfLines],pLDS->TotalLinePasses[ulNumberOfLines]/1000);
|
|
DI->DrawText((u8*)TEXT ,FrameBufferResult.SX - LineCountW - 4*8, KBase - ulNumberOfLines * 16, 1.0f,1.0f,Color ,0);
|
|
//DRawTEXT_Soft((u8*)TEXT ,(u32*)FrameBufferResult.BASE,FrameBufferResult.SX - LineCountW, KBase - ulNumberOfLines * 16, FrameBufferResult.PITCH, FrameBufferResult.SY, Color,0,0);
|
|
}
|
|
|
|
if ((!LUA_DEBUG_Flags)&&(pLDS->LineToDebug == ulNumberOfLines))
|
|
{
|
|
|
|
char *pToSB,*pToSL;
|
|
pToSB = pToSL = TEXT1+MouseX/8;
|
|
char ToUpper(char H);
|
|
|
|
if (pToSB-TEXT1 > strlen(TEXT1))
|
|
{
|
|
pToSB = pToSL = TEXT1+strlen(TEXT1);
|
|
}
|
|
|
|
while ((pToSB > TEXT1) && (
|
|
/* (*(pToSB-1) == '(') ||
|
|
(*(pToSB-1) == ')') || */
|
|
/* (*(pToSB-1) == '[') ||
|
|
(*(pToSB-1) == ']') || */
|
|
(*(pToSB-1) == ':') ||
|
|
(*(pToSB-1) == '.') ||
|
|
IsNameChar(*(pToSB-1))))
|
|
pToSB--;
|
|
while ((*pToSL) && (IsNameChar(*(pToSL))))
|
|
pToSL++;
|
|
|
|
memcpy(pLDS->DEBUG_TOTEST,pToSB,pToSL-pToSB);
|
|
pLDS->DEBUG_TOTEST[pToSL-pToSB] = 0;
|
|
|
|
}
|
|
}
|
|
if ((!LUA_DEBUG_Flags) )
|
|
{
|
|
if ((!pLDS->DeubgTraceMode)&&(pLDS->LineMs[ulNumberOfLines] && pLDS->LinePasses[ulNumberOfLines] && pLDS->LineMsSort2[ulNumberOfLines] < 9))
|
|
{
|
|
Color = 0xffff80ff;
|
|
DI->DrawText((u8*)TEXT1 ,0, FrameBufferResult.SY - NumberOfDisplayLines * 16 - pLDS->LineMsSort2[ulNumberOfLines] * 16 - 16 , 1.0f,1.0f,Color ,0);
|
|
//DRawTEXT_Soft((u8*)TEXT1 ,(u32*)FrameBufferResult.BASE,0, FrameBufferResult.SY - NumberOfDisplayLines * 16 - pLDS->LineMsSort2[ulNumberOfLines] * 16 - 16, FrameBufferResult.PITCH, FrameBufferResult.SY, Color , 0 , 0);
|
|
|
|
sprintf(TEXT , " %2.1f ms",pLDS->LineMs[ulNumberOfLines]);
|
|
DI->DrawText((u8*)TEXT ,FrameBufferResult.SX - LineCountW*2, FrameBufferResult.SY - NumberOfDisplayLines * 16 - pLDS->LineMsSort2[ulNumberOfLines] * 16- 16, 1.0f,1.0f,Color ,0);
|
|
//DRawTEXT_Soft((u8*)TEXT ,(u32*)FrameBufferResult.BASE,FrameBufferResult.SX - LineCountW*2, FrameBufferResult.SY - NumberOfDisplayLines * 16 - pLDS->LineMsSort2[ulNumberOfLines] * 16- 16, FrameBufferResult.PITCH, FrameBufferResult.SY, Color,0,0);
|
|
sprintf(TEXT , "%7d ",pLDS->LinePasses[ulNumberOfLines]);
|
|
DI->DrawText((u8*)TEXT ,FrameBufferResult.SX - LineCountW, FrameBufferResult.SY - NumberOfDisplayLines * 16 - pLDS->LineMsSort2[ulNumberOfLines] * 16- 16, 1.0f,1.0f,Color ,0);
|
|
//DRawTEXT_Soft((u8*)TEXT ,(u32*)FrameBufferResult.BASE,FrameBufferResult.SX - LineCountW, FrameBufferResult.SY - NumberOfDisplayLines * 16 - pLDS->LineMsSort2[ulNumberOfLines] * 16- 16, FrameBufferResult.PITCH, FrameBufferResult.SY, Color,0,0);
|
|
}
|
|
}
|
|
}
|
|
*pTextParserLAST = SaveL;
|
|
pTextParser = pTextParserLAST;
|
|
|
|
if (!pLDS->DeubgTraceMode)
|
|
{
|
|
pLDS->LinePasses[ulNumberOfLines] = 0;
|
|
pLDS->LineMsOld[ulNumberOfLines] = 0;
|
|
}
|
|
|
|
ulNumberOfLines++;
|
|
}
|
|
sprintf(TEXT," Line %s",pLDS->AllScriptFileName[pLDS->CurrentFile]);
|
|
if (!LUA_DEBUG_Flags)
|
|
{
|
|
if ((MouseY > NumberOfDisplayLines * 16 - 16) && (MouseY < NumberOfDisplayLines * 16))
|
|
{
|
|
DI->DrawText((u8*)TEXT ,0, FrameBufferResult.SY - NumberOfDisplayLines * 16 , 1.0f,1.0f,0xffffffff,0);
|
|
//DRawTEXT_Soft_B((u8*)TEXT ,(u32*)FrameBufferResult.BASE,0, FrameBufferResult.SY - NumberOfDisplayLines * 16 , FrameBufferResult.PITCH, FrameBufferResult.SY, 0xffFFffff);
|
|
if (MouseButton && !pLDS->showFileList)
|
|
{
|
|
pLDS->showFileList = true;
|
|
pLDS->fileListStartDelta = 0;
|
|
MouseButton = 0;
|
|
}
|
|
}
|
|
else
|
|
DI->DrawText((u8*)TEXT ,0, FrameBufferResult.SY - NumberOfDisplayLines * 16 , 1.0f,1.0f,0xff00ffff,0);
|
|
//DRawTEXT_Soft_B((u8*)TEXT ,(u32*)FrameBufferResult.BASE,0, FrameBufferResult.SY - NumberOfDisplayLines * 16 , FrameBufferResult.PITCH, FrameBufferResult.SY, 0xffff);
|
|
DI->DrawText((u8*)"Line Count" ,FrameBufferResult.SX - LineCountW, FrameBufferResult.SY - NumberOfDisplayLines * 16 , 1.0f,1.0f,0xff00ffff,0);
|
|
DI->DrawText((u8*)"Line ms" ,FrameBufferResult.SX - LineCountW * 2, FrameBufferResult.SY - NumberOfDisplayLines * 16 , 1.0f,1.0f,0xff00ffff,0);
|
|
// DRawTEXT_Soft_B((u8*)"Line Count" ,(u32*)FrameBufferResult.BASE,FrameBufferResult.SX - LineCountW, FrameBufferResult.SY - NumberOfDisplayLines * 16 , FrameBufferResult.PITCH, FrameBufferResult.SY, 0xffff);
|
|
// DRawTEXT_Soft_B((u8*)"Line ms" ,(u32*)FrameBufferResult.BASE,FrameBufferResult.SX - LineCountW * 2, FrameBufferResult.SY - NumberOfDisplayLines * 16 , FrameBufferResult.PITCH, FrameBufferResult.SY, 0xffff);
|
|
//DI->DrawLine(
|
|
/*DrawLine_Clip(&FrameBufferResult,8*6,FrameBufferResult.SY,8*6,0,0xff0000);
|
|
DrawLine_Clip(&FrameBufferResult,FrameBufferResult.SX - LineCountW,FrameBufferResult.SY,FrameBufferResult.SX - LineCountW,0,0xff0000);
|
|
DrawLine_Clip(&FrameBufferResult,FrameBufferResult.SX - LineCountW*2,FrameBufferResult.SY,FrameBufferResult.SX - LineCountW*2,0,0xff0000);
|
|
DrawLine_Clip(&FrameBufferResult,0,FrameBufferResult.SY - NumberOfDisplayLines * 16 + 17,FrameBufferResult.SX,FrameBufferResult.SY - NumberOfDisplayLines * 16 + 17,0xff0000);
|
|
DrawLine_Clip(&FrameBufferResult,0,FrameBufferResult.SY - NumberOfDisplayLines * 16 ,FrameBufferResult.SX,FrameBufferResult.SY - NumberOfDisplayLines * 16 ,0xff0000);*/
|
|
|
|
if (pLDS->showFileList)
|
|
{
|
|
DI->AfterEffect(12,0,0.3f,0.3f,0.3f,0,0);
|
|
|
|
#define NBLUAFILESDISPLAYED 30
|
|
|
|
if (pLDS->fileListStartDelta>(s32)pLDS->MaxFile-NBLUAFILESDISPLAYED)
|
|
pLDS->fileListStartDelta = (s32)pLDS->MaxFile-NBLUAFILESDISPLAYED;
|
|
if (pLDS->fileListStartDelta<0)
|
|
pLDS->fileListStartDelta = 0;
|
|
u32 limit = pLDS->fileListStartDelta + NBLUAFILESDISPLAYED;
|
|
if (limit>pLDS->MaxFile)
|
|
limit = pLDS->MaxFile;
|
|
|
|
for (u32 i=pLDS->fileListStartDelta;i<limit;i++)
|
|
{
|
|
sprintf(TEXT," %s",pLDS->AllScriptFileName[i]);
|
|
unsigned int color = 0xffffffff;
|
|
if ((MouseY > NumberOfDisplayLines * 16 - 16 - 16*(i-pLDS->fileListStartDelta)) && (MouseY < NumberOfDisplayLines * 16 - 16*(i-pLDS->fileListStartDelta)))
|
|
{
|
|
color = 0xff00ffff;
|
|
if (MouseButton)
|
|
{
|
|
pLDS->CurrentFile = i;
|
|
MouseButton = 0;
|
|
if (pLDS->CompleteFile) CC_free(pLDS->CompleteFile);
|
|
pLDS->CompleteFile = NULL;
|
|
pLDS->showFileList = false;
|
|
}
|
|
}
|
|
DI->DrawText((u8*)TEXT, 0, FrameBufferResult.SY - NumberOfDisplayLines * 16 + 16*(i-pLDS->fileListStartDelta) , 1.0f,1.0f,color,0);
|
|
}
|
|
u32 infoY = NBLUAFILESDISPLAYED;
|
|
if (infoY>pLDS->MaxFile)
|
|
infoY = pLDS->MaxFile;
|
|
sprintf(TEXT," Choose the lua file to debug (%d-%d/%d) :",pLDS->fileListStartDelta+1,min(pLDS->fileListStartDelta+1+NBLUAFILESDISPLAYED,limit+1), pLDS->MaxFile+1);
|
|
DI->DrawText((u8*)TEXT, 0, FrameBufferResult.SY - NumberOfDisplayLines * 16 + 16*(infoY+1) , 1.0f,1.0f,0xff00ff00,0);
|
|
u32 len = strlen(TEXT);
|
|
u32 pxPerLetter = 8;
|
|
u32 crossDeltaLetter = 6;
|
|
sprintf(TEXT,"X");
|
|
DI->DrawText((u8*)TEXT, (len+crossDeltaLetter)*pxPerLetter, FrameBufferResult.SY - NumberOfDisplayLines * 16 + 16*(infoY+1) , 1.0f,1.0f,0xff0000ff,0);
|
|
if ((MouseY > NumberOfDisplayLines * 16 - 16 - 16*(infoY+1)) && (MouseY < NumberOfDisplayLines * 16 - 16*(infoY+1)))
|
|
if ((MouseX > (len+crossDeltaLetter)*pxPerLetter) && (MouseX < (len+crossDeltaLetter+1)*pxPerLetter) && MouseButton)
|
|
pLDS->showFileList = false;
|
|
}
|
|
}
|
|
if (pLDS->DeubgTraceMode)
|
|
{
|
|
for (u32 Counter = 1 ; Counter < pLDS->CurrentDepth; Counter++)
|
|
{
|
|
DI->DrawText((u8*)pLDS->CallStack[Counter],0,
|
|
FrameBufferResult.SY - NumberOfDisplayLines * 16 + 16 * Counter - 16 * pLDS->CurrentDepth, 1.0f,1.0f,0xFF8080FF,0);
|
|
}
|
|
}
|
|
DI->SetClipping(0, 0, XSize, 16);
|
|
DI->AfterEffect(12,0,0.0,0.0,0.0,0,0); // MUL
|
|
DI->SetClipping(0, 0, XSize, YSize);
|
|
char help[] = "F5 = RUN | F9 = Toggle break | F10 = Step over | F11 = Step in | F12 = shift F11 = Step out";
|
|
char help2[]= "F5 = | F9 = | F10 = | F11 = | F12 = shift F11 ";
|
|
DI->DrawText((u8*)help,(XSize - strlen(help) * 8)/2,0, 1.0f,1.0f,0xFFF0F0FF,0);
|
|
DI->DrawText((u8*)help2,(XSize - strlen(help) * 8)/2,0, 1.0f,1.0f,0xFF0000FF,0);
|
|
|
|
|
|
u32 GlobalScope = 0;
|
|
if ((!pLDS->DEBUG_TEXT[0]) && pLDS->DEBUG_TOTEST[0])
|
|
{
|
|
lua_sethook(luaScriptTable[currentScript], NULL, 0, 0);
|
|
|
|
sprintf(pLDS->DEBUG_TEXT,"return TableToString(%s)",pLDS->DEBUG_TOTEST);
|
|
//sprintf(pLDS->DEBUG_TEXT,"return debug.traceback()",pLDS->DEBUG_TOTEST);
|
|
|
|
if (!luaL_dostring(luaScriptTable[currentScript],pLDS->DEBUG_TEXT))
|
|
{
|
|
sprintf(pLDS->DEBUG_TEXT,"%s = %s",pLDS->DEBUG_TOTEST,lua_tostring(luaScriptTable[currentScript],-1));
|
|
}
|
|
else
|
|
sprintf(pLDS->DEBUG_TEXT,"%s = nil",pLDS->DEBUG_TOTEST);
|
|
lua_pop(luaScriptTable[currentScript],1);
|
|
GlobalScope = 1;
|
|
|
|
lua_sethook(luaScriptTable[currentScript], LDRS_HOOK, LUA_HOOKMASK, 1);
|
|
}//*/
|
|
|
|
if ((pLDS->DEBUG_TEXT[0]))
|
|
{
|
|
u32 ColorDBG;
|
|
if (GlobalScope)
|
|
ColorDBG = 0xff8080ff;
|
|
else
|
|
ColorDBG = 0xff80ffff;
|
|
if (pLDS->LocalFound)
|
|
ColorDBG = 0xff80ff80;
|
|
if (strlen(pLDS->DEBUG_TEXT) >= 1952)
|
|
pLDS->DEBUG_TEXT[1952] = 0;
|
|
sprintf( TEXT , "%s" , pLDS->DEBUG_TEXT);
|
|
|
|
if (LUA_DEBUG_Flags)
|
|
DRawTEXT_BackFull((u8*)TEXT,(u8*)"F1 to unlock",MouseX+16, FrameBufferResult.SY-MouseY-16, 0, ColorDBG);
|
|
else
|
|
{
|
|
if ((MouseY < NumberOfDisplayLines * 16 - 16) && !pLDS->showFileList)
|
|
DRawTEXT_BackFull((u8*)TEXT,(u8*)"F1 to lock",MouseX+16, FrameBufferResult.SY-MouseY-16, 0, ColorDBG);
|
|
}
|
|
}
|
|
pLDS->DEBUG_TEXT[0] = 0;
|
|
|
|
pLDS->LastLineNumber = -1;
|
|
}
|
|
|
|
{
|
|
//DI->AfterEffect(12,0,0.3f,0.3f,0.3f,0,0);
|
|
//#define STICKW
|
|
|
|
if (pLDS->HasHooked /*&& !pLDS->DeubgTraceMode*/)
|
|
{
|
|
s32 DXS = XSize/4,DYS = YSize/4;
|
|
DI->SetViewport(XSize-DXS,YSize-DYS,DXS,DYS);
|
|
DI->LayerOperation(20,7,0xffffffff,0.0f,0.0f);
|
|
DI->SetViewport(0,0,XSize,XSize);//*/
|
|
// pLDS->HasHooked = 0;
|
|
}
|
|
|
|
//DI->AfterEffect(0,0,0.01f,0.0f);
|
|
}
|
|
LastMB = GetAsyncKeyState(VK_MBUTTON);
|
|
} else
|
|
if (pLDS)
|
|
LUA_DEBUG_CLEAN();
|
|
}
|
|
|
|
bool debuggingFile = false;
|
|
char debuggingStr[1024] = "";
|
|
|
|
#define DBG_FILE "DBGInfo.txt"
|
|
u32 FILEIO_IsModePackedEXE();
|
|
void SaveDBGInfo(char *text)
|
|
{
|
|
if (FILEIO_IsModePackedEXE()) return;
|
|
if (debuggingFile && text)
|
|
{
|
|
if (strcmp(debuggingStr, text))
|
|
{
|
|
SYSTEMTIME time;
|
|
char dateStr[128];
|
|
char timeStr[128];
|
|
char dbgPath[1024];
|
|
extern char CurrentDir[];
|
|
GetSystemTime(&time);
|
|
GetDateFormat(NULL, DATE_SHORTDATE, &time, NULL, dateStr, 128);
|
|
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &time, NULL, timeStr, 128);
|
|
|
|
sprintf(dbgPath, "%s\\%s", CurrentDir, DBG_FILE);
|
|
FILE *file = CC_fopen(dbgPath, "a+");
|
|
if (file)
|
|
{
|
|
fprintf(file, "%s|%s - %s\n", dateStr, timeStr, text);
|
|
//fprintf(file, "%s|%s|%u - %s\n", dateStr, timeStr, GetCurrentThreadId(), text);
|
|
CC_fclose(file);
|
|
}
|
|
strcpy(debuggingStr, text);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*void WORLD::LUA_DEBUG_THREAD()
|
|
{
|
|
|
|
}
|
|
*/
|
|
|