Exemplo n.º 1
0
bool_t flush_fonts(void)
{
    font_node_t *fontnode;
    hash_search_t  sptr;
    list_t delete_list;
    list_elem_t elem;
    char *key;
    bool_t result;

    delete_list = create_list();
  
    begin_hash_scan(font_table, &sptr);
    while ( next_hash_entry(sptr, &key, (hash_entry_t*)(&fontnode)) ) {
	if (fontnode->ref_count == 0) {
	    elem = insert_list_elem(delete_list, NULL, (list_elem_data_t)key);
	}
    }
    end_hash_scan(sptr);

    elem = get_list_head(delete_list);
    while (elem != NULL) {
	key = (char*)get_list_elem_data(elem);

	result = del_font( key );
	check_assertion(result, "Attempt to flush non-existant font");

	elem = get_next_list_elem(delete_list, elem);
    }

    del_list(delete_list);

    return True;

}
Exemplo n.º 2
0
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" );
}
Exemplo n.º 3
0
/*!
 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;
}
Exemplo n.º 4
0
/*!
 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;
}
Exemplo n.º 5
0
/*!
 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;
}