by Sarah » Sat Dec 16, 2017 3:32 pm
So I'm trying to read a specific lump in a pk3 and it's not working. I am on the Dec 15th build so that's not the issue, unless it's a bug, but I'm going to assume human error for now. The file does exist, so I'm assuming I'm doing something wrong in the code. Anyone have an example of reading files in a pk3? Especially using
Wads.CheckNumForFullName() ? Or can you see what I'm doing wrong from the code below? Thanks
Note/Edit: I just realized I was still trying to use
Wads.FindLump() in my demo code. However when changing to
CheckNumForFullName() , the game stops responding and seems to consume lots of memory, after force quitting via Task Manager. I haven't tested further yet but my first thought is it's the loop.
Edit2: Updated the code here in the post. Found a
nice example from Graf here on trying to load lumps. So I've integrated it and changed my test file into more of a definition file and created a quick and dirty parser loop. Again the game behaves as stated in my first edit. This seems to be loop related. The looping function
zWindow_Init() is called from
OnRegister() , is that a problem?
Code: Select all
class zWin_Events : EventHandler
{
zWinDefs zDefs;
CVar cvZDebug;
bool bFileNamesLoaded, // true when "fileNames.zwin" has been read
bPicsLoaded; // true when file names have been loaded to NULL_ZWIN
// Primary Initialization
override void OnRegister()
{
zDefs = zWinDefs.Get();
cvZDebug = CVar.FindCVar(zDefs.zcv_Debug);
bFileNamesLoaded = bPicsLoaded = false;
consoleDebugMessage("Z-Windows Primary Handler Registered!");
zWindow_Init();
}
// Z-Window Definition Parser
void zWindow_Init()
{
consoleDebugMessage("ZWIN-PH : Z-Window Definition Parser executing.");
Array<string> fileNames;
int lump = zDefs.NO_FILE;
// Check for lump by full path
lump = Wads.CheckNumForFullName(zDefs.zfln_zWindowPath);
// Try normal lookup
if (lump == zDefs.NO_FILE)
{
consoleDebugMessage("ZWIN-PH : Full path search for window definitions failed\ntrying normal lookup.");
lump = Wads.CheckNumForName(zDefs.zfln_zWindow, Wads.ns_global);
}
//File Not Found
if (lump == zDefs.NO_FILE)
consoleDebugMessage("ZWIN-PH : NO ZWINDOW DEFINITIONS FOUND!", zDefs.FORCE);
// File was found, comence reading
else
{
consoleDebugMessage("ZWIN-PH : Storing Definition file names.");
string line = zDefs.NOTHING;
bool isMaster = false;
int reads = 0;
while (line != zDefs.FILE_END && (isMaster || reads == 0))
{
line = Wads.ReadLump(lump);
if (reads == 0 && line == zDefs.MASTER_HEADER)
{
consoleDebugMessage("ZWIN-PH : File is a valid Master.");
isMaster = true;
}
else if (isMaster && line != zDefs.FILE_END)
{
fileNames.Push(line);
if (cvZDebug.GetBool() == true)
console.printf("ZWIN-PH : File %s stored in slot %i.", fileNames[reads], reads);
reads++;
}
}
}
}
// Prints a message to the console if the debug cvar is on
// - full debug info is output if cvar is changed at titlescreen, not sure about titlemap
// - cvar is not saved to ini and is a user cvar
void consoleDebugMessage(string message, bool force = false)
{
if (cvZDebug.GetBool() || force)
Console.Printf(message);
}
override void WorldTick()
{
}
override void RenderOverlay(RenderEvent e)
{
}
}
Spoiler: Old CodeCode: Select all
class zWin_Events : EventHandler
{
zWinDefs zDefs;
CVar cvZDebug;
bool bFileNamesLoaded, // true when "fileNames.zwin" has been read
bPicsLoaded, // true when file names have been loaded to NULL_ZWIN
bZDebug; // true when debugging is on
// Primary Initialization
override void OnRegister()
{
zDefs = zWinDefs.Get();
cvZDebug = CVar.FindCVar(zDefs.zcv_Debug);
bFileNamesLoaded = bPicsLoaded = bZDebug = false;
consoleDebugMessage("Z-Windows Primary Handler Registered!");
readTest();
}
void readTest()
{
consoleDebugMessage("ZWIN-PH : Z-Window Definition Parser executing.");
int lump = -1;
while (-1 != (lump = Wads.CheckNumForFullName("zswindefs/zswindow")))
{
console.printf("%s", Wads.ReadLump(lump));
}
}
void consoleDebugMessage(string message)
{
if (cvZDebug.GetBool())
Console.Printf(message);
}
override void WorldTick()
{
}
override void RenderOverlay(RenderEvent e)
{
}
}
So I'm trying to read a specific lump in a pk3 and it's not working. I am on the Dec 15th build so that's not the issue, unless it's a bug, but I'm going to assume human error for now. The file does exist, so I'm assuming I'm doing something wrong in the code. Anyone have an example of reading files in a pk3? Especially using [b]Wads.CheckNumForFullName()[/b]? Or can you see what I'm doing wrong from the code below? Thanks :D Note/Edit: I just realized I was still trying to use [b]Wads.FindLump()[/b] in my demo code. However when changing to [b]CheckNumForFullName()[/b], the game stops responding and seems to consume lots of memory, after force quitting via Task Manager. I haven't tested further yet but my first thought is it's the loop. Edit2: Updated the code here in the post. Found a [url=https://forum.zdoom.org/viewtopic.php?f=18&t=15535&p=311745&hilit=wads.checknumforfullname#p311745]nice example from Graf here[/url] on trying to load lumps. So I've integrated it and changed my test file into more of a definition file and created a quick and dirty parser loop. Again the game behaves as stated in my first edit. This seems to be loop related. The looping function [b]zWindow_Init()[/b] is called from [b]OnRegister()[/b], is that a problem? [code]class zWin_Events : EventHandler { zWinDefs zDefs; CVar cvZDebug; bool bFileNamesLoaded, // true when "fileNames.zwin" has been read bPicsLoaded; // true when file names have been loaded to NULL_ZWIN // Primary Initialization override void OnRegister() { zDefs = zWinDefs.Get(); cvZDebug = CVar.FindCVar(zDefs.zcv_Debug); bFileNamesLoaded = bPicsLoaded = false; consoleDebugMessage("Z-Windows Primary Handler Registered!"); zWindow_Init(); } // Z-Window Definition Parser void zWindow_Init() { consoleDebugMessage("ZWIN-PH : Z-Window Definition Parser executing."); Array<string> fileNames; int lump = zDefs.NO_FILE; // Check for lump by full path lump = Wads.CheckNumForFullName(zDefs.zfln_zWindowPath); // Try normal lookup if (lump == zDefs.NO_FILE) { consoleDebugMessage("ZWIN-PH : Full path search for window definitions failed\ntrying normal lookup."); lump = Wads.CheckNumForName(zDefs.zfln_zWindow, Wads.ns_global); } //File Not Found if (lump == zDefs.NO_FILE) consoleDebugMessage("ZWIN-PH : NO ZWINDOW DEFINITIONS FOUND!", zDefs.FORCE); // File was found, comence reading else { consoleDebugMessage("ZWIN-PH : Storing Definition file names."); string line = zDefs.NOTHING; bool isMaster = false; int reads = 0; while (line != zDefs.FILE_END && (isMaster || reads == 0)) { line = Wads.ReadLump(lump); if (reads == 0 && line == zDefs.MASTER_HEADER) { consoleDebugMessage("ZWIN-PH : File is a valid Master."); isMaster = true; } else if (isMaster && line != zDefs.FILE_END) { fileNames.Push(line); if (cvZDebug.GetBool() == true) console.printf("ZWIN-PH : File %s stored in slot %i.", fileNames[reads], reads); reads++; } } } } // Prints a message to the console if the debug cvar is on // - full debug info is output if cvar is changed at titlescreen, not sure about titlemap // - cvar is not saved to ini and is a user cvar void consoleDebugMessage(string message, bool force = false) { if (cvZDebug.GetBool() || force) Console.Printf(message); } override void WorldTick() { } override void RenderOverlay(RenderEvent e) { } }[/code] [spoiler="Old Code"][code]class zWin_Events : EventHandler { zWinDefs zDefs; CVar cvZDebug; bool bFileNamesLoaded, // true when "fileNames.zwin" has been read bPicsLoaded, // true when file names have been loaded to NULL_ZWIN bZDebug; // true when debugging is on // Primary Initialization override void OnRegister() { zDefs = zWinDefs.Get(); cvZDebug = CVar.FindCVar(zDefs.zcv_Debug); bFileNamesLoaded = bPicsLoaded = bZDebug = false; consoleDebugMessage("Z-Windows Primary Handler Registered!"); readTest(); } void readTest() { consoleDebugMessage("ZWIN-PH : Z-Window Definition Parser executing."); int lump = -1; while (-1 != (lump = Wads.CheckNumForFullName("zswindefs/zswindow"))) { console.printf("%s", Wads.ReadLump(lump)); } } void consoleDebugMessage(string message) { if (cvZDebug.GetBool()) Console.Printf(message); } override void WorldTick() { } override void RenderOverlay(RenderEvent e) { } }[/code][/spoiler]