Skip to content

Commit

Permalink
Both LineDef and SideDef can now have lm_sampledist_... properties
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRaveYard authored and dpjudas committed Aug 1, 2023
1 parent 0655ffd commit 280063a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 23 deletions.
46 changes: 37 additions & 9 deletions src/level/doomdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,33 @@ struct MapSideDef
uint16_t sector;
};

enum class WallPart
{
TOP,
MIDDLE,
BOTTOM,
};

struct SurfaceSampleProps
{
int sampleDistance = 0;
};

struct SideDefSampleProps
{
SurfaceSampleProps line;
SurfaceSampleProps lineSegments[3];

inline int GetSampleDistance(WallPart part) const
{
auto sampleDistance = lineSegments[static_cast<int>(part)].sampleDistance;
return sampleDistance ? sampleDistance : line.sampleDistance;
}

inline void SetSampleDistance(WallPart part, int dist) { lineSegments[int(part)].sampleDistance = dist; }
inline void SetGeneralSampleDistance(int dist) { line.sampleDistance = dist; }
};

struct IntLineDef;

struct IntSideDef
Expand All @@ -61,17 +88,10 @@ struct IntSideDef

IntLineDef *line;

int sampleDistance;
int sampleDistanceTop;
int sampleDistanceMiddle;
int sampleDistanceBottom;

inline int GetSampleDistanceTop() const { return sampleDistanceTop ? sampleDistanceTop : sampleDistance; }
inline int GetSampleDistanceMiddle() const { return sampleDistanceMiddle ? sampleDistanceMiddle : sampleDistance; }
inline int GetSampleDistanceBottom() const { return sampleDistanceBottom ? sampleDistanceBottom : sampleDistance; }

SideDefSampleProps sampling;
TArray<UDMFKey> props;

inline int GetSampleDistance(WallPart part) const;
inline int GetSectorGroup() const;
};

Expand Down Expand Up @@ -111,6 +131,8 @@ struct IntLineDef

IntSector *frontsector = nullptr, *backsector = nullptr;

SideDefSampleProps sampling;

inline int GetSectorGroup() const;
};

Expand Down Expand Up @@ -185,6 +207,12 @@ inline int IntLineDef::GetSectorGroup() const
return frontsector ? frontsector->group : (backsector ? backsector->group : 0);
}

inline int IntSideDef::GetSampleDistance(WallPart part) const
{
auto sampleDistance = sampling.GetSampleDistance(part);
return sampleDistance ? sampleDistance : line->sampling.GetSampleDistance(part);
}

inline int IntSideDef::GetSectorGroup() const
{
return line ? line->GetSectorGroup() : 0;
Expand Down
37 changes: 29 additions & 8 deletions src/level/level_udmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ void FProcessor::ParseThing(IntThing *th)

void FProcessor::ParseLinedef(IntLineDef *ld)
{
ld->sampling.SetGeneralSampleDistance(0);
ld->sampling.SetSampleDistance(WallPart::TOP, 0);
ld->sampling.SetSampleDistance(WallPart::MIDDLE, 0);
ld->sampling.SetSampleDistance(WallPart::BOTTOM, 0);

std::vector<int> moreids;
SC_MustGetStringName("{");
while (!SC_CheckString("}"))
Expand Down Expand Up @@ -320,6 +325,22 @@ void FProcessor::ParseLinedef(IntLineDef *ld)
ld->ids.Clear();
if (id != -1) ld->ids.Push(id);
}
else if (stricmp(key, "lm_sampledist_line") == 0)
{
ld->sampling.SetGeneralSampleDistance(CheckInt(key));
}
else if (stricmp(key, "lm_sampledist_top") == 0)
{
ld->sampling.SetSampleDistance(WallPart::TOP, CheckInt(key));
}
else if (stricmp(key, "lm_sampledist_mid") == 0)
{
ld->sampling.SetSampleDistance(WallPart::MIDDLE, CheckInt(key));
}
else if (stricmp(key, "lm_sampledist_bot") == 0)
{
ld->sampling.SetSampleDistance(WallPart::BOTTOM, CheckInt(key));
}

if (!stricmp(key, "sidefront"))
{
Expand Down Expand Up @@ -359,10 +380,10 @@ void FProcessor::ParseSidedef(IntSideDef *sd)
sd->midtexture[1] = 0;
sd->bottomtexture[0] = '-';
sd->bottomtexture[1] = 0;
sd->sampleDistance = 0;
sd->sampleDistanceTop = 0;
sd->sampleDistanceMiddle = 0;
sd->sampleDistanceBottom = 0;
sd->sampling.SetGeneralSampleDistance(0);
sd->sampling.SetSampleDistance(WallPart::TOP, 0);
sd->sampling.SetSampleDistance(WallPart::MIDDLE, 0);
sd->sampling.SetSampleDistance(WallPart::BOTTOM, 0);
while (!SC_CheckString("}"))
{
const char *value;
Expand Down Expand Up @@ -396,19 +417,19 @@ void FProcessor::ParseSidedef(IntSideDef *sd)
}
else if (stricmp(key, "lm_sampledist_line") == 0)
{
sd->sampleDistance = CheckInt(key);
sd->sampling.SetGeneralSampleDistance(CheckInt(key));
}
else if (stricmp(key, "lm_sampledist_top") == 0)
{
sd->sampleDistanceTop = CheckInt(key);
sd->sampling.SetSampleDistance(WallPart::TOP, CheckInt(key));
}
else if (stricmp(key, "lm_sampledist_mid") == 0)
{
sd->sampleDistanceMiddle = CheckInt(key);
sd->sampling.SetSampleDistance(WallPart::MIDDLE, CheckInt(key));
}
else if (stricmp(key, "lm_sampledist_bot") == 0)
{
sd->sampleDistanceBottom = CheckInt(key);
sd->sampling.SetSampleDistance(WallPart::BOTTOM, CheckInt(key));
}

// now store the key in its unprocessed form
Expand Down
18 changes: 12 additions & 6 deletions src/lightmap/levelmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,12 @@ int LevelMesh::CreatePlanePortal(FLevel& doomMap, const IntLineDef& srcLine, con
return it->second;
}

int LevelMesh::GetSampleDistance(const IntSideDef& sidedef, WallPart part) const
{
auto sampleDistance = sidedef.GetSampleDistance(part);
return sampleDistance ? sampleDistance : defaultSamples;
}

void LevelMesh::CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
{
IntSector *front;
Expand Down Expand Up @@ -744,7 +750,7 @@ void LevelMesh::CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
surf->type = ST_MIDDLESIDE;
surf->typeIndex = typeIndex;
surf->controlSector = nullptr;
surf->sampleDimension = (surf->sampleDimension = side->GetSampleDistanceMiddle()) ? surf->sampleDimension : defaultSamples;
surf->sampleDimension = GetSampleDistance(*side, WallPart::MIDDLE);

float texZ = surf->verts[0].z;

Expand Down Expand Up @@ -796,7 +802,7 @@ void LevelMesh::CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
surf->type = ST_MIDDLESIDE;
surf->typeIndex = typeIndex;
surf->controlSector = nullptr;
surf->sampleDimension = (surf->sampleDimension = side->GetSampleDistanceMiddle()) ? surf->sampleDimension : defaultSamples;
surf->sampleDimension = GetSampleDistance(*side, WallPart::MIDDLE);

float texZ = surf->verts[0].z;

Expand Down Expand Up @@ -843,7 +849,7 @@ void LevelMesh::CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
surf->type = ST_MIDDLESIDE;
surf->typeIndex = typeIndex;
surf->controlSector = xfloor;
surf->sampleDimension = (surf->sampleDimension = otherSide->GetSampleDistanceMiddle()) ? surf->sampleDimension : defaultSamples;
surf->sampleDimension = GetSampleDistance(*side, WallPart::MIDDLE);
surf->verts.resize(4);
surf->verts[0].x = surf->verts[2].x = v2.x;
surf->verts[0].y = surf->verts[2].y = v2.y;
Expand Down Expand Up @@ -918,7 +924,7 @@ void LevelMesh::CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
surf->typeIndex = typeIndex;
surf->bSky = bSky;
surf->controlSector = nullptr;
surf->sampleDimension = (surf->sampleDimension = side->GetSampleDistanceBottom()) ? surf->sampleDimension : defaultSamples;
surf->sampleDimension = GetSampleDistance(*side, WallPart::BOTTOM);

float texZ = surf->verts[0].z;

Expand Down Expand Up @@ -976,7 +982,7 @@ void LevelMesh::CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
surf->typeIndex = typeIndex;
surf->bSky = bSky;
surf->controlSector = nullptr;
surf->sampleDimension = (surf->sampleDimension = side->GetSampleDistanceTop()) ? surf->sampleDimension : defaultSamples;
surf->sampleDimension = GetSampleDistance(*side, WallPart::TOP);

float texZ = surf->verts[0].z;

Expand Down Expand Up @@ -1022,7 +1028,7 @@ void LevelMesh::CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
surf->type = ST_MIDDLESIDE;
surf->typeIndex = typeIndex;
surf->controlSector = nullptr;
surf->sampleDimension = (surf->sampleDimension = side->GetSampleDistanceMiddle()) ? surf->sampleDimension : defaultSamples;
surf->sampleDimension = GetSampleDistance(*side, WallPart::MIDDLE);

float texZ = surf->verts[0].z;

Expand Down
4 changes: 4 additions & 0 deletions src/lightmap/levelmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ struct FLevel;
struct ThingLight;
class FWadWriter;

enum class WallPart;

enum SurfaceType
{
ST_UNKNOWN,
Expand Down Expand Up @@ -186,4 +188,6 @@ class LevelMesh

int CreateLinePortal(FLevel &doomMap, const IntLineDef& srcLine, const IntLineDef& dstLine);
int CreatePlanePortal(FLevel &doomMap, const IntLineDef& srcLine, const IntLineDef& dstLine);

int GetSampleDistance(const IntSideDef& sidedef, WallPart part) const;
};

0 comments on commit 280063a

Please sign in to comment.