X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fgame.cpp;h=f967e349cd7885361fee659dd732d22de32b6665;hb=d176dabeb4f04f9a1179cad9b23653fe6e19169e;hp=2b7d50eb53600b1f8f9820c38cd155a1a8ba0ca0;hpb=5cb7f6a9b7268ee6bfa5eae4f8af9613403f9965;p=minetest.git diff --git a/src/game.cpp b/src/game.cpp index 2b7d50eb5..f967e349c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "camera.h" #include "client.h" +#include "client/inputhandler.h" #include "client/tile.h" // For TextureSource #include "client/keys.h" #include "client/joystick_controller.h" @@ -50,7 +51,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "quicktune_shortcutter.h" #include "server.h" #include "settings.h" -#include "shader.h" // For ShaderSource #include "sky.h" #include "subgame.h" #include "tool.h" @@ -59,20 +59,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/pointedthing.h" #include "irrlicht_changes/static_text.h" #include "version.h" -#include "minimap.h" -#include "mapblock_mesh.h" #include "script/scripting_client.h" -#include "sound.h" - #if USE_SOUND #include "sound_openal.h" #endif -#ifdef HAVE_TOUCHSCREENGUI - #include "touchscreengui.h" -#endif - extern Settings *g_settings; extern Profiler *g_profiler; @@ -723,16 +715,19 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter m_eye_position_pixel.set(eye_position_array, services); m_eye_position_vertex.set(eye_position_array, services); - float minimap_yaw_array[3]; - v3f minimap_yaw = m_client->getMinimap()->getYawVec(); + if (m_client->getMinimap()) { + float minimap_yaw_array[3]; + v3f minimap_yaw = m_client->getMinimap()->getYawVec(); #if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8) - minimap_yaw_array[0] = minimap_yaw.X; - minimap_yaw_array[1] = minimap_yaw.Y; - minimap_yaw_array[2] = minimap_yaw.Z; + minimap_yaw_array[0] = minimap_yaw.X; + minimap_yaw_array[1] = minimap_yaw.Y; + minimap_yaw_array[2] = minimap_yaw.Z; #else - minimap_yaw.getAs3Values(minimap_yaw_array); + minimap_yaw.getAs3Values(minimap_yaw_array); #endif - m_minimap_yaw.set(minimap_yaw_array, services); + m_minimap_yaw.set(minimap_yaw_array, services); + + } SamplerLayer_t base_tex = 0, normal_tex = 1, @@ -1956,7 +1951,8 @@ bool Game::createClient(const std::string &playername, } mapper = client->getMinimap(); - mapper->setMinimapMode(MINIMAP_MODE_OFF); + if (mapper) + mapper->setMinimapMode(MINIMAP_MODE_OFF); return true; } @@ -2434,7 +2430,7 @@ void Game::updateStats(RunStats *stats, const FpsControl &draw_times, void Game::processUserInput(f32 dtime) { // Reset input if window not active or some menu is active - if (!device->isWindowActive() || !noMenuActive() || guienv->hasFocus(gui_chat_console)) { + if (!device->isWindowActive() || isMenuActive() || guienv->hasFocus(gui_chat_console)) { input->clear(); #ifdef HAVE_TOUCHSCREENGUI g_touchscreengui->hide(); @@ -2789,7 +2785,7 @@ void Game::toggleHud() void Game::toggleMinimap(bool shift_pressed) { - if (!flags.show_hud || !g_settings->getBool("enable_minimap")) + if (!mapper || !flags.show_hud || !g_settings->getBool("enable_minimap")) return; if (shift_pressed) { @@ -2964,7 +2960,8 @@ void Game::toggleFullViewRange() void Game::updateCameraDirection(CameraOrientation *cam, float dtime) { - if ((device->isWindowActive() && noMenuActive()) || random_input) { + if ((device->isWindowActive() && device->isWindowFocused() + && !isMenuActive()) || random_input) { #ifndef __ANDROID__ if (!random_input) { @@ -2989,8 +2986,7 @@ void Game::updateCameraDirection(CameraOrientation *cam, float dtime) device->getCursorControl()->setVisible(true); #endif - if (!m_first_loop_after_window_activation) - m_first_loop_after_window_activation = true; + m_first_loop_after_window_activation = true; } } @@ -3452,7 +3448,15 @@ void Game::updateSound(f32 dtime) v3f(0, 0, 0), // velocity camera->getDirection(), camera->getCameraNode()->getUpVector()); - sound->setListenerGain(g_settings->getFloat("sound_volume")); + + // Check if volume is in the proper range, else fix it. + float old_volume = g_settings->getFloat("sound_volume"); + float new_volume = rangelim(old_volume, 0.0f, 1.0f); + sound->setListenerGain(new_volume); + + if (old_volume != new_volume) { + g_settings->setFloat("sound_volume", new_volume); + } LocalPlayer *player = client->getEnv().getLocalPlayer(); @@ -3709,12 +3713,9 @@ PointedThing Game::updatePointedThing( float sin_r = 0.08 * sin(timerf); float sin_g = 0.08 * sin(timerf + irr::core::PI * 0.5); float sin_b = 0.08 * sin(timerf + irr::core::PI); - c.setRed( - core::clamp(core::round32(c.getRed() * (0.8 + sin_r)), 0, 255)); - c.setGreen( - core::clamp(core::round32(c.getGreen() * (0.8 + sin_g)), 0, 255)); - c.setBlue( - core::clamp(core::round32(c.getBlue() * (0.8 + sin_b)), 0, 255)); + c.setRed(core::clamp(core::round32(c.getRed() * (0.8 + sin_r)), 0, 255)); + c.setGreen(core::clamp(core::round32(c.getGreen() * (0.8 + sin_g)), 0, 255)); + c.setBlue(core::clamp(core::round32(c.getBlue() * (0.8 + sin_b)), 0, 255)); // Set mesh final color hud->setSelectionMeshColor(c); @@ -4183,7 +4184,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, if (current_formspec->getReferenceCount() == 1) { current_formspec->drop(); current_formspec = NULL; - } else if (!noMenuActive()) { + } else if (isMenuActive()) { guiroot->bringToFront(current_formspec); } } @@ -4197,7 +4198,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, TimeTaker tt_draw("mainloop: draw"); driver->beginScene(true, true, skycolor); - draw_scene(driver, smgr, *camera, *client, player, *hud, *mapper, + draw_scene(driver, smgr, *camera, *client, player, *hud, mapper, guienv, screensize, skycolor, flags.show_hud, flags.show_minimap); @@ -4232,7 +4233,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, /* Update minimap pos and rotation */ - if (flags.show_minimap && flags.show_hud) { + if (mapper && flags.show_minimap && flags.show_hud) { mapper->setPos(floatToInt(player->getPosition(), BS)); mapper->setAngle(player->getYaw()); }