void cleanup_mem(void) { int i; destroy_url_list(); history_destroy(); command_cleanup(); queue_destroy(buddy_request_queue); cleanup_manufacture(); cleanup_text_buffers(); cleanup_fonts(); cursors_cleanup(); destroy_all_actors(); end_actors_lists(); cleanup_lights(); /* 2d objects */ destroy_all_2d_objects(); /* 3d objects */ destroy_all_3d_objects(); /* caches */ cache_e3d->free_item = &destroy_e3d; cache_delete(cache_e3d); cache_e3d = NULL; free_texture_cache(); // This should be fixed now Sir_Odie cache_delete(cache_system); cache_system = NULL; /* map location information */ for (i = 0; continent_maps[i].name; i++) { free(continent_maps[i].name); } free (continent_maps); destroy_hash_table(server_marks); for (i = 0; i < video_modes_count; i++) { if (video_modes[i].name) free(video_modes[i].name); } free_shaders(); }
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) { #ifdef OTHER_LIFE handle_extended_protocol_message(message->data, message->length); #else process_message_from_server(message->data, message->length); #endif 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(); destroy_all_root_windows(); 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(); clean_update(); cleanup_tcp(); if (use_frame_buffer) free_reflection_framebuffer(); cursors_cleanup(); printf("doing SDL_Quit\n"); fflush(stderr); SDL_Quit( ); printf("done SDL_Quit\n"); fflush(stderr); cleanup_mem(); xmlCleanupParser(); FreeXML(); exit_logging(); return(0); }