Skip to content

Commit

Permalink
Merge pull request #1156 from MageKing17/cleanup/demo-compatibility
Browse files Browse the repository at this point in the history
Improves FSO's compatibility with the FS2 Demo data
  • Loading branch information
asarium committed Jan 28, 2017
2 parents 6bc1e1c + 377751a commit 39649e9
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 25 deletions.
4 changes: 4 additions & 0 deletions code/bmpman/bmpman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3080,6 +3080,10 @@ int bm_unload(int handle, int clear_render_targets, bool nodebug) {
bitmap_entry *be;
bitmap *bmp;

if (handle == -1) {
return -1;
}

int n = handle % MAX_BITMAPS;

Assert((n >= 0) && (n < MAX_BITMAPS));
Expand Down
4 changes: 1 addition & 3 deletions code/graphics/2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -995,10 +995,8 @@ bool gr_init(std::unique_ptr<os::GraphicsOperations>&& graphicsOps, int d_mode,

if (gr_get_resolution_class(width, height) != GR_640) {
// check for hi-res interface files so that we can verify our width/height is correct
bool has_sparky_hi = (cf_exists_full("2_ChoosePilot-m.pcx", CF_TYPE_ANY) && cf_exists_full("2_TechShipData-m.pcx", CF_TYPE_ANY));

// if we don't have it then fall back to 640x480 mode instead
if ( !has_sparky_hi ) {
if ( !cf_exists_full("2_ChoosePilot-m.pcx", CF_TYPE_ANY)) {
if ( (width == 1024) && (height == 768) ) {
width = 640;
height = 480;
Expand Down
28 changes: 27 additions & 1 deletion code/hud/hudconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ HC_special_bitmap HC_special_bitmaps[NUM_HC_SPECIAL_BITMAPS] =
*/

static int HC_background_bitmap;
static int HC_background_bitmap_mask;
static UI_WINDOW HC_ui_window;

static int HC_gauge_hot; // mouse is over this gauge
Expand Down Expand Up @@ -705,9 +706,19 @@ void hud_config_init_ui()

hud_config_synch_ui();
HC_background_bitmap = bm_load(Hud_config_fname[gr_screen.res]);
if (HC_background_bitmap < 0) {
Warning(LOCATION, "Error loading HUD config menu background %s", Hud_config_fname[gr_screen.res]);
}

HC_ui_window.create( 0, 0, gr_screen.max_w_unscaled, gr_screen.max_h_unscaled, 0 );
HC_ui_window.set_mask_bmap(Hud_config_mask_fname[gr_screen.res]);

HC_background_bitmap_mask = bm_load(Hud_config_mask_fname[gr_screen.res]);
if (HC_background_bitmap_mask < 0) {
Warning(LOCATION, "Error loading HUD config menu mask %s", Hud_config_mask_fname[gr_screen.res]);
return;
} else {
HC_ui_window.set_mask_bmap(Hud_config_mask_fname[gr_screen.res]);
}

for (i=0; i<NUM_HUD_GAUGES; i++) {
hg = &HC_gauge_regions[gr_screen.res][i];
Expand Down Expand Up @@ -1472,6 +1483,13 @@ void hud_config_do_frame(float frametime)
hud_config_init();
}

// If we don't have a mask, we don't have enough data to do anything with this screen.
if (HC_background_bitmap_mask == -1) {
popup_game_feature_not_in_demo();
gameseq_post_event(GS_EVENT_PREVIOUS_STATE);
return;
}

HC_gauge_hot = -1;

hud_config_set_button_state();
Expand Down Expand Up @@ -1545,7 +1563,15 @@ void hud_config_close()

hud_config_color_close();

if (HC_background_bitmap != -1) {
bm_release(HC_background_bitmap);
}

HC_ui_window.destroy();

if (HC_background_bitmap_mask != -1) {
bm_release(HC_background_bitmap_mask);
}
}

// hud_set_default_hud_config() will set the hud configuration to default values
Expand Down
7 changes: 4 additions & 3 deletions code/menuui/mainhallmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2187,9 +2187,10 @@ void parse_main_hall_table(const char* filename)
stuff_string(temp_string, F_NAME, MAX_FILENAME_LEN);
m->mask = temp_string;

required_string("+Music:");
stuff_string(temp_string, F_NAME, MAX_FILENAME_LEN);
m->music_name = temp_string;
if (optional_string("+Music:")) { // Demo doesn't have these lines.
stuff_string(temp_string, F_NAME, MAX_FILENAME_LEN);
m->music_name = temp_string;
}

// Goober5000
if (optional_string("+Substitute Music:")) {
Expand Down
31 changes: 30 additions & 1 deletion code/menuui/readyroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ static int list_w1;
static int list_w2;
static int list_h;
static int Background_bitmap;
static int Campaign_background_bitmap_mask;
static UI_WINDOW Ui_window;
static UI_BUTTON List_buttons[LIST_BUTTONS_MAX]; // buttons for each line of text in list

Expand Down Expand Up @@ -1641,7 +1642,13 @@ void campaign_room_init()
list_h = Mission_list_coords[gr_screen.res][3];

Ui_window.create(0, 0, gr_screen.max_w_unscaled, gr_screen.max_h_unscaled, 0);
Ui_window.set_mask_bmap(Campaign_mask_filename[gr_screen.res]);

Campaign_background_bitmap_mask = bm_load(Campaign_mask_filename[gr_screen.res]);
if (Campaign_background_bitmap_mask < 0) {
Warning(LOCATION, "Error loading campaign room mask %s", Campaign_mask_filename[gr_screen.res]);
} else {
Ui_window.set_mask_bmap(Campaign_mask_filename[gr_screen.res]);
}

for (i=0; i<CR_NUM_BUTTONS; i++) {
b = &Cr_buttons[gr_screen.res][i];
Expand Down Expand Up @@ -1672,6 +1679,9 @@ void campaign_room_init()
// Cr_buttons[gr_screen.res][CR_HELP_BUTTON].button.set_hotkey(KEY_F2);

Background_bitmap = bm_load(Campaign_filename[gr_screen.res]);
if (Background_bitmap < 0) {
Warning(LOCATION, "Error loading campaign room background %s", Campaign_filename[gr_screen.res]);
}

// load in help overlay bitmap
Campaign_room_overlay_id = help_overlay_get_index(CAMPAIGN_ROOM_OVERLAY);
Expand Down Expand Up @@ -1718,6 +1728,11 @@ void campaign_room_close()
mission_campaign_free_list();

Ui_window.destroy();

if (Campaign_background_bitmap_mask >= 0) {
bm_release(Campaign_background_bitmap_mask);
}

common_free_interface_palette(); // restore game palette
Pilot.save_player();
}
Expand All @@ -1729,6 +1744,20 @@ void campaign_room_do_frame(float frametime)
int i, k, y, line;
int select_tease_line = -1; // line mouse is down on, but won't be selected until button released

// If we don't have a mask, we don't have enough data to do anything with this screen.
if (Campaign_background_bitmap_mask == -1) {
{
//popup_game_feature_not_in_demo();
int reset_campaign = popup(PF_USE_AFFIRMATIVE_ICON|PF_BODY_BIG, 2, "Exit", "Restart Campaign", "Campaign Room only available in full version. However, you may restart the campaign.");
if (reset_campaign == 1) {
// Rather than hardcoding the reset, let's reuse this.
campaign_room_reset_campaign(Active_campaign_index);
}
}
gameseq_post_event(GS_EVENT_MAIN_MENU);
return;
}

if ( help_overlay_active(Campaign_room_overlay_id) ) {
// Cr_buttons[gr_screen.res][CR_HELP_BUTTON].button.reset_status();
Ui_window.set_ignore_gadgets(1);
Expand Down
31 changes: 24 additions & 7 deletions code/menuui/techmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "missionui/missionscreencommon.h"
#include "parse/parselo.h"
#include "playerman/player.h"
#include "popup/popup.h"
#include "render/3d.h"
#include "render/batching.h"
#include "ship/ship.h"
Expand Down Expand Up @@ -192,6 +193,7 @@ static techroom_buttons Buttons[GR_NUM_RESOLUTIONS][NUM_BUTTONS] = {
static UI_WINDOW Ui_window;
static UI_BUTTON View_window;
static int Tech_background_bitmap;
static int Tech_background_bitmap_mask;
static int Tab = SHIPS_DATA_TAB;
static int List_offset;
static int Select_tease_line;
Expand All @@ -210,7 +212,6 @@ static int Cur_entry_index = -1; // this is the current entry selected, using m
static int Techroom_ship_modelnum;
static float Techroom_ship_rot;
static UI_BUTTON List_buttons[LIST_BUTTONS_MAX]; // buttons for each line of text in list
static int Palette_bmp;

static int Ships_loaded = 0;
static int Weapons_loaded = 0;
Expand Down Expand Up @@ -1117,12 +1118,19 @@ void techroom_init()

// set up UI stuff
Ui_window.create(0, 0, gr_screen.max_w_unscaled, gr_screen.max_h_unscaled, 0);
Ui_window.set_mask_bmap(Tech_mask_filename[gr_screen.res]);

Tech_background_bitmap = bm_load(Tech_background_filename[gr_screen.res]);
if (Tech_background_bitmap < 0) {
// failed to load bitmap, not a good thing
Error(LOCATION,"Couldn't load techroom background bitmap");
Warning(LOCATION,"Error loading techroom background bitmap %s", Tech_background_filename[gr_screen.res]);
}

Tech_background_bitmap_mask = bm_load(Tech_mask_filename[gr_screen.res]);
if (Tech_background_bitmap_mask < 0) {
Warning(LOCATION, "Error loading techroom background mask %s", Tech_mask_filename[gr_screen.res]);
return;
} else {
Ui_window.set_mask_bmap(Tech_mask_filename[gr_screen.res]);
}

for (i=0; i<NUM_BUTTONS; i++) {
Expand Down Expand Up @@ -1260,22 +1268,31 @@ void techroom_close()

Techroom_show_all = 0;

if (Tech_background_bitmap) {
if (Tech_background_bitmap != -1) {
bm_release(Tech_background_bitmap);
}

Ui_window.destroy();
common_free_interface_palette(); // restore game palette
if (Palette_bmp){
bm_release(Palette_bmp);

if (Tech_background_bitmap_mask != -1) {
bm_release(Tech_background_bitmap_mask);
}

common_free_interface_palette(); // restore game palette
}

void techroom_do_frame(float frametime)
{

int i, k;

// If we don't have a mask, we don't have enough data to do anything with this screen.
if (Tech_background_bitmap_mask == -1) {
popup_game_feature_not_in_demo();
gameseq_post_event(GS_EVENT_MAIN_MENU);
return;
}

// turn off controls when overlay is on
if ( help_overlay_active(Techroom_overlay_id) ) {
Buttons[gr_screen.res][HELP_BUTTON].button.reset_status();
Expand Down
3 changes: 0 additions & 3 deletions code/mission/missiontraining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,6 @@ int comp_training_lines_by_born_on_date(const void *m1, const void *m2)
int *e1, *e2;
e1 = (int*) m1;
e2 = (int*) m2;

Assert(Mission_events[*e1 & 0xffff].born_on_date != 0);
Assert(Mission_events[*e2 & 0xffff].born_on_date != 0);

return (Mission_events[*e1 & 0xffff].born_on_date - Mission_events[*e2 & 0xffff].born_on_date);
}
Expand Down
8 changes: 6 additions & 2 deletions code/missionui/missionbrief.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,9 @@ void brief_render(float frametime)
}
}

brief_maybe_blit_scene_cut(frametime);
if (Fade_anim.first_frame != -1) {
brief_maybe_blit_scene_cut(frametime);
}

#if !defined(NDEBUG)
gr_set_color_fast(&Color_normal);
Expand Down Expand Up @@ -1822,7 +1824,9 @@ void brief_close()
// unload the audio streams used for voice playback
brief_voice_unload_all();

bm_unload(Fade_anim.first_frame);
if (Fade_anim.first_frame != -1) {
bm_unload(Fade_anim.first_frame);
}

Brief_ui_window.destroy();

Expand Down
6 changes: 6 additions & 0 deletions code/popup/popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,3 +1164,9 @@ void popup_change_text(const char *new_text)
// recalculate all display information
popup_split_lines(&Popup_info,Popup_flags);
}

// If we're running on demo data, certain menus can't be displayed; this message will get shown instead.
void popup_game_feature_not_in_demo()
{
popup(PF_USE_AFFIRMATIVE_ICON|PF_BODY_BIG, 1, POPUP_OK, XSTR( "Sorry, this feature is available only in the retail version", 200));
}
3 changes: 3 additions & 0 deletions code/popup/popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,7 @@ void popup_kill_any_active();
// change the text inside of the popup
void popup_change_text(const char *new_text);

// Used if certain data is missing (e.g. running demo data).
void popup_game_feature_not_in_demo();

#endif
29 changes: 24 additions & 5 deletions code/stats/medals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "palman/palman.h"
#include "parse/parselo.h"
#include "playerman/player.h"
#include "popup/popup.h"
#include "stats/medals.h"
#include "ui/ui.h"

Expand Down Expand Up @@ -557,7 +558,7 @@ void medal_main_init(player *pl, int mode)

Medals_bitmap = bm_load(bitmap_buf);
if (Medals_bitmap < 0) {
Error(LOCATION, "Error loading medal background bitmap %s", bitmap_buf);
Warning(LOCATION, "Error loading medal background bitmap %s", bitmap_buf);
} else {
Init_flags |= MEDAL_BITMAP_INIT;
}
Expand All @@ -570,18 +571,21 @@ void medal_main_init(player *pl, int mode)

Medals_bitmap_mask = bm_load(bitmap_buf);
if (Medals_bitmap_mask < 0) {
Error(LOCATION, "Error loading medal mask file %s", bitmap_buf);
Warning(LOCATION, "Error loading medal mask file %s", bitmap_buf);
} else {
Init_flags |= MASK_BITMAP_INIT;
Medals_mask = bm_lock(Medals_bitmap_mask, 8, BMP_AABITMAP);
bm_get_info(Medals_bitmap_mask, &Medals_mask_w, &Medals_mask_h);

init_medal_bitmaps();
}
init_medal_bitmaps();

init_snazzy_regions();

gr_set_color_fast(&Color_normal);

Medals_window.set_mask_bmap(bitmap_buf);
if (Medals_bitmap_mask >= 0)
Medals_window.set_mask_bmap(bitmap_buf);
}

void blit_label(char *label, int num)
Expand Down Expand Up @@ -659,6 +663,16 @@ void blit_callsign()
int medal_main_do()
{
int region,selected, k;

// If we don't have a mask, we don't have enough data to do anything with this screen.
if (Medals_bitmap_mask == -1) {
popup_game_feature_not_in_demo();
if (Medals_mode == MM_NORMAL)
gameseq_post_event(GS_EVENT_PREVIOUS_STATE);
// any calling popup function will know to close the screen down
return 0;
}

k = Medals_window.process();

// process an exit command
Expand Down Expand Up @@ -729,7 +743,6 @@ void medal_main_close()

if (Init_flags & MASK_BITMAP_INIT) {
bm_unlock(Medals_bitmap_mask);
bm_release(Medals_bitmap_mask);
}

for (SCP_vector<medal_display_info>::iterator idx = Medal_display_info.begin(); idx != Medal_display_info.end(); ++idx) {
Expand All @@ -743,7 +756,13 @@ void medal_main_close()
Medal_regions = NULL;

Player_score = NULL;

Medals_window.destroy();

if (Init_flags & MASK_BITMAP_INIT) {
bm_release(Medals_bitmap_mask);
}

snazzy_menu_close();
palette_restore_palette();
}
Expand Down

0 comments on commit 39649e9

Please sign in to comment.