Removed redundant call of songs_stop_all() when starting credits; Added failsafe for loop in case MHDR_DONE flag is not properly set by MIDI device; Added more verbosity for hmp_reset()

This commit is contained in:
zicodxx 2012-04-12 19:45:45 +02:00
parent e45dd761b3
commit 2c7a8b419b
4 changed files with 63 additions and 11 deletions

View file

@ -3,6 +3,7 @@ D2X-Rebirth Changelog
20120412
--------
main/collide.c, main/gameseq.c, main/multi.c, main/multi.h, main/net_udp.c: Fixed some Multiplayer bugs: Reactor invulnerable time did not checked for hours spent in level so reactor would become invulnerable again after 60 minutes; Fixed the fix (heh) for misordered explode/reappear packets; Reset Player_eggs_dropped when initializing new ship so eggs are properly dropped when player disconnects two times without respawning; Cleaned player disconnecting a little bit and made code more straightforward
main/menu.c, misc/hmp.c: Removed redundant call of songs_stop_all() when starting credits; Added failsafe for loop in case MHDR_DONE flag is not properly set by MIDI device; Added more verbosity for hmp_reset()
20120411
--------

View file

@ -1139,7 +1139,7 @@ int find_homing_object_complete(vms_vector *curpos, object *tracker, int track_o
}
}
}
printf("best objnum %i\n",best_objnum);
}
return best_objnum;

View file

@ -624,7 +624,6 @@ int do_option ( int select)
do_options_menu();
break;
case MENU_SHOW_CREDITS:
songs_stop_all();
credits_show(NULL);
break;
#ifndef RELEASE

View file

@ -12,6 +12,7 @@
#include "hmp.h"
#include "u_mem.h"
#include "console.h"
#include "timer.h"
#ifdef WORDS_BIGENDIAN
#define MIDIINT(x) (x)
@ -141,7 +142,7 @@ void hmp_stop(hmp_file *hmp)
//PumpMessages();
midiStreamStop(hmp->hmidi);
while (hmp->bufs_in_mm)
Sleep(0);
timer_delay(1);
}
while ((mhdr = hmp->evbuf)) {
midiOutUnprepareHeader((HMIDIOUT)hmp->hmidi, mhdr, sizeof(MIDIHDR));
@ -548,16 +549,67 @@ void hmp_reset()
mhdr.lpData = GS_Reset;
mhdr.dwBufferLength = sizeof(GS_Reset);
mhdr.dwFlags = 0;
midiOutPrepareHeader(hmidi, &mhdr, sizeof(MIDIHDR));
midiOutLongMsg(hmidi, &mhdr, sizeof(MIDIHDR));
while (!(mhdr.dwFlags & MHDR_DONE));
midiOutUnprepareHeader(hmidi, &mhdr, sizeof(MIDIHDR));
if ((rval = midiOutPrepareHeader(hmidi, &mhdr, sizeof(MIDIHDR))) == MMSYSERR_NOERROR)
{
if ((rval = midiOutLongMsg(hmidi, &mhdr, sizeof(MIDIHDR))) == MMSYSERR_NOERROR)
{
fix64 wait_done = timer_query();
while (!(mhdr.dwFlags & MHDR_DONE))
{
timer_update();
if (timer_query() >= wait_done + F1_0)
{
con_printf(CON_DEBUG, "hmp_reset: Timeout waiting for MHDR_DONE\n");
break;
}
}
}
else
{
switch (rval)
{
case MIDIERR_NOTREADY:
con_printf(CON_DEBUG, "midiOutLongMsg Error: the hardware is busy with other data.\n");
break;
case MIDIERR_UNPREPARED:
con_printf(CON_DEBUG, "midiOutLongMsg Error: the buffer pointed to by lpMidiOutHdr has not been prepared.\n");
break;
case MMSYSERR_INVALHANDLE:
con_printf(CON_DEBUG, "midiOutLongMsg Error: the specified device handle is invalid.\n");
break;
case MMSYSERR_INVALPARAM:
con_printf(CON_DEBUG, "midiOutLongMsg Error: the specified pointer or structure is invalid.\n");
break;
default:
con_printf(CON_DEBUG, "midiOutLongMsg Error code %i\n",rval);
break;
}
}
midiOutUnprepareHeader(hmidi, &mhdr, sizeof(MIDIHDR));
Sleep( 50 );
for (channel = 0; channel < 16; channel++)
midiOutShortMsg(hmidi, (DWORD)(channel | MIDI_CONTROL_CHANGE << 4 | MIDI_VOLUME << 8 | (100 * midi_volume / MIDI_VOLUME_SCALE) << 16));
timer_delay(F1_0/20);
for (channel = 0; channel < 16; channel++)
midiOutShortMsg(hmidi, (DWORD)(channel | MIDI_CONTROL_CHANGE << 4 | MIDI_VOLUME << 8 | (100 * midi_volume / MIDI_VOLUME_SCALE) << 16));
}
else
{
switch (rval)
{
case MMSYSERR_INVALHANDLE:
con_printf(CON_DEBUG, "midiOutPrepareHeader Error: The specified device handle is invalid.\n");
break;
case MMSYSERR_INVALPARAM:
con_printf(CON_DEBUG, "midiOutPrepareHeader Error: The specified address is invalid or the given stream buffer is greater than 64K.\n");
break;
case MMSYSERR_NOMEM:
con_printf(CON_DEBUG, "midiOutPrepareHeader Error: The system is unable to allocate or lock memory.\n");
break;
default:
con_printf(CON_DEBUG, "midiOutPrepareHeader Error code %i\n",rval);
break;
}
}
midiOutClose(hmidi);
}
#endif