/*! Call when a race has just been won \author jfpatry \date Created: 2000-09-24 \date Modified: 2000-09-24 */ void update_for_won_race( void ) { race_data_t *race_data; check_assertion( g_game.practicing == False, "Tried to update for won race in practice mode" ); race_data = (race_data_t*)get_list_elem_data( cur_elem ); if ( last_completed_race == NULL || compare_race_positions( cup_data, last_completed_race, cur_elem ) > 0 ) { last_completed_race = cur_elem; if ( cur_elem == get_list_tail( race_list ) ) { cup_complete = True; if ( !set_last_completed_cup( plyr->name, g_game.current_event, g_game.difficulty, g_game.current_cup ) ) { print_warning( IMPORTANT_WARNING, "Couldn't save cup completion" ); } else { print_debug( DEBUG_GAME_LOGIC, "Cup %s completed", g_game.current_cup ); } } } }
static void set_cur_cup_to_first_incomplete( event_data_t *event_data, list_t cup_list ) { cur_cup = get_last_complete_cup_for_event( event_data ); if ( cur_cup == NULL ) { cur_cup = get_list_head( cup_list ); } else if ( cur_cup != get_list_tail( cup_list ) ) { cur_cup = get_next_list_elem( cup_list, cur_cup ); } }
/*! Advances to the next item in the list. Returns true if successful, or false if the current item (before the change) is the last item \author jfpatry \date Created: 2000-09-30 \date Modified: 2000-09-30 */ bool_t listbox_goto_next_item( listbox_t *listbox ) { check_assertion( listbox != NULL, "listbox is NULL" ); if ( listbox->cur_item == get_list_tail( listbox->item_list ) ) { return False; } button_simulate_mouse_click( listbox->down_button ); return True; }
/* * Search the outlets of a breaker for the receptacles having id of receptacle_id. * * Returns: * Not Found: NULL * Found: VA receptacle_t */ static receptacle_t *get_receptacle_by_id_from_breaker_id(uint32_t breaker_id, uint32_t receptacle_id) { receptacle_t *r = NULL; list_t *outlet_list = get_outlet_list_on_breaker(breaker_id); node_t *outlet_node_ptr = get_first_node(outlet_list); while (get_list_tail(outlet_list) != outlet_node_ptr) { r = search_outlet_for_receptacle_id((outlet_t *)outlet_node_ptr->data, receptacle_id); if (NULL != r) break; outlet_node_ptr = outlet_node_ptr->next; } return r; }
/* * Calculate the total amp load on a breaker having id of breaker_id. * * Returns: * Success: amp_load >= 0.0 * Failure: ERR_INVALID_BREAKER_ID */ float get_total_amp_load_on_breaker_by_breaker_id(uint32_t breaker_id) { if (FALSE == breaker_id_is_installed(breaker_id)) { return ERR_INVALID_BREAKER_ID; } // sum amp loads of installed breakers float total_amp_load = 0.0; list_t *outlet_list = get_outlet_list_on_breaker(breaker_id); node_t * outlet_node_ptr = get_first_node(outlet_list); while (get_list_tail(outlet_list) != outlet_node_ptr) { total_amp_load += get_total_amp_load_on_outlet_by_outlet_va((outlet_t *)outlet_node_ptr->data); outlet_node_ptr = outlet_node_ptr->next; } return total_amp_load; }
int in_reg2_list(CTXTdeclc Psc psc) { Cell list,term; list = reg[2]; XSB_Deref(list); if (isnil(list)) return TRUE; /* if filter is empty, return all */ while (!isnil(list)) { term = get_list_head(list); XSB_Deref(term); if (isconstr(term)) { if (psc == get_str_psc(term)) return TRUE; } else if (isstring(term)) { if (get_name(psc) == string_val(term)) return TRUE; } list = get_list_tail(list); } return FALSE; }
/* * Search the e_model for the breaker having id of breaker_id. * * Returns: * Not Found: NULL * Found: VA breaker_t */ static breaker_t *get_breaker_by_id(uint32_t breaker_id) { #ifdef PATCHED if ((FALSE == load_center_is_created()) || (0 == e_model->breakers_installed_cnt) || (breaker_id >= e_model->breakers_installed_cnt)) { #else if ((FALSE == load_center_is_created()) || (0 == e_model->breakers_installed_cnt)) { #endif return NULL; } return &(e_model->breakers[breaker_id]); } /* * Search the e_model for the outlet having id of outlet_id. * * Returns: * Not Found: NULL * Found: VA outlet_t */ static outlet_t *get_outlet_by_id(uint32_t outlet_id) { outlet_t *o = NULL; int8_t breakers_installed_cnt = get_number_of_breakers_installed_in_load_center(); if (0 > breakers_installed_cnt) { return NULL; } for (uint32_t breaker_id = 0; breaker_id < breakers_installed_cnt; breaker_id++) { list_t *outlet_list = get_outlet_list_on_breaker(breaker_id); node_t *outlet_node_ptr = get_first_node(outlet_list); while (get_list_tail(outlet_list) != outlet_node_ptr) { o = (outlet_t *)outlet_node_ptr->data; if (outlet_id == o->id) { break; } else { o = NULL; } outlet_node_ptr = outlet_node_ptr->next; } } return o; }
/* * Search the e_model for light string having id of light_string_id. * * Returns: * Not Found: NULL * Found: VA light_string_t */ static light_string_t *get_light_string_by_id(uint32_t light_string_id) { light_string_t *ls = NULL; int8_t breakers_installed_cnt = get_number_of_breakers_installed_in_load_center(); if (0 > breakers_installed_cnt) { return NULL; } for (uint32_t breaker_id = 0; breaker_id < breakers_installed_cnt; breaker_id++) { list_t *outlet_list = get_outlet_list_on_breaker(breaker_id); node_t *outlet_node_ptr = get_first_node(outlet_list); while (get_list_tail(outlet_list) != outlet_node_ptr) { outlet_t *o = (outlet_t *)outlet_node_ptr->data; ls = search_outlet_for_light_string_id(o, light_string_id); if (NULL != ls) { break; } outlet_node_ptr = outlet_node_ptr->next; } } return ls; }
/* * Search the e_model for splitter having id of splitter_id. * * Returns: * Not Found: NULL * Found: VA n_way_splitter_t */ static n_way_splitter_t *get_splitter_by_id(uint32_t splitter_id) { n_way_splitter_t *s = NULL; int8_t breakers_installed_cnt = get_number_of_breakers_installed_in_load_center(); if (0 > breakers_installed_cnt) { return NULL; } for (uint32_t breaker_id = 0; breaker_id < breakers_installed_cnt; breaker_id++) { list_t *outlet_list = get_outlet_list_on_breaker(breaker_id); node_t *outlet_node_ptr = get_first_node(outlet_list); while (get_list_tail(outlet_list) != outlet_node_ptr) { outlet_t *o = (outlet_t *)outlet_node_ptr->data; s = search_outlet_for_splitter_id(o, splitter_id); if (NULL != s) { break; } outlet_node_ptr = outlet_node_ptr->next; } } return s; }
/*! Updates the enabled states of the arrow buttons \author jfpatry \date Created: 2000-09-17 \date Modified: 2000-09-17 */ static void update_button_enabled_states( listbox_t *listbox ) { check_assertion( listbox != NULL, "listbox is NULL" ); if ( listbox->cur_item == NULL ) { /* No items in list */ button_set_enabled( listbox->up_button, False ); button_set_enabled( listbox->down_button, False ); } else { if ( listbox->cur_item == get_list_head( listbox->item_list ) ) { button_set_enabled( listbox->up_button, False ); } else { button_set_enabled( listbox->up_button, True ); } if ( listbox->cur_item == get_list_tail( listbox->item_list ) ) { button_set_enabled( listbox->down_button, False ); } else { button_set_enabled( listbox->down_button, True ); } } }
int get_incr_sccs(CTXTdeclc Cell listterm) { Cell orig_listterm, intterm, node; long int node_num=0; int i = 0, dfn, component = 1; int * dfn_stack; int dfn_top = 0, ret; SCCNode * nodes; struct hashtable_itr *itr; struct hashtable* hasht; XSB_Deref(listterm); hasht = create_hashtable1(HASH_TABLE_SIZE, hashid, equalkeys); orig_listterm = listterm; intterm = get_list_head(listterm); XSB_Deref(intterm); // printf("listptr %p @%p\n",listptr,(CPtr) int_val(*listptr)); insert_some(hasht,(void *) oint_val(intterm),(void *) node_num); node_num++; listterm = get_list_tail(listterm); XSB_Deref(listterm); while (!isnil(listterm)) { intterm = get_list_head(listterm); XSB_Deref(intterm); node = oint_val(intterm); if (NULL == search_some(hasht, (void *)node)) { insert_some(hasht,(void *)node,(void *)node_num); node_num++; } listterm = get_list_tail(listterm); XSB_Deref(listterm); } nodes = (SCCNode *) mem_calloc(node_num, sizeof(SCCNode),OTHER_SPACE); dfn_stack = (int *) mem_alloc(node_num*sizeof(int),OTHER_SPACE); listterm = orig_listterm;; //printf("listptr %p @%p\n",listptr,(void *)int_val(*(listptr))); intterm = get_list_head(listterm); XSB_Deref(intterm); nodes[0].node = (CPtr) oint_val(intterm); listterm = get_list_tail(listterm); XSB_Deref(listterm); i = 1; while (!isnil(listterm)) { intterm = get_list_head(listterm); XSB_Deref(intterm); node = oint_val(intterm); nodes[i].node = (CPtr) node; listterm = get_list_tail(listterm); XSB_Deref(listterm); i++; } itr = hashtable1_iterator(hasht); SQUASH_LINUX_COMPILER_WARN(itr); // do { // printf("k %p val %p\n",hashtable1_iterator_key(itr),hashtable1_iterator_value(itr)); // } while (hashtable1_iterator_advance(itr)); listterm = orig_listterm; // printf("2: k %p v %p\n",(void *) int_val(*listptr), // search_some(hasht,(void *) int_val(*listptr))); // while (!isnil(*listptr)) { now all wrong... // listptr = listptr + 1; // node = int_val(*clref_val(listptr)); // printf("2: k %p v %p\n",(CPtr) node,search_some(hasht,(void *) node)); // listptr = listptr + 1; // } dfn = 1; for (i = 0; i < node_num; i++) { if (nodes[i].dfn == 0) xsb_compute_scc(nodes,dfn_stack,i,&dfn_top,hasht,&dfn,&component); // printf("++component for node %d is %d (high %d)\n",i,nodes[i].component,component); } ret = return_scc_list(CTXTc nodes, node_num); hashtable1_destroy(hasht,0); mem_dealloc(nodes,node_num*sizeof(SCCNode),OTHER_SPACE); mem_dealloc(dfn_stack,node_num*sizeof(int),OTHER_SPACE); return ret; }
static void preference_init(void) { list_t sound_list = NULL; list_t video_list = NULL; point2d_t dummy_pos = {0, 0}; int* opt1 = malloc(sizeof(int)); *opt1 = 0; int* opt2 = malloc(sizeof(int)); *opt2 = 1; int* opt3 = malloc(sizeof(int)); *opt3 = 2; winsys_set_display_func( main_loop ); winsys_set_idle_func( main_loop ); winsys_set_reshape_func( reshape ); winsys_set_mouse_func( ui_event_mouse_func ); winsys_set_motion_func( ui_event_motion_func ); winsys_set_passive_motion_func( ui_event_motion_func ); sound_list = create_list(); list_elem_t last_sound = get_list_tail( sound_list ); last_sound = insert_list_elem( sound_list, last_sound, (list_elem_data_t) opt1); if (getparam_sound_enabled() == *opt1) cur_sound = last_sound; last_sound = insert_list_elem( sound_list, last_sound, (list_elem_data_t) opt2); if (getparam_sound_enabled() == *opt2) cur_sound = last_sound; video_list = create_list(); list_elem_t last_video = get_list_tail( video_list ); last_video = insert_list_elem( video_list, last_video, (list_elem_data_t) opt1); if (getparam_video_quality() == *opt1) cur_video = last_video; last_video = insert_list_elem( video_list, last_video, (list_elem_data_t) opt2); if (getparam_video_quality() == *opt2) cur_video = last_video; last_video = insert_list_elem( video_list, last_video, (list_elem_data_t) opt3); if (getparam_video_quality() == *opt3) cur_video = last_video; chancel_btn = button_create( dummy_pos, 80 * mWidth / 480, 48 * mHeight / 320, "button_label", (mWidth>320)?"Back":"<< " ); button_set_hilit_font_binding( chancel_btn, "button_label_hilit" ); button_set_visible( chancel_btn, True ); button_set_click_event_cb( chancel_btn, chancel_click_cb, NULL ); save_btn = button_create( dummy_pos, 80 * mWidth / 480, 48 * mHeight / 320, "button_label", (mWidth>320)?"Save":" >>" ); button_set_hilit_font_binding( save_btn, "button_label_hilit" ); button_set_disabled_font_binding( save_btn, "button_label_disabled" ); button_set_visible( save_btn, True ); button_set_click_event_cb( save_btn, save_click_cb, NULL ); sound_listbox = listbox_create( dummy_pos, 120 * mHeight / 320, 44 * mHeight / 320, "listbox_item", sound_list, sound_list_elem_to_string_func ); listbox_set_current_item( sound_listbox, cur_sound ); listbox_set_item_change_event_cb( sound_listbox, sound_listbox_item_change_cb, NULL ); listbox_set_visible( sound_listbox, True ); video_listbox = listbox_create( dummy_pos, 120 * mHeight / 320, 44 * mHeight / 320, "listbox_item", video_list, video_list_elem_to_string_func ); listbox_set_current_item( video_listbox, cur_video ); listbox_set_item_change_event_cb( video_listbox, video_listbox_item_change_cb, NULL ); listbox_set_visible( video_listbox, True ); play_music( "start_screen" ); }
/*! Sets the widget positions and draws other on-screen goo \author jfpatry \date Created: 2000-09-24 \date Modified: 2000-09-24 */ static void set_widget_positions_and_draw_decorations() { int w = getparam_x_resolution(); int h = getparam_y_resolution(); int box_width, box_height, box_max_y; int x_org, y_org; char *string; font_t *font; char *current_course; int text_width, asc, desc; GLuint texobj; /* set the dimensions of the box in which all widgets should fit */ #ifdef __APPLE__ box_width = w; box_height = 200 * mHeight / 320; box_max_y = h - 128 * mHeight / 320; x_org = 10 * mHeight / 320; y_org = box_height/2 * mHeight / 320; if ( y_org + box_height > box_max_y ) { y_org = box_max_y - box_height + 50 * mHeight / 320; } button_set_position( back_btn, make_point2d( 0, 0 ) ); button_set_position( start_btn, make_point2d( box_width - button_get_width( start_btn ), 0 ) ); listbox_set_position( race_listbox, make_point2d( 160 * mHeight / 320, box_height/2.0+40 * mHeight / 320 ) ); #ifdef __APPLE__ textarea_set_position( desc_ta, make_point2d( 1000, 1000 ) ); #else textarea_set_position( desc_ta, make_point2d( x_org, y_org + 66 * mHeight / 320 ) ); #endif if ( g_game.practicing || ( cup_complete && conditions_ssbtn && wind_ssbtn && snow_ssbtn && mirror_ssbtn ) ) { ssbutton_set_position( conditions_ssbtn, make_point2d( x_org + box_width - 4*36 + 4, y_org + 151 ) ); ssbutton_set_position( wind_ssbtn, make_point2d( x_org + box_width - 3*36 + 4 , y_org + 151 ) ); ssbutton_set_position( snow_ssbtn, make_point2d( x_org + box_width - 2*36 + 4, y_org + 151 ) ); ssbutton_set_position( mirror_ssbtn, make_point2d( x_org + box_width - 1*36 + 4, y_org + 151 ) ); #else box_width = 460; box_height = 310; box_max_y = h - 128; x_org = w/2 - box_width/2; y_org = h/2 - box_height/2; if ( y_org + box_height > box_max_y ) { y_org = box_max_y - box_height; } button_set_position( back_btn, make_point2d( x_org + 131 - button_get_width( back_btn )/2.0, 42 ) ); button_set_position( start_btn, make_point2d( x_org + 343 - button_get_width( start_btn )/2.0, 42 ) ); listbox_set_position( race_listbox, make_point2d( x_org, y_org + 221 ) ); textarea_set_position( desc_ta, make_point2d( x_org, y_org + 66 ) ); if ( g_game.practicing || ( cup_complete && conditions_ssbtn && wind_ssbtn && snow_ssbtn && mirror_ssbtn ) ) { ssbutton_set_position( conditions_ssbtn, make_point2d( x_org + box_width - 4*36 + 4, y_org + 181 ) ); ssbutton_set_position( wind_ssbtn, make_point2d( x_org + box_width - 3*36 + 4 , y_org + 181 ) ); ssbutton_set_position( snow_ssbtn, make_point2d( x_org + box_width - 2*36 + 4, y_org + 181 ) ); ssbutton_set_position( mirror_ssbtn, make_point2d( x_org + box_width - 1*36 + 4, y_org + 181 ) ); #endif } else { /* Draw tux life icons */ GLuint texobj; int i; glPushMatrix(); { #ifdef __APPLE__ glTranslatef( 10 * mHeight / 320, 60 * mHeight / 320, 0 ); #else glTranslatef( x_org + box_width - 4*36 + 4, y_org + 181, 0 ); #endif check_assertion( INIT_NUM_LIVES == 4, "Assumption about number of lives invalid -- " "need to recode this part" ); if ( !get_texture_binding( "tux_life", &texobj ) ) { texobj = 0; } glBindTexture( GL_TEXTURE_2D, texobj ); for ( i=0; i<4; i++ ) { point2d_t ll, ur; if ( plyr->lives > i ) { ll = make_point2d( 0, 0.5 ); ur = make_point2d( 1, 1 ); } else { ll = make_point2d( 0, 0 ); ur = make_point2d( 1, 0.5 ); } glBegin( GL_QUADS ); { glTexCoord2f( ll.x, ll.y ); glVertex2f( 0, 0 ); glTexCoord2f( ur.x, ll.y ); glVertex2f( 32 * mHeight / 320, 0 ); glTexCoord2f( ur.x, ur.y ); glVertex2f( 32 * mHeight / 320, 32 * mHeight / 320 ); glTexCoord2f( ll.x, ur.y ); glVertex2f( 0, 32 * mHeight / 320 ); } glEnd(); glTranslatef( 36 * mHeight / 320, 0, 0 ); } } glPopMatrix(); } #ifndef __APPLE__ // We don't care about that stuff /* Draw other stuff */ if ( !get_font_binding( "menu_label", &font ) ) { print_warning( IMPORTANT_WARNING, "Couldn't get font for binding menu_label" ); } else { bind_font_texture( font ); string = "Select a race"; get_font_metrics( font, string, &text_width, &asc, &desc ); glPushMatrix(); { glTranslatef( x_org + box_width/2.0 - text_width/2.0, y_org + 310 - asc, 0 ); draw_string( font, string ); } glPopMatrix(); } /* Draw text indicating race requirements (if race not completed), or results in race if race completed. */ draw_status_msg( x_org, y_org, box_width, box_height ); #else /* Draw text indicating race requirements (if race not completed), or results in race if race completed. */ draw_status_msg( x_org, y_org, box_width, box_height ); #endif /* Draw preview */ if ( g_game.practicing ) { list_elem_t elem; open_course_data_t *data; elem = listbox_get_current_item( race_listbox ); data = (open_course_data_t*) get_list_elem_data( elem ); current_course = data->course; } else { list_elem_t elem; race_data_t *data; elem = listbox_get_current_item( race_listbox ); data = (race_data_t*) get_list_elem_data( elem ); current_course = data->course; } glDisable( GL_TEXTURE_2D ); glColor4f( 0.0, 0.0, 0.0, 0.3 ); #ifdef __APPLE__ float margin = 4.f * mHeight / 320; float yoffset = 26 * mHeight / 320 + 30 * mHeight / 320; glBegin( GL_QUADS ); { glVertex2f( x_org, y_org + yoffset ); glVertex2f( x_org + 140 * mHeight / 320, y_org + yoffset ); glVertex2f( x_org + 140 * mHeight / 320, y_org + yoffset+107 * mHeight / 320 ); glVertex2f( x_org, y_org + yoffset+107 * mHeight / 320 ); } glEnd(); #else glBegin( GL_QUADS ); { glVertex2f( x_org+box_width-140, y_org+66 ); glVertex2f( x_org+box_width, y_org+66 ); glVertex2f( x_org+box_width, y_org+66+107 ); glVertex2f( x_org+box_width-140, y_org+66+107 ); } glEnd(); #endif glColor4f( 1.0, 1.0, 1.0, 1.0 ); glEnable( GL_TEXTURE_2D ); if ( !get_texture_binding( current_course, &texobj ) ) { if ( !get_texture_binding( "no_preview", &texobj ) ) { texobj = 0; } } glBindTexture( GL_TEXTURE_2D, texobj ); #ifdef __APPLE__ glBegin( GL_QUADS ); { glTexCoord2d( 0, 0); glVertex2f( x_org + margin, y_org + yoffset+margin ); glTexCoord2d( 1, 0); glVertex2f( x_org + 140 * mHeight / 320 - margin, y_org + yoffset+margin ); glTexCoord2d( 1, 1); glVertex2f( x_org + 140 * mHeight / 320 - margin, y_org + yoffset+margin+99 * mHeight / 320 ); glTexCoord2d( 0, 1); glVertex2f( x_org + margin, y_org + yoffset+margin+99 * mHeight / 320 ); } glEnd(); #else glBegin( GL_QUADS ); { glTexCoord2d( 0, 0); glVertex2f( x_org+box_width-136, y_org+70 ); glTexCoord2d( 1, 0); glVertex2f( x_org+box_width-4, y_org+70 ); glTexCoord2d( 1, 1); glVertex2f( x_org+box_width-4, y_org+70+99 ); glTexCoord2d( 0, 1); glVertex2f( x_org+box_width-136, y_org+70+99 ); } glEnd(); #endif } /*---------------------------------------------------------------------------*/ /*! Mode initialization function \author jfpatry \date Created: 2000-09-24 \date Modified: 2000-09-24 */ static void race_select_init(void) { listbox_list_elem_to_string_fptr_t conv_func = NULL; point2d_t dummy_pos = {0, 0}; int i; winsys_set_display_func( main_loop ); winsys_set_idle_func( main_loop ); winsys_set_reshape_func( reshape ); winsys_set_mouse_func( ui_event_mouse_func ); winsys_set_motion_func( ui_event_motion_func ); winsys_set_passive_motion_func( ui_event_motion_func ); plyr = get_player_data( local_player() ); /* Setup the race list */ if ( g_game.practicing ) { g_game.current_event = "__Practice_Event__"; g_game.current_cup = "__Practice_Cup__"; race_list = get_open_courses_list(); conv_func = get_name_from_open_course_data; cup_data = NULL; last_completed_race = NULL; event_data = NULL; } else { event_data = (event_data_t*) get_list_elem_data( get_event_by_name( g_game.current_event ) ); check_assertion( event_data != NULL, "Couldn't find current event." ); cup_data = (cup_data_t*) get_list_elem_data( get_event_cup_by_name( event_data, g_game.current_cup ) ); check_assertion( cup_data != NULL, "Couldn't find current cup." ); race_list = get_cup_race_list( cup_data ); conv_func = get_name_from_race_data; } /* Unless we're coming back from a race, initialize the race data to defaults. */ if ( g_game.prev_mode != GAME_OVER ) { /* Make sure we don't play previously loaded course */ cup_complete = False; /* Initialize the race data */ cur_elem = get_list_head( race_list ); if ( g_game.practicing ) { g_game.race.course = NULL; g_game.race.name = NULL; g_game.race.description = NULL; for (i=0; i<DIFFICULTY_NUM_LEVELS; i++) { g_game.race.herring_req[i] = 0; g_game.race.time_req[i] = 0; g_game.race.score_req[i] = 0; } g_game.race.mirrored = False; g_game.race.conditions = RACE_CONDITIONS_SUNNY; g_game.race.windy = False; g_game.race.snowing = False; } else { /* Not practicing */ race_data_t *data; data = (race_data_t*) get_list_elem_data( cur_elem ); g_game.race = *data; if ( is_cup_complete( event_data, get_event_cup_by_name( event_data, g_game.current_cup ) ) ) { cup_complete = True; last_completed_race = get_list_tail( race_list ); } else { cup_complete = False; last_completed_race = NULL; } } } else { /* Back from a race */ if ( !g_game.race_aborted ) { update_race_results(); } if (!g_game.practicing && !cup_complete) { if ( was_current_race_won() ) { update_for_won_race(); /* Advance to next race */ if ( cur_elem != get_list_tail( race_list ) ) { cur_elem = get_next_list_elem( race_list, cur_elem ); } } else { /* lost race */ plyr->lives -= 1; } print_debug( DEBUG_GAME_LOGIC, "Current lives: %d", plyr->lives ); } } back_btn = button_create( dummy_pos, 80 * mWidth / 480, 48 * mHeight / 320, "button_label", (mWidth>320)?"Back":"<< " ); button_set_hilit_font_binding( back_btn, "button_label_hilit" ); button_set_visible( back_btn, True ); button_set_click_event_cb( back_btn, back_click_cb, NULL ); start_btn = button_create( dummy_pos, 80 * mWidth / 480, 48 * mHeight / 320, "button_label", (mWidth>320)?"Race":" >>" ); button_set_hilit_font_binding( start_btn, "button_label_hilit" ); button_set_disabled_font_binding( start_btn, "button_label_disabled" ); button_set_visible( start_btn, True ); button_set_click_event_cb( start_btn, start_click_cb, NULL ); #ifdef __APPLE__ race_listbox = listbox_create( dummy_pos, mWidth - 170 * mHeight / 320, 44 * mHeight / 320, "course_name_label", race_list, conv_func ); #else race_listbox = listbox_create( dummy_pos, 460 * mHeight / 320, 44 * mHeight / 320, "listbox_item", race_list, conv_func ); #endif listbox_set_current_item( race_listbox, cur_elem ); listbox_set_item_change_event_cb( race_listbox, race_listbox_item_change_cb, NULL ); listbox_set_visible( race_listbox, True ); /* * Create text area */ #ifdef __APPLE__ desc_ta = textarea_create( dummy_pos, 150, 147, "race_description", "" ); #else desc_ta = textarea_create( dummy_pos, 312, 107, "race_description", "" ); #endif if ( g_game.practicing ) { open_course_data_t *data; data = (open_course_data_t*) get_list_elem_data( cur_elem ); textarea_set_text( desc_ta, data->description ); } else { race_data_t *data; data = (race_data_t*) get_list_elem_data( cur_elem ); textarea_set_text( desc_ta, data->description ); } textarea_set_visible( desc_ta, True ); /* * Create state buttons - only if practicing or if cup_complete */ if ( g_game.practicing || cup_complete ) { /* mirror */ mirror_ssbtn = ssbutton_create( dummy_pos, 32, 32, 2 ); ssbutton_set_state_image( mirror_ssbtn, 0, "mirror_button", make_point2d( 0.0/64.0, 32.0/64.0 ), make_point2d( 32.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state_image( mirror_ssbtn, 1, "mirror_button", make_point2d( 32.0/64.0, 32.0/64.0 ), make_point2d( 64.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state( mirror_ssbtn, (int)g_game.race.mirrored ); #ifdef __APPLE__ ssbutton_set_visible( mirror_ssbtn, False ); #else ssbutton_set_visible( mirror_ssbtn, True ); #endif /* conditions */ conditions_ssbtn = ssbutton_create( dummy_pos, 32, 32, 4 ); float border = 2.0; ssbutton_set_state_image( conditions_ssbtn, 0, "conditions_button", make_point2d( (0.0 + border)/64.0, (32.0 + border)/64.0 ), make_point2d( (32.0 - border)/64.0, (64.0 - border)/64.0 ), white ); ssbutton_set_state_image( conditions_ssbtn, 1, "conditions_button", make_point2d( (32.0 + border)/64.0, (0.0 + border)/64.0 ), make_point2d( (64.0 - border)/64.0, (32.0 - border)/64.0 ), white ); ssbutton_set_state_image( conditions_ssbtn, 2, "conditions_button", make_point2d( (32.0 + border)/64.0, (32.0 + border)/64.0 ), make_point2d( (64.0 - border)/64.0, (64.0 - border)/64.0 ), white ); ssbutton_set_state_image( conditions_ssbtn, 3, "conditions_button", make_point2d( (0.0 + border)/64.0, (0.0 + border)/64.0 ), make_point2d( (32.0 - border)/64.0, (32.0 - border)/64.0 ), white ); ssbutton_set_state( conditions_ssbtn, (int)g_game.race.conditions ); ssbutton_set_visible( conditions_ssbtn, True ); #ifdef __APPLE__ ssbutton_set_visible( conditions_ssbtn, False ); #else ssbutton_set_visible( conditions_ssbtn, True ); #endif /* wind */ wind_ssbtn = ssbutton_create( dummy_pos, 32, 32, 2 ); ssbutton_set_state_image( wind_ssbtn, 0, "wind_button", make_point2d( 0.0/64.0, 32.0/64.0 ), make_point2d( 32.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state_image( wind_ssbtn, 1, "wind_button", make_point2d( 32.0/64.0, 32.0/64.0 ), make_point2d( 64.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state( wind_ssbtn, (int)g_game.race.windy ); #ifdef __APPLE__ ssbutton_set_visible( wind_ssbtn, False ); #else ssbutton_set_visible( wind_ssbtn, True ); #endif /* snow */ snow_ssbtn = ssbutton_create( dummy_pos, 32, 32, 2 ); ssbutton_set_state_image( snow_ssbtn, 0, "snow_button", make_point2d( 0.0/64.0, 32.0/64.0 ), make_point2d( 32.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state_image( snow_ssbtn, 1, "snow_button", make_point2d( 32.0/64.0, 32.0/64.0 ), make_point2d( 64.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state( snow_ssbtn, (int)g_game.race.snowing ); #ifdef __APPLE__ ssbutton_set_visible( snow_ssbtn, False ); #else ssbutton_set_visible( snow_ssbtn, True ); #endif /* XXX snow button doesn't do anything, so disable for now */ ssbutton_set_enabled( snow_ssbtn, False ); /* Can't change conditions if in cup mode */ if ( !g_game.practicing ) { ssbutton_set_enabled( conditions_ssbtn, False ); ssbutton_set_enabled( wind_ssbtn, False ); ssbutton_set_enabled( snow_ssbtn, False ); ssbutton_set_enabled( mirror_ssbtn, False ); } } else { conditions_ssbtn = NULL; wind_ssbtn = NULL; snow_ssbtn = NULL; mirror_ssbtn = NULL; } update_race_data(); update_button_enabled_states(); play_music( "start_screen" ); }
/*! Mode initialization function \author jfpatry \date Created: 2000-09-24 \date Modified: 2000-09-24 */ static void race_select_init(void) { listbox_list_elem_to_string_fptr_t conv_func = NULL; point2d_t dummy_pos = {0, 0}; int i; winsys_set_display_func( main_loop ); winsys_set_idle_func( main_loop ); winsys_set_reshape_func( reshape ); winsys_set_mouse_func( ui_event_mouse_func ); winsys_set_motion_func( ui_event_motion_func ); winsys_set_passive_motion_func( ui_event_motion_func ); plyr = get_player_data( local_player() ); /* Setup the race list */ if ( g_game.practicing ) { g_game.current_event = "__Practice_Event__"; g_game.current_cup = "__Practice_Cup__"; if(g_game.is_speed_only_mode) race_list = get_speed_courses_list(); else race_list = get_score_courses_list(); conv_func = get_name_from_open_course_data; cup_data = NULL; last_completed_race = NULL; event_data = NULL; } else { event_data = (event_data_t*) get_list_elem_data( get_event_by_name( g_game.current_event ) ); check_assertion( event_data != NULL, "Couldn't find current event." ); cup_data = (cup_data_t*) get_list_elem_data( get_event_cup_by_name( event_data, g_game.current_cup ) ); check_assertion( cup_data != NULL, "Couldn't find current cup." ); race_list = get_cup_race_list( cup_data ); conv_func = get_name_from_race_data; } /* Unless we're coming back from a race, initialize the race data to defaults. */ if ( g_game.prev_mode != GAME_OVER ) { /* Make sure we don't play previously loaded course */ cup_complete = False; /* Initialize the race data */ cur_elem = get_list_head( race_list ); if ( g_game.practicing ) { g_game.race.course = NULL; g_game.race.name = NULL; g_game.race.description = NULL; for (i=0; i<DIFFICULTY_NUM_LEVELS; i++) { g_game.race.herring_req[i] = 0; g_game.race.time_req[i] = 0; g_game.race.score_req[i] = 0; } g_game.race.mirrored = False; g_game.race.conditions = RACE_CONDITIONS_SUNNY; g_game.race.windy = False; g_game.race.snowing = False; } else { /* Not practicing */ race_data_t *data; data = (race_data_t*) get_list_elem_data( cur_elem ); g_game.race = *data; if ( is_cup_complete( event_data, get_event_cup_by_name( event_data, g_game.current_cup ) ) ) { cup_complete = True; last_completed_race = get_list_tail( race_list ); } else { cup_complete = False; last_completed_race = NULL; } } } else { /* Back from a race */ if ( !g_game.race_aborted ) { update_race_results(); } } back_btn = button_create( dummy_pos, 150, 40, "button_label", Localize("Back","") ); button_set_hilit_font_binding( back_btn, "button_label_hilit" ); button_set_visible( back_btn, True ); button_set_click_event_cb( back_btn, back_click_cb, NULL ); start_btn = button_create( dummy_pos, 150, 40, "button_label", Localize("Race!","") ); button_set_hilit_font_binding( start_btn, "button_label_hilit" ); button_set_disabled_font_binding( start_btn, "button_label_disabled" ); button_set_visible( start_btn, True ); button_set_click_event_cb( start_btn, start_click_cb, NULL ); #ifdef __APPLE__ race_listbox = listbox_create( dummy_pos, 300, 44, "course_name_label", race_list, conv_func ); #else race_listbox = listbox_create( dummy_pos, 460, 44, "listbox_item", race_list, conv_func ); #endif listbox_set_current_item( race_listbox, cur_elem ); listbox_set_item_change_event_cb( race_listbox, race_listbox_item_change_cb, NULL ); listbox_set_visible( race_listbox, True ); /* * Create text area */ #ifdef __APPLE__ desc_ta = textarea_create( dummy_pos, 170, 147, "race_description", "" ); #else desc_ta = textarea_create( dummy_pos, 312, 107, "race_description", "" ); #endif if ( g_game.practicing ) { open_course_data_t *data; data = (open_course_data_t*) get_list_elem_data( cur_elem ); textarea_set_text( desc_ta, data->description ); } else { race_data_t *data; data = (race_data_t*) get_list_elem_data( cur_elem ); textarea_set_text( desc_ta, data->description ); } textarea_set_visible( desc_ta, True ); /* * Create state buttons - only if practicing or if cup_complete */ if ( g_game.practicing || cup_complete ) { /* mirror */ mirror_ssbtn = ssbutton_create( dummy_pos, 32, 32, 2 ); ssbutton_set_state_image( mirror_ssbtn, 0, "mirror_button", make_point2d( 0.0/64.0, 32.0/64.0 ), make_point2d( 32.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state_image( mirror_ssbtn, 1, "mirror_button", make_point2d( 32.0/64.0, 32.0/64.0 ), make_point2d( 64.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state( mirror_ssbtn, (int)g_game.race.mirrored ); #ifdef __APPLE__ ssbutton_set_visible( mirror_ssbtn, False ); #else ssbutton_set_visible( mirror_ssbtn, True ); #endif /* conditions */ conditions_ssbtn = ssbutton_create( dummy_pos, 32, 32, 4 ); float border = 2.0; ssbutton_set_state_image( conditions_ssbtn, 0, "conditions_button", make_point2d( (0.0 + border)/64.0, (32.0 + border)/64.0 ), make_point2d( (32.0 - border)/64.0, (64.0 - border)/64.0 ), white ); ssbutton_set_state_image( conditions_ssbtn, 1, "conditions_button", make_point2d( (32.0 + border)/64.0, (0.0 + border)/64.0 ), make_point2d( (64.0 - border)/64.0, (32.0 - border)/64.0 ), white ); ssbutton_set_state_image( conditions_ssbtn, 2, "conditions_button", make_point2d( (32.0 + border)/64.0, (32.0 + border)/64.0 ), make_point2d( (64.0 - border)/64.0, (64.0 - border)/64.0 ), white ); ssbutton_set_state_image( conditions_ssbtn, 3, "conditions_button", make_point2d( (0.0 + border)/64.0, (0.0 + border)/64.0 ), make_point2d( (32.0 - border)/64.0, (32.0 - border)/64.0 ), white ); ssbutton_set_state( conditions_ssbtn, (int)g_game.race.conditions ); ssbutton_set_visible( conditions_ssbtn, True ); #ifdef __APPLE__ ssbutton_set_visible( conditions_ssbtn, False ); #else ssbutton_set_visible( conditions_ssbtn, True ); #endif /* wind */ wind_ssbtn = ssbutton_create( dummy_pos, 32, 32, 2 ); ssbutton_set_state_image( wind_ssbtn, 0, "wind_button", make_point2d( 0.0/64.0, 32.0/64.0 ), make_point2d( 32.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state_image( wind_ssbtn, 1, "wind_button", make_point2d( 32.0/64.0, 32.0/64.0 ), make_point2d( 64.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state( wind_ssbtn, (int)g_game.race.windy ); #ifdef __APPLE__ ssbutton_set_visible( wind_ssbtn, False ); #else ssbutton_set_visible( wind_ssbtn, True ); #endif /* snow */ snow_ssbtn = ssbutton_create( dummy_pos, 32, 32, 2 ); ssbutton_set_state_image( snow_ssbtn, 0, "snow_button", make_point2d( 0.0/64.0, 32.0/64.0 ), make_point2d( 32.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state_image( snow_ssbtn, 1, "snow_button", make_point2d( 32.0/64.0, 32.0/64.0 ), make_point2d( 64.0/64.0, 64.0/64.0 ), white ); ssbutton_set_state( snow_ssbtn, (int)g_game.race.snowing ); #ifdef __APPLE__ ssbutton_set_visible( snow_ssbtn, False ); #else ssbutton_set_visible( snow_ssbtn, True ); #endif /* XXX snow button doesn't do anything, so disable for now */ ssbutton_set_enabled( snow_ssbtn, False ); /* Can't change conditions if in cup mode */ if ( !g_game.practicing ) { ssbutton_set_enabled( conditions_ssbtn, False ); ssbutton_set_enabled( wind_ssbtn, False ); ssbutton_set_enabled( snow_ssbtn, False ); ssbutton_set_enabled( mirror_ssbtn, False ); } } else { conditions_ssbtn = NULL; wind_ssbtn = NULL; snow_ssbtn = NULL; mirror_ssbtn = NULL; } update_race_data(); update_button_enabled_states(); play_music( "start_screen" ); }
static void race_select_init(void) { point2d_t dummy_pos = {0, 0}; coord_t button_coord; list_elem_t tmp; int i; scoreboard_open=True; winsys_set_display_func( main_loop ); winsys_set_idle_func( main_loop ); winsys_set_reshape_func( reshape ); winsys_set_mouse_func( GameMenu_mouse_func ); winsys_set_motion_func( GameMenu_motion_func ); winsys_set_passive_motion_func( GameMenu_motion_func ); winsys_set_joystick_func( NULL ); winsys_set_joystick_button_func( NULL ); winsys_reset_js_bindings(); winsys_add_js_axis_bindings(); winsys_add_js_button_binding(SDL_CONTROLLER_BUTTON_A, SDLK_RETURN); winsys_add_js_button_binding(SDL_CONTROLLER_BUTTON_B, SDLK_ESCAPE); winsys_add_js_button_binding(SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDLK_LEFT); winsys_add_js_button_binding(SDL_CONTROLLER_BUTTON_DPAD_RIGHT, SDLK_RIGHT); GameMenu_init(); setup_gui(); plyr = get_player_data( local_player() ); /* Setup the race list */ if ( g_game.practicing ) { g_game.current_event = "__Practice_Event__"; g_game.current_cup = "__Practice_Cup__"; #ifdef SPEED_MODE if(g_game.is_speed_only_mode) race_list = get_speed_courses_list(); else race_list = get_score_courses_list(); #else race_list = get_score_courses_list(); #endif cup_data = NULL; last_completed_race = NULL; event_data = NULL; } /* Unless we're coming back from a race, initialize the race data to defaults. */ if ( g_game.prev_mode != GAME_OVER ) { /* Make sure we don't play previously loaded course */ cup_complete = False; /* Initialize the race data */ if (cur_elem==NULL) { cur_elem = get_list_head( race_list ); } else { bool_t needs_changing=False; tmp=get_list_head(race_list); while (tmp!=cur_elem && tmp!=NULL) { tmp=get_next_list_elem(race_list, tmp); } if (!tmp) { cur_elem = get_list_head( race_list ); } } if ( g_game.practicing ) { g_game.race.course = NULL; g_game.race.name = NULL; g_game.race.description = NULL; for (i=0; i<DIFFICULTY_NUM_LEVELS; i++) { g_game.race.herring_req[i] = 0; g_game.race.time_req[i] = 0; g_game.race.score_req[i] = 0; } g_game.race.mirrored = False; g_game.race.conditions = RACE_CONDITIONS_SUNNY; g_game.race.windy = False; g_game.race.snowing = False; } else { /* Not practicing */ race_data_t *data; data = (race_data_t*) get_list_elem_data( cur_elem ); g_game.race = *data; if ( is_cup_complete( event_data, get_event_cup_by_name( event_data, g_game.current_cup ) ) ) { cup_complete = True; last_completed_race = get_list_tail( race_list ); } else { cup_complete = False; last_completed_race = NULL; } } } else { /* Back from a race */ if ( !g_game.race_aborted ) { update_race_results(); } } /* * Create text area */ desc_ta = textarea_create( make_point2d( 0.1*getparam_x_resolution(), 0.2*getparam_y_resolution()), 0.4*getparam_x_resolution(), 0.23*getparam_y_resolution(), "race_description", "" ); textarea_set_visible( desc_ta, True ); update_race_data(); button_coord.x_coord_type=button_coord.y_coord_type=NORMALIZED_COORD; button_coord.x=0.50; button_coord.y=0.85; button_coord.x_just=CENTER_JUST; button_coord.y_just=CENTER_JUST; gui_add_widget(course_title_label=create_label(""), &button_coord); button_coord.x=0.1; button_coord.x_just=LEFT_JUST; gui_add_widget(prev_course_btn=create_button(LEFT_ARROW, prev_cb), &button_coord); button_coord.x=0.9; button_coord.x_just=RIGHT_JUST; gui_add_widget(next_course_btn=create_button(RIGHT_ARROW, next_cb), &button_coord); course_title_label->font_binding="race_selection_title"; prev_course_btn->font_binding="race_selection_title"; next_course_btn->font_binding="race_selection_title"; button_coord.x=0.30; button_coord.y=0.09; button_coord.x_just=CENTER_JUST; gui_add_widget(back_button=create_button(get_back_text(), back_cb), &button_coord); button_coord.x=0.70; gui_add_widget(play_button=create_button(get_race_text(), play_cb), &button_coord); init_scoreboard_labels(); init_scoreboard(); play_music( "start_screen" ); }
/*! tux_events Tcl callback Here's a sample call to tux_events: tux_events { { -name "Herring Run" -icon noicon -cups { { -name "Cup 1" -icon noicon -races { { -course path_of_daggers \ -description "nice long description" \ -herring { 15 20 25 30 } \ -time { 40.0 35.0 30.0 25.0 } \ -score { 0 0 0 0 } \ -mirrored yes -conditions cloudy \ -windy no -snowing no } { -course ingos_speedway \ -description "nice long description" \ -herring { 15 20 25 30 } \ -time { 40.0 35.0 30.0 25.0 } \ -score { 0 0 0 0 } \ -mirrored yes -conditions cloudy \ -windy no -snowing no } } -name "Cup 2" -icon noicon -races { { -course penguins_cant_fly \ -description "nice long description" \ -herring { 15 20 25 30 } \ -time { 40.0 35.0 30.0 25.0 } \ -score { 0 0 0 0 } \ -mirrored yes -conditions cloudy \ -windy no -snowing no } { -course ingos_speedway \ -description "nice long description" \ -herring { 15 20 25 30 } \ -time { 40.0 35.0 30.0 25.0 } \ -score { 0 0 0 0 } \ -mirrored yes -conditions cloudy \ -windy no -snowing no } } } } } } \return Tcl error code \author jfpatry \date Created: 2000-09-19 \date Modified: 2000-09-19 */ static int events_cb( ClientData cd, Tcl_Interp *ip, int argc, const char **argv ) { char *err_msg; const char **list = NULL; int num_events; list_elem_t last_event = NULL; int i; /* Make sure module has been initialized */ check_assertion( initialized, "course_mgr module not initialized" ); if ( argc != 2 ) { err_msg = "Incorrect number of arguments"; goto bail_events; } if ( Tcl_SplitList( ip, argv[1], &num_events, &list ) == TCL_ERROR ) { err_msg = "Argument is not a list"; goto bail_events; } /* We currently only allow tux_events to be called once */ last_event = get_list_tail( event_list ); if ( last_event != NULL ) { err_msg = "tux_events has already been called; it can only be called " "once."; goto bail_events; } for (i=0; i<num_events; i++) { event_data_t *data = create_event_data( ip, list[i], &err_msg ); if ( data == NULL ) { goto bail_events; } last_event = insert_list_elem( event_list, last_event, (list_elem_data_t) data ); } Tcl_Free( (char*) list ); list = NULL; return TCL_OK; bail_events: if ( list != NULL ) { Tcl_Free( (char*) list ); } /* Clean out event list */ if ( event_list != NULL ) { last_event = get_list_tail( event_list ); while ( last_event != NULL ) { event_data_t *data; data = (event_data_t*) delete_list_elem( event_list, last_event ); free( data ); last_event = get_list_tail( event_list ); } } Tcl_AppendResult( ip, "Error in call to tux_events: ", err_msg, "\n", "Usage: tux_events { list of event data }", (NULL) ); return TCL_ERROR; }
/*! Creates a cup_data_t object from a Tcl string. \return New cup_data_t object if successful, or NULL if error \author jfpatry \date Created: 2000-09-19 \date Modified: 2000-09-19 */ static cup_data_t* create_cup_data( Tcl_Interp *ip, const char *string, char **err_msg ) { const char **argv = NULL; const char **orig_argv = NULL; int argc = 0; char *name = NULL; char *icon = NULL; list_t race_list = NULL; list_elem_t last_race = NULL; const char **races = NULL; int num_races = 0; int i; cup_data_t *cup_data = NULL; if ( Tcl_SplitList( ip, string, &argc, &argv ) == TCL_ERROR ) { *err_msg = "cup data is not a list"; goto bail_cup_data; } orig_argv = argv; while ( *argv != NULL ) { if ( strcmp( *argv, "-name" ) == 0 ) { NEXT_ARG; if ( *argv == NULL ) { *err_msg = "No data supplied for -name in cup data"; goto bail_cup_data; } name = string_copy( *argv ); } else if ( strcmp( *argv, "-icon" ) == 0 ) { NEXT_ARG; if ( *argv == NULL ) { *err_msg = "No data supplied for -icon in cup data"; goto bail_cup_data; } icon = string_copy( *argv ); } else if ( strcmp( *argv, "-races" ) == 0 ) { NEXT_ARG; if ( *argv == NULL ) { *err_msg= "No data supplied for -races in cup data"; goto bail_cup_data; } race_list = create_list(); last_race = NULL; if ( Tcl_SplitList( ip, *argv, &num_races, &races ) == TCL_ERROR ) { *err_msg = "Race data is not a list in event data"; goto bail_cup_data; } for ( i=0; i<num_races; i++) { race_data_t *race_data; race_data = create_race_data( ip, races[i], err_msg ); if ( race_data == NULL ) { goto bail_cup_data; } last_race = insert_list_elem( race_list, last_race, (list_elem_data_t) race_data ); } Tcl_Free( (char*) races ); races = NULL; } else { sprintf( err_buff, "Unrecognized argument `%s'", *argv ); *err_msg = err_buff; goto bail_cup_data; } NEXT_ARG; } /* Make sure mandatory fields have been specified */ if ( name == NULL ) { *err_msg = "Must specify a name in cup data"; goto bail_cup_data; } if ( icon == NULL ) { *err_msg = "Must specify an icon texture in cup data"; goto bail_cup_data; } if ( race_list == NULL ) { *err_msg = "Must specify a race list in cup data"; goto bail_cup_data; } /* Create a new cup data object */ cup_data = (cup_data_t*) malloc( sizeof( cup_data_t ) ); check_assertion( cup_data != NULL, "out of memory" ); cup_data->name = name; cup_data->race_list = race_list; bind_texture( name, icon ); Tcl_Free( (char*) orig_argv ); argv = NULL; free( icon ); return cup_data; bail_cup_data: if ( orig_argv ) { Tcl_Free( (char*) orig_argv ); } if ( name ) { free( name ); } if ( icon ) { free( icon ); } if ( races ) { Tcl_Free( (char*) races ); } /* Clean out race list */ if ( race_list ) { last_race = get_list_tail( race_list ); while ( last_race != NULL ) { race_data_t *data; data = (race_data_t*) delete_list_elem( race_list, last_race ); free( data ); last_race = get_list_tail( race_list ); } del_list( race_list ); } if ( cup_data ) { free( cup_data ); } return NULL; }
/*! tux_open_courses Tcl callback \author jfpatry \date Created: 2000-09-19 \date Modified: 2000-09-19 */ static int open_courses_cb( ClientData cd, Tcl_Interp *ip, int argc, const char **argv ) { char *err_msg; const char **list = NULL; int num_courses; list_elem_t last_elem = NULL; list_elem_t last_speed_elem = NULL; list_elem_t last_score_elem = NULL; int i, j; char preview_file[100]; check_assertion( initialized, "course_mgr module not initialized" ); if ( argc != 2 ) { err_msg = "Wrong number of arguments"; goto bail_open_courses; } if ( Tcl_SplitList( ip, argv[1], &num_courses, &list ) == TCL_ERROR ) { err_msg = "Argument is not a list"; goto bail_open_courses; } /* Add items to end of list */ last_elem = get_list_tail( open_course_list ); last_speed_elem = get_list_tail( speed_course_list ); last_score_elem = get_list_tail( score_course_list ); for ( i=0; i<num_courses; i++ ) { open_course_data_t *data; data = create_open_course_data( ip, list[i], &err_msg ); #ifdef __ANDROID__ sprintf(preview_file, "courses/%s/preview.jpg", data->course); #else sprintf(preview_file, "%s/courses/%s/preview.jpg", getparam_data_dir(), data->course); #endif load_texture(data->course, preview_file, 1); bind_texture(data->course, data->course); if ( data == NULL ) { goto bail_open_courses; } last_elem = insert_list_elem( open_course_list, last_elem, (list_elem_data_t) data ); if(data->speed) { last_speed_elem = insert_list_elem( speed_course_list, last_speed_elem, (list_elem_data_t) data ); } if(data->score) { last_score_elem = insert_list_elem( score_course_list, last_score_elem, (list_elem_data_t) data ); } } Tcl_Free( (char*) list ); list = NULL; return TCL_OK; bail_open_courses: /* We'll leave the data that was successfully added in the list. */ Tcl_AppendResult( ip, "Error in call to tux_open_courses: ", err_msg, "\n", "Usage: tux_open_courses { list of open courses }", (NULL) ); return TCL_ERROR; }