VOXEDIT: fps limit refactoring
parent
1b69f50d7c
commit
275e7b54b7
|
@ -68,6 +68,10 @@ void App::remBlocker(AppState blockedState) {
|
|||
_blockers.erase(blockedState);
|
||||
}
|
||||
|
||||
void App::setFramesPerSecondsCap(float framesPerSecondsCap) {
|
||||
_framesPerSecondsCap->setVal(framesPerSecondsCap);
|
||||
}
|
||||
|
||||
void App::traceBeginFrame(const char *threadName) {
|
||||
}
|
||||
|
||||
|
@ -144,7 +148,8 @@ void App::onFrame() {
|
|||
case AppState::Running: {
|
||||
{
|
||||
core_trace_scoped(AppOnRunning);
|
||||
if (_framesPerSecondsCap < 1.0 || _nextFrameMillis > now) {
|
||||
const double framesPerSecondsCap = _framesPerSecondsCap->floatVal();
|
||||
if (framesPerSecondsCap < 1.0 || _nextFrameMillis > now) {
|
||||
{
|
||||
core_trace_scoped(AppOnBeforeRunning);
|
||||
onBeforeRunning();
|
||||
|
@ -158,12 +163,12 @@ void App::onFrame() {
|
|||
onAfterRunning();
|
||||
}
|
||||
}
|
||||
if (_framesPerSecondsCap > 1.0) {
|
||||
if (framesPerSecondsCap > 1.0) {
|
||||
const uint64_t delay = _nextFrameMillis - now;
|
||||
if (delay > 0u) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(delay));
|
||||
}
|
||||
_nextFrameMillis += uint64_t((1000.0 / _framesPerSecondsCap) + 0.00001);
|
||||
_nextFrameMillis += uint64_t((1000.0 / framesPerSecondsCap) + 0.00001);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -189,6 +194,8 @@ void App::onFrame() {
|
|||
|
||||
AppState App::onConstruct() {
|
||||
VarPtr logVar = core::Var::get(cfg::CoreLogLevel, _initialLogLevel);
|
||||
// this ensures that we are sleeping 1 millisecond if there is enough room for it
|
||||
_framesPerSecondsCap = core::Var::get(cfg::CoreMaxFPS, "1000.0");
|
||||
registerArg("--loglevel").setShort("-l").setDescription("Change log level from 1 (trace) to 6 (only critical)");
|
||||
const std::string& logLevelVal = getArgVal("--loglevel");
|
||||
if (!logLevelVal.empty()) {
|
||||
|
|
|
@ -118,7 +118,7 @@ protected:
|
|||
* @note Only handled if the max frames cap is set
|
||||
*/
|
||||
uint64_t _nextFrameMillis = 0ul;
|
||||
double _framesPerSecondsCap = 0.0;
|
||||
core::VarPtr _framesPerSecondsCap;
|
||||
|
||||
/**
|
||||
* @brief If the application failed to init or must be closed due to a failure, you
|
||||
|
@ -151,9 +151,7 @@ protected:
|
|||
* @brief There is no fps limit per default, but you set one on a per-app basis
|
||||
* @param[in] framesPerSecondsCap The frames to cap the application loop at
|
||||
*/
|
||||
void setFramesPerSecondsCap(double framesPerSecondsCap) {
|
||||
_framesPerSecondsCap = framesPerSecondsCap;
|
||||
}
|
||||
void setFramesPerSecondsCap(float framesPerSecondsCap);
|
||||
|
||||
virtual void traceBeginFrame(const char *threadName) override;
|
||||
virtual void traceBegin(const char *threadName, const char* name) override;
|
||||
|
|
|
@ -53,6 +53,7 @@ constexpr const char *ServerPort = "sv_port";
|
|||
constexpr const char *ServerMaxClients = "sv_maxclients";
|
||||
constexpr const char *ServerPostgresLib = "sv_postgreslib";
|
||||
|
||||
constexpr const char *CoreMaxFPS = "core_maxfps";
|
||||
constexpr const char *CoreLogLevel = "core_loglevel";
|
||||
constexpr const char *CoreSysLog = "core_syslog";
|
||||
|
||||
|
|
|
@ -34,8 +34,6 @@ Server::Server(const metric::MetricPtr& metric, const backend::ServerLoopPtr& se
|
|||
_serverLoop(serverLoop) {
|
||||
_syslog = true;
|
||||
_coredump = true;
|
||||
// this ensures that we are sleeping 1 millisecond if there is enough room for it
|
||||
setFramesPerSecondsCap(1000.0);
|
||||
init(ORGANISATION, "server");
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ TestTraze::TestTraze(const metric::MetricPtr& metric, const io::FilesystemPtr& f
|
|||
init(ORGANISATION, "testtraze");
|
||||
setRenderAxis(false);
|
||||
setRelativeMouseMode(false);
|
||||
setFramesPerSecondsCap(60);
|
||||
_allowRelativeMouseMode = false;
|
||||
_eventBus->subscribe<traze::NewGridEvent>(*this);
|
||||
_eventBus->subscribe<traze::NewGamesEvent>(*this);
|
||||
|
@ -46,6 +45,7 @@ const traze::Player& TestTraze::player(traze::PlayerId playerId) const {
|
|||
|
||||
core::AppState TestTraze::onConstruct() {
|
||||
core::AppState state = Super::onConstruct();
|
||||
setFramesPerSecondsCap(60.0);
|
||||
core::Var::get("mosquitto_host", "traze.iteratec.de");
|
||||
core::Var::get("mosquitto_port", "1883");
|
||||
_name = core::Var::get("name", "noname_testtraze");
|
||||
|
|
|
@ -14,7 +14,6 @@ VoxEdit::VoxEdit(const metric::MetricPtr& metric, const io::FilesystemPtr& files
|
|||
Super(metric, filesystem, eventBus, timeProvider), _mainWindow(nullptr), _meshPool(meshPool), _sceneMgr(voxedit::sceneMgr()) {
|
||||
init(ORGANISATION, "voxedit");
|
||||
_allowRelativeMouseMode = false;
|
||||
setFramesPerSecondsCap(60.0);
|
||||
}
|
||||
|
||||
bool VoxEdit::importheightmapFile(const std::string& file) {
|
||||
|
@ -59,6 +58,8 @@ core::AppState VoxEdit::onCleanup() {
|
|||
core::AppState VoxEdit::onConstruct() {
|
||||
const core::AppState state = Super::onConstruct();
|
||||
|
||||
setFramesPerSecondsCap(60.0);
|
||||
|
||||
_sceneMgr.construct();
|
||||
|
||||
auto fileCompleter = [=] (const std::string& str, std::vector<std::string>& matches) -> int {
|
||||
|
|
Loading…
Reference in New Issue