Browse Source

+ Added support for parsing [COMBO] options to add proper define macros to the shader code

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
Alexis Maiquez 7 năm trước cách đây
mục cha
commit
d05e751839
2 tập tin đã thay đổi với 63 bổ sung và 2 xóa
  1. 57 2
      wallpaperengine/shaders/compiler.cpp
  2. 6 0
      wallpaperengine/shaders/compiler.h

+ 57 - 2
wallpaperengine/shaders/compiler.cpp

@@ -356,8 +356,27 @@ namespace wp
                     if (this->peekString ("//", it) == true)
                     {
                         std::string::const_iterator begin = it - 2;
-                        this->ignoreUpToNextLineFeed (it);
-                        this->m_compiledContent.append (begin, it);
+                        // is there a COMBO mark to take care of?
+                        this->ignoreSpaces (it);
+
+                        if (this->peekString ("[COMBO]", it) == true)
+                        {
+                            // parse combo json data to define the proper variables
+                            this->ignoreSpaces (it);
+                            begin = it;
+                            this->ignoreUpToNextLineFeed (it);
+
+                            std::string configuration; configuration.append (begin, it);
+
+                            this->m_compiledContent += "// [COMBO] " + configuration;
+
+                            this->parseComboConfiguration (configuration); BREAK_IF_ERROR;
+                        }
+                        else
+                        {
+                            this->ignoreUpToNextLineFeed (it);
+                            this->m_compiledContent.append (begin, it);
+                        }
                     }
                     else if (this->peekString ("/*", it) == true)
                     {
@@ -408,6 +427,41 @@ namespace wp
         #undef BREAK_IF_ERROR
         }
 
+        void compiler::parseComboConfiguration (const std::string& content)
+        {
+            json data = json::parse (content);
+            json::const_iterator combo = data.find ("combo");
+            json::const_iterator defvalue = data.find ("default");
+
+            // add line feed just in case
+            this->m_compiledContent += "\n";
+
+            // {"material":"ui_editor_properties_perspective","combo":"PERSPECTIVE","type":"options","default":0}
+
+            if (combo == data.end () || defvalue == data.end ())
+            {
+                wp::irrlicht::device->getLogger ()->log ("Cannot parse combo information", irr::ELL_ERROR);
+                return;
+            }
+
+            if ((*defvalue).is_number_float ())
+            {
+                this->m_compiledContent += "#define " + (*combo).get <std::string> () + " " + std::to_string ((*defvalue).get <irr::f32> ()) + "\n";
+            }
+            else if ((*defvalue).is_number_integer ())
+            {
+                this->m_compiledContent += "#define " + (*combo).get <std::string> () + " " + std::to_string ((*defvalue).get <irr::s32> ()) + "\n";
+            }
+            else if ((*defvalue).is_string ())
+            {
+                this->m_compiledContent += "#define " + (*combo).get <std::string> () + " " + (*defvalue).get <std::string> () + "\n";
+            }
+            else
+            {
+                wp::irrlicht::device->getLogger ()->log ("Cannot parse combo information, unknown type", irr::ELL_ERROR);
+            }
+        }
+
         void compiler::parseParameterConfiguration (const std::string& type, const std::string& name, const std::string& content)
         {
             json data = json::parse (content);
@@ -418,6 +472,7 @@ namespace wp
             // this is not a real parameter
             if (material == data.end () || defvalue == data.end ())
             {
+                wp::irrlicht::device->getLogger ()->log ("Cannot parse parameter info for ", name.c_str (), irr::ELL_ERROR);
                 return;
             }
 

+ 6 - 0
wallpaperengine/shaders/compiler.h

@@ -186,6 +186,12 @@ namespace wp
              * @return Whether the character in the current position is a number or not
              */
             bool isNumeric (std::string::const_iterator& it);
+            /**
+             * Parses a COMBO value to add the proper define to the code
+             *
+             * @param content The parameter configuration
+             */
+            void parseComboConfiguration (const std::string& content);
             /**
              * Parses a parameter extra metadata created by wallpaper engine
              *