Torque3D/Engine/source/util/fpsTracker.cpp

99 lines
3.4 KiB
C++
Raw Normal View History

2012-09-19 15:15:01 +00:00
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "util/fpsTracker.h"
#include "console/console.h"
#include "console/engineAPI.h"
2012-09-19 15:15:01 +00:00
FPSTracker gFPS;
FPSTracker::FPSTracker()
{
mUpdateInterval = 0.25f;
reset();
}
void FPSTracker::reset()
{
fpsNext = (F32)Platform::getRealMilliseconds()/1000.0f + mUpdateInterval;
fpsRealLast = 0.0f;
fpsReal = 0.0f;
fpsRealMin = 0.000001f; // Avoid division by zero.
fpsRealMax = 1.0f;
fpsVirtualLast = 0.0f;
fpsVirtual = 0.0f;
fpsFrames = 0;
}
void FPSTracker::update()
{
const F32 alpha = 0.07f;
2012-09-19 15:15:01 +00:00
F32 realSeconds = (F32)Platform::getRealMilliseconds()/1000.0f;
F32 virtualSeconds = (F32)Platform::getVirtualMilliseconds()/1000.0f;
fpsFrames++;
if (fpsFrames > 1)
{
fpsReal = fpsReal*(1.0-alpha) + (realSeconds-fpsRealLast)*alpha;
fpsVirtual = fpsVirtual*(1.0-alpha) + (virtualSeconds-fpsVirtualLast)*alpha;
if( fpsFrames > 10 ) // Wait a few frames before updating these.
{
// Update min/max. This is a bit counter-intuitive, as the comparisons are
// inversed because these are all one-over-x values.
if( fpsReal > fpsRealMin )
fpsRealMin = fpsReal;
if( fpsReal < fpsRealMax )
fpsRealMax = fpsReal;
}
}
fpsRealLast = realSeconds;
fpsVirtualLast = virtualSeconds;
// update variables every few frames
F32 update = fpsRealLast - fpsNext;
if (update > 0.5f)
{
Updated Assimp Added initial behavior for ImageAssets to hold a list of GFX resources of different texture profiles to avoid mem leaks with incorrect-typed usages Added function to ImageAsset to get best-fit asset, allowing for fallbacks if the requested assetID is not found Added function to ShapeAsset to get best-fit asset, allowing for fallbacks if the requested assetID is not found Disabled fields for dynamic and static shadowmap refresh rates Moved noShape model to core/rendering/shapes to place it in a more logical module position Added an include to avoid undefined type compile error and removed unneeded semicolon from zone code Added call to reload probe textures when a reloadTextures call is made Adjusted default directional light shadowmap settings to not be as extreme Added utility function to probe manager to allow any class to request a 'best fit' list of probes that would affect a given location, allowing other classes such as fog or particles to utilize IBL. Also updated probeManager's forward rendering to utilize same function to reduce code duplication. Shifted shape loader code to utilize assimp for loader consistency and testing Changed render bin used for SSAO postfx so it runs at the right time Made Core_Rendering module scan for assets Updated loose file references to a number of assets to follow proper formatting Refactored asset import code to follow a more consistent object heirarchy structure on importing assets, allowing more reliable cross-referencing between inbound items Updated asset import logic for materials/images so that they properly utilize ImageType. Images correctly save out the assigned image type, materials reference the images' type to know what map slot they should be used in. Importer logic also updated to better find-and-add associated images based on type. Cleaned up a bunch of old, outdated code in the asset importer Added initial handling for in-place importing of files without needing to process them through the UI. Added ability to edit module script from RMB context menu if torsion path is set Updated list field code for variable inspector to utilize correct ownerObject field
2020-03-19 14:47:38 +00:00
F32 delta = realSeconds - fpsNext;
Con::setVariable( "fps::frameDelta",avar("%g", delta));
2012-09-19 15:15:01 +00:00
Con::setVariable( "fps::real", avar( "%4.1f", 1.0f / fpsReal ) );
Con::setVariable( "fps::realMin", avar( "%4.1f", 1.0f / fpsRealMin ) );
Con::setVariable( "fps::realMax", avar( "%4.1f", 1.0f / fpsRealMax ) );
Con::setVariable( "fps::virtual", avar( "%4.1f", 1.0f / fpsVirtual ) );
if (update > mUpdateInterval)
fpsNext = fpsRealLast + mUpdateInterval;
else
fpsNext += mUpdateInterval;
}
}
2018-04-17 14:33:56 +00:00
DefineEngineFunction( resetFPSTracker, void, (), , "()"
2012-09-19 15:15:01 +00:00
"@brief Reset FPS stats (fps::)\n\n"
"@ingroup Game")
{
gFPS.reset();
}