fixed so that the demo player doesn't crash when the map isn't found

This commit is contained in:
Magnus Auvinen 2009-06-15 13:16:33 +00:00
parent feade98dae
commit 57b2c49d57
5 changed files with 42 additions and 6 deletions

View file

@ -1902,9 +1902,10 @@ static void con_addfavorite(void *result, void *user_data)
client_serverbrowse_addfavorite(addr);
}
void client_demoplayer_play(const char *filename)
const char *client_demoplayer_play(const char *filename)
{
int crc;
const char *error;
client_disconnect();
netclient_error_string_reset(net);
@ -1912,14 +1913,20 @@ void client_demoplayer_play(const char *filename)
demorec_playback_registercallbacks(client_democallback_snapshot, client_democallback_message);
if(demorec_playback_load(filename))
return;
return "error loading demo";
/* load map */
crc = (demorec_playback_info()->header.crc[0]<<24)|
(demorec_playback_info()->header.crc[1]<<16)|
(demorec_playback_info()->header.crc[2]<<8)|
(demorec_playback_info()->header.crc[3]);
client_load_map_search(demorec_playback_info()->header.map, crc);
error = client_load_map_search(demorec_playback_info()->header.map, crc);
if(error)
{
client_disconnect_with_reason(error);
return error;
}
modc_connected();
/* setup buffers */
@ -1943,6 +1950,8 @@ void client_demoplayer_play(const char *filename)
demorec_playback_play();
modc_entergame();
return 0;
}
static void con_play(void *result, void *user_data)

View file

@ -567,7 +567,7 @@ typedef struct DEMOPLAYBACK_INFO
float speed;
} DEMOPLAYBACK_INFO;
void client_demoplayer_play(const char *filename);
const char *client_demoplayer_play(const char *filename);
const DEMOPLAYBACK_INFO *client_demoplayer_getinfo();
void client_demoplayer_setpos(float percent);
void client_demoplayer_setpause(int paused);

View file

@ -666,6 +666,15 @@ void MENUS::on_init()
config.cl_show_welcome = 0;
}
void MENUS::popup_message(const char *topic, const char *body, const char *button)
{
str_copy(message_topic, topic, sizeof(message_topic));
str_copy(message_body, body, sizeof(message_body));
str_copy(message_button, button, sizeof(message_button));
popup = POPUP_MESSAGE;
}
int MENUS::render()
{
RECT screen = *ui_screen();
@ -749,7 +758,13 @@ int MENUS::render()
const char *button_text = "";
int extra_align = 0;
if(popup == POPUP_CONNECTING)
if(popup == POPUP_MESSAGE)
{
title = message_topic;
extra_text = message_body;
button_text = message_button;
}
else if(popup == POPUP_CONNECTING)
{
title = localize("Connecting to");
extra_text = config.ui_server_address; // TODO: query the client about the address

View file

@ -68,6 +68,7 @@ class MENUS : public COMPONENT
POPUP_NONE=0,
POPUP_FIRST_LAUNCH,
POPUP_CONNECTING,
POPUP_MESSAGE,
POPUP_DISCONNECTED,
POPUP_PURE,
POPUP_PASSWORD,
@ -95,6 +96,13 @@ class MENUS : public COMPONENT
vec2 mouse_pos;
int64 last_input;
//
char message_topic[512];
char message_body[512];
char message_button[512];
void popup_message(const char *topic, const char *body, const char *button);
// TODO: this is a bit ugly but.. well.. yeah
enum { MAX_INPUTEVENTS = 32 };

View file

@ -406,7 +406,11 @@ void MENUS::render_demolist(RECT main_view)
if(ui_do_button(&play_button, localize("Play"), 0, &play_rect, ui_draw_menu_button, 0))
{
if(selected_item >= 0 && selected_item < demos.size())
client_demoplayer_play(demos[selected_item].filename);
{
const char *error = client_demoplayer_play(demos[selected_item].filename);
if(error)
popup_message(localize("Error"), error, localize("Ok"));
}
}
}