Add camera smoothing and cinematic mode (F8)

This commit is contained in:
rubenwardy 2015-02-15 19:27:15 +00:00 committed by Loic Blot
parent b4acac706d
commit d65a90a86b
4 changed files with 62 additions and 23 deletions

@ -48,6 +48,7 @@
#keymap_rangeselect = KEY_KEY_R #keymap_rangeselect = KEY_KEY_R
#keymap_freemove = KEY_KEY_K #keymap_freemove = KEY_KEY_K
#keymap_fastmove = KEY_KEY_J #keymap_fastmove = KEY_KEY_J
#keymap_cinematic = KEY_F8
#keymap_screenshot = KEY_F12 #keymap_screenshot = KEY_F12
# If true, keymap_special1 instead of keymap_sneak is used for climbing down and descending # If true, keymap_special1 instead of keymap_sneak is used for climbing down and descending
#aux1_descends = false #aux1_descends = false
@ -127,6 +128,13 @@
#free_move = false #free_move = false
# Continuous forward movement (for testing) # Continuous forward movement (for testing)
#continuous_forward = false #continuous_forward = false
# Enable cinematic mode
#cinematic = false
# Camera smoothing - smooths rotation of camera. 0 is no smoothing.
# Must be equal to or greater than 0, and less than 1.
#camera_smoothing = 0.0
# Camera smoothing when in cinematic mode
#cinematic_camera_smoothing = 0.7
# Fast movement (keymap_special1) # Fast movement (keymap_special1)
#fast_move = false #fast_move = false
# Invert mouse # Invert mouse

@ -48,6 +48,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("keymap_freemove", "KEY_KEY_K"); settings->setDefault("keymap_freemove", "KEY_KEY_K");
settings->setDefault("keymap_fastmove", "KEY_KEY_J"); settings->setDefault("keymap_fastmove", "KEY_KEY_J");
settings->setDefault("keymap_noclip", "KEY_KEY_H"); settings->setDefault("keymap_noclip", "KEY_KEY_H");
settings->setDefault("keymap_cinematic", "KEY_F8");
settings->setDefault("keymap_screenshot", "KEY_F12"); settings->setDefault("keymap_screenshot", "KEY_F12");
settings->setDefault("keymap_toggle_hud", "KEY_F1"); settings->setDefault("keymap_toggle_hud", "KEY_F1");
settings->setDefault("keymap_toggle_chat", "KEY_F2"); settings->setDefault("keymap_toggle_chat", "KEY_F2");
@ -115,6 +116,9 @@ void set_default_settings(Settings *settings)
settings->setDefault("free_move", "false"); settings->setDefault("free_move", "false");
settings->setDefault("noclip", "false"); settings->setDefault("noclip", "false");
settings->setDefault("continuous_forward", "false"); settings->setDefault("continuous_forward", "false");
settings->setDefault("cinematic", "false");
settings->setDefault("camera_smoothing", "0");
settings->setDefault("cinematic_camera_smoothing", "0.7");
settings->setDefault("fast_move", "false"); settings->setDefault("fast_move", "false");
settings->setDefault("invert_mouse", "false"); settings->setDefault("invert_mouse", "false");
settings->setDefault("enable_clouds", "true"); settings->setDefault("enable_clouds", "true");

@ -1253,6 +1253,7 @@ struct KeyCache {
KEYMAP_ID_FREEMOVE, KEYMAP_ID_FREEMOVE,
KEYMAP_ID_FASTMOVE, KEYMAP_ID_FASTMOVE,
KEYMAP_ID_NOCLIP, KEYMAP_ID_NOCLIP,
KEYMAP_ID_CINEMATIC,
KEYMAP_ID_SCREENSHOT, KEYMAP_ID_SCREENSHOT,
KEYMAP_ID_TOGGLE_HUD, KEYMAP_ID_TOGGLE_HUD,
KEYMAP_ID_TOGGLE_CHAT, KEYMAP_ID_TOGGLE_CHAT,
@ -1301,6 +1302,7 @@ void KeyCache::populate()
key[KEYMAP_ID_FREEMOVE] = getKeySetting("keymap_freemove"); key[KEYMAP_ID_FREEMOVE] = getKeySetting("keymap_freemove");
key[KEYMAP_ID_FASTMOVE] = getKeySetting("keymap_fastmove"); key[KEYMAP_ID_FASTMOVE] = getKeySetting("keymap_fastmove");
key[KEYMAP_ID_NOCLIP] = getKeySetting("keymap_noclip"); key[KEYMAP_ID_NOCLIP] = getKeySetting("keymap_noclip");
key[KEYMAP_ID_CINEMATIC] = getKeySetting("keymap_cinematic");
key[KEYMAP_ID_SCREENSHOT] = getKeySetting("keymap_screenshot"); key[KEYMAP_ID_SCREENSHOT] = getKeySetting("keymap_screenshot");
key[KEYMAP_ID_TOGGLE_HUD] = getKeySetting("keymap_toggle_hud"); key[KEYMAP_ID_TOGGLE_HUD] = getKeySetting("keymap_toggle_hud");
key[KEYMAP_ID_TOGGLE_CHAT] = getKeySetting("keymap_toggle_chat"); key[KEYMAP_ID_TOGGLE_CHAT] = getKeySetting("keymap_toggle_chat");
@ -1497,6 +1499,7 @@ protected:
void toggleFreeMoveAlt(float *statustext_time, float *jump_timer); void toggleFreeMoveAlt(float *statustext_time, float *jump_timer);
void toggleFast(float *statustext_time); void toggleFast(float *statustext_time);
void toggleNoClip(float *statustext_time); void toggleNoClip(float *statustext_time);
void toggleCinematic(float *statustext_time);
void toggleChat(float *statustext_time, bool *flag); void toggleChat(float *statustext_time, bool *flag);
void toggleHud(float *statustext_time, bool *flag); void toggleHud(float *statustext_time, bool *flag);
@ -1737,6 +1740,7 @@ void Game::run()
{ {
ProfilerGraph graph; ProfilerGraph graph;
RunStats stats = { 0 }; RunStats stats = { 0 };
CameraOrientation cam_view_target = { 0 };
CameraOrientation cam_view = { 0 }; CameraOrientation cam_view = { 0 };
GameRunData runData = { 0 }; GameRunData runData = { 0 };
FpsControl draw_times = { 0 }; FpsControl draw_times = { 0 };
@ -1792,7 +1796,17 @@ void Game::run()
updateProfilers(runData, stats, draw_times, dtime); updateProfilers(runData, stats, draw_times, dtime);
processUserInput(&flags, &runData, dtime); processUserInput(&flags, &runData, dtime);
// Update camera before player movement to avoid camera lag of one frame // Update camera before player movement to avoid camera lag of one frame
updateCameraDirection(&cam_view, &flags); updateCameraDirection(&cam_view_target, &flags);
float cam_smoothing = 0;
if (g_settings->getBool("cinematic"))
cam_smoothing = 1 - g_settings->getFloat("cinematic_camera_smoothing");
else
cam_smoothing = 1 - g_settings->getFloat("camera_smoothing");
cam_smoothing = rangelim(cam_smoothing, 0.01f, 1.0f);
cam_view.camera_yaw += (cam_view_target.camera_yaw -
cam_view.camera_yaw) * cam_smoothing;
cam_view.camera_pitch += (cam_view_target.camera_pitch -
cam_view.camera_pitch) * cam_smoothing;
updatePlayerControl(cam_view); updatePlayerControl(cam_view);
step(&dtime); step(&dtime);
processClientEvents(&cam_view, &runData.damage_flash); processClientEvents(&cam_view, &runData.damage_flash);
@ -2568,6 +2582,8 @@ void Game::processKeyboardInput(VolatileRunFlags *flags,
toggleFast(statustext_time); toggleFast(statustext_time);
} else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_NOCLIP])) { } else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_NOCLIP])) {
toggleNoClip(statustext_time); toggleNoClip(statustext_time);
} else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_CINEMATIC])) {
toggleCinematic(statustext_time);
} else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_SCREENSHOT])) { } else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_SCREENSHOT])) {
client->makeScreenshot(device); client->makeScreenshot(device);
} else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_TOGGLE_HUD])) { } else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_TOGGLE_HUD])) {
@ -2754,6 +2770,16 @@ void Game::toggleNoClip(float *statustext_time)
statustext += L" (note: no 'noclip' privilege)"; statustext += L" (note: no 'noclip' privilege)";
} }
void Game::toggleCinematic(float *statustext_time)
{
static const wchar_t *msg[] = { L"cinematic disabled", L"cinematic enabled" };
bool cinematic = !g_settings->getBool("cinematic");
g_settings->set("cinematic", bool_to_cstr(cinematic));
*statustext_time = 0;
statustext = msg[cinematic];
}
void Game::toggleChat(float *statustext_time, bool *flag) void Game::toggleChat(float *statustext_time, bool *flag)
{ {
@ -4237,4 +4263,3 @@ void the_game(bool *kill,
error_message = narrow_to_wide(e.what()) + wstrgettext("\nCheck debug.txt for details."); error_message = narrow_to_wide(e.what()) + wstrgettext("\nCheck debug.txt for details.");
} }
} }

@ -51,6 +51,7 @@ enum
GUI_ID_KEY_FAST_BUTTON, GUI_ID_KEY_FAST_BUTTON,
GUI_ID_KEY_JUMP_BUTTON, GUI_ID_KEY_JUMP_BUTTON,
GUI_ID_KEY_NOCLIP_BUTTON, GUI_ID_KEY_NOCLIP_BUTTON,
GUI_ID_KEY_CINEMATIC_BUTTON,
GUI_ID_KEY_CHAT_BUTTON, GUI_ID_KEY_CHAT_BUTTON,
GUI_ID_KEY_CMD_BUTTON, GUI_ID_KEY_CMD_BUTTON,
GUI_ID_KEY_CONSOLE_BUTTON, GUI_ID_KEY_CONSOLE_BUTTON,
@ -137,20 +138,20 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
{ {
key_setting *k = key_settings.at(i); key_setting *k = key_settings.at(i);
{ {
core::rect < s32 > rect(0, 0, 100, 20); core::rect < s32 > rect(0, 0, 110, 20);
rect += topleft + v2s32(offset.X, offset.Y); rect += topleft + v2s32(offset.X, offset.Y);
Environment->addStaticText(k->button_name, rect, false, true, this, -1); Environment->addStaticText(k->button_name, rect, false, true, this, -1);
} }
{ {
core::rect < s32 > rect(0, 0, 100, 30); core::rect < s32 > rect(0, 0, 100, 30);
rect += topleft + v2s32(offset.X + 105, offset.Y - 5); rect += topleft + v2s32(offset.X + 115, offset.Y - 5);
const wchar_t *text = wgettext(k->key.name()); const wchar_t *text = wgettext(k->key.name());
k->button = Environment->addButton(rect, this, k->id, text); k->button = Environment->addButton(rect, this, k->id, text);
delete[] text; delete[] text;
} }
if(i + 1 == KMaxButtonPerColumns) if(i + 1 == KMaxButtonPerColumns)
offset = v2s32(250, 60); offset = v2s32(260, 60);
else else
offset += v2s32(0, 25); offset += v2s32(0, 25);
} }
@ -408,6 +409,7 @@ void GUIKeyChangeMenu::init_keys()
this->add_key(GUI_ID_KEY_CONSOLE_BUTTON, wgettext("Console"), "keymap_console"); this->add_key(GUI_ID_KEY_CONSOLE_BUTTON, wgettext("Console"), "keymap_console");
this->add_key(GUI_ID_KEY_FLY_BUTTON, wgettext("Toggle fly"), "keymap_freemove"); this->add_key(GUI_ID_KEY_FLY_BUTTON, wgettext("Toggle fly"), "keymap_freemove");
this->add_key(GUI_ID_KEY_FAST_BUTTON, wgettext("Toggle fast"), "keymap_fastmove"); this->add_key(GUI_ID_KEY_FAST_BUTTON, wgettext("Toggle fast"), "keymap_fastmove");
this->add_key(GUI_ID_KEY_CINEMATIC_BUTTON, wgettext("Toggle Cinematic"), "keymap_cinematic");
this->add_key(GUI_ID_KEY_NOCLIP_BUTTON, wgettext("Toggle noclip"), "keymap_noclip"); this->add_key(GUI_ID_KEY_NOCLIP_BUTTON, wgettext("Toggle noclip"), "keymap_noclip");
this->add_key(GUI_ID_KEY_RANGE_BUTTON, wgettext("Range select"), "keymap_rangeselect"); this->add_key(GUI_ID_KEY_RANGE_BUTTON, wgettext("Range select"), "keymap_rangeselect");
this->add_key(GUI_ID_KEY_DUMP_BUTTON, wgettext("Print stacks"), "keymap_print_debug_stacks"); this->add_key(GUI_ID_KEY_DUMP_BUTTON, wgettext("Print stacks"), "keymap_print_debug_stacks");