Skip to content

Commit

Permalink
Now the members of MasterDir are private
Browse files Browse the repository at this point in the history
  • Loading branch information
ioan-chera committed Nov 4, 2023
1 parent 40a9e0f commit ccd43a9
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 133 deletions.
4 changes: 2 additions & 2 deletions src/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ class Instance

// M_LOADSAVE
Lump_c *Load_LookupAndSeek(const Wad_file *wad, const char *name) const;
void LoadLevel(Wad_file *wad, const SString &level);
void LoadLevelNum(Wad_file *wad, int lev_num);
void LoadLevel(const Wad_file *wad, const SString &level);
void LoadLevelNum(const Wad_file *wad, int lev_num);
bool MissingIWAD_Dialog();
bool M_SaveMap();
void ValidateVertexRefs(LineDef *ld, int num);
Expand Down
4 changes: 2 additions & 2 deletions src/WadData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ void WadData::reloadResources(const LoadingData &loading, const ConfigData &conf
for(const std::shared_ptr<Wad_file> &wad : resourceWads)
newWad.master.MasterDir_Add(wad);

if (newWad.master.edit_wad)
newWad.master.MasterDir_Add(newWad.master.edit_wad);
if (newWad.master.editWad())
newWad.master.MasterDir_Add(newWad.master.editWad());

// finally, load textures and stuff...
newWad.W_LoadPalette();
Expand Down
17 changes: 15 additions & 2 deletions src/WadData.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,26 @@ class MasterDir
{
return dir;
}
public: // TODO: make private

const std::shared_ptr<Wad_file> &gameWad() const
{
return game_wad;
}
const std::shared_ptr<Wad_file> &editWad() const
{
return edit_wad;
}
const std::shared_ptr<Wad_file> &activeWad() const
{
return edit_wad ? edit_wad : game_wad;
}

private:
// the current PWAD, or NULL for none.
// when present it is also at master_dir.back()
std::shared_ptr<Wad_file> edit_wad;
std::shared_ptr<Wad_file> game_wad;

private:
std::vector<std::shared_ptr<Wad_file>> dir; // the IWAD, never NULL, always at master_dir.front()
};

Expand Down
38 changes: 19 additions & 19 deletions src/bsp_level.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ static void SaveXGL3Format(const Instance &inst, node_t *root_node)

static void LoadLevel(const Instance &inst)
{
Lump_c *LEV = inst.wad.master.edit_wad->GetLump(lev_current_start);
Lump_c *LEV = inst.wad.master.editWad()->GetLump(lev_current_start);

lev_current_name = LEV->Name();
lev_overflows = 0;
Expand Down Expand Up @@ -1841,22 +1841,22 @@ static void UpdateGLMarker(const Instance &inst, Lump_c *marker)

static void AddMissingLump(const Instance &inst, const char *name, const char *after)
{
if (inst.wad.master.edit_wad->LevelLookupLump(lev_current_idx, name) >= 0)
if (inst.wad.master.editWad()->LevelLookupLump(lev_current_idx, name) >= 0)
return;

int exist = inst.wad.master.edit_wad->LevelLookupLump(lev_current_idx, after);
int exist = inst.wad.master.editWad()->LevelLookupLump(lev_current_idx, after);

// if this happens, the level structure is very broken
if (exist < 0)
{
Warning(inst, "Missing %s lump -- level structure is broken\n", after);

exist = inst.wad.master.edit_wad->LevelLastLump(lev_current_idx);
exist = inst.wad.master.editWad()->LevelLastLump(lev_current_idx);
}

inst.wad.master.edit_wad->InsertPoint(exist + 1);
inst.wad.master.editWad()->InsertPoint(exist + 1);

inst.wad.master.edit_wad->AddLump(name);
inst.wad.master.editWad()->AddLump(name);
}

static Lump_c &CreateGLMarker(const Instance &inst);
Expand All @@ -1866,7 +1866,7 @@ static build_result_e SaveLevel(node_t *root_node, const Instance &inst)
// Note: root_node may be NULL

// remove any existing GL-Nodes
inst.wad.master.edit_wad->RemoveGLNodes(lev_current_idx);
inst.wad.master.editWad()->RemoveGLNodes(lev_current_idx);

// ensure all necessary level lumps are present
AddMissingLump(inst, "SEGS", "VERTEXES");
Expand Down Expand Up @@ -1952,7 +1952,7 @@ static build_result_e SaveLevel(node_t *root_node, const Instance &inst)
UpdateGLMarker(inst, gl_marker);
}

inst.wad.master.edit_wad->writeToDisk();
inst.wad.master.editWad()->writeToDisk();

if (lev_overflows > 0)
{
Expand All @@ -1969,7 +1969,7 @@ static build_result_e SaveLevel(node_t *root_node, const Instance &inst)
static build_result_e SaveUDMF(const Instance &inst, node_t *root_node)
{
// remove any existing ZNODES lump
inst.wad.master.edit_wad->RemoveZNodes(lev_current_idx);
inst.wad.master.editWad()->RemoveZNodes(lev_current_idx);

if (num_real_lines >= 0)
{
Expand All @@ -1978,7 +1978,7 @@ static build_result_e SaveUDMF(const Instance &inst, node_t *root_node)
SaveXGL3Format(inst, root_node);
}

inst.wad.master.edit_wad->writeToDisk();
inst.wad.master.editWad()->writeToDisk();

if (lev_overflows > 0)
{
Expand Down Expand Up @@ -2100,12 +2100,12 @@ void ZLibFinishLump(void)

static Lump_c * FindLevelLump(const Instance &inst, const char *name)
{
int idx = inst.wad.master.edit_wad->LevelLookupLump(lev_current_idx, name);
int idx = inst.wad.master.editWad()->LevelLookupLump(lev_current_idx, name);

if (idx < 0)
return NULL;

return inst.wad.master.edit_wad->GetLump(idx);
return inst.wad.master.editWad()->GetLump(idx);
}


Expand All @@ -2116,16 +2116,16 @@ static Lump_c * CreateLevelLump(const Instance &inst, const char *name)

if(!lump)
{
int last_idx = inst.wad.master.edit_wad->LevelLastLump(lev_current_idx);
int last_idx = inst.wad.master.editWad()->LevelLastLump(lev_current_idx);

// in UDMF maps, insert before the ENDMAP lump, otherwise insert
// after the last known lump of the level.
if (inst.loaded.levelFormat != MapFormat::udmf)
last_idx++;

inst.wad.master.edit_wad->InsertPoint(last_idx);
inst.wad.master.editWad()->InsertPoint(last_idx);

lump = &inst.wad.master.edit_wad->AddLump(name);
lump = &inst.wad.master.editWad()->AddLump(name);
}

lump->clearData();
Expand All @@ -2147,11 +2147,11 @@ static Lump_c & CreateGLMarker(const Instance &inst)
name_buf = "GL_LEVEL";
}

int last_idx = inst.wad.master.edit_wad->LevelLastLump(lev_current_idx);
int last_idx = inst.wad.master.editWad()->LevelLastLump(lev_current_idx);

inst.wad.master.edit_wad->InsertPoint(last_idx + 1);
inst.wad.master.editWad()->InsertPoint(last_idx + 1);

return inst.wad.master.edit_wad->AddLump(name_buf);
return inst.wad.master.editWad()->AddLump(name_buf);
}


Expand All @@ -2174,7 +2174,7 @@ static build_result_e BuildLevel(nodebuildinfo_t *info, int lev_idx, const Insta
return BUILD_Cancelled;

lev_current_idx = lev_idx;
lev_current_start = inst.wad.master.edit_wad->LevelHeader(lev_idx);
lev_current_start = inst.wad.master.editWad()->LevelHeader(lev_idx);

LoadLevel(inst);

Expand Down
6 changes: 3 additions & 3 deletions src/m_editlump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,12 @@ void Instance::CMD_EditLump()
return;
}

Wad_file* wad = this->wad.master.edit_wad ? this->wad.master.edit_wad.get() : this->wad.master.game_wad.get();
Wad_file* wad = this->wad.master.activeWad().get();

// create the editor window
UI_TextEditor* editor = new UI_TextEditor(*this);

if (!this->wad.master.edit_wad || this->wad.master.edit_wad->IsReadOnly())
if (!this->wad.master.editWad() || this->wad.master.editWad()->IsReadOnly())
editor->SetReadOnly();

// if lump exists, load the contents
Expand Down Expand Up @@ -473,7 +473,7 @@ void Instance::CMD_EditLump()
if (res != UI_TextEditor::RUN_Save)
break;

SYS_ASSERT(wad == this->wad.master.edit_wad.get());
SYS_ASSERT(wad == this->wad.master.editWad().get());

if (lump_name == EDLUMP_HEADER)
{
Expand Down
8 changes: 4 additions & 4 deletions src/m_files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -568,14 +568,14 @@ fs::path Instance::M_PickDefaultIWAD() const
{
default_game = "doom";
}
else if (wad.master.edit_wad)
else if (wad.master.editWad())
{
int idx = wad.master.edit_wad->LevelFindFirst();
int idx = wad.master.editWad()->LevelFindFirst();

if (idx >= 0)
{
idx = wad.master.edit_wad->LevelHeader(idx);
const SString &name = wad.master.edit_wad->GetLump(idx)->Name();
idx = wad.master.editWad()->LevelHeader(idx);
const SString &name = wad.master.editWad()->GetLump(idx)->Name();

if (toupper(name[0]) == 'E')
default_game = "doom";
Expand Down
Loading

0 comments on commit ccd43a9

Please sign in to comment.