]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/client/game.h
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / src / client / game.h
index c24d57413bce089cb9af6407c909c8d77a621abd..0e5d0550d296b156acd1652b7bfcf205197b5a95 100644 (file)
@@ -68,6 +68,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "util/pointedthing.h"
 #include "util/quicktune_shortcutter.h"
 #include "irrlicht_changes/static_text.h"
+#include "irr_ptr.h"
 #include "version.h"
 #include "script/scripting_client.h"
 #include "hud.h"
@@ -75,7 +76,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <string>
 
 class InputHandler;
-class ChatBackend;  /* to avoid having to include chat.h */
+class ChatBackend;
+class RenderingEngine;
 struct SubgameSpec;
 struct GameStartData;
 
@@ -84,7 +86,7 @@ struct Jitter {
 };
 
 struct RunStats {
-       u32 drawtime;
+       u64 drawtime; // (us)
 
        Jitter dtime_jitter, busy_time_jitter;
 };
@@ -188,13 +190,7 @@ struct LocalFormspecHandler : public TextDest
                                return;
                        }
 
-                       if (fields.find("quit") != fields.end()) {
-                               return;
-                       }
-
-                       if (fields.find("btn_continue") != fields.end()) {
-                               return;
-                       }
+                       return;
                }
 
                if (m_formname == "MT_DEATH_SCREEN") {
@@ -203,7 +199,7 @@ struct LocalFormspecHandler : public TextDest
                        return;
                }
 
-               if (m_client && m_client->modsLoaded())
+               if (m_client->modsLoaded())
                        m_client->getScript()->on_formspec_input(m_formname, fields);
        }
 
@@ -295,7 +291,7 @@ class SoundMaker
                m_sound(sound),
                m_ndef(ndef),
                makes_footstep_sound(true),
-               m_player_step_timer(0),
+               m_player_step_timer(0.0f),
                m_player_jump_timer(0.0f)
        {
        }
@@ -422,12 +418,7 @@ class GameOnDemandSoundFetcher: public OnDemandSoundFetcher
 };
 
 
-// before 1.8 there isn't a "integer interface", only float
-#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
-typedef f32 SamplerLayer_t;
-#else
 typedef s32 SamplerLayer_t;
-#endif
 
 
 class GameGlobalShaderConstantSetter : public IShaderConstantSetter
@@ -441,6 +432,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
        CachedVertexShaderSetting<float> m_animation_timer_vertex;
        CachedPixelShaderSetting<float> m_animation_timer_pixel;
        CachedPixelShaderSetting<float, 3> m_day_light;
+       CachedPixelShaderSetting<float, 4> m_star_color;
        CachedPixelShaderSetting<float, 3> m_eye_position_pixel;
        CachedVertexShaderSetting<float, 3> m_eye_position_vertex;
        CachedPixelShaderSetting<float, 3> m_minimap_yaw;
@@ -448,7 +440,6 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
        CachedPixelShaderSetting<float, 3> m_camera_offset_vertex;
        CachedPixelShaderSetting<SamplerLayer_t> m_base_texture;
        CachedPixelShaderSetting<SamplerLayer_t> m_normal_texture;
-       CachedPixelShaderSetting<SamplerLayer_t> m_texture_flags;
        Client *m_client;
 
 public:
@@ -475,6 +466,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
                m_animation_timer_vertex("animationTimer"),
                m_animation_timer_pixel("animationTimer"),
                m_day_light("dayLight"),
+               m_star_color("starColor"),
                m_eye_position_pixel("eyePosition"),
                m_eye_position_vertex("eyePosition"),
                m_minimap_yaw("yawVec"),
@@ -482,7 +474,6 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
                m_camera_offset_vertex("cameraOffset"),
                m_base_texture("baseTexture"),
                m_normal_texture("normalTexture"),
-               m_texture_flags("textureFlags"),
                m_client(client)
        {
                g_settings->registerChangedCallback("enable_fog", settingsCallback, this);
@@ -494,12 +485,8 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
                g_settings->deregisterChangedCallback("enable_fog", settingsCallback, this);
        }
 
-       virtual void onSetConstants(video::IMaterialRendererServices *services,
-                       bool is_highlevel)
+       void onSetConstants(video::IMaterialRendererServices *services) override
        {
-               if (!is_highlevel)
-                       return;
-
                // Background color
                video::SColor bgcolor = m_sky->getBgColor();
                video::SColorf bgcolorf(bgcolor);
@@ -528,6 +515,10 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
                        sunlight.b };
                m_day_light.set(dnc, services);
 
+               video::SColorf star_color = m_sky->getCurrentStarColor();
+               float clr[4] = {star_color.r, star_color.g, star_color.b, star_color.a};
+               m_star_color.set(clr, services);
+
                u32 animation_timer = porting::getTimeMs() % 1000000;
                float animation_timer_f = (float)animation_timer / 100000.f;
                m_animation_timer_vertex.set(&animation_timer_f, services);
@@ -535,47 +526,26 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
 
                float eye_position_array[3];
                v3f epos = m_client->getEnv().getLocalPlayer()->getEyePosition();
-#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
-               eye_position_array[0] = epos.X;
-               eye_position_array[1] = epos.Y;
-               eye_position_array[2] = epos.Z;
-#else
                epos.getAs3Values(eye_position_array);
-#endif
                m_eye_position_pixel.set(eye_position_array, services);
                m_eye_position_vertex.set(eye_position_array, services);
 
                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;
-#else
                        minimap_yaw.getAs3Values(minimap_yaw_array);
-#endif
                        m_minimap_yaw.set(minimap_yaw_array, services);
                }
 
                float camera_offset_array[3];
                v3f offset = intToFloat(m_client->getCamera()->getOffset(), BS);
-#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
-               camera_offset_array[0] = offset.X;
-               camera_offset_array[1] = offset.Y;
-               camera_offset_array[2] = offset.Z;
-#else
                offset.getAs3Values(camera_offset_array);
-#endif
                m_camera_offset_pixel.set(camera_offset_array, services);
                m_camera_offset_vertex.set(camera_offset_array, services);
 
-               SamplerLayer_t base_tex = 0,
-                               normal_tex = 1,
-                               flags_tex = 2;
+               SamplerLayer_t base_tex = 0, normal_tex = 1;
                m_base_texture.set(&base_tex, services);
                m_normal_texture.set(&normal_tex, services);
-               m_texture_flags.set(&flags_tex, services);
        }
 };
 
@@ -606,7 +576,7 @@ class GameGlobalShaderConstantSetterFactory : public IShaderConstantSetterFactor
 
        virtual IShaderConstantSetter* create()
        {
-               GameGlobalShaderConstantSetter *scs = new GameGlobalShaderConstantSetter(
+               auto *scs = new GameGlobalShaderConstantSetter(
                                m_sky, m_force_fog_off, m_fog_range, m_client);
                if (!m_sky)
                        created_nosky.push_back(scs);
@@ -614,20 +584,28 @@ class GameGlobalShaderConstantSetterFactory : public IShaderConstantSetterFactor
        }
 };
 
-#ifdef __ANDROID__
+#ifdef HAVE_TOUCHSCREENGUI
 #define SIZE_TAG "size[11,5.5]"
 #else
 #define SIZE_TAG "size[11,5.5,true]" // Fixed size on desktop
 #endif
 
 /****************************************************************************
-
  ****************************************************************************/
 
 const float object_hit_delay = 0.2;
 
 struct FpsControl {
-       u32 last_time, busy_time, sleep_time;
+       FpsControl() : last_time(0), busy_time(0), sleep_time(0) {}
+
+       void reset();
+
+       void limit(IrrlichtDevice *device, f32 *dtime);
+
+       u32 getBusyMs() const { return busy_time / 1000; }
+
+       // all values in microseconds (us)
+       u64 last_time, busy_time, sleep_time;
 };
 
 
@@ -642,15 +620,15 @@ struct GameRunData {
        u16 new_playeritem;
        PointedThing pointed_old;
        bool digging;
-       bool ldown_for_dig;
+       bool punching;
+       bool btn_down_for_dig;
        bool dig_instantly;
        bool digging_blocked;
-       bool left_punch;
        bool reset_jump_timer;
        float nodig_delay_timer;
        float dig_time;
        float dig_time_complete;
-       float repeat_rightclick_timer;
+       float repeat_place_timer;
        float object_hit_delay_timer;
        float time_from_last_punch;
        ClientActiveObject *selected_object;
@@ -673,6 +651,8 @@ struct ClientEventHandler
        void (Game::*handler)(ClientEvent *, CameraOrientation *);
 };
 
+using PausedNodesList = std::vector<std::pair<irr_ptr<scene::IAnimatedMeshSceneNode>, float>>;
+
 class Game {
 public:
        Game();
@@ -680,6 +660,7 @@ class Game {
 
        bool startup(bool *kill,
                        InputHandler *input,
+                       RenderingEngine *rendering_engine,
                        const GameStartData &game_params,
                        std::string &error_message,
                        bool *reconnect,
@@ -689,8 +670,6 @@ class Game {
        void run();
        void shutdown();
 
-       void extendedResourceCleanup();
-
        // Basic initialisation
        bool init(const std::string &map_dir, const std::string &address,
                        u16 port, const SubgameSpec &gamespec);
@@ -714,6 +693,7 @@ class Game {
        bool handleCallbacks();
        void processQueues();
        void updateProfilers(const RunStats &stats, const FpsControl &draw_times, f32 dtime);
+       void updateDebugState();
        void updateStats(RunStats *stats, const FpsControl &draw_times, f32 dtime);
        void updateProfilerGraphs(ProfilerGraph *graph);
 
@@ -724,18 +704,19 @@ class Game {
 
        void dropSelectedItem(bool single_item = false);
        void openInventory();
-       void openSpecialInventory();
+       void openEnderchest();
        void openConsole(float scale, const wchar_t *line=NULL);
        void toggleFreeMove();
        void toggleFreeMoveAlt();
        void togglePitchMove();
        void toggleFast();
        void toggleNoClip();
-       void toggleXray();
-       void toggleFullbright();
        void toggleKillaura();
        void toggleFreecam();
+       void toggleScaffold();
+       void toggleNextItem();
        void toggleCinematic();
+       void toggleBlockBounds();
        void toggleAutoforward();
 
        void toggleMinimap(bool shift_pressed);
@@ -754,9 +735,9 @@ class Game {
        void updatePlayerControl(const CameraOrientation &cam);
        void step(f32 *dtime);
        void processClientEvents(CameraOrientation *cam);
-       void updateCamera(u32 busy_time, f32 dtime);
+       void updateCamera(f32 dtime);
        void updateSound(f32 dtime);
-       void processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug);
+       void processPlayerInteraction(f32 dtime, bool show_hud);
        /*!
         * Returns the object or node the player is pointing at.
         * Also updates the selected thing in the Hud.
@@ -773,7 +754,6 @@ class Game {
        PointedThing updatePointedThing(
                        const core::line3d<f32> &shootline, bool liquids_pointable,
                        bool look_for_object, const v3s16 &camera_offset);
-       void handleKillaura(v3f origin, f32 max_d);
        void handlePointingAtNothing(const ItemStack &playerItem);
        void handlePointingAtNode(const PointedThing &pointed,
                        const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime);
@@ -783,25 +763,21 @@ class Game {
                        const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime);
        void updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
                        const CameraOrientation &cam);
+       void updateShadows();
 
        // Misc
-       void limitFps(FpsControl *fps_timings, f32 *dtime);
-
        void showOverlayMessage(const char *msg, float dtime, int percent,
                        bool draw_clouds = true);
 
        static void freecamChangedCallback(const std::string &setting_name, void *data);
        static void settingChangedCallback(const std::string &setting_name, void *data);
+       static void updateAllMapBlocksCallback(const std::string &setting_name, void *data);
        void readSettings();
 
-       inline bool isKeyDown(GameKeyType k)
-       {
-               return input->isKeyDown(k);
-       }
-       inline bool wasKeyDown(GameKeyType k)
-       {
-               return input->wasKeyDown(k);
-       }
+       bool isKeyDown(GameKeyType k);
+       bool wasKeyDown(GameKeyType k);
+       bool wasKeyPressed(GameKeyType k);
+       bool wasKeyReleased(GameKeyType k);
 
 #ifdef __ANDROID__
        void handleAndroidChatInput();
@@ -815,6 +791,9 @@ class Game {
        void showDeathFormspec();
        void showPauseMenu();
 
+       void pauseAnimation();
+       void resumeAnimation();
+
        // ClientEvent handlers
        void handleClientEvent_None(ClientEvent *event, CameraOrientation *cam);
        void handleClientEvent_PlayerDamage(ClientEvent *event, CameraOrientation *cam);
@@ -835,13 +814,15 @@ class Game {
                CameraOrientation *cam);
        void handleClientEvent_CloudParams(ClientEvent *event, CameraOrientation *cam);
 
-       void updateChat(f32 dtime, const v2u32 &screensize);
+       void updateChat(f32 dtime);
 
        bool nodePlacement(const ItemDefinition &selected_def, const ItemStack &selected_item,
                const v3s16 &nodepos, const v3s16 &neighbourpos, const PointedThing &pointed,
-               const NodeMetadata *meta);
+               const NodeMetadata *meta, bool force = false);
        static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX];
 
+       f32 getSensitivityScaleFactor() const;
+
        InputHandler *input = nullptr;
 
        Client *client = nullptr;
@@ -858,10 +839,10 @@ class Game {
        ISoundManager *sound = nullptr;
        bool sound_is_dummy = false;
        SoundMaker *soundmaker = nullptr;
-       
+
        ChatBackend *chat_backend = nullptr;
        LogOutputBuffer m_chat_log_buf;
-       
+
        EventManager *eventmgr = nullptr;
        QuicktuneShortcutter *quicktune = nullptr;
        bool registration_confirmation_shown = false;
@@ -876,6 +857,9 @@ class Game {
        Hud *hud = nullptr;
        Minimap *mapper = nullptr;
 
+       // Map server hud ids to client hud ids
+       std::unordered_map<u32, u32> m_hud_server_to_client;
+
        GameRunData runData;
        Flags m_flags;
 
@@ -884,14 +868,15 @@ class Game {
           these items (e.g. device)
        */
        IrrlichtDevice *device;
+       RenderingEngine *m_rendering_engine;
        video::IVideoDriver *driver;
        scene::ISceneManager *smgr;
        bool *kill;
        std::string *error_message;
        bool *reconnect_requested;
        scene::ISceneNode *skybox;
+       PausedNodesList paused_animated_nodes;
 
-       bool random_input;
        bool simple_singleplayer_mode;
        /* End 'cache' */
 
@@ -916,7 +901,7 @@ class Game {
        bool m_cache_enable_free_move;
        f32  m_cache_mouse_sensitivity;
        f32  m_cache_joystick_frustum_sensitivity;
-       f32  m_repeat_right_click_time;
+       f32  m_repeat_place_time;
        f32  m_cache_cam_smoothing;
        f32  m_cache_fog_start;
 
@@ -926,8 +911,17 @@ class Game {
 
        bool m_does_lost_focus_pause_game = false;
 
-#ifdef __ANDROID__
+       CameraOrientation cam_view_target = {}; // added by dragonfireclient
+       CameraOrientation cam_view  = {};       // added by dragonfireclient
+
+#if IRRLICHT_VERSION_MT_REVISION < 5
+       int m_reset_HW_buffer_counter = 0;
+#endif
+
+#ifdef HAVE_TOUCHSCREENGUI
        bool m_cache_hold_aux1;
+#endif
+#ifdef __ANDROID__
        bool m_android_chat_open;
 #endif
 };
@@ -935,6 +929,7 @@ extern Game *g_game;
 
 void the_game(bool *kill,
                InputHandler *input,
+               RenderingEngine *rendering_engine,
                const GameStartData &start_data,
                std::string &error_message,
                ChatBackend &chat_backend,