summaryrefslogtreecommitdiff
path: root/main/main.cpp
diff options
context:
space:
mode:
authormarynate <mary.w.nate@gmail.com>2014-02-19 23:35:39 +0800
committermarynate <mary.w.nate@gmail.com>2014-03-18 18:00:18 +0800
commitc0547f5691c9293f82f6713d18b344524146441a (patch)
treeb9af649946085f4e6f900fcf525dc2ec725a35a3 /main/main.cpp
parente20e3c9525c2f0d5bb95e85138a8d88a0088d439 (diff)
Add possibility to limit frame to main loop (application/target_fps)
target-fps working, and use fixed physics step before adding physics-fps in project setting Complete implementation of framelimit Conflicts: main/main.cpp
Diffstat (limited to 'main/main.cpp')
-rw-r--r--main/main.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/main/main.cpp b/main/main.cpp
index 7d19c2ebcf..16cb32ed0c 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -648,7 +648,8 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
OS::get_singleton()->set_screen_orientation(OS::SCREEN_LANDSCAPE);
}
- OS::get_singleton()->set_iterations_per_second(GLOBAL_DEF("display/target_fps",60));
+ OS::get_singleton()->set_iterations_per_second(GLOBAL_DEF("physics/fixed_fps",60));
+ OS::get_singleton()->set_target_fps(GLOBAL_DEF("application/target_fps",0));
if (!OS::get_singleton()->_verbose_stdout) //overrided
OS::get_singleton()->_verbose_stdout=GLOBAL_DEF("debug/verbose_stdout",false);
@@ -1210,6 +1211,7 @@ bool Main::start() {
}
uint64_t Main::last_ticks=0;
+uint64_t Main::target_ticks=0;
float Main::time_accum=0;
uint32_t Main::frames=0;
uint32_t Main::frame=0;
@@ -1295,7 +1297,6 @@ bool Main::iteration() {
}
} else {
VisualServer::get_singleton()->flush(); // flush visual commands
-
}
if (AudioServer::get_singleton())
@@ -1343,6 +1344,16 @@ bool Main::iteration() {
OS::get_singleton()->delay_usec( OS::get_singleton()->get_frame_delay()*1000 );
}
+ int taret_fps = OS::get_singleton()->get_target_fps();
+ if (taret_fps>0) {
+ uint64_t time_step = 1000000L/taret_fps;
+ target_ticks += time_step;
+ uint64_t current_ticks = OS::get_singleton()->get_ticks_usec();
+ if (current_ticks<target_ticks) OS::get_singleton()->delay_usec(target_ticks-current_ticks);
+ current_ticks = OS::get_singleton()->get_ticks_usec();
+ target_ticks = MIN(MAX(target_ticks,current_ticks-time_step),current_ticks+time_step);
+ }
+
return exit;
}