From 0e5675d88ab5b47b0ed6a3c873720a6577b018ad Mon Sep 17 00:00:00 2001 From: Taylor Richards Date: Tue, 29 Mar 2005 02:18:47 +0000 Subject: [PATCH] Various 64-bit platform fixes Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) Streaming audio support (big thanks to Pierre Willenbrock!!) Removed dependance on strings.tbl for FS1 since we don't actually need it now --- include/scoring.h | 11 +- include/unix.h | 4 + src/controlconfig/controlsconfig.cpp | 25 +- src/cutscene/cutscenes.cpp | 24 +- src/gamehelp/contexthelp.cpp | 9 +- src/gamehelp/gameplayhelp.cpp | 23 +- src/hud/hudconfig.cpp | 30 +- src/hud/hudmessage.cpp | 9 +- src/localization/localize.cpp | 14 +- src/menuui/barracks.cpp | 32 +- src/menuui/credits.cpp | 15 +- src/menuui/optionsmenu.cpp | 24 +- src/menuui/optionsmenumulti.cpp | 52 +-- src/menuui/playermenu.cpp | 22 +- src/menuui/readyroom.cpp | 40 +- src/menuui/techmenu.cpp | 21 +- src/mission/missionhotkey.cpp | 20 +- src/missionui/missionbrief.cpp | 32 +- src/missionui/missioncmdbrief.cpp | 24 +- src/missionui/missiondebrief.cpp | 29 +- src/missionui/missionshipchoice.cpp | 24 +- src/missionui/missionweaponchoice.cpp | 26 +- src/missionui/redalert.cpp | 24 +- src/network/multi_pinfo.cpp | 26 +- src/network/multiui.cpp | 96 ++--- src/ship/aicode.cpp | 24 ++ src/sound/acm-unix.cpp | 158 ++++++- src/sound/audiostr.cpp | 567 +++++++++++++++++++++----- src/sound/sound.cpp | 15 +- src/stats/medals.cpp | 24 +- 30 files changed, 1017 insertions(+), 427 deletions(-) diff --git a/include/scoring.h b/include/scoring.h index 0a29f82..95e8d61 100644 --- a/include/scoring.h +++ b/include/scoring.h @@ -15,6 +15,13 @@ * Scoring system structures, medals, rank, etc. * * $Log$ + * Revision 1.5 2005/03/29 02:18:47 taylor + * Various 64-bit platform fixes + * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too + * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) + * Streaming audio support (big thanks to Pierre Willenbrock!!) + * Removed dependance on strings.tbl for FS1 since we don't actually need it now + * * Revision 1.4 2003/06/11 18:30:32 taylor * plug memory leaks * @@ -270,8 +277,8 @@ typedef struct scoring_struct { unsigned int missions_flown; // total # of missions flown unsigned int flight_time; // total # of flight hours the player has - time_t last_flown; // last time the player has flown - time_t last_backup; // so we can easily call scoring_level_backout() + fs_time_t last_flown; // last time the player has flown + fs_time_t last_backup; // so we can easily call scoring_level_backout() // Mission total int m_medal_earned; // which medal (if any) earned this mission diff --git a/include/unix.h b/include/unix.h index 0ed1678..473a36c 100644 --- a/include/unix.h +++ b/include/unix.h @@ -39,7 +39,11 @@ #define PASCAL #define CALLBACK +#if ( defined(__x86_64__) || defined(_WIN64) ) +typedef unsigned int DWORD; +#else typedef unsigned long DWORD; +#endif typedef unsigned short WORD; extern void strlwr (char *str); diff --git a/src/controlconfig/controlsconfig.cpp b/src/controlconfig/controlsconfig.cpp index e3f131e..957edde 100644 --- a/src/controlconfig/controlsconfig.cpp +++ b/src/controlconfig/controlsconfig.cpp @@ -15,6 +15,13 @@ * C module for keyboard, joystick and mouse configuration * * $Log$ + * Revision 1.7 2005/03/29 02:18:47 taylor + * Various 64-bit platform fixes + * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too + * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) + * Streaming audio support (big thanks to Pierre Willenbrock!!) + * Removed dependance on strings.tbl for FS1 since we don't actually need it now + * * Revision 1.6 2004/09/20 01:31:44 theoddone33 * GCC 3.4 fixes. * @@ -590,15 +597,12 @@ ui_button_info CC_Buttons[GR_NUM_RESOLUTIONS][NUM_BUTTONS] = { }; // strings -#ifdef MAKE_FS1 - #define CC_NUM_TEXT 0 -#else - #define CC_NUM_TEXT 20 -#endif +#ifndef MAKE_FS1 +#define CC_NUM_TEXT 20 + UI_XSTR CC_text[GR_NUM_RESOLUTIONS][CC_NUM_TEXT] = { + // nothing needed for FS1 { // GR_640 - // nothing needed for FS1 -#ifndef MAKE_FS1 { "Targeting", 1340, 17, 384, UI_XSTR_COLOR_GREEN, -1, &CC_Buttons[0][TARGET_TAB].button }, { "Ship", 1341, 103, 384, UI_XSTR_COLOR_GREEN, -1, &CC_Buttons[0][SHIP_TAB].button }, { "Weapons", 1065, 154, 384, UI_XSTR_COLOR_GREEN, -1, &CC_Buttons[0][WEAPON_TAB].button }, @@ -619,11 +623,8 @@ UI_XSTR CC_text[GR_NUM_RESOLUTIONS][CC_NUM_TEXT] = { { "All", 1349, 483, 396, UI_XSTR_COLOR_GREEN, -1, &CC_Buttons[0][CLEAR_ALL_BUTTON].button }, { "Clear", 1414, 529, 388, UI_XSTR_COLOR_PINK, -1, &CC_Buttons[0][CLEAR_BUTTON].button }, { "Selected", 1350, 517, 396, UI_XSTR_COLOR_PINK, -1, &CC_Buttons[0][CLEAR_BUTTON].button }, -#endif }, { // GR_1024 - // nothing needed for FS1 -#ifndef MAKE_FS1 { "Targeting", 1340, 47, 615, UI_XSTR_COLOR_GREEN, -1, &CC_Buttons[1][TARGET_TAB].button }, { "Ship", 1341, 176, 615, UI_XSTR_COLOR_GREEN, -1, &CC_Buttons[1][SHIP_TAB].button }, { "Weapons", 1065, 266, 615, UI_XSTR_COLOR_GREEN, -1, &CC_Buttons[1][WEAPON_TAB].button }, @@ -644,9 +645,9 @@ UI_XSTR CC_text[GR_NUM_RESOLUTIONS][CC_NUM_TEXT] = { { "All", 1349, 772, 634, UI_XSTR_COLOR_GREEN, -1, &CC_Buttons[1][CLEAR_ALL_BUTTON].button }, { "Clear", 1414, 871, 619, UI_XSTR_COLOR_PINK, -1, &CC_Buttons[1][CLEAR_BUTTON].button }, { "Selected", 1350, 852, 634, UI_XSTR_COLOR_PINK, -1, &CC_Buttons[1][CLEAR_BUTTON].button }, -#endif } }; +#endif // linked list head of undo items config_item_undo *Config_item_undo; @@ -1626,10 +1627,12 @@ void control_config_init() b->button.link_hotspot(b->hotspot); } +#ifndef MAKE_FS1 // create all text for(i=0; ibutton.link_hotspot(b->hotspot); } +#ifndef MAKE_FS1 // add xstrs for(i=0; i= 0){ - gr_set_bitmap(Overlay); + gr_set_bitmap(Overlay, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(0, 0); } #else diff --git a/src/gamehelp/gameplayhelp.cpp b/src/gamehelp/gameplayhelp.cpp index 5348a6f..94cc6ac 100644 --- a/src/gamehelp/gameplayhelp.cpp +++ b/src/gamehelp/gameplayhelp.cpp @@ -15,6 +15,13 @@ * Module for displaying in-game help * * $Log$ + * Revision 1.6 2005/03/29 02:18:47 taylor + * Various 64-bit platform fixes + * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too + * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) + * Streaming audio support (big thanks to Pierre Willenbrock!!) + * Removed dependance on strings.tbl for FS1 since we don't actually need it now + * * Revision 1.5 2004/09/20 01:31:44 theoddone33 * GCC 3.4 fixes. * @@ -209,27 +216,21 @@ static gameplay_help_buttons Buttons[GR_NUM_RESOLUTIONS][NUM_BUTTONS] = { //XSTR:ON }; -#ifdef MAKE_FS1 - #define GAME_HELP_NUM_TEXT 0 -#else - #define GAME_HELP_NUM_TEXT 2 -#endif +#ifndef MAKE_FS1 +#define GAME_HELP_NUM_TEXT 2 + static UI_XSTR Game_help_text[GR_NUM_RESOLUTIONS][GAME_HELP_NUM_TEXT] = { { // GR_640 - // not needed for FS1 -#ifndef MAKE_FS1 { "Press ESC to return to the game", 1441, 263, 389, UI_XSTR_COLOR_GREEN, -1, NULL }, { "Continue", 1069, 571, 413, UI_XSTR_COLOR_GREEN, -1, &Buttons[gr_screen.res][CONTINUE_BUTTON].button } -#endif }, { // GR_1024 // not needed for FS1 -#ifndef MAKE_FS1 { "Press ESC to return to the game", 1441, 421, 622, UI_XSTR_COLOR_GREEN, -1, NULL }, { "Continue", 1069, 928, 663, UI_XSTR_COLOR_GREEN, -1, &Buttons[gr_screen.res][CONTINUE_BUTTON].button } -#endif } }; +#endif static char *Game_help_filename[GR_NUM_RESOLUTIONS] = { "F1", @@ -357,11 +358,13 @@ void gameplay_help_init() b->button.link_hotspot(b->hotspot); } +#ifndef MAKE_FS1 // add all xstrs for (i=0; i= 0 ) { Assert(offset < HC_gauge_regions[gr_screen.res][i].nframes); - gr_set_bitmap(HC_gauge_regions[gr_screen.res][i].bitmap+offset); + gr_set_bitmap(HC_gauge_regions[gr_screen.res][i].bitmap+offset, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(HC_gauge_regions[gr_screen.res][i].x, HC_gauge_regions[gr_screen.res][i].y); } } @@ -1787,7 +1787,7 @@ void hud_config_render_special_bitmaps() int i; for (i=1; i= 0) { - gr_set_bitmap(HC_special_bitmaps[i].bitmap); + gr_set_bitmap(HC_special_bitmaps[i].bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(HC_special_bitmaps[i].x, HC_special_bitmaps[i].y); } } @@ -1860,7 +1860,7 @@ void hud_config_do_frame(float frametime) #ifdef MAKE_FS1 if (HC_special_bitmaps[HC_SPECIAL_RETICLE].bitmap >= 0) { hud_set_default_color(); - gr_set_bitmap(HC_special_bitmaps[HC_SPECIAL_RETICLE].bitmap); + gr_set_bitmap(HC_special_bitmaps[HC_SPECIAL_RETICLE].bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_aabitmap(HC_special_bitmaps[HC_SPECIAL_RETICLE].x, HC_special_bitmaps[HC_SPECIAL_RETICLE].y); } #endif diff --git a/src/hud/hudmessage.cpp b/src/hud/hudmessage.cpp index 15fa77a..5b81212 100644 --- a/src/hud/hudmessage.cpp +++ b/src/hud/hudmessage.cpp @@ -15,6 +15,13 @@ * C module that controls and manages the message window on the HUD * * $Log$ + * Revision 1.9 2005/03/29 02:18:47 taylor + * Various 64-bit platform fixes + * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too + * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) + * Streaming audio support (big thanks to Pierre Willenbrock!!) + * Removed dependance on strings.tbl for FS1 since we don't actually need it now + * * Revision 1.8 2004/09/20 01:31:44 theoddone33 * GCC 3.4 fixes. * @@ -1497,7 +1504,7 @@ void hud_scrollback_do_frame(float frametime) #ifdef MAKE_FS1 if ((Scrollback_mode == SCROLLBACK_MODE_OBJECTIVES) && (Status_bitmap >= 0)) { - gr_set_bitmap(Status_bitmap); + gr_set_bitmap(Status_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(Hud_mission_log_status_coords[gr_screen.res][0], Hud_mission_log_status_coords[gr_screen.res][1]); } #endif diff --git a/src/localization/localize.cpp b/src/localization/localize.cpp index a3bb7c8..96425d8 100644 --- a/src/localization/localize.cpp +++ b/src/localization/localize.cpp @@ -14,6 +14,13 @@ * * * $Log$ + * Revision 1.8 2005/03/29 02:18:47 taylor + * Various 64-bit platform fixes + * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too + * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) + * Streaming audio support (big thanks to Pierre Willenbrock!!) + * Removed dependance on strings.tbl for FS1 since we don't actually need it now + * * Revision 1.7 2004/07/04 11:39:06 taylor * fix missing debrief text, crash on exit, path separator's, warning fixes, no GR_SOFT * @@ -517,16 +524,20 @@ int lcl_get_language() // initialize the xstr table void lcl_xstr_init() { + int i; +#ifndef MAKE_FS1 char chr, buf[4096]; char language_tag[512]; - int i, z, index, rval; + int z, index, rval; char *p_offset = NULL; int offset_lo = 0, offset_hi = 0; +#endif for (i=0; iadd_XSTR(&Om_pro_text[gr_screen.res][idx]); } +#endif // create the tracker input boxes Om_tracker_login.create(Om_window, Om_tracker_login_coords[gr_screen.res][0], Om_tracker_login_coords[gr_screen.res][1], Om_tracker_login_coords[gr_screen.res][2], LOGIN_LEN - 1, Multi_tracker_login, UI_INPUTBOX_FLAG_INVIS | UI_INPUTBOX_FLAG_ESC_CLR | UI_INPUTBOX_FLAG_KEYTHRU | UI_INPUTBOX_FLAG_NO_BACK); @@ -1741,10 +1729,12 @@ void options_multi_load_gen_controls() Om_gen_buttons[gr_screen.res][idx].button.link_hotspot(Om_gen_buttons[gr_screen.res][idx].hotspot); } +#ifndef MAKE_FS1 // text for(idx=0; idxadd_XSTR(&Om_gen_text[gr_screen.res][idx]); } +#endif // bogus control Om_gen_bogus.base_create(Om_window, UI_KIND_ICON, 0, 0, 0, 0); @@ -2025,10 +2015,12 @@ void options_multi_load_vox_controls() Om_vox_buttons[gr_screen.res][idx].button.link_hotspot(Om_vox_buttons[gr_screen.res][idx].hotspot); } +#ifndef MAKE_FS1 // text for(idx=0; idxadd_XSTR(&Om_vox_text[gr_screen.res][idx]); } +#endif // sliders for ( idx = 0; idx < NUM_OM_VOX_SLIDERS; idx++ ) { diff --git a/src/menuui/playermenu.cpp b/src/menuui/playermenu.cpp index a6d167b..8257a91 100644 --- a/src/menuui/playermenu.cpp +++ b/src/menuui/playermenu.cpp @@ -15,6 +15,13 @@ * Code to drive the Player Select initial screen * * $Log$ + * Revision 1.9 2005/03/29 02:18:47 taylor + * Various 64-bit platform fixes + * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too + * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) + * Streaming audio support (big thanks to Pierre Willenbrock!!) + * Removed dependance on strings.tbl for FS1 since we don't actually need it now + * * Revision 1.8 2004/09/20 01:31:44 theoddone33 * GCC 3.4 fixes. * @@ -326,25 +333,18 @@ static barracks_buttons Player_select_buttons[GR_NUM_RESOLUTIONS][NUM_PLAYER_SEL }; // FIXME add to strings.tbl -#ifdef MAKE_FS1 - #define PLAYER_SELECT_NUM_TEXT 0 -#else - #define PLAYER_SELECT_NUM_TEXT 1 -#endif +#ifndef MAKE_FS1 +#define PLAYER_SELECT_NUM_TEXT 1 + UI_XSTR Player_select_text[GR_NUM_RESOLUTIONS][PLAYER_SELECT_NUM_TEXT] = { { // GR_640 - // not needed for FS1 -#ifndef MAKE_FS1 { "Choose Pilot", 1436, 122, 90, UI_XSTR_COLOR_GREEN, -1, NULL } -#endif }, { // GR_1024 - // not needed for FS1 -#ifndef MAKE_FS1 { "Choose Pilot", 1436, 195, 143, UI_XSTR_COLOR_GREEN, -1, NULL } -#endif } }; +#endif UI_WINDOW Player_select_window; // ui window for this screen UI_BUTTON Player_select_list_region; // button for detecting mouse clicks on this screen diff --git a/src/menuui/readyroom.cpp b/src/menuui/readyroom.cpp index 44847d4..94cf41e 100644 --- a/src/menuui/readyroom.cpp +++ b/src/menuui/readyroom.cpp @@ -15,6 +15,13 @@ * Ready Room code, which is the UI screen for selecting Campaign/mission to play next mainly. * * $Log$ + * Revision 1.8 2005/03/29 02:18:47 taylor + * Various 64-bit platform fixes + * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too + * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) + * Streaming audio support (big thanks to Pierre Willenbrock!!) + * Removed dependance on strings.tbl for FS1 since we don't actually need it now + * * Revision 1.7 2004/12/15 04:10:45 taylor * outwnd_unix.cpp from fs2_open for logging to file in debug mode * fixes for default function values @@ -254,29 +261,21 @@ char *Campaign_mask_filename[GR_NUM_RESOLUTIONS] = { }; // misc text. ("Mission" and "Filename" -#ifdef MAKE_FS1 - #define NUM_SIM_MISC_TEXT 0 -#else - #define NUM_SIM_MISC_TEXT 2 -#endif +#ifndef MAKE_FS1 +#define NUM_SIM_MISC_TEXT 2 #define SIM_MISC_TEXT_MISSION 0 #define SIM_MISC_TEXT_FILENAME 1 int Sim_misc_text_coords[GR_NUM_RESOLUTIONS][NUM_SIM_MISC_TEXT][2] = { { // GR_640 - // nothing needed for FS1 -#ifndef MAKE_FS1 {33, 95}, {491, 95} -#endif }, { // GR_1024 - // nothing needed for FS1 -#ifndef MAKE_FS1 {43, 155}, {491, 155} -#endif } }; +#endif // readyroom text line stuff #define READYROOM_LINE_CAMPAIGN 1 @@ -1501,7 +1500,7 @@ void sim_room_blit_icons(int line_index, int y_start, fs_builtin_mission *fb, in #ifdef MAKE_FS1 if(is_md && (Mission_icon_bitmaps[MISSION_ICON_MDISK] >= 0)){ - gr_set_bitmap(Mission_icon_bitmaps[MISSION_ICON_MDISK]); + gr_set_bitmap(Mission_icon_bitmaps[MISSION_ICON_MDISK], GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(Sim_silent_icon_x[gr_screen.res], y_start + MISSION_ICON_MDISK_Y_OFFSET); } #endif @@ -1576,29 +1575,22 @@ ui_button_info Cr_buttons[GR_NUM_RESOLUTIONS][CR_NUM_BUTTONS] = { }; // text -#ifdef MAKE_FS1 - #define CR_NUM_TEXT 0 -#else - #define CR_NUM_TEXT 3 -#endif +#ifndef MAKE_FS1 +#define CR_NUM_TEXT 3 + UI_XSTR Cr_text[GR_NUM_RESOLUTIONS][CR_NUM_TEXT] = { { // GR_640 - // not needed for FS1 -#ifndef MAKE_FS1 { "Restart", 1403, 569, 326, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[0][CR_RESET_BUTTON].button }, { "Campaign", 1404, 569, 337, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[0][CR_RESET_BUTTON].button }, { "Select", 1409, 568, 413, UI_XSTR_COLOR_PINK, -1, &Cr_buttons[0][CR_COMMIT_BUTTON].button }, -#endif }, { // GR_1024 - // not needed for FS1 -#ifndef MAKE_FS1 { "Restart", 1403, 922, 523, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[1][CR_RESET_BUTTON].button }, { "Campaign", 1404, 922, 538, UI_XSTR_COLOR_GREEN, -1, &Cr_buttons[1][CR_RESET_BUTTON].button }, { "Select", 1409, 921, 665, UI_XSTR_COLOR_PINK, -1, &Cr_buttons[1][CR_COMMIT_BUTTON].button }, -#endif } }; +#endif static int Num_desc_lines; static int Desc_scroll_offset; @@ -1822,10 +1814,12 @@ void campaign_room_init() List_buttons[i].disable(); } +#ifndef MAKE_FS1 // add xstrs for(i=0; i= 0) { - gr_set_bitmap(Tech_background_bitmap); + gr_set_bitmap(Tech_background_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(0, 0); } #endif @@ -1987,22 +1994,22 @@ void techroom_do_frame(float frametime) #ifdef MAKE_FS1 if (ShipWin01) { - gr_set_bitmap(ShipWin01); + gr_set_bitmap(ShipWin01, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(223, 104); } if (ShipWin02) { - gr_set_bitmap(ShipWin02); + gr_set_bitmap(ShipWin02, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(621, 124); } if (ShipWin03) { - gr_set_bitmap(ShipWin03); + gr_set_bitmap(ShipWin03, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(223, 338); } if (ShipWin04) { - gr_set_bitmap(ShipWin04); + gr_set_bitmap(ShipWin04, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(218, 124); } #endif @@ -2014,7 +2021,7 @@ void techroom_do_frame(float frametime) // clear & draw bg bitmap GR_MAYBE_CLEAR_RES(Tech_data_background_bitmap); if (Tech_data_background_bitmap >= 0) { - gr_set_bitmap(Tech_data_background_bitmap); + gr_set_bitmap(Tech_data_background_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(0, 0); } #endif @@ -2027,7 +2034,7 @@ void techroom_do_frame(float frametime) // clear & draw bg bitmap GR_MAYBE_CLEAR_RES(Tech_data_background_bitmap); if (Tech_data_background_bitmap >= 0) { - gr_set_bitmap(Tech_data_background_bitmap); + gr_set_bitmap(Tech_data_background_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(0, 0); } #endif diff --git a/src/mission/missionhotkey.cpp b/src/mission/missionhotkey.cpp index db5b348..e1ccc68 100644 --- a/src/mission/missionhotkey.cpp +++ b/src/mission/missionhotkey.cpp @@ -15,6 +15,13 @@ * C module for the Hotkey selection screen * * $Log$ + * Revision 1.7 2005/03/29 02:18:47 taylor + * Various 64-bit platform fixes + * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too + * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) + * Streaming audio support (big thanks to Pierre Willenbrock!!) + * Removed dependance on strings.tbl for FS1 since we don't actually need it now + * * Revision 1.6 2004/09/20 01:31:44 theoddone33 * GCC 3.4 fixes. * @@ -427,35 +434,30 @@ static hotkey_buttons Buttons[GR_NUM_RESOLUTIONS][NUM_BUTTONS] = { #pragma warning(default: 4710) #endif -#ifdef MAKE_FS1 -#define HOTKEY_NUM_TEXT 0 -#else +#ifndef MAKE_FS1 #define HOTKEY_NUM_TEXT 6 -#endif + static UI_XSTR Hotkey_text[GR_NUM_RESOLUTIONS][HOTKEY_NUM_TEXT] = { { // GR_640 -#ifndef MAKE_FS1 { "Cancel", 1516, 7, 392, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_640][CANCEL_BUTTON].button }, { "Clear", 1517, 85, 392, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_640][CLEAR_BUTTON].button }, { "Reset", 1518, 159, 392, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_640][RESET_BUTTON].button }, { "Help", 1519, 500, 440, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_640][HELP_BUTTON].button }, { "Options", 1520, 479, 464, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_640][OPTIONS_BUTTON].button }, { "Accept", 1521, 573, 413, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_640][ACCEPT_BUTTON].button } -#endif }, { // GR_1024 -#ifndef MAKE_FS1 { "Cancel", 1516, 30, 629, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_1024][CANCEL_BUTTON].button }, { "Clear", 1517, 151, 629, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_1024][CLEAR_BUTTON].button }, { "Reset", 1518, 269, 629, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_1024][RESET_BUTTON].button }, { "Help", 1519, 800, 704, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_1024][HELP_BUTTON].button }, { "Options", 1520, 797, 743, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_1024][OPTIONS_BUTTON].button }, { "Accept", 1521, 902, 661, UI_XSTR_COLOR_GREEN, -1, &Buttons[GR_1024][ACCEPT_BUTTON].button } -#endif } }; +#endif @@ -1153,10 +1155,12 @@ void mission_hotkey_init() b->button.link_hotspot(b->hotspot); } +#ifndef MAKE_FS1 // add all xstr text for(i=0; ilink_hotspot(Brief_buttons[gr_screen.res][i].hotspot); } +#ifndef MAKE_FS1 // add all xstrs for(i=0; ibutton.link_hotspot(b->hotspot); } +#ifndef MAKE_FS1 // add text for(i=0; ibutton.link_hotspot(b->hotspot); } +#ifndef MAKE_FS1 // add all xstrs for(i=0; i= 0) { - gr_set_bitmap(Rank_text_bitmap); + gr_set_bitmap(Rank_text_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(Debrief_rank_text_coords[gr_screen.res][0], Debrief_rank_text_coords[gr_screen.res][1]); } if (Medal_text_bitmap >= 0) { - gr_set_bitmap(Medal_text_bitmap); + gr_set_bitmap(Medal_text_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(Debrief_medal_text_coords[gr_screen.res][0], Debrief_medal_text_coords[gr_screen.res][1]); } if (Badge_text_bitmap >= 0) { - gr_set_bitmap(Badge_text_bitmap); + gr_set_bitmap(Badge_text_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(Debrief_badge_text_coords[gr_screen.res][0], Debrief_badge_text_coords[gr_screen.res][1]); } #endif diff --git a/src/missionui/missionshipchoice.cpp b/src/missionui/missionshipchoice.cpp index 818d364..afc5c17 100644 --- a/src/missionui/missionshipchoice.cpp +++ b/src/missionui/missionshipchoice.cpp @@ -15,6 +15,13 @@ * C module to allow player ship selection for the mission * * $Log$ + * Revision 1.6 2005/03/29 02:18:47 taylor + * Various 64-bit platform fixes + * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too + * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) + * Streaming audio support (big thanks to Pierre Willenbrock!!) + * Removed dependance on strings.tbl for FS1 since we don't actually need it now + * * Revision 1.5 2004/09/20 01:31:44 theoddone33 * GCC 3.4 fixes. * @@ -654,25 +661,18 @@ static ss_buttons Ship_select_buttons[GR_NUM_RESOLUTIONS][NUM_SS_BUTTONS] = { }; // ship select text -#ifdef MAKE_FS1 - #define SHIP_SELECT_NUM_TEXT 0 -#else - #define SHIP_SELECT_NUM_TEXT 1 -#endif +#ifndef MAKE_FS1 +#define SHIP_SELECT_NUM_TEXT 1 + UI_XSTR Ship_select_text[GR_NUM_RESOLUTIONS][SHIP_SELECT_NUM_TEXT] = { { // GR_640 - // not needed for FS1 -#ifndef MAKE_FS1 { "Reset", 1337, 580, 337, UI_XSTR_COLOR_GREEN, -1, &Ship_select_buttons[0][SS_BUTTON_RESET].button } -#endif }, { // GR_1024 - // not needed for FS1 -#ifndef MAKE_FS1 { "Reset", 1337, 938, 546, UI_XSTR_COLOR_GREEN, -1, &Ship_select_buttons[1][SS_BUTTON_RESET].button } -#endif } }; +#endif // Mask bitmap pointer and Mask bitmap_id static bitmap* ShipSelectMaskPtr; // bitmap pointer to the ship select mask bitmap @@ -967,10 +967,12 @@ void ship_select_buttons_init() b->button.link_hotspot(b->hotspot); } +#ifndef MAKE_FS1 // add all xstrs for(i=0; ibutton.link_hotspot(b->hotspot); } +#ifndef MAKE_FS1 // all text for(i=0; ilast_flown == 0){ strcpy(Multi_pinfo_stats_vals[MPI_LAST_FLOWN],XSTR("No missions flown",693)); } else { - tm *tmr = gmtime(&sc->last_flown); + time_t last_flown_tmp; + tm *tmr = gmtime(&last_flown_tmp); + sc->last_flown = (fs_time_t)last_flown_tmp; if(tmr != NULL){ strftime(Multi_pinfo_stats_vals[MPI_LAST_FLOWN],MAX_LABEL_TEXT,"%m/%d/%y %H:%M",tmr); } else { diff --git a/src/network/multiui.cpp b/src/network/multiui.cpp index c9c22a6..1b5d8b7 100644 --- a/src/network/multiui.cpp +++ b/src/network/multiui.cpp @@ -15,6 +15,13 @@ * C file for all the UI controls of the mulitiplayer screens * * $Log$ + * Revision 1.11 2005/03/29 02:18:47 taylor + * Various 64-bit platform fixes + * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too + * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) + * Streaming audio support (big thanks to Pierre Willenbrock!!) + * Removed dependance on strings.tbl for FS1 since we don't actually need it now + * * Revision 1.10 2004/09/20 01:31:44 theoddone33 * GCC 3.4 fixes. * @@ -1025,16 +1032,11 @@ ui_button_info Multi_join_buttons[GR_NUM_RESOLUTIONS][MULTI_JOIN_NUM_BUTTONS] = } }; -#ifdef MAKE_FS1 -#define MULTI_JOIN_NUM_TEXT 0 -#else +#ifndef MAKE_FS1 #define MULTI_JOIN_NUM_TEXT 13 -#endif UI_XSTR Multi_join_text[GR_NUM_RESOLUTIONS][MULTI_JOIN_NUM_TEXT] = { { // GR_640 - // not needed for FS1 -#ifndef MAKE_FS1 {"Refresh", 1299, 65, 364, UI_XSTR_COLOR_GREEN, -1, &Multi_join_buttons[0][MJ_REFRESH].button}, {"Join as", 1300, 476, 376, UI_XSTR_COLOR_GREEN, -1, &Multi_join_buttons[0][MJ_JOIN_OBSERVER].button}, {"Observer", 1301, 467, 385, UI_XSTR_COLOR_GREEN, -1, &Multi_join_buttons[0][MJ_JOIN_OBSERVER].button}, @@ -1048,11 +1050,8 @@ UI_XSTR Multi_join_text[GR_NUM_RESOLUTIONS][MULTI_JOIN_NUM_TEXT] = { {"Server", 1305, 116, 37, UI_XSTR_COLOR_GREEN, -1, NULL}, {"Players", 1306, 471, 37, UI_XSTR_COLOR_GREEN, -1, NULL}, {"Ping", 1307, 555, 37, UI_XSTR_COLOR_GREEN, -1, NULL} -#endif }, { // GR_1024 - // not needed for FS1 -#ifndef MAKE_FS1 {"Refresh", 1299, 104, 582, UI_XSTR_COLOR_GREEN, -1, &Multi_join_buttons[1][MJ_REFRESH].button}, {"Join as", 1300, 783, 602, UI_XSTR_COLOR_GREEN, -1, &Multi_join_buttons[1][MJ_JOIN_OBSERVER].button}, {"Observer", 1301, 774, 611, UI_XSTR_COLOR_GREEN, -1, &Multi_join_buttons[1][MJ_JOIN_OBSERVER].button}, @@ -1066,9 +1065,9 @@ UI_XSTR Multi_join_text[GR_NUM_RESOLUTIONS][MULTI_JOIN_NUM_TEXT] = { {"Server", 1305, 186, 60, UI_XSTR_COLOR_GREEN, -1, NULL}, {"Players", 1306, 753, 60, UI_XSTR_COLOR_GREEN, -1, NULL}, {"Ping", 1307, 888, 60, UI_XSTR_COLOR_GREEN, -1, NULL} -#endif } }; +#endif // constants for coordinate look ups #define MJ_X_COORD 0 @@ -1405,10 +1404,12 @@ void multi_join_game_init() Multi_join_buttons[gr_screen.res][idx].button.link_hotspot(Multi_join_buttons[gr_screen.res][idx].hotspot); } +#ifndef MAKE_FS1 // create all xstrs for(idx=0; idxfilename); if((fb != NULL) && (fb->flags & FSB_FROM_MDISK)){ if(Multi_common_icons[MICON_MDISK] >= 0){ - gr_set_bitmap(Multi_common_icons[MICON_MDISK]); + gr_set_bitmap(Multi_common_icons[MICON_MDISK], GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1); gr_bitmap(Mc_icon_silent_coords[gr_screen.res][MC_X_COORD],y_start + Mc_icon_silent_coords[gr_screen.res][MC_Y_COORD]); } } @@ -6180,15 +6176,11 @@ int Multi_ho_lastframe_input = 0; // game information text areas // ho titles -#ifdef MAKE_FS1 -#define MULTI_HO_NUM_TITLES 0 -#else +#ifndef MAKE_FS1 #define MULTI_HO_NUM_TITLES 14 -#endif + UI_XSTR Multi_ho_titles[GR_NUM_RESOLUTIONS][MULTI_HO_NUM_TITLES] = { { // GR_640 - // not needed for FS1 -#ifndef MAKE_FS1 { "AI Orders", 1289, 32, 144, UI_XSTR_COLOR_GREEN, -1, NULL }, { "End Mission", 1290, 32, 242, UI_XSTR_COLOR_GREEN, -1, NULL }, { "Time Limit", 1291, 32, 347, UI_XSTR_COLOR_GREEN, -1, NULL }, @@ -6203,11 +6195,8 @@ UI_XSTR Multi_ho_titles[GR_NUM_RESOLUTIONS][MULTI_HO_NUM_TITLES] = { { "sec", 1522, 523, 292, UI_XSTR_COLOR_GREEN, -1, NULL }, { "sec", 1523, 523, 332, UI_XSTR_COLOR_GREEN, -1, NULL }, { "Voice Wait", 1298, 437, 313, UI_XSTR_COLOR_GREEN, -1, NULL }, -#endif }, { // GR_1024 - // not needed for FS1 -#ifndef MAKE_FS1 { "AI Orders", 1289, 48, 238, UI_XSTR_COLOR_GREEN, -1, NULL }, { "End Mission", 1290, 48, 394, UI_XSTR_COLOR_GREEN, -1, NULL }, { "Time Limit", 1291, 50, 568, UI_XSTR_COLOR_GREEN, -1, NULL }, @@ -6222,9 +6211,9 @@ UI_XSTR Multi_ho_titles[GR_NUM_RESOLUTIONS][MULTI_HO_NUM_TITLES] = { { "sec", 1522, 837, 467, UI_XSTR_COLOR_GREEN, -1, NULL }, { "sec", 1523, 837, 534, UI_XSTR_COLOR_GREEN, -1, NULL }, { "Voice Wait", 1298, 742, 510, UI_XSTR_COLOR_GREEN, -1, NULL }, -#endif } }; +#endif // mission time limit input box int Ho_time_coords[GR_NUM_RESOLUTIONS][4] = { @@ -6398,10 +6387,12 @@ void multi_host_options_init() #endif } +#ifndef MAKE_FS1 // create misc text for(idx=0; idxtype == OBJ_ASTEROID) { + if ( eeo->turret_parent_objnum == asteroid_collide_objnum(objp) ) { + // give priority to the closest asteroid *impact* (ms intervals) + dist *= 0.9f + (0.01f * asteroid_time_to_impact(objp)); + + if (dist < eeo->nearest_dist ) { + if ( (eeo->current_enemy == -1) || object_in_turret_fov(objp, tp, eeo->tvec, eeo->tpos, dist + objp->radius) ) { + eeo->nearest_dist = dist; + eeo->nearest_objnum = OBJ_INDEX(objp); + } + } + } + } // end asteroid selection +#endif } // return 0 only if objnum is beam protected and turret is beam turret diff --git a/src/sound/acm-unix.cpp b/src/sound/acm-unix.cpp index 8540a61..6bc13dd 100644 --- a/src/sound/acm-unix.cpp +++ b/src/sound/acm-unix.cpp @@ -1,7 +1,28 @@ /*********************************************************** * Portions of this file are Copyright (c) Ryan C. Gordon ***********************************************************/ - + +/* + * $Logfile: /Freespace2/code/Sound/ACM.cpp $ + * $Revision$ + * $Date$ + * $Author$ + * + * ADPCM decoder + * + * $Log$ + * Revision 1.6 2005/03/29 02:18:47 taylor + * Various 64-bit platform fixes + * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too + * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) + * Streaming audio support (big thanks to Pierre Willenbrock!!) + * Removed dependance on strings.tbl for FS1 since we don't actually need it now + * + * + * $NoKeywords: $ + */ + + #include "pstypes.h" #include "acm.h" @@ -38,6 +59,11 @@ typedef struct ADPCM_FMT_T { ubyte nibble; } adpcm_fmt_t; +typedef struct acm_stream_t { + adpcm_fmt_t *fmt; + ushort dest_bps; + ushort src_bps; +} acm_stream_t; // similar to BIAL_IF_MACRO in SDL_sound #define IF_ERR(a, b) if (a) { printf("IF_ERR-ACM, function: %s, line %d...\n", __FUNCTION__, __LINE__); return b; } @@ -317,7 +343,10 @@ int ACM_convert_ADPCM_to_PCM(WAVEFORMATEX *pwfxSrc, ubyte *src, int src_len, uby } // estimate size of uncompressed data - new_size = src_len * ( (dest_bps * pwfxSrc->nChannels * pwfxSrc->wBitsPerSample) / 8 ); + // uncompressed data has: channels=pfwxScr->nChannels, bitPerSample=destbits + // compressed data has: channels=pfwxScr->nChannels, bitPerSample=pwfxSrc->wBitsPerSample + new_size = ( src_len * dest_bps ) / pwfxSrc->wBitsPerSample; + new_size *= 2;//buffer must be large enough for all data // DO NOT free() here, *estimated size* if ( *dest == NULL ) { @@ -325,7 +354,8 @@ int ACM_convert_ADPCM_to_PCM(WAVEFORMATEX *pwfxSrc, ubyte *src, int src_len, uby IF_ERR(*dest == NULL, -1); - memset(*dest, 0x80, new_size); // silence (for 8 bits/sec) +// memset(*dest, 0x80, new_size); // silence (for 8 bits/sample) + memset(*dest, 0x00, new_size); // silence (for 16 bits/sample) } adpcm_fmt_t *fmt = (adpcm_fmt_t *)malloc(sizeof(adpcm_fmt_t)); @@ -365,10 +395,12 @@ int ACM_convert_ADPCM_to_PCM(WAVEFORMATEX *pwfxSrc, ubyte *src, int src_len, uby // sanity check, should always be 4 if (fmt->adpcm.wav.wBitsPerSample != 4) { adpcm_memory_free(fmt); + SDL_RWclose(hdr); + SDL_RWclose(rw); return -1; } - fmt->sample_frame_size = 2; + fmt->sample_frame_size = dest_bps/8*pwfxSrc->nChannels; if ( !max_dest_bytes ) { max_dest_bytes = new_size; @@ -383,33 +415,141 @@ int ACM_convert_ADPCM_to_PCM(WAVEFORMATEX *pwfxSrc, ubyte *src, int src_len, uby // cleanup adpcm_memory_free(fmt); + SDL_RWclose(hdr); + SDL_RWclose(rw); return 0; } int ACM_stream_open(WAVEFORMATEX *pwfxSrc, WAVEFORMATEX *pwfxDest, void **stream, int dest_bps) { - return -1; + Assert( pwfxSrc != NULL ); + Assert( pwfxSrc->wFormatTag == WAVE_FORMAT_ADPCM ); + Assert( stream != NULL ); + + SDL_RWops *hdr = SDL_RWFromMem(pwfxSrc, sizeof(WAVEFORMATEX) + pwfxSrc->cbSize); + uint rc; + + if ( ACM_inited == 0 ) { + rc = ACM_init(); + if ( rc != 0 ) + return -1; + } + + adpcm_fmt_t *fmt = (adpcm_fmt_t *)malloc(sizeof(adpcm_fmt_t)); + IF_ERR(fmt == NULL, -1); + memset(fmt, '\0', sizeof(adpcm_fmt_t)); + + // wav header info (WAVEFORMATEX) + IF_ERR(!read_word(hdr, &fmt->adpcm.wav.wFormatTag), -1); + IF_ERR(!read_word(hdr, &fmt->adpcm.wav.nChannels), -1); + IF_ERR(!read_dword(hdr, &fmt->adpcm.wav.nSamplesPerSec), -1); + IF_ERR(!read_dword(hdr, &fmt->adpcm.wav.nAvgBytesPerSec), -1); + IF_ERR(!read_word(hdr, &fmt->adpcm.wav.nBlockAlign), -1); + IF_ERR(!read_word(hdr, &fmt->adpcm.wav.wBitsPerSample), -1); + IF_ERR(!read_word(hdr, &fmt->adpcm.wav.cbSize), -1); + // adpcm specific header info + IF_ERR(!read_word_s(hdr, &fmt->adpcm.wSamplesPerBlock), -1); + IF_ERR(!read_word_s(hdr, &fmt->adpcm.wNumCoef), -1); + + // allocate memory for COEF struct and fill it + fmt->adpcm.aCoef = (ADPCMCOEFSET *)malloc(sizeof(ADPCMCOEFSET) * fmt->adpcm.wNumCoef); + IF_ERR(fmt->adpcm.aCoef == NULL, -1); + + for (int i=0; iadpcm.wNumCoef; i++) { + IF_ERR(!read_short(hdr, &fmt->adpcm.aCoef[i].iCoef1), -1); + IF_ERR(!read_short(hdr, &fmt->adpcm.aCoef[i].iCoef2), -1); + } + + // allocate memory for the ADPCM block header that's to be filled later + fmt->header = (ADPCMBLOCKHEADER *)malloc(sizeof(ADPCMBLOCKHEADER) * fmt->adpcm.wav.nChannels); + IF_ERR(fmt->header == NULL, -1); + + // sanity check, should always be 4 + if (fmt->adpcm.wav.wBitsPerSample != 4) { + adpcm_memory_free(fmt); + SDL_RWclose(hdr); + return -1; + } + + fmt->sample_frame_size = dest_bps/8*pwfxSrc->nChannels; + + acm_stream_t *str = (acm_stream_t *)malloc(sizeof(acm_stream_t)); + IF_ERR(str == NULL, -1); + str->fmt = fmt; + str->dest_bps = dest_bps; + str->src_bps = pwfxSrc->wBitsPerSample; + *stream = str; + + SDL_RWclose(hdr); + + return 0; } int ACM_stream_close(void *stream) { - return -1; + Assert(stream != NULL); + acm_stream_t *str = (acm_stream_t *)stream; + adpcm_memory_free(str->fmt); + free(str); + return 0; } +/* + * How many bytes are needed to get approximately dest_len bytes output? + */ int ACM_query_source_size(void *stream, int dest_len) { - return -1; + Assert(stream != NULL); + acm_stream_t *str = (acm_stream_t *)stream; + // estimate size of compressed data + // uncompressed data has: channels=pfwxScr->nChannels, bitPerSample=destbits + // compressed data has: channels=pfwxScr->nChannels, bitPerSample=pwfxSrc->wBitsPerSample + return (dest_len * str->src_bps) / str->dest_bps; } +/* + * How many output bytes would approximately be produced by src_len bytes input? + */ int ACM_query_dest_size(void *stream, int src_len) { - return -1; + Assert(stream != NULL); + acm_stream_t *str = (acm_stream_t *)stream; + // estimate size of uncompressed data + // uncompressed data has: channels=pfwxScr->nChannels, bitPerSample=destbits + // compressed data has: channels=pfwxScr->nChannels, bitPerSample=pwfxSrc->wBitsPerSample + return ( src_len * str->dest_bps ) / str->src_bps; } +/* + * We are allowed to use fewer bytes than delivered to us + */ int ACM_convert(void *stream, ubyte *src, int src_len, ubyte *dest, int max_dest_bytes, unsigned int *dest_len, unsigned int *src_bytes_used) { - return -1; + Assert(stream != NULL); + Assert( src != NULL ); + Assert( src_len > 0 ); + Assert( dest_len != NULL ); + acm_stream_t *str = (acm_stream_t *)stream; + uint rc; + + SDL_RWops *rw = SDL_RWFromMem(src, src_len); + + // buffer to estimated size since we have to process the whole thing at once + str->fmt->buffer_size = max_dest_bytes; + str->fmt->bytes_remaining = src_len; + str->fmt->bytes_processed = 0; + + // convert to PCM + rc = read_sample_fmt_adpcm(dest, rw, str->fmt); + + // send back actual sizes + *dest_len = rc; + *src_bytes_used = str->fmt->bytes_processed; + + SDL_RWclose(rw); + + return 0; } // ACM_init() - decoding should always work diff --git a/src/sound/audiostr.cpp b/src/sound/audiostr.cpp index 0e1b9d5..eb02fed 100644 --- a/src/sound/audiostr.cpp +++ b/src/sound/audiostr.cpp @@ -15,6 +15,13 @@ * Routines to stream large WAV files from disk * * $Log$ + * Revision 1.7 2005/03/29 02:18:47 taylor + * Various 64-bit platform fixes + * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too + * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) + * Streaming audio support (big thanks to Pierre Willenbrock!!) + * Removed dependance on strings.tbl for FS1 since we don't actually need it now + * * Revision 1.6 2003/08/03 16:10:30 taylor * cleanup; compile warning fixes * @@ -189,17 +196,27 @@ * $NoKeywords: $ */ -#define VC_EXTRALEAN -#define STRICT #include "pstypes.h" #ifndef PLAT_UNIX +#define VC_EXTRALEAN +#define STRICT #include #include #include #include #include "vdsound.h" +#else +#ifdef __APPLE__ +#include +#include +#include +#else +#include +#include +#include +#endif // __APPLE__ #endif #include "audiostr.h" #include "cfile.h" // needed for cf_get_path @@ -208,15 +225,63 @@ #include "acm.h" #include "ds.h" + +#ifdef PLAT_UNIX +#ifndef NDEBUG +#define OpenAL_ErrorCheck(onerr) do { \ + int i = alGetError(); \ + if (i != AL_NO_ERROR) { \ + while(i != AL_NO_ERROR) { \ + nprintf(("Warning", "%s/%s:%d - OpenAL error %s\n", __FUNCTION__, __FILE__, __LINE__, alGetString(i))); \ + i = alGetError(); \ + } \ + onerr; \ + } \ +} while (0); +#else +#define OpenAL_ErrorCheck(onerr) +#endif + +#define MAX_AL_BUF 4 + +#define BYTE byte +#define LONG long +#define LPBYTE BYTE * + +static int audiostr_read_word(SDL_RWops *rw, WORD *i) +{ + int rc = SDL_RWread( rw, i, 1, sizeof(WORD) ); + + if (rc != sizeof(WORD)) { + return 0; + } + + *i = INTEL_SHORT(*i); + + return 1; +} + +static int audiostr_read_dword(SDL_RWops *rw, DWORD *i) +{ + int rc = SDL_RWread( rw, i, 1, sizeof(DWORD) ); + + if (rc != sizeof(DWORD)) + return 0; + + *i = INTEL_INT(*i); + + return 1; +} +#endif + + // Constants #ifndef SUCCESS #define SUCCESS TRUE // Error returns for all member functions #define FAILURE FALSE #endif // SUCCESS -#ifndef PLAT_UNIX - -typedef BOOL (*TIMERCALLBACK)(DWORD); +typedef BOOL (*TIMERCALLBACK)(ptr_u); #define BIGBUF_SIZE 180000 // This can be reduced to 88200 once we don't use any stereo //#define BIGBUF_SIZE 88300 // This can be reduced to 88200 once we don't use any stereo @@ -245,14 +310,22 @@ class Timer public: void constructor(void); void destructor(void); - BOOL Create (UINT nPeriod, UINT nRes, DWORD dwUser, TIMERCALLBACK pfnCallback); + BOOL Create (UINT nPeriod, UINT nRes, ptr_u dwUser, TIMERCALLBACK pfnCallback); protected: +#ifndef PLAT_UNIX static void CALLBACK TimeProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2); +#else + static Uint32 CALLBACK TimeProc(Uint32 interval, void *dwUser); +#endif TIMERCALLBACK m_pfnCallback; DWORD m_dwUser; UINT m_nPeriod; UINT m_nRes; +#ifndef PLAT_UNIX UINT m_nIDTimer; +#else + SDL_TimerID m_nIDTimer; +#endif }; @@ -290,7 +363,11 @@ public: protected: UINT m_data_offset; // number of bytes to actual wave data int m_data_bytes_left; +#ifndef PLAT_UNIX HMMIO cfp; +#else + SDL_RWops *cfp; +#endif UINT m_wave_format; // format of wave source (ie WAVE_FORMAT_PCM, WAVE_FORMAT_ADPCM) UINT m_nBlockAlign; // wave data block alignment spec @@ -299,9 +376,15 @@ protected: UINT m_nBytesPlayed; // offset into data chunk BOOL m_abort_next_read; +#ifndef PLAT_UNIX HACMSTREAM m_hStream; int m_hStream_open; WAVEFORMATEX m_wfxDest; +#else + void* m_hStream; + int m_hStream_open; + WAVEFORMATEX m_wfxDest; +#endif }; // Classes @@ -321,9 +404,11 @@ class AudioStreamServices public: void Constructor(void); BOOL Initialize (); +#ifndef PLAT_UNIX LPDIRECTSOUND GetPDS (void) { return m_pds; } protected: LPDIRECTSOUND m_pds; +#endif }; @@ -375,15 +460,25 @@ protected: BOOL WriteSilence (UINT cbSize); DWORD GetMaxWriteSize (void); BOOL ServiceBuffer (void); - static BOOL TimerCallback (DWORD dwUser); + static BOOL TimerCallback (ptr_u dwUser); +#ifdef PLAT_UNIX + BOOL GetWritingDone (void); +#endif AudioStreamServices * m_pass; // ptr to AudioStreamServices object +#ifndef PLAT_UNIX LPDIRECTSOUNDBUFFER m_pdsb; // ptr to Direct Sound buffer +#else + ALuint m_al_multichannel_id; // name of openAL source + ALuint m_al_buffer_ids[MAX_AL_BUF]; //names of buffers +#endif WaveFile * m_pwavefile; // ptr to WaveFile object Timer m_timer; // ptr to Timer object BOOL m_fCued; // semaphore (stream cued) BOOL m_fPlaying; // semaphore (stream playing) +#ifndef PLAT_UNIX DSBUFFERDESC m_dsbd; // Direct Sound buffer description +#endif LONG m_lInService; // reentrancy semaphore UINT m_cbBufOffset; // last write position UINT m_nBufLength; // length of sound buffer in msec @@ -403,7 +498,11 @@ protected: DWORD m_finished_id; // timestamp so we know when we've played #bytes required BOOL m_bPastLimit; // flag to show we've played past the number of bytes requred LONG m_lDefaultVolume; +#ifdef PLAT_UNIX + int m_al_buffer_play; +#else HRESULT h_result; +#endif CRITICAL_SECTION write_lock; }; @@ -416,16 +515,20 @@ protected: // Constructor void AudioStreamServices::Constructor(void) { +#ifndef PLAT_UNIX // Initialize member data m_pds = NULL; // It would seem to make sense to initialize DirectSound here, // but because there could be an error, it's best done in a // separate member function, ::Initialize. +#endif } +#ifndef PLAT_UNIX extern LPDIRECTSOUND pDirectSound; // From Sound.cpp +#endif // Initialize @@ -434,9 +537,11 @@ BOOL AudioStreamServices::Initialize () BOOL fRtn = SUCCESS; // assume success +#ifndef PLAT_UNIX if (m_pds == NULL) { m_pds = pDirectSound; } +#endif return (fRtn); } @@ -455,14 +560,22 @@ const UINT DefBufferServiceInterval = 250; // default buffer service interval i // Constructor AudioStream::AudioStream (void) { +#ifndef PLAT_UNIX InitializeCriticalSection( &write_lock ); +#else + write_lock = SDL_CreateMutex(); +#endif } // Destructor AudioStream::~AudioStream (void) { +#ifndef PLAT_UNIX DeleteCriticalSection( &write_lock ); +#else + SDL_DestroyMutex( write_lock ); +#endif } @@ -482,7 +595,13 @@ void AudioStream::Init_Data () m_bReadingDone = FALSE; m_pwavefile = NULL; +#ifndef PLAT_UNIX m_pdsb = NULL; +#else + memset(m_al_buffer_ids, 0, sizeof(m_al_buffer_ids)); + m_al_multichannel_id = 0; + m_al_buffer_play = 0; +#endif m_fPlaying = m_fCued = FALSE; m_lInService = FALSE; m_cbBufOffset = 0; @@ -516,6 +635,7 @@ BOOL AudioStream::Create (LPSTR pszFilename, AudioStreamServices * pass) m_pwavefile->m_bits_per_sample_uncompressed = m_bits_per_sample_uncompressed; if (m_pwavefile->Open (pszFilename)) { // Calculate sound buffer size in bytes +#ifndef PLAT_UNIX // Buffer size is average data rate times length of buffer // No need for buffer to be larger than wave data though m_cbBufSize = (m_pwavefile->GetUncompressedAvgDataRate () * m_nBufLength) / 1000; @@ -548,6 +668,44 @@ BOOL AudioStream::Create (LPSTR pszFilename, AudioStreamServices * pass) fRtn = FAILURE; } +#else + + m_cbBufSize = + (m_nBufLength/1000)* + (m_pwavefile->m_wfmt.wBitsPerSample/8) * + m_pwavefile->m_wfmt.nChannels* + m_pwavefile->m_wfmt.nSamplesPerSec; +// nprintf(("SOUND", "SOUND => Stream buffer created using %d bytes\n", m_cbBufSize)); + // Create sound buffer + alGenBuffers(MAX_AL_BUF, m_al_buffer_ids); + + OpenAL_ErrorCheck(return FAILURE); + + alGenSources(1, &m_al_multichannel_id); + + OpenAL_ErrorCheck(return FAILURE); + + alSourcef(m_al_multichannel_id,AL_ROLLOFF_FACTOR,0); + + OpenAL_ErrorCheck(return FAILURE); + + alSourcef(m_al_multichannel_id,AL_SOURCE_RELATIVE,AL_TRUE); + + OpenAL_ErrorCheck(return FAILURE); + + ALfloat posv[] = { 0,0,0 }; + alSourcefv(m_al_multichannel_id,AL_POSITION,posv); + + OpenAL_ErrorCheck(return FAILURE); + + alSourcef(m_al_multichannel_id,AL_GAIN,1); + + OpenAL_ErrorCheck(return FAILURE); + + // Cue for playback + Cue (); + Snd_sram += m_cbBufSize; +#endif } else { // Error opening file @@ -578,17 +736,26 @@ BOOL AudioStream::Destroy (void) { BOOL fRtn = SUCCESS; +#ifndef PLAT_UNIX EnterCriticalSection(&write_lock); +#else + SDL_LockMutex(write_lock); +#endif // Stop playback Stop (); // Release DirectSound buffer +#ifndef PLAT_UNIX if (m_pdsb) { m_pdsb->Release (); m_pdsb = NULL; Snd_sram -= m_cbBufSize; } +#else + alDeleteBuffers(MAX_AL_BUF,m_al_buffer_ids); + alDeleteSources(1,&m_al_multichannel_id); +#endif // Delete WaveFile object if (m_pwavefile) { @@ -599,7 +766,11 @@ BOOL AudioStream::Destroy (void) status = ASF_FREE; +#ifndef PLAT_UNIX LeaveCriticalSection(&write_lock); +#else + SDL_UnlockMutex(write_lock); +#endif return fRtn; } @@ -610,6 +781,7 @@ BOOL AudioStream::Destroy (void) // ServiceBuffer; it's not exposed to users of the AudioStream class. BOOL AudioStream::WriteWaveData (UINT size, UINT *num_bytes_written, int service) { +#ifndef PLAT_UNIX HRESULT hr; LPBYTE lpbuf1 = NULL; LPBYTE lpbuf2 = NULL; @@ -617,6 +789,7 @@ BOOL AudioStream::WriteWaveData (UINT size, UINT *num_bytes_written, int service DWORD dwsize2 = 0; DWORD dwbyteswritten1 = 0; DWORD dwbyteswritten2 = 0; +#endif BOOL fRtn = SUCCESS; unsigned char *uncompressed_wave_data; @@ -626,6 +799,7 @@ BOOL AudioStream::WriteWaveData (UINT size, UINT *num_bytes_written, int service return fRtn; } +#ifndef PLAT_UNIX if ( !m_pdsb || !m_pwavefile ) { return fRtn; } @@ -633,6 +807,15 @@ BOOL AudioStream::WriteWaveData (UINT size, UINT *num_bytes_written, int service if ( service ) { EnterCriticalSection(&Global_service_lock); } +#else + if ( (m_al_buffer_ids[0] == 0) || !m_pwavefile ) { + return fRtn; + } + + if ( service ) { + SDL_LockMutex(Global_service_lock); + } +#endif if ( service ) { uncompressed_wave_data = Wavedata_service_buffer; @@ -642,6 +825,7 @@ BOOL AudioStream::WriteWaveData (UINT size, UINT *num_bytes_written, int service int num_bytes_read = 0; +#ifndef PLAT_UNIX // Lock the sound buffer hr = m_pdsb->Lock (m_cbBufOffset, size, (void**)(&lpbuf1), &dwsize1, (void**)(&lpbuf2), &dwsize2, 0); if (hr == DS_OK) { @@ -650,6 +834,9 @@ BOOL AudioStream::WriteWaveData (UINT size, UINT *num_bytes_written, int service Assert(lpbuf1); num_bytes_read = m_pwavefile->Read(uncompressed_wave_data, dwsize1+dwsize2,service); +#else + num_bytes_read = m_pwavefile->Read(uncompressed_wave_data, m_cbBufSize ,service); +#endif if ( num_bytes_read == -1 ) { // means nothing left to read! num_bytes_read = 0; @@ -657,6 +844,7 @@ BOOL AudioStream::WriteWaveData (UINT size, UINT *num_bytes_written, int service } if ( num_bytes_read > 0 ) { +#ifndef PLAT_UNIX if ( (unsigned int)num_bytes_read > dwsize1 ) { dwbyteswritten1 = dwsize1; dwbyteswritten2 = num_bytes_read - dwsize1; @@ -669,8 +857,48 @@ BOOL AudioStream::WriteWaveData (UINT size, UINT *num_bytes_written, int service dwbyteswritten2 = 0; memcpy(lpbuf1, uncompressed_wave_data, num_bytes_read); } - } +#else + nprintf(("SOUND", "SOUND ==> Queueing %d bytes of Data\n", num_bytes_read)); + // Lock the sound buffer + ALenum format = AL_FORMAT_MONO8; + + if (m_pwavefile->m_wfmt.nChannels == 1) { + if (m_pwavefile->m_wfmt.wBitsPerSample == 8) + format = AL_FORMAT_MONO8; + else if (m_pwavefile->m_wfmt.wBitsPerSample == 16) + format = AL_FORMAT_MONO16; + } else if (m_pwavefile->m_wfmt.nChannels == 2) { + if (m_pwavefile->m_wfmt.wBitsPerSample == 8) + format = AL_FORMAT_STEREO8; + else if (m_pwavefile->m_wfmt.wBitsPerSample == 16) + format = AL_FORMAT_STEREO16; + } + + ALuint bid = 0; + + alSourceUnqueueBuffers(m_al_multichannel_id,1,&bid); + + alGetError(); + + alBufferData(m_al_buffer_ids[m_al_buffer_play],format,uncompressed_wave_data,num_bytes_read,m_pwavefile->m_wfmt.nSamplesPerSec); + + OpenAL_ErrorCheck(return FAILURE); + + alSourceQueueBuffers(m_al_multichannel_id,1,&m_al_buffer_ids[m_al_buffer_play]); + + OpenAL_ErrorCheck(return FAILURE); + m_al_buffer_play++; + + if (m_al_buffer_play>=MAX_AL_BUF) + m_al_buffer_play = 0; + + m_cbBufOffset = (m_cbBufOffset + num_bytes_read) % m_cbBufSize; + *num_bytes_written = num_bytes_read; +#endif + } + +#ifndef PLAT_UNIX // Update our buffer offset and unlock sound buffer m_cbBufOffset = (m_cbBufOffset + dwbyteswritten1 + dwbyteswritten2) % m_cbBufSize; *num_bytes_written = dwbyteswritten1 + dwbyteswritten2; @@ -681,14 +909,20 @@ BOOL AudioStream::WriteWaveData (UINT size, UINT *num_bytes_written, int service nprintf(("SOUND", "SOUND ==> Error, unable to lock sound buffer in AudioStr\n")); fRtn = FAILURE; } +#endif if ( service ) { +#ifndef PLAT_UNIX LeaveCriticalSection(&Global_service_lock); +#else + SDL_UnlockMutex(Global_service_lock); +#endif } return (fRtn); } +#ifndef PLAT_UNIX // WriteSilence // @@ -740,6 +974,8 @@ BOOL AudioStream::WriteSilence (UINT size) return (fRtn); } +#endif + // GetMaxWriteSize // @@ -747,6 +983,7 @@ BOOL AudioStream::WriteSilence (UINT size) // free space there is in buffer. DWORD AudioStream::GetMaxWriteSize (void) { +#ifndef PLAT_UNIX DWORD dwWriteCursor, dwPlayCursor, dwMaxSize; // Get current play position @@ -766,11 +1003,42 @@ DWORD AudioStream::GetMaxWriteSize (void) Int3(); dwMaxSize = 0; } +#else + DWORD dwMaxSize = m_cbBufSize; + ALint n,q; + + alGetSourcei(m_al_multichannel_id,AL_BUFFERS_PROCESSED,&n); + + OpenAL_ErrorCheck(return 0); + + alGetSourcei(m_al_multichannel_id,AL_BUFFERS_QUEUED,&q); + + OpenAL_ErrorCheck(return 0); + + if (!n && q>=MAX_AL_BUF) //all buffers queued + dwMaxSize = 0; +#endif // nprintf(("Alan","Max write size: %d\n", dwMaxSize)); return (dwMaxSize); } +#ifdef PLAT_UNIX +// GetWritingDone +// +// Helper function to check if all data is written +BOOL AudioStream::GetWritingDone (void) +{ + ALint n; + + alGetSourcei(m_al_multichannel_id,AL_BUFFERS_PROCESSED,&n); + + OpenAL_ErrorCheck(return 1); + + return (n == MAX_AL_BUF); //both buffers processed + +} +#endif // ServiceBuffer // @@ -787,16 +1055,26 @@ BOOL AudioStream::ServiceBuffer (void) if ( status != ASF_USED ) return FALSE; +#ifndef PLAT_UNIX EnterCriticalSection(&write_lock); +#else + SDL_LockMutex(write_lock); +#endif // status may have changed, so lets check once again if ( status != ASF_USED ){ +#ifndef PLAT_UNIX LeaveCriticalSection(&write_lock); +#else + SDL_UnlockMutex(write_lock); +#endif return FALSE; } // Check for reentrance +#ifndef PLAT_UNIX if (InterlockedExchange (&m_lInService, TRUE) == FALSE) { +#endif if ( m_bFade == TRUE ) { if ( m_lCutoffVolume == -10000 ) { vol = Get_Volume(); @@ -815,17 +1093,27 @@ BOOL AudioStream::ServiceBuffer (void) m_bFade = 0; m_lCutoffVolume = -10000; if ( m_bDestroy_when_faded == TRUE ) { +#ifndef PLAT_UNIX LeaveCriticalSection(&write_lock); +#else + SDL_UnlockMutex(write_lock); +#endif Destroy(); // Reset reentrancy semaphore +#ifndef PLAT_UNIX InterlockedExchange (&m_lInService, FALSE); +#endif return FALSE; } else { Stop_and_Rewind(); // Reset reentrancy semaphore +#ifndef PLAT_UNIX LeaveCriticalSection(&write_lock); InterlockedExchange (&m_lInService, FALSE); +#else + SDL_UnlockMutex(write_lock); +#endif return TRUE; } } @@ -860,6 +1148,7 @@ BOOL AudioStream::ServiceBuffer (void) m_bPastLimit = TRUE; } +#ifndef PLAT_UNIX if ( (num_bytes_written < dwFreeSpace) && m_bReadingDone ) { int num_bytes_silence; num_bytes_silence = dwFreeSpace - num_bytes_written; @@ -874,12 +1163,21 @@ BOOL AudioStream::ServiceBuffer (void) if ( m_silence_written >= m_cbBufSize ) { m_silence_written = 0; +#else + if ( m_bReadingDone && GetWritingDone()) { +#endif if ( m_bDestroy_when_faded == TRUE ) { +#ifndef PLAT_UNIX LeaveCriticalSection(&write_lock); +#else + SDL_UnlockMutex(write_lock); +#endif Destroy(); // Reset reentrancy semaphore +#ifndef PLAT_UNIX InterlockedExchange (&m_lInService, FALSE); +#endif return FALSE; } @@ -890,8 +1188,10 @@ BOOL AudioStream::ServiceBuffer (void) else { Stop_and_Rewind(); } +#ifndef PLAT_UNIX } } +#endif } } else { @@ -900,7 +1200,7 @@ BOOL AudioStream::ServiceBuffer (void) Int3(); } } - +#ifndef PLAT_UNIX // Reset reentrancy semaphore InterlockedExchange (&m_lInService, FALSE); } else { @@ -909,6 +1209,12 @@ BOOL AudioStream::ServiceBuffer (void) } LeaveCriticalSection(&write_lock); +#endif + +#ifdef PLAT_UNIX + SDL_UnlockMutex(write_lock); +#endif + return (fRtn); } @@ -933,8 +1239,13 @@ void AudioStream::Cue (void) // Reset file ptr, etc m_pwavefile->Cue (); +#ifndef PLAT_UNIX // Reset DirectSound buffer m_pdsb->SetCurrentPosition (0); +#else + // Unqueue all buffers + alSourceUnqueueBuffers(m_al_multichannel_id,MAX_AL_BUF,m_al_buffer_ids); +#endif // Fill buffer with wave data WriteWaveData (m_cbBufSize, &num_bytes_written,0); @@ -947,7 +1258,11 @@ void AudioStream::Cue (void) // Play void AudioStream::Play (long volume, int looping) { +#ifndef PLAT_UNIX if (m_pdsb) { +#else + if (m_al_buffer_ids[0] != 0) { +#endif // If playing, stop if (m_fPlaying) { if ( m_bIsPaused == FALSE) @@ -964,19 +1279,26 @@ void AudioStream::Play (long volume, int looping) else m_bLooping = 0; +#ifndef PLAT_UNIX // Begin DirectSound playback HRESULT hr = m_pdsb->Play (0, 0, DSBPLAY_LOOPING); if (hr == DS_OK) { +#else + alSourcePlay(m_al_multichannel_id); + + OpenAL_ErrorCheck(return); +#endif m_nTimeStarted = timer_get_milliseconds(); Set_Volume(volume); // Kick off timer to service buffer m_timer.constructor(); - m_timer.Create (m_nBufService, m_nBufService, DWORD (this), TimerCallback); + m_timer.Create (m_nBufService, m_nBufService, ptr_u (this), TimerCallback); // Playback begun, no longer cued m_fPlaying = TRUE; m_bIsPaused = FALSE; +#ifndef PLAT_UNIX } else { // If the buffer was lost, try to restore it @@ -995,11 +1317,12 @@ void AudioStream::Play (long volume, int looping) nprintf(("Sound", "Sound => Play failed with return value %s\n", get_DSERR_text(hr) )); } } +#endif } } // Timer callback for Timer object created by ::Play method. -BOOL AudioStream::TimerCallback (DWORD dwUser) +BOOL AudioStream::TimerCallback (ptr_u dwUser) { // dwUser contains ptr to AudioStream object AudioStream * pas = (AudioStream *) dwUser; @@ -1044,7 +1367,15 @@ void AudioStream::Stop(int paused) { if (m_fPlaying) { // Stop DirectSound playback +#ifndef PLAT_UNIX m_pdsb->Stop (); +#else + if (paused) { + alSourcePause(m_al_multichannel_id); + } else { + alSourceStop(m_al_multichannel_id); + } +#endif m_fPlaying = FALSE; m_bIsPaused = paused; @@ -1058,7 +1389,12 @@ void AudioStream::Stop_and_Rewind (void) { if (m_fPlaying) { // Stop DirectSound playback +#ifndef PLAT_UNIX m_pdsb->Stop (); +#else + alSourceStop(m_al_multichannel_id); + OpenAL_ErrorCheck(return); +#endif // Delete Timer object m_timer.destructor(); @@ -1080,14 +1416,25 @@ void AudioStream::Set_Volume(long vol) vol = 0; Assert( vol >= -10000 && vol <= 0 ); + +#ifndef PLAT_UNIX h_result = m_pdsb->SetVolume(vol); +#else + ALfloat alvol = (vol != -10000) ? pow(10.0, (float)vol / (-600.0 / log10(.5))): 0.0; + + alSourcef(m_al_multichannel_id,AL_GAIN,alvol); +#endif + m_lVolume = vol; + +#ifndef PLAT_UNIX if ( h_result != DS_OK ) nprintf(("Sound","SOUND => SetVolume() failed with code '%s'\n", get_DSERR_text(h_result) )); +#endif } -// Set_Volume +// Get_Volume long AudioStream::Get_Volume() { return m_lVolume; @@ -1097,6 +1444,9 @@ long AudioStream::Get_Volume() void Timer::constructor(void) { m_nIDTimer = NULL; +#ifdef PLAT_UNIX + SDL_InitSubSystem(SDL_INIT_TIMER); +#endif } @@ -1104,14 +1454,18 @@ void Timer::constructor(void) void Timer::destructor(void) { if (m_nIDTimer) { +#ifndef PLAT_UNIX timeKillEvent (m_nIDTimer); +#else + SDL_RemoveTimer (m_nIDTimer); +#endif m_nIDTimer = NULL; } } // Create -BOOL Timer::Create (UINT nPeriod, UINT nRes, DWORD dwUser, TIMERCALLBACK pfnCallback) +BOOL Timer::Create (UINT nPeriod, UINT nRes, ptr_u dwUser, TIMERCALLBACK pfnCallback) { BOOL bRtn = SUCCESS; // assume success @@ -1124,7 +1478,12 @@ BOOL Timer::Create (UINT nPeriod, UINT nRes, DWORD dwUser, TIMERCALLBACK pfnCall m_dwUser = dwUser; m_pfnCallback = pfnCallback; +#ifndef PLAT_UNIX if ((m_nIDTimer = timeSetEvent (m_nPeriod, m_nRes, TimeProc, (DWORD) this, TIME_PERIODIC)) == NULL) { +#else + if ((m_nIDTimer = SDL_AddTimer (m_nPeriod, TimeProc, (void*) this)) == NULL) { + nprintf(("SOUND", "SOUND ==> Error, unable to create timer\n")); +#endif bRtn = FAILURE; } @@ -1137,13 +1496,26 @@ BOOL Timer::Create (UINT nPeriod, UINT nRes, DWORD dwUser, TIMERCALLBACK pfnCall // Calls procedure specified when Timer object was created. The // dwUser parameter contains "this" pointer for associated Timer object. // +#ifndef PLAT_UNIX void CALLBACK Timer::TimeProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) +#else +Uint32 CALLBACK Timer::TimeProc(Uint32 interval, void *dwUser) +#endif { // dwUser contains ptr to Timer object Timer * ptimer = (Timer *) dwUser; // Call user-specified callback and pass back user specified data (ptimer->m_pfnCallback) (ptimer->m_dwUser); +#ifdef PLAT_UNIX + if (ptimer->m_nPeriod) + return interval; + else { + SDL_RemoveTimer(ptimer->m_nIDTimer); + ptimer->m_nIDTimer = NULL; + return 0; + } +#endif } @@ -1185,8 +1557,11 @@ void WaveFile::Close(void) // Close file if (cfp) { - //cfclose(cfp); +#ifndef PLAT_UNIX mmioClose( cfp, 0 ); +#else + SDL_RWclose(cfp); +#endif cfp = NULL; } } @@ -1210,34 +1585,71 @@ BOOL WaveFile::Open (LPSTR pszFilename) goto OPEN_ERROR; } +#ifndef PLAT_UNIX cfp = mmioOpen(fullpath, NULL, MMIO_ALLOCBUF | MMIO_READ); +#else + cfp = SDL_RWFromFile(fullpath, "rb"); +#endif + if ( cfp == NULL ) { goto OPEN_ERROR; } // Skip the "RIFF" tag and file size (8 bytes) // Skip the "WAVE" tag (4 bytes) +#ifndef PLAT_UNIX mmioSeek( cfp, 12+FileOffset, SEEK_SET ); - +#else + SDL_RWseek( cfp, 12+FileOffset, SEEK_SET ); +#endif // Now read RIFF tags until the end of file uint tag, size, next_chunk; while(done == FALSE) { +#ifndef PLAT_UNIX if ( mmioRead(cfp, (char *)&tag, sizeof(uint)) != sizeof(uint) ) +#else + if ( SDL_RWread(cfp, &tag, 1, sizeof(uint)) != sizeof(uint) ) +#endif break; + tag = INTEL_INT( tag ); + +#ifndef PLAT_UNIX if ( mmioRead(cfp, (char *)&size, sizeof(uint)) != sizeof(uint) ) +#else + if ( SDL_RWread(cfp, &size, 1, sizeof(uint)) != sizeof(uint) ) +#endif break; + size = INTEL_INT( size ); + +#ifndef PLAT_UNIX next_chunk = mmioSeek( cfp, 0, SEEK_CUR ); +#else + next_chunk = SDL_RWtell( cfp ); +#endif next_chunk += size; switch( tag ) { case 0x20746d66: // The 'fmt ' tag +#ifndef PLAT_UNIX mmioRead( cfp, (char *)&pcmwf, sizeof(PCMWAVEFORMAT) ); if ( pcmwf.wf.wFormatTag != WAVE_FORMAT_PCM ) { mmioRead( cfp, (char *)&cbExtra, sizeof(short) ); } +#else + audiostr_read_word(cfp, &pcmwf.wf.wFormatTag); + audiostr_read_word(cfp, &pcmwf.wf.nChannels); + audiostr_read_dword(cfp, &pcmwf.wf.nSamplesPerSec); + audiostr_read_dword(cfp, &pcmwf.wf.nAvgBytesPerSec); + audiostr_read_word(cfp, &pcmwf.wf.nBlockAlign); + audiostr_read_word(cfp, &pcmwf.wBitsPerSample); + + if ( pcmwf.wf.wFormatTag != WAVE_FORMAT_PCM ) { + audiostr_read_word(cfp, &cbExtra); + } +#endif // Allocate memory for WAVEFORMATEX structure + extra bytes if ( (m_pwfmt_original = (WAVEFORMATEX *) malloc ( sizeof(WAVEFORMATEX)+cbExtra )) != NULL ){ @@ -1248,7 +1660,11 @@ BOOL WaveFile::Open (LPSTR pszFilename) // Read those extra bytes, append to WAVEFORMATEX structure if (cbExtra != 0) { +#ifndef PLAT_UNIX mmioRead( cfp, (char *)((ubyte *)(m_pwfmt_original) + sizeof(WAVEFORMATEX)), cbExtra ); +#else + SDL_RWread( cfp, ((ubyte *)(m_pwfmt_original) + sizeof(WAVEFORMATEX)), 1, cbExtra ); +#endif } } else { @@ -1260,7 +1676,11 @@ BOOL WaveFile::Open (LPSTR pszFilename) case 0x61746164: // the 'data' tag m_nDataSize = size; // This is size of data chunk. Compressed if ADPCM. m_data_bytes_left = size; +#ifndef PLAT_UNIX m_data_offset = mmioSeek( cfp, 0, SEEK_CUR); +#else + m_data_offset = SDL_RWtell( cfp ); +#endif done = TRUE; break; @@ -1268,7 +1688,11 @@ BOOL WaveFile::Open (LPSTR pszFilename) break; } // end switch +#ifndef PLAT_UNIX mmioSeek( cfp, next_chunk, SEEK_SET ); +#else + SDL_RWseek( cfp, next_chunk, SEEK_SET ); +#endif } // At this stage, examine source format, and set up WAVEFORATEX structure for DirectSound. @@ -1283,6 +1707,7 @@ BOOL WaveFile::Open (LPSTR pszFilename) case WAVE_FORMAT_ADPCM: m_wave_format = WAVE_FORMAT_ADPCM; m_wfmt.wBitsPerSample = 16; + m_bits_per_sample_uncompressed = 16; break; default: @@ -1318,7 +1743,11 @@ OPEN_ERROR: fRtn = FAILURE; if (cfp != NULL) { // Close file +#ifndef PLAT_UNIX mmioClose( cfp, 0 ); +#else + SDL_RWclose( cfp ); +#endif cfp = NULL; } if (m_pwfmt_original) @@ -1344,7 +1773,11 @@ BOOL WaveFile::Cue (void) m_total_uncompressed_bytes_read = 0; m_max_uncompressed_bytes_to_read = AS_HIGHEST_MAX; +#ifndef PLAT_UNIX rval = mmioSeek( cfp, m_data_offset, SEEK_SET ); +#else + rval = SDL_RWseek( cfp, m_data_offset, SEEK_SET ); +#endif if ( rval == -1 ) { fRtn = FAILURE; } @@ -1386,10 +1819,11 @@ int WaveFile::Read(BYTE *pbDest, UINT cbSize, int service) case WAVE_FORMAT_ADPCM: if ( !m_hStream_open ) { - if ( !ACM_stream_open(m_pwfmt_original, &m_wfxDest, (void**)&m_hStream), m_bits_per_sample_uncompressed ) { + if ( !ACM_stream_open(m_pwfmt_original, &m_wfxDest, (void**)&m_hStream, m_bits_per_sample_uncompressed) ) { m_hStream_open = 1; } else { Int3(); + return -1; } } @@ -1413,6 +1847,7 @@ int WaveFile::Read(BYTE *pbDest, UINT cbSize, int service) default: nprintf(("SOUND", "SOUND => Not supporting %d format for playing wave files\n")); Int3(); + return -1; break; } // end switch @@ -1438,7 +1873,11 @@ int WaveFile::Read(BYTE *pbDest, UINT cbSize, int service) num_bytes_read = m_data_bytes_left; } +#ifndef PLAT_UNIX actual_read = mmioRead( cfp, (char *)dest_buf, num_bytes_read ); +#else + actual_read = SDL_RWread( cfp, dest_buf, 1, num_bytes_read ); +#endif if ( (actual_read <= 0) || (m_abort_next_read) ) { num_bytes_read = 0; uncompressed_bytes_written = 0; @@ -1461,13 +1900,18 @@ int WaveFile::Read(BYTE *pbDest, UINT cbSize, int service) } if ( convert_len == 0 ) { Int3(); + goto READ_ERROR; } } Assert(src_bytes_used <= num_bytes_read); if ( src_bytes_used < num_bytes_read ) { // seek back file pointer to reposition before unused source data +#ifndef PLAT_UNIX mmioSeek(cfp, src_bytes_used - num_bytes_read, SEEK_CUR); +#else + SDL_RWseek( cfp, src_bytes_used - num_bytes_read, SEEK_CUR ); +#endif } // Adjust number of bytes left @@ -1498,6 +1942,7 @@ READ_DONE: } +#ifndef PLAT_UNIX // GetSilenceData // // Returns 8 bits of data representing silence for the Wave file format. @@ -1531,20 +1976,23 @@ BYTE WaveFile::GetSilenceData (void) } else { Int3(); + return -1; } } else { Int3(); + return -1; } return (bSilenceData); } +#endif + AudioStreamServices * m_pass = NULL; // ptr to AudioStreamServices object #define MAX_AUDIO_STREAMS 30 AudioStream Audio_streams[MAX_AUDIO_STREAMS]; -#endif // !PLAT_UNIX int Audiostream_inited = 0; @@ -1553,9 +2001,6 @@ void audiostream_init() if ( Audiostream_inited == 1 ) return; -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else int i; if ( !ACM_is_inited() ) { @@ -1570,10 +2015,11 @@ void audiostream_init() if (m_pass) { m_pass->Constructor(); m_pass->Initialize(); - +#ifndef PLAT_UNIX if ( !pDirectSound ) { return; } +#endif } // Allocate memory for the buffer which holds the uncompressed wave data that is streamed from the @@ -1607,7 +2053,10 @@ void audiostream_init() Audio_streams[i].type = ASF_NONE; } +#ifndef PLAT_UNIX InitializeCriticalSection( &Global_service_lock ); +#else + Global_service_lock = SDL_CreateMutex( ); #endif Audiostream_inited = 1; @@ -1620,9 +2069,6 @@ void audiostream_close() if ( Audiostream_inited == 0 ) return; -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else int i; for ( i = 0; i < MAX_AUDIO_STREAMS; i++ ) { @@ -1659,7 +2105,10 @@ void audiostream_close() Compressed_service_buffer = NULL; } +#ifndef PLAT_UNIX DeleteCriticalSection( &Global_service_lock ); +#else + SDL_DestroyMutex( Global_service_lock ); #endif Audiostream_inited = 0; } @@ -1676,10 +2125,7 @@ void audiostream_close() // failure => -1 int audiostream_open( char * filename, int type ) { -#ifdef PLAT_UNIX - STUB_FUNCTION; - return -1; -#else + int i, rc; if (!Audiostream_inited || !snd_is_inited()) return -1; @@ -1717,7 +2163,6 @@ int audiostream_open( char * filename, int type ) } else return i; -#endif } @@ -1728,9 +2173,6 @@ void audiostream_close_file(int i, int fade) if ( i == -1 ) return; -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else Assert( i >= 0 && i < MAX_AUDIO_STREAMS ); @@ -1742,14 +2184,10 @@ void audiostream_close_file(int i, int fade) Audio_streams[i].Destroy(); } } -#endif } void audiostream_close_all(int fade) { -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else int i; for ( i = 0; i < MAX_AUDIO_STREAMS; i++ ) { @@ -1758,7 +2196,6 @@ void audiostream_close_all(int fade) audiostream_close_file(i, fade); } -#endif } extern int ds_convert_volume(float volume); @@ -1771,9 +2208,6 @@ void audiostream_play(int i, float volume, int looping) if ( i == -1 ) return; -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else Assert(looping >= 0); Assert( i >= 0 && i < MAX_AUDIO_STREAMS ); @@ -1790,7 +2224,6 @@ void audiostream_play(int i, float volume, int looping) Assert( Audio_streams[i].status == ASF_USED ); Audio_streams[i].Set_Default_Volume(converted_volume); Audio_streams[i].Play(converted_volume, looping); -#endif } void audiostream_stop(int i, int rewind, int paused) @@ -1800,9 +2233,6 @@ void audiostream_stop(int i, int rewind, int paused) if ( i == -1 ) return; -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else Assert( i >= 0 && i < MAX_AUDIO_STREAMS ); Assert( Audio_streams[i].status == ASF_USED ); @@ -1810,7 +2240,6 @@ void audiostream_stop(int i, int rewind, int paused) Audio_streams[i].Stop_and_Rewind(); else Audio_streams[i].Stop(paused); -#endif } int audiostream_is_playing(int i) @@ -1818,24 +2247,16 @@ int audiostream_is_playing(int i) if ( i == -1 ) return 0; -#ifdef PLAT_UNIX - STUB_FUNCTION; - return 0; -#else Assert( i >= 0 && i < MAX_AUDIO_STREAMS ); if ( Audio_streams[i].status != ASF_USED ) return 0; return Audio_streams[i].Is_Playing(); -#endif } void audiostream_set_volume_all(float volume, int type) { -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else int i; for ( i = 0; i < MAX_AUDIO_STREAMS; i++ ) { @@ -1848,7 +2269,6 @@ void audiostream_set_volume_all(float volume, int type) Audio_streams[i].Set_Volume(converted_volume); } } -#endif } @@ -1857,9 +2277,6 @@ void audiostream_set_volume(int i, float volume) if ( i == -1 ) return; -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else Assert( i >= 0 && i < MAX_AUDIO_STREAMS ); Assert( volume >= 0 && volume <= 1); @@ -1869,7 +2286,6 @@ void audiostream_set_volume(int i, float volume) int converted_volume; converted_volume = ds_convert_volume(volume); Audio_streams[i].Set_Volume(converted_volume); -#endif } @@ -1878,10 +2294,6 @@ int audiostream_is_paused(int i) if ( i == -1 ) return 0; -#ifdef PLAT_UNIX - STUB_FUNCTION; - return 0; -#else Assert( i >= 0 && i < MAX_AUDIO_STREAMS ); if ( Audio_streams[i].status == ASF_FREE ) return -1; @@ -1889,7 +2301,6 @@ int audiostream_is_paused(int i) BOOL is_paused; is_paused = Audio_streams[i].Is_Paused(); return is_paused; -#endif } @@ -1898,9 +2309,6 @@ void audiostream_set_byte_cutoff(int i, unsigned int cutoff) if ( i == -1 ) return; -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else Assert( i >= 0 && i < MAX_AUDIO_STREAMS ); Assert( cutoff > 0 ); @@ -1908,7 +2316,6 @@ void audiostream_set_byte_cutoff(int i, unsigned int cutoff) return; Audio_streams[i].Set_Byte_Cutoff(cutoff); -#endif } @@ -1917,10 +2324,6 @@ unsigned int audiostream_get_bytes_committed(int i) if ( i == -1 ) return 0; -#ifdef PLAT_UNIX - STUB_FUNCTION; - return 0; -#else Assert( i >= 0 && i < MAX_AUDIO_STREAMS ); if ( Audio_streams[i].status == ASF_FREE ) @@ -1929,7 +2332,6 @@ unsigned int audiostream_get_bytes_committed(int i) unsigned int num_bytes_committed; num_bytes_committed = Audio_streams[i].Get_Bytes_Committed(); return num_bytes_committed; -#endif } int audiostream_done_reading(int i) @@ -1937,10 +2339,6 @@ int audiostream_done_reading(int i) if ( i == -1 ) return 0; -#ifdef PLAT_UNIX - STUB_FUNCTION; - return 0; -#else Assert( i >= 0 && i < MAX_AUDIO_STREAMS ); if ( Audio_streams[i].status == ASF_FREE ) @@ -1949,7 +2347,6 @@ int audiostream_done_reading(int i) int done_reading; done_reading = Audio_streams[i].Is_Past_Limit(); return done_reading; -#endif } @@ -1964,9 +2361,6 @@ void audiostream_pause(int i) if ( i == -1 ) return; -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else Assert( i >= 0 && i < MAX_AUDIO_STREAMS ); if ( Audio_streams[i].status == ASF_FREE ) return; @@ -1974,15 +2368,11 @@ void audiostream_pause(int i) if ( audiostream_is_playing(i) == TRUE ) { audiostream_stop(i, 0, 1); } -#endif } // pause all audio streams that are currently playing. void audiostream_pause_all() { -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else int i; for ( i = 0; i < MAX_AUDIO_STREAMS; i++ ) { @@ -1991,7 +2381,6 @@ void audiostream_pause_all() audiostream_pause(i); } -#endif } // unpause the audio stream identified by handle i. @@ -2000,9 +2389,6 @@ void audiostream_unpause(int i) if ( i == -1 ) return; -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else int is_looping; Assert( i >= 0 && i < MAX_AUDIO_STREAMS ); @@ -2013,15 +2399,11 @@ void audiostream_unpause(int i) is_looping = Audio_streams[i].Is_looping(); audiostream_play(i, -1.0f, is_looping); } -#endif } // unpause all audio streams that are currently paused void audiostream_unpause_all() { -#ifdef PLAT_UNIX - STUB_FUNCTION; -#else int i; for ( i = 0; i < MAX_AUDIO_STREAMS; i++ ) { @@ -2030,6 +2412,5 @@ void audiostream_unpause_all() audiostream_unpause(i); } -#endif } diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp index f89ace1..89e174f 100644 --- a/src/sound/sound.cpp +++ b/src/sound/sound.cpp @@ -15,6 +15,13 @@ * Low-level sound code * * $Log$ + * Revision 1.10 2005/03/29 02:18:47 taylor + * Various 64-bit platform fixes + * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too + * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) + * Streaming audio support (big thanks to Pierre Willenbrock!!) + * Removed dependance on strings.tbl for FS1 since we don't actually need it now + * * Revision 1.9 2002/06/22 16:34:40 relnev * removed file * @@ -457,14 +464,16 @@ int snd_init(int use_a3d, int use_eax) } } + if ( ACM_init() == -1 ) { #ifndef PLAT_UNIX // Init the Audio Compression Manager - if ( ACM_init() == -1 ) { HWND hwnd = (HWND)os_get_window(); MessageBox(hwnd, XSTR("Could not properly initialize the Microsoft ADPCM codec.\n\nPlease see the readme.txt file for detailed instructions on installing the Microsoft ADPCM codec.",972), NULL, MB_OK); // Warning(LOCATION, "Could not properly initialize the Microsoft ADPCM codec.\nPlease see the readme.txt file for detailed instructions on installing the Microsoft ADPCM codec."); - } +#else + nprintf(( "Sound", "Could not initialize ADPCM codec.\n" )); #endif + } // Init the audio streaming stuff audiostream_init(); @@ -717,9 +726,7 @@ void snd_close(void) snd_stop_all(); if (!ds_initialized) return; snd_unload_all(); // free the sound data stored in DirectSound secondary buffers -#ifndef PLAT_UNIX ACM_close(); // Close the Audio Compression Manager (ACM) -#endif ds3d_close(); // Close DirectSound3D dscap_close(); // Close DirectSoundCapture ds_close(); // Close DirectSound off diff --git a/src/stats/medals.cpp b/src/stats/medals.cpp index 62bc80c..a5b91ce 100644 --- a/src/stats/medals.cpp +++ b/src/stats/medals.cpp @@ -13,6 +13,13 @@ * $Author$ * * $Log$ + * Revision 1.14 2005/03/29 02:18:47 taylor + * Various 64-bit platform fixes + * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too + * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions) + * Streaming audio support (big thanks to Pierre Willenbrock!!) + * Removed dependance on strings.tbl for FS1 since we don't actually need it now + * * Revision 1.13 2004/09/20 01:31:45 theoddone33 * GCC 3.4 fixes. * @@ -353,25 +360,18 @@ ui_button_info Medals_buttons[GR_NUM_RESOLUTIONS][MEDALS_NUM_BUTTONS] = { } }; -#ifdef MAKE_FS1 - #define MEDALS_NUM_TEXT 0 -#else - #define MEDALS_NUM_TEXT 1 -#endif +#ifndef MAKE_FS1 +#define MEDALS_NUM_TEXT 1 + UI_XSTR Medals_text[GR_NUM_RESOLUTIONS][MEDALS_NUM_TEXT] = { { // GR_640 - // not needed for FS1 -#ifndef MAKE_FS1 {"Exit", 1466, 587, 416, UI_XSTR_COLOR_PINK, -1, &Medals_buttons[GR_640][MEDALS_EXIT].button }, -#endif }, { // GR_1024 - // not needed for FS1 -#ifndef MAKE_FS1 {"Exit", 1466, 943, 673, UI_XSTR_COLOR_PINK, -1, &Medals_buttons[GR_1024][MEDALS_EXIT].button }, -#endif }, }; +#endif static char* Medals_background_filename[GR_NUM_RESOLUTIONS] = { "MedalsDisplayEmpty", @@ -553,10 +553,12 @@ void medal_main_init(player *pl, int mode) Medals_buttons[gr_screen.res][idx].button.link_hotspot(Medals_buttons[gr_screen.res][idx].hotspot); } +#ifndef MAKE_FS1 // add all xstrs for (idx=0; idx