Moved initialization code into first tick.

This commit is contained in:
Kiri 2023-04-01 13:03:24 -07:00
parent fd674d870e
commit 78f4c30c2c

View File

@ -9,6 +9,7 @@ class JumperCablesMapLoader : EventHandler
{ {
Map<int, int> originalLinedefSpecials2; Map<int, int> originalLinedefSpecials2;
Array<JumperCablesDeployed> deployedCables; Array<JumperCablesDeployed> deployedCables;
bool worldScanCompleted;
static JumperCablesMapLoader Get() static JumperCablesMapLoader Get()
{ {
@ -17,21 +18,44 @@ class JumperCablesMapLoader : EventHandler
return loader; return loader;
} }
override void WorldLoaded(WorldEvent e) override void WorldUnloaded(WorldEvent e)
{ {
JumperCablesMapLoader loader = Get(); JumperCablesMapLoader loader = Get();
// Clear out anything from the last level. // Clear out anything from the last level.
deployedCables.Clear(); deployedCables.Clear();
loader.originalLinedefSpecials2.Clear(); loader.originalLinedefSpecials2.Clear();
worldScanCompleted = false;
}
// Go through all the linedefs and make note of what they're override void WorldLoaded(WorldEvent e)
// supposed to do. {
for(int k = 0; k < level.Lines.size(); k++) { // JumperCablesMapLoader loader = Get();
Line line = level.Lines[k];
if(line.special != 0) { // // Clear out anything from the last level.
loader.originalLinedefSpecials2.Insert(line.index(), line.special); // deployedCables.Clear();
// loader.originalLinedefSpecials2.Clear();
// worldScanCompleted = false;
}
override void WorldTick()
{
JumperCablesMapLoader loader = Get();
if(!loader.worldScanCompleted) {
// Go through all the linedefs and make note of what they're
// supposed to do.
for(int k = 0; k < level.Lines.size(); k++) {
Line line = level.Lines[k];
if(line.special != 0) {
loader.originalLinedefSpecials2.Insert(line.index(), line.special);
}
} }
loader.worldScanCompleted = true;
Console.printf("JMP: World scan completed.");
} }
} }
@ -57,7 +81,7 @@ class JumperCablesMapLoader : EventHandler
deployedCables.Push(cableActor); deployedCables.Push(cableActor);
// FIXME: Remove this. // FIXME: Remove this.
Console.printf("Cables registered %d\n", deployedCables.size()); // Console.printf("Cables registered %d\n", deployedCables.size());
} }
} }