Fix SOC/Lua loading messages to display full names or even display at all (for PK3s at least), and otherwise some cleanup of existing code for the messages.

Also, I moved lua_lumploading on/offing to LUA_LoadFile.
This commit is contained in:
Monster Iestyn 2018-02-09 22:43:08 +00:00
parent b533d36143
commit 8556a05668
2 changed files with 34 additions and 17 deletions

View File

@ -176,11 +176,16 @@ static inline void LUA_LoadFile(MYFILE *f, char *name)
LUA_ClearState();
lua_pushinteger(gL, f->wad);
lua_setfield(gL, LUA_REGISTRYINDEX, "WAD");
lua_lumploading = true; // turn on loading flag
if (luaL_loadbuffer(gL, f->data, f->size, va("@%s",name)) || lua_pcall(gL, 0, 0, 0)) {
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL,-1));
lua_pop(gL,1);
}
lua_gc(gL, LUA_GCCOLLECT, 0);
lua_lumploading = false; // turn off again
}
// Load a script from a lump
@ -188,24 +193,28 @@ void LUA_LoadLump(UINT16 wad, UINT16 lump)
{
MYFILE f;
char *name;
f.wad = wad;
f.size = W_LumpLengthPwad(wad, lump);
f.data = Z_Malloc(f.size, PU_LUA, NULL);
W_ReadLumpPwad(wad, lump, f.data);
f.curpos = f.data;
name = malloc(strlen(wadfiles[wad]->filename)+10);
strcpy(name, wadfiles[wad]->filename);
if (!fasticmp(&name[strlen(name) - 4], ".lua")) {
// If it's not a .lua file, copy the lump name in too.
name[strlen(wadfiles[wad]->filename)] = '|';
M_Memcpy(name+strlen(wadfiles[wad]->filename)+1, wadfiles[wad]->lumpinfo[lump].name, 8);
name[strlen(wadfiles[wad]->filename)+9] = '\0';
if (wadfiles[wad]->type == RET_LUA)
{
name = malloc(strlen(wadfiles[wad]->filename)+1);
strcpy(name, wadfiles[wad]->filename);
}
else // If it's not a .lua file, copy the lump name in too.
{
lumpinfo_t *lump_p = &wadfiles[wad]->lumpinfo[lump];
size_t length = strlen(wadfiles[wad]->filename) + 1 + strlen(lump_p->name2); // length of file name, '|', and lump name
name = malloc(length + 1);
sprintf(name, "%s|%s", wadfiles[wad]->filename, lump_p->name2);
name[length] = '\0';
}
lua_lumploading = true; // turn on loading flag
LUA_LoadFile(&f, name); // actually load file!
lua_lumploading = false; // turn off again
free(name);
Z_Free(f.data);

View File

@ -198,7 +198,17 @@ static inline void W_LoadDehackedLumpsPK3(UINT16 wadnum)
{
posEnd = W_CheckNumForFolderEndPK3("SOCs/", wadnum, posStart);
for(; posStart < posEnd; posStart++)
{
lumpinfo_t *lump_p = &wadfiles[wadnum]->lumpinfo[posStart];
size_t length = strlen(wadfiles[wadnum]->filename) + 1 + strlen(lump_p->name2); // length of file name, '|', and lump name
char *name = malloc(length + 1);
sprintf(name, "%s|%s", wadfiles[wadnum]->filename, lump_p->name2);
name[length] = '\0';
CONS_Printf(M_GetText("Loading SOC from %s\n"), name);
DEH_LoadDehackedLumpPwad(wadnum, posStart);
free(name);
}
}
}
@ -222,16 +232,14 @@ static inline void W_LoadDehackedLumps(UINT16 wadnum)
for (lump = 0; lump < wadfiles[wadnum]->numlumps; lump++, lump_p++)
if (memcmp(lump_p->name,"SOC_",4)==0) // Check for generic SOC lump
{ // shameless copy+paste of code from LUA_LoadLump
char *name = malloc(strlen(wadfiles[wadnum]->filename)+10);
strcpy(name, wadfiles[wadnum]->filename);
/*if (!fasticmp(&name[strlen(name) - 4], ".soc"))*/ {
// If it's not a .soc file, copy the lump name in too.
name[strlen(wadfiles[wadnum]->filename)] = '|';
M_Memcpy(name+strlen(wadfiles[wadnum]->filename)+1, lump_p->name, 8);
name[strlen(wadfiles[wadnum]->filename)+9] = '\0';
}
size_t length = strlen(wadfiles[wadnum]->filename) + 1 + strlen(lump_p->name2); // length of file name, '|', and lump name
char *name = malloc(length + 1);
sprintf(name, "%s|%s", wadfiles[wadnum]->filename, lump_p->name2);
name[length] = '\0';
CONS_Printf(M_GetText("Loading SOC from %s\n"), name);
DEH_LoadDehackedLumpPwad(wadnum, lump);
free(name);
}
else if (memcmp(lump_p->name,"MAINCFG",8)==0) // Check for MAINCFG
{