void read_game_init_script() { char cwd[BUFF_LEN]; if ( getcwd( cwd, BUFF_LEN ) == NULL ) { handle_system_error( 1, "getcwd failed" ); } if ( chdir( getparam_data_dir() ) != 0 ) { /* Print a more informative warning since this is a common error */ handle_system_error( 1, "Can't find the tuxracer data " "directory. Please check the\nvalue of `data_dir' in " "~/.tuxracer/options and set it to the location where you\n" "installed the TRWC-data files.\n\n" "Couldn't chdir to %s", getparam_data_dir() ); } if ( Tcl_EvalFile( g_game.tcl_interp, GAME_INIT_SCRIPT) == TCL_ERROR ) { handle_error( 1, "error evalating %s/%s: %s\n" "Please check the value of `data_dir' in ~/.tuxracer/options " "and make sure it\npoints to the location of the " "latest version of the TRWC-data files.", getparam_data_dir(), GAME_INIT_SCRIPT, Tcl_GetStringResult( g_game.tcl_interp ) ); } check_assertion( !Tcl_InterpDeleted( g_game.tcl_interp ), "Tcl interpreter deleted" ); if ( chdir( cwd ) != 0 ) { handle_system_error( 1, "couldn't chdir to %s", cwd ); } }
void load_tux() { char cwd[BUFF_LEN]; if ( tuxLoaded == True ) return; tuxLoaded = True; registerHierCallbacks( g_game.tcl_interp ); register_tux_callbacks( g_game.tcl_interp ); initialize_scene_graph(); if ( getcwd( cwd, BUFF_LEN ) == NULL ) { handle_system_error( 1, "getcwd failed" ); } if ( chdir( getparam_data_dir() ) != 0 ) { /* Print a more informative warning since this is a common error */ handle_system_error( 1, "Can't find the tuxracer data " "directory. Please check the\nvalue of `data_dir' in " "~/.tuxracer/options and set it to the location where you\n" "installed the TRWC-data files.\n\n" "Couldn't chdir to %s", getparam_data_dir() ); /* handle_system_error( 1, "couldn't chdir to %s", getparam_data_dir() ); */ } if ( Tcl_EvalFile( g_game.tcl_interp, "tux.tcl") == TCL_ERROR ) { handle_error( 1, "error evalating %s/tux.tcl: %s\n" "Please check the value of `data_dir' in ~/.tuxracer/options " "and make sure it\npoints to the location of the " "latest version of the TRWC-data files.", getparam_data_dir(), Tcl_GetStringResult( g_game.tcl_interp ) ); } check_assertion( !Tcl_InterpDeleted( g_game.tcl_interp ), "Tcl interpreter deleted" ); if ( chdir( cwd ) != 0 ) { handle_system_error( 1, "couldn't chdir to %s", cwd ); } }
void calc_normals(const char *course) { scalar_t *elevation; scalar_t courseWidth, courseLength; int nx, ny; int x,y; point_t p0, p1, p2; vector_t n, nml, v1, v2; char buff[BUFF_LEN]; sprintf( buff, "%s/courses/%s/normal.data", getparam_data_dir(), course ); get_course_dimensions( &courseWidth, &courseLength ); get_course_divisions( &nx, &ny ); if(nmls != (void*)-1 && nmls_fd != -1) { munmap(nmls, nmls_len); close(nmls_fd); } #if 0 else { free(nmls); } #endif struct stat buf; int exists = (stat(buff, &buf) == 0); if(exists) { nmls_fd = open(buff, O_RDONLY); if ( nmls_fd == -1) { handle_system_error( 1, "can't open file failed" ); } TRDebugLog("mapping to memory normal.data\n"); nmls_len = sizeof(vector_t)*nx*ny; nmls = mmap(NULL, nmls_len, PROT_READ, MAP_SHARED,nmls_fd, 0); if ( nmls == (void *)-1 ) { handle_system_error( 1, "read mmap failed" ); } } else { nmls_len = sizeof(vector_t)*nx*ny; #if TARGET_IPHONE_SIMULATOR nmls_fd = open(buff, O_RDWR | O_CREAT | O_TRUNC, 0644); if ( nmls_fd == -1) { handle_system_error( 1, "can't open file failed" ); } int result = lseek(nmls_fd, nmls_len-1, SEEK_SET); if (result == -1) { handle_system_error( 1, "can't write file failed" ); } result = write(nmls_fd, "", 1); if (result != 1) { handle_system_error( 1, "can't write file failed" ); } nmls = mmap(NULL, nmls_len, PROT_READ | PROT_WRITE, MAP_SHARED, nmls_fd, 0); if ( nmls == (void *)-1 ) { handle_system_error( 1, "write mmap failed" ); } TRDebugLog("Writing to normal.data\n"); #else # ifdef TR_DEBUG_MODE abort(); // This shouldn't be reached on simulator. Crash to indicate. # endif nmls = malloc(nmls_len); #endif elevation = get_course_elev_data(); for ( y=0; y<ny; y++) { for ( x=0; x<nx; x++) { nml = make_vector( 0., 0., 0. ); p0 = make_point( XCD(x), ELEV(x,y), ZCD(y) ); /* The terrain is meshed as follows: ... +-+-+-+-+ x<---+ |\|/|\|/| | ...+-+-+-+-+... V |/|\|/|\| y +-+-+-+-+ ... So there are two types of vertices: those surrounded by four triangles (x+y is odd), and those surrounded by eight (x+y is even). */ #define POINT(x,y) make_point( XCD(x), ELEV(x,y), ZCD(y) ) if ( (x + y) % 2 == 0 ) { if ( x > 0 && y > 0 ) { p1 = POINT(x, y-1); p2 = POINT(x-1,y-1); v1 = subtract_points( p1, p0 ); v2 = subtract_points( p2, p0 ); n = cross_product( v2, v1 ); check_assertion( n.y > 0, "course normal points down" ); normalize_vector( &n ); nml = add_vectors( nml, n ); p1 = POINT(x-1,y-1); p2 = POINT(x-1,y ); v1 = subtract_points( p1, p0 ); v2 = subtract_points( p2, p0 ); n = cross_product( v2, v1 ); check_assertion( n.y > 0, "course normal points down" ); normalize_vector( &n ); nml = add_vectors( nml, n ); } if ( x > 0 && y < ny-1 ) { p1 = POINT(x-1,y ); p2 = POINT(x-1,y+1); v1 = subtract_points( p1, p0 ); v2 = subtract_points( p2, p0 ); n = cross_product( v2, v1 ); check_assertion( n.y > 0, "course normal points down" ); normalize_vector( &n ); nml = add_vectors( nml, n ); p1 = POINT(x-1,y+1); p2 = POINT(x ,y+1); v1 = subtract_points( p1, p0 ); v2 = subtract_points( p2, p0 ); n = cross_product( v2, v1 ); check_assertion( n.y > 0, "course normal points down" ); normalize_vector( &n ); nml = add_vectors( nml, n ); } if ( x < nx-1 && y > 0 ) { p1 = POINT(x+1,y ); p2 = POINT(x+1,y-1); v1 = subtract_points( p1, p0 ); v2 = subtract_points( p2, p0 ); n = cross_product( v2, v1 ); check_assertion( n.y > 0, "course normal points down" ); normalize_vector( &n ); nml = add_vectors( nml, n ); p1 = POINT(x+1,y-1); p2 = POINT(x ,y-1); v1 = subtract_points( p1, p0 ); v2 = subtract_points( p2, p0 ); n = cross_product( v2, v1 ); check_assertion( n.y > 0, "course normal points down" ); normalize_vector( &n ); nml = add_vectors( nml, n ); } if ( x < nx-1 && y < ny-1 ) { p1 = POINT(x+1,y ); p2 = POINT(x+1,y+1); v1 = subtract_points( p1, p0 ); v2 = subtract_points( p2, p0 ); n = cross_product( v1, v2 ); check_assertion( n.y > 0, "course normal points down" ); normalize_vector( &n ); nml = add_vectors( nml, n ); p1 = POINT(x+1,y+1); p2 = POINT(x ,y+1); v1 = subtract_points( p1, p0 ); v2 = subtract_points( p2, p0 ); n = cross_product( v1, v2 ); check_assertion( n.y > 0, "course normal points down" ); normalize_vector( &n ); nml = add_vectors( nml, n ); } } else { /* x + y is odd */ if ( x > 0 && y > 0 ) { p1 = POINT(x, y-1); p2 = POINT(x-1,y ); v1 = subtract_points( p1, p0 ); v2 = subtract_points( p2, p0 ); n = cross_product( v2, v1 ); check_assertion( n.y > 0, "course normal points down" ); normalize_vector( &n ); nml = add_vectors( nml, n ); } if ( x > 0 && y < ny-1 ) { p1 = POINT(x-1,y ); p2 = POINT(x ,y+1); v1 = subtract_points( p1, p0 ); v2 = subtract_points( p2, p0 ); n = cross_product( v2, v1 ); check_assertion( n.y > 0, "course normal points down" ); normalize_vector( &n ); nml = add_vectors( nml, n ); } if ( x < nx-1 && y > 0 ) { p1 = POINT(x+1,y ); p2 = POINT(x ,y-1); v1 = subtract_points( p1, p0 ); v2 = subtract_points( p2, p0 ); n = cross_product( v2, v1 ); check_assertion( n.y > 0, "course normal points down" ); normalize_vector( &n ); nml = add_vectors( nml, n ); } if ( x < nx-1 && y < ny-1 ) { p1 = POINT(x+1,y ); p2 = POINT(x ,y+1); v1 = subtract_points( p1, p0 ); v2 = subtract_points( p2, p0 ); n = cross_product( v1, v2 ); check_assertion( n.y > 0, "course normal points down" ); normalize_vector( &n ); nml = add_vectors( nml, n ); } } normalize_vector( &nml ); NORMAL(x,y) = nml; continue; } #undef POINT } #if TARGET_IPHONE_SIMULATOR munmap(nmls, nmls_len); close(nmls_fd); nmls_fd = open(buff, O_RDONLY); if (nmls_fd == -1) { handle_system_error( 1, "can't remount normal.data" ); } TRDebugLog("remounting to memory normal.data\n"); nmls_len = sizeof(vector_t)*nx*ny; nmls = mmap(NULL, nmls_len, PROT_READ, MAP_SHARED, nmls_fd, 0); if ( nmls == (void *)-1 ) { handle_system_error( 1, "remount mmap failed" ); } #endif } }
/*! 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; }