diff --git a/src/Document.h b/src/Document.h index 53f1dd7a..53e85997 100644 --- a/src/Document.h +++ b/src/Document.h @@ -32,6 +32,7 @@ class crc32_c; class Instance; +struct BadCount; // // The document associated with a file. All stuff will go here @@ -144,6 +145,15 @@ struct Document void LoadThings_Hexen(int loading_level, const Wad_file *load_wad); void LoadVertices(int loading_level, const Wad_file *load_wad); void LoadSectors(int loading_level, const Wad_file *load_wad); + void LoadSideDefs(int loading_level, const Wad_file *load_wad, const ConfigData &config, BadCount &bad); + + void CreateFallbackVertices(); + void CreateFallbackSideDef(const ConfigData &config); + void CreateFallbackSector(const ConfigData &config); + void ValidateVertexRefs(LineDef &ld, int num, BadCount &bad); + void ValidateSidedefRefs(LineDef &ld, int num, const ConfigData &config, BadCount &bad); + void ValidateSectorRef(SideDef &sd, int num, const ConfigData &config, BadCount &bad); + void ValidateLevel_UDMF(const ConfigData &config, BadCount &bad); void clear(); private: diff --git a/src/Instance.h b/src/Instance.h index 58ed1237..c9448f05 100644 --- a/src/Instance.h +++ b/src/Instance.h @@ -282,9 +282,6 @@ class Instance void LoadLevelNum(const Wad_file *wad, int lev_num); bool MissingIWAD_Dialog(); bool M_SaveMap(); - void ValidateVertexRefs(LineDef *ld, int num, BadCount &bad); - void ValidateSectorRef(SideDef *sd, int num, BadCount &bad); - void ValidateSidedefRefs(LineDef *ld, int num, BadCount &bad); // M_NODES void BuildNodesAfterSave(int lev_idx); @@ -383,8 +380,6 @@ class Instance void DoExecuteCommand(const editor_command_t *cmd); // M_LOADSAVE - void CreateFallbackSector(); - void CreateFallbackSideDef(); void EmptyLump(const char *name) const; void FreshLevel(); void LoadBehavior(int loading_level, const Wad_file *load_wad); @@ -392,7 +387,6 @@ class Instance void LoadLineDefs(int loading_level, const Wad_file *load_wad, BadCount &bad); void LoadLineDefs_Hexen(int loading_level, const Wad_file *load_wad, BadCount &bad); void LoadScripts(int loading_level, const Wad_file *load_wad); - void LoadSideDefs(int loading_level, const Wad_file *load_wad, BadCount &bad); bool M_ExportMap(); void Navigate2D(); @@ -414,9 +408,6 @@ class Instance // M_NODES build_result_e BuildAllNodes(nodebuildinfo_t *info); - // M_UDMF - void ValidateLevel_UDMF(BadCount &bad); - // R_GRID bool Grid_ParseUser(const std::vector &tokens); void Grid_WriteUser(std::ostream &os) const; diff --git a/src/m_loadsave.cc b/src/m_loadsave.cc index 6d4f1878..b0b3ba19 100644 --- a/src/m_loadsave.cc +++ b/src/m_loadsave.cc @@ -454,33 +454,33 @@ void Document::LoadSectors(int loading_level, const Wad_file *load_wad) } -void Instance::CreateFallbackSector() +void Document::CreateFallbackSector(const ConfigData &config) { gLog.printf("Creating a fallback sector.\n"); auto sec = std::make_unique(); - sec->SetDefaults(conf); + sec->SetDefaults(config); - level.sectors.push_back(std::move(sec)); + sectors.push_back(std::move(sec)); } -void Instance::CreateFallbackSideDef() +void Document::CreateFallbackSideDef(const ConfigData &config) { // we need a valid sector too! - if (level.numSectors() == 0) - CreateFallbackSector(); + if (numSectors() == 0) + CreateFallbackSector(config); gLog.printf("Creating a fallback sidedef.\n"); auto sd = std::make_unique(); - sd->SetDefaults(conf, false); + sd->SetDefaults(config, false); - level.sidedefs.push_back(std::move(sd)); + sidedefs.push_back(std::move(sd)); } -static void CreateFallbackVertices(Document &doc) +void Document::CreateFallbackVertices() { gLog.printf("Creating two fallback vertices.\n"); @@ -493,8 +493,8 @@ static void CreateFallbackVertices(Document &doc) v2->raw_x = FFixedPoint(555); v2->raw_y = FFixedPoint(555); - doc.vertices.push_back(std::move(v1)); - doc.vertices.push_back(std::move(v2)); + vertices.push_back(std::move(v1)); + vertices.push_back(std::move(v2)); } struct BadCount @@ -504,60 +504,60 @@ struct BadCount int sidedef_refs; }; -void Instance::ValidateSidedefRefs(LineDef * ld, int num, BadCount &bad) +void Document::ValidateSidedefRefs(LineDef & ld, int num, const ConfigData &config, BadCount &bad) { - if (ld->right >= level.numSidedefs() || ld->left >= level.numSidedefs()) + if (ld.right >= numSidedefs() || ld.left >= numSidedefs()) { gLog.printf("WARNING: linedef #%d has invalid sidedefs (%d / %d)\n", - num, ld->right, ld->left); + num, ld.right, ld.left); bad.sidedef_refs++; // ensure we have a usable sidedef - if (level.numSidedefs() == 0) - CreateFallbackSideDef(); + if (numSidedefs() == 0) + CreateFallbackSideDef(config); - if (ld->right >= level.numSidedefs()) - ld->right = 0; + if (ld.right >= numSidedefs()) + ld.right = 0; - if (ld->left >= level.numSidedefs()) - ld->left = 0; + if (ld.left >= numSidedefs()) + ld.left = 0; } } -void Instance::ValidateVertexRefs(LineDef *ld, int num, BadCount &bad) +void Document::ValidateVertexRefs(LineDef &ld, int num, BadCount &bad) { - if (ld->start >= level.numVertices() || ld->end >= level.numVertices() || - ld->start == ld->end) + if (ld.start >= numVertices() || ld.end >= numVertices() || + ld.start == ld.end) { gLog.printf("WARNING: linedef #%d has invalid vertices (%d -> %d)\n", - num, ld->start, ld->end); + num, ld.start, ld.end); bad.linedef_count++; // ensure we have a valid vertex - if (level.numVertices() < 2) - CreateFallbackVertices(level); + if (numVertices() < 2) + CreateFallbackVertices(); - ld->start = 0; - ld->end = level.numVertices() - 1; + ld.start = 0; + ld.end = numVertices() - 1; } } -void Instance::ValidateSectorRef(SideDef *sd, int num, BadCount &bad) +void Document::ValidateSectorRef(SideDef &sd, int num, const ConfigData &config, BadCount &bad) { - if (sd->sector >= level.numSectors()) + if (sd.sector >= numSectors()) { gLog.printf("WARNING: sidedef #%d has invalid sector (%d)\n", - num, sd->sector); + num, sd.sector); bad.sector_refs++; // ensure we have a valid sector - if (level.numSectors() == 0) - CreateFallbackSector(); + if (numSectors() == 0) + CreateFallbackSector(config); - sd->sector = 0; + sd.sector = 0; } } @@ -671,7 +671,7 @@ void Document::LoadThings_Hexen(int loading_level, const Wad_file *load_wad) } -void Instance::LoadSideDefs(int loading_level, const Wad_file *load_wad, BadCount &bad) +void Document::LoadSideDefs(int loading_level, const Wad_file *load_wad, const ConfigData &config, BadCount &bad) { const Lump_c *lump = Load_LookupAndSeek(loading_level, load_wad, "SIDEDEFS"); if(!lump) @@ -707,9 +707,9 @@ void Instance::LoadSideDefs(int loading_level, const Wad_file *load_wad, BadCoun sd->sector = LE_U16(raw.sector); - ValidateSectorRef(sd.get(), i, bad); + ValidateSectorRef(*sd, i, config, bad); - level.sidedefs.push_back(std::move(sd)); + sidedefs.push_back(std::move(sd)); } } @@ -753,8 +753,8 @@ void Instance::LoadLineDefs(int loading_level, const Wad_file *load_wad, BadCoun if (ld->right == 0xFFFF) ld->right = -1; if (ld-> left == 0xFFFF) ld-> left = -1; - ValidateVertexRefs(ld.get(), i, bad); - ValidateSidedefRefs(ld.get(), i, bad); + level.ValidateVertexRefs(*ld, i, bad); + level.ValidateSidedefRefs(*ld, i, conf, bad); level.linedefs.push_back(std::move(ld)); } @@ -805,8 +805,8 @@ void Instance::LoadLineDefs_Hexen(int loading_level, const Wad_file *load_wad, B if (ld->right == 0xFFFF) ld->right = -1; if (ld-> left == 0xFFFF) ld-> left = -1; - ValidateVertexRefs(ld.get(), i, bad); - ValidateSidedefRefs(ld.get(), i, bad); + level.ValidateVertexRefs(*ld, i, bad); + level.ValidateSidedefRefs(*ld, i, conf, bad); level.linedefs.push_back(std::move(ld)); } @@ -939,7 +939,7 @@ void Instance::LoadLevelNum(const Wad_file *wad, int lev_num) level.LoadVertices(loading_level, wad); level.LoadSectors(loading_level, wad); - LoadSideDefs(loading_level, wad, bad); + level.LoadSideDefs(loading_level, wad, conf, bad); if (loaded.levelFormat == MapFormat::hexen) { diff --git a/src/m_udmf.cc b/src/m_udmf.cc index 4e47c588..b74ec590 100644 --- a/src/m_udmf.cc +++ b/src/m_udmf.cc @@ -632,19 +632,19 @@ static void UDMF_ParseObject(Document &doc, Udmf_Parser& parser, const Udmf_Toke } -void Instance::ValidateLevel_UDMF(BadCount &bad) +void Document::ValidateLevel_UDMF(const ConfigData &config, BadCount &bad) { - for (int n = 0 ; n < level.numSidedefs() ; n++) + for (int n = 0 ; n < numSidedefs() ; n++) { - ValidateSectorRef(level.sidedefs[n].get(), n, bad); + ValidateSectorRef(*sidedefs[n], n, config, bad); } - for (int n = 0 ; n < level.numLinedefs(); n++) + for (int n = 0 ; n < numLinedefs(); n++) { - auto &L = level.linedefs[n]; + auto &L = linedefs[n]; - ValidateVertexRefs(L.get(), n, bad); - ValidateSidedefRefs(L.get(), n, bad); + ValidateVertexRefs(*L, n, bad); + ValidateSidedefRefs(*L, n, config, bad); } } @@ -693,7 +693,7 @@ void Instance::UDMF_LoadLevel(int loading_level, const Wad_file *load_wad, BadCo parser.SkipToEOLN(); } - ValidateLevel_UDMF(bad); + level.ValidateLevel_UDMF(conf, bad); }