Skip to content

Commit

Permalink
Encapsulate reject
Browse files Browse the repository at this point in the history
  • Loading branch information
ioan-chera committed Nov 5, 2023
1 parent c3b2012 commit 2525b8f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
15 changes: 14 additions & 1 deletion src/bsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,18 @@ class LevelData
int Compare(const void *p1, const void *p2) const;
};

struct Reject
{
void Init(const Document &doc);
void Free();
void GroupSectors(const Document &doc);
void ProcessSectors(const Document &doc);

u8_t *rej_matrix = nullptr;
int rej_total_size = 0; // in bytes
std::vector<int> rej_sector_groups;
};

/* ----- create blockmap ------------------------------------ */

void WriteBlockmap(const Instance &inst) const;
Expand All @@ -448,7 +460,7 @@ class LevelData

// REJECT : Generate the reject table
void Reject_WriteLump(const Instance &inst) const;
void PutReject(const Instance &inst) const;
void PutReject(const Instance &inst);

// allocation routines
vertex_t *NewVertex();
Expand Down Expand Up @@ -573,6 +585,7 @@ class LevelData
vertex_t *NewVertexFromSplitSeg(seg_t *seg, double x, double y, const Document &doc);

Block block = {};
Reject rej = {};

SString current_name;
int current_idx = 0;
Expand Down
27 changes: 10 additions & 17 deletions src/bsp_level.cc
Original file line number Diff line number Diff line change
Expand Up @@ -545,17 +545,10 @@ void LevelData::PutBlockmap(const Instance &inst)
// REJECT : Generate the reject table
//------------------------------------------------------------------------


static u8_t *rej_matrix;
static int rej_total_size; // in bytes

static std::vector<int> rej_sector_groups;


//
// Allocate the matrix, init sectors into individual groups.
//
static void Reject_Init(const Document &doc)
void LevelData::Reject::Init(const Document &doc)
{
rej_total_size = (doc.numSectors() * doc.numSectors() + 7) / 8;

Expand All @@ -571,7 +564,7 @@ static void Reject_Init(const Document &doc)
}


static void Reject_Free()
void LevelData::Reject::Free()
{
delete[] rej_matrix;
rej_matrix = NULL;
Expand All @@ -585,7 +578,7 @@ static void Reject_Free()
// Now we scan the linedef list. For each two-sectored line,
// merge the two sector groups into one. That's it!
//
static void Reject_GroupSectors(const Document &doc)
void LevelData::Reject::GroupSectors(const Document &doc)
{
for(const auto &L : doc.linedefs)
{
Expand Down Expand Up @@ -645,7 +638,7 @@ static void Reject_DebugGroups()
#endif


static void Reject_ProcessSectors(const Document &doc)
void LevelData::Reject::ProcessSectors(const Document &doc)
{
for (int view=0 ; view < doc.numSectors() ; view++)
{
Expand All @@ -669,7 +662,7 @@ void LevelData::Reject_WriteLump(const Instance &inst) const
{
Lump_c &lump = CreateLevelLump(inst, "REJECT");

lump.Write(rej_matrix, rej_total_size);
lump.Write(rej.rej_matrix, rej.rej_total_size);
}


Expand All @@ -680,7 +673,7 @@ void LevelData::Reject_WriteLump(const Instance &inst) const
// determining all isolated groups of sectors (islands that are
// surrounded by void space).
//
void LevelData::PutReject(const Instance &inst) const
void LevelData::PutReject(const Instance &inst)
{
if (! cur_info->do_reject || inst.level.numSectors() == 0)
{
Expand All @@ -689,16 +682,16 @@ void LevelData::PutReject(const Instance &inst) const
return;
}

Reject_Init(inst.level);
Reject_GroupSectors(inst.level);
Reject_ProcessSectors(inst.level);
rej.Init(inst.level);
rej.GroupSectors(inst.level);
rej.ProcessSectors(inst.level);

# if DEBUG_REJECT
Reject_DebugGroups();
# endif

Reject_WriteLump(inst);
Reject_Free();
rej.Free();

PrintDetail("Added simple reject lump\n");
}
Expand Down

0 comments on commit 2525b8f

Please sign in to comment.