1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-03 19:39:41 +00:00

Report frame number, number of actors and objects to stats

This commit is contained in:
elsid 2020-05-22 00:11:23 +02:00
parent 2618974ad6
commit 69df6098e5
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
14 changed files with 72 additions and 6 deletions

View file

@ -203,12 +203,14 @@ bool OMW::Engine::frame(float frametime)
if (stats->collectStats("resource")) if (stats->collectStats("resource"))
{ {
stats->setAttribute(frameNumber, "FrameNumber", frameNumber);
mResourceSystem->reportStats(frameNumber, stats); mResourceSystem->reportStats(frameNumber, stats);
stats->setAttribute(frameNumber, "WorkQueue", mWorkQueue->getNumItems()); stats->setAttribute(frameNumber, "WorkQueue", mWorkQueue->getNumItems());
stats->setAttribute(frameNumber, "WorkThread", mWorkQueue->getNumActiveThreads()); stats->setAttribute(frameNumber, "WorkThread", mWorkQueue->getNumActiveThreads());
mEnvironment.getWorld()->getNavigator()->reportStats(frameNumber, *stats); mEnvironment.reportStats(frameNumber, *stats);
} }
} }

View file

@ -198,3 +198,9 @@ const MWBase::Environment& MWBase::Environment::get()
assert (sThis); assert (sThis);
return *sThis; return *sThis;
} }
void MWBase::Environment::reportStats(unsigned int frameNumber, osg::Stats& stats) const
{
mMechanicsManager->reportStats(frameNumber, stats);
mWorld->reportStats(frameNumber, stats);
}

View file

@ -1,6 +1,11 @@
#ifndef GAME_BASE_ENVIRONMENT_H #ifndef GAME_BASE_ENVIRONMENT_H
#define GAME_BASE_ENVIRONMENT_H #define GAME_BASE_ENVIRONMENT_H
namespace osg
{
class Stats;
}
namespace MWBase namespace MWBase
{ {
class World; class World;
@ -97,6 +102,8 @@ namespace MWBase
static const Environment& get(); static const Environment& get();
///< Return instance of this class. ///< Return instance of this class.
void reportStats(unsigned int frameNumber, osg::Stats& stats) const;
}; };
} }

View file

@ -11,6 +11,7 @@
namespace osg namespace osg
{ {
class Stats;
class Vec3f; class Vec3f;
} }
@ -269,6 +270,8 @@ namespace MWBase
virtual bool isAttackPreparing(const MWWorld::Ptr& ptr) = 0; virtual bool isAttackPreparing(const MWWorld::Ptr& ptr) = 0;
virtual bool isRunning(const MWWorld::Ptr& ptr) = 0; virtual bool isRunning(const MWWorld::Ptr& ptr) = 0;
virtual bool isSneaking(const MWWorld::Ptr& ptr) = 0; virtual bool isSneaking(const MWWorld::Ptr& ptr) = 0;
virtual void reportStats(unsigned int frameNumber, osg::Stats& stats) const = 0;
}; };
} }

View file

@ -21,6 +21,7 @@ namespace osg
class Matrixf; class Matrixf;
class Quat; class Quat;
class Image; class Image;
class Stats;
} }
namespace Loading namespace Loading
@ -629,6 +630,8 @@ namespace MWBase
virtual bool hasCollisionWithDoor(const MWWorld::ConstPtr& door, const osg::Vec3f& position, const osg::Vec3f& destination) const = 0; virtual bool hasCollisionWithDoor(const MWWorld::ConstPtr& door, const osg::Vec3f& position, const osg::Vec3f& destination) const = 0;
virtual bool isAreaOccupiedByOtherActor(const osg::Vec3f& position, const float radius, const MWWorld::ConstPtr& ignore) const = 0; virtual bool isAreaOccupiedByOtherActor(const osg::Vec3f& position, const float radius, const MWWorld::ConstPtr& ignore) const = 0;
virtual void reportStats(unsigned int frameNumber, osg::Stats& stats) const = 0;
}; };
} }

View file

@ -70,6 +70,7 @@ namespace MWMechanics
PtrActorMap::const_iterator begin() { return mActors.begin(); } PtrActorMap::const_iterator begin() { return mActors.begin(); }
PtrActorMap::const_iterator end() { return mActors.end(); } PtrActorMap::const_iterator end() { return mActors.end(); }
std::size_t size() const { return mActors.size(); }
void notifyDied(const MWWorld::Ptr &actor); void notifyDied(const MWWorld::Ptr &actor);

View file

@ -1,5 +1,7 @@
#include "mechanicsmanagerimp.hpp" #include "mechanicsmanagerimp.hpp"
#include <osg/Stats>
#include <components/misc/rng.hpp> #include <components/misc/rng.hpp>
#include <components/esm/esmwriter.hpp> #include <components/esm/esmwriter.hpp>
@ -1944,4 +1946,9 @@ namespace MWMechanics
mActors.cleanupSummonedCreature(caster.getClass().getCreatureStats(caster), creatureActorId); mActors.cleanupSummonedCreature(caster.getClass().getCreatureStats(caster), creatureActorId);
} }
void MechanicsManager::reportStats(unsigned int frameNumber, osg::Stats& stats) const
{
stats.setAttribute(frameNumber, "Mechanics Actors", mActors.size());
stats.setAttribute(frameNumber, "Mechanics Objects", mObjects.size());
}
} }

View file

@ -240,6 +240,8 @@ namespace MWMechanics
virtual bool isRunning(const MWWorld::Ptr& ptr) override; virtual bool isRunning(const MWWorld::Ptr& ptr) override;
virtual bool isSneaking(const MWWorld::Ptr& ptr) override; virtual bool isSneaking(const MWWorld::Ptr& ptr) override;
virtual void reportStats(unsigned int frameNumber, osg::Stats& stats) const override;
private: private:
bool canCommitCrimeAgainst(const MWWorld::Ptr& victim, const MWWorld::Ptr& attacker); bool canCommitCrimeAgainst(const MWWorld::Ptr& victim, const MWWorld::Ptr& attacker);
bool canReportCrime(const MWWorld::Ptr &actor, const MWWorld::Ptr &victim, std::set<MWWorld::Ptr> &playerFollowers); bool canReportCrime(const MWWorld::Ptr &actor, const MWWorld::Ptr &victim, std::set<MWWorld::Ptr> &playerFollowers);

View file

@ -52,6 +52,11 @@ namespace MWMechanics
void persistAnimationStates(); void persistAnimationStates();
void getObjectsInRange (const osg::Vec3f& position, float radius, std::vector<MWWorld::Ptr>& out); void getObjectsInRange (const osg::Vec3f& position, float radius, std::vector<MWWorld::Ptr>& out);
std::size_t size() const
{
return mObjects.size();
}
}; };
} }

View file

@ -1,6 +1,7 @@
#include "physicssystem.hpp" #include "physicssystem.hpp"
#include <osg/Group> #include <osg/Group>
#include <osg/Stats>
#include <BulletCollision/CollisionShapes/btConeShape.h> #include <BulletCollision/CollisionShapes/btConeShape.h>
#include <BulletCollision/CollisionShapes/btSphereShape.h> #include <BulletCollision/CollisionShapes/btSphereShape.h>
@ -883,4 +884,11 @@ namespace MWPhysics
mCollisionWorld->getBroadphase()->aabbTest(aabbMin, aabbMax, callback); mCollisionWorld->getBroadphase()->aabbTest(aabbMin, aabbMax, callback);
return callback.getResult(); return callback.getResult();
} }
void PhysicsSystem::reportStats(unsigned int frameNumber, osg::Stats& stats) const
{
stats.setAttribute(frameNumber, "Physics Actors", mActors.size());
stats.setAttribute(frameNumber, "Physics Objects", mObjects.size());
stats.setAttribute(frameNumber, "Physics HeightFields", mHeightFields.size());
}
} }

View file

@ -17,6 +17,7 @@ namespace osg
{ {
class Group; class Group;
class Object; class Object;
class Stats;
} }
namespace MWRender namespace MWRender
@ -186,6 +187,8 @@ namespace MWPhysics
bool isAreaOccupiedByOtherActor(const osg::Vec3f& position, const float radius, const MWWorld::ConstPtr& ignore) const; bool isAreaOccupiedByOtherActor(const osg::Vec3f& position, const float radius, const MWWorld::ConstPtr& ignore) const;
void reportStats(unsigned int frameNumber, osg::Stats& stats) const;
private: private:
void updateWater(); void updateWater();

View file

@ -3947,4 +3947,10 @@ namespace MWWorld
{ {
return mPhysics->isAreaOccupiedByOtherActor(position, radius, ignore); return mPhysics->isAreaOccupiedByOtherActor(position, radius, ignore);
} }
void World::reportStats(unsigned int frameNumber, osg::Stats& stats) const
{
mNavigator->reportStats(frameNumber, stats);
mPhysics->reportStats(frameNumber, stats);
}
} }

View file

@ -20,6 +20,7 @@
namespace osg namespace osg
{ {
class Group; class Group;
class Stats;
} }
namespace osgViewer namespace osgViewer
@ -732,6 +733,8 @@ namespace MWWorld
bool hasCollisionWithDoor(const MWWorld::ConstPtr& door, const osg::Vec3f& position, const osg::Vec3f& destination) const override; bool hasCollisionWithDoor(const MWWorld::ConstPtr& door, const osg::Vec3f& position, const osg::Vec3f& destination) const override;
bool isAreaOccupiedByOtherActor(const osg::Vec3f& position, const float radius, const MWWorld::ConstPtr& ignore) const override; bool isAreaOccupiedByOtherActor(const osg::Vec3f& position, const float radius, const MWWorld::ConstPtr& ignore) const override;
void reportStats(unsigned int frameNumber, osg::Stats& stats) const override;
}; };
} }

View file

@ -262,7 +262,6 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
stateset->setAttribute(new osg::PolygonMode(), osg::StateAttribute::PROTECTED); stateset->setAttribute(new osg::PolygonMode(), osg::StateAttribute::PROTECTED);
#endif #endif
osg::Vec3 pos(_statsWidth-420.f, _statsHeight-500.0f,0.0f);
osg::Vec4 backgroundColor(0.0, 0.0, 0.0f, 0.3); osg::Vec4 backgroundColor(0.0, 0.0, 0.0f, 0.3);
osg::Vec4 staticTextColor(1.0, 1.0, 0.0f, 1.0); osg::Vec4 staticTextColor(1.0, 1.0, 0.0f, 1.0);
osg::Vec4 dynamicTextColor(1.0, 1.0, 1.0f, 1.0); osg::Vec4 dynamicTextColor(1.0, 1.0, 1.0f, 1.0);
@ -277,6 +276,8 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
_switch->addChild(group, false); _switch->addChild(group, false);
static const std::vector<std::string> statNames({ static const std::vector<std::string> statNames({
"FrameNumber",
"",
"Compiling", "Compiling",
"WorkQueue", "WorkQueue",
"WorkThread", "WorkThread",
@ -302,16 +303,25 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
"NavMesh CacheSize", "NavMesh CacheSize",
"NavMesh UsedTiles", "NavMesh UsedTiles",
"NavMesh CachedTiles", "NavMesh CachedTiles",
"",
"Mechanics Actors",
"Mechanics Objects",
"",
"Physics Actors",
"Physics Objects",
"Physics HeightFields",
}); });
static const auto longest = std::max_element(statNames.begin(), statNames.end(), static const auto longest = std::max_element(statNames.begin(), statNames.end(),
[] (const std::string& lhs, const std::string& rhs) { return lhs.size() < rhs.size(); }); [] (const std::string& lhs, const std::string& rhs) { return lhs.size() < rhs.size(); });
const int numLines = statNames.size();
const float statNamesWidth = 13 * _characterSize + 2 * backgroundMargin; const float statNamesWidth = 13 * _characterSize + 2 * backgroundMargin;
const float statTextWidth = 7 * _characterSize + 2 * backgroundMargin;
const float statHeight = statNames.size() * _characterSize + 2 * backgroundMargin;
osg::Vec3 pos(_statsWidth - statNamesWidth - backgroundSpacing - statTextWidth, statHeight, 0.0f);
group->addChild(createBackgroundRectangle(pos + osg::Vec3(-backgroundMargin, _characterSize + backgroundMargin, 0), group->addChild(createBackgroundRectangle(pos + osg::Vec3(-backgroundMargin, _characterSize + backgroundMargin, 0),
statNamesWidth, statNamesWidth,
numLines * _characterSize + 2 * backgroundMargin, statHeight,
backgroundColor)); backgroundColor));
osg::ref_ptr<osgText::Text> staticText = new osgText::Text; osg::ref_ptr<osgText::Text> staticText = new osgText::Text;
@ -335,8 +345,8 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
pos.x() += statNamesWidth + backgroundSpacing; pos.x() += statNamesWidth + backgroundSpacing;
group->addChild(createBackgroundRectangle(pos + osg::Vec3(-backgroundMargin, _characterSize + backgroundMargin, 0), group->addChild(createBackgroundRectangle(pos + osg::Vec3(-backgroundMargin, _characterSize + backgroundMargin, 0),
7 * _characterSize + 2 * backgroundMargin, statTextWidth,
numLines * _characterSize + 2 * backgroundMargin, statHeight,
backgroundColor)); backgroundColor));
osg::ref_ptr<osgText::Text> statsText = new osgText::Text; osg::ref_ptr<osgText::Text> statsText = new osgText::Text;