— New utilities for better abstraction added.

This commit is contained in:
Christoph Oelckers 2021-11-21 08:42:36 +01:00
parent d115d90961
commit 323b5441d5
3 changed files with 63 additions and 35 deletions

View file

@ -194,39 +194,6 @@ inline bool validWallIndex(int wallnum)
return wallnum >= 0 && wallnum < numwalls;
}
inline sectortype* spritetype::sector() const
{
#ifdef _DEBUG
return !validSectorIndex(sectnum) ? nullptr : &::sector[sectnum];
#else
return &::sector[sectnum];
#endif
}
inline bool spritetype::insector() const
{
return validSectorIndex(sectnum);
}
inline sectortype* walltype::nextSector() const
{
return &::sector[nextsector];
}
inline walltype* walltype::nextWall() const
{
return &::wall[nextwall];
}
inline walltype* walltype::point2Wall() const
{
return &::wall[point2];
}
inline walltype* sectortype::firstWall() const
{
return &wall[wallptr];
}
EXTERN int32_t randomseed;
@ -745,12 +712,42 @@ inline bool testgotpic(int32_t tilenume, bool reset = false)
return res;
}
inline sectortype* spritetype::sector() const
{
return !validSectorIndex(sectnum)? nullptr : &::sector[sectnum];
}
inline bool spritetype::insector() const
{
return validSectorIndex(sectnum);
}
inline sectortype* walltype::nextSector() const
{
return !validSectorIndex(nextsector)? nullptr : &::sector[nextsector];
}
inline walltype* walltype::nextWall() const
{
return !validWallIndex(nextwall)? nullptr : &::wall[nextwall];
}
inline sectortype* walltype::sectorp() const
{
return &::sector[sector]; // cannot be -1 in a proper map.
}
inline walltype* walltype::point2Wall() const
{
return &::wall[point2]; // cannot be -1 in a proper map.
}
inline walltype* sectortype::firstWall() const
{
return &wall[wallptr]; // cannot be -1 in a proper map
}
#include "iterators.h"

View file

@ -208,6 +208,7 @@ struct walltype
void addxpan(float add) { xpan_ = fmodf(xpan_ + add + 512, 256); } // +512 is for handling negative offsets
void addypan(float add) { ypan_ = fmodf(ypan_ + add + 512, 256); } // +512 is for handling negative offsets
sectortype* nextSector() const;
sectortype* sectorp() const;
walltype* nextWall() const;
walltype* point2Wall() const;
vec2_t delta() const { return point2Wall()->pos - pos; }

View file

@ -82,6 +82,36 @@ public:
}
};
class BFSSectorSearch : public BFSSearch
{
public:
BFSSectorSearch(sectortype* startnode) : BFSSearch(numsectors, sector.IndexOf(startnode))
{
}
bool Check(sectortype* index) const
{
return BFSSearch::Check(sector.IndexOf(index));
}
void Set(sectortype* index)
{
BFSSearch::Set(sector.IndexOf(index));
}
sectortype* GetNext()
{
unsigned ret = BFSSearch::GetNext();
return ret == EOL? nullptr : &sector[ret];
}
void Add(sectortype* elem)
{
BFSSearch::Add(sector.IndexOf(elem));
}
};
extern int cameradist, cameraclock;
void loaddefinitionsfile(const char* fn, bool cumulative = false, bool maingrp = false);