Skip to content

Commit 9575b0a

Browse files
RealBadAngelPilzAdam
authored andcommitted
Add code to play main_menu.ogg in main menu
1 parent 6911a7d commit 9575b0a

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

src/main.cpp

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
7676
#include "subgame.h"
7777
#include "quicktune.h"
7878
#include "serverlist.h"
79+
#include "sound.h"
80+
#include "sound_openal.h"
7981

8082
/*
8183
Settings.
@@ -200,7 +202,49 @@ u32 getTime(TimePrecision prec) {
200202
return 0;
201203
return g_timegetter->getTime(prec);
202204
}
205+
#endif
206+
207+
//Client side main menu music fetcher
208+
#ifndef SERVER
209+
class MenuMusicFetcher: public OnDemandSoundFetcher
210+
{
211+
std::set<std::string> m_fetched;
212+
public:
203213

214+
void fetchSounds(const std::string &name,
215+
std::set<std::string> &dst_paths,
216+
std::set<std::string> &dst_datas)
217+
{
218+
if(m_fetched.count(name))
219+
return;
220+
m_fetched.insert(name);
221+
std::string base;
222+
base = porting::path_share + DIR_DELIM + "sounds";
223+
dst_paths.insert(base + DIR_DELIM + name + ".ogg");
224+
dst_paths.insert(base + DIR_DELIM + name + ".0.ogg");
225+
dst_paths.insert(base + DIR_DELIM + name + ".1.ogg");
226+
dst_paths.insert(base + DIR_DELIM + name + ".2.ogg");
227+
dst_paths.insert(base + DIR_DELIM + name + ".3.ogg");
228+
dst_paths.insert(base + DIR_DELIM + name + ".4.ogg");
229+
dst_paths.insert(base + DIR_DELIM + name + ".5.ogg");
230+
dst_paths.insert(base + DIR_DELIM + name + ".6.ogg");
231+
dst_paths.insert(base + DIR_DELIM + name + ".7.ogg");
232+
dst_paths.insert(base + DIR_DELIM + name + ".8.ogg");
233+
dst_paths.insert(base + DIR_DELIM + name + ".9.ogg");
234+
base = porting::path_user + DIR_DELIM + "sounds";
235+
dst_paths.insert(base + DIR_DELIM + name + ".ogg");
236+
dst_paths.insert(base + DIR_DELIM + name + ".0.ogg");
237+
dst_paths.insert(base + DIR_DELIM + name + ".1.ogg");
238+
dst_paths.insert(base + DIR_DELIM + name + ".2.ogg");
239+
dst_paths.insert(base + DIR_DELIM + name + ".3.ogg");
240+
dst_paths.insert(base + DIR_DELIM + name + ".4.ogg");
241+
dst_paths.insert(base + DIR_DELIM + name + ".5.ogg");
242+
dst_paths.insert(base + DIR_DELIM + name + ".6.ogg");
243+
dst_paths.insert(base + DIR_DELIM + name + ".7.ogg");
244+
dst_paths.insert(base + DIR_DELIM + name + ".8.ogg");
245+
dst_paths.insert(base + DIR_DELIM + name + ".9.ogg");
246+
}
247+
};
204248
#endif
205249

206250
class StderrLogOutput: public ILogOutput
@@ -1776,6 +1820,16 @@ int main(int argc, char *argv[])
17761820
// Time is in milliseconds, for clouds
17771821
u32 lasttime = device->getTimer()->getTime();
17781822

1823+
MenuMusicFetcher soundfetcher;
1824+
ISoundManager *sound = NULL;
1825+
sound = createOpenALSoundManager(&soundfetcher);
1826+
if(!sound)
1827+
sound = &dummySoundManager;
1828+
SimpleSoundSpec spec;
1829+
spec.name = "main_menu";
1830+
spec.gain = 1;
1831+
s32 handle = sound->playSound(spec, true);
1832+
17791833
infostream<<"Created main menu"<<std::endl;
17801834

17811835
while(device->run() && kill == false)
@@ -1857,7 +1911,12 @@ int main(int argc, char *argv[])
18571911
sleep_ms(25);
18581912
}
18591913
}
1860-
1914+
sound->stopSound(handle);
1915+
if(sound != &dummySoundManager){
1916+
delete sound;
1917+
sound = NULL;
1918+
}
1919+
18611920
infostream<<"Dropping main menu"<<std::endl;
18621921

18631922
menu->drop();

0 commit comments

Comments
 (0)