]> git.lizzy.rs Git - minetest.git/blobdiff - src/client/fontengine.h
Fix lighting of upright_sprite entities (#12336)
[minetest.git] / src / client / fontengine.h
index 865b2d3ffcb1346a37e4be3d5bb7d7f6eeb29d79..78608e517906c2f2471e68807af8608648def98d 100644 (file)
@@ -20,21 +20,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #pragma once
 
 #include <map>
-#include <vector>
 #include "util/basic_macros.h"
+#include "irrlichttypes.h"
 #include <IGUIFont.h>
 #include <IGUISkin.h>
 #include <IGUIEnvironment.h>
 #include "settings.h"
+#include "threading/mutex_auto_lock.h"
 
 #define FONT_SIZE_UNSPECIFIED 0xFFFFFFFF
 
 enum FontMode : u8 {
        FM_Standard = 0,
        FM_Mono,
-       FM_Fallback,
-       FM_Simple,
-       FM_SimpleMono,
+       _FM_Fallback, // do not use directly
        FM_MaxMode,
        FM_Unspecified
 };
@@ -46,9 +45,9 @@ struct FontSpec {
                bold(bold),
                italic(italic) {}
 
-       u16 getHash()
+       u16 getHash() const
        {
-               return (mode << 2) | (bold << 1) | italic;
+               return (mode << 2) | (static_cast<u8>(bold) << 1) | static_cast<u8>(italic);
        }
 
        unsigned int size;
@@ -61,7 +60,7 @@ class FontEngine
 {
 public:
 
-       FontEngine(Settings* main_settings, gui::IGUIEnvironment* env);
+       FontEngine(gui::IGUIEnvironment* env);
 
        ~FontEngine();
 
@@ -127,34 +126,30 @@ class FontEngine
        /** get font size for a specific mode */
        unsigned int getFontSize(FontMode mode);
 
-       /** initialize font engine */
-       void initialize(Settings* main_settings, gui::IGUIEnvironment* env);
-
        /** update internal parameters from settings */
        void readSettings();
 
 private:
+       irr::gui::IGUIFont *getFont(FontSpec spec, bool may_fail);
+
        /** update content of font cache in case of a setting change made it invalid */
        void updateFontCache();
 
-       /** initialize a new font */
+       /** initialize a new TTF font */
        gui::IGUIFont *initFont(const FontSpec &spec);
 
-       /** initialize a font without freetype */
-       gui::IGUIFont *initSimpleFont(const FontSpec &spec);
-
        /** update current minetest skin with font changes */
        void updateSkin();
 
        /** clean cache */
        void cleanCache();
 
-       /** pointer to settings for registering callbacks or reading config */
-       Settings* m_settings = nullptr;
-
        /** pointer to irrlicht gui environment */
        gui::IGUIEnvironment* m_env = nullptr;
 
+       /** mutex used to protect font init and cache */
+       std::recursive_mutex m_font_mutex;
+
        /** internal storage for caching fonts of different size */
        std::map<unsigned int, irr::gui::IGUIFont*> m_font_cache[FM_MaxMode << 2];
 
@@ -165,8 +160,8 @@ class FontEngine
        bool m_default_bold = false;
        bool m_default_italic = false;
 
-       /** current font engine mode */
-       FontMode m_currentMode = FM_Standard;
+       /** default font engine mode (fixed) */
+       static const FontMode m_currentMode = FM_Standard;
 
        DISABLE_CLASS_COPY(FontEngine);
 };