Imported kball_final_src_16dec2004.tar.gz
[kball.git] / src / musiclvl.cpp
blobf4f13b8df270b3b45714f887cc715014f4e2c217
1 // ------------------------------------------------------------------
2 // musiclvl.cpp
3 // System for handling level's music
4 // ------------------------------------------------------------------
5 // By Kronoman - In loving memory of my father
6 // Copyright (c) 2004, Kronoman
7 // ------------------------------------------------------------------
9 #include <allegro.h>
10 #include <dumb.h>
12 #include "musiclvl.h"
13 #include "gerror.h"
14 #include "filehelp.h"
16 CMusicLvl::CMusicLvl()
18 music_in_ram = NULL;
19 data_loaded = NULL;
20 free_memory();
23 CMusicLvl::~CMusicLvl()
25 free_memory();
29 void CMusicLvl::free_memory()
31 if (data_loaded != NULL)
32 unload_datafile_object(data_loaded);
34 data_loaded = NULL;
36 music_in_ram = NULL;
38 file_loaded[0] = '\0';
40 index_loaded = -1;
43 DUH *CMusicLvl::get_music(char *filename, int index)
45 char str[1024];
46 DATAFILE *data = NULL;
47 char tmp_file_buf[2048];
49 where_is_the_filename(tmp_file_buf, filename);
51 // use the cache if it is present
52 if (index == index_loaded)
54 if (ustrcmp(tmp_file_buf, file_loaded) == 0)
55 return music_in_ram;
58 free_memory();
60 usprintf(str, "M%d_XM", index);
61 data = load_datafile_object(tmp_file_buf, str);
63 if (data != NULL)
65 usprintf(file_loaded, "%s", tmp_file_buf);
66 index_loaded = index;
68 data_loaded = data;
69 music_in_ram = (DUH *)data->dat;
71 return music_in_ram; // found OK
75 return NULL; // not found