diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index acb9c860e8..2fcb444772 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1168,7 +1168,6 @@ set (PCH_SOURCES p_udmf.cpp p_usdf.cpp p_user.cpp - p_writemap.cpp p_xlat.cpp parsecontext.cpp po_man.cpp diff --git a/src/actor.h b/src/actor.h index 439ae2644c..d4f5f27c5a 100644 --- a/src/actor.h +++ b/src/actor.h @@ -779,14 +779,7 @@ public: // set translation void SetTranslation(FName trname); - double GetBobOffset(double ticfrac = 0) const - { - if (!(flags2 & MF2_FLOATBOB)) - { - return 0; - } - return BobSin(FloatBobPhase + level.maptime + ticfrac); - } + double GetBobOffset(double ticfrac = 0) const; // Enter the crash state void Crash(); diff --git a/src/am_map.cpp b/src/am_map.cpp index 9f68f944ee..09ca93b965 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -70,6 +70,7 @@ #include "po_man.h" #include "a_keys.h" #include "r_data/colormaps.h" +#include "g_levellocals.h" //============================================================================= @@ -601,23 +602,21 @@ CUSTOM_CVAR (Int, am_showalllines, -1, 0) // This is a cheat so don't save it. { int flagged = 0; int total = 0; - if (self > 0 && numlines > 0) + if (self > 0 && level.lines.Size() > 0) { - for(int i=0;ifrontsector == line->backsector) continue; + if (line.frontsector == line.backsector) continue; // disregard control sectors for deep water - if (line->frontsector->e->FakeFloor.Sectors.Size() > 0) continue; + if (line.frontsector->e->FakeFloor.Sectors.Size() > 0) continue; // disregard control sectors for 3D-floors - if (line->frontsector->e->XFloor.attached.Size() > 0) continue; + if (line.frontsector->e->XFloor.attached.Size() > 0) continue; total++; - if (line->flags & ML_DONTDRAW) flagged++; + if (line.flags & ML_DONTDRAW) flagged++; } am_showallenabled = (flagged * 100 / total >= self); } @@ -1030,17 +1029,17 @@ static void AM_findMinMaxBoundaries () min_x = min_y = FLT_MAX; max_x = max_y = FIXED_MIN; - for (int i = 0; i < numvertexes; i++) + for (auto &vert : level.vertexes) { - if (vertexes[i].fX() < min_x) - min_x = vertexes[i].fX(); - else if (vertexes[i].fX() > max_x) - max_x = vertexes[i].fX(); + if (vert.fX() < min_x) + min_x = vert.fX(); + else if (vert.fX() > max_x) + max_x = vert.fX(); - if (vertexes[i].fY() < min_y) - min_y = vertexes[i].fY(); - else if (vertexes[i].fY() > max_y) - max_y = vertexes[i].fY(); + if (vert.fY() < min_y) + min_y = vert.fY(); + else if (vert.fY() > max_y) + max_y = vert.fY(); } max_w = max_x - min_x; @@ -2382,7 +2381,6 @@ bool AM_isLockBoundary (line_t &line, int *lockptr = NULL) void AM_drawWalls (bool allmap) { - int i; static mline_t l; int lock, color; @@ -2393,18 +2391,18 @@ void AM_drawWalls (bool allmap) if (p == MapPortalGroup) continue; - for (i = 0; i < numlines; i++) + for (auto &line : level.lines) { int pg; - if (lines[i].sidedef[0]->Flags & WALLF_POLYOBJ) + if (line.sidedef[0]->Flags & WALLF_POLYOBJ) { // For polyobjects we must test the surrounding sector to get the proper group. - pg = P_PointInSector(lines[i].v1->fX() + lines[i].Delta().X / 2, lines[i].v1->fY() + lines[i].Delta().Y / 2)->PortalGroup; + pg = P_PointInSector(line.v1->fX() + line.Delta().X / 2, line.v1->fY() + line.Delta().Y / 2)->PortalGroup; } else { - pg = lines[i].frontsector->PortalGroup; + pg = line.frontsector->PortalGroup; } DVector2 offset; bool portalmode = numportalgroups > 0 && pg != MapPortalGroup; @@ -2418,10 +2416,10 @@ void AM_drawWalls (bool allmap) } else continue; - l.a.x = (lines[i].v1->fX() + offset.X); - l.a.y = (lines[i].v1->fY() + offset.Y); - l.b.x = (lines[i].v2->fX() + offset.X); - l.b.y = (lines[i].v2->fY() + offset.Y); + l.a.x = (line.v1->fX() + offset.X); + l.a.y = (line.v1->fY() + offset.Y); + l.b.x = (line.v2->fX() + offset.X); + l.b.y = (line.v2->fY() + offset.Y); if (am_rotate == 1 || (am_rotate == 2 && viewactive)) { @@ -2429,9 +2427,9 @@ void AM_drawWalls (bool allmap) AM_rotatePoint(&l.b.x, &l.b.y); } - if (am_cheat != 0 || (lines[i].flags & ML_MAPPED)) + if (am_cheat != 0 || (line.flags & ML_MAPPED)) { - if ((lines[i].flags & ML_DONTDRAW) && (am_cheat == 0 || am_cheat >= 4)) + if ((line.flags & ML_DONTDRAW) && (am_cheat == 0 || am_cheat >= 4)) { if (!am_showallenabled || CheckCheatmode(false)) { @@ -2443,27 +2441,27 @@ void AM_drawWalls (bool allmap) { AM_drawMline(&l, AMColors.PortalColor); } - else if (AM_CheckSecret(&lines[i])) + else if (AM_CheckSecret(&line)) { // map secret sectors like Boom AM_drawMline(&l, AMColors.SecretSectorColor); } - else if (lines[i].flags & ML_SECRET) + else if (line.flags & ML_SECRET) { // secret door - if (am_cheat != 0 && lines[i].backsector != NULL) + if (am_cheat != 0 && line.backsector != NULL) AM_drawMline(&l, AMColors.SecretWallColor); else AM_drawMline(&l, AMColors.WallColor); } - else if (AM_isTeleportBoundary(lines[i]) && AMColors.isValid(AMColors.IntraTeleportColor)) + else if (AM_isTeleportBoundary(line) && AMColors.isValid(AMColors.IntraTeleportColor)) { // intra-level teleporters AM_drawMline(&l, AMColors.IntraTeleportColor); } - else if (AM_isExitBoundary(lines[i]) && AMColors.isValid(AMColors.InterTeleportColor)) + else if (AM_isExitBoundary(line) && AMColors.isValid(AMColors.InterTeleportColor)) { // inter-level/game-ending teleporters AM_drawMline(&l, AMColors.InterTeleportColor); } - else if (AM_isLockBoundary(lines[i], &lock)) + else if (AM_isLockBoundary(line, &lock)) { if (AMColors.displayLocks) { @@ -2483,25 +2481,25 @@ void AM_drawWalls (bool allmap) } else if (am_showtriggerlines && AMColors.isValid(AMColors.SpecialWallColor) - && AM_isTriggerBoundary(lines[i])) + && AM_isTriggerBoundary(line)) { AM_drawMline(&l, AMColors.SpecialWallColor); // wall with special non-door action the player can do } - else if (lines[i].backsector == NULL) + else if (line.backsector == NULL) { AM_drawMline(&l, AMColors.WallColor); // one-sided wall } - else if (lines[i].backsector->floorplane - != lines[i].frontsector->floorplane) + else if (line.backsector->floorplane + != line.frontsector->floorplane) { AM_drawMline(&l, AMColors.FDWallColor); // floor level change } - else if (lines[i].backsector->ceilingplane - != lines[i].frontsector->ceilingplane) + else if (line.backsector->ceilingplane + != line.frontsector->ceilingplane) { AM_drawMline(&l, AMColors.CDWallColor); // ceiling level change } - else if (AM_Check3DFloors(&lines[i])) + else if (AM_Check3DFloors(&line)) { AM_drawMline(&l, AMColors.EFWallColor); // Extra floor border } @@ -2512,7 +2510,7 @@ void AM_drawWalls (bool allmap) } else if (allmap) { - if ((lines[i].flags & ML_DONTDRAW) && (am_cheat == 0 || am_cheat >= 4)) + if ((line.flags & ML_DONTDRAW) && (am_cheat == 0 || am_cheat >= 4)) { if (!am_showallenabled || CheckCheatmode(false)) { diff --git a/src/bbannouncer.cpp b/src/bbannouncer.cpp index a19ba72f42..6fbf314793 100644 --- a/src/bbannouncer.cpp +++ b/src/bbannouncer.cpp @@ -49,6 +49,7 @@ #include "d_player.h" #include "g_level.h" #include "doomstat.h" +#include "g_levellocals.h" // MACROS ------------------------------------------------------------------ diff --git a/src/c_cmds.cpp b/src/c_cmds.cpp index 2923a8ae81..be4944b8c9 100644 --- a/src/c_cmds.cpp +++ b/src/c_cmds.cpp @@ -72,6 +72,7 @@ #include "r_utility.h" #include "r_data/r_interpolate.h" #include "c_functions.h" +#include "g_levellocals.h" extern FILE *Logfile; extern bool insave; diff --git a/src/c_console.cpp b/src/c_console.cpp index 0e9b949966..8bf7f4cd9c 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -67,6 +67,7 @@ #include "d_player.h" #include "gstrings.h" #include "c_consolebuffer.h" +#include "g_levellocals.h" #include "gi.h" diff --git a/src/compatibility.cpp b/src/compatibility.cpp index 8f4472c856..0b27a1efa0 100644 --- a/src/compatibility.cpp +++ b/src/compatibility.cpp @@ -52,6 +52,7 @@ #include "p_tags.h" #include "r_state.h" #include "w_wad.h" +#include "g_levellocals.h" // MACROS ------------------------------------------------------------------ @@ -475,9 +476,9 @@ void SetCompatibilityParams() { case CP_CLEARFLAGS: { - if (CompatParams[i+1] < numlines) + if ((unsigned)CompatParams[i+1] < level.lines.Size()) { - line_t *line = &lines[CompatParams[i+1]]; + line_t *line = &level.lines[CompatParams[i+1]]; line->flags &= ~CompatParams[i+2]; } i+=3; @@ -485,9 +486,9 @@ void SetCompatibilityParams() } case CP_SETFLAGS: { - if (CompatParams[i+1] < numlines) + if ((unsigned)CompatParams[i+1] < level.lines.Size()) { - line_t *line = &lines[CompatParams[i+1]]; + line_t *line = &level.lines[CompatParams[i+1]]; line->flags |= CompatParams[i+2]; } i+=3; @@ -495,9 +496,9 @@ void SetCompatibilityParams() } case CP_SETSPECIAL: { - if (CompatParams[i+1] < numlines) + if ((unsigned)CompatParams[i+1] < level.lines.Size()) { - line_t *line = &lines[CompatParams[i+1]]; + line_t *line = &level.lines[CompatParams[i+1]]; line->special = CompatParams[i+2]; for(int ii=0;ii<5;ii++) { @@ -509,9 +510,9 @@ void SetCompatibilityParams() } case CP_CLEARSPECIAL: { - if (CompatParams[i+1] < numlines) + if ((unsigned)CompatParams[i+1] < level.lines.Size()) { - line_t *line = &lines[CompatParams[i+1]]; + line_t *line = &level.lines[CompatParams[i+1]]; line->special = 0; memset(line->args, 0, sizeof(line->args)); } @@ -520,9 +521,9 @@ void SetCompatibilityParams() } case CP_SETACTIVATION: { - if (CompatParams[i+1] < numlines) + if ((unsigned)CompatParams[i+1] < level.lines.Size()) { - line_t *line = &lines[CompatParams[i+1]]; + line_t *line = &level.lines[CompatParams[i+1]]; line->activation = CompatParams[i+2]; } i += 3; @@ -552,9 +553,9 @@ void SetCompatibilityParams() } case CP_SETWALLYSCALE: { - if (CompatParams[i+1] < numlines) + if ((unsigned)CompatParams[i+1] < level.lines.Size()) { - side_t *side = lines[CompatParams[i+1]].sidedef[CompatParams[i+2]]; + side_t *side = level.lines[CompatParams[i+1]].sidedef[CompatParams[i+2]]; if (side != NULL) { side->SetTextureYScale(CompatParams[i+3], CompatParams[i+4] / 65536.); diff --git a/src/d_main.cpp b/src/d_main.cpp index 1ea2d2707c..2c6b1c9e96 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -109,6 +109,7 @@ #include "p_local.h" #include "autosegs.h" #include "fragglescript/t_fs.h" +#include "g_levellocals.h" EXTERN_CVAR(Bool, hud_althud) void DrawHUD(); diff --git a/src/d_net.cpp b/src/d_net.cpp index 4bda255103..0ebb7de383 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -63,6 +63,7 @@ #include "r_utility.h" #include "a_keys.h" #include "intermission/intermission.h" +#include "g_levellocals.h" EXTERN_CVAR (Int, disableautosave) EXTERN_CVAR (Int, autosavecount) diff --git a/src/decallib.cpp b/src/decallib.cpp index 7bfdfc3e73..52a4eadf5b 100644 --- a/src/decallib.cpp +++ b/src/decallib.cpp @@ -49,6 +49,7 @@ #include "colormatcher.h" #include "b_bot.h" #include "serializer.h" +#include "g_levellocals.h" FDecalLib DecalLibrary; diff --git a/src/dobject.cpp b/src/dobject.cpp index c6e20be5e6..b96cc5ff9f 100644 --- a/src/dobject.cpp +++ b/src/dobject.cpp @@ -49,6 +49,7 @@ #include "dsectoreffect.h" #include "serializer.h" #include "virtual.h" +#include "g_levellocals.h" //========================================================================== // diff --git a/src/dobjgc.cpp b/src/dobjgc.cpp index 11cfdc8c27..625f806785 100644 --- a/src/dobjgc.cpp +++ b/src/dobjgc.cpp @@ -77,6 +77,7 @@ #include "r_utility.h" #include "menu/menu.h" #include "intermission/intermission.h" +#include "g_levellocals.h" // MACROS ------------------------------------------------------------------ @@ -709,15 +710,15 @@ size_t DSectorMarker::PropagateMark() moretodo = true; } } - if (!moretodo && sides != NULL) + if (!moretodo && level.sides.Size() > 0) { - for (i = 0; i < SIDEDEFSTEPSIZE && SideNum + i < numsides; ++i) + for (i = 0; i < SIDEDEFSTEPSIZE && SideNum + i < (int)level.sides.Size(); ++i) { - side_t *side = &sides[SideNum + i]; + side_t *side = &level.sides[SideNum + i]; for(int j=0;j<3;j++) GC::Mark(side->textures[j].interpolation); } marked += i * sizeof(side_t); - if (SideNum + i < numsides) + if (SideNum + i < (int)level.sides.Size()) { SideNum += i; moretodo = true; diff --git a/src/doomstat.cpp b/src/doomstat.cpp index 87ca50a168..3093983318 100644 --- a/src/doomstat.cpp +++ b/src/doomstat.cpp @@ -29,6 +29,7 @@ #include "i_system.h" #include "g_level.h" #include "p_local.h" +#include "g_levellocals.h" int SaveVersion; diff --git a/src/edata.cpp b/src/edata.cpp index 258c2a187d..015be0bb17 100644 --- a/src/edata.cpp +++ b/src/edata.cpp @@ -49,6 +49,7 @@ #include "v_palette.h" #include "p_acs.h" #include "r_data/colormaps.h" +#include "g_levellocals.h" struct FEDOptions : public FOptionalMapinfoData @@ -705,7 +706,7 @@ void ProcessEDLinedef(line_t *ld, int recordnum) ld->flags = (ld->flags&~fmask) | eld->flags; ld->setAlpha(eld->alpha); memcpy(ld->args, eld->args, sizeof(ld->args)); - tagManager.AddLineID(int(ld - lines), eld->tag); + tagManager.AddLineID(ld->Index(), eld->tag); } void ProcessEDSector(sector_t *sec, int recordnum) @@ -760,12 +761,12 @@ void ProcessEDSectors() auto numsectors = level.sectors.Size(); int *sectorrecord = new int[numsectors]; memset(sectorrecord, -1, numsectors * sizeof(int)); - for (int i = 0; i < numlines; i++) + for (auto &line : level.lines) { - if (lines[i].special == Static_Init && lines[i].args[1] == Init_EDSector) + if (line.special == Static_Init && line.args[1] == Init_EDSector) { - sectorrecord[lines[i].frontsector->Index()] = lines[i].args[0]; - lines[i].special = 0; + sectorrecord[line.frontsector->Index()] = line.args[0]; + line.special = 0; } } for (unsigned i = 0; i < numsectors; i++) diff --git a/src/fragglescript/t_cmd.cpp b/src/fragglescript/t_cmd.cpp index 1434870d1b..6917400243 100644 --- a/src/fragglescript/t_cmd.cpp +++ b/src/fragglescript/t_cmd.cpp @@ -48,6 +48,7 @@ #include "g_level.h" #include "r_renderer.h" #include "d_player.h" +#include "g_levellocals.h" //========================================================================== // diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index 080adbd46f..514d9aaea9 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -71,6 +71,7 @@ #include "r_utility.h" #include "a_ammo.h" #include "math/cmath.h" +#include "g_levellocals.h" static FRandom pr_script("FScript"); @@ -2171,7 +2172,7 @@ void FParser::SF_SetLineBlocking(void) int i; while ((i = itr.Next()) >= 0) { - lines[i].flags = (lines[i].flags & ~(ML_BLOCKING | ML_BLOCKEVERYTHING)) | blocking; + level.lines[i].flags = (level.lines[i].flags & ~(ML_BLOCKING | ML_BLOCKEVERYTHING)) | blocking; } } } @@ -2194,7 +2195,7 @@ void FParser::SF_SetLineMonsterBlocking(void) int i; while ((i = itr.Next()) >= 0) { - lines[i].flags = (lines[i].flags & ~ML_BLOCKMONSTERS) | blocking; + level.lines[i].flags = (level.lines[i].flags & ~ML_BLOCKMONSTERS) | blocking; } } } @@ -2251,11 +2252,11 @@ void FParser::SF_SetLineTexture(void) while ((i = itr.Next()) >= 0) { // bad sidedef, Hexen just SEGV'd here! - if (lines[i].sidedef[side] != NULL) + if (level.lines[i].sidedef[side] != NULL) { if (position >= 0 && position <= 2) { - lines[i].sidedef[side]->SetTexture(position, texturenum); + level.lines[i].sidedef[side]->SetTexture(position, texturenum); } } } @@ -2270,7 +2271,7 @@ void FParser::SF_SetLineTexture(void) FLineIdIterator itr(tag); while ((i = itr.Next()) >= 0) { - side_t *sided = lines[i].sidedef[side]; + side_t *sided = level.lines[i].sidedef[side]; if(sided != NULL) { if(sections & 1) sided->SetTexture(side_t::top, picnum); @@ -3363,19 +3364,19 @@ void FParser::SF_ObjState() void FParser::SF_LineFlag() { line_t* line; - int linenum; + unsigned linenum; int flagnum; if (CheckArgs(2)) { linenum = intvalue(t_argv[0]); - if(linenum < 0 || linenum > numlines) + if(linenum >= level.lines.Size()) { script_error("LineFlag: Invalid line number.\n"); return; } - line = lines + linenum; + line = &level.lines[linenum]; flagnum = intvalue(t_argv[1]); if(flagnum < 0 || (flagnum > 8 && flagnum!=15)) @@ -3987,9 +3988,9 @@ void FParser::SF_SetLineTrigger() mld.special = spec; mld.tag = tag; mld.flags = 0; - int f = lines[i].flags; - P_TranslateLineDef(&lines[i], &mld); - lines[i].flags = (lines[i].flags & (ML_MONSTERSCANACTIVATE | ML_REPEAT_SPECIAL | ML_SPAC_MASK | ML_FIRSTSIDEONLY)) | + int f = level.lines[i].flags; + P_TranslateLineDef(&level.lines[i], &mld); + level.lines[i].flags = (level.lines[i].flags & (ML_MONSTERSCANACTIVATE | ML_REPEAT_SPECIAL | ML_SPAC_MASK | ML_FIRSTSIDEONLY)) | (f & ~(ML_MONSTERSCANACTIVATE | ML_REPEAT_SPECIAL | ML_SPAC_MASK | ML_FIRSTSIDEONLY)); } diff --git a/src/fragglescript/t_load.cpp b/src/fragglescript/t_load.cpp index 0f3d8417b2..b3b38543d9 100644 --- a/src/fragglescript/t_load.cpp +++ b/src/fragglescript/t_load.cpp @@ -43,6 +43,7 @@ #include "cmdlib.h" #include "p_lnspec.h" #include "gi.h" +#include "g_levellocals.h" #include "xlat/xlat.h" void T_Init(); diff --git a/src/fragglescript/t_script.cpp b/src/fragglescript/t_script.cpp index 0469e50633..b5c21632b0 100644 --- a/src/fragglescript/t_script.cpp +++ b/src/fragglescript/t_script.cpp @@ -55,6 +55,7 @@ #include "doomerrors.h" #include "doomstat.h" #include "serializer.h" +#include "g_levellocals.h" //========================================================================== // diff --git a/src/g_game.cpp b/src/g_game.cpp index d803601937..6565d53244 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -91,6 +91,7 @@ #include #include "g_hub.h" +#include "g_levellocals.h" static FRandom pr_dmspawn ("DMSpawn"); @@ -2241,7 +2242,7 @@ void G_DoSaveGame (bool okForQuicksave, FString filename, const char *descriptio // Do not even try, if we're not in a level. (Can happen after // a demo finishes playback.) - if (lines == NULL || level.sectors.Size() == 0 || gamestate != GS_LEVEL) + if (level.lines.Size() == 0 || level.sectors.Size() == 0 || gamestate != GS_LEVEL) { return; } diff --git a/src/g_hub.cpp b/src/g_hub.cpp index cabcef2d3c..e87dcff7d9 100644 --- a/src/g_hub.cpp +++ b/src/g_hub.cpp @@ -44,6 +44,7 @@ #include "gstrings.h" #include "wi_stuff.h" #include "serializer.h" +#include "g_levellocals.h" //========================================================================== diff --git a/src/g_inventory/a_artifacts.cpp b/src/g_inventory/a_artifacts.cpp index c859666d44..80ddac56d1 100644 --- a/src/g_inventory/a_artifacts.cpp +++ b/src/g_inventory/a_artifacts.cpp @@ -22,6 +22,7 @@ #include "serializer.h" #include "r_utility.h" #include "virtual.h" +#include "g_levellocals.h" #include "r_data/colormaps.h" diff --git a/src/g_inventory/a_pickups.cpp b/src/g_inventory/a_pickups.cpp index c963fd9184..e7a21fee60 100644 --- a/src/g_inventory/a_pickups.cpp +++ b/src/g_inventory/a_pickups.cpp @@ -22,6 +22,7 @@ #include "virtual.h" #include "a_ammo.h" #include "c_functions.h" +#include "g_levellocals.h" EXTERN_CVAR(Bool, sv_unlimited_pickup) diff --git a/src/g_level.cpp b/src/g_level.cpp index b0636d4d68..7e60a7ac99 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -88,6 +88,7 @@ #include "gi.h" #include "g_hub.h" +#include "g_levellocals.h" #include diff --git a/src/g_level.h b/src/g_level.h index 5808df138a..6274c22b03 100644 --- a/src/g_level.h +++ b/src/g_level.h @@ -376,77 +376,6 @@ struct level_info_t } }; -struct FLevelLocals -{ - void Tick (); - void AddScroller (int secnum); - - BYTE md5[16]; // for savegame validation. If the MD5 does not match the savegame won't be loaded. - int time; // time in the hub - int maptime; // time in the map - int totaltime; // time in the game - int starttime; - int partime; - int sucktime; - - level_info_t *info; - int cluster; - int clusterflags; - int levelnum; - int lumpnum; - FString LevelName; - FString MapName; // the lump name (E1M1, MAP01, etc) - FString NextMap; // go here when using the regular exit - FString NextSecretMap; // map to go to when used secret exit - EMapType maptype; - - TStaticArray sectors; - - DWORD flags; - DWORD flags2; - DWORD flags3; - - DWORD fadeto; // The color the palette fades to (usually black) - DWORD outsidefog; // The fog for sectors with sky ceilings - - FString Music; - int musicorder; - int cdtrack; - unsigned int cdid; - FTextureID skytexture1; - FTextureID skytexture2; - - float skyspeed1; // Scrolling speed of sky textures, in pixels per ms - float skyspeed2; - - int total_secrets; - int found_secrets; - - int total_items; - int found_items; - - int total_monsters; - int killed_monsters; - - double gravity; - double aircontrol; - double airfriction; - int airsupply; - int DefaultEnvironment; // Default sound environment. - - TArray Scrolls; // NULL if no DScrollers in this level - - SBYTE WallVertLight; // Light diffs for vert/horiz walls - SBYTE WallHorizLight; - - bool FromSnapshot; // The current map was restored from a snapshot - - double teamdamage; - - bool IsJumpingAllowed() const; - bool IsCrouchingAllowed() const; - bool IsFreelookAllowed() const; -}; struct cluster_info_t { @@ -476,8 +405,6 @@ struct cluster_info_t #define CLUSTER_LOOKUPCLUSTERNAME 0x00000080 // Cluster name is the name of a language string #define CLUSTER_ALLOWINTERMISSION 0x00000100 // Allow intermissions between levels in a hub. -extern FLevelLocals level; - extern TArray wadlevelinfos; extern TArray wadclusterinfos; diff --git a/src/g_levellocals.h b/src/g_levellocals.h new file mode 100644 index 0000000000..08b18145d9 --- /dev/null +++ b/src/g_levellocals.h @@ -0,0 +1,101 @@ +#pragma once + +#include "g_level.h" +#include "r_defs.h" + +struct FLevelLocals +{ + void Tick (); + void AddScroller (int secnum); + + BYTE md5[16]; // for savegame validation. If the MD5 does not match the savegame won't be loaded. + int time; // time in the hub + int maptime; // time in the map + int totaltime; // time in the game + int starttime; + int partime; + int sucktime; + + level_info_t *info; + int cluster; + int clusterflags; + int levelnum; + int lumpnum; + FString LevelName; + FString MapName; // the lump name (E1M1, MAP01, etc) + FString NextMap; // go here when using the regular exit + FString NextSecretMap; // map to go to when used secret exit + EMapType maptype; + + TStaticArray vertexes; + TStaticArray sectors; + TStaticArray lines; + TStaticArray sides; + + DWORD flags; + DWORD flags2; + DWORD flags3; + + DWORD fadeto; // The color the palette fades to (usually black) + DWORD outsidefog; // The fog for sectors with sky ceilings + + FString Music; + int musicorder; + int cdtrack; + unsigned int cdid; + FTextureID skytexture1; + FTextureID skytexture2; + + float skyspeed1; // Scrolling speed of sky textures, in pixels per ms + float skyspeed2; + + int total_secrets; + int found_secrets; + + int total_items; + int found_items; + + int total_monsters; + int killed_monsters; + + double gravity; + double aircontrol; + double airfriction; + int airsupply; + int DefaultEnvironment; // Default sound environment. + + TArray Scrolls; // NULL if no DScrollers in this level + + SBYTE WallVertLight; // Light diffs for vert/horiz walls + SBYTE WallHorizLight; + + bool FromSnapshot; // The current map was restored from a snapshot + + double teamdamage; + + bool IsJumpingAllowed() const; + bool IsCrouchingAllowed() const; + bool IsFreelookAllowed() const; +}; + +extern FLevelLocals level; + +inline int vertex_t::Index() const +{ + return int(this - &level.vertexes[0]); +} + +inline int side_t::Index() const +{ + return int(this - &level.sides[0]); +} + +inline int line_t::Index() const +{ + return int(this - &level.lines[0]); +} + +inline int sector_t::Index() const +{ + return int(this - &level.sectors[0]); +} diff --git a/src/g_mapinfo.cpp b/src/g_mapinfo.cpp index 6a60765657..3fab0bd0d6 100644 --- a/src/g_mapinfo.cpp +++ b/src/g_mapinfo.cpp @@ -51,6 +51,7 @@ #include "autosegs.h" #include "version.h" #include "v_text.h" +#include "g_levellocals.h" TArray wadclusterinfos; TArray wadlevelinfos; diff --git a/src/g_shared/a_decals.cpp b/src/g_shared/a_decals.cpp index bfbe6d13d2..5ac3cb452c 100644 --- a/src/g_shared/a_decals.cpp +++ b/src/g_shared/a_decals.cpp @@ -47,6 +47,7 @@ #include "serializer.h" #include "doomdata.h" #include "r_state.h" +#include "g_levellocals.h" static double DecalWidth, DecalLeft, DecalRight; static double SpreadZ; @@ -415,7 +416,7 @@ void DBaseDecal::SpreadLeft (double r, vertex_t *v1, side_t *feelwall, F3DFloor double x = v1->fX(); double y = v1->fY(); - feelwall = &sides[feelwall->LeftSide]; + feelwall = &level.sides[feelwall->LeftSide]; GetWallStuff (feelwall, v1, ldx, ldy); double wallsize = Length (ldx, ldy); r += DecalLeft; @@ -455,7 +456,7 @@ void DBaseDecal::SpreadRight (double r, side_t *feelwall, double wallsize, F3DFl while (r > wallsize && feelwall->RightSide != NO_SIDE) { - feelwall = &sides[feelwall->RightSide]; + feelwall = &level.sides[feelwall->RightSide]; side_t *nextwall = NextWall (feelwall); if (nextwall != NULL && nextwall->LeftSide != NO_SIDE) diff --git a/src/g_shared/a_fastprojectile.cpp b/src/g_shared/a_fastprojectile.cpp index fb0faef0fc..3bfaf8d94f 100644 --- a/src/g_shared/a_fastprojectile.cpp +++ b/src/g_shared/a_fastprojectile.cpp @@ -7,6 +7,7 @@ #include "b_bot.h" #include "p_checkposition.h" #include "virtual.h" +#include "g_levellocals.h" IMPLEMENT_CLASS(AFastProjectile, false, false) diff --git a/src/g_shared/a_flashfader.cpp b/src/g_shared/a_flashfader.cpp index 3e0b939e0f..006b7ef843 100644 --- a/src/g_shared/a_flashfader.cpp +++ b/src/g_shared/a_flashfader.cpp @@ -2,6 +2,7 @@ #include "g_level.h" #include "d_player.h" #include "serializer.h" +#include "g_levellocals.h" IMPLEMENT_CLASS(DFlashFader, false, true) diff --git a/src/g_shared/a_lightning.cpp b/src/g_shared/a_lightning.cpp index 1598b87f01..deeb8405b3 100644 --- a/src/g_shared/a_lightning.cpp +++ b/src/g_shared/a_lightning.cpp @@ -10,6 +10,7 @@ #include "g_level.h" #include "r_state.h" #include "serializer.h" +#include "g_levellocals.h" static FRandom pr_lightning ("Lightning"); diff --git a/src/g_shared/a_morph.cpp b/src/g_shared/a_morph.cpp index 935efa2db9..b48a126cd0 100644 --- a/src/g_shared/a_morph.cpp +++ b/src/g_shared/a_morph.cpp @@ -16,6 +16,7 @@ #include "d_player.h" #include "a_armor.h" #include "r_data/sprites.h" +#include "g_levellocals.h" static FRandom pr_morphmonst ("MorphMonster"); diff --git a/src/g_shared/a_movingcamera.cpp b/src/g_shared/a_movingcamera.cpp index c09d93fd55..f32550f2df 100644 --- a/src/g_shared/a_movingcamera.cpp +++ b/src/g_shared/a_movingcamera.cpp @@ -38,6 +38,7 @@ #include "p_lnspec.h" #include "doomstat.h" #include "serializer.h" +#include "g_levellocals.h" /* == InterpolationPoint: node along a camera's path diff --git a/src/g_shared/a_randomspawner.cpp b/src/g_shared/a_randomspawner.cpp index d5a396d0d9..9be5cac7b3 100644 --- a/src/g_shared/a_randomspawner.cpp +++ b/src/g_shared/a_randomspawner.cpp @@ -16,6 +16,7 @@ #include "v_text.h" #include "doomstat.h" #include "doomdata.h" +#include "g_levellocals.h" #define MAX_RANDOMSPAWNERS_RECURSION 32 // Should be largely more than enough, honestly. static FRandom pr_randomspawn("RandomSpawn"); diff --git a/src/g_shared/sbarinfo.cpp b/src/g_shared/sbarinfo.cpp index c06abf90d2..fb7d42a462 100644 --- a/src/g_shared/sbarinfo.cpp +++ b/src/g_shared/sbarinfo.cpp @@ -60,6 +60,7 @@ #include "version.h" #include "cmdlib.h" #include "a_ammo.h" +#include "g_levellocals.h" #define ARTIFLASH_OFFSET (statusBar->invBarOffset+6) enum diff --git a/src/g_shared/shared_hud.cpp b/src/g_shared/shared_hud.cpp index a061dbf59a..0c9b74255d 100644 --- a/src/g_shared/shared_hud.cpp +++ b/src/g_shared/shared_hud.cpp @@ -55,6 +55,7 @@ #include "d_player.h" #include "r_utility.h" #include "cmdlib.h" +#include "g_levellocals.h" #include diff --git a/src/g_shared/shared_sbar.cpp b/src/g_shared/shared_sbar.cpp index c288a05c86..cb3ada8e9e 100644 --- a/src/g_shared/shared_sbar.cpp +++ b/src/g_shared/shared_sbar.cpp @@ -55,6 +55,7 @@ #include "gstrings.h" #include "r_utility.h" #include "cmdlib.h" +#include "g_levellocals.h" #include "../version.h" diff --git a/src/g_skill.cpp b/src/g_skill.cpp index 70daadc23f..d158fa4cdd 100644 --- a/src/g_skill.cpp +++ b/src/g_skill.cpp @@ -43,6 +43,7 @@ #include "v_font.h" #include "m_fixed.h" #include "gstrings.h" +#include "g_levellocals.h" TArray AllSkills; int DefaultSkill = -1; diff --git a/src/g_strife/strife_sbar.cpp b/src/g_strife/strife_sbar.cpp index ccf17f8f1f..110bcfbe9c 100644 --- a/src/g_strife/strife_sbar.cpp +++ b/src/g_strife/strife_sbar.cpp @@ -19,6 +19,7 @@ #include "colormatcher.h" #include "v_palette.h" #include "cmdlib.h" +#include "g_levellocals.h" // Number of tics to move the popscreen up and down. #define POP_TIME (TICRATE/8) diff --git a/src/gl/compatibility/gl_20.cpp b/src/gl/compatibility/gl_20.cpp index 0f9ee5f43f..eeb5572c18 100644 --- a/src/gl/compatibility/gl_20.cpp +++ b/src/gl/compatibility/gl_20.cpp @@ -38,6 +38,7 @@ #include "i_system.h" #include "v_text.h" #include "r_utility.h" +#include "g_levellocals.h" #include "gl/dynlights/gl_dynlight.h" #include "gl/utility/gl_geometric.h" #include "gl/renderer/gl_renderer.h" diff --git a/src/gl/data/gl_data.cpp b/src/gl/data/gl_data.cpp index e8c5f22bb3..07fac1b2ee 100644 --- a/src/gl/data/gl_data.cpp +++ b/src/gl/data/gl_data.cpp @@ -41,6 +41,7 @@ #include "g_level.h" #include "doomstat.h" #include "d_player.h" +#include "g_levellocals.h" #include "gl/system/gl_interface.h" #include "gl/renderer/gl_renderer.h" @@ -547,7 +548,7 @@ CCMD(dumpgeometry) { Printf(PRINT_LOG, " (%4.4f, %4.4f), (%4.4f, %4.4f) - seg %d, linedef %d, side %d", seg->v1->fX(), seg->v1->fY(), seg->v2->fX(), seg->v2->fY(), - int(seg-segs), int(seg->linedef-lines), seg->sidedef != seg->linedef->sidedef[0]); + int(seg-segs), seg->linedef->Index(), seg->sidedef != seg->linedef->sidedef[0]); } else { diff --git a/src/gl/data/gl_portaldata.cpp b/src/gl/data/gl_portaldata.cpp index 71b10b4bb2..c705da5891 100644 --- a/src/gl/data/gl_portaldata.cpp +++ b/src/gl/data/gl_portaldata.cpp @@ -38,6 +38,7 @@ #include "gi.h" #include "g_level.h" #include "a_sharedglobal.h" +#include "g_levellocals.h" #include "gl/renderer/gl_renderer.h" #include "gl/data/gl_data.h" diff --git a/src/gl/data/gl_setup.cpp b/src/gl/data/gl_setup.cpp index 3fc022cf8e..6bdf57d4c3 100644 --- a/src/gl/data/gl_setup.cpp +++ b/src/gl/data/gl_setup.cpp @@ -40,6 +40,7 @@ #include "gi.h" #include "p_setup.h" #include "g_level.h" +#include "g_levellocals.h" #include "gl/renderer/gl_renderer.h" #include "gl/data/gl_data.h" @@ -402,51 +403,50 @@ static void InitVertexData() int i,j,k; - vt_sectorlists = new TArray[numvertexes]; + vt_sectorlists = new TArray[level.vertexes.Size()]; - for(i=0;iv1 : line->v2; + vertex_t * v = j==0? line.v1 : line.v2; for(k=0;k<2;k++) { - sector_t * sec = k==0? line->frontsector : line->backsector; + sector_t * sec = k==0? line.frontsector : line.backsector; if (sec) { extsector_t::xfloor &x = sec->e->XFloor; - AddToVertex(sec, vt_sectorlists[v-vertexes]); - if (sec->heightsec) AddToVertex(sec->heightsec, vt_sectorlists[v-vertexes]); + AddToVertex(sec, vt_sectorlists[v->Index()]); + if (sec->heightsec) AddToVertex(sec->heightsec, vt_sectorlists[v->Index()]); } } } } - for(i=0;i1) { - vertexes[i].numsectors= cnt; - vertexes[i].sectors=new sector_t*[cnt]; - vertexes[i].heightlist = new float[cnt*2]; + vert.numsectors= cnt; + vert.sectors=new sector_t*[cnt]; + vert.heightlist = new float[cnt*2]; for(int j=0;jsidedef[0] == &sides[sdnum]) + line_t *ln = level.sides[sdnum].linedef; + if (ln->sidedef[0] == &level.sides[sdnum]) { *v1 = ln->v1->fPos(); *v2 = ln->v2->fPos(); @@ -489,54 +489,25 @@ static int segcmp(const void *a, const void *b) static void PrepareSegs() { + auto numsides = level.sides.Size(); int *segcount = new int[numsides]; int realsegs = 0; // Get floatng point coordinates of vertices - for(int i = 0; i < numvertexes; i++) + for(auto &v : level.vertexes) { - vertexes[i].dirty = true; + v.dirty = true; } // count the segs memset(segcount, 0, numsides * sizeof(int)); - - // set up the extra data in case the map was loaded with regular nodes that might pass as GL nodes. - if (glsegextras == NULL) - { - for(int i=0;iPartnerSeg = &segs[partner]; - else seg->PartnerSeg = NULL; - seg->Subsector = glsegextras[i].Subsector; - } - } for(int i=0;isidedef == NULL) continue; // miniseg - int sidenum = int(seg->sidedef - sides); + int sidenum = seg->sidedef->Index(); realsegs++; segcount[sidenum]++; @@ -550,13 +521,13 @@ static void PrepareSegs() } // allocate memory - sides[0].segs = new seg_t*[realsegs]; - sides[0].numsegs = 0; + level.sides[0].segs = new seg_t*[realsegs]; + level.sides[0].numsegs = 0; for(int i = 1; i < numsides; i++) { - sides[i].segs = sides[i-1].segs + segcount[i-1]; - sides[i].numsegs = 0; + level.sides[i].segs = level.sides[i-1].segs + segcount[i-1]; + level.sides[i].numsegs = 0; } delete [] segcount; @@ -570,7 +541,7 @@ static void PrepareSegs() // sort the segs for(int i = 0; i < numsides; i++) { - if (sides[i].numsegs > 1) qsort(sides[i].segs, sides[i].numsegs, sizeof(seg_t*), segcmp); + if (level.sides[i].numsegs > 1) qsort(level.sides[i].segs, level.sides[i].numsegs, sizeof(seg_t*), segcmp); } } @@ -586,8 +557,8 @@ void gl_PreprocessLevel() PrepareSegs(); PrepareSectorData(); InitVertexData(); - int *checkmap = new int[numvertexes]; - memset(checkmap, -1, sizeof(int)*numvertexes); + int *checkmap = new int[level.vertexes.Size()]; + memset(checkmap, -1, sizeof(int)*level.vertexes.Size()); for(auto &sec : level.sectors) { int i = sec.sectornum; @@ -598,21 +569,21 @@ void gl_PreprocessLevel() { if (l->sidedef[0]->Flags & WALLF_POLYOBJ) continue; // don't bother with polyobjects - int vtnum1 = int(l->v1 - vertexes); - int vtnum2 = int(l->v2 - vertexes); + int vtnum1 = l->v1->Index(); + int vtnum2 = l->v2->Index(); if (checkmap[vtnum1] < i) { checkmap[vtnum1] = i; - sec.e->vertices.Push(&vertexes[vtnum1]); - vertexes[vtnum1].dirty = true; + sec.e->vertices.Push(&level.vertexes[vtnum1]); + level.vertexes[vtnum1].dirty = true; } if (checkmap[vtnum2] < i) { checkmap[vtnum2] = i; - sec.e->vertices.Push(&vertexes[vtnum2]); - vertexes[vtnum2].dirty = true; + sec.e->vertices.Push(&level.vertexes[vtnum2]); + level.vertexes[vtnum2].dirty = true; } } } @@ -652,27 +623,24 @@ void gl_CleanLevelData() mo=next; } - if (vertexes != NULL) + for(auto &v : level.vertexes) if (v.numsectors > 0) { - for(int i = 0; i < numvertexes; i++) if (vertexes[i].numsectors > 0) + if (v.sectors != nullptr) { - if (vertexes[i].sectors != NULL) - { - delete [] vertexes[i].sectors; - vertexes[i].sectors = NULL; - } - if (vertexes[i].heightlist != NULL) - { - delete [] vertexes[i].heightlist; - vertexes[i].heightlist = NULL; - } + delete [] v.sectors; + v.sectors = nullptr; + } + if (v.heightlist != nullptr) + { + delete [] v.heightlist; + v.heightlist = nullptr; } } - if (sides && sides[0].segs) + if (level.sides.Size() > 0 && level.sides[0].segs) { - delete [] sides[0].segs; - sides[0].segs = NULL; + delete [] level.sides[0].segs; + level.sides[0].segs = NULL; } if (level.sectors.Size() > 0 && level.sectors[0].subsectors) { @@ -712,7 +680,7 @@ CCMD(listmapsections) { if (subsectors[j].mapsection == i) { - Printf("Mapsection %d, sector %d, line %d\n", i, subsectors[j].render_sector->sectornum, int(subsectors[j].firstline->linedef-lines)); + Printf("Mapsection %d, sector %d, line %d\n", i, subsectors[j].render_sector->Index(), subsectors[j].firstline->linedef->Index()); break; } } diff --git a/src/gl/data/gl_vertexbuffer.cpp b/src/gl/data/gl_vertexbuffer.cpp index a645fbff4e..4973ad39de 100644 --- a/src/gl/data/gl_vertexbuffer.cpp +++ b/src/gl/data/gl_vertexbuffer.cpp @@ -31,6 +31,7 @@ #include "r_state.h" #include "m_argv.h" #include "c_cvars.h" +#include "g_levellocals.h" #include "gl/system/gl_interface.h" #include "gl/renderer/gl_renderer.h" #include "gl/shaders/gl_shader.h" diff --git a/src/gl/dynlights/a_dynlight.cpp b/src/gl/dynlights/a_dynlight.cpp index 82c8c4e54c..1283cc9728 100644 --- a/src/gl/dynlights/a_dynlight.cpp +++ b/src/gl/dynlights/a_dynlight.cpp @@ -71,6 +71,7 @@ #include "portal.h" #include "doomstat.h" #include "serializer.h" +#include "g_levellocals.h" #include "gl/renderer/gl_renderer.h" diff --git a/src/gl/dynlights/gl_dynlight.cpp b/src/gl/dynlights/gl_dynlight.cpp index bc107c60e7..a0d9292a91 100644 --- a/src/gl/dynlights/gl_dynlight.cpp +++ b/src/gl/dynlights/gl_dynlight.cpp @@ -49,6 +49,7 @@ #include "zstring.h" #include "d_dehacked.h" #include "v_text.h" +#include "g_levellocals.h" #include "gl/dynlights/gl_dynlight.h" diff --git a/src/gl/models/gl_models.cpp b/src/gl/models/gl_models.cpp index f3dfbd569d..ce6b22ee84 100644 --- a/src/gl/models/gl_models.cpp +++ b/src/gl/models/gl_models.cpp @@ -37,6 +37,7 @@ #include "g_level.h" #include "r_state.h" #include "d_player.h" +#include "g_levellocals.h" //#include "resources/voxels.h" //#include "gl/gl_intern.h" diff --git a/src/gl/renderer/gl_lightdata.cpp b/src/gl/renderer/gl_lightdata.cpp index d09484a1f5..3ba5577371 100644 --- a/src/gl/renderer/gl_lightdata.cpp +++ b/src/gl/renderer/gl_lightdata.cpp @@ -38,6 +38,7 @@ #include "p_local.h" #include "g_level.h" #include "r_sky.h" +#include "g_levellocals.h" // externally settable lighting properties static float distfogtable[2][256]; // light to fog conversion table for black fog diff --git a/src/gl/scene/gl_bsp.cpp b/src/gl/scene/gl_bsp.cpp index da60770495..af4d46d61a 100644 --- a/src/gl/scene/gl_bsp.cpp +++ b/src/gl/scene/gl_bsp.cpp @@ -87,7 +87,7 @@ static sector_t *currentsector; static void AddLine (seg_t *seg, bool portalclip) { #ifdef _DEBUG - if (seg->linedef - lines == 38) + if (seg->linedef->Index() == 38) { int a = 0; } diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 5fc775603e..7e9a3e6d28 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -32,6 +32,7 @@ #include "r_utility.h" #include "r_state.h" #include "doomstat.h" +#include "g_levellocals.h" #include "gl/system/gl_cvars.h" #include "gl/data/gl_data.h" diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index efadbcebee..c4296c50d3 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -35,6 +35,7 @@ #include "d_player.h" #include "portal.h" #include "templates.h" +#include "g_levellocals.h" #include "gl/system/gl_interface.h" #include "gl/system/gl_cvars.h" diff --git a/src/gl/scene/gl_renderhacks.cpp b/src/gl/scene/gl_renderhacks.cpp index 9242df2a91..4dd7b7d819 100644 --- a/src/gl/scene/gl_renderhacks.cpp +++ b/src/gl/scene/gl_renderhacks.cpp @@ -30,7 +30,7 @@ #include "r_defs.h" #include "r_sky.h" #include "g_level.h" - +#include "g_levellocals.h" #include "gl/renderer/gl_renderer.h" #include "gl/data/gl_data.h" diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 13cd2eac44..7f1432e142 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -43,6 +43,7 @@ #include "p_local.h" #include "gl/gl_functions.h" #include "serializer.h" +#include "g_levellocals.h" #include "gl/dynlights/gl_lightbuffer.h" #include "gl/system/gl_interface.h" diff --git a/src/gl/scene/gl_sky.cpp b/src/gl/scene/gl_sky.cpp index 2a29525489..19d1c91275 100644 --- a/src/gl/scene/gl_sky.cpp +++ b/src/gl/scene/gl_sky.cpp @@ -28,6 +28,7 @@ #include "r_utility.h" #include "doomdata.h" #include "portal.h" +#include "g_levellocals.h" #include "gl/gl_functions.h" #include "gl/data/gl_data.h" @@ -51,7 +52,7 @@ void GLSkyInfo::init(int sky1, PalEntry FadeColor) memset(this, 0, sizeof(*this)); if ((sky1 & PL_SKYFLAT) && (sky1 & (PL_SKYFLAT - 1))) { - const line_t *l = &lines[(sky1&(PL_SKYFLAT - 1)) - 1]; + const line_t *l = &level.lines[(sky1&(PL_SKYFLAT - 1)) - 1]; const side_t *s = l->sidedef[0]; int pos; diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index b0cfcebe34..198dfea6e3 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -36,6 +36,7 @@ #include "r_utility.h" #include "a_pickups.h" #include "d_player.h" +#include "g_levellocals.h" #include "gl/system/gl_interface.h" #include "gl/system/gl_framebuffer.h" diff --git a/src/gl/scene/gl_walls.cpp b/src/gl/scene/gl_walls.cpp index 9d471b72d2..5965eebc38 100644 --- a/src/gl/scene/gl_walls.cpp +++ b/src/gl/scene/gl_walls.cpp @@ -33,6 +33,7 @@ #include "p_maputl.h" #include "doomdata.h" #include "portal.h" +#include "g_levellocals.h" #include "gl/system/gl_cvars.h" #include "gl/renderer/gl_lightdata.h" @@ -326,7 +327,7 @@ void GLWall::SplitWall(sector_t * frontsector, bool translucent) //::SplitWall.Clock(); #ifdef _DEBUG - if (seg->linedef-lines==1) + if (seg->linedef->Index() == 1) { int a = 0; } @@ -1414,7 +1415,7 @@ void GLWall::Process(seg_t *seg, sector_t * frontsector, sector_t * backsector) sector_t * segback; #ifdef _DEBUG - if (seg->linedef - lines < 4) + if (seg->linedef->Index() == 1) { int a = 0; } @@ -1547,7 +1548,7 @@ void GLWall::Process(seg_t *seg, sector_t * frontsector, sector_t * backsector) zbottom[1] = zfloor[1]; PutPortal(PORTALTYPE_LINETOLINE); } - else if (seg->linedef->portaltransferred > 0) + else if (seg->linedef->GetTransferredPortal()) { SkyLine(frontsector, seg->linedef); } diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 7662c78768..953509495c 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -32,6 +32,7 @@ #include "doomstat.h" #include "d_player.h" #include "g_level.h" +#include "g_levellocals.h" #include "gl/system/gl_interface.h" #include "gl/system/gl_cvars.h" diff --git a/src/gl/utility/gl_clock.cpp b/src/gl/utility/gl_clock.cpp index 0dc9fd76ca..68a2b06e58 100644 --- a/src/gl/utility/gl_clock.cpp +++ b/src/gl/utility/gl_clock.cpp @@ -48,6 +48,7 @@ #include "c_dispatch.h" #include "r_utility.h" #include "v_video.h" +#include "g_levellocals.h" #include "gl/utility/gl_clock.h" #include "gl/utility/gl_convert.h" diff --git a/src/hu_scores.cpp b/src/hu_scores.cpp index 35e18006d2..1164eaf1c2 100644 --- a/src/hu_scores.cpp +++ b/src/hu_scores.cpp @@ -50,6 +50,7 @@ #include "gstrings.h" #include "d_net.h" #include "c_dispatch.h" +#include "g_levellocals.h" // MACROS ------------------------------------------------------------------ diff --git a/src/intermission/intermission.cpp b/src/intermission/intermission.cpp index 2aacd215b3..2416f01c41 100644 --- a/src/intermission/intermission.cpp +++ b/src/intermission/intermission.cpp @@ -51,6 +51,7 @@ #include "p_conversation.h" #include "menu/menu.h" #include "d_net.h" +#include "g_levellocals.h" FIntermissionDescriptorList IntermissionDescriptors; diff --git a/src/m_cheat.cpp b/src/m_cheat.cpp index 53ae789c68..414fafba90 100644 --- a/src/m_cheat.cpp +++ b/src/m_cheat.cpp @@ -49,6 +49,7 @@ #include "a_morph.h" #include "a_armor.h" #include "a_ammo.h" +#include "g_levellocals.h" // [RH] Actually handle the cheat. The cheat code in st_stuff.c now just // writes some bytes to the network data stream, and the network code diff --git a/src/menu/readthis.cpp b/src/menu/readthis.cpp index b8a3837ee0..f1e82cd515 100644 --- a/src/menu/readthis.cpp +++ b/src/menu/readthis.cpp @@ -37,6 +37,7 @@ #include "v_video.h" #include "g_level.h" #include "gi.h" +#include "g_levellocals.h" #include "textures/textures.h" class DReadThisMenu : public DMenu diff --git a/src/nodebuild.h b/src/nodebuild.h index 7e2a61aaac..9599bc0d2e 100644 --- a/src/nodebuild.h +++ b/src/nodebuild.h @@ -209,10 +209,10 @@ public: bool makeGLNodes); ~FNodeBuilder (); - void Extract (node_t *&nodes, int &nodeCount, - seg_t *&segs, glsegextra_t *&glsegextras, int &segCount, + void Extract(node_t *&nodes, int &nodeCount, + seg_t *&segs, int &segCount, subsector_t *&ssecs, int &subCount, - vertex_t *&verts, int &vertCount); + TStaticArray &vertexes); const int *GetOldVertexTable(); // These are used for building sub-BSP trees for polyobjects. diff --git a/src/nodebuild_extract.cpp b/src/nodebuild_extract.cpp index c3f63c8202..11332f049a 100644 --- a/src/nodebuild_extract.cpp +++ b/src/nodebuild_extract.cpp @@ -53,14 +53,14 @@ #endif void FNodeBuilder::Extract (node_t *&outNodes, int &nodeCount, - seg_t *&outSegs, glsegextra_t *&outSegExtras, int &segCount, + seg_t *&outSegs, int &segCount, subsector_t *&outSubs, int &subCount, - vertex_t *&outVerts, int &vertCount) + TStaticArray &outVerts) { int i; - vertCount = Vertices.Size (); - outVerts = new vertex_t[vertCount]; + int vertCount = Vertices.Size (); + outVerts.Alloc(vertCount); for (i = 0; i < vertCount; ++i) { @@ -109,14 +109,13 @@ void FNodeBuilder::Extract (node_t *&outNodes, int &nodeCount, for (i = 0; i < subCount; ++i) { - DWORD numsegs = CloseSubsector (segs, i, outVerts); + DWORD numsegs = CloseSubsector (segs, i, &outVerts[0]); outSubs[i].numlines = numsegs; outSubs[i].firstline = (seg_t *)(size_t)(segs.Size() - numsegs); } segCount = segs.Size (); outSegs = new seg_t[segCount]; - outSegExtras = new glsegextra_t[segCount]; for (i = 0; i < segCount; ++i) { @@ -124,11 +123,11 @@ void FNodeBuilder::Extract (node_t *&outNodes, int &nodeCount, if (segs[i].Partner != DWORD_MAX) { - outSegExtras[i].PartnerSeg = Segs[segs[i].Partner].storedseg; + outSegs[i].PartnerSeg = &outSegs[Segs[segs[i].Partner].storedseg]; } else { - outSegExtras[i].PartnerSeg = DWORD_MAX; + outSegs[i].PartnerSeg = nullptr; } } } @@ -137,7 +136,6 @@ void FNodeBuilder::Extract (node_t *&outNodes, int &nodeCount, memcpy (outSubs, &Subsectors[0], subCount*sizeof(subsector_t)); segCount = Segs.Size (); outSegs = new seg_t[segCount]; - outSegExtras = NULL; for (i = 0; i < segCount; ++i) { const FPrivSeg *org = &Segs[SegList[i].SegNum]; @@ -145,12 +143,13 @@ void FNodeBuilder::Extract (node_t *&outNodes, int &nodeCount, D(Printf(PRINT_LOG, "Seg %d: v1(%d) -> v2(%d)\n", i, org->v1, org->v2)); - out->v1 = outVerts + org->v1; - out->v2 = outVerts + org->v2; + out->v1 = &outVerts[org->v1]; + out->v2 = &outVerts[org->v2]; out->backsector = org->backsector; out->frontsector = org->frontsector; out->linedef = Level.Lines + org->linedef; out->sidedef = Level.Sides + org->sidedef; + out->PartnerSeg = nullptr; } } for (i = 0; i < subCount; ++i) @@ -162,8 +161,8 @@ void FNodeBuilder::Extract (node_t *&outNodes, int &nodeCount, for (i = 0; i < Level.NumLines; ++i) { - Level.Lines[i].v1 = outVerts + (size_t)Level.Lines[i].v1; - Level.Lines[i].v2 = outVerts + (size_t)Level.Lines[i].v2; + Level.Lines[i].v1 = &outVerts[(size_t)Level.Lines[i].v1]; + Level.Lines[i].v2 = &outVerts[(size_t)Level.Lines[i].v2]; } } diff --git a/src/nodebuild_utility.cpp b/src/nodebuild_utility.cpp index 02e280261d..b6115f4c8e 100644 --- a/src/nodebuild_utility.cpp +++ b/src/nodebuild_utility.cpp @@ -50,6 +50,7 @@ #include "i_system.h" #include "po_man.h" #include "r_state.h" +#include "g_levellocals.h" #include "math/cmath.h" static const int PO_LINE_START = 1; @@ -186,7 +187,7 @@ int FNodeBuilder::CreateSeg (int linenum, int sidenum) } seg.linedef = linenum; side_t *sd = Level.Lines[linenum].sidedef[sidenum]; - seg.sidedef = sd != NULL? int(sd - sides) : int(NO_SIDE); + seg.sidedef = sd != NULL? sd->Index() : int(NO_SIDE); seg.nextforvert = Vertices[seg.v1].segs; seg.nextforvert2 = Vertices[seg.v2].segs2; diff --git a/src/p_3dfloors.cpp b/src/p_3dfloors.cpp index e4778e91d7..c25d4a532c 100644 --- a/src/p_3dfloors.cpp +++ b/src/p_3dfloors.cpp @@ -47,6 +47,7 @@ #include "r_utility.h" #include "p_spec.h" #include "r_data/colormaps.h" +#include "g_levellocals.h" EXTERN_CVAR(Int, vid_renderer) @@ -850,16 +851,14 @@ void P_LineOpening_XFloors (FLineOpening &open, AActor * thing, const line_t *li void P_Spawn3DFloors (void) { static int flagvals[] = {512, 2+512, 512+1024}; - int i; - line_t * line; - for (i=0,line=lines;ispecial) + switch(line.special) { case ExtraFloor_LightOnly: - if (line->args[1] < 0 || line->args[1] > 2) line->args[1] = 0; - P_Set3DFloor(line, 3, flagvals[line->args[1]], 0); + if (line.args[1] < 0 || line.args[1] > 2) line.args[1] = 0; + P_Set3DFloor(&line, 3, flagvals[line.args[1]], 0); break; case Sector_Set3DFloor: @@ -868,24 +867,24 @@ void P_Spawn3DFloors (void) // In Doom format the translators can take full integers for the tag and the line ID always is the same as the tag. if (level.maptype == MAPTYPE_HEXEN) { - if (line->args[1]&8) + if (line.args[1]&8) { - tagManager.AddLineID(i, line->args[4]); + tagManager.AddLineID(line.Index(), line.args[4]); } else { - line->args[0]+=256*line->args[4]; - line->args[4]=0; + line.args[0]+=256*line.args[4]; + line.args[4]=0; } } - P_Set3DFloor(line, line->args[1]&~8, line->args[2], line->args[3]); + P_Set3DFloor(&line, line.args[1]&~8, line.args[2], line.args[3]); break; default: continue; } - line->special=0; - line->args[0] = line->args[1] = line->args[2] = line->args[3] = line->args[4] = 0; + line.special=0; + line.args[0] = line.args[1] = line.args[2] = line.args[3] = line.args[4] = 0; } // kg3D - do it in software for (auto &sec : level.sectors) diff --git a/src/p_3dmidtex.cpp b/src/p_3dmidtex.cpp index b775055d80..cb7f27a082 100644 --- a/src/p_3dmidtex.cpp +++ b/src/p_3dmidtex.cpp @@ -41,6 +41,7 @@ #include "p_terrain.h" #include "p_maputl.h" #include "p_spec.h" +#include "g_levellocals.h" //============================================================================ @@ -121,10 +122,10 @@ void P_Attach3dMidtexLinesToSector(sector_t *sector, int lineid, int tag, bool c extsector_t::midtex::plane &scrollplane = ceiling? sector->e->Midtex.Ceiling : sector->e->Midtex.Floor; // Bit arrays that mark whether a line or sector is to be attached. - BYTE *found_lines = new BYTE[(numlines+7)/8]; + BYTE *found_lines = new BYTE[(level.lines.Size()+7)/8]; BYTE *found_sectors = new BYTE[(level.sectors.Size()+7)/8]; - memset(found_lines, 0, sizeof (BYTE) * ((numlines+7)/8)); + memset(found_lines, 0, sizeof (BYTE) * ((level.lines.Size()+7)/8)); memset(found_sectors, 0, sizeof (BYTE) * ((level.sectors.Size()+7)/8)); // mark all lines and sectors that are already attached to this one @@ -132,13 +133,13 @@ void P_Attach3dMidtexLinesToSector(sector_t *sector, int lineid, int tag, bool c // from the marker arrays. for (unsigned i=0; i < scrollplane.AttachedLines.Size(); i++) { - int line = int(scrollplane.AttachedLines[i] - lines); + int line = scrollplane.AttachedLines[i]->Index(); found_lines[line>>3] |= 1 << (line&7); } for (unsigned i=0; i < scrollplane.AttachedSectors.Size(); i++) { - int sec = scrollplane.AttachedSectors[i]->sectornum; + int sec = scrollplane.AttachedSectors[i]->Index(); found_sectors[sec>>3] |= 1 << (sec&7); } @@ -151,7 +152,7 @@ void P_Attach3dMidtexLinesToSector(sector_t *sector, int lineid, int tag, bool c int line; while ((line = itr.Next()) >= 0) { - line_t *ln = &lines[line]; + line_t *ln = &level.lines[line]; if (ln->frontsector == NULL || ln->backsector == NULL || !(ln->flags & ML_3DMIDTEX)) { @@ -176,24 +177,25 @@ void P_Attach3dMidtexLinesToSector(sector_t *sector, int lineid, int tag, bool c // Only consider two-sided lines with the 3DMIDTEX flag continue; } - int lineno = int(ln-lines); - found_lines[lineno>>3] |= 1 << (lineno&7); + int lineno = ln->Index(); + found_lines[lineno >> 3] |= 1 << (lineno & 7); } } } - for(int i=0; i < numlines; i++) + for(unsigned i=0; i < level.lines.Size(); i++) { if (found_lines[i>>3] & (1 << (i&7))) { - scrollplane.AttachedLines.Push(&lines[i]); + auto &line = level.lines[i]; + scrollplane.AttachedLines.Push(&line); - v = lines[i].frontsector->sectornum; + v = line.frontsector->Index(); assert(v < (int)level.sectors.Size()); found_sectors[v>>3] |= 1 << (v&7); - v = lines[i].backsector->sectornum; + v = line.backsector->Index(); assert(v < (int)level.sectors.Size()); found_sectors[v>>3] |= 1 << (v&7); } diff --git a/src/p_acs.cpp b/src/p_acs.cpp index d35714ca5f..f1a0ae8bfd 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -86,6 +86,7 @@ #include "a_armor.h" #include "a_ammo.h" #include "r_data/colormaps.h" +#include "g_levellocals.h" extern FILE *Logfile; @@ -3284,7 +3285,7 @@ void DLevelScript::SetLineTexture (int lineid, int side, int position, int name) int linenum = -1; const char *texname = FBehavior::StaticLookupString (name); - if (texname == NULL) + if (texname == nullptr) return; side = !!side; @@ -3296,8 +3297,8 @@ void DLevelScript::SetLineTexture (int lineid, int side, int position, int name) { side_t *sidedef; - sidedef = lines[linenum].sidedef[side]; - if (sidedef == NULL) + sidedef = level.lines[linenum].sidedef[side]; + if (sidedef == nullptr) continue; switch (position) @@ -3332,16 +3333,14 @@ void DLevelScript::ReplaceTextures (int fromnamei, int tonamei, int flags) picnum1 = TexMan.GetTexture (fromname, FTexture::TEX_Wall, FTextureManager::TEXMAN_Overridable); picnum2 = TexMan.GetTexture (toname, FTexture::TEX_Wall, FTextureManager::TEXMAN_Overridable); - for (int i = 0; i < numsides; ++i) + for (auto &side : level.sides) { - side_t *wal = &sides[i]; - for(int j=0;j<3;j++) { static BYTE bits[]={NOT_TOP, NOT_MIDDLE, NOT_BOTTOM}; - if (!(flags & bits[j]) && wal->GetTexture(j) == picnum1) + if (!(flags & bits[j]) && side.GetTexture(j) == picnum1) { - wal->SetTexture(j, picnum2); + side.SetTexture(j, picnum2); } } } @@ -4428,14 +4427,14 @@ int DLevelScript::SideFromID(int id, int side) { if (activationline == NULL) return -1; if (activationline->sidedef[side] == NULL) return -1; - return activationline->sidedef[side]->Index; + return activationline->sidedef[side]->UDMFIndex; } else { int line = P_FindFirstLineFromID(id); if (line == -1) return -1; - if (lines[line].sidedef[side] == NULL) return -1; - return lines[line].sidedef[side]->Index; + if (level.lines[line].sidedef[side] == NULL) return -1; + return level.lines[line].sidedef[side]->UDMFIndex; } } @@ -4444,7 +4443,7 @@ int DLevelScript::LineFromID(int id) if (id == 0) { if (activationline == NULL) return -1; - return int(activationline - lines); + return activationline->Index(); } else { @@ -5695,7 +5694,7 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound) FLineIdIterator itr(args[0]); while ((line = itr.Next()) >= 0) { - lines[line].activation = args[1]; + level.lines[line].activation = args[1]; } } break; @@ -5704,7 +5703,7 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound) if (argCount > 0) { int line = P_FindFirstLineFromID(args[0]); - return line >= 0 ? lines[line].activation : 0; + return line >= 0 ? level.lines[line].activation : 0; } break; @@ -7742,7 +7741,7 @@ scriptwait: if (activationline != NULL) { activationline->special = 0; - DPrintf(DMSG_SPAMMY, "Cleared line special on line %d\n", (int)(activationline - lines)); + DPrintf(DMSG_SPAMMY, "Cleared line special on line %d\n", activationline->Index()); } break; @@ -8307,32 +8306,33 @@ scriptwait: case PCD_SETLINEBLOCKING: { - int line; + int lineno; FLineIdIterator itr(STACK(2)); - while ((line = itr.Next()) >= 0) + while ((lineno = itr.Next()) >= 0) { + auto &line = level.lines[lineno]; switch (STACK(1)) { case BLOCK_NOTHING: - lines[line].flags &= ~(ML_BLOCKING|ML_BLOCKEVERYTHING|ML_RAILING|ML_BLOCK_PLAYERS); + line.flags &= ~(ML_BLOCKING|ML_BLOCKEVERYTHING|ML_RAILING|ML_BLOCK_PLAYERS); break; case BLOCK_CREATURES: default: - lines[line].flags &= ~(ML_BLOCKEVERYTHING|ML_RAILING|ML_BLOCK_PLAYERS); - lines[line].flags |= ML_BLOCKING; + line.flags &= ~(ML_BLOCKEVERYTHING|ML_RAILING|ML_BLOCK_PLAYERS); + line.flags |= ML_BLOCKING; break; case BLOCK_EVERYTHING: - lines[line].flags &= ~(ML_RAILING|ML_BLOCK_PLAYERS); - lines[line].flags |= ML_BLOCKING|ML_BLOCKEVERYTHING; + line.flags &= ~(ML_RAILING|ML_BLOCK_PLAYERS); + line.flags |= ML_BLOCKING|ML_BLOCKEVERYTHING; break; case BLOCK_RAILING: - lines[line].flags &= ~(ML_BLOCKEVERYTHING|ML_BLOCK_PLAYERS); - lines[line].flags |= ML_RAILING|ML_BLOCKING; + line.flags &= ~(ML_BLOCKEVERYTHING|ML_BLOCK_PLAYERS); + line.flags |= ML_RAILING|ML_BLOCKING; break; case BLOCK_PLAYERS: - lines[line].flags &= ~(ML_BLOCKEVERYTHING|ML_BLOCKING|ML_RAILING); - lines[line].flags |= ML_BLOCK_PLAYERS; + line.flags &= ~(ML_BLOCKEVERYTHING|ML_BLOCKING|ML_RAILING); + line.flags |= ML_BLOCK_PLAYERS; break; } } @@ -8349,9 +8349,9 @@ scriptwait: while ((line = itr.Next()) >= 0) { if (STACK(1)) - lines[line].flags |= ML_BLOCKMONSTERS; + level.lines[line].flags |= ML_BLOCKMONSTERS; else - lines[line].flags &= ~ML_BLOCKMONSTERS; + level.lines[line].flags &= ~ML_BLOCKMONSTERS; } sp -= 2; @@ -8374,7 +8374,7 @@ scriptwait: FLineIdIterator itr(STACK(7)); while ((linenum = itr.Next()) >= 0) { - line_t *line = &lines[linenum]; + line_t *line = &level.lines[linenum]; line->special = specnum; line->args[0] = arg0; line->args[1] = STACK(4); diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index f4b2f81036..b90f656c1d 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -80,6 +80,7 @@ #include "math/cmath.h" #include "a_armor.h" #include "a_health.h" +#include "g_levellocals.h" AActor *SingleActorFromTID(int tid, AActor *defactor); diff --git a/src/p_buildmap.cpp b/src/p_buildmap.cpp index 99f3fb6383..3a1943fc87 100644 --- a/src/p_buildmap.cpp +++ b/src/p_buildmap.cpp @@ -19,6 +19,7 @@ #include "gi.h" #include "p_spec.h" +#if 0 // MACROS ------------------------------------------------------------------ //#define SHADE2LIGHT(s) (160-2*(s)) @@ -487,7 +488,7 @@ static void LoadWalls (walltype *walls, int numwalls, sectortype *bsec) // Setting numvertexes to the same as numwalls is overly conservative, // but the extra vertices will be removed during the BSP building pass. numsides = numvertexes = numwalls; - numlines = 0; + int numlines = 0; sides = new side_t[numsides]; memset (sides, 0, numsides*sizeof(side_t)); @@ -562,8 +563,8 @@ static void LoadWalls (walltype *walls, int numwalls, sectortype *bsec) } // Set line properties that Doom doesn't store per-sidedef - lines = new line_t[numlines]; - memset (lines, 0, numlines*sizeof(line_t)); + level.lines.Alloc(numlines); + memset (&level.lines[0], 0, numlines*sizeof(line_t)); for (i = 0, j = -1; i < numwalls; ++i) { @@ -573,6 +574,7 @@ static void LoadWalls (walltype *walls, int numwalls, sectortype *bsec) } j = int(intptr_t(sides[i].linedef)); + auto &lines = level.lines; lines[j].sidedef[0] = (side_t*)(intptr_t)i; lines[j].sidedef[1] = (side_t*)(intptr_t)walls[i].nextwall; lines[j].v1 = FindVertex (walls[i].x, walls[i].y); @@ -654,8 +656,8 @@ static void LoadWalls (walltype *walls, int numwalls, sectortype *bsec) slope.z[0] = slope.z[1] = slope.z[2] = -bsec->ceilingZ; CalcPlane (slope, sec.ceilingplane); } - int linenum = int(intptr_t(sides[bsec->wallptr].linedef)); - int sidenum = int(intptr_t(lines[linenum].sidedef[1])); + int linenum = sides[bsec->wallptr].linedef->Index(); + int sidenum = int(intptr_t(level.lines[linenum].sidedef[1] - sides)); if (bsec->floorstat & 64) { // floor is aligned to first wall P_AlignFlat (linenum, sidenum == bsec->wallptr, 0); @@ -667,8 +669,8 @@ static void LoadWalls (walltype *walls, int numwalls, sectortype *bsec) } for (i = 0; i < numlines; i++) { - intptr_t front = intptr_t(lines[i].sidedef[0]); - intptr_t back = intptr_t(lines[i].sidedef[1]); + intptr_t front = intptr_t(level.lines[i].sidedef[0]-sides); + intptr_t back = intptr_t(level.lines[i].sidedef[1]-sides); lines[i].sidedef[0] = front >= 0 ? &sides[front] : NULL; lines[i].sidedef[1] = back >= 0 ? &sides[back] : NULL; } @@ -851,6 +853,7 @@ static void Decrypt (void *to_, const void *from_, int len, int key) } } +#endif //========================================================================== // // Just an actor to make the Build sprites show up. It doesn't do anything @@ -892,3 +895,4 @@ void ACustomSprite::BeginPlay () // set face/wall/floor flags renderflags |= ActorRenderFlags::FromInt (((cstat >> 4) & 3) << 12); } + diff --git a/src/p_ceiling.cpp b/src/p_ceiling.cpp index 79fd295910..7bf1f9099e 100644 --- a/src/p_ceiling.cpp +++ b/src/p_ceiling.cpp @@ -31,6 +31,7 @@ #include "gi.h" #include "serializer.h" #include "p_spec.h" +#include "g_levellocals.h" //============================================================================ // diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index 5fd21e73b3..4f7f2fea70 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -60,6 +60,7 @@ #include "r_utility.h" #include "p_local.h" #include "menu/menu.h" +#include "g_levellocals.h" // The conversations as they exist inside a SCRIPTxx lump. struct Response diff --git a/src/p_doors.cpp b/src/p_doors.cpp index 1490647fcf..3101be1c77 100644 --- a/src/p_doors.cpp +++ b/src/p_doors.cpp @@ -38,6 +38,7 @@ #include "serializer.h" #include "d_player.h" #include "p_spec.h" +#include "g_levellocals.h" //============================================================================ // diff --git a/src/p_effect.cpp b/src/p_effect.cpp index 1077594271..e0679338df 100644 --- a/src/p_effect.cpp +++ b/src/p_effect.cpp @@ -53,6 +53,7 @@ #include "colormatcher.h" #include "d_player.h" #include "r_utility.h" +#include "g_levellocals.h" CVAR (Int, cl_rockettrails, 1, CVAR_ARCHIVE); CVAR (Bool, r_rail_smartspiral, 0, CVAR_ARCHIVE); @@ -272,7 +273,7 @@ void P_ThinkParticles () auto oldtrans = particle->alpha; particle->alpha -= particle->fadestep; particle->size += particle->sizestep; - if (oldtrans < particle->alpha || --particle->ttl <= 0 || (particle->size <= 0)) + if (particle->alpha <= 0 || oldtrans < particle->alpha || --particle->ttl <= 0 || (particle->size <= 0)) { // The particle has expired, so free it memset (particle, 0, sizeof(particle_t)); if (prev) diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index a3d48a7ace..ac4e0f04b6 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -52,6 +52,7 @@ #include "p_checkposition.h" #include "math/cmath.h" #include "a_ammo.h" +#include "g_levellocals.h" #include "gi.h" diff --git a/src/p_floor.cpp b/src/p_floor.cpp index dbe3792daf..48c73f1310 100644 --- a/src/p_floor.cpp +++ b/src/p_floor.cpp @@ -32,6 +32,7 @@ #include "p_3dmidtex.h" #include "p_spec.h" #include "r_data/r_interpolate.h" +#include "g_levellocals.h" //========================================================================== // diff --git a/src/p_glnodes.cpp b/src/p_glnodes.cpp index 26e341aab7..35f9f45020 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -67,6 +67,7 @@ #include "m_misc.h" #include "r_utility.h" #include "cmdlib.h" +#include "g_levellocals.h" void P_GetPolySpots (MapData * lump, TArray &spots, TArray &anchors); @@ -129,6 +130,7 @@ struct gl5_mapnode_t static int CheckForMissingSegs() { + auto numsides = level.sides.Size(); double *added_seglen = new double[numsides]; int missing = 0; @@ -141,13 +143,13 @@ static int CheckForMissingSegs() { // check all the segs and calculate the length they occupy on their sidedef DVector2 vec1(seg->v2->fX() - seg->v1->fX(), seg->v2->fY() - seg->v1->fY()); - added_seglen[seg->sidedef - sides] += vec1.Length(); + added_seglen[seg->sidedef->Index()] += vec1.Length(); } } - for(int i=0;iDelta().Length(); + double linelen = level.sides[i].linedef->Delta().Length(); missing += (added_seglen[i] < linelen - 1.); } @@ -222,7 +224,7 @@ static bool LoadGLVertexes(FileReader * lump) BYTE *gldata; int i; - firstglvertex = numvertexes; + firstglvertex = level.vertexes.Size(); int gllen=lump->GetLength(); @@ -247,23 +249,23 @@ static bool LoadGLVertexes(FileReader * lump) } else format5=false; - mapglvertex_t* mgl; + mapglvertex_t* mgl = (mapglvertex_t *)(gldata + GL_VERT_OFFSET); + unsigned numvertexes = firstglvertex + (gllen - GL_VERT_OFFSET)/sizeof(mapglvertex_t); - vertex_t * oldvertexes = vertexes; - numvertexes += (gllen - GL_VERT_OFFSET)/sizeof(mapglvertex_t); - vertexes = new vertex_t[numvertexes]; - mgl = (mapglvertex_t *) (gldata + GL_VERT_OFFSET); + TStaticArray oldvertexes = std::move(level.vertexes); + level.vertexes.Alloc(numvertexes); - memcpy(vertexes, oldvertexes, firstglvertex * sizeof(vertex_t)); - for(i=0;ix)/65536., LittleLong(mgl->y)/65536.); + level.vertexes[i].set(LittleLong(mgl->x)/65536., LittleLong(mgl->y)/65536.); mgl++; } delete[] gldata; @@ -317,18 +319,16 @@ static bool LoadGLSegs(FileReader * lump) numsegs/=sizeof(glseg_t); segs = new seg_t[numsegs]; memset(segs,0,sizeof(seg_t)*numsegs); - glsegextras = new glsegextra_t[numsegs]; glseg_t * ml = (glseg_t*)data; for(i = 0; i < numsegs; i++) { // check for gl-vertices - segs[i].v1 = &vertexes[checkGLVertex(LittleShort(ml->v1))]; - segs[i].v2 = &vertexes[checkGLVertex(LittleShort(ml->v2))]; - - glsegextras[i].PartnerSeg = ml->partner == 0xFFFF ? DWORD_MAX : LittleShort(ml->partner); + segs[i].v1 = &level.vertexes[checkGLVertex(LittleShort(ml->v1))]; + segs[i].v2 = &level.vertexes[checkGLVertex(LittleShort(ml->v2))]; + segs[i].PartnerSeg = ml->partner == 0xFFFF ? nullptr : &segs[LittleShort(ml->partner)]; if(ml->linedef != 0xffff) { - ldef = &lines[LittleShort(ml->linedef)]; + ldef = &level.lines[LittleShort(ml->linedef)]; segs[i].linedef = ldef; @@ -370,19 +370,17 @@ static bool LoadGLSegs(FileReader * lump) numsegs/=sizeof(glseg3_t); segs = new seg_t[numsegs]; memset(segs,0,sizeof(seg_t)*numsegs); - glsegextras = new glsegextra_t[numsegs]; glseg3_t * ml = (glseg3_t*)(data+ (format5? 0:4)); for(i = 0; i < numsegs; i++) { // check for gl-vertices - segs[i].v1 = &vertexes[checkGLVertex3(LittleLong(ml->v1))]; - segs[i].v2 = &vertexes[checkGLVertex3(LittleLong(ml->v2))]; - - glsegextras[i].PartnerSeg = LittleLong(ml->partner); + segs[i].v1 = &level.vertexes[checkGLVertex3(LittleLong(ml->v1))]; + segs[i].v2 = &level.vertexes[checkGLVertex3(LittleLong(ml->v2))]; + segs[i].PartnerSeg = LittleLong(ml->partner) == 0xffffffffu? nullptr : &segs[LittleLong(ml->partner)]; if(ml->linedef != 0xffff) // skip minisegs { - ldef = &lines[LittleLong(ml->linedef)]; + ldef = &level.lines[LittleLong(ml->linedef)]; segs[i].linedef = ldef; @@ -1000,18 +998,18 @@ bool P_CheckNodes(MapData * map, bool rebuilt, int buildtime) P_GetPolySpots (map, polyspots, anchors); FNodeBuilder::FLevel leveldata = { - vertexes, numvertexes, - sides, numsides, - lines, numlines, + &level.vertexes[0], (int)level.vertexes.Size(), + &level.sides[0], (int)level.sides.Size(), + &level.lines[0], (int)level.lines.Size(), 0, 0, 0, 0 }; leveldata.FindMapBounds (); FNodeBuilder builder (leveldata, polyspots, anchors, true); - delete[] vertexes; + builder.Extract (nodes, numnodes, - segs, glsegextras, numsegs, + segs, numsegs, subsectors, numsubsectors, - vertexes, numvertexes); + level.vertexes); endTime = I_FPSTime (); DPrintf (DMSG_NOTIFY, "BSP generation took %.3f sec (%d segs)\n", (endTime - startTime) * 0.001, numsegs); buildtime = endTime - startTime; @@ -1093,11 +1091,11 @@ static void CreateCachedNodes(MapData *map) MemFile ZNodes; WriteLong(ZNodes, 0); - WriteLong(ZNodes, numvertexes); - for(int i=0;iIndex()); + WriteLong(ZNodes, segs[i].PartnerSeg == nullptr? 0xffffffffu : DWORD(segs[i].PartnerSeg - segs)); if (segs[i].linedef) { - WriteLong(ZNodes, DWORD(segs[i].linedef - lines)); + WriteLong(ZNodes, DWORD(segs[i].linedef->Index())); WriteByte(ZNodes, segs[i].sidedef == segs[i].linedef->sidedef[0]? 0:1); } else @@ -1156,7 +1153,7 @@ static void CreateCachedNodes(MapData *map) uLongf outlen = ZNodes.Size(); BYTE *compressed; - int offset = numlines * 8 + 12 + 16; + int offset = level.lines.Size() * 8 + 12 + 16; int r; do { @@ -1171,13 +1168,13 @@ static void CreateCachedNodes(MapData *map) while (r == Z_BUF_ERROR); memcpy(compressed, "CACH", 4); - DWORD len = LittleLong(numlines); + DWORD len = LittleLong(level.lines.Size()); memcpy(compressed+4, &len, 4); map->GetChecksum(compressed+8); - for(int i=0;iIndex())), LittleLong(DWORD(level.lines[i].v2->Index())) }; + memcpy(compressed + 8 + 16 + 8 * i, ndx, 8); } memcpy(compressed + offset - 4, "ZGL3", 4); @@ -1219,7 +1216,7 @@ static bool CheckCachedNodes(MapData *map) if (fread(&numlin, 4, 1, f) != 1) goto errorout; numlin = LittleLong(numlin); - if ((int)numlin != numlines) goto errorout; + if (numlin != level.lines.Size()) goto errorout; if (fread(md5, 1, 16, f) != 16) goto errorout; map->GetChecksum(md5map); @@ -1261,10 +1258,11 @@ static bool CheckCachedNodes(MapData *map) goto errorout; } - for(int i=0;irender_sector = ss->sector; - } - return; - } + int partner = (int)(p - segs); - for(i=0;i= numsegs) + { + segs[i].PartnerSeg = nullptr; + } - if (partner<0 || partner>=numsegs/*eh? || &segs[partner]!=glsegextras[i].PartnerSeg*/) - { - glsegextras[i].PartnerSeg=DWORD_MAX; + // glbsp creates such incorrect references for Strife. + if (segs[i].linedef && segs[i].PartnerSeg != nullptr && !segs[i].PartnerSeg->linedef) + { + segs[i].PartnerSeg = segs[i].PartnerSeg->PartnerSeg = nullptr; + } } - // glbsp creates such incorrect references for Strife. - if (segs[i].linedef && glsegextras[i].PartnerSeg != DWORD_MAX && !segs[glsegextras[i].PartnerSeg].linedef) + for (i = 0; i < numsegs; i++) { - glsegextras[i].PartnerSeg = glsegextras[glsegextras[i].PartnerSeg].PartnerSeg = DWORD_MAX; - } - } - - for(i=0;iPartnerSeg != &segs[i]) + { + segs[i].PartnerSeg = nullptr; + } } } @@ -1498,7 +1488,7 @@ void P_SetRenderSector() seg = ss->firstline; for(j=0; jnumlines; j++) { - if(seg->sidedef && (glsegextras[seg - segs].PartnerSeg == DWORD_MAX || seg->sidedef->sector!=segs[glsegextras[seg - segs].PartnerSeg].sidedef->sector)) + if(seg->sidedef && (seg->PartnerSeg == nullptr || seg->sidedef->sector!=seg->PartnerSeg->sidedef->sector)) { ss->render_sector = seg->sidedef->sector; break; @@ -1522,15 +1512,14 @@ void P_SetRenderSector() for(j=0; jnumlines; j++) { - DWORD partner = glsegextras[seg - segs].PartnerSeg; - if (partner != DWORD_MAX && glsegextras[partner].Subsector) + if (seg->PartnerSeg != nullptr && seg->PartnerSeg->Subsector) { - sector_t * backsec = glsegextras[partner].Subsector->render_sector; + sector_t * backsec = seg->PartnerSeg->Subsector->render_sector; if (backsec) { - ss->render_sector=backsec; + ss->render_sector = backsec; undetermined.Delete(i); - deleted=1; + deleted = 1; break; } } diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp index 9aa178e64d..b6ffcb6995 100644 --- a/src/p_interaction.cpp +++ b/src/p_interaction.cpp @@ -60,6 +60,7 @@ #include "a_morph.h" #include "virtual.h" #include "a_health.h" +#include "g_levellocals.h" static FRandom pr_obituary ("Obituary"); static FRandom pr_botrespawn ("BotRespawn"); diff --git a/src/p_lights.cpp b/src/p_lights.cpp index d9fc19c79c..5442809e45 100644 --- a/src/p_lights.cpp +++ b/src/p_lights.cpp @@ -32,6 +32,7 @@ #include "p_lnspec.h" #include "doomstat.h" #include "p_maputl.h" +#include "g_levellocals.h" // State. #include "r_state.h" diff --git a/src/p_linkedsectors.cpp b/src/p_linkedsectors.cpp index 8a0cc9ca01..0dd29c10e2 100644 --- a/src/p_linkedsectors.cpp +++ b/src/p_linkedsectors.cpp @@ -37,6 +37,7 @@ #include "p_local.h" #include "p_lnspec.h" #include "p_spec.h" +#include "g_levellocals.h" enum { @@ -360,7 +361,7 @@ void P_AddSectorLinksByID(sector_t *control, int id, INTBOOL ceiling) int line; while ((line = itr.Next()) >= 0) { - line_t *ld = &lines[line]; + line_t *ld = &level.lines[line]; if (ld->special == Static_Init && ld->args[1] == Init_SectorLink) { diff --git a/src/p_lnspec.cpp b/src/p_lnspec.cpp index c1e342de82..77682d1e3b 100644 --- a/src/p_lnspec.cpp +++ b/src/p_lnspec.cpp @@ -61,6 +61,7 @@ #include "r_data/colormaps.h" #include "fragglescript/t_fs.h" #include "p_spec.h" +#include "g_levellocals.h" // Remaps EE sector change types to Generic_Floor values. According to the Eternity Wiki: /* @@ -2604,7 +2605,7 @@ FUNC(LS_Line_SetTextureOffset) int line; while ((line = itr.Next()) >= 0) { - side_t *side = lines[line].sidedef[arg3]; + side_t *side = level.lines[line].sidedef[arg3]; if (side != NULL) { @@ -2659,7 +2660,7 @@ FUNC(LS_Line_SetTextureScale) int line; while ((line = itr.Next()) >= 0) { - side_t *side = lines[line].sidedef[arg3]; + side_t *side = level.lines[line].sidedef[arg3]; if (side != NULL) { if ((arg4&8)==0) @@ -2733,7 +2734,7 @@ FUNC(LS_Line_SetBlocking) int line; while ((line = itr.Next()) >= 0) { - lines[line].flags = (lines[line].flags & ~clearflags) | setflags; + level.lines[line].flags = (level.lines[line].flags & ~clearflags) | setflags; } return true; } @@ -3028,14 +3029,14 @@ FUNC(LS_TranslucentLine) int linenum; while ((linenum = itr.Next()) >= 0) { - lines[linenum].alpha = clamp(arg1, 0, 255) / 255.; + level.lines[linenum].alpha = clamp(arg1, 0, 255) / 255.; if (arg2 == 0) { - lines[linenum].flags &= ~ML_ADDTRANS; + level.lines[linenum].flags &= ~ML_ADDTRANS; } else if (arg2 == 1) { - lines[linenum].flags |= ML_ADDTRANS; + level.lines[linenum].flags |= ML_ADDTRANS; } else { diff --git a/src/p_map.cpp b/src/p_map.cpp index 7f6a47b66f..d48fb4e5aa 100644 --- a/src/p_map.cpp +++ b/src/p_map.cpp @@ -63,6 +63,7 @@ #include "r_data/r_translate.h" #include "g_level.h" #include "r_sky.h" +#include "g_levellocals.h" CVAR(Bool, cl_bloodsplats, true, CVAR_ARCHIVE) CVAR(Int, sv_smartaim, 0, CVAR_ARCHIVE | CVAR_SERVERINFO) @@ -183,7 +184,7 @@ static bool PIT_FindFloorCeiling(FMultiBlockLinesIterator &mit, FMultiBlockLines if (ffcf_verbose) { Printf("Hit line %d at position %f,%f, group %d\n", - int(ld - lines), cres.Position.X, cres.Position.Y, ld->frontsector->PortalGroup); + ld->Index(), cres.Position.X, cres.Position.Y, ld->frontsector->PortalGroup); } if (!ld->backsector) @@ -3296,7 +3297,6 @@ bool FSlide::BounceTraverse(const DVector2 &start, const DVector2 &end) } li = in->d.line; - assert(((size_t)li - (size_t)lines) % sizeof(line_t) == 0); if (li->flags & ML_BLOCKEVERYTHING) { goto bounceblocking; @@ -3907,7 +3907,7 @@ struct aim_t int frontflag = P_PointOnLineSidePrecise(startpos, li); if (aimdebug) - Printf("Found line %d: ___toppitch = %f, ___bottompitch = %f\n", int(li - lines), toppitch.Degrees, bottompitch.Degrees); + Printf("Found line %d: toppitch = %f, bottompitch = %f\n", li->Index(), toppitch.Degrees, bottompitch.Degrees); if (li->isLinePortal() && frontflag == 0) { @@ -3951,7 +3951,7 @@ struct aim_t return; if (aimdebug) - Printf("After line %d: toppitch = %f, bottompitch = %f, planestocheck = %d\n", int(li - lines), toppitch.Degrees, bottompitch.Degrees, planestocheck); + Printf("After line %d: toppitch = %f, bottompitch = %f, planestocheck = %d\n", li->Index(), toppitch.Degrees, bottompitch.Degrees, planestocheck); sector_t *entersec = frontflag ? li->frontsector : li->backsector; sector_t *exitsec = frontflag ? li->backsector : li->frontsector; diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp index d4ac79ce7c..e6b2aebea1 100644 --- a/src/p_maputl.cpp +++ b/src/p_maputl.cpp @@ -44,6 +44,7 @@ #include "r_state.h" #include "templates.h" #include "po_man.h" +#include "g_levellocals.h" sector_t *P_PointInSectorBuggy(double x, double y); int P_VanillaPointOnDivlineSide(double x, double y, const divline_t* line); @@ -330,7 +331,7 @@ bool AActor::FixMapthingPos() for (list = blockmaplump + blockmap[blocky*bmapwidth + blockx] + 1; *list != -1; ++list) { - line_t *ldef = &lines[*list]; + line_t *ldef = &level.lines[*list]; if (ldef->frontsector == ldef->backsector) { // Skip two-sided lines inside a single sector @@ -367,10 +368,10 @@ bool AActor::FixMapthingPos() if (distance < radius) { - DPrintf(DMSG_NOTIFY, "%s at (%f,%f) lies on %s line %td, distance = %f\n", + DPrintf(DMSG_NOTIFY, "%s at (%f,%f) lies on %s line %d, distance = %f\n", this->GetClass()->TypeName.GetChars(), X(), Y(), ldef->Delta().X == 0 ? "vertical" : ldef->Delta().Y == 0 ? "horizontal" : "diagonal", - ldef - lines, distance); + ldef->Index(), distance); DAngle ang = ldef->Delta().Angle(); if (ldef->backsector != NULL && ldef->backsector == secstart) { @@ -709,7 +710,7 @@ line_t *FBlockLinesIterator::Next() { while (*list != -1) { - line_t *ld = &lines[*list]; + line_t *ld = &level.lines[*list]; list++; if (ld->validcount != validcount) diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 3bdf3718dc..d5ec020a05 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -72,6 +72,7 @@ #include "a_armor.h" #include "a_ammo.h" #include "a_health.h" +#include "g_levellocals.h" // MACROS ------------------------------------------------------------------ @@ -7539,6 +7540,22 @@ DEFINE_ACTION_FUNCTION(AActor, A_RestoreSpecialPosition) return 0; } +double AActor::GetBobOffset(double ticfrac) const +{ + if (!(flags2 & MF2_FLOATBOB)) + { + return 0; + } + return BobSin(FloatBobPhase + level.maptime + ticfrac); +} + +DEFINE_ACTION_FUNCTION(AActor, GetBobOffset) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_FLOAT_DEF(frac); + ACTION_RETURN_FLOAT(self->GetBobOffset(frac)); +} + @@ -7639,13 +7656,6 @@ DEFINE_ACTION_FUNCTION(AActor, GetDefaultByType) ACTION_RETURN_OBJECT(cls == nullptr? nullptr : GetDefaultByType(cls)); } -DEFINE_ACTION_FUNCTION(AActor, GetBobOffset) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_FLOAT_DEF(frac); - ACTION_RETURN_FLOAT(self->GetBobOffset(frac)); -} - // This combines all 3 variations of the internal function DEFINE_ACTION_FUNCTION(AActor, VelFromAngle) { diff --git a/src/p_pillar.cpp b/src/p_pillar.cpp index d4682e570a..d603edc8a0 100644 --- a/src/p_pillar.cpp +++ b/src/p_pillar.cpp @@ -39,6 +39,7 @@ #include "s_sndseq.h" #include "serializer.h" #include "r_data/r_interpolate.h" +#include "g_levellocals.h" IMPLEMENT_CLASS(DPillar, false, true) diff --git a/src/p_plats.cpp b/src/p_plats.cpp index 7bbf33b271..8dd82c024a 100644 --- a/src/p_plats.cpp +++ b/src/p_plats.cpp @@ -32,6 +32,7 @@ #include "gi.h" #include "serializer.h" #include "p_spec.h" +#include "g_levellocals.h" static FRandom pr_doplat ("DoPlat"); diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index c6f871acef..4d77bb6458 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -30,6 +30,7 @@ #include "serializer.h" #include "v_text.h" #include "cmdlib.h" +#include "g_levellocals.h" // MACROS ------------------------------------------------------------------ diff --git a/src/p_pusher.cpp b/src/p_pusher.cpp index 8a4032b402..5190b5ced0 100644 --- a/src/p_pusher.cpp +++ b/src/p_pusher.cpp @@ -32,6 +32,7 @@ #include "p_maputl.h" #include "p_local.h" #include "d_player.h" +#include "g_levellocals.h" CVAR(Bool, var_pushers, true, CVAR_SERVERINFO); @@ -358,11 +359,10 @@ AActor *P_GetPushThing (int s) void P_SpawnPushers () { - int i; - line_t *l = lines; + line_t *l = &level.lines[0]; int s; - for (i = 0; i < numlines; i++, l++) + for (unsigned i = 0; i < level.lines.Size(); i++, l++) { switch (l->special) { diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 5f9aeec427..227fc91fdc 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -62,6 +62,11 @@ #include "r_sky.h" #include "r_renderer.h" #include "serializer.h" +#include "g_levellocals.h" + +static TStaticArray loadsectors; +static TStaticArray loadlines; +static TStaticArray loadsides; //========================================================================== @@ -353,6 +358,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, subsector_t *&ss, subs str = &encoded[0]; if (arc.BeginArray(key)) { + auto numvertexes = level.vertexes.Size(); arc(nullptr, numvertexes) (nullptr, numsubsectors) .StringPtr(nullptr, str) @@ -371,7 +377,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, subsector_t *&ss, subs .StringPtr(nullptr, str) .EndArray(); - if (num_verts == numvertexes && num_subs == numsubsectors && hasglnodes) + if (num_verts == level.vertexes.Size() && num_subs == numsubsectors && hasglnodes) { success = true; int sub = 0; @@ -898,8 +904,8 @@ void G_SerializeLevel(FSerializer &arc, bool hubload) // deep down in the deserializer or just a crash if the few insufficient safeguards were not triggered. BYTE chk[16] = { 0 }; arc.Array("checksum", chk, 16); - if (arc.GetSize("linedefs") != (unsigned)numlines || - arc.GetSize("sidedefs") != (unsigned)numsides || + if (arc.GetSize("linedefs") != level.lines.Size() || + arc.GetSize("sidedefs") != level.sides.Size() || arc.GetSize("sectors") != level.sectors.Size() || arc.GetSize("polyobjs") != (unsigned)po_NumPolyobjs || memcmp(chk, level.md5, 16)) @@ -952,8 +958,8 @@ void G_SerializeLevel(FSerializer &arc, bool hubload) FBehavior::StaticSerializeModuleStates(arc); // The order here is important: First world state, then portal state, then thinkers, and last polyobjects. - arc.Array("linedefs", lines, &loadlines[0], numlines); - arc.Array("sidedefs", sides, &loadsides[0], numsides); + arc.Array("linedefs", &level.lines[0], &loadlines[0], level.lines.Size()); + arc.Array("sidedefs", &level.sides[0], &loadsides[0], level.sides.Size()); arc.Array("sectors", &level.sectors[0], &loadsectors[0], level.sectors.Size()); arc("zones", Zones); arc("lineportals", linePortals); @@ -988,4 +994,18 @@ void G_SerializeLevel(FSerializer &arc, bool hubload) } +// Create a backup of the map data so the savegame code can toss out all fields that haven't changed in order to reduce processing time and file size. +void P_BackupMapData() +{ + loadsectors = level.sectors; + loadlines = level.lines; + loadsides = level.sides; +} + +void P_FreeMapDataBackup() +{ + loadsectors.Clear(); + loadlines.Clear(); + loadsides.Clear(); +} \ No newline at end of file diff --git a/src/p_saveg.h b/src/p_saveg.h index 6c4c74f464..715fd6a19c 100644 --- a/src/p_saveg.h +++ b/src/p_saveg.h @@ -46,4 +46,7 @@ void P_WriteACSDefereds (FSerializer &); void G_SerializeLevel(FSerializer &arc, bool hubLoad); +void P_BackupMapData(); +void P_FreeMapDataBackup(); + #endif // __P_SAVEG_H__ diff --git a/src/p_scroll.cpp b/src/p_scroll.cpp index 954b1ac368..403eb30870 100644 --- a/src/p_scroll.cpp +++ b/src/p_scroll.cpp @@ -29,6 +29,7 @@ #include "serializer.h" #include "p_lnspec.h" #include "r_data/r_interpolate.h" +#include "g_levellocals.h" //----------------------------------------------------------------------------- // @@ -191,19 +192,19 @@ void DScroller::Tick () case EScroll::sc_side: // killough 3/7/98: Scroll wall texture if (m_Parts & EScrollPos::scw_top) { - sides[m_Affectee].AddTextureXOffset(side_t::top, dx); - sides[m_Affectee].AddTextureYOffset(side_t::top, dy); + level.sides[m_Affectee].AddTextureXOffset(side_t::top, dx); + level.sides[m_Affectee].AddTextureYOffset(side_t::top, dy); } - if (m_Parts & EScrollPos::scw_mid && (sides[m_Affectee].linedef->backsector == NULL || - !(sides[m_Affectee].linedef->flags&ML_3DMIDTEX))) + if (m_Parts & EScrollPos::scw_mid && (level.sides[m_Affectee].linedef->backsector == NULL || + !(level.sides[m_Affectee].linedef->flags&ML_3DMIDTEX))) { - sides[m_Affectee].AddTextureXOffset(side_t::mid, dx); - sides[m_Affectee].AddTextureYOffset(side_t::mid, dy); + level.sides[m_Affectee].AddTextureXOffset(side_t::mid, dx); + level.sides[m_Affectee].AddTextureYOffset(side_t::mid, dy); } if (m_Parts & EScrollPos::scw_bottom) { - sides[m_Affectee].AddTextureXOffset(side_t::bottom, dx); - sides[m_Affectee].AddTextureYOffset(side_t::bottom, dy); + level.sides[m_Affectee].AddTextureXOffset(side_t::bottom, dx); + level.sides[m_Affectee].AddTextureYOffset(side_t::bottom, dy); } break; @@ -276,19 +277,19 @@ DScroller::DScroller (EScroll type, double dx, double dy, break; case EScroll::sc_side: - sides[affectee].Flags |= WALLF_NOAUTODECALS; + level.sides[affectee].Flags |= WALLF_NOAUTODECALS; if (m_Parts & EScrollPos::scw_top) { - m_Interpolations[0] = sides[m_Affectee].SetInterpolation(side_t::top); + m_Interpolations[0] = level.sides[m_Affectee].SetInterpolation(side_t::top); } - if (m_Parts & EScrollPos::scw_mid && (sides[m_Affectee].linedef->backsector == NULL || - !(sides[m_Affectee].linedef->flags&ML_3DMIDTEX))) + if (m_Parts & EScrollPos::scw_mid && (level.sides[m_Affectee].linedef->backsector == nullptr || + !(level.sides[m_Affectee].linedef->flags&ML_3DMIDTEX))) { - m_Interpolations[1] = sides[m_Affectee].SetInterpolation(side_t::mid); + m_Interpolations[1] = level.sides[m_Affectee].SetInterpolation(side_t::mid); } if (m_Parts & EScrollPos::scw_bottom) { - m_Interpolations[2] = sides[m_Affectee].SetInterpolation(side_t::bottom); + m_Interpolations[2] = level.sides[m_Affectee].SetInterpolation(side_t::bottom); } break; @@ -349,22 +350,22 @@ DScroller::DScroller (double dx, double dy, const line_t *l, m_LastHeight = 0; if ((m_Control = control) != -1) m_LastHeight = level.sectors[control].CenterFloor() + level.sectors[control].CenterCeiling(); - m_Affectee = int(l->sidedef[0] - sides); - sides[m_Affectee].Flags |= WALLF_NOAUTODECALS; + m_Affectee = l->sidedef[0]->Index(); + level.sides[m_Affectee].Flags |= WALLF_NOAUTODECALS; m_Interpolations[0] = m_Interpolations[1] = m_Interpolations[2] = NULL; if (m_Parts & EScrollPos::scw_top) { - m_Interpolations[0] = sides[m_Affectee].SetInterpolation(side_t::top); + m_Interpolations[0] = level.sides[m_Affectee].SetInterpolation(side_t::top); } - if (m_Parts & EScrollPos::scw_mid && (sides[m_Affectee].linedef->backsector == NULL || - !(sides[m_Affectee].linedef->flags&ML_3DMIDTEX))) + if (m_Parts & EScrollPos::scw_mid && (level.sides[m_Affectee].linedef->backsector == NULL || + !(level.sides[m_Affectee].linedef->flags&ML_3DMIDTEX))) { - m_Interpolations[1] = sides[m_Affectee].SetInterpolation(side_t::mid); + m_Interpolations[1] = level.sides[m_Affectee].SetInterpolation(side_t::mid); } if (m_Parts & EScrollPos::scw_bottom) { - m_Interpolations[2] = sides[m_Affectee].SetInterpolation(side_t::bottom); + m_Interpolations[2] = level.sides[m_Affectee].SetInterpolation(side_t::bottom); } } @@ -380,24 +381,23 @@ DScroller::DScroller (double dx, double dy, const line_t *l, void P_SpawnScrollers(void) { - int i; - line_t *l = lines; + line_t *l = &level.lines[0]; TArray copyscrollers; - for (i = 0; i < numlines; i++) + for (auto &line : level.lines) { - if (lines[i].special == Sector_CopyScroller) + if (line.special == Sector_CopyScroller) { // don't allow copying the scroller if the sector has the same tag as it would just duplicate it. - if (!tagManager.SectorHasTag(lines[i].frontsector, lines[i].args[0])) + if (!tagManager.SectorHasTag(line.frontsector, line.args[0])) { - copyscrollers.Push(i); + copyscrollers.Push(line.Index()); } - lines[i].special = 0; + line.special = 0; } } - for (i = 0; i < numlines; i++, l++) + for (unsigned i = 0; i < level.lines.Size(); i++, l++) { double dx; // direction and speed of scrolling double dy; @@ -474,7 +474,7 @@ void P_SpawnScrollers(void) } for (unsigned j = 0; j < copyscrollers.Size(); j++) { - line_t *line = &lines[copyscrollers[j]]; + line_t *line = &level.lines[copyscrollers[j]]; if (line->args[0] == l->args[0] && (line->args[1] & 1)) { @@ -494,7 +494,7 @@ void P_SpawnScrollers(void) } for(unsigned j = 0;j < copyscrollers.Size(); j++) { - line_t *line = &lines[copyscrollers[j]]; + line_t *line = &level.lines[copyscrollers[j]]; if (line->args[0] == l->args[0] && (line->args[1] & 2)) { @@ -512,7 +512,7 @@ void P_SpawnScrollers(void) } for(unsigned j = 0;j < copyscrollers.Size(); j++) { - line_t *line = &lines[copyscrollers[j]]; + line_t *line = &level.lines[copyscrollers[j]]; if (line->args[0] == l->args[0] && (line->args[1] & 4)) { @@ -530,48 +530,48 @@ void P_SpawnScrollers(void) while ((s = itr.Next()) >= 0) { if (s != i) - new DScroller(dx, dy, lines + s, control, accel); + new DScroller(dx, dy, &level.lines[s], control, accel); } break; } case Scroll_Texture_Offsets: // killough 3/2/98: scroll according to sidedef offsets - s = int(lines[i].sidedef[0] - sides); - new DScroller (EScroll::sc_side, -sides[s].GetTextureXOffset(side_t::mid), - sides[s].GetTextureYOffset(side_t::mid), -1, s, accel, SCROLLTYPE(l->args[0])); + s = level.lines[i].sidedef[0]->Index(); + new DScroller (EScroll::sc_side, -level.sides[s].GetTextureXOffset(side_t::mid), + level.sides[s].GetTextureYOffset(side_t::mid), -1, s, accel, SCROLLTYPE(l->args[0])); break; case Scroll_Texture_Left: l->special = special; // Restore the special, for compat_useblocking's benefit. - s = int(lines[i].sidedef[0] - sides); + s = level.lines[i].sidedef[0]->Index(); new DScroller (EScroll::sc_side, l->args[0] / 64., 0, -1, s, accel, SCROLLTYPE(l->args[1])); break; case Scroll_Texture_Right: l->special = special; - s = int(lines[i].sidedef[0] - sides); + s = level.lines[i].sidedef[0]->Index(); new DScroller (EScroll::sc_side, -l->args[0] / 64., 0, -1, s, accel, SCROLLTYPE(l->args[1])); break; case Scroll_Texture_Up: l->special = special; - s = int(lines[i].sidedef[0] - sides); + s = level.lines[i].sidedef[0]->Index(); new DScroller (EScroll::sc_side, 0, l->args[0] / 64., -1, s, accel, SCROLLTYPE(l->args[1])); break; case Scroll_Texture_Down: l->special = special; - s = int(lines[i].sidedef[0] - sides); + s = level.lines[i].sidedef[0]->Index(); new DScroller (EScroll::sc_side, 0, -l->args[0] / 64., -1, s, accel, SCROLLTYPE(l->args[1])); break; case Scroll_Texture_Both: - s = int(lines[i].sidedef[0] - sides); + s = level.lines[i].sidedef[0]->Index(); if (l->args[0] == 0) { dx = (l->args[1] - l->args[2]) / 64.; dy = (l->args[4] - l->args[3]) / 64.; @@ -608,8 +608,8 @@ void SetWallScroller (int id, int sidechoice, double dx, double dy, EScrollPos W { int wallnum = scroller->GetWallNum (); - if (wallnum >= 0 && tagManager.LineHasID(sides[wallnum].linedef, id) && - int(sides[wallnum].linedef->sidedef[sidechoice] - sides) == wallnum && + if (wallnum >= 0 && tagManager.LineHasID(level.sides[wallnum].linedef, id) && + level.sides[wallnum].linedef->sidedef[sidechoice]->Index() == wallnum && Where == scroller->GetScrollParts()) { scroller->Destroy (); @@ -628,8 +628,8 @@ void SetWallScroller (int id, int sidechoice, double dx, double dy, EScrollPos W while ( (collect.Obj = iterator.Next ()) ) { if ((collect.RefNum = ((DScroller *)collect.Obj)->GetWallNum ()) != -1 && - tagManager.LineHasID(sides[collect.RefNum].linedef, id) && - int(sides[collect.RefNum].linedef->sidedef[sidechoice] - sides) == collect.RefNum && + tagManager.LineHasID(level.sides[collect.RefNum].linedef, id) && + level.sides[collect.RefNum].linedef->sidedef[sidechoice]->Index() == collect.RefNum && Where == ((DScroller *)collect.Obj)->GetScrollParts()) { ((DScroller *)collect.Obj)->SetRate (dx, dy); @@ -645,9 +645,9 @@ void SetWallScroller (int id, int sidechoice, double dx, double dy, EScrollPos W FLineIdIterator itr(id); while ((linenum = itr.Next()) >= 0) { - if (lines[linenum].sidedef[sidechoice] != NULL) + if (level.lines[linenum].sidedef[sidechoice] != NULL) { - int sidenum = int(lines[linenum].sidedef[sidechoice] - sides); + int sidenum = level.lines[linenum].sidedef[sidechoice]->Index(); unsigned int i; for (i = 0; i < numcollected; i++) { diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index d4abcc5343..c95f48d150 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -35,6 +35,7 @@ #include "p_local.h" #include "r_sky.h" #include "r_data/colormaps.h" +#include "g_levellocals.h" // [RH] @@ -710,7 +711,7 @@ double sector_t::FindHighestFloorPoint (vertex_t **v) const { if (v != NULL) { - if (Lines.Size() == 0) *v = &vertexes[0]; + if (Lines.Size() == 0) *v = &level.vertexes[0]; else *v = Lines[0]->v1; } return -floorplane.fD(); @@ -759,7 +760,7 @@ double sector_t::FindLowestCeilingPoint (vertex_t **v) const { if (v != NULL) { - if (Lines.Size() == 0) *v = &vertexes[0]; + if (Lines.Size() == 0) *v = &level.vertexes[0]; else *v = Lines[0]->v1; } return ceilingplane.fD(); @@ -1772,6 +1773,205 @@ DEFINE_ACTION_FUNCTION(_Sector, NextLowestFloorAt) ACTION_RETURN_FLOAT(self->CenterCeiling()); } + DEFINE_ACTION_FUNCTION(_Sector, Index) + { + PARAM_SELF_STRUCT_PROLOGUE(sector_t); + unsigned ndx = self->Index(); + if (ndx >= level.sectors.Size()) + { + // This qualifies as an array out of bounds exception. Normally it can only happen when a sector copy is concerned which scripts should not be able to create. + ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "Accessed invalid sector"); + } + ACTION_RETURN_INT(ndx); + } + + //=========================================================================== + // + // line_t exports + // + //=========================================================================== + + DEFINE_ACTION_FUNCTION(_Line, isLinePortal) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + ACTION_RETURN_BOOL(self->isLinePortal()); + } + + DEFINE_ACTION_FUNCTION(_Line, isVisualPortal) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + ACTION_RETURN_BOOL(self->isVisualPortal()); + } + + DEFINE_ACTION_FUNCTION(_Line, getPortalDestination) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + ACTION_RETURN_POINTER(self->getPortalDestination()); + } + + DEFINE_ACTION_FUNCTION(_Line, getPortalAlignment) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + ACTION_RETURN_INT(self->getPortalAlignment()); + } + + DEFINE_ACTION_FUNCTION(_Line, Index) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + unsigned ndx = self->Index(); + if (ndx >= level.lines.Size()) + { + ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "Accessed invalid line"); + } + ACTION_RETURN_INT(ndx); + } + + //=========================================================================== + // + // + // + //=========================================================================== + + DEFINE_ACTION_FUNCTION(_Side, GetTexture) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + PARAM_INT(which); + ACTION_RETURN_INT(self->GetTexture(which).GetIndex()); + } + + DEFINE_ACTION_FUNCTION(_Side, SetTexture) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + PARAM_INT(which); + PARAM_INT(tex); + self->SetTexture(which, FSetTextureID(tex)); + return 0; + } + + DEFINE_ACTION_FUNCTION(_Side, SetTextureXOffset) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + PARAM_INT(which); + PARAM_FLOAT(ofs); + self->SetTextureXOffset(which, ofs); + return 0; + } + + DEFINE_ACTION_FUNCTION(_Side, AddTextureXOffset) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + PARAM_INT(which); + PARAM_FLOAT(ofs); + self->AddTextureXOffset(which, ofs); + return 0; + } + + DEFINE_ACTION_FUNCTION(_Side, GetTextureXOffset) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + PARAM_INT(which); + ACTION_RETURN_FLOAT(self->GetTextureXOffset(which)); + } + + DEFINE_ACTION_FUNCTION(_Side, SetTextureYOffset) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + PARAM_INT(which); + PARAM_FLOAT(ofs); + self->SetTextureYOffset(which, ofs); + return 0; + } + + DEFINE_ACTION_FUNCTION(_Side, AddTextureYOffset) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + PARAM_INT(which); + PARAM_FLOAT(ofs); + self->AddTextureYOffset(which, ofs); + return 0; + } + + DEFINE_ACTION_FUNCTION(_Side, GetTextureYOffset) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + PARAM_INT(which); + ACTION_RETURN_FLOAT(self->GetTextureYOffset(which)); + } + + DEFINE_ACTION_FUNCTION(_Side, SetTextureXScale) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + PARAM_INT(which); + PARAM_FLOAT(ofs); + self->SetTextureXScale(which, ofs); + return 0; + } + + DEFINE_ACTION_FUNCTION(_Side, MultiplyTextureXScale) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + PARAM_INT(which); + PARAM_FLOAT(ofs); + self->MultiplyTextureXScale(which, ofs); + return 0; + } + + DEFINE_ACTION_FUNCTION(_Side, GetTextureXScale) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + PARAM_INT(which); + ACTION_RETURN_FLOAT(self->GetTextureXScale(which)); + } + + DEFINE_ACTION_FUNCTION(_Side, SetTextureYScale) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + PARAM_INT(which); + PARAM_FLOAT(ofs); + self->SetTextureYScale(which, ofs); + return 0; + } + + DEFINE_ACTION_FUNCTION(_Side, MultiplyTextureYScale) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + PARAM_INT(which); + PARAM_FLOAT(ofs); + self->MultiplyTextureYScale(which, ofs); + return 0; + } + + DEFINE_ACTION_FUNCTION(_Side, GetTextureYScale) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + PARAM_INT(which); + ACTION_RETURN_FLOAT(self->GetTextureYScale(which)); + } + + DEFINE_ACTION_FUNCTION(_Side, V1) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + ACTION_RETURN_POINTER(self->V1()); + } + + DEFINE_ACTION_FUNCTION(_Side, V2) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + ACTION_RETURN_POINTER(self->V2()); + } + + DEFINE_ACTION_FUNCTION(_Side, Index) + { + PARAM_SELF_STRUCT_PROLOGUE(side_t); + ACTION_RETURN_INT(self->Index()); + } + + DEFINE_ACTION_FUNCTION(_Vertex, Index) + { + PARAM_SELF_STRUCT_PROLOGUE(vertex_t); + ACTION_RETURN_INT(self->Index()); + } + //=========================================================================== // // @@ -1838,7 +2038,7 @@ bool secplane_t::CopyPlaneIfValid (secplane_t *dest, const secplane_t *opp) cons bool P_AlignFlat (int linenum, int side, int fc) { - line_t *line = lines + linenum; + line_t *line = &level.lines[linenum]; sector_t *sec = side ? line->backsector : line->frontsector; if (!sec) @@ -1871,10 +2071,10 @@ void subsector_t::BuildPolyBSP() assert((BSP == NULL || BSP->bDirty) && "BSP computed more than once"); // Set up level information for the node builder. - PolyNodeLevel.Sides = sides; - PolyNodeLevel.NumSides = numsides; - PolyNodeLevel.Lines = lines; - PolyNodeLevel.NumLines = numlines; + PolyNodeLevel.Sides = &level.sides[0]; + PolyNodeLevel.NumSides = level.sides.Size(); + PolyNodeLevel.Lines = &level.lines[0]; + PolyNodeLevel.NumLines = numlines; // is this correct??? // Feed segs to the nodebuilder and build the nodes. PolyNodeBuilder.Clear(); @@ -2100,6 +2300,12 @@ DEFINE_FIELD_X(Line, line_t, backsector) DEFINE_FIELD_X(Line, line_t, validcount) DEFINE_FIELD_X(Line, line_t, locknumber) DEFINE_FIELD_X(Line, line_t, portalindex) +DEFINE_FIELD_X(Line, line_t, portaltransferred) + +DEFINE_FIELD_X(Side, side_t, sector) +DEFINE_FIELD_X(Side, side_t, linedef) +DEFINE_FIELD_X(Side, side_t, Light) +DEFINE_FIELD_X(Side, side_t, Flags) DEFINE_FIELD_X(Secplane, secplane_t, normal) DEFINE_FIELD_X(Secplane, secplane_t, D) diff --git a/src/p_setup.cpp b/src/p_setup.cpp index e03b7ac231..ad713fab98 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -73,6 +73,8 @@ #include "p_blockmap.h" #include "r_utility.h" #include "p_spec.h" +#include "p_saveg.h" +#include "g_levellocals.h" #ifndef NO_EDATA #include "edata.h" #endif @@ -88,7 +90,6 @@ void BloodCrypt (void *data, int key, int len); void P_ClearUDMFKeys(); extern AActor *P_SpawnMapThing (FMapThing *mthing, int position); -extern bool P_LoadBuildMap (BYTE *mapdata, size_t len, FMapThing **things, int *numthings); extern void P_TranslateTeleportThings (void); @@ -106,25 +107,25 @@ CVAR (Bool, showloadtimes, false, 0); static void P_Shutdown (); -bool P_IsBuildMap(MapData *map); +inline bool P_IsBuildMap(MapData *map) +{ + return false; +} + +inline bool P_LoadBuildMap(BYTE *mapdata, size_t len, FMapThing **things, int *numthings) +{ + return false; +} // // MAP related Lookup tables. // Store VERTEXES, LINEDEFS, SIDEDEFS, etc. // -int numvertexes; -vertex_t* vertexes; -int numvertexdatas; -vertexdata_t* vertexdatas; +TArray vertexdatas; int numsegs; seg_t* segs; -glsegextra_t* glsegextras; - -//int numsectors; -//sector_t* sectors; -TArray loadsectors; int numsubsectors; subsector_t* subsectors; @@ -132,14 +133,6 @@ subsector_t* subsectors; int numnodes; node_t* nodes; -int numlines; -line_t* lines; -TArray loadlines; - -int numsides; -side_t* sides; -TArray loadsides; - TArray Zones; node_t * gamenodes; @@ -195,7 +188,7 @@ TArray deathmatchstarts (16); FPlayerStart playerstarts[MAXPLAYERS]; TArray AllPlayerStarts; -static void P_AllocateSideDefs (int count); +static void P_AllocateSideDefs (MapData *map, int count); //=========================================================================== @@ -594,11 +587,11 @@ static void SetTexture (side_t *side, int position, const char *name, FMissingTe { // Print an error that lists all references to this sidedef. // We must scan the linedefs manually for all references to this sidedef. - for(int i = 0; i < numlines; i++) + for(unsigned i = 0; i < level.lines.Size(); i++) { for(int j = 0; j < 2; j++) { - if (lines[i].sidedef[j] == side) + if (level.lines[i].sidedef[j] == side) { Printf(TEXTCOLOR_RED"Unknown %s texture '" TEXTCOLOR_ORANGE "%s" TEXTCOLOR_RED @@ -836,12 +829,9 @@ void P_FloodZones () void P_LoadVertexes (MapData * map) { - int i; - // Determine number of vertices: // total lump length / vertex record length. - numvertexes = map->Size(ML_VERTEXES) / sizeof(mapvertex_t); - numvertexdatas = 0; + unsigned numvertexes = map->Size(ML_VERTEXES) / sizeof(mapvertex_t); if (numvertexes == 0) { @@ -849,18 +839,18 @@ void P_LoadVertexes (MapData * map) } // Allocate memory for buffer. - vertexes = new vertex_t[numvertexes]; - vertexdatas = NULL; + level.vertexes.Alloc(numvertexes); + vertexdatas.Clear(); map->Seek(ML_VERTEXES); // Copy and convert vertex coordinates, internal representation as fixed. - for (i = 0; i < numvertexes; i++) + for (auto &v : level.vertexes) { - SWORD x, y; + int16_t x, y; (*map->file) >> x >> y; - vertexes[i].set(double(x), double(y)); + v.set(double(x), double(y)); } } @@ -881,9 +871,9 @@ void P_LoadZSegs (FileReaderBase &data) data >> v1 >> v2 >> line >> side; - segs[i].v1 = &vertexes[v1]; - segs[i].v2 = &vertexes[v2]; - segs[i].linedef = ldef = &lines[line]; + segs[i].v1 = &level.vertexes[v1]; + segs[i].v2 = &level.vertexes[v2]; + segs[i].linedef = ldef = &level.lines[line]; segs[i].sidedef = ldef->sidedef[side]; segs[i].frontsector = ldef->sidedef[side]->sector; if (ldef->flags & ML_TWOSIDED && ldef->sidedef[side^1] != NULL) @@ -931,7 +921,7 @@ void P_LoadGLZSegs (FileReaderBase &data, int type) data >> side; seg = subsectors[i].firstline + j; - seg->v1 = &vertexes[v1]; + seg->v1 = &level.vertexes[v1]; if (j == 0) { seg[subsectors[i].numlines - 1].v2 = seg->v1; @@ -940,12 +930,12 @@ void P_LoadGLZSegs (FileReaderBase &data, int type) { seg[-1].v2 = seg->v1; } - glsegextras[seg - segs].PartnerSeg = partner; + seg->PartnerSeg = &segs[partner]; if (line != 0xFFFFFFFF) { line_t *ldef; - seg->linedef = ldef = &lines[line]; + seg->linedef = ldef = &level.lines[line]; seg->sidedef = ldef->sidedef[side]; seg->frontsector = ldef->sidedef[side]->sector; if (ldef->flags & ML_TWOSIDED && ldef->sidedef[side^1] != NULL) @@ -978,23 +968,26 @@ void LoadZNodes(FileReaderBase &data, int glnodes) { // Read extra vertices added during node building DWORD orgVerts, newVerts; - vertex_t *newvertarray; + TStaticArray newvertarray; unsigned int i; data >> orgVerts >> newVerts; - if (orgVerts > (DWORD)numvertexes) + if (orgVerts > level.vertexes.Size()) { // These nodes are based on a map with more vertex data than we have. // We can't use them. throw CRecoverableError("Incorrect number of vertexes in nodes.\n"); } - if (orgVerts + newVerts == (DWORD)numvertexes) + bool fix; + if (orgVerts + newVerts == level.vertexes.Size()) { - newvertarray = vertexes; + newvertarray = std::move(level.vertexes); + fix = false; } else { - newvertarray = new vertex_t[orgVerts + newVerts]; - memcpy (newvertarray, vertexes, orgVerts * sizeof(vertex_t)); + newvertarray.Alloc(orgVerts + newVerts); + memcpy (&newvertarray[0], &level.vertexes[0], orgVerts * sizeof(vertex_t)); + fix = true; } for (i = 0; i < newVerts; ++i) { @@ -1002,16 +995,14 @@ void LoadZNodes(FileReaderBase &data, int glnodes) data >> x >> y; newvertarray[i + orgVerts].set(x, y); } - if (vertexes != newvertarray) + if (fix) { - for (i = 0; i < (DWORD)numlines; ++i) + for (auto &line : level.lines) { - lines[i].v1 = lines[i].v1 - vertexes + newvertarray; - lines[i].v2 = lines[i].v2 - vertexes + newvertarray; + line.v1 = line.v1 - &level.vertexes[0] + &newvertarray[0]; + line.v2 = line.v2 - &level.vertexes[0] + &newvertarray[0]; } - delete[] vertexes; - vertexes = newvertarray; - numvertexes = orgVerts + newVerts; + level.vertexes = std::move(newvertarray); } // Read the subsectors @@ -1047,7 +1038,6 @@ void LoadZNodes(FileReaderBase &data, int glnodes) numsegs = numSegs; segs = new seg_t[numsegs]; memset (segs, 0, numsegs*sizeof(seg_t)); - glsegextras = NULL; for (i = 0; i < numSubs; ++i) { @@ -1060,7 +1050,6 @@ void LoadZNodes(FileReaderBase &data, int glnodes) } else { - glsegextras = new glsegextra_t[numsegs]; P_LoadGLZSegs (data, glnodes); } @@ -1215,9 +1204,9 @@ void P_LoadSegs (MapData * map) { int i; BYTE *data; + int numvertexes = level.vertexes.Size(); BYTE *vertchanged = new BYTE[numvertexes]; // phares 10/4/98 DWORD segangle; - line_t* line; // phares 10/4/98 //int ptp_angle; // phares 10/4/98 //int delta_angle; // phares 10/4/98 int vnum1,vnum2; // phares 10/4/98 @@ -1252,10 +1241,9 @@ void P_LoadSegs (MapData * map) // Mark those used by linedefs. A marked vertex is one that is not a // candidate for movement further down. - line = lines; - for (i = 0; i < numlines ; i++, line++) + for (auto &line : level.lines) { - vertchanged[line->v1 - vertexes] = vertchanged[line->v2 - vertexes] = 1; + vertchanged[line.v1->Index()] = vertchanged[line.v2->Index()] = 1; } try @@ -1276,8 +1264,8 @@ void P_LoadSegs (MapData * map) throw badseg(0, i, MAX(vnum1, vnum2)); } - li->v1 = &vertexes[vnum1]; - li->v2 = &vertexes[vnum2]; + li->v1 = &level.vertexes[vnum1]; + li->v2 = &level.vertexes[vnum2]; segangle = (WORD)LittleShort(ml->angle); @@ -1332,16 +1320,16 @@ void P_LoadSegs (MapData * map) } linedef = LittleShort(ml->linedef); - if ((unsigned)linedef >= (unsigned)numlines) + if ((unsigned)linedef >= level.lines.Size()) { throw badseg(1, i, linedef); } - ldef = &lines[linedef]; + ldef = &level.lines[linedef]; li->linedef = ldef; side = LittleShort(ml->side); - if ((unsigned)(ldef->sidedef[side] - sides) >= (unsigned)numsides) + if ((unsigned)(ldef->sidedef[side]->Index()) >= level.sides.Size()) { - throw badseg(2, i, int(ldef->sidedef[side] - sides)); + throw badseg(2, i, ldef->sidedef[side]->Index()); } li->sidedef = ldef->sidedef[side]; li->frontsector = ldef->sidedef[side]->sector; @@ -1367,11 +1355,11 @@ void P_LoadSegs (MapData * map) break; case 1: - Printf ("Seg %d references a nonexistant linedef %d (max %d).\n", bad.badsegnum, bad.baddata, numlines); + Printf ("Seg %d references a nonexistant linedef %d (max %u).\n", bad.badsegnum, bad.baddata, level.lines.Size()); break; case 2: - Printf ("The linedef for seg %d references a nonexistant sidedef %d (max %d).\n", bad.badsegnum, bad.baddata, numsides); + Printf ("The linedef for seg %d references a nonexistant sidedef %d (max %d).\n", bad.badsegnum, bad.baddata, level.sides.Size()); break; } Printf ("The BSP will be rebuilt.\n"); @@ -1981,7 +1969,7 @@ void P_SaveLineSpecial (line_t *ld) if (ld->sidedef[0] == NULL) return; - DWORD sidenum = DWORD(ld->sidedef[0]-sides); + DWORD sidenum = ld->sidedef[0]->Index(); // killough 4/4/98: support special sidedef interpretation below // [RH] Save Static_Init only if it's interested in the textures if (ld->special != Static_Init || ld->args[1] == Init_Color) @@ -2003,7 +1991,7 @@ void P_FinishLoadingLineDef(line_t *ld, int alpha) ld->backsector = ld->sidedef[1] != NULL ? ld->sidedef[1]->sector : NULL; double dx = (ld->v2->fX() - ld->v1->fX()); double dy = (ld->v2->fY() - ld->v1->fY()); - int linenum = int(ld-lines); + int linenum = ld->Index(); if (ld->frontsector == NULL) { @@ -2027,8 +2015,6 @@ void P_FinishLoadingLineDef(line_t *ld, int alpha) switch (ld->special) { // killough 4/11/98: handle special types - int j; - case TranslucentLine: // killough 4/11/98: translucent 2s textures // [RH] Second arg controls how opaque it is. if (alpha == SHRT_MIN) @@ -2053,14 +2039,14 @@ void P_FinishLoadingLineDef(line_t *ld, int alpha) } else { - for (j = 0; j < numlines; j++) + for (unsigned j = 0; j < level.lines.Size(); j++) { if (tagManager.LineHasID(j, ld->args[0])) { - lines[j].alpha = dalpha; + level.lines[j].alpha = dalpha; if (additive) { - lines[j].flags |= ML_ADDTRANS; + level.lines[j].flags |= ML_ADDTRANS; } } } @@ -2072,9 +2058,9 @@ void P_FinishLoadingLineDef(line_t *ld, int alpha) // killough 4/4/98: delay using sidedefs until they are loaded void P_FinishLoadingLineDefs () { - for (int i = 0; i < numlines; i++) + for (auto &line : level.lines) { - P_FinishLoadingLineDef(&lines[i], sidetemp[lines[i].sidedef[0]-sides].a.alpha); + P_FinishLoadingLineDef(&line, sidetemp[line.sidedef[0]->Index()].a.alpha); } } @@ -2084,10 +2070,10 @@ static void P_SetSideNum (side_t **sidenum_p, WORD sidenum) { *sidenum_p = NULL; } - else if (sidecount < numsides) + else if (sidecount < (int)level.sides.Size()) { sidetemp[sidecount].a.map = sidenum; - *sidenum_p = &sides[sidecount++]; + *sidenum_p = &level.sides[sidecount++]; } else { @@ -2103,10 +2089,10 @@ void P_LoadLineDefs (MapData * map) char * mldf; maplinedef_t *mld; - numlines = lumplen / sizeof(maplinedef_t); - lines = new line_t[numlines]; + int numlines = lumplen / sizeof(maplinedef_t); + level.lines.Alloc(numlines); linemap.Resize(numlines); - memset (lines, 0, numlines*sizeof(line_t)); + memset (&level.lines[0], 0, numlines*sizeof(line_t)); mldf = new char[lumplen]; map->Read(ML_LINEDEFS, mldf); @@ -2118,17 +2104,16 @@ void P_LoadLineDefs (MapData * map) for (skipped = sidecount = i = 0; i < numlines; ) { mld = ((maplinedef_t*)mldf) + i; - int v1 = LittleShort(mld->v1); - int v2 = LittleShort(mld->v2); + unsigned v1 = LittleShort(mld->v1); + unsigned v2 = LittleShort(mld->v2); - if (v1 >= numvertexes || v2 >= numvertexes) + if (v1 >= level.vertexes.Size() || v2 >= level.vertexes.Size()) { delete [] mldf; - I_Error ("Line %d has invalid vertices: %d and/or %d.\nThe map only contains %d vertices.", i+skipped, v1, v2, numvertexes); + I_Error ("Line %d has invalid vertices: %d and/or %d.\nThe map only contains %u vertices.", i+skipped, v1, v2, level.vertexes.Size()); } else if (v1 == v2 || - (vertexes[LittleShort(mld->v1)].fX() == vertexes[LittleShort(mld->v2)].fX() && - vertexes[LittleShort(mld->v1)].fY() == vertexes[LittleShort(mld->v2)].fY())) + (level.vertexes[v1].fX() == level.vertexes[v2].fX() && level.vertexes[v1].fY() == level.vertexes[v2].fY())) { Printf ("Removing 0-length line %d\n", i+skipped); memmove (mld, mld+1, sizeof(*mld)*(numlines-i-1)); @@ -2153,14 +2138,15 @@ void P_LoadLineDefs (MapData * map) } } - P_AllocateSideDefs (sidecount); + P_AllocateSideDefs (map, sidecount); mld = (maplinedef_t *)mldf; - ld = lines; + ld = &level.lines[0]; for (i = 0; i < numlines; i++, mld++, ld++) { ld->alpha = 1.; // [RH] Opaque by default ld->portalindex = UINT_MAX; + ld->portaltransferred = UINT_MAX; // [RH] Translate old linedef special and flags to be // compatible with the new format. @@ -2178,8 +2164,8 @@ void P_LoadLineDefs (MapData * map) } #endif - ld->v1 = &vertexes[LittleShort(mld->v1)]; - ld->v2 = &vertexes[LittleShort(mld->v2)]; + ld->v1 = &level.vertexes[LittleShort(mld->v1)]; + ld->v2 = &level.vertexes[LittleShort(mld->v2)]; P_SetSideNum (&ld->sidedef[0], LittleShort(mld->sidenum[0])); P_SetSideNum (&ld->sidedef[1], LittleShort(mld->sidenum[1])); @@ -2202,10 +2188,10 @@ void P_LoadLineDefs2 (MapData * map) char * mldf; maplinedef2_t *mld; - numlines = lumplen / sizeof(maplinedef2_t); - lines = new line_t[numlines]; + int numlines = lumplen / sizeof(maplinedef2_t); + level.lines.Alloc(numlines); linemap.Resize(numlines); - memset (lines, 0, numlines*sizeof(line_t)); + memset (&level.lines[0], 0, numlines*sizeof(line_t)); mldf = new char[lumplen]; map->Read(ML_LINEDEFS, mldf); @@ -2216,8 +2202,8 @@ void P_LoadLineDefs2 (MapData * map) mld = ((maplinedef2_t*)mldf) + i; if (mld->v1 == mld->v2 || - (vertexes[LittleShort(mld->v1)].fX() == vertexes[LittleShort(mld->v2)].fX() && - vertexes[LittleShort(mld->v1)].fY() == vertexes[LittleShort(mld->v2)].fY())) + (level.vertexes[LittleShort(mld->v1)].fX() == level.vertexes[LittleShort(mld->v2)].fX() && + level.vertexes[LittleShort(mld->v1)].fY() == level.vertexes[LittleShort(mld->v2)].fY())) { Printf ("Removing 0-length line %d\n", i+skipped); memmove (mld, mld+1, sizeof(*mld)*(numlines-i-1)); @@ -2245,15 +2231,16 @@ void P_LoadLineDefs2 (MapData * map) ForceNodeBuild = true; } - P_AllocateSideDefs (sidecount); + P_AllocateSideDefs (map, sidecount); mld = (maplinedef2_t *)mldf; - ld = lines; + ld = &level.lines[0]; for (i = 0; i < numlines; i++, mld++, ld++) { int j; ld->portalindex = UINT_MAX; + ld->portaltransferred = UINT_MAX; for (j = 0; j < 5; j++) ld->args[j] = mld->args[j]; @@ -2261,8 +2248,8 @@ void P_LoadLineDefs2 (MapData * map) ld->flags = LittleShort(mld->flags); ld->special = mld->special; - ld->v1 = &vertexes[LittleShort(mld->v1)]; - ld->v2 = &vertexes[LittleShort(mld->v2)]; + ld->v1 = &level.vertexes[LittleShort(mld->v1)]; + ld->v2 = &level.vertexes[LittleShort(mld->v2)]; ld->alpha = 1.; // [RH] Opaque by default P_SetSideNum (&ld->sidedef[0], LittleShort(mld->sidenum[0])); @@ -2294,26 +2281,22 @@ void P_LoadLineDefs2 (MapData * map) // // P_LoadSideDefs // -// killough 4/4/98: split into two functions -void P_LoadSideDefs (MapData * map) -{ - numsides = map->Size(ML_SIDEDEFS) / sizeof(mapsidedef_t); -} -static void P_AllocateSideDefs (int count) +static void P_AllocateSideDefs (MapData *map, int count) { int i; - sides = new side_t[count]; - memset (sides, 0, count*sizeof(side_t)); + level.sides.Alloc(count); + memset(&level.sides[0], 0, count * sizeof(side_t)); - sidetemp = new sidei_t[MAX(count,numvertexes)]; + sidetemp = new sidei_t[MAX(count, level.vertexes.Size())]; for (i = 0; i < count; i++) { sidetemp[i].a.special = sidetemp[i].a.tag = 0; sidetemp[i].a.alpha = SHRT_MIN; sidetemp[i].a.map = NO_SIDE; } + auto numsides = map->Size(ML_SIDEDEFS) / sizeof(mapsidedef_t); if (count < numsides) { Printf ("Map has %d unused sidedefs\n", numsides - count); @@ -2334,9 +2317,10 @@ static void P_LoopSidedefs (bool firstloop) { delete[] sidetemp; } - sidetemp = new sidei_t[MAX(numvertexes, numsides)]; + int numsides = level.sides.Size(); + sidetemp = new sidei_t[MAX(level.vertexes.Size(), numsides)]; - for (i = 0; i < numvertexes; ++i) + for (i = 0; i < (int)level.vertexes.Size(); ++i) { sidetemp[i].b.first = NO_SIDE; sidetemp[i].b.next = NO_SIDE; @@ -2350,17 +2334,17 @@ static void P_LoopSidedefs (bool firstloop) { // For each vertex, build a list of sidedefs that use that vertex // as their left edge. - line_t *line = sides[i].linedef; - int lineside = (line->sidedef[0] != &sides[i]); - int vert = int((lineside ? line->v2 : line->v1) - vertexes); + line_t *line = level.sides[i].linedef; + int lineside = (line->sidedef[0] != &level.sides[i]); + int vert = lineside ? line->v2->Index() : line->v1->Index(); sidetemp[i].b.lineside = lineside; sidetemp[i].b.next = sidetemp[vert].b.first; sidetemp[vert].b.first = i; // Set each side so that it is the only member of its loop - sides[i].LeftSide = NO_SIDE; - sides[i].RightSide = NO_SIDE; + level.sides[i].LeftSide = NO_SIDE; + level.sides[i].RightSide = NO_SIDE; } // For each side, find the side that is to its right and set the @@ -2369,7 +2353,7 @@ static void P_LoopSidedefs (bool firstloop) for (i = 0; i < numsides; ++i) { DWORD right; - line_t *line = sides[i].linedef; + line_t *line = level.sides[i].linedef; // If the side's line only exists in a single sector, // then consider that line to be a self-contained loop @@ -2381,21 +2365,21 @@ static void P_LoopSidedefs (bool firstloop) if (NULL == rightside) { // There is no right side! - if (firstloop) Printf ("Line %d's right edge is unconnected\n", linemap[unsigned(line-lines)]); + if (firstloop) Printf ("Line %d's right edge is unconnected\n", linemap[line->Index()]); continue; } - right = DWORD(rightside - sides); + right = rightside->Index(); } else { if (sidetemp[i].b.lineside) { - right = int(line->v1 - vertexes); + right = line->v1->Index(); } else { - right = int(line->v2 - vertexes); + right = line->v2->Index(); } right = sidetemp[right].b.first; @@ -2403,7 +2387,7 @@ static void P_LoopSidedefs (bool firstloop) if (right == NO_SIDE) { // There is no right side! - if (firstloop) Printf ("Line %d's right edge is unconnected\n", linemap[unsigned(line-lines)]); + if (firstloop) Printf ("Line %d's right edge is unconnected\n", linemap[line->Index()]); continue; } @@ -2414,7 +2398,7 @@ static void P_LoopSidedefs (bool firstloop) line_t *leftline, *rightline; DAngle ang1, ang2, ang; - leftline = sides[i].linedef; + leftline = level.sides[i].linedef; ang1 = leftline->Delta().Angle(); if (!sidetemp[i].b.lineside) { @@ -2423,9 +2407,9 @@ static void P_LoopSidedefs (bool firstloop) while (right != NO_SIDE) { - if (sides[right].LeftSide == NO_SIDE) + if (level.sides[right].LeftSide == NO_SIDE) { - rightline = sides[right].linedef; + rightline = level.sides[right].linedef; if (rightline->frontsector != rightline->backsector) { ang2 = rightline->Delta().Angle(); @@ -2450,8 +2434,8 @@ static void P_LoopSidedefs (bool firstloop) } assert((unsigned)i<(unsigned)numsides); assert(right<(unsigned)numsides); - sides[i].RightSide = right; - sides[right].LeftSide = i; + level.sides[i].RightSide = right; + level.sides[right].LeftSide = i; } // We keep the sidedef init info around until after polyobjects are initialized, @@ -2607,14 +2591,13 @@ void P_ProcessSideTextures(bool checktranmap, side_t *sd, sector_t *sec, intmaps void P_LoadSideDefs2 (MapData *map, FMissingTextureTracker &missingtex) { - int i; char * msdf = new char[map->Size(ML_SIDEDEFS)]; map->Read(ML_SIDEDEFS, msdf); - for (i = 0; i < numsides; i++) + for (unsigned i = 0; i < level.sides.Size(); i++) { mapsidedef_t *msd = ((mapsidedef_t*)msdf) + sidetemp[i].a.map; - side_t *sd = sides + i; + side_t *sd = &level.sides[i]; sector_t *sec; // [RH] The Doom renderer ignored the patch y locations when @@ -2631,7 +2614,7 @@ void P_LoadSideDefs2 (MapData *map, FMissingTextureTracker &missingtex) sd->SetTextureYScale(1.); sd->linedef = NULL; sd->Flags = 0; - sd->Index = i; + sd->UDMFIndex = i; // killough 4/4/98: allow sidedef texture names to be overloaded // killough 4/11/98: refined to allow colormaps to work as wall @@ -2773,22 +2756,21 @@ static void P_CreateBlockMap () int bmapwidth, bmapheight; double dminx, dmaxx, dminy, dmaxy; int minx, maxx, miny, maxy; - int i; int line; - if (numvertexes <= 0) + if (level.vertexes.Size() == 0) return; // Find map extents for the blockmap - dminx = dmaxx = vertexes[0].fX(); - dminy = dmaxy = vertexes[0].fY(); + dminx = dmaxx = level.vertexes[0].fX(); + dminy = dmaxy = level.vertexes[0].fY(); - for (i = 1; i < numvertexes; ++i) + for (auto &vert : level.vertexes) { - if (vertexes[i].fX() < dminx) dminx = vertexes[i].fX(); - else if (vertexes[i].fX() > dmaxx) dmaxx = vertexes[i].fX(); - if (vertexes[i].fY() < dminy) dminy = vertexes[i].fY(); - else if (vertexes[i].fY() > dmaxy) dmaxy = vertexes[i].fY(); + if (vert.fX() < dminx) dminx = vert.fX(); + else if (vert.fX() > dmaxx) dmaxx = vert.fX(); + if (vert.fY() < dminy) dminy = vert.fY(); + else if (vert.fY() > dmaxy) dmaxy = vert.fY(); } minx = int(dminx); @@ -2808,12 +2790,12 @@ static void P_CreateBlockMap () BlockLists = new TArray[bmapwidth * bmapheight]; - for (line = 0; line < numlines; ++line) + for (line = 0; line < (int)level.lines.Size(); ++line) { - int x1 = int(lines[line].v1->fX()); - int y1 = int(lines[line].v1->fY()); - int x2 = int(lines[line].v2->fX()); - int y2 = int(lines[line].v2->fY()); + int x1 = int(level.lines[line].v1->fX()); + int y1 = int(level.lines[line].v1->fY()); + int x2 = int(level.lines[line].v2->fX()); + int y2 = int(level.lines[line].v2->fY()); int dx = x2 - x1; int dy = y2 - y1; int bx = (x1 - minx) >> BLOCKBITS; @@ -2996,7 +2978,7 @@ static bool P_VerifyBlockMap(int count) // scan the list for out-of-range linedef indicies in list for(tmplist = list; *tmplist != -1; tmplist++) { - if(*tmplist < 0 || *tmplist >= numlines) + if((unsigned)*tmplist >= level.lines.Size()) { Printf(PRINT_HIGH, "P_VerifyBlockMap: index >= numlines\n"); return false; @@ -3105,14 +3087,11 @@ static void P_GroupLines (bool buildmap) { subsectors[i].sector = subsectors[i].firstline->sidedef->sector; } - if (glsegextras != NULL) + for (int i = 0; i < numsubsectors; i++) { - for (int i = 0; i < numsubsectors; i++) + for (jj = 0; jj < subsectors[i].numlines; ++jj) { - for (jj = 0; jj < subsectors[i].numlines; ++jj) - { - glsegextras[subsectors[i].firstline - segs + jj].Subsector = &subsectors[i]; - } + subsectors[i].firstline[jj].Subsector = &subsectors[i]; } } times[0].Unclock(); @@ -3120,9 +3099,9 @@ static void P_GroupLines (bool buildmap) // count number of lines in each sector times[1].Clock(); total = 0; - for (int i = 0; i < numlines; i++) + for (unsigned i = 0; i < level.lines.Size(); i++) { - auto li = &lines[i]; + auto li = &level.lines[i]; if (li->frontsector == NULL) { if (!flaggedNoFronts) @@ -3174,9 +3153,9 @@ static void P_GroupLines (bool buildmap) } } - for (int i = 0; i < numlines; i++) + for (unsigned i = 0; i < level.lines.Size(); i++) { - auto li = &lines[i]; + auto li = &level.lines[i]; if (li->frontsector != NULL) { li->frontsector->Lines[linesDoneInEachSector[li->frontsector->Index()]++] = li; @@ -3393,11 +3372,11 @@ static void P_PrecacheLevel() hitlist[level.sectors[i].GetTexture(sector_t::ceiling).GetIndex()] |= FTextureManager::HIT_Flat; } - for (i = numsides - 1; i >= 0; i--) + for (i = level.sides.Size() - 1; i >= 0; i--) { - hitlist[sides[i].GetTexture(side_t::top).GetIndex()] |= FTextureManager::HIT_Wall; - hitlist[sides[i].GetTexture(side_t::mid).GetIndex()] |= FTextureManager::HIT_Wall; - hitlist[sides[i].GetTexture(side_t::bottom).GetIndex()] |= FTextureManager::HIT_Wall; + hitlist[level.sides[i].GetTexture(side_t::top).GetIndex()] |= FTextureManager::HIT_Wall; + hitlist[level.sides[i].GetTexture(side_t::mid).GetIndex()] |= FTextureManager::HIT_Wall; + hitlist[level.sides[i].GetTexture(side_t::bottom).GetIndex()] |= FTextureManager::HIT_Wall; } // Sky texture is always present. @@ -3431,6 +3410,7 @@ extern polyblock_t **PolyBlockMap; void P_FreeLevelData () { + P_FreeMapDataBackup(); interpolator.ClearInterpolations(); // [RH] Nothing to interpolate on a fresh level. Renderer->CleanLevelData(); FPolyObj::ClearAllSubsectorLinks(); // can't be done as part of the polyobj deletion process. @@ -3443,28 +3423,20 @@ void P_FreeLevelData () wminfo.maxfrags = 0; FBehavior::StaticUnloadModules (); - if (vertexes != NULL) - { - delete[] vertexes; - vertexes = NULL; - } - numvertexes = 0; if (segs != NULL) { delete[] segs; segs = NULL; } numsegs = 0; - if (glsegextras != NULL) - { - delete[] glsegextras; - glsegextras = NULL; - } if (level.sectors.Size() > 0) { delete[] level.sectors[0].e; } level.sectors.Clear(); + level.lines.Clear(); + level.sides.Clear(); + level.vertexes.Clear(); if (gamenodes != NULL && gamenodes != nodes) { @@ -3493,18 +3465,6 @@ void P_FreeLevelData () numsubsectors = numgamesubsectors = 0; nodes = gamenodes = NULL; numnodes = numgamenodes = 0; - if (lines != NULL) - { - delete[] lines; - lines = NULL; - } - numlines = 0; - if (sides != NULL) - { - delete[] sides; - sides = NULL; - } - numsides = 0; if (blockmaplump != NULL) { @@ -3761,7 +3721,6 @@ void P_SetupLevel (const char *lumpname, int position) times[1].Unclock(); times[2].Clock(); - P_LoadSideDefs (map); times[2].Unclock(); times[3].Clock(); @@ -3925,9 +3884,9 @@ void P_SetupLevel (const char *lumpname, int position) P_GetPolySpots (map, polyspots, anchors); FNodeBuilder::FLevel leveldata = { - vertexes, numvertexes, - sides, numsides, - lines, numlines, + &level.vertexes[0], (int)level.vertexes.Size(), + &level.sides[0], (int)level.sides.Size(), + &level.lines[0], (int)level.lines.Size(), 0, 0, 0, 0 }; leveldata.FindMapBounds (); @@ -3935,11 +3894,10 @@ void P_SetupLevel (const char *lumpname, int position) // In case a sync critical game mode is started, also build GL nodes to avoid problems // if the different machines' am_textured setting differs. FNodeBuilder builder (leveldata, polyspots, anchors, BuildGLNodes); - delete[] vertexes; builder.Extract (nodes, numnodes, - segs, glsegextras, numsegs, + segs, numsegs, subsectors, numsubsectors, - vertexes, numvertexes); + level.vertexes); endTime = I_FPSTime (); DPrintf (DMSG_NOTIFY, "BSP generation took %.3f sec (%d segs)\n", (endTime - startTime) * 0.001, numsegs); oldvertextable = builder.GetOldVertexTable(); @@ -4193,18 +4151,7 @@ void P_SetupLevel (const char *lumpname, int position) MapThingsUserDataIndex.Clear(); MapThingsUserData.Clear(); - loadsectors.Resize(level.sectors.Size()); - memcpy(&loadsectors[0], &level.sectors[0], loadsectors.Size() * sizeof(sector_t)); - loadlines.Resize(numlines); - memcpy(&loadlines[0], lines, numlines * sizeof(line_t)); - loadsides.Resize(numsides); - memcpy(&loadsides[0], sides, numsides * sizeof(side_t)); - - if (glsegextras != NULL) - { - delete[] glsegextras; - glsegextras = NULL; - } + P_BackupMapData(); } diff --git a/src/p_setup.h b/src/p_setup.h index 38d61c1eb1..3d8c021a74 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -150,7 +150,6 @@ struct sidei_t // [RH] Only keep BOOM sidedef init stuff around for init }; extern sidei_t *sidetemp; extern bool hasglnodes; -extern struct glsegextra_t *glsegextras; struct FMissingCount { diff --git a/src/p_sight.cpp b/src/p_sight.cpp index eb62e505a3..74b9fe1658 100644 --- a/src/p_sight.cpp +++ b/src/p_sight.cpp @@ -29,6 +29,7 @@ #include "r_state.h" #include "stats.h" +#include "g_levellocals.h" static FRandom pr_botchecksight ("BotCheckSight"); static FRandom pr_checksight ("CheckSight"); @@ -116,6 +117,7 @@ public: sightend = t2->PosRelative(task->portalgroup); sightstart.Z += t1->Height * 0.75; + portalgroup = task->portalgroup; Startfrac = task->Frac; Trace = { sightstart.X, sightstart.Y, sightend.X - sightstart.X, sightend.Y - sightstart.Y }; Lastztop = Lastzbottom = sightstart.Z; @@ -482,7 +484,7 @@ int SightCheck::P_SightBlockLinesIterator (int x, int y) for (list = blockmaplump + offset + 1; *list != -1; list++) { - if (!P_SightCheckLine (&lines[*list])) + if (!P_SightCheckLine (&level.lines[*list])) { if (!portalfound) return 0; else res = -1; @@ -790,6 +792,7 @@ sightcounts[2]++; bool traverseres = P_SightTraverseIntercepts ( ); if (itres == -1) return false; // if the iterator had an early out there was no line of sight. The traverser was only called to collect more portals. + if (seeingthing->Sector->PortalGroup != portalgroup) return false; // We are in a different group than the seeingthing, so this trace cannot determine visibility alone. return traverseres; } diff --git a/src/p_slopes.cpp b/src/p_slopes.cpp index ff0159940e..c574d189b3 100644 --- a/src/p_slopes.cpp +++ b/src/p_slopes.cpp @@ -38,6 +38,7 @@ #include "p_lnspec.h" #include "p_maputl.h" #include "p_spec.h" +#include "g_levellocals.h" //=========================================================================== // @@ -52,7 +53,7 @@ static void P_SlopeLineToPoint (int lineid, const DVector3 &pos, bool slopeCeil) FLineIdIterator itr(lineid); while ((linenum = itr.Next()) >= 0) { - const line_t *line = &lines[linenum]; + const line_t *line = &level.lines[linenum]; sector_t *sec; secplane_t *plane; @@ -257,9 +258,9 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, { if (mt->info->Special == SMT_VertexFloorZ || mt->info->Special == SMT_VertexCeilingZ) { - for (int i = 0; i < numvertexes; i++) + for (unsigned i = 0; i < level.vertexes.Size(); i++) { - if (vertexes[i].fX() == mt->pos.X && vertexes[i].fY() == mt->pos.Y) + if (level.vertexes[i].fX() == mt->pos.X && level.vertexes[i].fY() == mt->pos.Y) { if (mt->info->Special == SMT_VertexFloorZ) { @@ -277,7 +278,7 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, } } - for(int i = 0; i < numvertexdatas; i++) + for(unsigned i = 0; i < vertexdatas.Size(); i++) { int ii = oldvertextable == NULL ? i : oldvertextable[i]; @@ -295,9 +296,8 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, } // If vertexdata_t is ever extended for non-slope usage, this will obviously have to be deferred or removed. - delete[] vertexdatas; - vertexdatas = NULL; - numvertexdatas = 0; + vertexdatas.Clear(); + vertexdatas.ShrinkToFit(); if (vt_found) { @@ -309,14 +309,14 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, DVector3 vec1, vec2; int vi1, vi2, vi3; - vi1 = int(sec.Lines[0]->v1 - vertexes); - vi2 = int(sec.Lines[0]->v2 - vertexes); + vi1 = sec.Lines[0]->v1->Index(); + vi2 = sec.Lines[0]->v2->Index(); vi3 = (sec.Lines[1]->v1 == sec.Lines[0]->v1 || sec.Lines[1]->v1 == sec.Lines[0]->v2)? - int(sec.Lines[1]->v2 - vertexes) : int(sec.Lines[1]->v1 - vertexes); + sec.Lines[1]->v2->Index() : sec.Lines[1]->v1->Index(); - vt1 = DVector3(vertexes[vi1].fPos(), 0); - vt2 = DVector3(vertexes[vi2].fPos(), 0); - vt3 = DVector3(vertexes[vi3].fPos(), 0); + vt1 = DVector3(level.vertexes[vi1].fPos(), 0); + vt2 = DVector3(level.vertexes[vi2].fPos(), 0); + vt3 = DVector3(level.vertexes[vi3].fPos(), 0); for(int j=0; j<2; j++) { @@ -329,7 +329,7 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, vt2.Z = h2? *h2 : j==0? sec.GetPlaneTexZ(sector_t::floor) : sec.GetPlaneTexZ(sector_t::ceiling); vt3.Z = h3? *h3 : j==0? sec.GetPlaneTexZ(sector_t::floor) : sec.GetPlaneTexZ(sector_t::ceiling); - if (P_PointOnLineSidePrecise(vertexes[vi3].fX(), vertexes[vi3].fY(), sec.Lines[0]) == 0) + if (P_PointOnLineSidePrecise(level.vertexes[vi3].fX(), level.vertexes[vi3].fY(), sec.Lines[0]) == 0) { vec1 = vt2 - vt3; vec2 = vt1 - vt3; @@ -359,7 +359,7 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, secplane_t *plane = j==0? &sec.floorplane : &sec.ceilingplane; - double dist = -cross[0] * vertexes[vi3].fX() - cross[1] * vertexes[vi3].fY() - cross[2] * vt3.Z; + double dist = -cross[0] * level.vertexes[vi3].fX() - cross[1] * level.vertexes[vi3].fY() - cross[2] * vt3.Z; plane->set(cross[0], cross[1], cross[2], dist); } } @@ -516,14 +516,14 @@ static void P_AlignPlane(sector_t *sec, line_t *line, int which) void P_SetSlopes () { - int i, s; + int s; - for (i = 0; i < numlines; i++) + for (auto &line : level.lines) { - if (lines[i].special == Plane_Align) + if (line.special == Plane_Align) { - lines[i].special = 0; - if (lines[i].backsector != NULL) + line.special = 0; + if (line.backsector != nullptr) { // args[0] is for floor, args[1] is for ceiling // @@ -531,15 +531,15 @@ void P_SetSlopes () // then args[0], bits 2-3 are for ceiling. for (s = 0; s < 2; s++) { - int bits = lines[i].args[s] & 3; + int bits = line.args[s] & 3; if (s == 1 && bits == 0) - bits = (lines[i].args[0] >> 2) & 3; + bits = (line.args[0] >> 2) & 3; if (bits == 1) // align front side to back - P_AlignPlane (lines[i].frontsector, lines + i, s); + P_AlignPlane (line.frontsector, &line, s); else if (bits == 2) // align back side to front - P_AlignPlane (lines[i].backsector, lines + i, s); + P_AlignPlane (line.backsector, &line, s); } } } @@ -554,9 +554,9 @@ void P_SetSlopes () void P_CopySlopes() { - for (int i = 0; i < numlines; i++) + for (auto &line : level.lines) { - if (lines[i].special == Plane_Copy) + if (line.special == Plane_Copy) { // The args are used for the tags of sectors to copy: // args[0]: front floor @@ -564,31 +564,31 @@ void P_CopySlopes() // args[2]: back floor // args[3]: back ceiling // args[4]: copy slopes from one side of the line to the other. - lines[i].special = 0; - for (int s = 0; s < (lines[i].backsector ? 4 : 2); s++) + line.special = 0; + for (int s = 0; s < (line.backsector ? 4 : 2); s++) { - if (lines[i].args[s]) - P_CopyPlane(lines[i].args[s], - (s & 2 ? lines[i].backsector : lines[i].frontsector), s & 1); + if (line.args[s]) + P_CopyPlane(line.args[s], + (s & 2 ? line.backsector : line.frontsector), s & 1); } - if (lines[i].backsector != NULL) + if (line.backsector != NULL) { - if ((lines[i].args[4] & 3) == 1) + if ((line.args[4] & 3) == 1) { - lines[i].backsector->floorplane = lines[i].frontsector->floorplane; + line.backsector->floorplane = line.frontsector->floorplane; } - else if ((lines[i].args[4] & 3) == 2) + else if ((line.args[4] & 3) == 2) { - lines[i].frontsector->floorplane = lines[i].backsector->floorplane; + line.frontsector->floorplane = line.backsector->floorplane; } - if ((lines[i].args[4] & 12) == 4) + if ((line.args[4] & 12) == 4) { - lines[i].backsector->ceilingplane = lines[i].frontsector->ceilingplane; + line.backsector->ceilingplane = line.frontsector->ceilingplane; } - else if ((lines[i].args[4] & 12) == 8) + else if ((line.args[4] & 12) == 8) { - lines[i].frontsector->ceilingplane = lines[i].backsector->ceilingplane; + line.frontsector->ceilingplane = line.backsector->ceilingplane; } } } diff --git a/src/p_spec.cpp b/src/p_spec.cpp index 45f4d043c1..b3953b1bd2 100644 --- a/src/p_spec.cpp +++ b/src/p_spec.cpp @@ -70,6 +70,7 @@ #include "d_player.h" #include "p_maputl.h" #include "p_blockmap.h" +#include "g_levellocals.h" #ifndef NO_EDATA #include "edata.h" #endif @@ -189,7 +190,7 @@ bool P_ActivateLine (line_t *line, AActor *mo, int side, int activationType, DVe // end of changed code if (developer >= DMSG_SPAMMY && buttonSuccess) { - Printf ("Line special %d activated on line %i\n", special, int(line - lines)); + Printf ("Line special %d activated on line %i\n", special, line->Index()); } return true; } @@ -361,7 +362,7 @@ bool P_PredictLine(line_t *line, AActor *mo, int side, int activationType) // end of changed code if (developer >= DMSG_SPAMMY && buttonSuccess) { - Printf("Line special %d predicted on line %i\n", special, int(line - lines)); + Printf("Line special %d predicted on line %i\n", special, line->Index()); } return true; } @@ -790,14 +791,14 @@ DWallLightTransfer::DWallLightTransfer (sector_t *srcSec, int target, BYTE flags FLineIdIterator itr(target); while ((linenum = itr.Next()) >= 0) { - if (flags & WLF_SIDE1 && lines[linenum].sidedef[0] != NULL) + if (flags & WLF_SIDE1 && level.lines[linenum].sidedef[0] != NULL) { - lines[linenum].sidedef[0]->Flags |= wallflags; + level.lines[linenum].sidedef[0]->Flags |= wallflags; } - if (flags & WLF_SIDE2 && lines[linenum].sidedef[1] != NULL) + if (flags & WLF_SIDE2 && level.lines[linenum].sidedef[1] != NULL) { - lines[linenum].sidedef[1]->Flags |= wallflags; + level.lines[linenum].sidedef[1]->Flags |= wallflags; } } ChangeStatNum(STAT_LIGHTTRANSFER); @@ -821,7 +822,7 @@ void DWallLightTransfer::DoTransfer (short lightlevel, int target, BYTE flags) FLineIdIterator itr(target); while ((linenum = itr.Next()) >= 0) { - line_t *line = &lines[linenum]; + line_t *line = &level.lines[linenum]; if (flags & WLF_SIDE1 && line->sidedef[0] != NULL) { @@ -958,42 +959,42 @@ static void CopyPortal(int sectortag, int plane, unsigned pnum, double alpha, bo SetPortal(&level.sectors[s], plane, pnum, alpha); } - for (int j=0;j= 0) { SetPortal(&level.sectors[s], plane, pnum, alpha); } } } - if (tolines && lines[j].special == Sector_SetPortal && - lines[j].args[1] == 5 && - lines[j].args[3] == sectortag) + if (tolines && line.special == Sector_SetPortal && + line.args[1] == 5 && + line.args[3] == sectortag) { - if (lines[j].args[0] == 0) + if (line.args[0] == 0) { - lines[j].portaltransferred = pnum; + line.portaltransferred = pnum; } else { - FLineIdIterator itr(lines[j].args[0]); + FLineIdIterator itr(line.args[0]); while ((s = itr.Next()) >= 0) { - lines[s].portaltransferred = pnum; + level.lines[s].portaltransferred = pnum; } } } @@ -1004,20 +1005,20 @@ static void CopyPortal(int sectortag, int plane, unsigned pnum, double alpha, bo void P_SpawnPortal(line_t *line, int sectortag, int plane, int bytealpha, int linked) { if (plane < 0 || plane > 2 || (linked && plane == 2)) return; - for (int i=0;iv1->fPos() + line->Delta() / 2; - DVector2 pos2 = lines[i].v1->fPos() + lines[i].Delta() / 2; - unsigned pnum = P_GetPortal(linked ? PORTS_LINKEDPORTAL : PORTS_PORTAL, plane, line->frontsector, lines[i].frontsector, pos2 - pos1); + DVector2 pos2 = oline.v1->fPos() + oline.Delta() / 2; + unsigned pnum = P_GetPortal(linked ? PORTS_LINKEDPORTAL : PORTS_PORTAL, plane, line->frontsector, oline.frontsector, pos2 - pos1); CopyPortal(sectortag, plane, pnum, bytealpha / 255., false); return; } @@ -1266,9 +1267,9 @@ void P_SpawnSpecials (void) P_SpawnSkybox(pt2); } - for (int i = 0; i < numlines; i++) + for (auto &line : level.lines) { - switch (lines[i].special) + switch (line.special) { int s; sector_t *sec; @@ -1277,16 +1278,16 @@ void P_SpawnSpecials (void) // support for drawn heights coming from different sector case Transfer_Heights: { - sec = lines[i].frontsector; - if (lines[i].args[1] & 2) + sec = line.frontsector; + if (line.args[1] & 2) { sec->MoreFlags |= SECF_FAKEFLOORONLY; } - if (lines[i].args[1] & 4) + if (line.args[1] & 4) { sec->MoreFlags |= SECF_CLIPFAKEPLANES; } - if (lines[i].args[1] & 8) + if (line.args[1] & 8) { sec->MoreFlags |= SECF_UNDERWATER; } @@ -1294,15 +1295,15 @@ void P_SpawnSpecials (void) { sec->MoreFlags |= SECF_FORCEDUNDERWATER; } - if (lines[i].args[1] & 16) + if (line.args[1] & 16) { sec->MoreFlags |= SECF_IGNOREHEIGHTSEC; } - if (lines[i].args[1] & 32) + if (line.args[1] & 32) { sec->MoreFlags |= SECF_NOFAKELIGHT; } - FSectorTagIterator itr(lines[i].args[0]); + FSectorTagIterator itr(line.args[0]); while ((s = itr.Next()) >= 0) { level.sectors[s].heightsec = sec; @@ -1315,29 +1316,29 @@ void P_SpawnSpecials (void) // killough 3/16/98: Add support for setting // floor lighting independently (e.g. lava) case Transfer_FloorLight: - new DLightTransfer (lines[i].frontsector, lines[i].args[0], true); + new DLightTransfer (line.frontsector, line.args[0], true); break; // killough 4/11/98: Add support for setting // ceiling lighting independently case Transfer_CeilingLight: - new DLightTransfer (lines[i].frontsector, lines[i].args[0], false); + new DLightTransfer (line.frontsector, line.args[0], false); break; // [Graf Zahl] Add support for setting lighting // per wall independently case Transfer_WallLight: - new DWallLightTransfer (lines[i].frontsector, lines[i].args[0], lines[i].args[1]); + new DWallLightTransfer (line.frontsector, line.args[0], line.args[1]); break; case Sector_Attach3dMidtex: - P_Attach3dMidtexLinesToSector(lines[i].frontsector, lines[i].args[0], lines[i].args[1], !!lines[i].args[2]); + P_Attach3dMidtexLinesToSector(line.frontsector, line.args[0], line.args[1], !!line.args[2]); break; case Sector_SetLink: - if (lines[i].args[0] == 0) + if (line.args[0] == 0) { - P_AddSectorLinks(lines[i].frontsector, lines[i].args[1], lines[i].args[2], lines[i].args[3]); + P_AddSectorLinks(line.frontsector, line.args[1], line.args[2], line.args[3]); } break; @@ -1355,30 +1356,29 @@ void P_SpawnSpecials (void) // arg 2 = 0:floor, 1:ceiling, 2:both // arg 3 = 0: anchor, 1: reference line // arg 4 = for the anchor only: alpha - if ((lines[i].args[1] == 0 || lines[i].args[1] == 6) && lines[i].args[3] == 0) + if ((line.args[1] == 0 || line.args[1] == 6) && line.args[3] == 0) { - P_SpawnPortal(&lines[i], lines[i].args[0], lines[i].args[2], lines[i].args[4], lines[i].args[1]); + P_SpawnPortal(&line, line.args[0], line.args[2], line.args[4], line.args[1]); } - else if (lines[i].args[1] == 3 || lines[i].args[1] == 4) + else if (line.args[1] == 3 || line.args[1] == 4) { - line_t *line = &lines[i]; - unsigned pnum = P_GetPortal(line->args[1] == 3 ? PORTS_PLANE : PORTS_HORIZON, line->args[2], line->frontsector, NULL, { 0,0 }); - CopyPortal(line->args[0], line->args[2], pnum, 0, true); + unsigned pnum = P_GetPortal(line.args[1] == 3 ? PORTS_PLANE : PORTS_HORIZON, line.args[2], line.frontsector, NULL, { 0,0 }); + CopyPortal(line.args[0], line.args[2], pnum, 0, true); } break; case Line_SetPortal: - P_SpawnLinePortal(&lines[i]); + P_SpawnLinePortal(&line); break; // [RH] ZDoom Static_Init settings case Static_Init: - switch (lines[i].args[1]) + switch (line.args[1]) { case Init_Gravity: { - double grav = lines[i].Delta().Length() / 100.; - FSectorTagIterator itr(lines[i].args[0]); + double grav = line.Delta().Length() / 100.; + FSectorTagIterator itr(line.args[0]); while ((s = itr.Next()) >= 0) level.sectors[s].gravity = grav; } @@ -1389,8 +1389,8 @@ void P_SpawnSpecials (void) case Init_Damage: { - int damage = int(lines[i].Delta().Length()); - FSectorTagIterator itr(lines[i].args[0]); + int damage = int(line.Delta().Length()); + FSectorTagIterator itr(line.args[0]); while ((s = itr.Next()) >= 0) { sector_t *sec = &level.sectors[s]; @@ -1416,8 +1416,8 @@ void P_SpawnSpecials (void) break; case Init_SectorLink: - if (lines[i].args[3] == 0) - P_AddSectorLinksByID(lines[i].frontsector, lines[i].args[0], lines[i].args[2]); + if (line.args[3] == 0) + P_AddSectorLinksByID(line.frontsector, line.args[0], line.args[2]); break; // killough 10/98: @@ -1431,9 +1431,9 @@ void P_SpawnSpecials (void) case Init_TransferSky: { - FSectorTagIterator itr(lines[i].args[0]); + FSectorTagIterator itr(line.args[0]); while ((s = itr.Next()) >= 0) - level.sectors[s].sky = (i + 1) | PL_SKYFLAT; + level.sectors[s].sky = (line.Index() + 1) | PL_SKYFLAT; break; } } @@ -1499,10 +1499,9 @@ void P_SpawnSpecials (void) static void P_SpawnFriction(void) { - int i; - line_t *l = lines; + line_t *l = &level.lines[0]; - for (i = 0 ; i < numlines ; i++,l++) + for (unsigned i = 0 ; i < level.lines.Size() ; i++,l++) { if (l->special == Sector_SetFriction) { diff --git a/src/p_tags.cpp b/src/p_tags.cpp index dc71e2663e..9e7d60d608 100644 --- a/src/p_tags.cpp +++ b/src/p_tags.cpp @@ -36,6 +36,7 @@ #include "p_tags.h" #include "c_dispatch.h" +#include "g_levellocals.h" FTagManager tagManager; @@ -45,17 +46,6 @@ FTagManager tagManager; // //----------------------------------------------------------------------------- -static inline int lineindex(const line_t *line) -{ - return (int)(intptr_t)(line - lines); -} - -//----------------------------------------------------------------------------- -// -// -// -//----------------------------------------------------------------------------- - void FTagManager::AddSectorTag(int sector, int tag) { if (tag == 0) return; @@ -244,7 +234,7 @@ bool FTagManager::SectorHasTag(const sector_t *sector, int tag) const int FTagManager::GetFirstLineID(const line_t *line) const { - int i = lineindex(line); + int i = line->Index(); return LineHasIDs(i) ? allIDs[startForLine[i]].tag : 0; } @@ -276,7 +266,7 @@ bool FTagManager::LineHasID(int i, int tag) const bool FTagManager::LineHasID(const line_t *line, int tag) const { - return LineHasID(lineindex(line), tag); + return LineHasID(line->Index(), tag); } //----------------------------------------------------------------------------- diff --git a/src/p_teleport.cpp b/src/p_teleport.cpp index 12f9ef4b83..5eb63e4ce9 100644 --- a/src/p_teleport.cpp +++ b/src/p_teleport.cpp @@ -38,6 +38,7 @@ #include "p_maputl.h" #include "r_utility.h" #include "p_spec.h" +#include "g_levellocals.h" #define FUDGEFACTOR 10 @@ -447,10 +448,10 @@ bool EV_SilentLineTeleport (line_t *line, int side, AActor *thing, int id, INTBO FLineIdIterator itr(id); while ((i = itr.Next()) >= 0) { - if (line-lines == i) + if (line->Index() == i) continue; - if ((l=lines+i) != line && l->backsector) + if ((l=&level.lines[i]) != line && l->backsector) { // Get the thing's position along the source linedef double pos; diff --git a/src/p_things.cpp b/src/p_things.cpp index 6aac786f07..f6c06a1e5e 100644 --- a/src/p_things.cpp +++ b/src/p_things.cpp @@ -51,6 +51,7 @@ #include "p_spec.h" #include "math/cmath.h" #include "actorptrselect.h" +#include "g_levellocals.h" // Set of spawnable things for the Thing_Spawn and Thing_Projectile specials. FClassMap SpawnableThings; diff --git a/src/p_tick.cpp b/src/p_tick.cpp index 332b7af81c..2f81514250 100644 --- a/src/p_tick.cpp +++ b/src/p_tick.cpp @@ -35,6 +35,7 @@ #include "g_level.h" #include "r_utility.h" #include "p_spec.h" +#include "g_levellocals.h" extern gamestate_t wipegamestate; diff --git a/src/p_trace.cpp b/src/p_trace.cpp index 4b0a5f3bdf..3597535e55 100644 --- a/src/p_trace.cpp +++ b/src/p_trace.cpp @@ -40,6 +40,7 @@ #include "p_maputl.h" #include "r_defs.h" #include "p_spec.h" +#include "g_levellocals.h" //========================================================================== // diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp index 63621d2fa1..b0c9dbc159 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -48,6 +48,7 @@ #include "w_wad.h" #include "p_tags.h" #include "p_terrain.h" +#include "g_levellocals.h" //=========================================================================== // @@ -393,7 +394,6 @@ class UDMFParser : public UDMFParserBase TArray ParsedSideTextures; TArray ParsedSectors; TArray ParsedVertices; - TArray ParsedVertexDatas; FDynamicColormap *fogMap, *normMap; FMissingTextureTracker &missingTex; @@ -792,6 +792,7 @@ public: memset(ld, 0, sizeof(*ld)); ld->alpha = 1.; ld->portalindex = UINT_MAX; + ld->portaltransferred = UINT_MAX; ld->sidedef[0] = ld->sidedef[1] = NULL; if (level.flags2 & LEVEL2_CLIPMIDTEX) ld->flags |= ML_CLIP_MIDTEX; if (level.flags2 & LEVEL2_WRAPMIDTEX) ld->flags |= ML_WRAP_MIDTEX; @@ -1135,7 +1136,7 @@ public: sdt->midtexture = "-"; sd->SetTextureXScale(1.); sd->SetTextureYScale(1.); - sd->Index = index; + sd->UDMFIndex = index; sc.MustGetToken('{'); while (!sc.CheckToken('}')) @@ -1788,12 +1789,12 @@ public: intptr_t v1i = intptr_t(ParsedLines[i].v1); intptr_t v2i = intptr_t(ParsedLines[i].v2); - if (v1i >= numvertexes || v2i >= numvertexes || v1i < 0 || v2i < 0) + if (v1i >= level.vertexes.Size() || v2i >= level.vertexes.Size() || v1i < 0 || v2i < 0) { - I_Error ("Line %d has invalid vertices: %zd and/or %zd.\nThe map only contains %d vertices.", i+skipped, v1i, v2i, numvertexes); + I_Error ("Line %d has invalid vertices: %zd and/or %zd.\nThe map only contains %u vertices.", i+skipped, v1i, v2i, level.vertexes.Size()); } else if (v1i == v2i || - (vertexes[v1i].fX() == vertexes[v2i].fX() && vertexes[v1i].fY() == vertexes[v2i].fY())) + (level.vertexes[v1i].fX() == level.vertexes[v2i].fX() && level.vertexes[v1i].fY() == level.vertexes[v2i].fY())) { Printf ("Removing 0-length line %d\n", i+skipped); ParsedLines.Delete(i); @@ -1802,8 +1803,8 @@ public: } else { - ParsedLines[i].v1 = &vertexes[v1i]; - ParsedLines[i].v2 = &vertexes[v2i]; + ParsedLines[i].v1 = &level.vertexes[v1i]; + ParsedLines[i].v2 = &level.vertexes[v2i]; if (ParsedLines[i].sidedef[0] != NULL) sidecount++; @@ -1813,13 +1814,14 @@ public: i++; } } - numlines = ParsedLines.Size(); - numsides = sidecount; - lines = new line_t[numlines]; - sides = new side_t[numsides]; + unsigned numlines = ParsedLines.Size(); + level.sides.Alloc(sidecount); + level.lines.Alloc(numlines); int line, side; + auto lines = &level.lines[0]; + auto sides = &level.sides[0]; - for(line = 0, side = 0; line < numlines; line++) + for(line = 0, side = 0; line < (int)numlines; line++) { short tempalpha[2] = { SHRT_MIN, SHRT_MIN }; @@ -1852,11 +1854,10 @@ public: P_AdjustLine(&lines[line]); P_FinishLoadingLineDef(&lines[line], tempalpha[0]); } - assert(side <= numsides); - if (side < numsides) + assert((unsigned)side <= level.sides.Size()); + if ((unsigned)side > level.sides.Size()) { - Printf("Map had %d invalid side references\n", numsides - side); - numsides = side; + Printf("Map had %d invalid side references\n", (int)level.sides.Size() - side); } } @@ -1994,7 +1995,7 @@ public: vertexdata_t vd; ParseVertex(&vt, &vd); ParsedVertices.Push(vt); - ParsedVertexDatas.Push(vd); + vertexdatas.Push(vd); } else { @@ -2009,14 +2010,8 @@ public: if (ParsedSides.Size() == 0) I_Error("Map has no sidedefs.\n"); // Create the real vertices - numvertexes = ParsedVertices.Size(); - vertexes = new vertex_t[numvertexes]; - memcpy(vertexes, &ParsedVertices[0], numvertexes * sizeof(*vertexes)); - - // Create the real vertex datas - numvertexdatas = ParsedVertexDatas.Size(); - vertexdatas = new vertexdata_t[numvertexdatas]; - memcpy(vertexdatas, &ParsedVertexDatas[0], numvertexdatas * sizeof(*vertexdatas)); + level.vertexes.Alloc(ParsedVertices.Size()); + memcpy(&level.vertexes[0], &ParsedVertices[0], level.vertexes.Size() * sizeof(vertex_t)); // Create the real sectors level.sectors.Alloc(ParsedSectors.Size()); diff --git a/src/p_user.cpp b/src/p_user.cpp index c4be5d5260..936fdf4ade 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -61,6 +61,7 @@ #include "virtual.h" #include "a_armor.h" #include "a_ammo.h" +#include "g_levellocals.h" static FRandom pr_skullpop ("SkullPop"); diff --git a/src/p_writemap.cpp b/src/p_writemap.cpp deleted file mode 100644 index cdf5a19d16..0000000000 --- a/src/p_writemap.cpp +++ /dev/null @@ -1,226 +0,0 @@ -#include "p_local.h" -#include "c_dispatch.h" -#include "gi.h" -#include "w_wad.h" -#include "r_defs.h" -#include "m_swap.h" -#include "doomstat.h" -#include "d_player.h" -#include "p_spec.h" - -static int WriteTHINGS (FILE *file); -static int WriteLINEDEFS (FILE *file); -static int WriteSIDEDEFS (FILE *file); -static int WriteVERTEXES (FILE *file); -static int WriteSEGS (FILE *file); -static int WriteSSECTORS (FILE *file); -static int WriteNODES (FILE *file); -static int WriteSECTORS (FILE *file); -static int WriteREJECT (FILE *file); -static int WriteBLOCKMAP (FILE *file); -static int WriteBEHAVIOR (FILE *file); - -#define APPEND(pos,name) \ - lumps[pos].FilePos = LittleLong((int)ftell (file)); \ - lumps[pos].Size = LittleLong(Write##name (file)); \ - memcpy (lumps[pos].Name, #name, sizeof(#name)-1); - -CCMD (dumpmap) -{ - const char *mapname; - FILE *file; - - if (argv.argc() < 2) - { - Printf ("Usage: dumpmap [mapname]\n"); - return; - } - - if (gamestate != GS_LEVEL) - { - Printf ("You can only dump a map when inside a level.\n"); - return; - } - - if (argv.argc() < 3) - { - if (gameinfo.flags & GI_MAPxx) - { - mapname = "MAP01"; - } - else - { - mapname = "E1M1"; - } - } - else - { - mapname = argv[2]; - } - - file = fopen (argv[1], "wb"); - if (file == NULL) - { - Printf ("Cannot write %s\n", argv[1]); - return; - } - - wadinfo_t header = { PWAD_ID, 12, 0 }; - wadlump_t lumps[12] = { {0, 0, {0}} }; - - fseek (file, 12, SEEK_SET); - - lumps[0].FilePos = LittleLong(12); - lumps[0].Size = 0; - uppercopy (lumps[0].Name, mapname); - - APPEND(1, THINGS); - APPEND(2, LINEDEFS); - APPEND(3, SIDEDEFS); - APPEND(4, VERTEXES); - APPEND(5, SEGS); - APPEND(6, SSECTORS); - APPEND(7, NODES); - APPEND(8, SECTORS); - APPEND(9, REJECT); - APPEND(10, BLOCKMAP); - APPEND(11, BEHAVIOR); - - header.InfoTableOfs = ftell (file); - - fwrite (lumps, 16, 12, file); - fseek (file, 0, SEEK_SET); - fwrite (&header, 12, 1, file); - - fclose (file); -} - -static int WriteTHINGS (FILE *file) -{ - mapthinghexen_t mt = { 0, 0, 0, 0, 0, 0, 0, 0, {0} }; - AActor *mo = players[consoleplayer].mo; - - mt.x = LittleShort(short(mo->X())); - mt.y = LittleShort(short(mo->Y())); - mt.angle = LittleShort(short(mo->Angles.Yaw.Degrees)); - mt.type = LittleShort((short)1); - mt.flags = LittleShort((short)(7|224|MTF_SINGLE)); - fwrite (&mt, sizeof(mt), 1, file); - return sizeof (mt); -} - -static int WriteLINEDEFS (FILE *file) -{ - maplinedef2_t mld; - - for (int i = 0; i < numlines; ++i) - { - mld.v1 = LittleShort(short(lines[i].v1 - vertexes)); - mld.v2 = LittleShort(short(lines[i].v2 - vertexes)); - mld.flags = LittleShort(short(lines[i].flags)); - mld.special = lines[i].special; - for (int j = 0; j < 5; ++j) - { - mld.args[j] = (BYTE)lines[i].args[j]; - } - mld.sidenum[0] = LittleShort(WORD(lines[i].sidedef[0] - sides)); - mld.sidenum[1] = LittleShort(WORD(lines[i].sidedef[1] - sides)); - fwrite (&mld, sizeof(mld), 1, file); - } - return numlines * sizeof(mld); -} - -static const char *GetTextureName (FTextureID texnum) -{ - FTexture *tex = TexMan[texnum]; - - if (tex != NULL) - { - return tex->Name; - } - else - { - return "-"; - } -} - -static int WriteSIDEDEFS (FILE *file) -{ - mapsidedef_t msd; - - for (int i = 0; i < numsides; ++i) - { - msd.textureoffset = LittleShort(short(sides[i].GetTextureXOffset(side_t::mid))); - msd.rowoffset = LittleShort(short(sides[i].GetTextureYOffset(side_t::mid))); - msd.sector = LittleShort(short(sides[i].sector - &level.sectors[0])); - uppercopy (msd.toptexture, GetTextureName (sides[i].GetTexture(side_t::top))); - uppercopy (msd.bottomtexture, GetTextureName (sides[i].GetTexture(side_t::bottom))); - uppercopy (msd.midtexture, GetTextureName (sides[i].GetTexture(side_t::mid))); - fwrite (&msd, sizeof(msd), 1, file); - } - return numsides * sizeof(msd); -} - -static int WriteVERTEXES (FILE *file) -{ - mapvertex_t mv; - - for (int i = 0; i < numvertexes; ++i) - { - mv.x = LittleShort(short(vertexes[i].fixX() >> FRACBITS)); - mv.y = LittleShort(short(vertexes[i].fixY() >> FRACBITS)); - fwrite (&mv, sizeof(mv), 1, file); - } - return numvertexes * sizeof(mv); -} - - -static int WriteSEGS (FILE *file) -{ - return 0; -} - -static int WriteSSECTORS (FILE *file) -{ - return 0; -} - -static int WriteNODES (FILE *file) -{ - return 0; -} - -static int WriteSECTORS (FILE *file) -{ - mapsector_t ms; - - for (unsigned i = 0; i < level.sectors.Size(); ++i) - { - ms.floorheight = LittleShort(short(level.sectors[i].GetPlaneTexZ(sector_t::floor))); - ms.ceilingheight = LittleShort(short(level.sectors[i].GetPlaneTexZ(sector_t::ceiling))); - uppercopy (ms.floorpic, GetTextureName (level.sectors[i].GetTexture(sector_t::floor))); - uppercopy (ms.ceilingpic, GetTextureName (level.sectors[i].GetTexture(sector_t::ceiling))); - ms.lightlevel = LittleShort((short)level.sectors[i].lightlevel); - ms.special = LittleShort(level.sectors[i].special); - ms.tag = LittleShort(tagManager.GetFirstSectorTag(&level.sectors[i])); - fwrite (&ms, sizeof(ms), 1, file); - } - return level.sectors.Size() * sizeof(ms); -} - -static int WriteREJECT (FILE *file) -{ - return 0; -} - -static int WriteBLOCKMAP (FILE *file) -{ - return 0; -} - -static int WriteBEHAVIOR (FILE *file) -{ - static const BYTE dummy[16] = { 'A', 'C', 'S', 0, 8 }; - fwrite (dummy, 16, 1, file); - return 16; -} diff --git a/src/p_xlat.cpp b/src/p_xlat.cpp index 424b93a525..29ccf966f3 100644 --- a/src/p_xlat.cpp +++ b/src/p_xlat.cpp @@ -44,6 +44,7 @@ #include "w_wad.h" #include "sc_man.h" #include "cmdlib.h" +#include "g_levellocals.h" #include "xlat/xlat.h" // define names for the TriggerType field of the general linedefs @@ -317,27 +318,27 @@ void P_TranslateTeleportThings () if (foundSomething) { - for (int i = 0; i < numlines; ++i) + for (auto &line : level.lines) { - if (lines[i].special == Teleport) + if (line.special == Teleport) { - if (lines[i].args[1] == 0) + if (line.args[1] == 0) { - lines[i].args[0] = 1; + line.args[0] = 1; } } - else if (lines[i].special == Teleport_NoFog) + else if (line.special == Teleport_NoFog) { - if (lines[i].args[2] == 0) + if (line.args[2] == 0) { - lines[i].args[0] = 1; + line.args[0] = 1; } } - else if (lines[i].special == Teleport_ZombieChanger) + else if (line.special == Teleport_ZombieChanger) { - if (lines[i].args[1] == 0) + if (line.args[1] == 0) { - lines[i].args[0] = 1; + line.args[0] = 1; } } } diff --git a/src/po_man.cpp b/src/po_man.cpp index 15c8d5a52c..e8c1cbbb87 100644 --- a/src/po_man.cpp +++ b/src/po_man.cpp @@ -32,6 +32,7 @@ #include "p_maputl.h" #include "r_utility.h" #include "p_blockmap.h" +#include "g_levellocals.h" // MACROS ------------------------------------------------------------------ @@ -39,17 +40,6 @@ // TYPES ------------------------------------------------------------------- -inline vertex_t *side_t::V1() const -{ - return this == linedef->sidedef[0]? linedef->v1 : linedef->v2; -} - -inline vertex_t *side_t::V2() const -{ - return this == linedef->sidedef[0]? linedef->v2 : linedef->v1; -} - - class DRotatePoly : public DPolyAction { DECLARE_CLASS (DRotatePoly, DPolyAction) @@ -148,8 +138,6 @@ static void ReleaseAllPolyNodes(); // EXTERNAL DATA DECLARATIONS ---------------------------------------------- -extern seg_t *segs; - // PUBLIC DATA DEFINITIONS ------------------------------------------------- polyblock_t **PolyBlockMap; @@ -1429,11 +1417,11 @@ static void InitBlockMap (void) static void InitSideLists () { - for (int i = 0; i < numsides; ++i) + for (unsigned i = 0; i < level.sides.Size(); ++i) { - if (sides[i].linedef != NULL && - (sides[i].linedef->special == Polyobj_StartLine || - sides[i].linedef->special == Polyobj_ExplicitLine)) + if (level.sides[i].linedef != NULL && + (level.sides[i].linedef->special == Polyobj_StartLine || + level.sides[i].linedef->special == Polyobj_ExplicitLine)) { KnownPolySides.Push (i); } @@ -1491,7 +1479,7 @@ static void IterFindPolySides (FPolyObj *po, side_t *side) assert(sidetemp != NULL); vnum.Clear(); - vnum.Push(DWORD(side->V1() - vertexes)); + vnum.Push(DWORD(side->V1()->Index())); vnumat = 0; while (vnum.Size() != vnumat) @@ -1499,8 +1487,8 @@ static void IterFindPolySides (FPolyObj *po, side_t *side) DWORD sidenum = sidetemp[vnum[vnumat++]].b.first; while (sidenum != NO_SIDE) { - po->Sidedefs.Push(&sides[sidenum]); - AddPolyVert(vnum, DWORD(sides[sidenum].V2() - vertexes)); + po->Sidedefs.Push(&level.sides[sidenum]); + AddPolyVert(vnum, DWORD(level.sides[sidenum].V2()->Index())); sidenum = sidetemp[sidenum].b.next; } } @@ -1534,7 +1522,7 @@ static void SpawnPolyobj (int index, int tag, int type) po->bBlocked = false; po->bHasPortals = 0; - side_t *sd = &sides[i]; + side_t *sd = &level.sides[i]; if (sd->linedef->special == Polyobj_StartLine && sd->linedef->args[0] == tag) @@ -1570,14 +1558,14 @@ static void SpawnPolyobj (int index, int tag, int type) i = KnownPolySides[ii]; if (i >= 0 && - sides[i].linedef->special == Polyobj_ExplicitLine && - sides[i].linedef->args[0] == tag) + level.sides[i].linedef->special == Polyobj_ExplicitLine && + level.sides[i].linedef->args[0] == tag) { - if (!sides[i].linedef->args[1]) + if (!level.sides[i].linedef->args[1]) { - I_Error("SpawnPolyobj: Explicit line missing order number in poly %d, linedef %d.\n", tag, int(sides[i].linedef - lines)); + I_Error("SpawnPolyobj: Explicit line missing order number in poly %d, linedef %d.\n", tag, level.sides[i].linedef->Index()); } - po->Sidedefs.Push (&sides[i]); + po->Sidedefs.Push (&level.sides[i]); } } qsort(&po->Sidedefs[0], po->Sidedefs.Size(), sizeof(po->Sidedefs[0]), posicmp); @@ -1776,11 +1764,11 @@ void PO_Init (void) } } // clear all polyobj specials so that they do not obstruct using other lines. - for (int i = 0; i < numlines; i++) + for (auto &line : level.lines) { - if (lines[i].special == Polyobj_ExplicitLine || lines[i].special == Polyobj_StartLine) + if (line.special == Polyobj_ExplicitLine || line.special == Polyobj_StartLine) { - lines[i].special = 0; + line.special = 0; } } } diff --git a/src/portal.cpp b/src/portal.cpp index fa5c9fed71..abe4425548 100644 --- a/src/portal.cpp +++ b/src/portal.cpp @@ -51,6 +51,7 @@ #include "p_spec.h" #include "p_checkposition.h" #include "math/cmath.h" +#include "g_levellocals.h" // simulation recurions maximum CVAR(Int, sv_portal_recursions, 4, CVAR_ARCHIVE|CVAR_SERVERINFO) @@ -115,7 +116,7 @@ static void BuildBlockmap() while (*list != -1) { - line_t *ld = &lines[*list++]; + line_t *ld = &level.lines[*list++]; FLinePortal *port = ld->getPortal(); if (port && port->mType != PORTT_VISUAL) { @@ -209,9 +210,9 @@ static line_t *FindDestination(line_t *src, int tag) while ((lineno = it.Next()) >= 0) { - if (&lines[lineno] != src) + if (&level.lines[lineno] != src) { - return &lines[lineno]; + return &level.lines[lineno]; } } } @@ -290,7 +291,7 @@ void P_SpawnLinePortal(line_t* line) if (port->mType == PORTT_INTERACTIVE && port->mAlign != PORG_ABSOLUTE) { // Due to the way z is often handled, these pose a major issue for parts of the code that needs to transparently handle interactive portals. - Printf(TEXTCOLOR_RED "Warning: z-offsetting not allowed for interactive portals. Changing line %d to teleport-portal!\n", int(line - lines)); + Printf(TEXTCOLOR_RED "Warning: z-offsetting not allowed for interactive portals. Changing line %d to teleport-portal!\n", line->Index()); port->mType = PORTT_TELEPORT; } } @@ -305,26 +306,26 @@ void P_SpawnLinePortal(line_t* line) int mytag = tagManager.GetFirstLineID(line); - for (int i = 0; i < numlines; i++) + for (auto &ln : level.lines) { - if (tagManager.GetFirstLineID(&lines[i]) == mytag && lines[i].args[0] == 1 && lines[i].special == Line_SetPortal) + if (tagManager.GetFirstLineID(&ln) == mytag && ln.args[0] == 1 && ln.special == Line_SetPortal) { line->portalindex = linePortals.Reserve(1); FLinePortal *port = &linePortals.Last(); memset(port, 0, sizeof(FLinePortal)); port->mOrigin = line; - port->mDestination = &lines[i]; + port->mDestination = &ln; port->mType = PORTT_LINKED; port->mAlign = PORG_ABSOLUTE; port->mDefFlags = PORTF_TYPEINTERACTIVE; // we need to create the backlink here, too. - lines[i].portalindex = linePortals.Reserve(1); + ln.portalindex = linePortals.Reserve(1); port = &linePortals.Last(); memset(port, 0, sizeof(FLinePortal)); - port->mOrigin = &lines[i]; + port->mOrigin = &ln; port->mDestination = line; port->mType = PORTT_LINKED; port->mAlign = PORG_ABSOLUTE; @@ -473,7 +474,7 @@ bool P_ChangePortal(line_t *ln, int thisid, int destid) bool res = false; while ((lineno = it.Next()) >= 0) { - res |= ChangePortalLine(&lines[lineno], destid); + res |= ChangePortalLine(&level.lines[lineno], destid); } return res; } @@ -868,13 +869,13 @@ static void AddDisplacementForPortal(FLinePortal *portal) int othergroup = portal->mDestination->frontsector->PortalGroup; if (thisgroup == othergroup) { - Printf("Portal between lines %d and %d has both sides in same group\n", int(portal->mOrigin-lines), int(portal->mDestination-lines)); + Printf("Portal between lines %d and %d has both sides in same group\n", portal->mOrigin->Index(), portal->mDestination->Index()); portal->mType = linePortals[portal->mDestination->portalindex].mType = PORTT_TELEPORT; return; } if (thisgroup <= 0 || thisgroup >= Displacements.size || othergroup <= 0 || othergroup >= Displacements.size) { - Printf("Portal between lines %d and %d has invalid group\n", int(portal->mOrigin - lines), int(portal->mDestination - lines)); + Printf("Portal between lines %d and %d has invalid group\n", portal->mOrigin->Index(), portal->mDestination->Index()); portal->mType = linePortals[portal->mDestination->portalindex].mType = PORTT_TELEPORT; return; } @@ -889,7 +890,7 @@ static void AddDisplacementForPortal(FLinePortal *portal) { if (disp.pos != portal->mDisplacement) { - Printf("Portal between lines %d and %d has displacement mismatch\n", int(portal->mOrigin - lines), int(portal->mDestination - lines)); + Printf("Portal between lines %d and %d has displacement mismatch\n", portal->mOrigin->Index(), portal->mDestination->Index()); portal->mType = linePortals[portal->mDestination->portalindex].mType = PORTT_TELEPORT; return; } @@ -1057,11 +1058,11 @@ void P_CreateLinkedPortals() bogus = true; } // mark everything that connects to a one-sided line - for (int i = 0; i < numlines; i++) + for (auto &line : level.lines) { - if (lines[i].backsector == NULL && lines[i].frontsector->PortalGroup == 0) + if (line.backsector == nullptr && line.frontsector->PortalGroup == 0) { - CollectSectors(-1, lines[i].frontsector); + CollectSectors(-1, line.frontsector); } } // and now print a message for everything that still wasn't processed. diff --git a/src/posix/sdl/i_main.cpp b/src/posix/sdl/i_main.cpp index ca704340df..90b11ef25d 100644 --- a/src/posix/sdl/i_main.cpp +++ b/src/posix/sdl/i_main.cpp @@ -52,6 +52,7 @@ #include "version.h" #include "w_wad.h" #include "g_level.h" +#include "g_levellocals.h" #include "r_state.h" #include "cmdlib.h" #include "r_utility.h" diff --git a/src/r_defs.h b/src/r_defs.h index 8a10a9fafa..e8af4ea688 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -130,11 +130,13 @@ struct vertex_t return FLOAT2FIXED(p.Y); } - DVector2 fPos() + DVector2 fPos() const { return p; } + int Index() const; + angle_t viewangle; // precalculated angle for clipping int angletime; // recalculation time for view angle bool dirty; // something has changed and needs to be recalculated @@ -655,7 +657,7 @@ public: double FindLowestCeilingPoint(vertex_t **v) const; double FindHighestFloorPoint(vertex_t **v) const; void RemoveForceField(); - int Index() const { return int(this - &level.sectors[0]); } + int Index() const; void AdjustFloorClip () const; void SetColor(int r, int g, int b, int desat); @@ -1157,7 +1159,7 @@ struct side_t WORD TexelLength; SWORD Light; BYTE Flags; - int Index; // needed to access custom UDMF fields which are stored in loading order. + int UDMFIndex; // needed to access custom UDMF fields which are stored in loading order. int GetLightLevel (bool foggy, int baselight, bool is3dlight=false, int *pfakecontrast_usedbygzdoom=NULL) const; @@ -1265,6 +1267,8 @@ struct side_t vertex_t *V1() const; vertex_t *V2() const; + int Index() const; + //For GL FLightNode * lighthead; // all blended lights that may affect this wall @@ -1336,8 +1340,20 @@ struct line_t { return portalindex >= linePortals.Size() ? 0 : linePortals[portalindex].mAlign; } + + int Index() const; }; +inline vertex_t *side_t::V1() const +{ + return this == linedef->sidedef[0] ? linedef->v1 : linedef->v2; +} + +inline vertex_t *side_t::V2() const +{ + return this == linedef->sidedef[0] ? linedef->v2 : linedef->v1; +} + // phares 3/14/98 // // Sector list node showing all sectors an object appears in. @@ -1401,12 +1417,6 @@ struct seg_t float sidefrac; // relative position of seg's ending vertex on owning sidedef }; -struct glsegextra_t -{ - DWORD PartnerSeg; - subsector_t *Subsector; -}; - extern seg_t *segs; diff --git a/src/r_sky.cpp b/src/r_sky.cpp index f29929c262..89a2bc44cb 100644 --- a/src/r_sky.cpp +++ b/src/r_sky.cpp @@ -34,6 +34,7 @@ #include "r_utility.h" #include "v_text.h" #include "gi.h" +#include "g_levellocals.h" // // sky mapping diff --git a/src/r_state.h b/src/r_state.h index c3fa036364..7151c0441b 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -42,10 +42,7 @@ extern "C" int viewheight; extern TArray sprites; extern DWORD NumStdSprites; -extern int numvertexes; -extern vertex_t* vertexes; -extern int numvertexdatas; -extern vertexdata_t* vertexdatas; +extern TArray vertexdatas; extern int numsegs; extern seg_t* segs; @@ -56,12 +53,6 @@ extern subsector_t* subsectors; extern int numnodes; extern node_t* nodes; -extern int numlines; -extern line_t* lines; - -extern int numsides; -extern side_t* sides; - extern TArray Zones; extern node_t * gamenodes; diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index 083e0eeef5..d2c40109a1 100644 --- a/src/s_advsound.cpp +++ b/src/s_advsound.cpp @@ -52,6 +52,7 @@ #include "d_player.h" #include "serializer.h" #include "v_text.h" +#include "g_levellocals.h" // MACROS ------------------------------------------------------------------ diff --git a/src/s_sndseq.cpp b/src/s_sndseq.cpp index 28786ef8f0..31ed314b7b 100644 --- a/src/s_sndseq.cpp +++ b/src/s_sndseq.cpp @@ -29,6 +29,7 @@ #include "g_level.h" #include "serializer.h" #include "d_player.h" +#include "g_levellocals.h" // MACROS ------------------------------------------------------------------ diff --git a/src/s_sound.cpp b/src/s_sound.cpp index a37182e206..3888ee3dc3 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -53,6 +53,7 @@ #include "serializer.h" #include "d_player.h" #include "r_state.h" +#include "g_levellocals.h" // MACROS ------------------------------------------------------------------ diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index 2e9654607d..46485b2268 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -49,6 +49,7 @@ #include "gstrings.h" #include "zstring.h" #include "d_event.h" +#include "g_levellocals.h" static TArray properties; static TArray AFTable; @@ -716,18 +717,31 @@ void InitThingdef() auto secplanestruct = NewNativeStruct("Secplane", nullptr); secplanestruct->Size = sizeof(secplane_t); secplanestruct->Align = alignof(secplane_t); + auto sectorstruct = NewNativeStruct("Sector", nullptr); sectorstruct->Size = sizeof(sector_t); sectorstruct->Align = alignof(sector_t); + auto linestruct = NewNativeStruct("Line", nullptr); + linestruct->Size = sizeof(line_t); + linestruct->Align = alignof(line_t); + + auto sidestruct = NewNativeStruct("Side", nullptr); + sidestruct->Size = sizeof(side_t); + sidestruct->Align = alignof(side_t); + + auto vertstruct = NewNativeStruct("Vertex", nullptr); + vertstruct->Size = sizeof(vertex_t); + vertstruct->Align = alignof(vertex_t); + // set up the lines array in the sector struct. This is a bit messy because the type system is not prepared to handle a pointer to an array of pointers to a native struct even remotely well... // As a result, the size has to be set to something large and arbritrary because it can change between maps. This will need some serious improvement when things get cleaned up. - sectorstruct->AddNativeField("lines", NewPointer(NewResizableArray(NewPointer(NewNativeStruct("line", nullptr), false)), false), myoffsetof(sector_t, Lines), VARF_Native); + sectorstruct->AddNativeField("lines", NewPointer(NewResizableArray(NewPointer(linestruct, false)), false), myoffsetof(sector_t, Lines), VARF_Native); - // add the sector planes. These are value items of native structs so they have to be done here. - sectorstruct->AddNativeField("ceilingplane", secplanestruct, myoffsetof(sector_t, ceilingplane), VARF_Native); - sectorstruct->AddNativeField("floorplane", secplanestruct, myoffsetof(sector_t, floorplane), VARF_Native); + // add the sector planes. These are value items of native structs so they have to be done here. Write access should be through functions only to allow later optimization inside the renderer. + sectorstruct->AddNativeField("ceilingplane", secplanestruct, myoffsetof(sector_t, ceilingplane), VARF_Native|VARF_ReadOnly); + sectorstruct->AddNativeField("floorplane", secplanestruct, myoffsetof(sector_t, floorplane), VARF_Native|VARF_ReadOnly); @@ -747,6 +761,9 @@ void InitThingdef() // Add the sector array to LevelLocals. lstruct->AddNativeField("sectors", NewPointer(NewResizableArray(sectorstruct), false), myoffsetof(FLevelLocals, sectors), VARF_Native); + lstruct->AddNativeField("lines", NewPointer(NewResizableArray(linestruct), false), myoffsetof(FLevelLocals, lines), VARF_Native); + lstruct->AddNativeField("sides", NewPointer(NewResizableArray(sidestruct), false), myoffsetof(FLevelLocals, sides), VARF_Native); + lstruct->AddNativeField("vertexes", NewPointer(NewResizableArray(vertstruct), false), myoffsetof(FLevelLocals, vertexes), VARF_Native|VARF_ReadOnly); // set up a variable for the DEH data PStruct *dstruct = NewNativeStruct("DehInfo", nullptr); diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index e54a00963f..c4c44a7091 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -73,6 +73,7 @@ #include "a_ammo.h" #include "a_health.h" #include "a_keys.h" +#include "g_levellocals.h" //========================================================================== // diff --git a/src/scripting/vm/vm.h b/src/scripting/vm/vm.h index fdf5f3c9fe..2e98e865e0 100644 --- a/src/scripting/vm/vm.h +++ b/src/scripting/vm/vm.h @@ -209,6 +209,9 @@ public: void MaybePrintMessage(); }; +// This must be a separate function because the VC compiler would otherwise allocate memory on the stack for every separate instance of the exception object that may get thrown. +void ThrowAbortException(EVMAbortException reason, const char *moreinfo, ...); + enum EVMOpMode { MODE_ASHIFT = 0, diff --git a/src/scripting/vm/vmexec.cpp b/src/scripting/vm/vmexec.cpp index 3183edcfb7..1ad4e32563 100644 --- a/src/scripting/vm/vmexec.cpp +++ b/src/scripting/vm/vmexec.cpp @@ -44,9 +44,7 @@ extern cycle_t VMCycles[10]; extern int VMCalls[10]; -// This must be a separate function because the VC compiler would otherwise allocate memory on the stack for every separate instance of the exception object that may get thrown. -void ThrowAbortException(EVMAbortException reason, const char *moreinfo, ...); -// intentionally implemented in a different source file tp prevent inlining. +// intentionally implemented in a different source file to prevent inlining. void ThrowVMException(VMException *x); #define IMPLEMENT_VMEXEC diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 9684ec9246..52cbc1d653 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -2336,6 +2336,7 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool sym->Variants[0].Implementation->DefaultArgs = std::move(argdefaults); } + PClass *clstype = static_cast(c->Type()); if (varflags & VARF_Virtual) { if (sym->Variants[0].Implementation == nullptr) @@ -2349,7 +2350,6 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool } if (forclass) { - PClass *clstype = static_cast(c->Type()); int vindex = clstype->FindVirtualIndex(sym->SymbolName, sym->Variants[0].Proto); // specifying 'override' is necessary to prevent one of the biggest problem spots with virtual inheritance: Mismatching argument types. if (varflags & VARF_Override) @@ -2383,6 +2383,14 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool Error(p, "Virtual functions can only be defined for classes"); } } + else if (forclass) + { + int vindex = clstype->FindVirtualIndex(sym->SymbolName, sym->Variants[0].Proto); + if (vindex != -1) + { + Error(f, "Function %s attempts to override parent function without 'override' qualifier", FName(f->Name).GetChars()); + } + } } } diff --git a/src/serializer.cpp b/src/serializer.cpp index 7c48f9b1e3..5154b0700c 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -64,6 +64,7 @@ #include "doomerrors.h" #include "v_text.h" #include "cmdlib.h" +#include "g_levellocals.h" char nulspace[1024 * 1024 * 4]; bool save_full = false; // for testing. Should be removed afterward. @@ -1458,7 +1459,7 @@ template<> FSerializer &Serialize(FSerializer &arc, const char *key, const FPoly template<> FSerializer &Serialize(FSerializer &arc, const char *key, side_t *&value, side_t **defval) { - return SerializePointer(arc, key, value, defval, sides); + return SerializePointer(arc, key, value, defval, &level.sides[0]); } template<> FSerializer &Serialize(FSerializer &arc, const char *key, sector_t *&value, sector_t **defval) @@ -1478,12 +1479,12 @@ template<> FSerializer &Serialize(FSerializer &arc, const char *key, player_t *& template<> FSerializer &Serialize(FSerializer &arc, const char *key, line_t *&value, line_t **defval) { - return SerializePointer(arc, key, value, defval, lines); + return SerializePointer(arc, key, value, defval, &level.lines[0]); } template<> FSerializer &Serialize(FSerializer &arc, const char *key, vertex_t *&value, vertex_t **defval) { - return SerializePointer(arc, key, value, defval, vertexes); + return SerializePointer(arc, key, value, defval, &level.vertexes[0]); } //========================================================================== diff --git a/src/serializer.h b/src/serializer.h index 4797a4bce5..e4dc8f2263 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -15,10 +15,6 @@ struct usercmd_t; struct FWriter; struct FReader; -extern TArray loadsectors; -extern TArray loadlines; -extern TArray loadsides; - inline bool nullcmp(const void *buffer, size_t length) { const char *p = (const char *)buffer; diff --git a/src/st_stuff.cpp b/src/st_stuff.cpp index 31cf9b3a7c..632eaadf8a 100644 --- a/src/st_stuff.cpp +++ b/src/st_stuff.cpp @@ -30,6 +30,7 @@ #include "d_net.h" #include "doomstat.h" #include "g_level.h" +#include "g_levellocals.h" EXTERN_CVAR (Bool, ticker); EXTERN_CVAR (Bool, noisedebug); diff --git a/src/statistics.cpp b/src/statistics.cpp index 92a459e150..e96f103272 100644 --- a/src/statistics.cpp +++ b/src/statistics.cpp @@ -71,6 +71,7 @@ #include "p_lnspec.h" #include "m_crc32.h" #include "serializer.h" +#include "g_levellocals.h" CVAR(Int, savestatistics, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(String, statfile, "zdoomstat.txt", CVAR_ARCHIVE|CVAR_GLOBALCONFIG) diff --git a/src/tarray.h b/src/tarray.h index 7e6affb97c..3ee1c5cb99 100644 --- a/src/tarray.h +++ b/src/tarray.h @@ -553,6 +553,13 @@ public: this->Count = 0; this->Array = NULL; } + TStaticArray(TStaticArray &&other) + { + this->Array = other.Array; + this->Count = other.Count; + other.Array = nullptr; + other.Count = 0; + } // This is not supposed to be copyable. TStaticArray(const TStaticArray &other) = delete; @@ -564,7 +571,7 @@ public: { if (this->Array) delete[] this->Array; this->Count = 0; - this->Array = NULL; + this->Array = nullptr; } void Alloc(unsigned int amount) { @@ -573,6 +580,21 @@ public: this->Array = new T[amount]; this->Count = amount; } + TStaticArray &operator=(const TStaticArray &other) + { + Alloc(other.Size()); + memcpy(this->Array, other.Array, this->Count * sizeof(T)); + return *this; + } + TStaticArray &operator=(TStaticArray &&other) + { + if (this->Array) delete[] this->Array; + this->Array = other.Array; + this->Count = other.Count; + other.Array = nullptr; + other.Count = 0; + return *this; + } }; diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 07c3d2a13e..a285fdd1ee 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -61,6 +61,7 @@ #include "d_net.h" #include "colormatcher.h" #include "r_data/colormaps.h" +#include "g_levellocals.h" CUSTOM_CVAR(Int, uiscale, 2, CVAR_ARCHIVE | CVAR_NOINITCALL) { diff --git a/src/v_palette.cpp b/src/v_palette.cpp index aa39ba7913..4f4c9cb189 100644 --- a/src/v_palette.cpp +++ b/src/v_palette.cpp @@ -56,6 +56,7 @@ #include "x86.h" #include "colormatcher.h" #include "v_palette.h" +#include "g_levellocals.h" #include "r_data/colormaps.h" FPalette GPalette; diff --git a/src/wi_stuff.cpp b/src/wi_stuff.cpp index 12ca10e320..eb1c7d2fac 100644 --- a/src/wi_stuff.cpp +++ b/src/wi_stuff.cpp @@ -52,6 +52,7 @@ #include "templates.h" #include "gstrings.h" #include "cmdlib.h" +#include "g_levellocals.h" // States for the intermission typedef enum diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index 2a99f43640..14c4791c60 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -81,6 +81,7 @@ #include "g_level.h" #include "doomstat.h" #include "r_utility.h" +#include "g_levellocals.h" #include "stats.h" #include "st_start.h" diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index 673257a3c2..232beccccc 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -190,6 +190,56 @@ struct Vertex native native readonly Vector2 p; } +struct Side +{ + enum ETexpart + { + top=0, + mid=1, + bottom=2 + }; + + enum EWallFlags + { + WALLF_ABSLIGHTING = 1, // Light is absolute instead of relative + WALLF_NOAUTODECALS = 2, // Do not attach impact decals to this wall + WALLF_NOFAKECONTRAST = 4, // Don't do fake contrast for this wall in side_t::GetLightLevel + WALLF_SMOOTHLIGHTING = 8, // Similar to autocontrast but applies to all angles. + WALLF_CLIP_MIDTEX = 16, // Like the line counterpart, but only for this side. + WALLF_WRAP_MIDTEX = 32, // Like the line counterpart, but only for this side. + WALLF_POLYOBJ = 64, // This wall belongs to a polyobject. + WALLF_LIGHT_FOG = 128, // This wall's Light is used even in fog. + }; + + native Sector sector; // Sector the SideDef is facing. + //DBaseDecal* AttachedDecals; // [RH] Decals bound to the wall + native Line linedef; + native int16 Light; + native uint8 Flags; + + native TextureID GetTexture(int which); + native void SetTexture(int which, TextureID tex); + native void SetTextureXOffset(int which, double offset); + native double GetTextureXOffset(int which); + native void AddTextureXOffset(int which, double delta); + native void SetTextureYOffset(int which, double offset); + native double GetTextureYOffset(int which); + native void AddTextureYOffset(int which, double delta); + native void SetTextureXScale(int which, double scale); + native double GetTextureXScale(int which); + native void MultiplyTextureXScale(int which, double delta); + native void SetTextureYScale(int which, double scale); + native double GetTextureYScale(int which); + native void MultiplyTextureYScale(int which, double delta); + //native DInterpolation *SetInterpolation(int position); + //native void StopInterpolation(int position); + + native Vertex V1(); + native Vertex V2(); + + native int Index(); +}; + struct Line native { enum ELineFlags @@ -226,7 +276,7 @@ struct Line native }; - //native readonly vertex v1, v2; // vertices, from v1 to v2 + native readonly vertex v1, v2; // vertices, from v1 to v2 native readonly Vector2 delta; // precalculated v2 - v1 for side checking native uint flags; native uint activation; // activation type @@ -239,6 +289,13 @@ struct Line native native int validcount; // if == validcount, already checked native int locknumber; // [Dusk] lock number for special native readonly uint portalindex; + native readonly uint portaltransferred; + + native bool isLinePortal(); + native bool isVisualPortal(); + native Line getPortalDestination(); + native int getPortalAlignment(); + native int Index(); } struct SecPlane native @@ -295,6 +352,12 @@ struct Sector native //SectorEffect ceilingdata; //SectorEffect lightingdata; + enum EPlane + { + floor, + ceiling + }; + enum EInterpolationType { CeilingMove, @@ -378,6 +441,7 @@ struct Sector native native readonly int sectornum; + native int Index(); native double, Sector, F3DFloor NextHighestCeilingAt(double x, double y, double bottomz, double topz, int flags = 0); native double, Sector, F3DFloor NextLowestFloorAt(double x, double y, double z, int flags = 0, double steph = 0); diff --git a/wadsrc/static/zscript/heretic/hereticartifacts.txt b/wadsrc/static/zscript/heretic/hereticartifacts.txt index 20f52a2c93..3b7f14ad82 100644 --- a/wadsrc/static/zscript/heretic/hereticartifacts.txt +++ b/wadsrc/static/zscript/heretic/hereticartifacts.txt @@ -66,7 +66,7 @@ Class ArtiTomeOfPower : PowerupGiver Loop; } - bool Use (bool pickup) + override bool Use (bool pickup) { Playerinfo p = Owner.player; if (p && p.morphTics && (p.MorphStyle & MRF_UNDOBYTOMEOFPOWER)) diff --git a/wadsrc/static/zscript/heretic/weaponblaster.txt b/wadsrc/static/zscript/heretic/weaponblaster.txt index 913abffdb6..e7e1e92b55 100644 --- a/wadsrc/static/zscript/heretic/weaponblaster.txt +++ b/wadsrc/static/zscript/heretic/weaponblaster.txt @@ -220,7 +220,7 @@ class Ripper : Actor Stop; } - int DoSpecialDamage (Actor target, int damage, Name damagetype) + override int DoSpecialDamage (Actor target, int damage, Name damagetype) { if (target is "Ironlich") { // Less damage to Ironlich bosses diff --git a/wadsrc/static/zscript/heretic/weaponphoenix.txt b/wadsrc/static/zscript/heretic/weaponphoenix.txt index eb75acb1dd..558a257cdd 100644 --- a/wadsrc/static/zscript/heretic/weaponphoenix.txt +++ b/wadsrc/static/zscript/heretic/weaponphoenix.txt @@ -311,7 +311,7 @@ class PhoenixFX2 : Actor } - int DoSpecialDamage (Actor target, int damage, Name damagetype) + override int DoSpecialDamage (Actor target, int damage, Name damagetype) { if (target.player && Random[PhoenixFX2]() < 128) { // Freeze player for a bit diff --git a/wadsrc/static/zscript/heretic/weaponskullrod.txt b/wadsrc/static/zscript/heretic/weaponskullrod.txt index a8d77e1d8c..da959f7ae7 100644 --- a/wadsrc/static/zscript/heretic/weaponskullrod.txt +++ b/wadsrc/static/zscript/heretic/weaponskullrod.txt @@ -402,7 +402,7 @@ class RainPillar : Actor // Rain pillar 1 ------------------------------------------------------------ - int DoSpecialDamage (Actor target, int damage, Name damagetype) + override int DoSpecialDamage (Actor target, int damage, Name damagetype) { if (target.bBoss) { // Decrease damage for bosses diff --git a/wadsrc/static/zscript/hexen/heresiarch.txt b/wadsrc/static/zscript/hexen/heresiarch.txt index db4860c349..f89d2fb839 100644 --- a/wadsrc/static/zscript/hexen/heresiarch.txt +++ b/wadsrc/static/zscript/hexen/heresiarch.txt @@ -112,7 +112,7 @@ class Heresiarch : Actor Stop; } - void Die (Actor source, Actor inflictor, int dmgflags) + override void Die (Actor source, Actor inflictor, int dmgflags) { // The heresiarch just executes a script instead of a special upon death int script = special; @@ -698,8 +698,8 @@ class SorcBall2 : SorcBall Actor parent = target; Actor mo = Spawn("SorcFX2", Pos + (0, 0, parent.Floorclip + Heresiarch.SORC_DEFENSE_HEIGHT), ALLOW_REPLACE); - bReflective = true; - bInvulnerable = true; + parent.bReflective = true; + parent.bInvulnerable = true; parent.args[0] = Heresiarch.SORC_DEFENSE_TIME; if (mo) mo.target = parent; } diff --git a/wadsrc/static/zscript/shared/setcolor.txt b/wadsrc/static/zscript/shared/setcolor.txt index 18105ef543..2d9d3be576 100644 --- a/wadsrc/static/zscript/shared/setcolor.txt +++ b/wadsrc/static/zscript/shared/setcolor.txt @@ -28,7 +28,7 @@ class FadeSetter : Actor RenderStyle "None"; } - void PostBeginPlay() + override void PostBeginPlay() { Super.PostBeginPlay(); CurSector.SetFade(color(args[0], args[1], args[2])); diff --git a/wadsrc/static/zscript/strife/weapongrenade.txt b/wadsrc/static/zscript/strife/weapongrenade.txt index 7a775c57ba..21e568313c 100644 --- a/wadsrc/static/zscript/strife/weapongrenade.txt +++ b/wadsrc/static/zscript/strife/weapongrenade.txt @@ -241,7 +241,7 @@ class PhosphorousFire : Actor Stop; } - int DoSpecialDamage (Actor target, int damage, Name damagetype) + override int DoSpecialDamage (Actor target, int damage, Name damagetype) { if (target.bNoBlood) {