mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 03:40:20 +02:00
Update scriptengine update rate to match displayPlugin target framerate
This commit is contained in:
parent
a2c5c0f36e
commit
97719cd128
3 changed files with 18 additions and 6 deletions
|
@ -5419,6 +5419,15 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
return !entityServerNode || isPhysicsEnabled();
|
return !entityServerNode || isPhysicsEnabled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
scriptEngine->setGetTargetUpdateRateFunction([this]() {
|
||||||
|
auto displayPlugin = _displayPlugin;
|
||||||
|
if (displayPlugin) {
|
||||||
|
auto targetUpdateRate = displayPlugin->getTargetFrameRate();
|
||||||
|
return targetUpdateRate;
|
||||||
|
}
|
||||||
|
return 60.0f;
|
||||||
|
});
|
||||||
|
|
||||||
// setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so
|
// setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so
|
||||||
// we can use the same ones from the application.
|
// we can use the same ones from the application.
|
||||||
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
|
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
|
||||||
|
|
|
@ -898,14 +898,14 @@ void ScriptEngine::run() {
|
||||||
while (!_isFinished) {
|
while (!_isFinished) {
|
||||||
auto beforeSleep = clock::now();
|
auto beforeSleep = clock::now();
|
||||||
|
|
||||||
// Throttle to SCRIPT_FPS
|
// Throttle to _targetUpdateRate
|
||||||
// We'd like to try to keep the script at a solid SCRIPT_FPS update rate. And so we will
|
// We'd like to try to keep the script at a solid _targetUpdateRate update rate. And so we will
|
||||||
// calculate a sleepUntil to be the time from our start time until the original target
|
// calculate a sleepUntil to be the time from our start time until the original target
|
||||||
// sleepUntil for this frame. This approach will allow us to "catch up" in the event
|
// sleepUntil for this frame. This approach will allow us to "catch up" in the event
|
||||||
// that some of our script udpates/frames take a little bit longer than the target average
|
// that some of our script udpates/frames take a little bit longer than the target average
|
||||||
// to execute.
|
// to execute.
|
||||||
// NOTE: if we go to variable SCRIPT_FPS, then we will need to reconsider this approach
|
// NOTE: if we go to variable SCRIPT_FPS, then we will need to reconsider this approach
|
||||||
const std::chrono::microseconds TARGET_SCRIPT_FRAME_DURATION(USECS_PER_SECOND / SCRIPT_FPS + 1);
|
const std::chrono::microseconds TARGET_SCRIPT_FRAME_DURATION(static_cast<int64_t>(USECS_PER_SECOND / _getTargetUpdateRate()) + 1);
|
||||||
clock::time_point targetSleepUntil(startTime + (thisFrame++ * TARGET_SCRIPT_FRAME_DURATION));
|
clock::time_point targetSleepUntil(startTime + (thisFrame++ * TARGET_SCRIPT_FRAME_DURATION));
|
||||||
|
|
||||||
// However, if our sleepUntil is not at least our average update and timer execution time
|
// However, if our sleepUntil is not at least our average update and timer execution time
|
||||||
|
|
|
@ -41,11 +41,9 @@
|
||||||
#include "ScriptUUID.h"
|
#include "ScriptUUID.h"
|
||||||
#include "Vec3.h"
|
#include "Vec3.h"
|
||||||
|
|
||||||
class QScriptEngineDebugger;
|
|
||||||
|
|
||||||
static const QString NO_SCRIPT("");
|
static const QString NO_SCRIPT("");
|
||||||
|
|
||||||
static const int SCRIPT_FPS = 60;
|
class QScriptEngineDebugger;
|
||||||
|
|
||||||
class CallbackData {
|
class CallbackData {
|
||||||
public:
|
public:
|
||||||
|
@ -56,6 +54,7 @@ public:
|
||||||
|
|
||||||
typedef QList<CallbackData> CallbackList;
|
typedef QList<CallbackData> CallbackList;
|
||||||
typedef QHash<QString, CallbackList> RegisteredEventHandlers;
|
typedef QHash<QString, CallbackList> RegisteredEventHandlers;
|
||||||
|
using GetTargetUpdateRateFunction = std::function<float()>;
|
||||||
|
|
||||||
class EntityScriptDetails {
|
class EntityScriptDetails {
|
||||||
public:
|
public:
|
||||||
|
@ -201,6 +200,8 @@ public:
|
||||||
|
|
||||||
bool getEntityScriptDetails(const EntityItemID& entityID, EntityScriptDetails &details) const;
|
bool getEntityScriptDetails(const EntityItemID& entityID, EntityScriptDetails &details) const;
|
||||||
|
|
||||||
|
void setGetTargetUpdateRateFunction(GetTargetUpdateRateFunction function) { _getTargetUpdateRate = function; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void callAnimationStateHandler(QScriptValue callback, AnimVariantMap parameters, QStringList names, bool useNames, AnimVariantResultHandler resultHandler);
|
void callAnimationStateHandler(QScriptValue callback, AnimVariantMap parameters, QStringList names, bool useNames, AnimVariantResultHandler resultHandler);
|
||||||
void updateMemoryCost(const qint64&);
|
void updateMemoryCost(const qint64&);
|
||||||
|
@ -270,6 +271,8 @@ protected:
|
||||||
std::atomic<bool> _isUserLoaded { false };
|
std::atomic<bool> _isUserLoaded { false };
|
||||||
bool _isReloading { false };
|
bool _isReloading { false };
|
||||||
|
|
||||||
|
GetTargetUpdateRateFunction _getTargetUpdateRate { []() { return 60.0f; } };
|
||||||
|
|
||||||
ArrayBufferClass* _arrayBufferClass;
|
ArrayBufferClass* _arrayBufferClass;
|
||||||
|
|
||||||
AssetScriptingInterface _assetScriptingInterface{ this };
|
AssetScriptingInterface _assetScriptingInterface{ this };
|
||||||
|
|
Loading…
Reference in a new issue