]> git.lizzy.rs Git - minetest.git/blobdiff - src/main.cpp
Fix lava damage on player's upper body
[minetest.git] / src / main.cpp
index 94382ec6085eaaa8575e7161cc9862e3f9b9b5ec..e5c8a55d38571c17683350f913cd1f011ed2de5f 100644 (file)
@@ -76,6 +76,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "subgame.h"
 #include "quicktune.h"
 #include "serverlist.h"
+#include "sound.h"
+#include "sound_openal.h"
 
 /*
        Settings.
@@ -200,7 +202,49 @@ u32 getTime(TimePrecision prec) {
                return 0;
        return g_timegetter->getTime(prec);
 }
+#endif
+
+//Client side main menu music fetcher
+#ifndef SERVER
+class MenuMusicFetcher: public OnDemandSoundFetcher
+{
+       std::set<std::string> m_fetched;
+public:
 
+       void fetchSounds(const std::string &name,
+                       std::set<std::string> &dst_paths,
+                       std::set<std::string> &dst_datas)
+       {
+               if(m_fetched.count(name))
+                       return;
+               m_fetched.insert(name);
+               std::string base;
+               base = porting::path_share + DIR_DELIM + "sounds";
+               dst_paths.insert(base + DIR_DELIM + name + ".ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".0.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".1.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".2.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".3.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".4.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".5.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".6.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".7.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".8.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".9.ogg");
+               base = porting::path_user + DIR_DELIM + "sounds";
+               dst_paths.insert(base + DIR_DELIM + name + ".ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".0.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".1.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".2.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".3.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".4.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".5.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".6.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".7.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".8.ogg");
+               dst_paths.insert(base + DIR_DELIM + name + ".9.ogg");
+               }
+};
 #endif
 
 class StderrLogOutput: public ILogOutput
@@ -619,12 +663,14 @@ class RandomInputHandler : public InputHandler
 struct MenuTextures
 {
        std::string current_gameid;
+       bool global_textures;
        video::ITexture *background;
        video::ITexture *overlay;
        video::ITexture *header;
        video::ITexture *footer;
 
        MenuTextures():
+               global_textures(false),
                background(NULL),
                overlay(NULL),
                header(NULL),
@@ -634,28 +680,49 @@ struct MenuTextures
        static video::ITexture* getMenuTexture(const std::string &tname,
                        video::IVideoDriver* driver, const SubgameSpec *spec)
        {
-               std::string path;
-               // eg. minetest_menu_background.png (for texture packs)
-               std::string pack_tname = spec->id + "_menu_" + tname + ".png";
-               path = getTexturePath(pack_tname);
-               if(path != "")
-                       return driver->getTexture(path.c_str());
-               // eg. games/minetest_game/menu/background.png
-               path = getImagePath(spec->path + DIR_DELIM + "menu" + DIR_DELIM + tname + ".png");
-               if(path != "")
-                       return driver->getTexture(path.c_str());
+               if(spec){
+                       std::string path;
+                       // eg. minetest_menu_background.png (for texture packs)
+                       std::string pack_tname = spec->id + "_menu_" + tname + ".png";
+                       path = getTexturePath(pack_tname);
+                       if(path != "")
+                               return driver->getTexture(path.c_str());
+                       // eg. games/minetest_game/menu/background.png
+                       path = getImagePath(spec->path + DIR_DELIM + "menu" + DIR_DELIM + tname + ".png");
+                       if(path != "")
+                               return driver->getTexture(path.c_str());
+               } else {
+                       std::string path;
+                       // eg. menu_background.png
+                       std::string pack_tname = "menu_" + tname + ".png";
+                       path = getTexturePath(pack_tname);
+                       if(path != "")
+                               return driver->getTexture(path.c_str());
+               }
                return NULL;
        }
 
-       void update(video::IVideoDriver* driver, const SubgameSpec *spec)
+       void update(video::IVideoDriver* driver, const SubgameSpec *spec, int tab)
        {
-               if(spec->id == current_gameid)
-                       return;
-               current_gameid = spec->id;
-               background = getMenuTexture("background", driver, spec);
-               overlay = getMenuTexture("overlay", driver, spec);
-               header = getMenuTexture("header", driver, spec);
-               footer = getMenuTexture("footer", driver, spec);
+               if(tab == TAB_SINGLEPLAYER){
+                       if(spec->id == current_gameid)
+                               return;
+                       current_gameid = spec->id;
+                       global_textures = false;
+                       background = getMenuTexture("background", driver, spec);
+                       overlay = getMenuTexture("overlay", driver, spec);
+                       header = getMenuTexture("header", driver, spec);
+                       footer = getMenuTexture("footer", driver, spec);
+               } else {
+                       if(global_textures)
+                               return;
+                       current_gameid = "";
+                       global_textures = true;
+                       background = getMenuTexture("background", driver, NULL);
+                       overlay = getMenuTexture("overlay", driver, NULL);
+                       header = getMenuTexture("header", driver, NULL);
+                       footer = getMenuTexture("footer", driver, NULL);
+               }
        }
 };
 
@@ -1734,7 +1801,7 @@ int main(int argc, char *argv[])
                                const SubgameSpec *menugame = getMenuGame(menudata);
 
                                MenuTextures menutextures;
-                               menutextures.update(driver, menugame);
+                               menutextures.update(driver, menugame, menudata.selected_tab);
 
                                if(skip_main_menu == false)
                                {
@@ -1776,6 +1843,18 @@ int main(int argc, char *argv[])
                                        // Time is in milliseconds, for clouds
                                        u32 lasttime = device->getTimer()->getTime();
 
+                                       MenuMusicFetcher soundfetcher;
+                                       ISoundManager *sound = NULL;
+#if USE_SOUND
+                                       sound = createOpenALSoundManager(&soundfetcher);
+#endif
+                                       if(!sound)
+                                               sound = &dummySoundManager;
+                                       SimpleSoundSpec spec;
+                                       spec.name = "main_menu";
+                                       spec.gain = 1;
+                                       s32 handle = sound->playSound(spec, true);
+
                                        infostream<<"Created main menu"<<std::endl;
 
                                        while(device->run() && kill == false)
@@ -1785,7 +1864,7 @@ int main(int argc, char *argv[])
 
                                                // Game can be selected in the menu
                                                menugame = getMenuGame(menudata);
-                                               menutextures.update(driver, menugame);
+                                               menutextures.update(driver, menugame, menu->getTab());
                                                // Clouds for the main menu
                                                bool cloud_menu_background = g_settings->getBool("menu_clouds");
                                                if(menugame){
@@ -1857,7 +1936,12 @@ int main(int argc, char *argv[])
                                                        sleep_ms(25);
                                                }
                                        }
-                                       
+                                       sound->stopSound(handle);
+                                       if(sound != &dummySoundManager){
+                                               delete sound;
+                                               sound = NULL;
+                                       }
+
                                        infostream<<"Dropping main menu"<<std::endl;
 
                                        menu->drop();
@@ -2063,6 +2147,10 @@ int main(int argc, char *argv[])
        */
        device->drop();
 
+#if USE_FREETYPE
+       font->drop();
+#endif
+
 #endif // !SERVER
        
        // Update configuration file