int save_local_data(char * text, int len){ save_bin_cfg(); //Save the quickbar spells save_quickspells(); //Save recipes save_recipes(); // save el.ini if asked if (write_ini_on_exit) write_el_ini (); // save notepad contents if the file was loaded if (notepad_loaded) notepad_save_file(); save_exploration_map(); flush_counters(); // for the new questlog, this actually just saves any pending changes // should be renamed when NEW_QUESTLOG #def is removed unload_questlog(); save_item_lists(); LOG_TO_CONSOLE(c_green1, "Local files saved, asking server to save too..."); return 0; }
int start_rendering() { static int done = 0; static void * network_thread_data[2] = { NULL, NULL }; static Uint32 last_frame_and_command_update = 0; SDL_Thread *network_thread; queue_t *message_queue; #ifndef WINDOWS SDL_EventState(SDL_SYSWMEVENT,SDL_ENABLE); #endif queue_initialise(&message_queue); network_thread_data[0] = message_queue; network_thread_data[1] = &done; network_thread = SDL_CreateThread(get_message_from_server, network_thread_data); /* Loop until done. */ while( !done ) { SDL_Event event; // handle SDL events in_main_event_loop = 1; while( SDL_PollEvent( &event ) ) { done = HandleEvent(&event); } in_main_event_loop = 0; //advance the clock cur_time = SDL_GetTicks(); //check for network data if(!queue_isempty(message_queue)) { message_t *message; while((message = queue_pop(message_queue)) != NULL) { process_message_from_server(message->data, message->length); free(message->data); free(message); } } #ifdef OLC olc_process(); #endif //OLC my_tcp_flush(my_socket); // make sure the tcp output buffer is set if (have_a_map && cur_time > last_frame_and_command_update + 60) { LOCK_ACTORS_LISTS(); next_command(); UNLOCK_ACTORS_LISTS(); move_to_next_frame(); last_frame_and_command_update = cur_time; } while (cur_time > next_second_time && real_game_second < 59) { real_game_second += 1; new_second(); next_second_time += 1000; } #ifdef NEW_SOUND weather_sound_control(); #endif //NEW_SOUND if(!limit_fps || (cur_time-last_time && 1000/(cur_time-last_time) <= limit_fps)) { weather_update(); animate_actors(); //draw everything draw_scene(); last_time=cur_time; } else { SDL_Delay(1);//give up timeslice for anyone else } #ifdef TIMER_CHECK //Check the timers to make sure that they are all still alive... check_timers(); #endif //cache handling if(cache_system)cache_system_maint(); //see if we need to exit if(exit_now) { done = 1; break; } } if(!done) { done = 1; } LOG_INFO("Client closed"); SDL_WaitThread(network_thread,&done); queue_destroy(message_queue); if(pm_log.ppl)free_pm_log(); //save all local data save_local_data(NULL, 0); #ifdef PAWN cleanup_pawn (); #endif #ifdef NEW_SOUND destroy_sound(); // Cleans up physical elements of the sound system and the streams thread clear_sound_data(); // Cleans up the config data #endif // NEW_SOUND ec_destroy_all_effects(); if (have_a_map) { destroy_map(); free_buffers(); } unload_questlog(); save_item_lists(); free_emotes(); free_actor_defs(); free_books(); free_vars(); cleanup_rules(); save_exploration_map(); cleanup_counters(); cleanup_chan_names(); cleanup_hud(); SDL_RemoveTimer(draw_scene_timer); SDL_RemoveTimer(misc_timer); end_particles (); free_bbox_tree(main_bbox_tree); main_bbox_tree = NULL; free_astro_buffer(); free_translations(); free_skybox(); /* Destroy our GL context, etc. */ SDL_QuitSubSystem(SDL_INIT_AUDIO); SDL_QuitSubSystem(SDL_INIT_TIMER); /*#ifdef WINDOWS // attempt to restart if requested if(restart_required > 0){ LOG_INFO("Restarting %s", win_command_line); SDL_CreateThread(system, win_command_line); } #endif //WINDOWS */ #ifdef NEW_SOUND final_sound_exit(); #endif #ifdef CUSTOM_UPDATE stopp_custom_update(); #endif /* CUSTOM_UPDATE */ clear_zip_archives(); destroy_tcp_out_mutex(); if (use_frame_buffer) free_reflection_framebuffer(); printf("doing SDL_Quit\n"); fflush(stderr); SDL_Quit( ); printf("done SDL_Quit\n"); fflush(stderr); cleanup_mem(); xmlCleanupParser(); FreeXML(); exit_logging(); return(0); }