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 ); } }
inline void rawsocket_connection::receive_handshake_handler( const boost::system::error_code& error_code, size_t bytes_transferred) { if (error_code) { handle_system_error(error_code); return; } assert(bytes_transferred == sizeof(m_capabilities)); const auto& handshake_handler = get_handshake_handler(); handshake_handler(shared_from_this(), ntohl(m_capabilities)); }
inline bool rawsocket_connection::send_message(const char* message, size_t length) { boost::system::error_code error_code; // First write the message length prefix. uint32_t length_prefix = htonl(length); write(&length_prefix, sizeof(length_prefix), error_code); if (error_code) { handle_system_error(error_code); return false; } // Then write the actual message. write(message, length, error_code); if (error_code) { handle_system_error(error_code); return false; } return true; }
inline bool rawsocket_connection::send_handshake(uint32_t capabilities) { boost::system::error_code error_code; write(&capabilities, sizeof(capabilities), error_code); if (error_code) { handle_system_error(error_code); return false; } return true; }
inline void rawsocket_connection::receive_message_body_handler( const boost::system::error_code& error_code, size_t bytes_transferred) { if (error_code) { handle_system_error(error_code); return; } const auto& message_handler = get_message_handler(); assert(message_handler); message_handler(shared_from_this(), m_message_buffer.data(), bytes_transferred); async_receive(); }
inline void rawsocket_connection::receive_message_header_handler( const boost::system::error_code& error_code, size_t bytes_transferred) { if (error_code) { handle_system_error(error_code); return; } // Convert the message length to host order for convenience. uint32_t message_length = ntohl(m_message_length); // We cannot be guaranteed that a client implementation won't accidentally // introduce this protocol violation. In the event that we ever encounter // a message that reports a zero length we fail that connection gracefully. static const uint32_t MAX_MESSAGE_LENGTH = 16*1024*1024; // 16MB if (message_length == 0 || message_length > MAX_MESSAGE_LENGTH) { BONEFISH_TRACE("invalid message length: %1%", message_length); const auto& fail_handler = get_fail_handler(); fail_handler(shared_from_this(), "invalid message length"); return; } m_message_buffer.reserve(message_length); std::weak_ptr<rawsocket_connection> weak_self = std::static_pointer_cast<rawsocket_connection>(shared_from_this()); auto handler = [weak_self]( const boost::system::error_code& error_code, size_t bytes_transferred) { auto shared_self = weak_self.lock(); if (shared_self) { shared_self->receive_message_body_handler(error_code, bytes_transferred); } }; async_read(m_message_buffer.data(), message_length, handler); }
void process_all_events(void) { TROUT_FUNC_ENTER; if(reset_mac_trylock() == 0) { return; } atomic_set(&g_event_cnt, get_total_num_pending_events()); stop_alarm(g_mac_event_timer); while(atomic_read(&g_event_cnt) > 0) { #ifdef TROUT_WIFI_POWER_SLEEP_ENABLE #ifdef WIFI_SLEEP_POLICY if (mutex_is_locked(&suspend_mutex) || (g_wifi_suspend_status != wifi_suspend_nosuspend)) { //libing, 20140114, fix fake connection pr_info("We can't do %s during suspending, g_wifi_suspend_status = %d\n", __func__, g_wifi_suspend_status); reset_mac_unlock(); return; } #endif #endif /* Process pending events in the event queues */ process_event_queues(); if (counter_tmpr++ > 100)//by lihua { counter_tmpr = 0; #ifdef WAKE_LOW_POWER_POLICY if(g_wifi_power_mode != WIFI_NORMAL_POWER_MODE) { pr_info("We can't do %s during low power mode, g_wifi_suspend_status = %d\n", __func__, g_wifi_suspend_status); break; } #endif tempr_compensated(); } #ifndef MAC_HW_UNIT_TEST_MODE /* Handle lack of memory for WLAN Rx packets */ // handle_rxq_replenishment(); #endif /* MAC_HW_UNIT_TEST_MODE */ #ifdef BSS_ACCESS_POINT_MODE #ifdef ENABLE_PS_PKT_FLUSH /* Find the STA with maximum PS buffers */ find_max_ps_ae(); #endif /* ENABLE_PS_PKT_FLUSH */ #endif /* BSS_ACCESS_POINT_MODE */ #ifdef INT_WPS_SUPP //wxb add #ifdef IBSS_BSS_STATION_MODE /* Handle scan request from user/protocol */ if(g_wps_scan_req_from_user == BTRUE)// caisf add for fix wps scan bug. 1121 { handle_start_scan_req();//may be reset_mac g_wps_scan_req_from_user = BFALSE; } #endif #endif /* ifdef INT_WPS_SUPP */ /* Service Watchdog */ service_wdt(); } //chenq add 2012-11-02 // if((BOOL_T)atomic_read(&g_mac_reset_done) == BFALSE) //shield by chengwg, 2013-01-11! // return; /* Handle system error due to any failure */ active_netif_queue(); //add by chengwg. handle_system_error();//may be reset_mac /* Handle scan request from user/protocol */ //chenq mask 2012-10-29 //handle_start_scan_req(); #ifdef INT_WPS_SUPP //wxb add #ifdef IBSS_BSS_STATION_MODE /* Handle scan request from user/protocol */ if(g_wps_scan_req_from_user == BTRUE)// caisf add for fix wps scan bug. 1121 { handle_start_scan_req(); //the function may be reset_mac g_wps_scan_req_from_user = BFALSE; } #endif #endif /* ifdef INT_WPS_SUPP */ /* Service Watchdog */ service_wdt(); if(get_total_num_pending_events() > 0) { if(g_mac_event_timer == NULL) { g_mac_event_timer = create_alarm(mac_time2event_work, 0, NULL); } start_alarm(g_mac_event_timer, 100); } reset_mac_unlock(); TRACE_FUNC_EXIT; }
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 } }