void gamesnd_add_sound_slot(int type, int num) { const int increase_by = 5; int i; switch (type) { case GAME_SND: { Assert(Snds != NULL); Assert(num < (Num_game_sounds + increase_by)); if (num >= Num_game_sounds) { Snds = (game_snd*)vm_realloc(Snds, sizeof(game_snd) * (Num_game_sounds + increase_by)); Verify(Snds != NULL); Num_game_sounds += increase_by; // default all new entries for (i = (Num_game_sounds - increase_by); i < Num_game_sounds; i++) { gamesnd_init_struct(&Snds[i]); } } } break; case IFACE_SND: { Assert(Snds_iface != NULL); Assert(num < (Num_game_sounds + increase_by)); if (num >= Num_iface_sounds) { Snds_iface = (game_snd*)vm_realloc(Snds_iface, sizeof(game_snd) * (Num_iface_sounds + increase_by)); Verify(Snds_iface != NULL); Num_iface_sounds += increase_by; Assert(Snds_iface_handle != NULL); Snds_iface_handle = (int*)vm_realloc(Snds_iface_handle, sizeof(int) * Num_iface_sounds); Verify(Snds_iface_handle != NULL); // default all new entries for (i = (Num_iface_sounds - increase_by); i < Num_iface_sounds; i++) { gamesnd_init_struct(&Snds_iface[i]); Snds_iface_handle[i] = -1; } } } break; default: Int3(); } }
// ------------------------------------------------------------------------------------------------- // gamesnd_init_sounds() will initialize the Snds[] and Snds_iface[] arrays // void gamesnd_init_sounds() { int i; // init the gameplay sounds for ( i = 0; i < MAX_GAME_SOUNDS; i++ ) { gamesnd_init_struct(&Snds[i]); } // init the interface sounds for ( i = 0; i < MAX_INTERFACE_SOUNDS; i++ ) { gamesnd_init_struct(&Snds_iface[i]); Snds_iface_handle[i] = -1; } }
// ------------------------------------------------------------------------------------------------- // gamesnd_init_sounds() will initialize the Snds[] and Snds_iface[] arrays // void gamesnd_init_sounds() { int i; if (Snds == NULL) { Snds = (game_snd*)vm_malloc(sizeof(game_snd) * MIN_GAME_SOUNDS); Verify(Snds != NULL); Num_game_sounds = MIN_GAME_SOUNDS; } Assert(Num_game_sounds > 0); // init the gameplay sounds for (i = 0; i < Num_game_sounds; i++) { gamesnd_init_struct(&Snds[i]); } if (Snds_iface == NULL) { Snds_iface = (game_snd*)vm_malloc(sizeof(game_snd) * MIN_INTERFACE_SOUNDS); Verify(Snds_iface != NULL); Num_iface_sounds = MIN_INTERFACE_SOUNDS; Assert(Snds_iface_handle == NULL); Snds_iface_handle = (int*)vm_malloc(sizeof(int) * Num_iface_sounds); Verify(Snds_iface_handle != NULL); } Assert(Num_iface_sounds > 0); // init the interface sounds for (i = 0; i < Num_iface_sounds; i++) { gamesnd_init_struct(&Snds_iface[i]); Snds_iface_handle[i] = -1; } }