Cleanup updateCameraDirection and fix random input not working

This commit is contained in:
Craig Robbins 2014-12-20 18:23:45 +10:00
parent 9b0d77a549
commit 53bc56dc3c

@ -1492,6 +1492,8 @@ protected:
void toggleFullViewRange(float *statustext_time); void toggleFullViewRange(float *statustext_time);
void updateCameraDirection(CameraOrientation *cam, VolatileRunFlags *flags); void updateCameraDirection(CameraOrientation *cam, VolatileRunFlags *flags);
void updateCameraOrientation(CameraOrientation *cam,
const VolatileRunFlags &flags);
void updatePlayerControl(const CameraOrientation &cam); void updatePlayerControl(const CameraOrientation &cam);
void step(f32 *dtime); void step(f32 *dtime);
void processClientEvents(CameraOrientation *cam, float *damage_flash); void processClientEvents(CameraOrientation *cam, float *damage_flash);
@ -1640,6 +1642,8 @@ Game::Game() :
m_cache_enable_fog = g_settings->getBool("enable_fog"); m_cache_enable_fog = g_settings->getBool("enable_fog");
m_cache_mouse_sensitivity = g_settings->getFloat("mouse_sensitivity"); m_cache_mouse_sensitivity = g_settings->getFloat("mouse_sensitivity");
m_repeat_right_click_time = g_settings->getFloat("repeat_rightclick_time"); m_repeat_right_click_time = g_settings->getFloat("repeat_rightclick_time");
m_cache_mouse_sensitivity = rangelim(m_cache_mouse_sensitivity, 0.001, 100.0);
} }
@ -1727,6 +1731,7 @@ void Game::run()
flags.show_hud = true; flags.show_hud = true;
flags.show_debug = g_settings->getBool("show_debug"); flags.show_debug = g_settings->getBool("show_debug");
flags.invert_mouse = g_settings->getBool("invert_mouse"); flags.invert_mouse = g_settings->getBool("invert_mouse");
flags.first_loop_after_window_activation = true;
/* Clear the profiler */ /* Clear the profiler */
Profiler::GraphValues dummyvalues; Profiler::GraphValues dummyvalues;
@ -2849,22 +2854,7 @@ void Game::toggleFullViewRange(float *statustext_time)
void Game::updateCameraDirection(CameraOrientation *cam, void Game::updateCameraDirection(CameraOrientation *cam,
VolatileRunFlags *flags) VolatileRunFlags *flags)
{ {
// float turn_amount = 0; // Deprecated? if ((device->isWindowActive() && noMenuActive()) || random_input) {
if (!(device->isWindowActive() && noMenuActive()) || random_input) {
// FIXME: Clean this up
#ifndef ANDROID
// Mac OSX gets upset if this is set every frame
if (device->getCursorControl()->isVisible() == false)
device->getCursorControl()->setVisible(true);
#endif
//infostream<<"window inactive"<<std::endl;
flags->first_loop_after_window_activation = true;
return;
}
#ifndef __ANDROID__ #ifndef __ANDROID__
if (!random_input) { if (!random_input) {
@ -2874,13 +2864,32 @@ void Game::updateCameraDirection(CameraOrientation *cam,
} }
#endif #endif
if (flags->first_loop_after_window_activation) { if (flags->first_loop_after_window_activation)
//infostream<<"window active, first loop"<<std::endl;
flags->first_loop_after_window_activation = false; flags->first_loop_after_window_activation = false;
else
updateCameraOrientation(cam, *flags);
input->setMousePos((driver->getScreenSize().Width / 2),
(driver->getScreenSize().Height / 2));
} else { } else {
#ifdef HAVE_TOUCHSCREENGUI #ifndef ANDROID
// Mac OSX gets upset if this is set every frame
if (device->getCursorControl()->isVisible() == false)
device->getCursorControl()->setVisible(true);
#endif
if (!flags->first_loop_after_window_activation)
flags->first_loop_after_window_activation = true;
}
}
void Game::updateCameraOrientation(CameraOrientation *cam,
const VolatileRunFlags &flags)
{
#ifdef HAVE_TOUCHSCREENGUI
if (g_touchscreengui) { if (g_touchscreengui) {
cam->camera_yaw = g_touchscreengui->getYaw(); cam->camera_yaw = g_touchscreengui->getYaw();
cam->camera_pitch = g_touchscreengui->getPitch(); cam->camera_pitch = g_touchscreengui->getPitch();
@ -2889,35 +2898,19 @@ void Game::updateCameraDirection(CameraOrientation *cam,
s32 dx = input->getMousePos().X - (driver->getScreenSize().Width / 2); s32 dx = input->getMousePos().X - (driver->getScreenSize().Width / 2);
s32 dy = input->getMousePos().Y - (driver->getScreenSize().Height / 2); s32 dy = input->getMousePos().Y - (driver->getScreenSize().Height / 2);
if (flags->invert_mouse if (flags.invert_mouse
|| (camera->getCameraMode() == CAMERA_MODE_THIRD_FRONT)) { || camera->getCameraMode() == CAMERA_MODE_THIRD_FRONT) {
dy = -dy; dy = -dy;
} }
//infostream<<"window active, pos difference "<<dx<<","<<dy<<std::endl; cam->camera_yaw -= dx * m_cache_mouse_sensitivity;
cam->camera_pitch += dy * m_cache_mouse_sensitivity;
float d = m_cache_mouse_sensitivity;
d = rangelim(d, 0.01, 100.0);
cam->camera_yaw -= dx * d;
cam->camera_pitch += dy * d;
// turn_amount = v2f(dx, dy).getLength() * d; // deprecated?
#ifdef HAVE_TOUCHSCREENGUI #ifdef HAVE_TOUCHSCREENGUI
} }
#endif #endif
if (cam->camera_pitch < -89.5) cam->camera_pitch = rangelim(cam->camera_pitch, -89.5, 89.5);
cam->camera_pitch = -89.5;
else if (cam->camera_pitch > 89.5)
cam->camera_pitch = 89.5;
}
input->setMousePos(driver->getScreenSize().Width / 2,
driver->getScreenSize().Height / 2);
// Deprecated? Not used anywhere else
// recent_turn_speed = recent_turn_speed * 0.9 + turn_amount * 0.1;
// std::cerr<<"recent_turn_speed = "<<recent_turn_speed<<std::endl;
} }