Fix regressions and minor improvements in refactor_the_game

a) Fix double tap for jump and show_debug
b) Revert changes to limitFps()... there is no verification that the new method was an issue, but going back to old method just in case
b.2) limitFps() no longer calls device->run() and also no longer has to be called immediately after a call to device->run()
This commit is contained in:
Craig Robbins 2014-11-06 18:44:06 +10:00 committed by RealBadAngel
parent 92981b2fee
commit 1c21e391ed

@ -1212,6 +1212,7 @@ struct GameRunData {
bool ldown_for_dig; bool ldown_for_dig;
bool left_punch; bool left_punch;
bool update_wielded_item_trigger; bool update_wielded_item_trigger;
bool reset_jump_timer;
float nodig_delay_timer; float nodig_delay_timer;
float dig_time; float dig_time;
float dig_time_complete; float dig_time_complete;
@ -1332,6 +1333,7 @@ protected:
void processKeyboardInput(VolatileRunFlags *flags, void processKeyboardInput(VolatileRunFlags *flags,
float *statustext_time, float *statustext_time,
float *jump_timer, float *jump_timer,
bool *reset_jump_timer,
u32 *profiler_current_page, u32 *profiler_current_page,
u32 profiler_max_page); u32 profiler_max_page);
void processItemSelection(u16 *new_playeritem); void processItemSelection(u16 *new_playeritem);
@ -1568,9 +1570,7 @@ void Game::run()
flags.show_chat = true; flags.show_chat = true;
flags.show_hud = true; flags.show_hud = true;
flags.show_debug = g_settings->getBool("show_debug");
/* FIXME: This should be updated every iteration, or not stored locally
now that key settings can be changed in-game */
flags.invert_mouse = g_settings->getBool("invert_mouse"); flags.invert_mouse = g_settings->getBool("invert_mouse");
/* Clear the profiler */ /* Clear the profiler */
@ -1585,6 +1585,8 @@ void Game::run()
&runData.fog_range, &runData.fog_range,
client)); client));
std::vector<aabb3f> highlight_boxes;
while (device->run() && !(*kill || g_gamecallback->shutdown_requested)) { while (device->run() && !(*kill || g_gamecallback->shutdown_requested)) {
/* Must be called immediately after a device->run() call because it /* Must be called immediately after a device->run() call because it
@ -1602,8 +1604,6 @@ void Game::run()
processQueues(); processQueues();
std::vector<aabb3f> highlight_boxes;
infotext = L""; infotext = L"";
hud->resizeHotbar(); hud->resizeHotbar();
addProfilerGraphs(stats, draw_times, dtime); addProfilerGraphs(stats, draw_times, dtime);
@ -2307,6 +2307,7 @@ void Game::processUserInput(VolatileRunFlags *flags,
flags, flags,
&interact_args->statustext_time, &interact_args->statustext_time,
&interact_args->jump_timer, &interact_args->jump_timer,
&interact_args->reset_jump_timer,
&interact_args->profiler_current_page, &interact_args->profiler_current_page,
interact_args->profiler_max_page); interact_args->profiler_max_page);
@ -2317,6 +2318,7 @@ void Game::processUserInput(VolatileRunFlags *flags,
void Game::processKeyboardInput(VolatileRunFlags *flags, void Game::processKeyboardInput(VolatileRunFlags *flags,
float *statustext_time, float *statustext_time,
float *jump_timer, float *jump_timer,
bool *reset_jump_timer,
u32 *profiler_current_page, u32 *profiler_current_page,
u32 profiler_max_page) u32 profiler_max_page)
{ {
@ -2339,6 +2341,7 @@ void Game::processKeyboardInput(VolatileRunFlags *flags,
toggleFreeMove(statustext_time); toggleFreeMove(statustext_time);
} else if (input->wasKeyDown(getKeySetting("keymap_jump"))) { } else if (input->wasKeyDown(getKeySetting("keymap_jump"))) {
toggleFreeMoveAlt(statustext_time, jump_timer); toggleFreeMoveAlt(statustext_time, jump_timer);
*reset_jump_timer = true;
} else if (input->wasKeyDown(getKeySetting("keymap_fastmove"))) { } else if (input->wasKeyDown(getKeySetting("keymap_fastmove"))) {
toggleFast(statustext_time); toggleFast(statustext_time);
} else if (input->wasKeyDown(getKeySetting("keymap_noclip"))) { } else if (input->wasKeyDown(getKeySetting("keymap_noclip"))) {
@ -2390,6 +2393,11 @@ void Game::processKeyboardInput(VolatileRunFlags *flags,
<< std::endl; << std::endl;
debug_stacks_print(); debug_stacks_print();
} }
if (!input->isKeyDown(getKeySetting("keymap_jump")) && *reset_jump_timer) {
*reset_jump_timer = false;
*jump_timer = 0.0;
}
} }
@ -2485,10 +2493,8 @@ void Game::toggleFreeMove(float *statustext_time)
void Game::toggleFreeMoveAlt(float *statustext_time, float *jump_timer) void Game::toggleFreeMoveAlt(float *statustext_time, float *jump_timer)
{ {
if (g_settings->getBool("doubletap_jump") && *jump_timer < 0.2f) { if (g_settings->getBool("doubletap_jump") && *jump_timer < 0.2f)
toggleFreeMove(statustext_time); toggleFreeMove(statustext_time);
*jump_timer = 0;
}
} }
@ -3759,6 +3765,7 @@ void Game::updateGui(float *statustext_time, const RunStats& stats,
drawtime_avg = drawtime_avg * 0.95 + stats.drawtime * 0.05; drawtime_avg = drawtime_avg * 0.95 + stats.drawtime * 0.05;
u16 fps = 1.0 / stats.dtime_jitter.avg; u16 fps = 1.0 / stats.dtime_jitter.avg;
//s32 fps = driver->getFPS();
std::ostringstream os(std::ios_base::binary); std::ostringstream os(std::ios_base::binary);
os << std::fixed os << std::fixed
@ -3871,13 +3878,11 @@ inline void Game::updateProfilerGraphs(ProfilerGraph *graph)
****************************************************************************/ ****************************************************************************/
/* On some computers framerate doesn't seem to be automatically limited /* On some computers framerate doesn't seem to be automatically limited
*
* *Must* be called after device->run() so that device->getTimer()->getTime();
* is correct
*/ */
inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime) inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime)
{ {
// not using getRealTime is necessary for wine // not using getRealTime is necessary for wine
device->getTimer()->tick(); // Maker sure device time is up-to-date
u32 time = device->getTimer()->getTime(); u32 time = device->getTimer()->getTime();
u32 last_time = fps_timings->last_time; u32 last_time = fps_timings->last_time;
@ -3894,37 +3899,25 @@ inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime)
if (fps_timings->busy_time < frametime_min) { if (fps_timings->busy_time < frametime_min) {
fps_timings->sleep_time = frametime_min - fps_timings->busy_time; fps_timings->sleep_time = frametime_min - fps_timings->busy_time;
device->sleep(fps_timings->sleep_time); device->sleep(fps_timings->sleep_time);
time += fps_timings->sleep_time;
} else { } else {
fps_timings->sleep_time = 0; fps_timings->sleep_time = 0;
} }
if (time > last_time) // Checking for overflow /* Get the new value of the device timer. Note that device->sleep() may
*dtime = (time - last_time) / 1000.0; * not sleep for the entire requested time as sleep may be interrupted and
else * therefore it is arguably more accurate to get the new time from the
*dtime = 0.03; // Choose 30fps as fallback in overflow case * device rather than calculating it by adding sleep_time to time.
fps_timings->last_time = time;
#if 0
/* This is the old method for calculating new_time and dtime, and seems
* like overkill considering timings are messed up by expected variation
* in execution speed in other places anyway. (This has nothing to do with
* WINE... the new method above calculates dtime based on sleep_time)
*/ */
// Necessary for device->getTimer()->getTime() device->getTimer()->tick(); // Update device timer
device->run();
time = device->getTimer()->getTime(); time = device->getTimer()->getTime();
if (time > last_time) // Make sure last_time hasn't overflowed if (time > last_time) // Make sure last_time hasn't overflowed
*dtime = (time - last_time) / 1000.0; *dtime = (time - last_time) / 1000.0;
else else
*dtime = 0.033; *dtime = 0;
params->last_time = time; fps_timings->last_time = time;
#endif
} }