Skip to content

Commit

Permalink
Debug|World|libcommon: Composing a plain text description of object c…
Browse files Browse the repository at this point in the history
…ross-refs
  • Loading branch information
skyjake committed Jul 27, 2017
1 parent 84c292f commit f260c8e
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 7 deletions.
2 changes: 2 additions & 0 deletions doomsday/apps/client/include/world/map.h
Expand Up @@ -203,6 +203,8 @@ class Map : public world::BaseMap

void deserializeInternalState(de::Reader &from, world::IThinkerMapping const &thinkerMapping) override;

de::String mapObjectsDescription() const;

public: //- Light sources --------------------------------------------------------------

#if 0
Expand Down
38 changes: 32 additions & 6 deletions doomsday/apps/client/src/world/base/map.cpp
Expand Up @@ -454,7 +454,7 @@ DENG2_PIMPL(Map)
if (de::abs(line.direction().x) < bsp::DIST_EPSILON)
return;

if( (line.bounds().maxX < p.testLineCenter.x - bsp::DIST_EPSILON)
if ( (line.bounds().maxX < p.testLineCenter.x - bsp::DIST_EPSILON)
|| (line.bounds().minX > p.testLineCenter.x + bsp::DIST_EPSILON))
return;

Expand Down Expand Up @@ -660,7 +660,7 @@ DENG2_PIMPL(Map)
}
} while ((hedge = &hedge->next()) != subspace.poly().hedge());

if(discontinuities)
if (discontinuities)
{
LOG_MAP_WARNING("Face geometry for BSP leaf [%p] at %s in sector %i "
"is not contiguous (%i gaps/overlaps).\n%s")
Expand Down Expand Up @@ -1569,14 +1569,14 @@ bool Map::hasLightGrid() const

LightGrid &Map::lightGrid()
{
if(bool(d->lightGrid)) return *d->lightGrid;
if (bool(d->lightGrid)) return *d->lightGrid;
/// @throw MissingLightGrid Attempted with no LightGrid initialized.
throw MissingLightGridError("Map::lightGrid", "No light grid is initialized");
}

LightGrid const &Map::lightGrid() const
{
if(bool(d->lightGrid)) return *d->lightGrid;
if (bool(d->lightGrid)) return *d->lightGrid;
/// @throw MissingLightGrid Attempted with no LightGrid initialized.
throw MissingLightGridError("Map::lightGrid", "No light grid is initialized");
}
Expand Down Expand Up @@ -2048,7 +2048,7 @@ void Map::setGravity(coord_t newGravity)

Thinkers &Map::thinkers() const
{
if(bool( d->thinkers )) return *d->thinkers;
if (bool( d->thinkers )) return *d->thinkers;
/// @throw MissingThinkersError The thinker lists are not yet initialized.
throw MissingThinkersError("Map::thinkers", "Thinkers not initialized");
}
Expand Down Expand Up @@ -2434,7 +2434,7 @@ LoopResult Map::forAllSectorsTouchingMobj(mobj_t &mob, std::function<LoopResult
if (ld->back().hasSector())
{
Sector &backSec = ld->back().sector();
if(backSec.validCount() != validCount)
if (backSec.validCount() != validCount)
{
backSec.setValidCount(validCount);
linkStore.append(&backSec);
Expand Down Expand Up @@ -3111,10 +3111,36 @@ void Map::update()

#ifdef __CLIENT__

String Map::mapObjectsDescription() const
{
String str;
QTextStream os(&str);

if (auto *descPtr = gx.GetVariable(DD_OBJECT_STATE_INFO_STR))
{
auto const descFunc = de::function_cast<de::String (*)(mobj_t const *)>(descPtr);

// Internal state of thinkers.
thinkers().forAll(0x3, [&os, &descFunc] (thinker_t *th)
{
if (Thinker_IsMobj(th))
{
os << descFunc(reinterpret_cast<mobj_t const *>(th));
}
return LoopContinue;
});
}

return str;
}

void Map::serializeInternalState(Writer &to) const
{
BaseMap::serializeInternalState(to);

//qDebug() << "DD_OBJECT_STATE_INFO_STR:";
//qDebug() << mapObjectsDescription().toLatin1().constData();

// Internal state of thinkers.
thinkers().forAll(0x3, [&to] (thinker_t *th)
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/libdoomsday/include/doomsday/gameapi.h
Expand Up @@ -91,7 +91,7 @@ enum {
DD_UNUSED4, // DD_TRACE_ADDRESS
DD_SPRITE_REPLACEMENT, ///< Sprite <-> model replacement.
DD_ACTION_LINK, ///< State action routine addresses.
DD_UNUSED10, // DD_MAP_NAME
DD_OBJECT_STATE_INFO_STR, ///< Information about mobjs in plain text Info format.
DD_UNUSED11, // DD_MAP_AUTHOR
DD_MAP_MUSIC,
DD_MAP_MIN_X,
Expand Down
20 changes: 20 additions & 0 deletions doomsday/apps/plugins/common/include/mobj.h
Expand Up @@ -25,9 +25,21 @@
#include "common.h"

#ifdef __cplusplus

#include <de/String>

extern "C" {
#endif

/**
* Returns the private internal ID of a map object. This is a unique 32-bit number
* that the engine chooses internally for identifying the object.
*
* @param mob Map object.
* @return Private ID.
*/
uint32_t Mobj_PrivateID(mobj_t const *mob);

/**
* Determines the current friction affecting @a mo, given the sector it is in and
* whether it is on the floor.
Expand Down Expand Up @@ -218,6 +230,14 @@ void Mobj_InflictDamage(mobj_t *mob, mobj_t const *inflictor, int damage);

#ifdef __cplusplus
} // extern "C"

/**
* Describe the object in plain text Info syntax.
* @param mob Map object.
* @return Description text.
*/
de::String Mobj_AsTextWithInfoSyntax(mobj_t const *mob);

#endif

#endif // LIBCOMMON_MOBJ_H
43 changes: 43 additions & 0 deletions doomsday/apps/plugins/common/src/world/mobj.cpp
Expand Up @@ -26,7 +26,10 @@

#include <cmath>
#include <doomsday/world/mobjthinkerdata.h>
#include <de/String>
#include <de/mathutil.h>
#include <QTextStream>

#include "dmu_lib.h"
#include "mapstatereader.h"
#include "mapstatewriter.h"
Expand Down Expand Up @@ -230,6 +233,19 @@ dd_bool Mobj_IsPlayerClMobj(mobj_t *mo)
return false;
}

uint32_t Mobj_PrivateID(mobj_t const *mob)
{
if (!mob)
{
return 0;
}
if (auto const *td = THINKER_DATA_MAYBE(mob->thinker, ThinkerData))
{
return td->id();
}
return 0;
}

dd_bool Mobj_IsPlayer(mobj_t const *mob)
{
if(!mob) return false;
Expand Down Expand Up @@ -1027,3 +1043,30 @@ void Mobj_InflictDamage(mobj_t *mob, mobj_t const *inflictor, int damage)
// Notify the engine.
THINKER_DATA(mob->thinker, MobjThinkerData).damageReceived(damage, inflictor);
}

de::String Mobj_AsTextWithInfoSyntax(mobj_t const *mob)
{
// Note: Used for debugging purposes.

using de::String;

QString str;
QTextStream os(&str);
os.setCodec("latin1");

os << "Mobj 0x" << String::number(Mobj_PrivateID(mob), 16) << " {\n";

os << " target = 0x" << String::number(Mobj_PrivateID(mob->target), 16) << "\n"
<< " onMobj = 0x" << String::number(Mobj_PrivateID(mob->onMobj), 16) << "\n";

#if defined (__JHEXEN__)
{
os << " tracer = 0x" << String::number(Mobj_PrivateID(mob->tracer), 16) << "\n"
<< " lastEnemy = 0x" << String::number(Mobj_PrivateID(mob->lastEnemy), 16) << "\n";
}
#endif

os << "}\n";

return str;
}
3 changes: 3 additions & 0 deletions doomsday/apps/plugins/hexen/src/h2_main.cpp
Expand Up @@ -119,6 +119,9 @@ void *X_GetVariable(int id)
case DD_TM_CEILING_Z:
return (void*) &tmCeilingZ;

case DD_OBJECT_STATE_INFO_STR:
return reinterpret_cast<void *>(Mobj_AsTextWithInfoSyntax);

default:
break;
}
Expand Down

0 comments on commit f260c8e

Please sign in to comment.