Skip to content

Commit

Permalink
World|Debug: Include subsector info in Sector descriptions (inspectse…
Browse files Browse the repository at this point in the history
…ctor cmd)
  • Loading branch information
danij-deng committed Aug 7, 2016
1 parent 7efdd52 commit d03490d
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 24 deletions.
14 changes: 12 additions & 2 deletions doomsday/apps/client/include/client/clientsubsector.h
Expand Up @@ -48,6 +48,11 @@ class ClientSubsector : public Subsector, public de::LightGrid::IBlockLightSourc
*/
ClientSubsector(QList<ConvexSubspace *> const &subspaces);

/**
* Returns a human-friendly, textual description of the subsector.
*/
de::String description() const;

/**
* Returns @c true if @a height (up-axis offset) lies above/below the ceiling/floor
* height of the subsector.
Expand Down Expand Up @@ -135,15 +140,20 @@ class ClientSubsector : public Subsector, public de::LightGrid::IBlockLightSourc
//- Decorations -------------------------------------------------------------------------

/**
* Mark the surface as needing a decoration update.
* Returns @c true if the subsector has one or more decorations.
*/
void markForDecorationUpdate(bool yes = true);
bool hasDecorations() const;

/**
* Perform scheduled decoration work.
*/
void decorate();

/**
* Mark the surface as needing a decoration update.
*/
void markForDecorationUpdate(bool yes = true);

void generateLumobjs();

//- Light grid --------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/client/include/render/decoration.h
Expand Up @@ -53,6 +53,8 @@ class Decoration : public world::MapObject
de::Vector3d const &origin = de::Vector3d());
virtual ~Decoration();

de::String description() const;

/**
* Returns the source of the decoration.
*
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/client/include/render/lightdecoration.h
Expand Up @@ -40,6 +40,8 @@ class LightDecoration : public Decoration, public Lumobj::Source
LightDecoration(MaterialAnimator::Decoration const &source,
de::Vector3d const &origin = de::Vector3d());

de::String description() const;

/**
* To be called to register the commands and variables of this module.
*/
Expand Down
10 changes: 10 additions & 0 deletions doomsday/apps/client/include/world/sector.h
Expand Up @@ -26,6 +26,7 @@
#include <QList>
#include <de/aabox.h>
#include <de/Error>
#include <de/Id>
#include <de/Observers>
#include <de/Vector>
#include <doomsday/world/MapElement>
Expand Down Expand Up @@ -189,6 +190,9 @@ class Sector : public world::MapElement

//- Subsectors --------------------------------------------------------------------------

/// Thrown when the referenced subsector is missing/unknown.
DENG2_ERROR(MissingSubsectorError);

typedef std::function<world::Subsector * (QList<world::ConvexSubspace *> const &)> SubsectorConstructor;

static void setSubsectorConstructor(SubsectorConstructor func);
Expand Down Expand Up @@ -237,6 +241,12 @@ class Sector : public world::MapElement
*/
world::Subsector *addSubsector(QList<world::ConvexSubspace *> const &subspaces);

bool hasSubsector(de::Id id) const;

world::Subsector &findSubsector(de::Id id) const;

world::Subsector *tryFindSubsector(de::Id id) const;

//- Sides -------------------------------------------------------------------------------

/**
Expand Down
11 changes: 11 additions & 0 deletions doomsday/apps/client/include/world/subsector.h
Expand Up @@ -24,6 +24,7 @@
#include <functional>
#include <QList>
#include <de/aabox.h>
#include <de/Id>
#include <de/Observers>
#include <de/Vector>
#include "ConvexSubspace"
Expand Down Expand Up @@ -60,6 +61,16 @@ class Subsector

DENG2_AS_IS_METHODS()

/**
* Returns a humman-friendly, textual description of the subsector.
*/
de::String description() const;

/**
* Returns the automatically generated, unique identifier of the subsector.
*/
de::Id id() const;

/**
* Returns the Sector attributed to the subsector.
*/
Expand Down
37 changes: 37 additions & 0 deletions doomsday/apps/client/src/client/clientsubsector.cpp
Expand Up @@ -1422,6 +1422,34 @@ ClientSubsector::ClientSubsector(QList<ConvexSubspace *> const &subspaces)
sector().audienceForLightColorChange() += d;
}

String ClientSubsector::description() const
{
auto desc = String( _E(l) "%1: " _E(.) _E(i) "Sector %2%3" _E(.)
" " _E(l) "%4: " _E(.) _E(i) "Sector %5%6" _E(.))
.arg(Sector::planeIdAsText(Sector::Floor ).upperFirstChar())
.arg(visFloor ().sector().indexInMap())
.arg(&visFloor () != &sector().floor () ? " (mapped)" : "")
.arg(Sector::planeIdAsText(Sector::Ceiling).upperFirstChar())
.arg(visCeiling().sector().indexInMap())
.arg(&visCeiling() != &sector().ceiling() ? " (mapped)" : "");
if (hasDecorations())
{
desc += String(_E(D) "\nDecorations:" _E(.));
dint decorIndex = 0;
for (Impl::DecoratedSurface &decorSurface : d->decorSurfaces)
for (Decoration *decor : decorSurface.decorations)
{
desc += String("\n[%1]: ").arg(decorIndex) + _E(>) + decor->description() + _E(<);
decorIndex += 1;
}
}

DENG2_DEBUG_ONLY(
desc.prepend(String("[ClientSubsector 0x%1]\n").arg(de::dintptr(this), 0, 16));
)
return Subsector::description() + "\n" + desc;
}

dint ClientSubsector::visPlaneCount() const
{
return sector().planeCount();
Expand Down Expand Up @@ -1782,6 +1810,15 @@ void ClientSubsector::decorate()
d->decorate(visCeiling().surface());
}

bool ClientSubsector::hasDecorations() const
{
for (Impl::DecoratedSurface const &decorSurface : d->decorSurfaces)
{
if (!decorSurface.decorations.isEmpty()) return true;
}
return false;
}

void ClientSubsector::generateLumobjs()
{
world::Map &map = sector().map();
Expand Down
19 changes: 18 additions & 1 deletion doomsday/apps/client/src/render/decoration.cpp
Expand Up @@ -20,7 +20,9 @@
*/

#include "render/decoration.h"
#include "Surface"

#include "world/surface.h"
#include <doomsday/world/MaterialManifest>

using namespace de;

Expand All @@ -40,6 +42,21 @@ Decoration::Decoration(MaterialAnimator::Decoration const &source, Vector3d cons
Decoration::~Decoration()
{}

String Decoration::description() const
{
auto desc = String( _E(l) "Origin: " _E(.)_E(i) "%1" _E(.)
" " _E(l) "Material: " _E(.)_E(i) "%2" _E(.)
" " _E(l) "Surface: " _E(.)_E(i) "%3" _E(.))
.arg(origin().asText())
.arg(source().decor().material().manifest().composeUri().asText())
.arg(String("[0x%1]").arg(de::dintptr(&surface()), 0, 16));

#ifdef DENG2_DEBUG
desc.prepend(String("[Decoration 0x%1]\n").arg(de::dintptr(this), 0, 16));
#endif
return desc;
}

MaterialAnimator::Decoration const &Decoration::source() const
{
DENG2_ASSERT(d->source);
Expand Down
9 changes: 9 additions & 0 deletions doomsday/apps/client/src/render/lightdecoration.cpp
Expand Up @@ -42,6 +42,15 @@ LightDecoration::LightDecoration(MaterialAnimator::Decoration const &source, Vec
, Source()
{}

String LightDecoration::description() const
{
String desc;
#ifdef DENG2_DEBUG
desc.prepend(String("[LightDecoration 0x%1]\n").arg(de::dintptr(this), 0, 16));
#endif
return Decoration::description() + "\n" + desc;
}

dfloat LightDecoration::occlusion(Vector3d const &eye) const
{
// Halo brightness drops as the angle gets too big.
Expand Down
18 changes: 13 additions & 5 deletions doomsday/apps/client/src/world/base/plane.cpp
Expand Up @@ -183,11 +183,19 @@ Plane::Plane(Sector &sector, Vector3f const &normal, ddouble height)

String Plane::description() const
{
return String(_E(D) "%1:\n" _E(.)
_E(l) "Height: " _E(.)_E(i) "%2" _E(.))
.arg(Sector::planeIdAsText(indexInSector()).upperFirstChar())
.arg(height())
+ " " + surface().description();
auto desc = String (_E(l) "Sector: " _E(.)_E(i) "%1" _E(.)
" " _E(l) "Height: " _E(.)_E(i) "%2" _E(.)
" " _E(l) "Height Target: " _E(.)_E(i) "%3" _E(.)
" " _E(l) "Speed: " _E(.)_E(i) "%4" _E(.))
.arg(sector().indexInMap())
.arg(height())
.arg(heightTarget())
.arg(speed());

DENG2_DEBUG_ONLY(
desc.prepend(String(_E(b) "Plane " _E(.) "[0x%1]\n").arg(de::dintptr(this), 0, 16));
)
return desc + "\n" + surface().description();
}

Sector &Plane::sector()
Expand Down
52 changes: 48 additions & 4 deletions doomsday/apps/client/src/world/base/sector.cpp
Expand Up @@ -377,9 +377,34 @@ Subsector *Sector::addSubsector(QList<ConvexSubspace *> const &subspaces)
/// @todo Add/move debug logic for ensuring the set is valid here. -ds
std::unique_ptr<Subsector> subsec(subsectorConstructor(subspaces));
d->subsectors << subsec.get();
LOG_MAP_XVERBOSE("New Subsector %s (sector-%s)") << subsec->id().asText() << indexInMap();
return subsec.release();
}

bool Sector::hasSubsector(de::Id id) const
{
for (Subsector *subsec : d->subsectors)
{
if (subsec->id() == id) return true;
}
return false;
}

Subsector *Sector::tryFindSubsector(de::Id id) const
{
for (Subsector *subsec : d->subsectors)
{
if (subsec->id() == id) return subsec;
}
return nullptr;
}

Subsector &Sector::findSubsector(de::Id id) const
{
if (Subsector *subsec = tryFindSubsector(id)) return *subsec;
throw MissingSubsectorError("Sector::findSubsector", "Unknown subsector \"" + id.asText() + "\"");
}

dint Sector::sideCount() const
{
return d->sides.count();
Expand Down Expand Up @@ -652,11 +677,30 @@ D_CMD(InspectSector)
_E(l) " Light Color: " _E(.)_E(i) "%s")
<< sec->lightLevel()
<< sec->lightColor().asText();
sec->forAllPlanes([] (Plane const &plane)
if (sec->planeCount())
{
LOG_SCR_MSG("") << plane.description();
return LoopContinue;
});
LOG_SCR_MSG(_E(D) "Planes (%i):") << sec->planeCount();
sec->forAllPlanes([] (Plane const &plane)
{
LOG_SCR_MSG("%s: " _E(>))
<< Sector::planeIdAsText(plane.indexInSector()).upperFirstChar()
<< plane.description();
return LoopContinue;
});
}
if (sec->subsectorCount())
{
LOG_SCR_MSG(_E(D) "Subsectors (%i):") << sec->subsectorCount();
dint subsectorIndex = 0;
sec->forAllSubsectors([&subsectorIndex] (Subsector const &subsec)
{
LOG_SCR_MSG("%s: " _E(>))
<< subsectorIndex
<< subsec.description();
subsectorIndex += 1;
return LoopContinue;
});
}

return true;
}
Expand Down
24 changes: 24 additions & 0 deletions doomsday/apps/client/src/world/base/subsector.cpp
Expand Up @@ -20,12 +20,15 @@

#include "world/subsector.h"

#include "world/map.h"
#include "BspLeaf"
#include "ConvexSubspace"
#include "Plane"
#include "Surface"
#include "Face"

#include "dd_main.h" // App_World()

#include <de/aabox.h>
#include <de/vector1.h>

Expand All @@ -37,6 +40,7 @@ DENG2_PIMPL_NOREF(Subsector)
{
QList<ConvexSubspace *> subspaces;
std::unique_ptr<AABoxd> bounds;
Id id;

/**
* Calculate the minimum bounding rectangle containing all the subspace geometries.
Expand Down Expand Up @@ -77,6 +81,26 @@ Subsector::~Subsector()
DENG2_FOR_AUDIENCE(Deletion, i) i->subsectorBeingDeleted(*this);
}

String Subsector::description() const
{
auto desc = String( _E(l) "Id: " _E(.) _E(i) "%1" _E(.)
" " _E(l) "Sector: " _E(.) _E(i) "%2" _E(.)
" " _E(l) "Bounds: " _E(.) _E(i) "%3" _E(.))
.arg(d->id.asText())
.arg(sector().indexInMap())
.arg((Vector2d(bounds().max) - Vector2d(bounds().min)).asText());

DENG2_DEBUG_ONLY(
desc.prepend(String("[Subsector 0x%1]\n").arg(de::dintptr(this), 0, 16));
)
return desc;
}

Id Subsector::id() const
{
return d->id;
}

Sector &Subsector::sector()
{
DENG2_ASSERT(!d->subspaces.isEmpty());
Expand Down
29 changes: 17 additions & 12 deletions doomsday/apps/client/src/world/base/surface.cpp
Expand Up @@ -158,18 +158,23 @@ Surface::Surface(MapElement &owner, dfloat opacity, Vector3f const &color)

String Surface::description() const
{
return String(_E(l) "Material: " _E(.)_E(i) "%1" _E(.)
_E(l) " Material Origin: " _E(.)_E(i) "%2" _E(.)
_E(l) " Normal: " _E(.)_E(i) "%3" _E(.)
_E(l) " Opacity: " _E(.)_E(i) "%4" _E(.)
_E(l) " Blend Mode: " _E(.)_E(i) "%5" _E(.)
_E(l) " Tint Color: " _E(.)_E(i) "%6" _E(.))
.arg(hasMaterial() ? material().manifest().composeUri().asText() : "None")
.arg(origin().asText())
.arg(normal().asText())
.arg(opacity())
.arg(String(R_NameForBlendMode(blendMode())))
.arg(color().asText());
auto desc = String( _E(l) "Material: " _E(.)_E(i) "%1" _E(.)
" " _E(l) "Material Origin: " _E(.)_E(i) "%2" _E(.)
" " _E(l) "Normal: " _E(.)_E(i) "%3" _E(.)
" " _E(l) "Opacity: " _E(.)_E(i) "%4" _E(.)
" " _E(l) "Blend Mode: " _E(.)_E(i) "%5" _E(.)
" " _E(l) "Tint Color: " _E(.)_E(i) "%6" _E(.))
.arg(hasMaterial() ? material().manifest().composeUri().asText() : "None")
.arg(origin().asText())
.arg(normal().asText())
.arg(opacity())
.arg(String(R_NameForBlendMode(blendMode())))
.arg(color().asText());

DENG2_DEBUG_ONLY(
desc.prepend(String("[Surface 0x%1]\n").arg(de::dintptr(this), 0, 16));
)
return desc;
}

Matrix3f const &Surface::tangentMatrix() const
Expand Down

0 comments on commit d03490d

Please sign in to comment.