static void die(void) { fprintf(stderr, " - saving and dying\n"); save_all(); unlock_gtt(); exit(1); }
/** * @brief Closes the small ingame menu and goes back to the main menu. * @param str Unused. */ static void menu_small_exit( unsigned int wid, char* str ) { (void) str; unsigned int info_wid, board_wid; /* if landed we must save anyways */ if (landed) { save_all(); land_cleanup(); } /* Close info menu if open. */ if (menu_isOpen(MENU_INFO)) { info_wid = window_get("Info"); window_destroy( info_wid ); menu_Close(MENU_INFO); } /* Force unboard. */ if (player_isBoarded()) { board_wid = window_get("Boarding"); board_exit(board_wid, NULL); } /* Stop player sounds because sometimes they hang. */ player_restoreControl( 0, _("Exited game.") ); player_soundStop(); /* Clean up. */ window_destroy( wid ); menu_Close(MENU_SMALL); menu_main(); }
/** * @brief Closes the small ingame menu and goes back to the main menu. * @param str Unused. */ static void menu_small_exit( unsigned int wid, char* str ) { (void) str; unsigned int info_wid; /* if landed we must save anyways */ if (landed) { /* increment time to match takeoff */ ntime_inc( RNG( 2*NTIME_UNIT_LENGTH, 3*NTIME_UNIT_LENGTH ) ); save_all(); land_cleanup(); } /* Close info menu if open. */ if (menu_isOpen(MENU_INFO)) { info_wid = window_get("Info"); window_destroy( info_wid ); menu_Close(MENU_INFO); } /* Stop player sounds because sometimes they hang. */ player_abortAutonav( "Exited game." ); player_stopSound(); /* Clean up. */ window_destroy( wid ); menu_Close(MENU_SMALL); menu_main(); }
bool core::archive::image_cache::update_file_from_tmp_files() { const bool to_add_exists = tools::system::is_exist(tmp_to_add_storage_->get_file_name()); if (to_add_exists) { images_map_t to_add; if (!read_file(*tmp_to_add_storage_, to_add)) return false; add_images_to_tree(to_add); if (!append_to_file(*storage_, to_add)) return false; } const bool to_delete_exists = tools::system::is_exist(tmp_to_delete_storage_->get_file_name()); if (to_delete_exists) { bool need_to_save_all = false; if (!process_deleted(need_to_save_all)) return false; if (need_to_save_all && !save_all()) return false; } delete_tmp_files(); return true; }
/** * @brief Exits the game. */ static void exit_game (void) { /* if landed we must save anyways */ if (landed) { save_all(); land_cleanup(); } SDL_Event quit; quit.type = SDL_QUIT; SDL_PushEvent(&quit); }
bool core::archive::image_cache::build(const contact_archive& _archive) { cancel_build_.clear(); tree_is_consistent_ = false; building_in_progress_ = true; image_by_msgid_.clear(); history_block messages; int64_t from = -1; while (true) { if (cancel_build_.test_and_set()) { return false; } cancel_build_.clear(); _archive.get_messages(from, fetch_size, -1, messages, contact_archive::get_message_policy::skip_patches_and_deleted); if (messages.empty()) { building_in_progress_ = false; tree_is_consistent_ = true; update_tree_from_tmp_files(); data_ready_.notify_all(); if (save_all()) { delete_tmp_files(); return true; } return false; } from = (*messages.begin())->get_msgid(); const auto images = extract_images(messages); if (!images.empty()) { { std::lock_guard<std::mutex> lock(mutex_); add_images_to_tree(images); } data_ready_.notify_all(); } } }
void cheat_manager::reload() { // if the cheat engine is disabled, we're done if (!machine().options().cheat()) return; // free everything m_cheatlist.reset(); // reset state m_framecount = 0; m_numlines = 0; m_lastline = 0; m_disabled = false; // load the cheat file, if it's a system that has a software list then try softlist_name/shortname.xml first, // if it fails to load then try to load via crc32 - basename/crc32.xml ( eg. 01234567.xml ) image_interface_iterator iter(machine().root_device()); for (device_image_interface *image = iter.first(); image != nullptr; image = iter.next()) if (image->exists()) { // if we are loading through a software list, try to load softlist_name/shortname.xml // this allows the coexistence of arcade cheats with cheats for home conversions which // have the same shortname if (image->software_entry() != nullptr) { std::string filename; strprintf(filename, "%s%s%s", image->software_list_name(), PATH_SEPARATOR, image->basename()); load_cheats(filename.c_str()); break; } // else we are loading outside the software list, try to load machine_basename/crc32.xml else { UINT32 crc = image->crc(); if (crc != 0) { std::string filename; strprintf(filename, "%s%s%08X", machine().basename(), PATH_SEPARATOR, crc); load_cheats(filename.c_str()); break; } } } // if we haven't found the cheats yet, load by basename if (m_cheatlist.count() == 0) load_cheats(machine().basename()); // temporary: save the file back out as output.xml for comparison if (m_cheatlist.count() != 0) save_all("output"); }
/** * @brief Exits the game. */ static void exit_game (void) { /* if landed we must save anyways */ if (landed) { /* increment time to match takeoff */ ntime_inc( RNG( 2*NTIME_UNIT_LENGTH, 3*NTIME_UNIT_LENGTH ) ); save_all(); land_cleanup(); } SDL_Event quit; quit.type = SDL_QUIT; SDL_PushEvent(&quit); }
void do_scan(){ load_features(); load_tests(); load_aho_corasick_triggers(); load_feature_selections(); add_post_rules(); struct timeval tv; gettimeofday(&tv, NULL); u64 st_time; u32 last_req=0; u64 last_time, last_h_time; st_time = tv.tv_sec * 1000LL + tv.tv_usec / 1000; last_time=st_time; last_h_time=st_time; enable_trap=1; maybe_queue_more_hosts(); u64 run_time; while ((next_from_queue() && !stop_soon)) { u64 end_time; struct timeval tv_tmp; gettimeofday(&tv_tmp, NULL); end_time = tv_tmp.tv_sec * 1000LL + tv_tmp.tv_usec / 1000; run_time = end_time - st_time; if(max_time && run_time>(max_time * 1000LL * 60LL)){ warn("Max time reached!"); stop_soon=1; } if(progress && ((end_time-last_time)>(1000*progress))){ req_sec = ((req_count - queue_cur)-last_req) * 1000.0 / ((end_time-last_time) + 1); last_time=end_time; last_req=(req_count - queue_cur); http_stats(st_time); } if((end_time-last_h_time)>500){ last_h_time=end_time; maybe_queue_more_hosts(); } } printf("FINISHED (avg req/s = %f)\n", ((req_count - queue_cur) * 1000.0) / (run_time + 1)); if(train || force_save) save_all(); if(store_successes) save_successes(); }
void cheat_manager::reload() { // if the cheat engine is disabled, we're done if (!machine().options().cheat()) return; // free everything m_cheatlist.reset(); // reset state m_framecount = 0; m_numlines = 0; m_lastline = 0; m_disabled = false; // load the cheat file, MESS will load a crc32.xml ( eg. 01234567.xml ) // and MAME will load gamename.xml image_interface_iterator iter(machine().root_device()); for (device_image_interface *image = iter.first(); image != NULL; image = iter.next()) if (image->exists()) { // if we are loading through software lists, try to load shortname.xml if (image->software_entry() != NULL) { load_cheats(image->basename()); break; } else { UINT32 crc = image->crc(); if (crc != 0) { astring filename; filename.printf("%08X", crc); load_cheats(filename); break; } } } // if we haven't found the cheats yet, load by basename if (m_cheatlist.count() == 0) load_cheats(machine().basename()); // temporary: save the file back out as output.xml for comparison if (m_cheatlist.count() != 0) save_all("output"); }
static void msg_command( struct mg_connection* nc, const char* p, int len ) { const char* cmd = p; int cmd_len = param_len( p, len ); if ( cmd_len == -1 ) { perror("cmd_len == -1"); return; } p += (cmd_len+1); len -= (cmd_len+1); if ( strncmp( cmd, "SAVE", cmd_len ) == 0 ) { msg_save( p, len ); return; } if ( strncmp( cmd, "RM", cmd_len ) == 0 ) { msg_rm( p, len ); return; } if ( strncmp( cmd, "JOIN", cmd_len ) == 0) { send_sources(nc); return; } if ( strncmp( cmd, "ARCHIVE", cmd_len ) == 0) { save_archive(); return; } if ( strncmp( cmd, "SAVE-ALL", cmd_len ) == 0 ) { save_all(nc); return; } printf("UNKNOWN %s\n",cmd); }
int Agent::best_choice() { static int base = 0; result[0] = -MAX_INT; move_list_len[0] = history->move_list_len(role, step); save_all(0); temp_move[0] = best_move[0] = 0; if(hash->exist(role)){ temp_move[0] = best_move[0] = hash->match_best; } if(best_move[0]){ board->put(best_move[0], role); result[0] = estimation(opp_role, 1, -MAX_INT, MAX_INT); recover_all(0); #ifdef VERBOSE printf("%d @ (%d, %d) <- %d (best)\n", result[0], xx[best_move[0]], yy[best_move[0]], history->get_init_index(best_move[0])); #endif } for(register int i = 1; i <= move_list_len[0]; ++i){ cur_move[0] = history->move(role, step, i); if( !board->can_put(cur_move[0], role) || cur_move[0] == temp_move[0]) continue; board->put(cur_move[0], role); value[0] = estimation(opp_role, 1, result[0], MAX_INT); recover_all(0); #ifdef VERBOSE printf("%d @ (%d, %d) <- %d\n", value[0], xx[cur_move[0]], yy[cur_move[0]],\ history->get_init_index(cur_move[0])); #endif if(value[0] > result[0]){ result[0] = value[0]; best_move[0] = cur_move[0]; } } hash->insert(result[0], role, H_EXACT, best_move[0], base, step); // this is for hash history saved file return best_move[0]; }
/** * @brief Makes the player take off if landed. * * @param delay Whether or not to have time pass as if the player landed normally. */ void takeoff( int delay ) { int h; char *nt; double a, r; if (!landed) return; /* Player's ship is not able to fly. */ if (!player_canTakeoff()) { char message[512]; pilot_reportSpaceworthy( player.p, message, sizeof(message) ); dialogue_msg( "Ship not fit for flight", message ); /* Check whether the player needs rescuing. */ land_stranded(); return; } /* Clear queued takeoff. */ land_takeoff = 0; /* Refuel if needed. */ land_refuel(); /* In case we had paused messy sounds. */ sound_stopAll(); /* ze music */ music_choose("takeoff"); /* to randomize the takeoff a bit */ a = RNGF() * 2. * M_PI; r = RNGF() * land_planet->radius; /* no longer authorized to land */ player_rmFlag(PLAYER_LANDACK); pilot_rmFlag(player.p,PILOT_LANDING); /* No longer landing. */ /* set player to another position with random facing direction and no vel */ player_warp( land_planet->pos.x + r * cos(a), land_planet->pos.y + r * sin(a) ); vect_pset( &player.p->solid->vel, 0., 0. ); player.p->solid->dir = RNGF() * 2. * M_PI; cam_setTargetPilot( player.p->id, 0 ); /* heal the player */ pilot_healLanded( player.p ); /* Clear planet target. Allows for easier autonav out of the system. */ player_targetPlanetSet( -1 ); /* initialize the new space */ h = player.p->nav_hyperspace; space_init(NULL); player.p->nav_hyperspace = h; /* cleanup */ if (save_all() < 0) /* must be before cleaning up planet */ dialogue_alert( "Failed to save game! You should exit and check the log to see what happened and then file a bug report!" ); /* time goes by, triggers hook before takeoff */ if (delay) ntime_inc( ntime_create( 0, 1, 0 ) ); /* 1 STP */ nt = ntime_pretty( 0, 2 ); player_message("\epTaking off from %s on %s.", land_planet->name, nt); free(nt); /* Hooks and stuff. */ land_cleanup(); /* Cleanup stuff */ hooks_run("takeoff"); /* Must be run after cleanup since we don't want the missions to think we are landed. */ if (menu_isOpen(MENU_MAIN)) return; player_addEscorts(); hooks_run("enter"); if (menu_isOpen(MENU_MAIN)) return; events_trigger( EVENT_TRIGGER_ENTER ); missions_run( MIS_AVAIL_SPACE, -1, NULL, NULL ); if (menu_isOpen(MENU_MAIN)) return; player.p->ptimer = PILOT_TAKEOFF_DELAY; pilot_setFlag( player.p, PILOT_TAKEOFF ); pilot_setThrust( player.p, 0. ); pilot_setTurn( player.p, 0. ); }
static void save_all_cb(RoccatConfigWindow *roccat_window, gpointer user_data) { save_all(KONEPURECONFIG_WINDOW(roccat_window), FALSE); }
static gboolean delete_event_cb(GtkWidget *window, GdkEvent *event, gpointer user_data) { return !save_all(KONEPURECONFIG_WINDOW(window), TRUE); }
int Agent::estimation(char color, int depth, int alpha, int beta) { if( !board->able_to_put(color)){ color = opposite(color); if( !board->able_to_put(color)){ if(!end_game) cost->update(); return eval->value(); } } temp_move[depth] = best_move[depth] = 0; switch(hash->exist(color, alpha, beta, depth)){ case H_NONE_EXIST: break; case H_MATCH_EXIST: temp_move[depth] = best_move[depth] = hash->match_best; break; case H_EXACT_EXIST: return hash->match_eval; } if(depth == max_depth){ //the last search ply, no pv used return terminal_eval(color, depth, alpha, beta); } //pv_found[depth] = false; save_all(depth); if(best_move[depth]){ board->put(best_move[depth], color); value[depth] = estimation(opposite(color), depth+1, alpha, beta); recover_all(depth); if( color == role){ if( value[depth] > alpha){ if( (alpha = value[depth]) >= beta){ return alpha; } //pv_found[depth] = true; } result[depth] = value[depth]; } else{ if(value[depth] < beta){ if( (beta = value[depth]) <= alpha){ return beta; } //pv_found[depth] = true; } result[depth] = value[depth]; } } else{ result[depth] = (color == role)? -MAX_INT: MAX_INT; } move_list_len[depth] = history->move_list_len(color, step+depth); for(register int i = 1; i <= move_list_len[depth]; ++i){ cur_move[depth] = history->move(color, step+depth, i); if( !board->can_put(cur_move[depth], color) || cur_move[depth] == temp_move[depth]) continue; board->put(cur_move[depth], color); //if(pv_found[depth] == true){ // if(color == role){ // value[depth] = estimation(opposite(color), depth+1, beta-1, beta); // if(value[depth] > alpha && value[depth] < beta){ // value[depth] = // estimation(opposite(color), depth+1, alpha, value[depth]); // } // } // else{ // value[depth] = estimation(opposite(color), depth+1, alpha, alpha+1); // if(value[depth] > alpha && value[depth] < beta){ // value[depth] = // estimation(opposite(color), depth+1, value[depth], beta); // } // } //} //else value[depth] = estimation(opposite(color), depth+1, alpha, beta); recover_all(depth); if( color == role){ if( value[depth] > alpha){ if( (alpha = value[depth]) >= beta){ history->advance_move(color, step+depth, i); hash->insert(alpha, color, H_LOW_BOUND, cur_move[depth], depth, step+depth); return alpha; } //(void)((pv_found[depth])? : pv_found[depth] = true); } if(value[depth] > result[depth]){ result[depth] = value[depth]; best_move[depth] = cur_move[depth]; } } else{ if(value[depth] < beta){ if( (beta = value[depth]) <= alpha){ history->advance_move(color, step+depth, i); hash->insert(beta, color, H_UP_BOUND, cur_move[depth], depth, step+depth); return beta; } //(void)((pv_found[depth])? : pv_found[depth] = true); } if(value[depth] < result[depth]){ result[depth] = value[depth]; best_move[depth] = cur_move[depth]; } } } hash->insert(result[depth], color, H_EXACT, best_move[depth], depth, step+depth); return result[depth]; }
// -------------------------------------------------------------------------- void main() { int i,j,k; int sec, t; double I[N]; FILE *fs, *fx, *fd; srand(0); initialize(); // for sec=1:60*60*5 for (sec=0; sec<60*60*5; sec++) { // for t=1:1000 % simulation of 1 sec for (t=0;t<1000;t++) { for (i=0;i<N;i++) I[i] = 0; I[int(floor(N*rand01))]=20; for (i=0;i<N;i++) // fired = find(v>=30); % indices of fired neurons if (v[i]>=30) { // v(fired)=-65; v[i] = -65; // u(fired)=u(fired)+d(fired); u[i]+=d[i]; // LTP(fired,t+D)=0.1; LTP[i][t+D]= 0.1; // LTD(fired)=0.12; LTD[i]=0.12; // for k=1:length(fired) // sd(pre{fired(k)}) = sd(pre{fired(k)})+LTP(N*t+aux{fired(k)}); // end; for (j=0;j<N_pre[i];j++) *sd_pre[i][j]+=LTP[I_pre[i][j]][t+D-D_pre[i][j]-1]; // firings=[firings; t+zeros(length(fired),1), fired]; firings[N_firings ][0]=t; firings[N_firings++][1]=i; if (N_firings == N_firings_max) { cout << "*** Two many spikes, t=" << t << "*** (ignoring)"; N_firings=1; } } // k=size(firings,1); k=N_firings-1; // while t-firings(k,1)<D while (t-firings[k][0] <D) { // del=delays{firings(k,2),t-firings(k,1)+1}; for (j=0; j< delays_length[firings[k][1]][t-firings[k][0]]; j++) { // ind = post(firings(k,2),del); i=post[firings[k][1]][delays[firings[k][1]][t-firings[k][0]][j]]; // I(ind)=I(ind)+s(firings(k,2), del)'; I[i]+=s[firings[k][1]][delays[firings[k][1]][t-firings[k][0]][j]]; // if firings(k,2) <=Ne if (firings[k][1] <Ne) // sd(firings(k,2),del)=sd(firings(k,2),del)-LTD(ind)'; sd[firings[k][1]][delays[firings[k][1]][t-firings[k][0]][j]]-=LTD[i]; // end; } // k=k-1; k--; // end; } for (i=0;i<N;i++) { // v = v + 0.5*((0.04*v+5).*v+140-u+I); % for numerical stability // v = v + 0.5*((0.04*v+5).*v+140-u+I); % time step is 0.5 ms v[i]+=0.5*((0.04*v[i]+5)*v[i]+140-u[i]+I[i]); v[i]+=0.5*((0.04*v[i]+5)*v[i]+140-u[i]+I[i]); // u = u + a.*(0.2*v-u); u[i]+=a[i]*(0.2*v[i]-u[i]); // LTP(:,t+D+1)=0.95*LTP(:,t+D); % tau = 20 ms LTP[i][t+D+1]=0.95*LTP[i][t+D]; // LTD=0.95*LTD; % tau = 20 ms LTD[i]*=0.95; } // end; } // frate(end+1)=sum(firings(:,2)<=Ne)/Ne; double frate=0; for (i=1;i<N_firings;i++) if ((firings[i][0] >=0) && (firings[i][1] <Ne)) frate++; frate = frate/Ne; // str(end+1) = sum(sum(s(find(post<=Ne)) > 6.3))/Ne; double str=0; for (i=0;i<Ne;i++) for (j=0;j<M;j++) if ((s[i][j] > 0.9*C_max) && (post[i][j] <Ne)) str++; str=100*str/Ne/M; // sec, [frate(end), str(end), sum(firings(:,2)>Ne)/Ni] double ifrate=0; for (i=1;i<N_firings;i++) if ((firings[i][0] >=0) && (firings[i][1] >=Ne)) ifrate++; ifrate = ifrate/Ni; cout << "sec=" << sec << ", exc. frate=" << frate << ", exc->exc str=" << str << ", inh. frate=" << ifrate << ".\n"; fx = fopen("..//dat.dat","a"); fprintf(fx, "%d %2.2f %2.2f %2.2f\n", sec, frate, str, ifrate); fclose(fx); // plot(firings(:,1),firings(:,2),'.'); // axis([0 1000 0 N]); drawnow; fs = fopen("..//spikest.dat","w"); for (i=1;i<N_firings;i++) if (firings[i][0] >=0) fprintf(fs, "%d %d\n", sec*000+firings[i][0], firings[i][1]); fclose(fs); remove("..//spikes.dat"); rename( "..//spikest.dat", "..//spikes.dat" ); // LTP(:,1:D+1)=LTP(:,1001:1001+D); for (i=0;i<N;i++) for (j=0;j<D+1;j++) LTP[i][j]=LTP[i][1000+j]; // ind = find(1001-firings(:,1) < D); k=N_firings-1; while (1000-firings[k][0]<D) k--; // firings=[-D 0; firings(ind,1)-1000, firings(ind,2)]; for (i=1;i<N_firings-k;i++) { firings[i][0]=firings[k+i][0]-1000; firings[i][1]=firings[k+i][1]; } N_firings = N_firings-k; // sd=0.9*sd; % tau = 250 ms // s(1:Ne,:)=max(0,min(7, 0.01+s(1:Ne,:)+sd(1:Ne,:))); for (i=0;i<Ne;i++) for (j=0;j<M;j++) { sd[i][j]*=0.9; s[i][j]+=0.01+sd[i][j]; if (s[i][j]>C_max) s[i][j]=C_max; if (s[i][j]<0) s[i][j]=0; } // if mod(sec,10)==0, // save all; // end; if ( (sec%100==0) & (sec > 0)) { save_all("..//all.dat"); fs = fopen("..//s.dat", "w"); for (i=0; i<Ne; i++) for (j=0;j<M; j++) fprintf(fs, "%d %3.3f\n", post[i][j], s[i][j]); fclose(fs); } // end; } fpoly = fopen("..//polyall.dat","w"); all_polychronous(); k=N_polychronous; fclose(fpoly); shuffle(); all_polychronous(); cout << "ratio (true/shuffled) = " << double(k)/(N_polychronous+1) << " "; }
static int command() { FILE *fp; int i; /* string holding name of save or load file */ char sv_file[MAX_LINE_LEN + 1]; for (i = 0; i < MAX_NUM_VAR; i++) c_dummy_var[i][0] = NUL; /* no dummy variables */ if (is_definition(c_token)) define(); else if (almost_equals(c_token, "h$elp") || equals(c_token, "?")) { c_token++; do_help(1); } else if (equals(c_token, "testtime")) { /* given a format and a time string, exercise the time code */ char format[160], string[160]; struct tm tm; double secs; if (isstring(++c_token)) { quote_str(format, c_token, 159); if (isstring(++c_token)) { quote_str(string, c_token++, 159); memset(&tm, 0, sizeof(tm)); gstrptime(string, format, &tm); secs = gtimegm(&tm); fprintf(stderr, "internal = %f - %d/%d/%d::%d:%d:%d , wday=%d, yday=%d\n", secs, tm.tm_mday, tm.tm_mon + 1, tm.tm_year % 100, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_wday, tm.tm_yday); memset(&tm, 0, sizeof(tm)); ggmtime(&tm, secs); gstrftime(string, 159, format, secs); fprintf(stderr, "convert back \"%s\" - %d/%d/%d::%d:%d:%d , wday=%d, yday=%d\n", string, tm.tm_mday, tm.tm_mon + 1, tm.tm_year % 100, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_wday, tm.tm_yday); } } } else if (almost_equals(c_token, "test")) { c_token++; test_term(); } else if (almost_equals(c_token, "scr$eendump")) { c_token++; #ifdef _Windows screen_dump(); #else fputs("screendump not implemented\n", stderr); #endif } else if (almost_equals(c_token, "pa$use")) { struct value a; int sleep_time, text = 0; char buf[MAX_LINE_LEN + 1]; c_token++; sleep_time = (int) real(const_express(&a)); buf[0] = NUL; if (!(END_OF_COMMAND)) { if (!isstring(c_token)) int_error("expecting string", c_token); else { quote_str(buf, c_token, MAX_LINE_LEN); ++c_token; #ifdef _Windows if (sleep_time >= 0) #else # ifdef OS2 if (strcmp(term->name, "pm") != 0 || sleep_time >= 0) # else # ifdef MTOS if (strcmp(term->name, "mtos") != 0 || sleep_time >= 0) # endif /* MTOS */ # endif /* OS2 */ #endif /* _Windows */ fputs(buf, stderr); text = 1; } } if (sleep_time < 0) { #ifdef _Windows if (!Pause(buf)) bail_to_command_line(); #else # ifdef OS2 if (strcmp(term->name, "pm") == 0 && sleep_time < 0) { int rc; if ((rc = PM_pause(buf)) == 0) bail_to_command_line(); else if (rc == 2) { fputs(buf, stderr); text = 1; (void) fgets(buf, MAX_LINE_LEN, stdin); } } # else /* !OS2 */ # ifdef _Macintosh if (strcmp(term->name, "macintosh") == 0 && sleep_time < 0) Pause(sleep_time); # else /* !_Macintosh */ # ifdef MTOS if (strcmp(term->name, "mtos") == 0) { int MTOS_pause(char *buf); int rc; if ((rc = MTOS_pause(buf)) == 0) bail_to_command_line(); else if (rc == 2) { fputs(buf, stderr); text = 1; (void) fgets(buf, MAX_LINE_LEN, stdin); } } else if (strcmp(term->name, "atari") == 0) { char *readline(char *); char *line = readline(""); if (line) free(line); } else (void) fgets(buf, MAX_LINE_LEN, stdin); # else /* !MTOS */ # ifdef ATARI if (strcmp(term->name, "atari") == 0) { char *readline(char *); char *line = readline(""); if (line) free(line); } else (void) fgets(buf, MAX_LINE_LEN, stdin); # else /* !ATARI */ (void) fgets(buf, MAX_LINE_LEN, stdin); /* Hold until CR hit. */ # endif /* !ATARI */ # endif /* !MTOS */ # endif /* !_Macintosh */ # endif /* !OS2 */ #endif } if (sleep_time > 0) GP_SLEEP(sleep_time); if (text != 0 && sleep_time >= 0) fputc('\n', stderr); screen_ok = FALSE; } else if (almost_equals(c_token, "pr$int")) { int need_space = 0; /* space printed between two expressions only */ screen_ok = FALSE; do { ++c_token; if (isstring(c_token)) { char s[MAX_LINE_LEN]; quote_str(s, c_token, MAX_LINE_LEN); fputs(s, stderr); need_space = 0; ++c_token; } else { struct value a; (void) const_express(&a); if (need_space) putc(' ', stderr); need_space = 1; disp_value(stderr, &a); } } while (!END_OF_COMMAND && equals(c_token, ",")); (void) putc('\n', stderr); } else if (almost_equals(c_token, "fit")) { ++c_token; do_fit(); } else if (almost_equals(c_token, "up$date")) { char tmps[80]; char tmps2[80]; /* Have to initialise tmps2, otherwise * update() cannot decide whether a valid * filename was given. lh */ tmps2[0] = NUL; if (!isstring(++c_token)) int_error("Parameter filename expected", c_token); quote_str(tmps, c_token++, 80); if (!(END_OF_COMMAND)) { if (!isstring(c_token)) int_error("New parameter filename expected", c_token); else quote_str(tmps2, c_token++, 80); } update(tmps, tmps2); } else if (almost_equals(c_token, "p$lot")) { plot_token = c_token++; SET_CURSOR_WAIT; plotrequest(); SET_CURSOR_ARROW; } else if (almost_equals(c_token, "sp$lot")) { plot_token = c_token++; SET_CURSOR_WAIT; plot3drequest(); SET_CURSOR_ARROW; } else if (almost_equals(c_token, "rep$lot")) { if (replot_line[0] == NUL) int_error("no previous plot", c_token); c_token++; SET_CURSOR_WAIT; replotrequest(); SET_CURSOR_ARROW; } else if (almost_equals(c_token, "se$t")) set_command(); else if (almost_equals(c_token, "res$et")) reset_command(); else if (almost_equals(c_token, "sh$ow")) show_command(); else if (almost_equals(c_token, "cl$ear")) { term_start_plot(); if (multiplot && term->fillbox) { unsigned int x1 = (unsigned int) (xoffset * term->xmax); unsigned int y1 = (unsigned int) (yoffset * term->ymax); unsigned int width = (unsigned int) (xsize * term->xmax); unsigned int height = (unsigned int) (ysize * term->ymax); (*term->fillbox) (0, x1, y1, width, height); } term_end_plot(); screen_ok = FALSE; c_token++; } else if (almost_equals(c_token, "she$ll")) { do_shell(); screen_ok = FALSE; c_token++; } else if (almost_equals(c_token, "sa$ve")) { if (almost_equals(++c_token, "f$unctions")) { if (!isstring(++c_token)) int_error("expecting filename", c_token); else { quote_str(sv_file, c_token, MAX_LINE_LEN); save_functions(fopen(sv_file, "w")); } } else if (almost_equals(c_token, "v$ariables")) { if (!isstring(++c_token)) int_error("expecting filename", c_token); else { quote_str(sv_file, c_token, MAX_LINE_LEN); save_variables(fopen(sv_file, "w")); } } else if (almost_equals(c_token, "s$et")) { if (!isstring(++c_token)) int_error("expecting filename", c_token); else { quote_str(sv_file, c_token, MAX_LINE_LEN); save_set(fopen(sv_file, "w")); } } else if (isstring(c_token)) { quote_str(sv_file, c_token, MAX_LINE_LEN); save_all(fopen(sv_file, "w")); } else { int_error("filename or keyword 'functions', 'variables', or 'set' expected", c_token); } c_token++; } else if (almost_equals(c_token, "l$oad")) { if (!isstring(++c_token)) int_error("expecting filename", c_token); else { quote_str(sv_file, c_token, MAX_LINE_LEN); /* load_file(fp=fopen(sv_file, "r"), sv_file, FALSE); OLD * DBT 10/6/98 handle stdin as special case * passes it on to load_file() so that it gets * pushed on the stack and recusion will work, etc */ fp = strcmp(sv_file, "-") ? fopen(sv_file, "r") : stdin; load_file(fp, sv_file, FALSE); /* input_line[] and token[] now destroyed! */ c_token = num_tokens = 0; } } else if (almost_equals(c_token, "ca$ll")) { if (!isstring(++c_token)) int_error("expecting filename", c_token); else { quote_str(sv_file, c_token, MAX_LINE_LEN); load_file(fopen(sv_file, "r"), sv_file, TRUE); /* Argument list follows filename */ /* input_line[] and token[] now destroyed! */ c_token = num_tokens = 0; } } else if (almost_equals(c_token, "if")) { double exprval; struct value t; if (!equals(++c_token, "(")) /* no expression */ int_error("expecting (expression)", c_token); exprval = real(const_express(&t)); if (exprval != 0.0) { /* fake the condition of a ';' between commands */ int eolpos = token[num_tokens - 1].start_index + token[num_tokens - 1].length; --c_token; token[c_token].length = 1; token[c_token].start_index = eolpos + 2; input_line[eolpos + 2] = ';'; input_line[eolpos + 3] = NUL; } else c_token = num_tokens = 0; } else if (almost_equals(c_token, "rer$ead")) { fp = lf_top(); if (fp != (FILE *) NULL) rewind(fp); c_token++; } else if (almost_equals(c_token, "cd")) { if (!isstring(++c_token)) int_error("expecting directory name", c_token); else { quote_str(sv_file, c_token, MAX_LINE_LEN); if (changedir(sv_file)) { int_error("Can't change to this directory", c_token); } c_token++; } } else if (almost_equals(c_token, "pwd")) { GP_GETCWD(sv_file, sizeof(sv_file)); fprintf(stderr, "%s\n", sv_file); c_token++; } else if (almost_equals(c_token, "ex$it") || almost_equals(c_token, "q$uit")) { /* graphics will be tidied up in main */ return (1); } else if (!equals(c_token, ";")) { /* null statement */ #ifdef OS2 if (_osmode == OS2_MODE) { if (token[c_token].is_token) { int rc; rc = ExecuteMacro(input_line + token[c_token].start_index, token[c_token].length); if (rc == 0) { c_token = num_tokens = 0; return (0); } } } #endif int_error("invalid command", c_token); } return (0); }
bool core::archive::image_cache::update(const history_block& _block) { if (!tree_is_consistent_) { image_vector_t to_add; image_vector_t to_delete; for (const auto& it : _block) { const history_message& message = *it; if (message.is_patch()) to_delete.emplace_back(image_data(message.get_msgid())); else extract_images(message, to_add); } const bool add_result = append_to_file(*tmp_to_add_storage_, to_add); const bool delete_result = append_to_file(*tmp_to_delete_storage_, to_delete); return add_result && delete_result; } const auto end = image_by_msgid_.end(); bool need_to_save_all = false; image_vector_t to_add; for (const auto& it : _block) { const history_message& message = *it; const auto msgid = message.get_msgid(); if (message.is_patch()) { auto to_delete = image_by_msgid_.find(msgid); if (to_delete != end) { need_to_save_all = true; image_by_msgid_.erase(to_delete); } } else { extract_images(message, to_add); } } if (need_to_save_all) { return save_all(); } else if (!to_add.empty()) { archive::storage_mode mode; mode.flags_.write_ = true; mode.flags_.append_ = true; if (!storage_->open(mode)) return false; core::tools::auto_scope lb([this]{ storage_->close(); }); add_images_to_tree(to_add); return serialize_block(*storage_, to_add); } return true; }
bool core::archive::image_cache::synchronize(const archive_index& _index) { erase_deleted_from_tree(_index); return save_all(); }
/** * @brief Makes the player take off if landed. * * @param delay Whether or not to have time pass as if the player landed normally. */ void takeoff( int delay ) { int h; char *nt; double a, r; if (!landed) return; /* Clear queued takeoff. */ land_takeoff = 0; /* Refuel if needed. */ land_checkAddRefuel(); /* In case we had paused messy sounds. */ sound_stopAll(); /* ze music */ music_choose("takeoff"); /* to randomize the takeoff a bit */ a = RNGF() * 2. * M_PI; r = RNGF() * land_planet->radius; /* no longer authorized to land */ player_rmFlag(PLAYER_LANDACK); pilot_rmFlag(player.p,PILOT_LANDING); /* No longer landing. */ /* set player to another position with random facing direction and no vel */ player_warp( land_planet->pos.x + r * cos(a), land_planet->pos.y + r * sin(a) ); vect_pset( &player.p->solid->vel, 0., 0. ); player.p->solid->dir = RNGF() * 2. * M_PI; cam_setTargetPilot( player.p->id, 0 ); /* heal the player */ player.p->armour = player.p->armour_max; player.p->shield = player.p->shield_max; player.p->energy = player.p->energy_max; player.p->stimer = 0.; /* initialize the new space */ h = player.p->nav_hyperspace; space_init(NULL); player.p->nav_hyperspace = h; /* cleanup */ if (save_all() < 0) { /* must be before cleaning up planet */ dialogue_alert( "Failed to save game! You should exit and check the log to see what happened and then file a bug report!" ); } /* time goes by, triggers hook before takeoff */ if (delay) ntime_inc( ntime_create( 0, 1, 0 ) ); /* 1 STP */ nt = ntime_pretty( 0, 2 ); player_message("\epTaking off from %s on %s.", land_planet->name, nt); free(nt); /* Hooks and stuff. */ land_cleanup(); /* Cleanup stuff */ hooks_run("takeoff"); /* Must be run after cleanup since we don't want the missions to think we are landed. */ if (menu_isOpen(MENU_MAIN)) return; player_addEscorts(); hooks_run("enter"); if (menu_isOpen(MENU_MAIN)) return; events_trigger( EVENT_TRIGGER_ENTER ); if (menu_isOpen(MENU_MAIN)) return; player.p->ptimer = PILOT_TAKEOFF_DELAY; pilot_setFlag( player.p, PILOT_TAKEOFF ); pilot_setThrust( player.p, 0. ); pilot_setTurn( player.p, 0. ); }
inline int Agent::terminal_eval(char color, int depth, int alpha, int beta) { save_all(depth); if(best_move[depth]){ board->put(best_move[depth], color); if(!end_game) cost->update(); value[depth] = eval->value(); recover_all(depth); if( color == role){ if( value[depth] > alpha){ if( (alpha = value[depth]) >= beta){ return alpha; } } result[depth] = value[depth]; } else{ if( value[depth] < beta){ if( (beta = value[depth]) <= alpha){ return beta; } } result[depth] = value[depth]; } } else{ result[depth] = (color == role)? -MAX_INT: MAX_INT; } move_list_len[depth] = history->move_list_len(color, step+depth); for(register int i = 1; i <= move_list_len[depth]; ++i){ cur_move[depth] = history->move(color, step+depth, i); if( !board->can_put(cur_move[depth], color) || cur_move[depth] == temp_move[depth]) continue; board->put(cur_move[depth], color); if(!end_game) cost->update(); value[depth] = eval->value(); recover_all(depth); if( color == role){ if( value[depth] > alpha){ if( (alpha = value[depth]) >= beta){ history->advance_move(color, step+depth, i); hash->insert(alpha, color, H_LOW_BOUND, cur_move[depth], depth, step+depth); return alpha; } } if( value[depth] > result[depth]){ result[depth] = value[depth]; best_move[depth] = cur_move[depth]; } } else{ if( value[depth] < beta){ if( (beta = value[depth]) <= alpha){ history->advance_move(color, step+depth, i); hash->insert(beta, color, H_UP_BOUND, cur_move[depth], depth, step+depth); return beta; } } if( value[depth] < result[depth]){ result[depth] = value[depth]; best_move[depth] = cur_move[depth]; } } } hash->insert(result[depth], color, H_EXACT, best_move[depth], depth, step+depth); return result[depth]; }
void getKeyboardPress(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); case 'w': walk_up(); break; case 's': walk_down(); break; case 'a': //cout << "a"; walk_left(); break; case 'd': walk_right(); break; case 'q': turn_left(); break; case 'e': turn_right(); break; case 'f': if ((CreatFlower == false) && (CreatTree == false)) { Flower* tem = new Flower; int temx, temy, temz; get_Groung_position(mouse_x, mouse_y, temx, temy, temz); tem->setPosition(temx, temz); tem->setAlpha(0.35f); flower_display_list.push_back(tem); CreatFlower = true; } coutstat(); break; case 't': if ((CreatFlower == false) && (CreatTree == false)) { Tree* tem = new Tree; int temx, temy, temz; get_Groung_position(mouse_x, mouse_y, temx, temy, temz); tem->setPosition(temx, temz); tree_display_list.push_back(tem); CreatTree = true; } coutstat(); break; case 'z': save_all(); break; case 'l': load_all(); break; case 'r': if (CreatFlower == true) { flower_display_list[flower_display_list.size() - 1]->change_petal_R(0.1f); } coutstat(); break; case 'g': if (CreatFlower == true) { flower_display_list[flower_display_list.size() - 1]->change_petal_G(0.1f); } coutstat(); break; case 'b': if (CreatFlower == true) { flower_display_list[flower_display_list.size() - 1]->change_petal_B(0.1f); } coutstat(); break; case 'n': if (CreatFlower == true) { flower_display_list[flower_display_list.size() - 1]->change_petal_NUM(1); } if (CreatTree == true) { tree_display_list[tree_display_list.size() - 1]->change_tree_level(1); } coutstat(); break; case 'm': if (CreatFlower == true) { flower_display_list[flower_display_list.size() - 1]->change_petal_NUM(-1); } if (CreatTree == true) { tree_display_list[tree_display_list.size() - 1]->change_tree_level(-1); } coutstat(); break; case 'p': is_snow = 1 - is_snow; snowcount = 0; coutstat(); break; case 'o': if (have_wind) stop_wind(); else start_wind(); coutstat(); break; case 'i': snow_down(); break; case 'j': change_snow_level(-5); coutstat(); break; case 'k': change_snow_level(5); coutstat(); break; } }
void menu_items_treatment (GtkWidget *Widget, guint Op) { gint CurrentPage, i; CurrentPage = gtk_notebook_get_current_page (GTK_NOTEBOOK(MainNotebook)); switch(Op) { case NEW : new_file (); break; case OPEN : open_file (); break; case SAVE : save_file (); break; case SAVE_ALL : save_all (); break; case SAVE_AS : save_file_as (); break; case PRINT : print_buffer (); break; case CLOSE : close_file (); break; case CLOSE_ALL : close_all (); break; case QUIT : quit (); break; case UNDO : if (OpenedFilesCnt) { proceed_undo (); break; } case REDO : if (OpenedFilesCnt) { proceed_redo (); break; } case CUT : if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly)) { gtk_editable_cut_clipboard (GTK_EDITABLE(FPROPS(CurrentPage, Text))); print_msg ("Selection cut to Clipboard..."); } break; case COPY : if (OpenedFilesCnt) { gtk_editable_copy_clipboard (GTK_EDITABLE(FPROPS(CurrentPage, Text))); print_msg ("Selection copied to Clipboard..."); } break; case PASTE : if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly)) { gtk_editable_paste_clipboard (GTK_EDITABLE(FPROPS(CurrentPage, Text))); print_msg ("Text pasted from Clipboard..."); } break; case CLEAR : if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly)) { gtk_editable_delete_text (GTK_EDITABLE(FPROPS(CurrentPage, Text)), 0, -1); print_msg ("Buffer cleared..."); } break; case SELECT_ALL : if (OpenedFilesCnt) { gtk_editable_select_region (GTK_EDITABLE(FPROPS(CurrentPage, Text)), 0, -1); print_msg ("All Text selected..."); } break; case COMPLETE : if (OpenedFilesCnt) auto_completion (GTK_TEXT(FPROPS(CurrentPage, Text))); break; case FIND : if (OpenedFilesCnt) search (FALSE); break; case REPLACE : if (OpenedFilesCnt) search (TRUE); break; case LINE : if (OpenedFilesCnt) goto_line (); break; case READONLY : toggle_readonly (); break; case CONVERTER : converter (); break; case COLOR : color_picker (); break; case INSERT_TIME : insert_time (CurrentPage); break; case TO_UPPER : if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly)) { change_case (1); print_msg ("Selection converted to upper Case..."); } break; case TO_LOWER : if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly)) { change_case (2); print_msg ("Selection converted to Lower Case..."); } break; case CAPITALIZE : if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly)) { change_case (3); print_msg ("Selection Capitalized..."); } break; case INVERT_CASE : if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly)) { change_case (4); print_msg ("Case inverted..."); } break; case UNIX_DOS : if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly)) { conv_unix_to_dos (); } break; case UNIX_MAC : if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly)) { conv_unix_to_mac (); } break; case DOS_UNIX : if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly)) { conv_dos_to_unix (); } break; case DOS_MAC : if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly)) { conv_dos_to_mac (); } break; case MAC_DOS : if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly)) { conv_mac_to_dos (); } break; case MAC_UNIX : if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly)) { conv_mac_to_unix (); } break; case UNIX_DOS_ALL : convert_all(conv_unix_to_dos); break; case UNIX_MAC_ALL : convert_all(conv_unix_to_mac); break; case DOS_UNIX_ALL : convert_all(conv_dos_to_unix); break; case DOS_MAC_ALL : convert_all(conv_dos_to_mac); break; case MAC_DOS_ALL : convert_all(conv_mac_to_dos); break; case MAC_UNIX_ALL : convert_all(conv_mac_to_unix); break; case FILE_INFO : file_info (CurrentPage); break; case TOOLBAR : if ((!ToolBarToggleDisplay) && (TOOLBAR_DISPLAY)) ToolBarToggleDisplay = TRUE; else { if (TOOLBAR_DISPLAY) { TOOLBAR_DISPLAY = FALSE; hide_toolbar (); print_msg ("Hide Tool Bar..."); } else { TOOLBAR_DISPLAY = TRUE; show_toolbar (); if (!ToolBarToggleDisplay) ToolBarToggleDisplay = TRUE; print_msg ("Display Tool Bar..."); } } break; case MSGBAR : if ((!MsgBarToggleDisplay) && (MSGBAR_DISPLAY)) MsgBarToggleDisplay = TRUE; else { if (MSGBAR_DISPLAY) { MSGBAR_DISPLAY = FALSE; hide_msgbar (); } else { MSGBAR_DISPLAY = TRUE; show_msgbar (); if (!MsgBarToggleDisplay) MsgBarToggleDisplay = TRUE; print_msg ("Display Msg Bar..."); } } break; case WORDWRAP : if ((!ToggleWordwrap) && (TOGGLE_WORDWRAP)) ToggleWordwrap = TRUE; else { if (TOGGLE_WORDWRAP) { TOGGLE_WORDWRAP = FALSE; for (i = 0; i < OpenedFilesCnt; i++) gtk_text_set_word_wrap (GTK_TEXT(FPROPS(CurrentPage, Text)), FALSE); print_msg ("Wordwrap disabled..."); } else { TOGGLE_WORDWRAP = TRUE; for (i = 0; i < OpenedFilesCnt; i++) gtk_text_set_word_wrap (GTK_TEXT(FPROPS(CurrentPage, Text)), TRUE); if (!ToggleWordwrap) ToggleWordwrap = TRUE; print_msg ("Wordwrap enabled..."); } } break; case TAB_POS_TOP : TAB_POSITION = 1; gtk_notebook_set_tab_pos (GTK_NOTEBOOK(MainNotebook), GTK_POS_TOP); break; case TAB_POS_BOTTOM : TAB_POSITION = 2; gtk_notebook_set_tab_pos (GTK_NOTEBOOK(MainNotebook), GTK_POS_BOTTOM); break; case TAB_POS_LEFT : TAB_POSITION = 3; gtk_notebook_set_tab_pos (GTK_NOTEBOOK(MainNotebook), GTK_POS_LEFT); break; case TAB_POS_RIGHT : TAB_POSITION = 4; gtk_notebook_set_tab_pos (GTK_NOTEBOOK(MainNotebook), GTK_POS_RIGHT); break; case SCROLLBAR_POS_LEFT : SCROLLBAR_POSITION = 1; for (i = 0; i < OpenedFilesCnt; i++) gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW (gtk_notebook_get_nth_page (GTK_NOTEBOOK(MainNotebook), i)), GTK_CORNER_TOP_RIGHT); break; case SCROLLBAR_POS_RIGHT : SCROLLBAR_POSITION = 2; for (i = 0; i < OpenedFilesCnt; i++) gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW (gtk_notebook_get_nth_page (GTK_NOTEBOOK(MainNotebook), i)), GTK_CORNER_TOP_LEFT); break; case PREFS : display_prefs (&Settings); break; case HELP : print_msg ("No help available yet..."); break; case ABOUT : about (); break; } (void)Widget; /* avoid the "unused parameter" warning */ }