]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/guiEngine.cpp
Fix player:set_animation() in third person view
[dragonfireclient.git] / src / guiEngine.cpp
index d5f528f3b0ed30501a9de0399380b474ee38be6a..e32d629d0da826d84b3e0d2d5964be23ea717240 100644 (file)
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "sound.h"
 #include "sound_openal.h"
 #include "clouds.h"
+#include "httpfetch.h"
 
 #include <IGUIStaticText.h>
 #include <ICameraSceneNode.h>
@@ -156,7 +157,7 @@ GUIEngine::GUIEngine(       irr::IrrlichtDevice* dev,
                m_sound_manager = &dummySoundManager;
 
        //create topleft header
-       core::rect<s32> rect(0, 0, 500, 40);
+       core::rect<s32> rect(0, 0, 500, 20);
        rect += v2s32(4, 0);
        std::string t = std::string("Minetest ") + minetest_version_hash;
 
@@ -165,7 +166,7 @@ GUIEngine::GUIEngine(       irr::IrrlichtDevice* dev,
                rect,false,true,0,-1);
 
        //create formspecsource
-       m_formspecgui = new FormspecFormSource("",&m_formspecgui);
+       m_formspecgui = new FormspecFormSource("");
 
        /* Create menu */
        m_menu =
@@ -175,28 +176,30 @@ GUIEngine::GUIEngine(     irr::IrrlichtDevice* dev,
                                                                m_menumanager,
                                                                0 /* &client */,
                                                                0 /* gamedef */,
-                                                               m_texture_source);
+                                                               m_texture_source,
+                                                               m_formspecgui,
+                                                               m_buttonhandler,
+                                                               NULL);
 
        m_menu->allowClose(false);
        m_menu->lockSize(true,v2u32(800,600));
-       m_menu->setFormSource(m_formspecgui);
-       m_menu->setTextDest(m_buttonhandler);
 
        // Initialize scripting
 
-       infostream<<"GUIEngine: Initializing Lua"<<std::endl;
+       infostream << "GUIEngine: Initializing Lua" << std::endl;
 
        m_script = new MainMenuScripting(this);
 
        try {
-               if (m_data->errormessage != "")
-               {
+               if (m_data->errormessage != "") {
                        m_script->setMainMenuErrorMessage(m_data->errormessage);
                        m_data->errormessage = "";
                }
 
-               if (!loadMainMenuScript())
-                       assert("no future without mainmenu" == 0);
+               if (!loadMainMenuScript()) {
+                       errorstream << "No future without mainmenu" << std::endl;
+                       abort();
+               }
 
                run();
        }
@@ -225,7 +228,8 @@ bool GUIEngine::loadMainMenuScript()
                }
                else {
                        infostream
-                               << "GUIEngine: execution of custom menu failed!"
+                               << "GUIEngine: execution of custom menu: \""
+                               << menuscript << "\" failed!"
                                << std::endl
                                << "\tfalling back to builtin menu"
                                << std::endl;
@@ -286,6 +290,8 @@ void GUIEngine::run()
                        cloudPostProcess();
                else
                        sleep_ms(25);
+
+               m_script->step();
        }
 }
 
@@ -505,51 +511,30 @@ bool GUIEngine::setTexture(texture_layer layer,std::string texturepath) {
 }
 
 /******************************************************************************/
-#if USE_CURL
-static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
-{
-       FILE* targetfile = (FILE*) userp;
-       fwrite(contents,size,nmemb,targetfile);
-       return size * nmemb;
-}
-#endif
 bool GUIEngine::downloadFile(std::string url,std::string target) {
 #if USE_CURL
-       //download file via curl
-       CURL *curl;
+       std::ofstream targetfile(target.c_str(), std::ios::out | std::ios::binary);
 
-       curl = curl_easy_init();
+       if (!targetfile.good()) {
+               return false;
+       }
 
-       if (curl)
-       {
-               CURLcode res;
-               bool retval = true;
-
-               FILE* targetfile = fopen(target.c_str(),"wb");
-
-               if (targetfile) {
-                       curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-                       curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-                       curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
-                       curl_easy_setopt(curl, CURLOPT_WRITEDATA, targetfile);
-                       curl_easy_setopt(curl, CURLOPT_USERAGENT, (std::string("Minetest ")+minetest_version_hash).c_str());
-                       res = curl_easy_perform(curl);
-                       if (res != CURLE_OK) {
-                               errorstream << "File at url \"" << url
-                                       <<"\" not found (" << curl_easy_strerror(res) << ")" <<std::endl;
-                               retval = false;
-                       }
-                       fclose(targetfile);
-               }
-               else {
-                       retval = false;
-               }
+       HTTPFetchRequest fetchrequest;
+       HTTPFetchResult fetchresult;
+       fetchrequest.url = url;
+       fetchrequest.caller = HTTPFETCH_SYNC;
+       httpfetch_sync(fetchrequest, fetchresult);
 
-               curl_easy_cleanup(curl);
-               return retval;
+       if (fetchresult.succeeded) {
+               targetfile << fetchresult.data;
+       } else {
+               return false;
        }
-#endif
+
+       return true;
+#else
        return false;
+#endif
 }
 
 /******************************************************************************/
@@ -576,3 +561,10 @@ void GUIEngine::stopSound(s32 handle)
 {
        m_sound_manager->stopSound(handle);
 }
+
+/******************************************************************************/
+unsigned int GUIEngine::queueAsync(std::string serialized_func,
+               std::string serialized_params) {
+       return m_script->queueAsync(serialized_func, serialized_params);
+}
+