audio_plug-in.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. //------------------------------------------------------------------------------------------------
  2. // version 0.0.2
  3. //------------------------------------------------------------------------------------------------
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include <errno.h>
  7. #include "3d_all.h"
  8. #include "Berusky3d_kofola_interface.h"
  9. #include "adas.h"
  10. #include "audio_plug-in.h"
  11. #include "Object.h"
  12. #include "Tools.h"
  13. extern char pSndDir[MAX_FILENAME];
  14. //------------------------------------------------------------------------------------------------
  15. // Init
  16. //------------------------------------------------------------------------------------------------
  17. void ap_Init(AUDIO_DATA * p_ad)
  18. {
  19. int i;
  20. p_ad->bAudio = 0;
  21. p_ad->Music_Gain = 1.0f;
  22. p_ad->p_Play_List = 0;
  23. p_ad->p_Material = 0;
  24. p_ad->Size_of_Play_List = 0;
  25. p_ad->Size_of_Material_List = 0;
  26. p_ad->Sound_Gain = 1.0f;
  27. p_ad->p_Source = (_SOURCE *) malloc((p_ad->Max_Sources) * sizeof(_SOURCE));
  28. if (!p_ad->p_Source) {
  29. kprintf(1, "Unable to allocate memory for active source database");
  30. return;
  31. }
  32. for (i = 0; i < p_ad->Max_Sources; i++) {
  33. p_ad->p_Source[i].Source = -1;
  34. p_ad->p_Source[i].flag = 1;
  35. }
  36. }
  37. //------------------------------------------------------------------------------------------------
  38. // Release
  39. //------------------------------------------------------------------------------------------------
  40. void ap_Release(AUDIO_DATA * p_ad)
  41. {
  42. free((void *) p_ad->p_Source);
  43. }
  44. //------------------------------------------------------------------------------------------------
  45. // Load sample from the sound directory
  46. //------------------------------------------------------------------------------------------------
  47. int ap_Load_Sample(int iCount, char *cFile)
  48. {
  49. char *pMem;
  50. long size;
  51. char filename[MAX_FILENAME];
  52. FILE *file;
  53. if (!cFile)
  54. return(FALSE);
  55. construct_path(filename, MAX_FILENAME, 2, pSndDir, cFile);
  56. file = fopen(filename, "rb");
  57. if (!file) {
  58. kprintf(1, "%s: %s", filename, strerror(errno));
  59. return(FALSE);
  60. }
  61. fseek(file, 0, SEEK_END);
  62. size = ftell(file);
  63. fseek(file, 0, SEEK_SET);
  64. pMem = (char *) mmalloc(sizeof(*pMem) * size);
  65. if (fread(pMem, sizeof(*pMem), size, file) != (size_t) size) {
  66. kprintf(1, "Cannot read %s: %s", filename, strerror(errno));
  67. fclose(file);
  68. return(FALSE);
  69. }
  70. fclose(file);
  71. return((!iCount) ? adas_Load_FirstMemory("index.dat", pMem, size, cFile):
  72. adas_Load_NextMemory(pMem, size, cFile));
  73. }
  74. //------------------------------------------------------------------------------------------------
  75. // Loads sample List
  76. //------------------------------------------------------------------------------------------------
  77. int ap_Load_Sound_List(AUDIO_DATA * p_ad, char *cFile, int iStart)
  78. {
  79. FILE *file;
  80. char text[MAX_FILENAME];
  81. int c = iStart;
  82. int iMaterial = 0;
  83. if (chdir(p_ber->dir.sound_dir)) {
  84. kprintf(1, "Cannot change directory to %s", p_ber->dir.sound_dir);
  85. return 0;
  86. }
  87. if (!strlen(cFile))
  88. return 0;
  89. construct_path(text, MAX_FILENAME, 2, pSndDir, cFile);
  90. file = fopen(text, "r");
  91. if (!file) {
  92. kprintf(1, "Play list file not found");
  93. return 0;
  94. }
  95. if(fgets(text, 255, file)) {
  96. iMaterial = atoi(text);
  97. while (!feof(file)) {
  98. memset(text, 0, 256);
  99. if(!fgets(text, 255, file) || !text[0])
  100. break;
  101. newline_cut(text);
  102. if(!ap_Load_Sample(c, text)) {
  103. // Loading failed - stop it
  104. break;
  105. }
  106. c++;
  107. }
  108. }
  109. fclose(file);
  110. return iMaterial;
  111. }
  112. //------------------------------------------------------------------------------------------------
  113. // loades play list
  114. //------------------------------------------------------------------------------------------------
  115. int ap_Load_Play_List(char *p_File_Name, AUDIO_DATA * p_ad)
  116. {
  117. FILE *file = 0;
  118. char text[30];
  119. int i;
  120. if (p_ad->p_Play_List)
  121. return 0;
  122. if (chdir(p_ber->dir.music_dir)) {
  123. kprintf(1, "Cannot change directory to %s", p_ber->dir.music_dir);
  124. return 0;
  125. }
  126. file = fopen(p_File_Name, "r");
  127. if (!file) {
  128. MyMessageBox(NULL, "##error_title", "##play_list_error", "");
  129. kprintf(1, "Play list file not found");
  130. return 0;
  131. }
  132. if (fgets(text, 30, file) == NULL) {
  133. kprintf(1, "Cannot read play list file");
  134. MyMessageBox(NULL, "##error_title", "##play_list_error", "");
  135. return 0;
  136. }
  137. p_ad->Size_of_Play_List = atoi(text);
  138. p_ad->p_Play_List = (PLAY_LIST_ITEM *) malloc((p_ad->Size_of_Play_List) * sizeof(PLAY_LIST_ITEM));
  139. if (!p_ad->p_Play_List) {
  140. kprintf(1, "Unable to allocate memory for play list");
  141. MyMessageBox(NULL, "##error_title", "##play_list_error", "");
  142. return 0;
  143. }
  144. for (i = 0; i < p_ad->Size_of_Play_List; i++) {
  145. char *p_name = p_ad->p_Play_List[i].Song_Name;
  146. if (fgets(p_name, 30, file) == NULL) {
  147. kprintf(1, "Cannot read play list file");
  148. MyMessageBox(NULL, "##error_title", "##play_list_error", "");
  149. return 0;
  150. }
  151. newline_cut(p_name);
  152. }
  153. fclose(file);
  154. return 1;
  155. }
  156. //------------------------------------------------------------------------------------------------
  157. // Releases play list
  158. //------------------------------------------------------------------------------------------------
  159. void ap_Release_Play_List(AUDIO_DATA * p_ad)
  160. {
  161. free((void *) p_ad->p_Play_List);
  162. p_ad->p_Play_List = 0;
  163. p_ad->Size_of_Play_List = 0;
  164. }
  165. //------------------------------------------------------------------------------------------------
  166. // Playes ogg song
  167. //------------------------------------------------------------------------------------------------
  168. int ap_Play_Song(int Index, char Random, AUDIO_DATA * p_ad)
  169. {
  170. // char text[256];
  171. char song_name[256];
  172. int song = 0;
  173. FILE *file;
  174. int c = 0;
  175. if (!p_ad->bAudio)
  176. return 1;
  177. if (p_ad->Music_Gain < 0.05f)
  178. return 1;
  179. CHOOSE_SONG:
  180. if (Random)
  181. song = (rand() % (p_ad->Size_of_Play_List - 12)) + 12;
  182. else
  183. song = Index;
  184. strcpy(song_name, p_ber->dir.music_dir);
  185. strcat(song_name, DIR_SLASH_STRING);
  186. strcat(song_name, p_ad->p_Play_List[song].Song_Name);
  187. file = fopen(song_name, "r");
  188. if (!file) {
  189. if (Random) {
  190. c++;
  191. if (c > 10)
  192. return 0;
  193. goto CHOOSE_SONG;
  194. }
  195. }
  196. else
  197. fclose(file);
  198. ogg_open(song_name, p_ad->Music_Gain);
  199. if (!ogg_playback())
  200. return 0;
  201. return 1;
  202. /* adas_Reset_Last_Error();
  203. adas_OGG_Open_Stream(song_name);
  204. if (adas_Get_Last_Error(text,256))
  205. {
  206. MessageBox(p_ad->hWnd,text,"Error",MB_OK);
  207. kprintf(1,"%s",text);
  208. return 0;
  209. }
  210. else
  211. {
  212. float pos[3] = {0.0f,0.0f,0.0f};
  213. adas_OGG_Set_Pitch(1.0f);
  214. adas_OGG_Set_Source_Relative(1);
  215. adas_OGG_Set_Position(pos);
  216. adas_OGG_Set_Velocity(pos);
  217. adas_Reset_Last_Error();
  218. adas_OGG_Play_Stream();
  219. if (adas_Get_Last_Error(text,256))
  220. {
  221. MessageBox(p_ad->hWnd,text,"Error",MB_OK);
  222. kprintf(1,text);
  223. return 0;
  224. }
  225. else
  226. return 1;
  227. }*/
  228. }
  229. //------------------------------------------------------------------------------------------------
  230. // Playes ogg song
  231. //------------------------------------------------------------------------------------------------
  232. int ap_Setup_and_Play_Song(int Index, char Random, AUDIO_DATA * p_ad)
  233. {
  234. /* int flag = 0;
  235. char text[256];
  236. char song_name[256];
  237. int song = 0;
  238. if (!p_ad->bAudio) return 1;
  239. if (p_ad->Music_Gain < 0.05f) return 1;
  240. if (Random)
  241. while(song < 2)
  242. song = rand()%p_ad->Size_of_Play_List;
  243. else
  244. song = Index;
  245. strcpy(song_name, p_ad->Music_Dir);
  246. strcat(song_name, "\\");
  247. strcat(song_name, p_ad->p_Play_List[song].Song_Name);
  248. adas_Reset_Last_Error();
  249. adas_OGG_Open_Stream(song_name);
  250. if (adas_Get_Last_Error(text,256))
  251. {
  252. MessageBox(p_ad->hWnd,text,"Error",MB_OK);
  253. kprintf(1,"%s",text);
  254. return 0;
  255. }
  256. else
  257. {
  258. float pos[3] = {0.0f,0.0f,0.0f};
  259. adas_OGG_Set_Gain(p_ad->Music_Gain);
  260. adas_OGG_Set_Pitch(1.0f);
  261. adas_OGG_Set_Source_Relative(1);
  262. adas_OGG_Set_Position(pos);
  263. adas_OGG_Set_Velocity(pos);
  264. adas_Reset_Last_Error();
  265. adas_OGG_Setup_Stream(&flag);
  266. if (adas_Get_Last_Error(text,256))
  267. {
  268. MessageBox(p_ad->hWnd,text,"Error",MB_OK);
  269. kprintf(1,text);
  270. return 0;
  271. }
  272. else
  273. {
  274. while(!flag)
  275. Sleep(100);
  276. return 1;
  277. }
  278. }*/
  279. return 1;
  280. }
  281. //------------------------------------------------------------------------------------------------
  282. // stops ogg song
  283. //------------------------------------------------------------------------------------------------
  284. void ap_Stop_Song(AUDIO_DATA * p_ad)
  285. {
  286. if (!p_ad->bAudio)
  287. return;
  288. ogg_release();
  289. /*adas_OGG_Stop_Stream();
  290. adas_OGG_Close_Stream(); */
  291. }
  292. //------------------------------------------------------------------------------------------------
  293. // Plays sound
  294. //------------------------------------------------------------------------------------------------
  295. int ap_Play_Sound(int Type, char Relative, char bAmbient, float *p_Pos,
  296. int Wave_Index, EAX_DATA * p_eax, AUDIO_DATA * p_ad)
  297. {
  298. char text[MAX_FILENAME];
  299. ADAS_SOUND_SOURCE_DATA ssd;
  300. int source;
  301. void *p_callback = 0;
  302. if (!karmin_aktivni)
  303. return -1;
  304. if (!p_ad->bAudio)
  305. return -1;
  306. if (bAmbient) {
  307. if (p_ad->Ambient_Gain < 0.05f)
  308. return -1;
  309. ssd.Gain = p_ad->Ambient_Gain;
  310. }
  311. else {
  312. if (p_ad->Sound_Gain < 0.05f)
  313. return -1;
  314. ssd.Gain = p_ad->Sound_Gain;
  315. }
  316. ssd.Owner = -1;
  317. ssd.Pitch = 1.0f;
  318. ssd.Pos[0] = p_Pos[0];
  319. ssd.Pos[1] = p_Pos[1];
  320. ssd.Pos[2] = p_Pos[2];
  321. ssd.Type = Type;
  322. ssd.Velocity[0] = 0.0f;
  323. ssd.Velocity[1] = 0.0f;
  324. ssd.Velocity[2] = 0.0f;
  325. ssd.Wave_Index = Wave_Index;
  326. ssd.Source_Relative = Relative;
  327. ssd.Bounding_Object.Type = UNDEFINED_VALUE;
  328. if (p_eax) {
  329. ssd.Obstruction = p_eax->Obstruction;
  330. ssd.ObstructionLF = p_eax->ObstructionLF;
  331. ssd.out_air_absorbtion = p_eax->out_air_absorbtion;
  332. ssd.out_room = p_eax->out_room;
  333. ssd.out_room_rolloff = p_eax->out_room_rolloff;
  334. ssd.out_roomHF = p_eax->out_roomHF;
  335. ssd.wall_occlusion = p_eax->wall_occlusion;
  336. ssd.wall_occlusion_room = p_eax->wall_occlusion_room;
  337. ssd.wall_occlusionLF = p_eax->wall_occlusionLF;
  338. }
  339. else {
  340. ssd.Obstruction = UNDEFINED_VALUE;
  341. ssd.ObstructionLF = (float) UNDEFINED_VALUE;
  342. ssd.out_air_absorbtion = (float) UNDEFINED_VALUE;
  343. ssd.out_room = UNDEFINED_VALUE;
  344. ssd.out_room_rolloff = (float) UNDEFINED_VALUE;
  345. ssd.out_roomHF = UNDEFINED_VALUE;
  346. ssd.wall_occlusion = UNDEFINED_VALUE;
  347. ssd.wall_occlusion_room = (float) UNDEFINED_VALUE;
  348. ssd.wall_occlusionLF = (float) UNDEFINED_VALUE;
  349. }
  350. adas_Reset_Last_Error();
  351. source = adas_Create_Source(&ssd, &p_callback);
  352. if (adas_Get_Last_Error(text, MAX_FILENAME)) {
  353. //MessageBox(p_ad->hWnd,text,"Error",MB_OK);
  354. kprintf(1, text);
  355. }
  356. else if ((source != -1) && !Relative) {
  357. // je to takovy cudny, ze zvuky s relativni pozici se nepocitaji, ale
  358. // zatim to nevadi. Uvidime, jestli to tak pujde dal. Jestli, musim
  359. // pridat priznak
  360. p_ad->p_Source[source].Source = source;
  361. p_ad->p_Source[source].flag = 1;
  362. *(char **) p_callback = &p_ad->p_Source[source].flag;
  363. }
  364. else if (p_callback)
  365. *(char **) p_callback = NULL;
  366. return source;
  367. }
  368. //------------------------------------------------------------------------------------------------
  369. // translates real position of object to logical(square map) posiiton
  370. //------------------------------------------------------------------------------------------------
  371. void ap_Translate_Position(float *p_real, int *p_log)
  372. {
  373. p_log[0] = (int) floor(p_real[0] / 2.0f);
  374. p_log[2] = (int) floor(p_real[1] / 2.0f);
  375. p_log[1] = (int) floor(p_real[2] / 2.0f);
  376. }
  377. //------------------------------------------------------------------------------------------------
  378. // makes normal vertor
  379. //------------------------------------------------------------------------------------------------
  380. void ap_Normal_Vector(float *v)
  381. {
  382. float size =
  383. (float) sqrt((v[0]) * (v[0]) + (v[1]) * (v[1]) + (v[2]) * (v[2]));
  384. if (size == 0)
  385. return;
  386. v[0] /= size;
  387. v[1] /= size;
  388. v[2] /= size;
  389. }
  390. //------------------------------------------------------------------------------------------------
  391. // count environment
  392. //------------------------------------------------------------------------------------------------
  393. void ap_Count_Environment(AUDIO_DATA * p_ad, void *p_Level)
  394. {
  395. int i;
  396. float s_pos[3], l_pos[3], v[3], size;
  397. int sl_pos[3], lp[3], material;
  398. char end, t_end;
  399. long m_pos;
  400. LEVELINFO *p_L = (LEVELINFO *) p_Level;
  401. for (i = 0; i < p_ad->Max_Sources; i++) {
  402. if (p_ad->p_Source[i].Source != -1) {
  403. if (!p_ad->p_Source[i].flag) {
  404. p_ad->p_Source[i].Source = -1;
  405. }
  406. else {
  407. adas_Get_Source_Position(p_ad->p_Source[i].Source, s_pos);
  408. adas_Get_Listener_Position(l_pos);
  409. v[0] = l_pos[0] - s_pos[0];
  410. v[1] = l_pos[1] - s_pos[1];
  411. v[2] = l_pos[2] - s_pos[2];
  412. // jestlize je vzdalenist vetsi nez 15, nema smysl pokracovat,
  413. // protoze okluze se tejne vzhledem ke vzdalenosti neprojevi
  414. size = (float) sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
  415. if (size > 15)
  416. continue;
  417. ap_Translate_Position(s_pos, sl_pos);
  418. if (sl_pos[0] > (p_L->Size[0] - 1) ||
  419. sl_pos[0] < 0 ||
  420. sl_pos[1] > (p_L->Size[1] - 1) ||
  421. sl_pos[1] < 0 || sl_pos[2] > (p_L->Size[2] - 1) || sl_pos[2] < 0)
  422. continue;
  423. ap_Normal_Vector(v);
  424. lp[0] = sl_pos[0];
  425. lp[1] = sl_pos[1];
  426. lp[2] = sl_pos[2];
  427. t_end = 0;
  428. while (!t_end) {
  429. end = 0;
  430. //posun o kosticku
  431. while (!end) {
  432. s_pos[0] += 0.1f * v[0];
  433. s_pos[1] += 0.1f * v[1];
  434. s_pos[2] += 0.1f * v[2];
  435. ap_Translate_Position(s_pos, sl_pos);
  436. if (lp[0] != sl_pos[0] ||
  437. lp[1] != sl_pos[1] || lp[2] != sl_pos[2])
  438. end = 1;
  439. }
  440. lp[0] = sl_pos[0];
  441. lp[1] = sl_pos[1];
  442. lp[2] = sl_pos[2];
  443. if (sl_pos[0] > (p_L->Size[0] - 1) ||
  444. sl_pos[0] < 0 ||
  445. sl_pos[1] > (p_L->Size[1] - 1) ||
  446. sl_pos[1] < 0 ||
  447. sl_pos[2] > (p_L->Size[2] - 1) || sl_pos[2] < 0) {
  448. /*
  449. adas_Set_Source_Obstruction(PARTICULAR_SOUND_SOURCE,
  450. UNDEFINED_VALUE, p_ad->p_Source[i].Source,
  451. EAXBUFFER_DEFAULTOBSTRUCTION);
  452. adas_Set_Source_ObstructionLF(PARTICULAR_SOUND_SOURCE,
  453. UNDEFINED_VALUE, p_ad->p_Source[i].Source,
  454. EAXBUFFER_DEFAULTOBSTRUCTIONLFRATIO);
  455. */
  456. t_end = 1;
  457. break;
  458. }
  459. m_pos = sl_pos[0] + sl_pos[1] * p_L->Size[0] +
  460. sl_pos[2] * p_L->Size[0] * p_L->Size[1];
  461. if (p_L->Level[m_pos])
  462. break;
  463. }
  464. if (!t_end) {
  465. if (p_L->Level[m_pos]) {
  466. material = p_L->Level[m_pos]->p_Object->Material - 1;
  467. if (material > 0) {
  468. material--;
  469. /*
  470. adas_Set_Source_Obstruction(PARTICULAR_SOUND_SOURCE,
  471. UNDEFINED_VALUE, p_ad->p_Source[i].Source,
  472. p_ad->p_Material[material].Obstruction);
  473. adas_Set_Source_ObstructionLF(PARTICULAR_SOUND_SOURCE,
  474. UNDEFINED_VALUE, p_ad->p_Source[i].Source,
  475. p_ad->p_Material[material].ObstructionLF);
  476. */
  477. }
  478. }
  479. else {
  480. /*
  481. adas_Set_Source_Obstruction(PARTICULAR_SOUND_SOURCE,
  482. UNDEFINED_VALUE, p_ad->p_Source[i].Source,
  483. EAXBUFFER_DEFAULTOBSTRUCTION);
  484. adas_Set_Source_ObstructionLF(PARTICULAR_SOUND_SOURCE,
  485. UNDEFINED_VALUE, p_ad->p_Source[i].Source,
  486. EAXBUFFER_DEFAULTOBSTRUCTIONLFRATIO);
  487. */
  488. }
  489. }
  490. }
  491. }
  492. }
  493. }
  494. //------------------------------------------------------------------------------------------------
  495. // loades material list
  496. //------------------------------------------------------------------------------------------------
  497. int ap_Load_Material_List(char *p_File_Name, AUDIO_DATA * p_ad)
  498. {
  499. FILE *file = 0;
  500. FILE *Material_file = 0;
  501. char text[30] = "", filename[MAX_FILENAME];
  502. int i;
  503. if (p_ad->p_Material)
  504. return 0;
  505. construct_path(filename, MAX_FILENAME, 2, pSndDir, p_File_Name);
  506. file = fopen(filename, "r");
  507. if (!file) {
  508. //MessageBox(p_ad->hWnd,"Material list file not found","Error", MB_OK);
  509. MyMessageBox(NULL, "##error_title", "##material_list_error", "");
  510. kprintf(1, "Material list file not found");
  511. return 0;
  512. }
  513. if (!fgets(text, 30, file)) {
  514. MyMessageBox(NULL, "##error_title", "##material_list_error", "");
  515. kprintf(1, "Cannot read material list file");
  516. fclose(file);
  517. return 0;
  518. }
  519. p_ad->Size_of_Material_List = atoi(text);
  520. p_ad->p_Material =
  521. (MATERIAL_LIST_ITEM *) malloc((p_ad->Size_of_Material_List) *
  522. sizeof(MATERIAL_LIST_ITEM));
  523. if (!p_ad->p_Material) {
  524. //MessageBox(p_ad->hWnd,"Unable to allocate memory for material list","Error",MB_OK);
  525. kprintf(1, "Unable to allocate memory for material list");
  526. MyMessageBox(NULL, "##error_title", "##material_list_error", "");
  527. return 0;
  528. }
  529. for (i = 0; i < p_ad->Size_of_Material_List; i++) {
  530. if(!fgets(text, 30, file))
  531. break;
  532. newline_cut(text);
  533. construct_path(filename, MAX_FILENAME, 2, pSndDir, text);
  534. Material_file = fopen(filename, "rb");
  535. if (!Material_file) {
  536. //MessageBox(p_ad->hWnd,error,"Error", MB_OK);
  537. kprintf(1, "%s not found", text);
  538. }
  539. else {
  540. size_t ret =
  541. fread(&p_ad->p_Material[i], sizeof(MATERIAL_LIST_ITEM), 1,
  542. Material_file);
  543. fclose(Material_file);
  544. if (ret != 1)
  545. kprintf(1, "cannot read %s", text);
  546. }
  547. }
  548. fclose(file);
  549. return 1;
  550. }
  551. //------------------------------------------------------------------------------------------------
  552. // Releases materail list
  553. //------------------------------------------------------------------------------------------------
  554. void ap_Release_Material_List(AUDIO_DATA * p_ad)
  555. {
  556. free((void *) p_ad->p_Material);
  557. p_ad->p_Material = 0;
  558. p_ad->Size_of_Material_List = 0;
  559. }
  560. //------------------------------------------------------------------------------------------------
  561. // load environment
  562. //------------------------------------------------------------------------------------------------
  563. int ap_Load_Environment(char *p_Env_Name, void *p_Level, AUDIO_DATA * p_ad)
  564. {
  565. char filename[MAX_FILENAME];
  566. FILE *file;
  567. LEVELINFO *p_L = (LEVELINFO *) p_Level;
  568. construct_path(filename, MAX_FILENAME, 2, pSndDir, p_Env_Name);
  569. file = fopen(filename, "rb");
  570. if (file) {
  571. size_t ret =
  572. fread(&p_L->Environment, sizeof(ENVIRONMENT), 1, file);
  573. fclose(file);
  574. if (ret != 1) {
  575. kprintf(1, "cannot read %s", filename);
  576. return 0;
  577. }
  578. return 1;
  579. }
  580. else {
  581. kprintf(1, "%s not found", filename);
  582. return 0;
  583. }
  584. }