From ec29beca907fced9324e406d128ea4731fbbaca2 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Thu, 5 Sep 2019 03:05:15 +0200 Subject: [PATCH] + Added FPS capping option for laptops ~ Changed default FPS cap to 30 FPS ~ Fixed bug where the windowed mode wasn't rendering anything Signed-off-by: Alexis Maiquez --- README.md | 6 ++++++ main.cpp | 36 ++++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ba02a5d..8e43d86 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,12 @@ Only screens configured with the XRandr extension are supported. To specify the **IMPORTANT: Right now this doesn't work if there is anything drawing to the background (like a compositor, nautilus, etc)** +#### 5.4.4. Limiting FPS +To reduce the performance hit to your system you can reduce (or increase) the FPS limit with the switch ```--fps```, specially useful for laptops: +``` +./wallengine --fps 30 +``` + ###### Example background This was the first background to even be compatible with the software. And It's not 100% compatible yet. Both textures and shaders are properly loaded, but there are still particles missing. diff --git a/main.cpp b/main.cpp index cb3e3a7..ec16d92 100644 --- a/main.cpp +++ b/main.cpp @@ -152,7 +152,8 @@ void print_help (const char* route) << " --silent\t\tMutes all the sound the wallpaper might produce" << std::endl << " --dir \tLoads an uncompressed background from the given " << std::endl << " --pkg \tLoads a scene.pkg file from the given " << std::endl - << " --screen-root \tDisplay as screen's background" << std::endl; + << " --screen-root \tDisplay as screen's background" << std::endl + << " --fps \tLimits the FPS to the given number, useful to keep battery consumption low" << std::endl; } std::string stringPathFixes(const std::string& s){ @@ -171,6 +172,7 @@ std::string stringPathFixes(const std::string& s){ int main (int argc, char* argv[]) { int mode = 0; + int max_fps = 30; bool audio_support = true; std::string path; @@ -180,9 +182,10 @@ int main (int argc, char* argv[]) {"screen-root", required_argument, 0, 'r'}, {"pkg", required_argument, 0, 'p'}, {"dir", required_argument, 0, 'd'}, - {"silent", optional_argument, 0, 's'}, - {"help", optional_argument, 0, 'h'}, - {nullptr, 0, 0, 0} + {"silent", no_argument, 0, 's'}, + {"help", no_argument, 0, 'h'}, + {"fps", required_argument, 0, 'f'}, + {nullptr, 0, 0, 0} }; while (true) @@ -217,6 +220,10 @@ int main (int argc, char* argv[]) print_help (argv [0]); return 0; + case 'f': + max_fps = atoi (optarg); + break; + default: break; } @@ -292,18 +299,21 @@ int main (int argc, char* argv[]) // register nodes wp::video::renderer::queueNode (wp_project->getScene ()); - int32_t lastTime = 0; - int32_t minimumTime = 1000 / 90; - int32_t currentTime = 0; + irr::u32 lastTime = 0; + irr::u32 minimumTime = 1000 / max_fps; + irr::u32 currentTime = 0; + + irr::u32 startTime = 0; + irr::u32 endTime = 0; while (wp::irrlicht::device->run () && wp::irrlicht::driver) { // if (device->isWindowActive ()) { - currentTime = wp::irrlicht::device->getTimer ()->getTime (); + currentTime = startTime = wp::irrlicht::device->getTimer ()->getTime (); g_Time = currentTime / 1000.0f; - if (currentTime - lastTime > minimumTime) + if (Viewports.size () > 0) { std::vector>::iterator cur = Viewports.begin (); std::vector>::iterator end = Viewports.end (); @@ -314,13 +324,15 @@ int main (int argc, char* argv[]) wp::irrlicht::driver->setViewPort (*cur); wp::video::renderer::render (); } - - lastTime = currentTime; } else { - wp::irrlicht::device->sleep (1, false); + wp::video::renderer::render (); } + + endTime = wp::irrlicht::device->getTimer ()->getTime (); + + wp::irrlicht::device->sleep (minimumTime - (endTime - startTime), false); } }