Skip to content

Commit

Permalink
Refactor|Cleanup: libdoomsday is cleared of app-specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jan 12, 2020
1 parent dd505cf commit 8c0bf8d
Show file tree
Hide file tree
Showing 24 changed files with 572 additions and 620 deletions.
31 changes: 5 additions & 26 deletions doomsday/apps/client/include/world/line.h
Expand Up @@ -24,6 +24,7 @@
#include <doomsday/world/line.h>

class Line;
class LineSideSegment;
class Plane;

class LineSide : public world::LineSide
Expand All @@ -44,7 +45,7 @@ class LineSide : public world::LineSide
public:
inline Line & line();
inline const Line &line() const;

/**
* To be called to update the shadow properties for the line side.
*
Expand Down Expand Up @@ -97,40 +98,18 @@ class LineSide : public world::LineSide
class LineSideSegment : public world::LineSideSegment
{
public:
/**
* Returns the distance along the attributed map line at which the
* from vertex vertex occurs.
*
* @see lineSide()
*/
double lineSideOffset() const;

/// @todo Refactor away.
void setLineSideOffset(double newOffset);

/**
* Returns the accurate length of the segment, from the 'from'
* vertex to the 'to' vertex in map coordinate space units.
*/
double length() const;

/// @todo Refactor away.
void setLength(double newLength);

/**
* Returns @c true iff the segment is marked as "front facing".
*/
bool isFrontFacing() const;
bool isFrontFacing() const { return _frontFacing; }

/**
* Mark the current segment as "front facing".
*/
void setFrontFacing(bool yes = true);
void setFrontFacing(bool yes = true) { _frontFacing = yes; }

private:
double _length = 0; // Accurate length of the segment.
double _lineSideOffset = 0; // Distance along the attributed map line at which the half-edge vertex occurs.
bool _frontFacing = false;
bool _frontFacing = false;
};

class Line : public world::Line
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/clientapp.cpp
Expand Up @@ -1099,9 +1099,9 @@ void ClientApp::reset()
DoomsdayApp::reset();

Rend_ResetLookups();
for (int i = 0; i < ClientApp::players().count(); ++i)
for (int i = 0; i < players().count(); ++i)
{
ClientApp::player(i).viewCompositor().glDeinit();
player(i).viewCompositor().glDeinit();
}
if (App_GameLoaded())
{
Expand Down
6 changes: 6 additions & 0 deletions doomsday/apps/client/src/world/base/clientserverworld.cpp
Expand Up @@ -277,13 +277,19 @@ DE_PIMPL(ClientServerWorld)
// Callbacks.
world::DmuArgs::setPointerToIndexFunc(P_ToIndex);
#ifdef __CLIENT__
world::Factory::setMobjThinkerDataConstructor([](const Id &id) -> MobjThinkerData * {
return new ClientMobjThinkerData(id);
});
world::Factory::setMaterialConstructor([](world::MaterialManifest &m) -> world::Material * {
return new ClientMaterial(m);
});
world::Factory::setSubsectorConstructor([](const List<world::ConvexSubspace *> &sl) -> world::Subsector * {
return new Subsector(sl);
});
#else
world::Factory::setMobjThinkerDataConstructor([](const Id &id) -> MobjThinkerData * {
return new MobjThinkerData(id);
});
world::Factory::setMaterialConstructor([] (world::MaterialManifest &m) -> world::Material * {
return new world::Material(m);
});
Expand Down
37 changes: 2 additions & 35 deletions doomsday/apps/client/src/world/line.cpp
Expand Up @@ -38,7 +38,8 @@ void LineSide::updateRadioCorner(shadowcorner_t &sc, float openness, Plane *prox
{
// Determine relative height offsets (affects shadow map selection).
sc.pHeight = sc.proximity->heightSmoothed();
sc.pOffset = sc.pHeight - sector().plane(top? world::Sector::Ceiling : world::Sector::Floor).as<Plane>().heightSmoothed();
sc.pOffset = sc.pHeight - sector().plane(top? world::Sector::Ceiling : world::Sector::Floor)
.as<Plane>().heightSmoothed();
}
else
{
Expand Down Expand Up @@ -344,40 +345,6 @@ void LineSide::updateRadioForFrame(int frameNumber)
}
}

//------------------------------------------------------------------------------------------------

double LineSideSegment::lineSideOffset() const
{
return _lineSideOffset;
}

void LineSideSegment::setLineSideOffset(double newOffset)
{
_lineSideOffset = newOffset;
}

double LineSideSegment::length() const
{
return _length;
}

void LineSideSegment::setLength(double newLength)
{
_length = newLength;
}

bool LineSideSegment::isFrontFacing() const
{
return _frontFacing;
}

void LineSideSegment::setFrontFacing(bool yes)
{
_frontFacing = yes;
}

//------------------------------------------------------------------------------------------------

bool Line::isShadowCaster() const
{
if (definesPolyobj()) return false;
Expand Down
8 changes: 8 additions & 0 deletions doomsday/apps/client/src/world/map.cpp
Expand Up @@ -1522,6 +1522,14 @@ bool Map::endEditing()
return false;
}

// Client mobjs use server-assigned IDs so we don't need to assign them locally.
thinkers().setIdAssignmentFunc([this](thinker_t &th){
if (!Cl_IsClientMobj(reinterpret_cast<mobj_t *>(&th)))
{
th.id = thinkers().newMobjId();
}
});

std::map<int, world::Sector *> sectorsByArchiveIndex;
forAllSectors([&sectorsByArchiveIndex](world::Sector &sector) {
sectorsByArchiveIndex[sector.indexInArchive()] = &sector;
Expand Down
9 changes: 9 additions & 0 deletions doomsday/apps/client/src/world/plane.cpp
Expand Up @@ -37,10 +37,19 @@ Plane::Plane(world::Sector &sector, const Vec3f &normal, double height)
: world::Plane(sector, normal, height)
{
surface().audienceForMaterialChange() += this;

audienceForHeightChange() += [this]() {
if (!World::ddMapSetup)
{
// Add ourself to tracked plane list (for movement interpolation).
map().trackedPlanes().insert(this);
}
};
}

Plane::~Plane()
{
// Stop movement tracking of this plane.
map().trackedPlanes().remove(this);
}

Expand Down
17 changes: 16 additions & 1 deletion doomsday/apps/client/src/world/surface.cpp
Expand Up @@ -32,7 +32,22 @@ using namespace de;

Surface::Surface(world::MapElement &owner, float opacity, const Vec3f &color)
: world::Surface(owner, opacity, color)
{}
{
audienceForOriginChange() += [this]() {
if (World::ddMapSetup)
{
// During map setup we'll apply this immediately to the visual origin also.
_originSmoothed = origin();
_originSmoothedDelta = Vec2f();

_oldOrigin[0] = _oldOrigin[1] = origin();
}
else
{
map().scrollingSurfaces().insert(this);
}
};
}

Surface::~Surface()
{
Expand Down
11 changes: 6 additions & 5 deletions doomsday/libs/doomsday/include/doomsday/mesh/face.h
Expand Up @@ -33,17 +33,15 @@ namespace mesh {
*/
class LIBDOOMSDAY_PUBLIC Face : public MeshElement
{
public: /// @todo make private:
/// Total number of half-edge's in the face geometry.
int _hedgeCount;

public:
explicit Face(Mesh &mesh);

/**
* Total number of half-edges in the face geometry.
*/
int hedgeCount() const;

void incrementHedgeCount() { _hedgeCount++; }

/**
* Returns a pointer to the first half-edge in the face geometry (note that
Expand Down Expand Up @@ -98,7 +96,10 @@ class LIBDOOMSDAY_PUBLIC Face : public MeshElement
de::String description() const;

private:
DE_PRIVATE(d)
HEdge * _hedge = nullptr; // First half-edge in the face geometry.
AABoxd _bounds; // Vertex bounding box.
de::Vec2d _center; // Center of vertices.
int _hedgeCount = 0; // Total number of half-edge's in the face geometry.
};

} // namespace mesh
10 changes: 6 additions & 4 deletions doomsday/libs/doomsday/include/doomsday/mesh/hedge.h
Expand Up @@ -176,11 +176,13 @@ class LIBDOOMSDAY_PUBLIC HEdge : public MeshElement
world::Subsector *subsector() const;

private:
DE_PRIVATE(d)

// Heavily used; visible for inline access:
world::Vertex *_vertex;
Face *_face; ///< Face geometry to which the half-edge is attributed (if any).
Face * _face = nullptr; // Face geometry to which the half-edge is attributed (if any).
HEdge *_twin = nullptr; // Linked @em twin half-edge (that on the other side of "this" half-edge).
HEdge *_neighbors[2]{}; // Previous (CounterClockwise) and next half-edge (clockwise) around the @em
// face.
mutable bool _subsectorMissing = false;
mutable world::Subsector *_subsector = nullptr;
};

} // namespace mesh
14 changes: 8 additions & 6 deletions doomsday/libs/doomsday/include/doomsday/mesh/mesh.h
Expand Up @@ -37,8 +37,8 @@ class Face;
class HEdge;

/**
* Two dimensioned mesh geometry data structure employing the half-edge model (more formally
* known as "Doubly connected edge list" (DECL)).
* Two dimensioned mesh geometry data structure employing the half-edge model, more formally
* known as "Doubly connected edge list" (DCEL).
*
* @see http://en.wikipedia.org/wiki/Doubly_connected_edge_list
*
Expand Down Expand Up @@ -107,12 +107,12 @@ class LIBDOOMSDAY_PUBLIC Mesh
void setMapElement(world::MapElement *newMapElement);

private:
Mesh *_owner = nullptr;
world::MapElement *_mapElement = nullptr; ///< Attributed MapElement (not owned).
Mesh * _owner = nullptr;
world::MapElement *_mapElement = nullptr; ///< Attributed MapElement (not owned).
};

public:
Mesh();
Mesh() = default;
~Mesh();

/**
Expand Down Expand Up @@ -199,7 +199,9 @@ class LIBDOOMSDAY_PUBLIC Mesh
const HEdges &hedges() const;

private:
DE_PRIVATE(d)
Vertices _vertices; // All vertices in the mesh.
HEdges _hedges; // All half-edges in the mesh.
Faces _faces; // All faces in the mesh.
};

typedef Mesh::Element MeshElement;
Expand Down
8 changes: 7 additions & 1 deletion doomsday/libs/doomsday/include/doomsday/world/factory.h
Expand Up @@ -28,13 +28,15 @@
class MobjThinkerData;
struct polyobj_s;

namespace mesh { class Face; }
namespace mesh { class Face; class HEdge; }

namespace world {

class BspLeaf;
class ConvexSubspace;
class Line;
class LineSide;
class LineSideSegment;
class MapElement;
class Material;
class MaterialManifest;
Expand All @@ -53,6 +55,8 @@ class LIBDOOMSDAY_PUBLIC Factory

static void setConvexSubspaceConstructor(const std::function<ConvexSubspace *(mesh::Face &, BspLeaf *)> &);
static void setLineConstructor(const std::function<Line *(Vertex &, Vertex &, int, Sector *, Sector *)> &);
static void setLineSideConstructor(const std::function<LineSide *(Line &, Sector *)> &);
static void setLineSideSegmentConstructor(const std::function<LineSideSegment *(LineSide &, mesh::HEdge &)> &);
static void setMaterialConstructor(const std::function<Material *(MaterialManifest &)> &);
static void setMobjThinkerDataConstructor(const std::function<MobjThinkerData *(const de::Id &)> &);
static void setPlaneConstructor(const std::function<Plane *(Sector &, const de::Vec3f &, double)> &);
Expand All @@ -65,6 +69,8 @@ class LIBDOOMSDAY_PUBLIC Factory
static Material * newMaterial(MaterialManifest &);
static MobjThinkerData * newMobjThinkerData(const de::Id &);
static Line * newLine(Vertex &from, Vertex &to, int flags = 0, Sector *frontSector = nullptr, Sector *backSector = nullptr);
static LineSide * newLineSide(Line &line, Sector *sector);
static LineSideSegment * newLineSideSegment(LineSide &side, mesh::HEdge &hedge);
static Plane * newPlane(Sector &sector, const de::Vec3f &normal = de::Vec3f(0, 0, 1), double height = 0);
static PolyobjData * newPolyobjData();
static Sky * newSky(const defn::Sky *);
Expand Down

0 comments on commit 8c0bf8d

Please sign in to comment.