From 5ec786eef74220e91cd89dd081289f02179ff880 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 8 Jan 2017 11:52:35 +0100 Subject: [PATCH 01/17] - removed the 'dumpmap' CCMD because it was mostly broken anyway and would require a complete rewrite in UDMF to get back on track. --- src/CMakeLists.txt | 1 - src/p_writemap.cpp | 226 --------------------------------------------- 2 files changed, 227 deletions(-) delete mode 100644 src/p_writemap.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5d5d52c0f..f06687988 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1123,7 +1123,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/p_writemap.cpp b/src/p_writemap.cpp deleted file mode 100644 index cdf5a19d1..000000000 --- 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; -} From 5ee52f159e8097ce75d5b152b71590dd0af57a9d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 8 Jan 2017 12:11:31 +0100 Subject: [PATCH 02/17] - refactored the level backup data needed by the serializer into p_saveg.h. --- src/p_saveg.cpp | 20 ++++++++++++++++++++ src/p_saveg.h | 3 +++ src/p_setup.cpp | 15 +++------------ src/serializer.h | 4 ---- src/tarray.h | 6 ++++++ 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 5f9aeec42..72536e7cd 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -63,6 +63,10 @@ #include "r_renderer.h" #include "serializer.h" +static TStaticArray loadsectors; +static TArray loadlines; +static TArray loadsides; + //========================================================================== // @@ -988,4 +992,20 @@ 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.Resize(numlines); + memcpy(&loadlines[0], lines, numlines * sizeof(line_t)); + loadsides.Resize(numsides); + memcpy(&loadsides[0], sides, numsides * sizeof(side_t)); +} + +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 6c4c74f46..715fd6a19 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_setup.cpp b/src/p_setup.cpp index e03b7ac23..34b6909c9 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -73,6 +73,7 @@ #include "p_blockmap.h" #include "r_utility.h" #include "p_spec.h" +#include "p_saveg.h" #ifndef NO_EDATA #include "edata.h" #endif @@ -122,10 +123,6 @@ int numsegs; seg_t* segs; glsegextra_t* glsegextras; -//int numsectors; -//sector_t* sectors; -TArray loadsectors; - int numsubsectors; subsector_t* subsectors; @@ -134,11 +131,9 @@ node_t* nodes; int numlines; line_t* lines; -TArray loadlines; int numsides; side_t* sides; -TArray loadsides; TArray Zones; @@ -3431,6 +3426,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. @@ -4193,12 +4189,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)); + P_BackupMapData(); if (glsegextras != NULL) { diff --git a/src/serializer.h b/src/serializer.h index 4797a4bce..e4dc8f226 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/tarray.h b/src/tarray.h index 7e6affb97..5b9752d0f 100644 --- a/src/tarray.h +++ b/src/tarray.h @@ -573,6 +573,12 @@ public: this->Array = new T[amount]; this->Count = amount; } + TStaticArray &operator=(const TStaticArray &other) + { + Alloc(other.Size()); + memcpy(Array, other.Array, Count * sizeof(T)); + return *this; + } }; From 71d1138376d7863abefae2a3852a5b25d850bbfd Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 8 Jan 2017 14:39:16 +0100 Subject: [PATCH 03/17] - refactored the global lines array into a more VM friendly form, moved it to FLevelLocals and exported it to ZScript. - disabled the Build map loader after finding out that it has been completely broken and nonfunctional for a long time. Since this has no real value it will probably removed entirely in an upcoming commit. --- src/am_map.cpp | 63 ++++++++-------- src/compatibility.cpp | 24 +++--- src/edata.cpp | 10 +-- src/fragglescript/t_func.cpp | 22 +++--- src/g_game.cpp | 2 +- src/g_level.h | 1 + src/gl/data/gl_data.cpp | 2 +- src/gl/data/gl_setup.cpp | 10 +-- src/gl/scene/gl_bsp.cpp | 2 +- src/gl/scene/gl_sky.cpp | 2 +- src/gl/scene/gl_walls.cpp | 4 +- src/p_3dfloors.cpp | 24 +++--- src/p_3dmidtex.cpp | 23 +++--- src/p_acs.cpp | 47 ++++++------ src/p_buildmap.cpp | 18 +++-- src/p_glnodes.cpp | 33 +++++---- src/p_linkedsectors.cpp | 2 +- src/p_lnspec.cpp | 12 +-- src/p_map.cpp | 7 +- src/p_maputl.cpp | 8 +- src/p_pusher.cpp | 5 +- src/p_saveg.cpp | 9 +-- src/p_scroll.cpp | 39 +++++----- src/p_sectors.cpp | 4 +- src/p_setup.cpp | 105 +++++++++++++------------- src/p_sight.cpp | 2 +- src/p_slopes.cpp | 52 ++++++------- src/p_spec.cpp | 126 ++++++++++++++++---------------- src/p_tags.cpp | 2 +- src/p_teleport.cpp | 4 +- src/p_udmf.cpp | 7 +- src/p_xlat.cpp | 20 ++--- src/po_man.cpp | 8 +- src/portal.cpp | 32 ++++---- src/r_defs.h | 5 ++ src/r_plane.cpp | 2 +- src/r_state.h | 3 - src/scripting/thingdef_data.cpp | 14 +++- src/serializer.cpp | 2 +- 39 files changed, 378 insertions(+), 379 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index 1cfb6db59..505d5f303 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -601,23 +601,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); } @@ -2382,7 +2380,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 +2390,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 +2415,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 +2426,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 +2440,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 +2480,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 +2509,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/compatibility.cpp b/src/compatibility.cpp index 8f4472c85..9a29457eb 100644 --- a/src/compatibility.cpp +++ b/src/compatibility.cpp @@ -475,9 +475,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 +485,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 +495,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 +509,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 +520,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 +552,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/edata.cpp b/src/edata.cpp index 258c2a187..4940bb8f2 100644 --- a/src/edata.cpp +++ b/src/edata.cpp @@ -705,7 +705,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 +760,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_func.cpp b/src/fragglescript/t_func.cpp index 080adbd46..816af43d0 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -2171,7 +2171,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 +2194,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 +2251,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 +2270,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 +3363,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 +3987,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/g_game.cpp b/src/g_game.cpp index d80360193..dbf2f2636 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -2241,7 +2241,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_level.h b/src/g_level.h index 5808df138..d949b1604 100644 --- a/src/g_level.h +++ b/src/g_level.h @@ -401,6 +401,7 @@ struct FLevelLocals EMapType maptype; TStaticArray sectors; + TStaticArray lines; DWORD flags; DWORD flags2; diff --git a/src/gl/data/gl_data.cpp b/src/gl/data/gl_data.cpp index e8c5f22bb..b1696f8ff 100644 --- a/src/gl/data/gl_data.cpp +++ b/src/gl/data/gl_data.cpp @@ -547,7 +547,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_setup.cpp b/src/gl/data/gl_setup.cpp index 3fc022cf8..6207f53a4 100644 --- a/src/gl/data/gl_setup.cpp +++ b/src/gl/data/gl_setup.cpp @@ -405,17 +405,15 @@ static void InitVertexData() vt_sectorlists = new TArray[numvertexes]; - 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) { @@ -712,7 +710,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/scene/gl_bsp.cpp b/src/gl/scene/gl_bsp.cpp index da6077049..af4d46d61 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_sky.cpp b/src/gl/scene/gl_sky.cpp index 2a2952548..7fa261d36 100644 --- a/src/gl/scene/gl_sky.cpp +++ b/src/gl/scene/gl_sky.cpp @@ -51,7 +51,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_walls.cpp b/src/gl/scene/gl_walls.cpp index 9d471b72d..3acf209a6 100644 --- a/src/gl/scene/gl_walls.cpp +++ b/src/gl/scene/gl_walls.cpp @@ -326,7 +326,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 +1414,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; } diff --git a/src/p_3dfloors.cpp b/src/p_3dfloors.cpp index e4778e91d..2f8b3b15c 100644 --- a/src/p_3dfloors.cpp +++ b/src/p_3dfloors.cpp @@ -850,16 +850,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 +866,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 b775055d8..adc487abb 100644 --- a/src/p_3dmidtex.cpp +++ b/src/p_3dmidtex.cpp @@ -121,10 +121,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 +132,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 +151,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 +176,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 d35714ca5..0f1feb7b5 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -3284,7 +3284,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 +3296,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) @@ -4434,8 +4434,8 @@ int DLevelScript::SideFromID(int id, int side) { 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]->Index; } } @@ -4444,7 +4444,7 @@ int DLevelScript::LineFromID(int id) if (id == 0) { if (activationline == NULL) return -1; - return int(activationline - lines); + return activationline->Index(); } else { @@ -5695,7 +5695,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 +5704,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 +7742,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 +8307,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 +8350,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 +8375,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_buildmap.cpp b/src/p_buildmap.cpp index 99f3fb638..3a1943fc8 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_glnodes.cpp b/src/p_glnodes.cpp index 26e341aab..7c76836e9 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -255,10 +255,10 @@ static bool LoadGLVertexes(FileReader * lump) mgl = (mapglvertex_t *) (gldata + GL_VERT_OFFSET); memcpy(vertexes, oldvertexes, firstglvertex * sizeof(vertex_t)); - for(i=0;ipartner == 0xFFFF ? DWORD_MAX : LittleShort(ml->partner); if(ml->linedef != 0xffff) { - ldef = &lines[LittleShort(ml->linedef)]; + ldef = &level.lines[LittleShort(ml->linedef)]; segs[i].linedef = ldef; @@ -382,7 +382,7 @@ static bool LoadGLSegs(FileReader * lump) if(ml->linedef != 0xffff) // skip minisegs { - ldef = &lines[LittleLong(ml->linedef)]; + ldef = &level.lines[LittleLong(ml->linedef)]; segs[i].linedef = ldef; @@ -1002,7 +1002,7 @@ bool P_CheckNodes(MapData * map, bool rebuilt, int buildtime) { vertexes, numvertexes, sides, numsides, - lines, numlines, + &level.lines[0], (int)level.lines.Size(), 0, 0, 0, 0 }; leveldata.FindMapBounds (); @@ -1114,7 +1114,7 @@ static void CreateCachedNodes(MapData *map) else WriteLong(ZNodes, 0); 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 +1156,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 +1171,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;iGetChecksum(md5map); @@ -1261,10 +1261,11 @@ static bool CheckCachedNodes(MapData *map) goto errorout; } - for(int i=0;i= 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 c1e342de8..8d08f8575 100644 --- a/src/p_lnspec.cpp +++ b/src/p_lnspec.cpp @@ -2604,7 +2604,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 +2659,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 +2733,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 +3028,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 7f6a47b66..342e8cb9d 100644 --- a/src/p_map.cpp +++ b/src/p_map.cpp @@ -183,7 +183,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 +3296,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 +3906,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 +3950,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 d4ac79ce7..5c7c39051 100644 --- a/src/p_maputl.cpp +++ b/src/p_maputl.cpp @@ -330,7 +330,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 +367,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 +709,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_pusher.cpp b/src/p_pusher.cpp index 8a4032b40..928d9bc5e 100644 --- a/src/p_pusher.cpp +++ b/src/p_pusher.cpp @@ -358,11 +358,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 72536e7cd..2c2cd34ba 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -64,7 +64,7 @@ #include "serializer.h" static TStaticArray loadsectors; -static TArray loadlines; +static TStaticArray loadlines; static TArray loadsides; @@ -902,7 +902,7 @@ 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 || + if (arc.GetSize("linedefs") != level.lines.Size() || arc.GetSize("sidedefs") != (unsigned)numsides || arc.GetSize("sectors") != level.sectors.Size() || arc.GetSize("polyobjs") != (unsigned)po_NumPolyobjs || @@ -956,7 +956,7 @@ 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("linedefs", &level.lines[0], &loadlines[0], level.lines.Size()); arc.Array("sidedefs", sides, &loadsides[0], numsides); arc.Array("sectors", &level.sectors[0], &loadsectors[0], level.sectors.Size()); arc("zones", Zones); @@ -997,8 +997,7 @@ void G_SerializeLevel(FSerializer &arc, bool hubload) void P_BackupMapData() { loadsectors = level.sectors; - loadlines.Resize(numlines); - memcpy(&loadlines[0], lines, numlines * sizeof(line_t)); + loadlines = level.lines; loadsides.Resize(numsides); memcpy(&loadsides[0], sides, numsides * sizeof(side_t)); } diff --git a/src/p_scroll.cpp b/src/p_scroll.cpp index 954b1ac36..95adb2b38 100644 --- a/src/p_scroll.cpp +++ b/src/p_scroll.cpp @@ -380,24 +380,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 +473,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 +493,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 +511,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 +529,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); + s = int(level.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])); break; case Scroll_Texture_Left: l->special = special; // Restore the special, for compat_useblocking's benefit. - s = int(lines[i].sidedef[0] - sides); + s = int(level.lines[i].sidedef[0] - sides); 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 = int(level.lines[i].sidedef[0] - sides); 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 = int(level.lines[i].sidedef[0] - sides); 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 = int(level.lines[i].sidedef[0] - sides); 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 = int(level.lines[i].sidedef[0] - sides); if (l->args[0] == 0) { dx = (l->args[1] - l->args[2]) / 64.; dy = (l->args[4] - l->args[3]) / 64.; @@ -645,9 +644,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 = int(level.lines[linenum].sidedef[sidechoice] - sides); unsigned int i; for (i = 0; i < numcollected; i++) { diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index d4abcc534..ef28af020 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -1838,7 +1838,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) @@ -1873,7 +1873,7 @@ void subsector_t::BuildPolyBSP() // Set up level information for the node builder. PolyNodeLevel.Sides = sides; PolyNodeLevel.NumSides = numsides; - PolyNodeLevel.Lines = lines; + PolyNodeLevel.Lines = &level.lines[0]; PolyNodeLevel.NumLines = numlines; // Feed segs to the nodebuilder and build the nodes. diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 34b6909c9..d81376abe 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -89,7 +89,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); @@ -107,7 +106,15 @@ 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; +} // @@ -129,9 +136,6 @@ subsector_t* subsectors; int numnodes; node_t* nodes; -int numlines; -line_t* lines; - int numsides; side_t* sides; @@ -589,11 +593,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 @@ -878,7 +882,7 @@ void P_LoadZSegs (FileReaderBase &data) segs[i].v1 = &vertexes[v1]; segs[i].v2 = &vertexes[v2]; - segs[i].linedef = ldef = &lines[line]; + 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) @@ -940,7 +944,7 @@ void P_LoadGLZSegs (FileReaderBase &data, int type) { 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) @@ -999,10 +1003,10 @@ void LoadZNodes(FileReaderBase &data, int glnodes) } if (vertexes != newvertarray) { - 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 - vertexes + newvertarray; + line.v2 = line.v2 - vertexes + newvertarray; } delete[] vertexes; vertexes = newvertarray; @@ -1212,7 +1216,6 @@ void P_LoadSegs (MapData * map) BYTE *data; 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 @@ -1247,10 +1250,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 - vertexes] = vertchanged[line.v2 - vertexes] = 1; } try @@ -1327,14 +1329,14 @@ 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] - sides) >= level.lines.Size()) { throw badseg(2, i, int(ldef->sidedef[side] - sides)); } @@ -1362,7 +1364,7 @@ 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: @@ -1998,7 +2000,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) { @@ -2022,8 +2024,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) @@ -2048,14 +2048,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; } } } @@ -2067,9 +2067,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]-sides].a.alpha); } } @@ -2098,10 +2098,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); @@ -2151,7 +2151,7 @@ void P_LoadLineDefs (MapData * map) P_AllocateSideDefs (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 @@ -2197,10 +2197,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); @@ -2243,7 +2243,7 @@ void P_LoadLineDefs2 (MapData * map) P_AllocateSideDefs (sidecount); mld = (maplinedef2_t *)mldf; - ld = lines; + ld = &level.lines[0]; for (i = 0; i < numlines; i++, mld++, ld++) { int j; @@ -2376,7 +2376,7 @@ 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; } @@ -2398,7 +2398,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; } @@ -2803,12 +2803,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; @@ -2991,7 +2991,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; @@ -3115,9 +3115,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) @@ -3169,9 +3169,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; @@ -3461,6 +3461,7 @@ void P_FreeLevelData () delete[] level.sectors[0].e; } level.sectors.Clear(); + level.lines.Clear(); if (gamenodes != NULL && gamenodes != nodes) { @@ -3489,12 +3490,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; @@ -3923,7 +3918,7 @@ void P_SetupLevel (const char *lumpname, int position) { vertexes, numvertexes, sides, numsides, - lines, numlines, + &level.lines[0], (int)level.lines.Size(), 0, 0, 0, 0 }; leveldata.FindMapBounds (); diff --git a/src/p_sight.cpp b/src/p_sight.cpp index eb62e505a..9cbf1f69e 100644 --- a/src/p_sight.cpp +++ b/src/p_sight.cpp @@ -482,7 +482,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; diff --git a/src/p_slopes.cpp b/src/p_slopes.cpp index ff0159940..cc116b692 100644 --- a/src/p_slopes.cpp +++ b/src/p_slopes.cpp @@ -52,7 +52,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; @@ -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 45f4d043c..15eae0146 100644 --- a/src/p_spec.cpp +++ b/src/p_spec.cpp @@ -189,7 +189,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 +361,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 +790,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 +821,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 +958,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 +1004,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 +1266,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 +1277,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 +1294,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 +1315,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 +1355,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 +1388,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 +1415,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 +1430,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 +1498,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 dc71e2663..fb0efa81c 100644 --- a/src/p_tags.cpp +++ b/src/p_tags.cpp @@ -47,7 +47,7 @@ FTagManager tagManager; static inline int lineindex(const line_t *line) { - return (int)(intptr_t)(line - lines); + return level.lines.Size(); } //----------------------------------------------------------------------------- diff --git a/src/p_teleport.cpp b/src/p_teleport.cpp index 12f9ef4b8..131169773 100644 --- a/src/p_teleport.cpp +++ b/src/p_teleport.cpp @@ -447,10 +447,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_udmf.cpp b/src/p_udmf.cpp index 63621d2fa..ba9805b1c 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -1813,13 +1813,14 @@ public: i++; } } - numlines = ParsedLines.Size(); + unsigned numlines = ParsedLines.Size(); numsides = sidecount; - lines = new line_t[numlines]; + level.lines.Alloc(numlines); sides = new side_t[numsides]; int line, side; + auto lines = &level.lines[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 }; diff --git a/src/p_xlat.cpp b/src/p_xlat.cpp index 424b93a52..01c09f450 100644 --- a/src/p_xlat.cpp +++ b/src/p_xlat.cpp @@ -317,27 +317,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 15c8d5a52..3b70fad9c 100644 --- a/src/po_man.cpp +++ b/src/po_man.cpp @@ -1575,7 +1575,7 @@ static void SpawnPolyobj (int index, int tag, int type) { if (!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, sides[i].linedef->Index()); } po->Sidedefs.Push (&sides[i]); } @@ -1776,11 +1776,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 fa5c9fed7..9d07666af 100644 --- a/src/portal.cpp +++ b/src/portal.cpp @@ -115,7 +115,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 +209,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 +290,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 +305,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 +473,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 +868,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 +889,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 +1057,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/r_defs.h b/src/r_defs.h index 07a66b09c..8b760d62e 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -1337,6 +1337,11 @@ struct line_t { return portalindex >= linePortals.Size() ? 0 : linePortals[portalindex].mAlign; } + + int Index() const + { + return int(this - &level.lines[0]); + } }; // phares 3/14/98 diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 64433b6d4..add2d6bf8 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1347,7 +1347,7 @@ void R_DrawSkyPlane (visplane_t *pl) else { // MBF's linedef-controlled skies // Sky Linedef - const line_t *l = &lines[(pl->sky & ~PL_SKYFLAT)-1]; + const line_t *l = &level.lines[(pl->sky & ~PL_SKYFLAT)-1]; // Sky transferred from first sidedef const side_t *s = l->sidedef[0]; diff --git a/src/r_state.h b/src/r_state.h index c3fa03636..a8476b52f 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -56,9 +56,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; diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index 2e9654607..621892a4e 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -716,18 +716,23 @@ 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); + // 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 +752,7 @@ 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); // set up a variable for the DEH data PStruct *dstruct = NewNativeStruct("DehInfo", nullptr); diff --git a/src/serializer.cpp b/src/serializer.cpp index 7c48f9b1e..e0f8517b9 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -1478,7 +1478,7 @@ 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) From cb89a1a81aadcf6ed4141831c7c6df6aefd2fd5a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 8 Jan 2017 14:59:31 +0100 Subject: [PATCH 04/17] - fixed inconsistent use of line_t::portaltransferred. Some parts used 0 as 'nothing' others used UINT_MAX. 0 should refer to the map's default sky, not to nothing. --- src/gl/scene/gl_walls.cpp | 2 +- src/p_sectors.cpp | 14 ++++++++++++++ src/p_setup.cpp | 2 ++ src/p_udmf.cpp | 3 +++ wadsrc/static/zscript/base.txt | 4 +++- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/gl/scene/gl_walls.cpp b/src/gl/scene/gl_walls.cpp index 3acf209a6..89eb1d67f 100644 --- a/src/gl/scene/gl_walls.cpp +++ b/src/gl/scene/gl_walls.cpp @@ -1547,7 +1547,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/p_sectors.cpp b/src/p_sectors.cpp index ef28af020..3d77b44c9 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -1772,6 +1772,19 @@ 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. + va_list ap; + throw CVMAbortException(X_ARRAY_OUT_OF_BOUNDS, "Accessed invalid sector", ap); + } + ACTION_RETURN_INT(ndx); + } + //=========================================================================== // // @@ -2100,6 +2113,7 @@ 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(Secplane, secplane_t, normal) DEFINE_FIELD_X(Secplane, secplane_t, D) diff --git a/src/p_setup.cpp b/src/p_setup.cpp index d81376abe..10f4265d3 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -2156,6 +2156,7 @@ void P_LoadLineDefs (MapData * map) { 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. @@ -2249,6 +2250,7 @@ void P_LoadLineDefs2 (MapData * map) int j; ld->portalindex = UINT_MAX; + ld->portaltransferred = UINT_MAX; for (j = 0; j < 5; j++) ld->args[j] = mld->args[j]; diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp index ba9805b1c..8e88fc89d 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -1824,6 +1824,9 @@ public: { short tempalpha[2] = { SHRT_MIN, SHRT_MIN }; + lines[line].portalindex = UINT_MAX; + lines[line].portaltransferred = UINT_MAX; + lines[line] = ParsedLines[line]; for(int sd = 0; sd < 2; sd++) diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index 673257a3c..b48f0ee58 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -226,7 +226,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 +239,7 @@ 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; } struct SecPlane native @@ -378,6 +379,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); From 1c74faea73369dc4af7b8f5ecb7b5e89f1867967 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 8 Jan 2017 15:45:37 +0100 Subject: [PATCH 05/17] - exported line_t's functions to the VM. --- src/p_sectors.cpp | 45 ++++++++++++++++++++++++++++++++-- src/scripting/vm/vm.h | 3 +++ src/scripting/vm/vmexec.cpp | 4 +-- wadsrc/static/zscript/base.txt | 6 +++++ 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index 3d77b44c9..8be0862b6 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -1779,12 +1779,53 @@ DEFINE_ACTION_FUNCTION(_Sector, NextLowestFloorAt) 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. - va_list ap; - throw CVMAbortException(X_ARRAY_OUT_OF_BOUNDS, "Accessed invalid sector", ap); + 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); + } + + //=========================================================================== // // diff --git a/src/scripting/vm/vm.h b/src/scripting/vm/vm.h index fdf5f3c9f..2e98e865e 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 3183edcfb..1ad4e3256 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/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index b48f0ee58..3dc846f0b 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -240,6 +240,12 @@ struct Line native 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 From a54d2d8a5581d1567b3ae742cb266af4278901ea Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 8 Jan 2017 16:09:21 +0100 Subject: [PATCH 06/17] - fixed UDMF initialization for linedef portal info. --- src/p_udmf.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp index 8e88fc89d..bbe7153f9 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -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; @@ -1824,9 +1825,6 @@ public: { short tempalpha[2] = { SHRT_MIN, SHRT_MIN }; - lines[line].portalindex = UINT_MAX; - lines[line].portaltransferred = UINT_MAX; - lines[line] = ParsedLines[line]; for(int sd = 0; sd < 2; sd++) From e188047d70e829fb84192d5ee68602720f362a08 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 8 Jan 2017 17:20:27 +0200 Subject: [PATCH 07/17] Fixed compilation with GCC/Clang --- src/tarray.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tarray.h b/src/tarray.h index 5b9752d0f..5ae24965d 100644 --- a/src/tarray.h +++ b/src/tarray.h @@ -576,7 +576,7 @@ public: TStaticArray &operator=(const TStaticArray &other) { Alloc(other.Size()); - memcpy(Array, other.Array, Count * sizeof(T)); + memcpy(this->Array, other.Array, this->Count * sizeof(T)); return *this; } }; From cd7986b1b122aa39e561c0ab170b018552c24a93 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 8 Jan 2017 18:45:30 +0100 Subject: [PATCH 08/17] - refactored global sides array to be more VM friendly. - moved FLevelLocals to its own header to resolve some circular include conflicts. --- src/actor.h | 9 +-- src/am_map.cpp | 1 + src/bbannouncer.cpp | 1 + src/c_cmds.cpp | 1 + src/c_console.cpp | 1 + src/compatibility.cpp | 1 + src/d_main.cpp | 1 + src/d_net.cpp | 1 + src/decallib.cpp | 1 + src/dobject.cpp | 1 + src/dobjgc.cpp | 9 +-- src/doomstat.cpp | 1 + src/edata.cpp | 1 + src/fragglescript/t_cmd.cpp | 1 + src/fragglescript/t_func.cpp | 1 + src/fragglescript/t_load.cpp | 1 + src/fragglescript/t_script.cpp | 1 + src/g_game.cpp | 1 + src/g_hub.cpp | 1 + src/g_inventory/a_artifacts.cpp | 1 + src/g_inventory/a_pickups.cpp | 1 + src/g_level.cpp | 1 + src/g_level.h | 74 --------------------- src/g_levellocals.h | 95 +++++++++++++++++++++++++++ src/g_mapinfo.cpp | 1 + src/g_shared/a_decals.cpp | 5 +- src/g_shared/a_fastprojectile.cpp | 1 + src/g_shared/a_flashfader.cpp | 1 + src/g_shared/a_lightning.cpp | 1 + src/g_shared/a_morph.cpp | 1 + src/g_shared/a_movingcamera.cpp | 1 + src/g_shared/a_randomspawner.cpp | 1 + src/g_shared/sbarinfo.cpp | 1 + src/g_shared/shared_hud.cpp | 1 + src/g_shared/shared_sbar.cpp | 1 + src/g_skill.cpp | 1 + src/g_strife/strife_sbar.cpp | 1 + src/gl/compatibility/gl_20.cpp | 1 + src/gl/data/gl_data.cpp | 1 + src/gl/data/gl_portaldata.cpp | 1 + src/gl/data/gl_setup.cpp | 24 +++---- src/gl/data/gl_vertexbuffer.cpp | 1 + src/gl/dynlights/a_dynlight.cpp | 1 + src/gl/dynlights/gl_dynlight.cpp | 1 + src/gl/models/gl_models.cpp | 1 + src/gl/renderer/gl_lightdata.cpp | 1 + src/gl/scene/gl_drawinfo.cpp | 1 + src/gl/scene/gl_flats.cpp | 1 + src/gl/scene/gl_renderhacks.cpp | 2 +- src/gl/scene/gl_scene.cpp | 1 + src/gl/scene/gl_sky.cpp | 1 + src/gl/scene/gl_sprite.cpp | 1 + src/gl/scene/gl_walls.cpp | 1 + src/gl/scene/gl_weapon.cpp | 1 + src/gl/utility/gl_clock.cpp | 1 + src/hu_scores.cpp | 1 + src/intermission/intermission.cpp | 1 + src/m_cheat.cpp | 1 + src/menu/readthis.cpp | 1 + src/nodebuild_utility.cpp | 2 +- src/p_3dfloors.cpp | 1 + src/p_3dmidtex.cpp | 1 + src/p_acs.cpp | 13 ++-- src/p_actionfunctions.cpp | 1 + src/p_ceiling.cpp | 1 + src/p_conversation.cpp | 1 + src/p_doors.cpp | 1 + src/p_effect.cpp | 1 + src/p_enemy.cpp | 1 + src/p_floor.cpp | 1 + src/p_glnodes.cpp | 10 +-- src/p_interaction.cpp | 1 + src/p_lights.cpp | 1 + src/p_linkedsectors.cpp | 1 + src/p_lnspec.cpp | 1 + src/p_map.cpp | 1 + src/p_maputl.cpp | 1 + src/p_mobj.cpp | 24 +++++-- src/p_pillar.cpp | 1 + src/p_plats.cpp | 1 + src/p_pspr.cpp | 1 + src/p_pusher.cpp | 1 + src/p_saveg.cpp | 10 +-- src/p_scroll.cpp | 69 +++++++++---------- src/p_sectors.cpp | 7 +- src/p_setup.cpp | 84 ++++++++++------------- src/p_sight.cpp | 1 + src/p_slopes.cpp | 1 + src/p_spec.cpp | 1 + src/p_tags.cpp | 16 +---- src/p_teleport.cpp | 1 + src/p_things.cpp | 1 + src/p_tick.cpp | 1 + src/p_trace.cpp | 1 + src/p_udmf.cpp | 14 ++-- src/p_user.cpp | 1 + src/p_xlat.cpp | 1 + src/po_man.cpp | 25 +++---- src/portal.cpp | 1 + src/r_bsp.cpp | 1 + src/r_defs.h | 11 ++-- src/r_plane.cpp | 1 + src/r_sky.cpp | 1 + src/r_state.h | 3 - src/r_things.cpp | 1 + src/s_advsound.cpp | 1 + src/s_sndseq.cpp | 1 + src/s_sound.cpp | 1 + src/scripting/thingdef_data.cpp | 1 + src/scripting/thingdef_properties.cpp | 1 + src/serializer.cpp | 3 +- src/st_stuff.cpp | 1 + src/statistics.cpp | 1 + src/v_draw.cpp | 1 + src/v_palette.cpp | 1 + src/wi_stuff.cpp | 1 + src/win32/i_main.cpp | 1 + 117 files changed, 354 insertions(+), 251 deletions(-) create mode 100644 src/g_levellocals.h diff --git a/src/actor.h b/src/actor.h index 439ae2644..d4f5f27c5 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 505d5f303..90d84360b 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" //============================================================================= diff --git a/src/bbannouncer.cpp b/src/bbannouncer.cpp index a19ba72f4..6fbf31479 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 2923a8ae8..be4944b8c 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 faeec0a68..a3f84723b 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 9a29457eb..0b27a1efa 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 ------------------------------------------------------------------ diff --git a/src/d_main.cpp b/src/d_main.cpp index 1ea2d2707..2c6b1c9e9 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 4bda25510..0ebb7de38 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 7bfdfc3e7..52a4eadf5 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 c6e20be5e..b96cc5ff9 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 11cfdc8c2..625f80678 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 87ca50a16..309398331 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 4940bb8f2..015be0bb1 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 diff --git a/src/fragglescript/t_cmd.cpp b/src/fragglescript/t_cmd.cpp index 1434870d1..691740024 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 816af43d0..514d9aaea 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"); diff --git a/src/fragglescript/t_load.cpp b/src/fragglescript/t_load.cpp index 0f3d8417b..b3b38543d 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 0469e5063..b5c21632b 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 dbf2f2636..6565d5324 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"); diff --git a/src/g_hub.cpp b/src/g_hub.cpp index cabcef2d3..e87dcff7d 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 9b67e2dc9..6ece99b38 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 c963fd918..e7a21fee6 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 a664e02b9..b8d73727c 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 d949b1604..6274c22b0 100644 --- a/src/g_level.h +++ b/src/g_level.h @@ -376,78 +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; - TStaticArray lines; - - 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 { @@ -477,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 000000000..c49be313b --- /dev/null +++ b/src/g_levellocals.h @@ -0,0 +1,95 @@ +#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 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 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 6a6076565..3fab0bd0d 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 bfbe6d13d..5ac3cb452 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 fb0faef0f..3bfaf8d94 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 3e0b939e0..006b7ef84 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 1598b87f0..deeb8405b 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 935efa2db..b48a126cd 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 c09d93fd5..f32550f2d 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 d5a396d0d..9be5cac7b 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 c06abf90d..fb7d42a46 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 a061dbf59..0c9b74255 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 c288a05c8..cb3ada8e9 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 70daadc23..d158fa4cd 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 46dd63ff7..1a8e216fd 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 0f9ee5f43..eeb5572c1 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 b1696f8ff..07fac1b2e 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" diff --git a/src/gl/data/gl_portaldata.cpp b/src/gl/data/gl_portaldata.cpp index 71b10b4bb..c705da589 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 6207f53a4..e41181228 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" @@ -459,8 +460,8 @@ static void InitVertexData() static void GetSideVertices(int sdnum, DVector2 *v1, DVector2 *v2) { - line_t *ln = sides[sdnum].linedef; - if (ln->sidedef[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(); @@ -487,6 +488,7 @@ 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; @@ -534,7 +536,7 @@ static void PrepareSegs() seg_t *seg = &segs[i]; if (seg->sidedef == NULL) continue; // miniseg - int sidenum = int(seg->sidedef - sides); + int sidenum = seg->sidedef->Index(); realsegs++; segcount[sidenum]++; @@ -548,13 +550,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; @@ -568,7 +570,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); } } @@ -667,10 +669,10 @@ void gl_CleanLevelData() } } - 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) { diff --git a/src/gl/data/gl_vertexbuffer.cpp b/src/gl/data/gl_vertexbuffer.cpp index a645fbff4..4973ad39d 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 15d9291bd..5f0d31552 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 bc107c60e..a0d9292a9 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 f3dfbd569..ce6b22ee8 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 d09484a1f..3ba557737 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_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 5fc775603..7e9a3e6d2 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 efadbcebe..c4296c50d 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 9242df2a9..4dd7b7d81 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 b4efe736e..cfd3f017e 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 7fa261d36..19d1c9127 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" diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index b0cfcebe3..198dfea6e 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 89eb1d67f..5965eebc3 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" diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 7662c7876..953509495 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 0dc9fd76c..68a2b06e5 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 35e18006d..1164eaf1c 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 2aacd215b..2416f01c4 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 53ae789c6..414fafba9 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 b8a3837ee..f1e82cd51 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_utility.cpp b/src/nodebuild_utility.cpp index 02e280261..85dea384f 100644 --- a/src/nodebuild_utility.cpp +++ b/src/nodebuild_utility.cpp @@ -186,7 +186,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 2f8b3b15c..c25d4a532 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) diff --git a/src/p_3dmidtex.cpp b/src/p_3dmidtex.cpp index adc487abb..cb7f27a08 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" //============================================================================ diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 0f1feb7b5..f1a0ae8bf 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; @@ -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 (level.lines[line].sidedef[side] == NULL) return -1; - return level.lines[line].sidedef[side]->Index; + return level.lines[line].sidedef[side]->UDMFIndex; } } diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index f4b2f8103..b90f656c1 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_ceiling.cpp b/src/p_ceiling.cpp index 79fd29591..7bf1f9099 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 5fd21e73b..4f7f2fea7 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 1490647fc..3101be1c7 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 107759427..44dc17971 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); diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index a3d48a7ac..ac4e0f04b 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 dbe3792da..48c73f131 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 7c76836e9..c68b0d5b0 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.); } @@ -1001,7 +1003,7 @@ bool P_CheckNodes(MapData * map, bool rebuilt, int buildtime) FNodeBuilder::FLevel leveldata = { vertexes, numvertexes, - sides, numsides, + &level.sides[0], (int)level.sides.Size(), &level.lines[0], (int)level.lines.Size(), 0, 0, 0, 0 }; diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp index 9aa178e64..b6ffcb699 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 d9fc19c79..5442809e4 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 03cd5af4e..0dd29c10e 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 { diff --git a/src/p_lnspec.cpp b/src/p_lnspec.cpp index 8d08f8575..77682d1e3 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: /* diff --git a/src/p_map.cpp b/src/p_map.cpp index 342e8cb9d..d48fb4e5a 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) diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp index 5c7c39051..e6b2aebea 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); diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 3bdf3718d..d5ec020a0 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 d4682e570..d603edc8a 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 7bbf33b27..8dd82c024 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 a6a581228..4349a7c02 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 928d9bc5e..5190b5ced 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); diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 2c2cd34ba..33f65bfa7 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -62,10 +62,11 @@ #include "r_sky.h" #include "r_renderer.h" #include "serializer.h" +#include "g_levellocals.h" static TStaticArray loadsectors; static TStaticArray loadlines; -static TArray loadsides; +static TStaticArray loadsides; //========================================================================== @@ -903,7 +904,7 @@ void G_SerializeLevel(FSerializer &arc, bool hubload) BYTE chk[16] = { 0 }; arc.Array("checksum", chk, 16); if (arc.GetSize("linedefs") != level.lines.Size() || - arc.GetSize("sidedefs") != (unsigned)numsides || + arc.GetSize("sidedefs") != level.sides.Size() || arc.GetSize("sectors") != level.sectors.Size() || arc.GetSize("polyobjs") != (unsigned)po_NumPolyobjs || memcmp(chk, level.md5, 16)) @@ -957,7 +958,7 @@ 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", &level.lines[0], &loadlines[0], level.lines.Size()); - arc.Array("sidedefs", sides, &loadsides[0], numsides); + 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); @@ -998,8 +999,7 @@ void P_BackupMapData() { loadsectors = level.sectors; loadlines = level.lines; - loadsides.Resize(numsides); - memcpy(&loadsides[0], sides, numsides * sizeof(side_t)); + loadsides = level.sides; } void P_FreeMapDataBackup() diff --git a/src/p_scroll.cpp b/src/p_scroll.cpp index 95adb2b38..403eb3087 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); } } @@ -536,41 +537,41 @@ void P_SpawnScrollers(void) case Scroll_Texture_Offsets: // killough 3/2/98: scroll according to sidedef offsets - s = int(level.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(level.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(level.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(level.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(level.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(level.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.; @@ -607,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 (); @@ -627,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); @@ -646,7 +647,7 @@ void SetWallScroller (int id, int sidechoice, double dx, double dy, EScrollPos W { if (level.lines[linenum].sidedef[sidechoice] != NULL) { - int sidenum = int(level.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 8be0862b6..daccbf06f 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] @@ -1925,10 +1926,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.Sides = &level.sides[0]; + PolyNodeLevel.NumSides = level.sides.Size(); PolyNodeLevel.Lines = &level.lines[0]; - PolyNodeLevel.NumLines = numlines; + PolyNodeLevel.NumLines = numlines; // is this correct??? // Feed segs to the nodebuilder and build the nodes. PolyNodeBuilder.Clear(); diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 10f4265d3..58b934438 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -74,6 +74,7 @@ #include "r_utility.h" #include "p_spec.h" #include "p_saveg.h" +#include "g_levellocals.h" #ifndef NO_EDATA #include "edata.h" #endif @@ -136,9 +137,6 @@ subsector_t* subsectors; int numnodes; node_t* nodes; -int numsides; -side_t* sides; - TArray Zones; node_t * gamenodes; @@ -194,7 +192,7 @@ TArray deathmatchstarts (16); FPlayerStart playerstarts[MAXPLAYERS]; TArray AllPlayerStarts; -static void P_AllocateSideDefs (int count); +static void P_AllocateSideDefs (MapData *map, int count); //=========================================================================== @@ -1336,9 +1334,9 @@ void P_LoadSegs (MapData * map) ldef = &level.lines[linedef]; li->linedef = ldef; side = LittleShort(ml->side); - if ((unsigned)(ldef->sidedef[side] - sides) >= level.lines.Size()) + 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; @@ -1368,7 +1366,7 @@ void P_LoadSegs (MapData * map) 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"); @@ -1978,7 +1976,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) @@ -2069,7 +2067,7 @@ void P_FinishLoadingLineDefs () { for (auto &line : level.lines) { - P_FinishLoadingLineDef(&line, sidetemp[line.sidedef[0]-sides].a.alpha); + P_FinishLoadingLineDef(&line, sidetemp[line.sidedef[0]->Index()].a.alpha); } } @@ -2079,10 +2077,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 { @@ -2148,7 +2146,7 @@ void P_LoadLineDefs (MapData * map) } } - P_AllocateSideDefs (sidecount); + P_AllocateSideDefs (map, sidecount); mld = (maplinedef_t *)mldf; ld = &level.lines[0]; @@ -2241,7 +2239,7 @@ void P_LoadLineDefs2 (MapData * map) ForceNodeBuild = true; } - P_AllocateSideDefs (sidecount); + P_AllocateSideDefs (map, sidecount); mld = (maplinedef2_t *)mldf; ld = &level.lines[0]; @@ -2291,18 +2289,13 @@ 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)]; for (i = 0; i < count; i++) @@ -2311,6 +2304,7 @@ static void P_AllocateSideDefs (int count) 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); @@ -2331,6 +2325,7 @@ static void P_LoopSidedefs (bool firstloop) { delete[] sidetemp; } + int numsides = level.sides.Size(); sidetemp = new sidei_t[MAX(numvertexes, numsides)]; for (i = 0; i < numvertexes; ++i) @@ -2347,8 +2342,8 @@ 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]); + line_t *line = level.sides[i].linedef; + int lineside = (line->sidedef[0] != &level.sides[i]); int vert = int((lineside ? line->v2 : line->v1) - vertexes); sidetemp[i].b.lineside = lineside; @@ -2356,8 +2351,8 @@ static void P_LoopSidedefs (bool firstloop) 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 @@ -2366,7 +2361,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 @@ -2382,7 +2377,7 @@ static void P_LoopSidedefs (bool firstloop) continue; } - right = DWORD(rightside - sides); + right = rightside->Index(); } else { @@ -2411,7 +2406,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) { @@ -2420,9 +2415,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(); @@ -2447,8 +2442,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, @@ -2604,14 +2599,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 @@ -2628,7 +2622,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 @@ -3390,11 +3384,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. @@ -3464,6 +3458,7 @@ void P_FreeLevelData () } level.sectors.Clear(); level.lines.Clear(); + level.sides.Clear(); if (gamenodes != NULL && gamenodes != nodes) { @@ -3492,12 +3487,6 @@ void P_FreeLevelData () numsubsectors = numgamesubsectors = 0; nodes = gamenodes = NULL; numnodes = numgamenodes = 0; - if (sides != NULL) - { - delete[] sides; - sides = NULL; - } - numsides = 0; if (blockmaplump != NULL) { @@ -3754,7 +3743,6 @@ void P_SetupLevel (const char *lumpname, int position) times[1].Unclock(); times[2].Clock(); - P_LoadSideDefs (map); times[2].Unclock(); times[3].Clock(); @@ -3919,7 +3907,7 @@ void P_SetupLevel (const char *lumpname, int position) FNodeBuilder::FLevel leveldata = { vertexes, numvertexes, - sides, numsides, + &level.sides[0], (int)level.sides.Size(), &level.lines[0], (int)level.lines.Size(), 0, 0, 0, 0 }; diff --git a/src/p_sight.cpp b/src/p_sight.cpp index 9cbf1f69e..a482f602d 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"); diff --git a/src/p_slopes.cpp b/src/p_slopes.cpp index cc116b692..672c9e77b 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" //=========================================================================== // diff --git a/src/p_spec.cpp b/src/p_spec.cpp index 15eae0146..b3953b1bd 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 diff --git a/src/p_tags.cpp b/src/p_tags.cpp index fb0efa81c..9e7d60d60 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 level.lines.Size(); -} - -//----------------------------------------------------------------------------- -// -// -// -//----------------------------------------------------------------------------- - 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 131169773..5eb63e4ce 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 diff --git a/src/p_things.cpp b/src/p_things.cpp index 6aac786f0..f6c06a1e5 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 332b7af81..2f8151425 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 4b0a5f3bd..3597535e5 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 bbe7153f9..d86e83a39 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" //=========================================================================== // @@ -1136,7 +1137,7 @@ public: sdt->midtexture = "-"; sd->SetTextureXScale(1.); sd->SetTextureYScale(1.); - sd->Index = index; + sd->UDMFIndex = index; sc.MustGetToken('{'); while (!sc.CheckToken('}')) @@ -1815,11 +1816,11 @@ public: } } unsigned numlines = ParsedLines.Size(); - numsides = sidecount; + level.sides.Alloc(sidecount); level.lines.Alloc(numlines); - sides = new side_t[numsides]; int line, side; auto lines = &level.lines[0]; + auto sides = &level.sides[0]; for(line = 0, side = 0; line < (int)numlines; line++) { @@ -1854,11 +1855,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); } } diff --git a/src/p_user.cpp b/src/p_user.cpp index 98108f780..662e60a28 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_xlat.cpp b/src/p_xlat.cpp index 01c09f450..29ccf966f 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 diff --git a/src/po_man.cpp b/src/po_man.cpp index 3b70fad9c..d9e15d1be 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 ------------------------------------------------------------------ @@ -1429,11 +1430,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); } @@ -1499,8 +1500,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() - vertexes)); sidenum = sidetemp[sidenum].b.next; } } @@ -1534,7 +1535,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 +1571,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, sides[i].linedef->Index()); + 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); diff --git a/src/portal.cpp b/src/portal.cpp index 9d07666af..abe442554 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) diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index fef7271e1..14a2f153f 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -51,6 +51,7 @@ #include "r_sky.h" #include "po_man.h" #include "r_data/colormaps.h" +#include "g_levellocals.h" CVAR (Bool, r_drawflat, false, 0) // [RH] Don't texture segs? EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor); diff --git a/src/r_defs.h b/src/r_defs.h index 8b760d62e..66fafe4cd 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -656,7 +656,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); @@ -1158,7 +1158,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; @@ -1266,6 +1266,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 @@ -1338,10 +1340,7 @@ struct line_t return portalindex >= linePortals.Size() ? 0 : linePortals[portalindex].mAlign; } - int Index() const - { - return int(this - &level.lines[0]); - } + int Index() const; }; // phares 3/14/98 diff --git a/src/r_plane.cpp b/src/r_plane.cpp index add2d6bf8..c57a6ac5b 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -58,6 +58,7 @@ #include "r_3dfloors.h" #include "v_palette.h" #include "r_data/colormaps.h" +#include "g_levellocals.h" #ifdef _MSC_VER #pragma warning(disable:4244) diff --git a/src/r_sky.cpp b/src/r_sky.cpp index f29929c26..89a2bc44c 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 a8476b52f..743bc11a0 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -56,9 +56,6 @@ extern subsector_t* subsectors; extern int numnodes; extern node_t* nodes; -extern int numsides; -extern side_t* sides; - extern TArray Zones; extern node_t * gamenodes; diff --git a/src/r_things.cpp b/src/r_things.cpp index 51b8221ec..62b424327 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -64,6 +64,7 @@ #include "r_data/voxels.h" #include "p_local.h" #include "p_maputl.h" +#include "g_levellocals.h" #include "r_thread.h" EXTERN_CVAR(Bool, st_scale) diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index 083e0eeef..d2c40109a 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 28786ef8f..31ed314b7 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 a37182e20..3888ee3dc 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 621892a4e..30b998beb 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; diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index e54a00963..c4c44a709 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/serializer.cpp b/src/serializer.cpp index e0f8517b9..181d4b741 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) diff --git a/src/st_stuff.cpp b/src/st_stuff.cpp index 31cf9b3a7..632eaadf8 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 92a459e15..e96f10327 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/v_draw.cpp b/src/v_draw.cpp index 6f8bc5198..16b0e405a 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 aa39ba791..4f4c9cb18 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 12ca10e32..eb1c7d2fa 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 2a99f4364..14c4791c6 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" From abdfb8788b310757fb8d780c8ce3c9eaf274d054 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 8 Jan 2017 18:53:02 +0100 Subject: [PATCH 09/17] - fixed bad variable assignment in Heresiarch. --- wadsrc/static/zscript/hexen/heresiarch.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wadsrc/static/zscript/hexen/heresiarch.txt b/wadsrc/static/zscript/hexen/heresiarch.txt index db4860c34..74bccbf4c 100644 --- a/wadsrc/static/zscript/hexen/heresiarch.txt +++ b/wadsrc/static/zscript/hexen/heresiarch.txt @@ -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; } From 7a5171a2e92af33bc98a1beb97621f35516e05d6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 8 Jan 2017 19:07:26 +0100 Subject: [PATCH 10/17] - fixed: The check for virtual function overrides was never done if the overriding function had no qualifier at all. - fixed several occurences where an 'override' qualifier was missing. --- src/scripting/zscript/zcc_compile.cpp | 10 +++++++++- wadsrc/static/zscript/heretic/hereticartifacts.txt | 2 +- wadsrc/static/zscript/heretic/weaponblaster.txt | 2 +- wadsrc/static/zscript/heretic/weaponphoenix.txt | 2 +- wadsrc/static/zscript/heretic/weaponskullrod.txt | 2 +- wadsrc/static/zscript/hexen/heresiarch.txt | 2 +- wadsrc/static/zscript/shared/setcolor.txt | 2 +- wadsrc/static/zscript/strife/weapongrenade.txt | 2 +- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 9684ec924..52cbc1d65 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/wadsrc/static/zscript/heretic/hereticartifacts.txt b/wadsrc/static/zscript/heretic/hereticartifacts.txt index 20f52a2c9..3b7f14ad8 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 913abffdb..e7e1e92b5 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 eb75acb1d..558a257cd 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 a8d77e1d8..da959f7ae 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 74bccbf4c..f89d2fb83 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; diff --git a/wadsrc/static/zscript/shared/setcolor.txt b/wadsrc/static/zscript/shared/setcolor.txt index 18105ef54..2d9d3be57 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 7a775c57b..21e568313 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) { From c9964d36d695f435f24f08e0b8feb4a1d3dddd6a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 8 Jan 2017 19:34:04 +0100 Subject: [PATCH 11/17] - fixed: A single sight check iteration may not succeed if origin and end point are in different portal groups. All those may do is collect more portals. --- src/p_sight.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/p_sight.cpp b/src/p_sight.cpp index a482f602d..40a392f32 100644 --- a/src/p_sight.cpp +++ b/src/p_sight.cpp @@ -791,6 +791,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; } @@ -820,6 +821,11 @@ bool P_CheckSight (AActor *t1, AActor *t2, int flags) return false; } + if (t2->player) + { + int a = 0; + } + const sector_t *s1 = t1->Sector; const sector_t *s2 = t2->Sector; int pnum = int(s1->Index()) * level.sectors.Size() + int(s2->Index()); From 97a90c52e07846522d29ffa48d26dd4895379429 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 8 Jan 2017 19:44:00 +0100 Subject: [PATCH 12/17] - fixed: Particles should disappear if their alpha goes below zero. --- src/p_effect.cpp | 2 +- src/p_sight.cpp | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/p_effect.cpp b/src/p_effect.cpp index 44dc17971..e0679338d 100644 --- a/src/p_effect.cpp +++ b/src/p_effect.cpp @@ -273,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_sight.cpp b/src/p_sight.cpp index 40a392f32..9ee543c8a 100644 --- a/src/p_sight.cpp +++ b/src/p_sight.cpp @@ -821,11 +821,6 @@ bool P_CheckSight (AActor *t1, AActor *t2, int flags) return false; } - if (t2->player) - { - int a = 0; - } - const sector_t *s1 = t1->Sector; const sector_t *s2 = t2->Sector; int pnum = int(s1->Index()) * level.sectors.Size() + int(s2->Index()); From f78927500e306665bf0bd26320df1819c920f4b7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 8 Jan 2017 21:42:26 +0100 Subject: [PATCH 13/17] - exported all meaningful parts of side_t to the VM. --- src/nodebuild_utility.cpp | 1 + src/p_sectors.cpp | 144 ++++++++++++++++++++++++++++++++ src/po_man.cpp | 13 --- src/r_defs.h | 10 +++ src/scripting/thingdef_data.cpp | 5 ++ wadsrc/static/zscript/base.txt | 56 +++++++++++++ 6 files changed, 216 insertions(+), 13 deletions(-) diff --git a/src/nodebuild_utility.cpp b/src/nodebuild_utility.cpp index 85dea384f..b6115f4c8 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; diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index daccbf06f..20489057c 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -1826,6 +1826,145 @@ DEFINE_ACTION_FUNCTION(_Sector, NextLowestFloorAt) 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()); + } //=========================================================================== // @@ -2157,6 +2296,11 @@ 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) DEFINE_FIELD_X(Secplane, secplane_t, negiC) diff --git a/src/po_man.cpp b/src/po_man.cpp index d9e15d1be..45b459281 100644 --- a/src/po_man.cpp +++ b/src/po_man.cpp @@ -40,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) @@ -149,8 +138,6 @@ static void ReleaseAllPolyNodes(); // EXTERNAL DATA DECLARATIONS ---------------------------------------------- -extern seg_t *segs; - // PUBLIC DATA DEFINITIONS ------------------------------------------------- polyblock_t **PolyBlockMap; diff --git a/src/r_defs.h b/src/r_defs.h index 66fafe4cd..ce6890311 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -1343,6 +1343,16 @@ struct line_t 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. diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index 30b998beb..0effa0c20 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -726,6 +726,10 @@ void InitThingdef() 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); + // 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. @@ -754,6 +758,7 @@ 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); // set up a variable for the DEH data PStruct *dstruct = NewNativeStruct("DehInfo", nullptr); diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index 3dc846f0b..232becccc 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 @@ -302,6 +352,12 @@ struct Sector native //SectorEffect ceilingdata; //SectorEffect lightingdata; + enum EPlane + { + floor, + ceiling + }; + enum EInterpolationType { CeilingMove, From 12037fdc951f9b7d886b54d97d58f207c970d20b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 9 Jan 2017 00:46:16 +0100 Subject: [PATCH 14/17] - made the vertexes array VM friendly. --- src/am_map.cpp | 18 ++--- src/g_levellocals.h | 6 ++ src/gl/data/gl_setup.cpp | 64 +++++++++--------- src/nodebuild.h | 4 +- src/nodebuild_extract.cpp | 16 ++--- src/p_glnodes.cpp | 52 +++++++------- src/p_saveg.cpp | 3 +- src/p_sectors.cpp | 10 ++- src/p_setup.cpp | 116 +++++++++++++++----------------- src/p_slopes.cpp | 20 +++--- src/p_udmf.cpp | 15 ++--- src/po_man.cpp | 4 +- src/r_defs.h | 4 +- src/r_state.h | 2 - src/scripting/thingdef_data.cpp | 5 ++ src/serializer.cpp | 2 +- src/tarray.h | 18 ++++- 17 files changed, 190 insertions(+), 169 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index 90d84360b..a6ccb92cf 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -1029,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; diff --git a/src/g_levellocals.h b/src/g_levellocals.h index c49be313b..08b18145d 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -27,6 +27,7 @@ struct FLevelLocals FString NextSecretMap; // map to go to when used secret exit EMapType maptype; + TStaticArray vertexes; TStaticArray sectors; TStaticArray lines; TStaticArray sides; @@ -79,6 +80,11 @@ struct FLevelLocals 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]); diff --git a/src/gl/data/gl_setup.cpp b/src/gl/data/gl_setup.cpp index e41181228..5b0affea5 100644 --- a/src/gl/data/gl_setup.cpp +++ b/src/gl/data/gl_setup.cpp @@ -403,7 +403,7 @@ static void InitVertexData() int i,j,k; - vt_sectorlists = new TArray[numvertexes]; + vt_sectorlists = new TArray[level.vertexes.Size()]; for(auto &line : level.lines) @@ -420,32 +420,33 @@ static void InitVertexData() { 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]->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,20 +653,17 @@ 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; } } diff --git a/src/nodebuild.h b/src/nodebuild.h index 7e2a61aaa..54d07ad5f 100644 --- a/src/nodebuild.h +++ b/src/nodebuild.h @@ -209,10 +209,10 @@ public: bool makeGLNodes); ~FNodeBuilder (); - void Extract (node_t *&nodes, int &nodeCount, + void Extract(node_t *&nodes, int &nodeCount, seg_t *&segs, glsegextra_t *&glsegextras, 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 c3f63c820..bec0fbc5d 100644 --- a/src/nodebuild_extract.cpp +++ b/src/nodebuild_extract.cpp @@ -55,12 +55,12 @@ void FNodeBuilder::Extract (node_t *&outNodes, int &nodeCount, seg_t *&outSegs, glsegextra_t *&outSegExtras, 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,7 +109,7 @@ 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); } @@ -145,8 +145,8 @@ 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; @@ -162,8 +162,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/p_glnodes.cpp b/src/p_glnodes.cpp index c68b0d5b0..4310c670e 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -224,7 +224,7 @@ static bool LoadGLVertexes(FileReader * lump) BYTE *gldata; int i; - firstglvertex = numvertexes; + firstglvertex = level.vertexes.Size(); int gllen=lump->GetLength(); @@ -249,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)); + memcpy(&level.vertexes[0], &oldvertexes[0], firstglvertex * sizeof(vertex_t)); for(auto &line : level.lines) { - line.v1 = vertexes + (line.v1 - oldvertexes); - line.v2 = vertexes + (line.v2 - oldvertexes); + // Remap vertex pointers in linedefs + line.v1 = &level.vertexes[line.v1 - &oldvertexes[0]]; + line.v2 = &level.vertexes[line.v2 - &oldvertexes[0]]; } - for (i = firstglvertex; i < numvertexes; i++) + for (i = firstglvertex; i < (int)numvertexes; i++) { - vertexes[i].set(LittleLong(mgl->x)/65536., LittleLong(mgl->y)/65536.); + level.vertexes[i].set(LittleLong(mgl->x)/65536., LittleLong(mgl->y)/65536.); mgl++; } delete[] gldata; @@ -324,8 +324,8 @@ static bool LoadGLSegs(FileReader * lump) 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))]; + segs[i].v1 = &level.vertexes[checkGLVertex(LittleShort(ml->v1))]; + segs[i].v2 = &level.vertexes[checkGLVertex(LittleShort(ml->v2))]; glsegextras[i].PartnerSeg = ml->partner == 0xFFFF ? DWORD_MAX : LittleShort(ml->partner); if(ml->linedef != 0xffff) @@ -377,8 +377,8 @@ static bool LoadGLSegs(FileReader * lump) 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))]; + segs[i].v1 = &level.vertexes[checkGLVertex3(LittleLong(ml->v1))]; + segs[i].v2 = &level.vertexes[checkGLVertex3(LittleLong(ml->v2))]; glsegextras[i].PartnerSeg = LittleLong(ml->partner); @@ -1002,18 +1002,18 @@ bool P_CheckNodes(MapData * map, bool rebuilt, int buildtime) P_GetPolySpots (map, polyspots, anchors); FNodeBuilder::FLevel leveldata = { - vertexes, numvertexes, + &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, 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; @@ -1095,11 +1095,11 @@ static void CreateCachedNodes(MapData *map) MemFile ZNodes; WriteLong(ZNodes, 0); - WriteLong(ZNodes, numvertexes); - for(int i=0;iIndex()); if (glsegextras != NULL) WriteLong(ZNodes, DWORD(glsegextras[i].PartnerSeg)); else WriteLong(ZNodes, 0); if (segs[i].linedef) @@ -1178,7 +1178,7 @@ static void CreateCachedNodes(MapData *map) map->GetChecksum(compressed+8); for (unsigned i = 0; i < level.lines.Size(); i++) { - DWORD ndx[2] = { LittleLong(DWORD(level.lines[i].v1 - vertexes)), LittleLong(DWORD(level.lines[i].v2 - vertexes)) }; + DWORD ndx[2] = { LittleLong(DWORD(level.lines[i].v1->Index())), LittleLong(DWORD(level.lines[i].v2->Index())) }; memcpy(compressed + 8 + 16 + 8 * i, ndx, 8); } memcpy(compressed + offset - 4, "ZGL3", 4); @@ -1266,8 +1266,8 @@ static bool CheckCachedNodes(MapData *map) for(auto &line : level.lines) { int i = line.Index(); - line.v1 = &vertexes[LittleLong(verts[i*2])]; - line.v2 = &vertexes[LittleLong(verts[i*2+1])]; + line.v1 = &level.vertexes[LittleLong(verts[i*2])]; + line.v2 = &level.vertexes[LittleLong(verts[i*2+1])]; } delete [] verts; diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 33f65bfa7..227fc91fd 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -358,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) @@ -376,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; diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index 20489057c..c95f48d15 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -711,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(); @@ -760,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(); @@ -1966,6 +1966,12 @@ DEFINE_ACTION_FUNCTION(_Sector, NextLowestFloorAt) ACTION_RETURN_INT(self->Index()); } + DEFINE_ACTION_FUNCTION(_Vertex, Index) + { + PARAM_SELF_STRUCT_PROLOGUE(vertex_t); + ACTION_RETURN_INT(self->Index()); + } + //=========================================================================== // // diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 58b934438..cf86a452d 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -122,8 +122,6 @@ inline bool P_LoadBuildMap(BYTE *mapdata, size_t len, FMapThing **things, int *n // MAP related Lookup tables. // Store VERTEXES, LINEDEFS, SIDEDEFS, etc. // -int numvertexes; -vertex_t* vertexes; int numvertexdatas; vertexdata_t* vertexdatas; @@ -833,11 +831,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); + unsigned numvertexes = map->Size(ML_VERTEXES) / sizeof(mapvertex_t); numvertexdatas = 0; if (numvertexes == 0) @@ -846,18 +842,18 @@ void P_LoadVertexes (MapData * map) } // Allocate memory for buffer. - vertexes = new vertex_t[numvertexes]; + level.vertexes.Alloc(numvertexes); vertexdatas = NULL; 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)); } } @@ -878,8 +874,8 @@ void P_LoadZSegs (FileReaderBase &data) data >> v1 >> v2 >> line >> side; - segs[i].v1 = &vertexes[v1]; - segs[i].v2 = &vertexes[v2]; + 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; @@ -928,7 +924,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; @@ -975,23 +971,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) { @@ -999,16 +998,14 @@ void LoadZNodes(FileReaderBase &data, int glnodes) data >> x >> y; newvertarray[i + orgVerts].set(x, y); } - if (vertexes != newvertarray) + if (fix) { for (auto &line : level.lines) { - line.v1 = line.v1 - vertexes + newvertarray; - line.v2 = line.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 @@ -1212,6 +1209,7 @@ 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; //int ptp_angle; // phares 10/4/98 @@ -1250,7 +1248,7 @@ void P_LoadSegs (MapData * map) for (auto &line : level.lines) { - vertchanged[line.v1 - vertexes] = vertchanged[line.v2 - vertexes] = 1; + vertchanged[line.v1->Index()] = vertchanged[line.v2->Index()] = 1; } try @@ -1271,8 +1269,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); @@ -2111,17 +2109,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)); @@ -2172,8 +2169,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])); @@ -2210,8 +2207,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)); @@ -2256,8 +2253,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])); @@ -2297,7 +2294,7 @@ static void P_AllocateSideDefs (MapData *map, int count) 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; @@ -2326,9 +2323,9 @@ static void P_LoopSidedefs (bool firstloop) delete[] sidetemp; } int numsides = level.sides.Size(); - sidetemp = new sidei_t[MAX(numvertexes, numsides)]; + 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; @@ -2344,7 +2341,7 @@ static void P_LoopSidedefs (bool firstloop) // as their left edge. line_t *line = level.sides[i].linedef; int lineside = (line->sidedef[0] != &level.sides[i]); - int vert = int((lineside ? line->v2 : line->v1) - vertexes); + int vert = lineside ? line->v2->Index() : line->v1->Index(); sidetemp[i].b.lineside = lineside; sidetemp[i].b.next = sidetemp[vert].b.first; @@ -2383,11 +2380,11 @@ static void P_LoopSidedefs (bool firstloop) { 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; @@ -2764,22 +2761,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); @@ -3435,12 +3431,6 @@ void P_FreeLevelData () wminfo.maxfrags = 0; FBehavior::StaticUnloadModules (); - if (vertexes != NULL) - { - delete[] vertexes; - vertexes = NULL; - } - numvertexes = 0; if (segs != NULL) { delete[] segs; @@ -3459,6 +3449,7 @@ void P_FreeLevelData () level.sectors.Clear(); level.lines.Clear(); level.sides.Clear(); + level.vertexes.Clear(); if (gamenodes != NULL && gamenodes != nodes) { @@ -3906,7 +3897,7 @@ void P_SetupLevel (const char *lumpname, int position) P_GetPolySpots (map, polyspots, anchors); FNodeBuilder::FLevel leveldata = { - vertexes, numvertexes, + &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 @@ -3916,11 +3907,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, 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(); diff --git a/src/p_slopes.cpp b/src/p_slopes.cpp index 672c9e77b..c16e03b3c 100644 --- a/src/p_slopes.cpp +++ b/src/p_slopes.cpp @@ -258,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) { @@ -310,14 +310,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++) { @@ -330,7 +330,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; @@ -360,7 +360,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); } } diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp index d86e83a39..0284c0c23 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -1790,12 +1790,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); @@ -1804,8 +1804,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++; @@ -2011,9 +2011,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)); + level.vertexes.Alloc(ParsedVertices.Size()); + memcpy(&level.vertexes[0], &ParsedVertices[0], level.vertexes.Size() * sizeof(vertex_t)); // Create the real vertex datas numvertexdatas = ParsedVertexDatas.Size(); diff --git a/src/po_man.cpp b/src/po_man.cpp index 45b459281..e8c1cbbb8 100644 --- a/src/po_man.cpp +++ b/src/po_man.cpp @@ -1479,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) @@ -1488,7 +1488,7 @@ static void IterFindPolySides (FPolyObj *po, side_t *side) while (sidenum != NO_SIDE) { po->Sidedefs.Push(&level.sides[sidenum]); - AddPolyVert(vnum, DWORD(level.sides[sidenum].V2() - vertexes)); + AddPolyVert(vnum, DWORD(level.sides[sidenum].V2()->Index())); sidenum = sidetemp[sidenum].b.next; } } diff --git a/src/r_defs.h b/src/r_defs.h index ce6890311..6972eab65 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -131,11 +131,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 diff --git a/src/r_state.h b/src/r_state.h index 743bc11a0..aa5b46342 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -42,8 +42,6 @@ extern "C" int viewheight; extern TArray sprites; extern DWORD NumStdSprites; -extern int numvertexes; -extern vertex_t* vertexes; extern int numvertexdatas; extern vertexdata_t* vertexdatas; diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index 0effa0c20..46485b226 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -730,6 +730,10 @@ void InitThingdef() 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. @@ -759,6 +763,7 @@ void InitThingdef() 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/serializer.cpp b/src/serializer.cpp index 181d4b741..5154b0700 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -1484,7 +1484,7 @@ template<> FSerializer &Serialize(FSerializer &arc, const char *key, line_t *&va 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/tarray.h b/src/tarray.h index 5ae24965d..3ee1c5cb9 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) { @@ -579,6 +586,15 @@ public: 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; + } }; From b9ac44e8f21a8c751b53aad7f41a44045e9bdc9e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 9 Jan 2017 01:28:07 +0100 Subject: [PATCH 15/17] - fixed: The sight checker's portalgroup variable was not initialized. - got rid of glsegextras. This was probably one of the most ill-conceived means to save some memory in ZDoom, but now, when a pure software rendered engine no longer needs to be considered it's just totally useless to keep this mess in. --- src/gl/data/gl_setup.cpp | 30 ----------------- src/nodebuild.h | 2 +- src/nodebuild_extract.cpp | 9 +++-- src/p_glnodes.cpp | 70 ++++++++++++++++----------------------- src/p_setup.cpp | 27 +++------------ src/p_setup.h | 1 - src/p_sight.cpp | 1 + src/r_defs.h | 6 ---- 8 files changed, 39 insertions(+), 107 deletions(-) diff --git a/src/gl/data/gl_setup.cpp b/src/gl/data/gl_setup.cpp index 5b0affea5..6bdf57d4c 100644 --- a/src/gl/data/gl_setup.cpp +++ b/src/gl/data/gl_setup.cpp @@ -501,36 +501,6 @@ static void PrepareSegs() // 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;i &vertexes); const int *GetOldVertexTable(); diff --git a/src/nodebuild_extract.cpp b/src/nodebuild_extract.cpp index bec0fbc5d..11332f049 100644 --- a/src/nodebuild_extract.cpp +++ b/src/nodebuild_extract.cpp @@ -53,7 +53,7 @@ #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, TStaticArray &outVerts) { @@ -116,7 +116,6 @@ void FNodeBuilder::Extract (node_t *&outNodes, int &nodeCount, 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]; @@ -151,6 +149,7 @@ void FNodeBuilder::Extract (node_t *&outNodes, int &nodeCount, 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) diff --git a/src/p_glnodes.cpp b/src/p_glnodes.cpp index 4310c670e..35f9f4502 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -319,15 +319,13 @@ 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 = &level.vertexes[checkGLVertex(LittleShort(ml->v1))]; segs[i].v2 = &level.vertexes[checkGLVertex(LittleShort(ml->v2))]; - - glsegextras[i].PartnerSeg = ml->partner == 0xFFFF ? DWORD_MAX : LittleShort(ml->partner); + segs[i].PartnerSeg = ml->partner == 0xFFFF ? nullptr : &segs[LittleShort(ml->partner)]; if(ml->linedef != 0xffff) { ldef = &level.lines[LittleShort(ml->linedef)]; @@ -372,15 +370,13 @@ 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 = &level.vertexes[checkGLVertex3(LittleLong(ml->v1))]; segs[i].v2 = &level.vertexes[checkGLVertex3(LittleLong(ml->v2))]; - - glsegextras[i].PartnerSeg = LittleLong(ml->partner); + segs[i].PartnerSeg = LittleLong(ml->partner) == 0xffffffffu? nullptr : &segs[LittleLong(ml->partner)]; if(ml->linedef != 0xffff) // skip minisegs { @@ -1011,7 +1007,7 @@ bool P_CheckNodes(MapData * map, bool rebuilt, int buildtime) FNodeBuilder builder (leveldata, polyspots, anchors, true); builder.Extract (nodes, numnodes, - segs, glsegextras, numsegs, + segs, numsegs, subsectors, numsubsectors, level.vertexes); endTime = I_FPSTime (); @@ -1112,8 +1108,7 @@ static void CreateCachedNodes(MapData *map) for(int i=0;iIndex()); - if (glsegextras != NULL) WriteLong(ZNodes, DWORD(glsegextras[i].PartnerSeg)); - else WriteLong(ZNodes, 0); + WriteLong(ZNodes, segs[i].PartnerSeg == nullptr? 0xffffffffu : DWORD(segs[i].PartnerSeg - segs)); if (segs[i].linedef) { WriteLong(ZNodes, DWORD(segs[i].linedef->Index())); @@ -1440,40 +1435,32 @@ void P_SetRenderSector() #endif // Check for incorrect partner seg info so that the following code does not crash. - if (glsegextras == NULL) + + for (i = 0; i < numsegs; i++) { - // This can be normal nodes, mistakenly identified as GL nodes so we must fill - // in the missing pieces differently. - - for (i = 0; i < numsubsectors; i++) + auto p = segs[i].PartnerSeg; + if (p != nullptr) { - ss = &subsectors[i]; - ss->render_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; + } } } @@ -1501,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; @@ -1525,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_setup.cpp b/src/p_setup.cpp index cf86a452d..e843cc655 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -127,7 +127,6 @@ vertexdata_t* vertexdatas; int numsegs; seg_t* segs; -glsegextra_t* glsegextras; int numsubsectors; subsector_t* subsectors; @@ -933,7 +932,7 @@ 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; @@ -1041,7 +1040,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) { @@ -1054,7 +1052,6 @@ void LoadZNodes(FileReaderBase &data, int glnodes) } else { - glsegextras = new glsegextra_t[numsegs]; P_LoadGLZSegs (data, glnodes); } @@ -3092,14 +3089,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(); @@ -3437,11 +3431,6 @@ void P_FreeLevelData () segs = NULL; } numsegs = 0; - if (glsegextras != NULL) - { - delete[] glsegextras; - glsegextras = NULL; - } if (level.sectors.Size() > 0) { delete[] level.sectors[0].e; @@ -3908,7 +3897,7 @@ void P_SetupLevel (const char *lumpname, int position) // if the different machines' am_textured setting differs. FNodeBuilder builder (leveldata, polyspots, anchors, BuildGLNodes); builder.Extract (nodes, numnodes, - segs, glsegextras, numsegs, + segs, numsegs, subsectors, numsubsectors, level.vertexes); endTime = I_FPSTime (); @@ -4165,12 +4154,6 @@ void P_SetupLevel (const char *lumpname, int position) MapThingsUserData.Clear(); P_BackupMapData(); - - if (glsegextras != NULL) - { - delete[] glsegextras; - glsegextras = NULL; - } } diff --git a/src/p_setup.h b/src/p_setup.h index 38d61c1eb..3d8c021a7 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 9ee543c8a..74b9fe165 100644 --- a/src/p_sight.cpp +++ b/src/p_sight.cpp @@ -117,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; diff --git a/src/r_defs.h b/src/r_defs.h index 6972eab65..86eb7c8c6 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -1418,12 +1418,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; From 472ace1bea2df2b46e32431ac9aaa39ced034c3d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 9 Jan 2017 01:40:14 +0100 Subject: [PATCH 16/17] - removed the needless copying around of the vertexdatas array. The slope code can just use this from the TArray created by the UDMF parser. --- src/p_setup.cpp | 6 ++---- src/p_slopes.cpp | 7 +++---- src/p_udmf.cpp | 8 +------- src/r_state.h | 3 +-- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/p_setup.cpp b/src/p_setup.cpp index e843cc655..ad713fab9 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -122,8 +122,7 @@ inline bool P_LoadBuildMap(BYTE *mapdata, size_t len, FMapThing **things, int *n // MAP related Lookup tables. // Store VERTEXES, LINEDEFS, SIDEDEFS, etc. // -int numvertexdatas; -vertexdata_t* vertexdatas; +TArray vertexdatas; int numsegs; seg_t* segs; @@ -833,7 +832,6 @@ void P_LoadVertexes (MapData * map) // Determine number of vertices: // total lump length / vertex record length. unsigned numvertexes = map->Size(ML_VERTEXES) / sizeof(mapvertex_t); - numvertexdatas = 0; if (numvertexes == 0) { @@ -842,7 +840,7 @@ void P_LoadVertexes (MapData * map) // Allocate memory for buffer. level.vertexes.Alloc(numvertexes); - vertexdatas = NULL; + vertexdatas.Clear(); map->Seek(ML_VERTEXES); diff --git a/src/p_slopes.cpp b/src/p_slopes.cpp index c16e03b3c..c574d189b 100644 --- a/src/p_slopes.cpp +++ b/src/p_slopes.cpp @@ -278,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]; @@ -296,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) { diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp index 0284c0c23..b0c9dbc15 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -394,7 +394,6 @@ class UDMFParser : public UDMFParserBase TArray ParsedSideTextures; TArray ParsedSectors; TArray ParsedVertices; - TArray ParsedVertexDatas; FDynamicColormap *fogMap, *normMap; FMissingTextureTracker &missingTex; @@ -1996,7 +1995,7 @@ public: vertexdata_t vd; ParseVertex(&vt, &vd); ParsedVertices.Push(vt); - ParsedVertexDatas.Push(vd); + vertexdatas.Push(vd); } else { @@ -2014,11 +2013,6 @@ public: level.vertexes.Alloc(ParsedVertices.Size()); memcpy(&level.vertexes[0], &ParsedVertices[0], level.vertexes.Size() * sizeof(vertex_t)); - // Create the real vertex datas - numvertexdatas = ParsedVertexDatas.Size(); - vertexdatas = new vertexdata_t[numvertexdatas]; - memcpy(vertexdatas, &ParsedVertexDatas[0], numvertexdatas * sizeof(*vertexdatas)); - // Create the real sectors level.sectors.Alloc(ParsedSectors.Size()); memcpy(&level.sectors[0], &ParsedSectors[0], level.sectors.Size() * sizeof(sector_t)); diff --git a/src/r_state.h b/src/r_state.h index aa5b46342..7151c0441 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -42,8 +42,7 @@ extern "C" int viewheight; extern TArray sprites; extern DWORD NumStdSprites; -extern int numvertexdatas; -extern vertexdata_t* vertexdatas; +extern TArray vertexdatas; extern int numsegs; extern seg_t* segs; From 8cc52dab5e407a29c4774ed501fb0eef0be2663b Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Sun, 8 Jan 2017 21:32:22 -0600 Subject: [PATCH 17/17] Fix build on GCC/Clang Obtained from: kcat/Csonicgo (IRC) --- src/posix/sdl/i_main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/posix/sdl/i_main.cpp b/src/posix/sdl/i_main.cpp index ca704340d..90b11ef25 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"