Ejemplo n.º 1
0
Archivo: file.c Proyecto: prophile/dim3
bool game_file_load(char *file_name,char *err_str)
{
	char				*c,path[1024],fname[256];
	file_save_header	head;
	
		// load and expand
		
	strcpy(fname,file_name);
	c=strrchr(fname,'.');
	if (c!=NULL) *c=0x0;			// remove any extensions
	
	file_paths_documents(&setup.file_path_setup,path,"Saved Games",fname,"sav");
	if (!game_file_expand_load(path,err_str)) return(FALSE);
	
	game_file_pos=0;

	progress_initialize("Loading");

		// if game isn't running, then start
		
	if (!server.game_open) {
		if (!game_start(skill_medium,NULL,err_str)) {
			free(game_file_data);
			return(FALSE);
		}
	}

		// get header

	game_file_get_chunk(&head);

		// check version
		
	if (strcmp(head.version,dim3_version)!=0) {
		sprintf(err_str,"This saved game file is from a different version of dim3");
		free(game_file_data);
		return(FALSE);
	}
		
		// reload map

	progress_draw(10);
	
	if ((!server.map_open) || (strcmp(head.map_name,map.info.name)!=0)) {		// need to load a map?
	
		if (server.map_open) map_end();
		
		strcpy(map.info.name,head.map_name);
		map.info.player_start_name[0]=0x0;
		map.info.player_start_type[0]=0x0;
		map.info.in_load=TRUE;

		if (!map_start(TRUE,err_str)) {
			free(game_file_data);
			return(FALSE);
		}
	}
	
		// timing
		
	game_time_set(head.tick);

		// view and server objects
		
	progress_draw(20);
					
	game_file_get_chunk(&view.time);
	game_file_get_chunk(&view.fps);
	game_file_get_chunk(&camera);
	
	game_file_get_chunk(&server.time);
	game_file_get_chunk(&server.player_obj_uid);
	game_file_get_chunk(&server.skill);
	
	game_file_get_chunk(&server.uid);
	game_file_get_chunk(&server.count);
	
	progress_draw(30);

	free(server.objs);
	free(server.weapons);
	free(server.proj_setups);

	server.objs=(obj_type*)game_file_replace_chunk();
	server.weapons=(weapon_type*)game_file_replace_chunk();
	server.proj_setups=(proj_setup_type*)game_file_replace_chunk();

	if ((server.objs==NULL) || (server.weapons==NULL) || (server.proj_setups==NULL)) {
		free(game_file_data);
		return(FALSE);
	}
	
	progress_draw(40);

	game_file_get_chunk(server.projs);
	game_file_get_chunk(server.effects);
	game_file_get_chunk(server.decals);

	progress_draw(50);

	game_file_get_chunk(hud.bitmaps);
	game_file_get_chunk(hud.texts);
	game_file_get_chunk(hud.bars);
	game_file_get_chunk(&hud.radar);
	
		// map changes
		
	progress_draw(60);

	game_file_get_chunk(&map.ambient);					
	game_file_get_chunk(&map.rain);					
	game_file_get_chunk(&map.background);					
	game_file_get_chunk(&map.sky);
	game_file_get_chunk(&map.fog);

	progress_draw(70);
	
	map_group_dispose_unit_list(&map);			// need to destroy and rebuild unit lists
	game_file_get_chunk(map.groups);
	map_group_create_unit_list(&map);

	game_file_get_chunk(map.movements);

	group_moves_synch_with_load();
	
		// script objects
		
	progress_draw(80);

	game_file_get_chunk(&js.script_current_uid);
	game_file_get_chunk(&js.count);
	game_file_get_chunk(&js.time);
	
	game_file_get_chunk(js.timers);
	game_file_get_chunk(js.globals);

		// reset model UIDs

	progress_draw(90);

	models_reset_uid();
	
		// send scripts load event
		// to restore globals
		
	progress_draw(95);
	
	script_state_load();

		// free game data
		
	progress_draw(100);
	free(game_file_data);
	
		// finished

	progress_shutdown();

		// fix some necessary functions

	map.rain.reset=TRUE;
	fade_screen_cancel();
		
		 // return to old game time

	game_time_reset();
  
    return(TRUE);
}
Ejemplo n.º 2
0
status_t
shutdown_media_server(bigtime_t timeout,
	bool (*progress)(int stage, const char* message, void* cookie),
	void* cookie)
{
	BMessage msg(B_QUIT_REQUESTED);
	status_t err = B_MEDIA_SYSTEM_FAILURE;
	bool shutdown = false;

	BMediaRoster* roster = BMediaRoster::Roster(&err);
	if (roster == NULL || err != B_OK)
		return err;

	if (progress == NULL && roster->Lock()) {
		MediaRosterEx(roster)->EnableLaunchNotification(true, true);
		roster->Unlock();
	}

	if ((err = msg.AddBool("be:_user_request", true)) != B_OK)
		return err;

	team_id mediaServer = be_roster->TeamFor(B_MEDIA_SERVER_SIGNATURE);
	team_id addOnServer = be_roster->TeamFor(B_MEDIA_ADDON_SERVER_SIGNATURE);

	if (mediaServer != B_ERROR) {
		BMessage reply;
		BMessenger messenger(B_MEDIA_SERVER_SIGNATURE, mediaServer);
		progress_shutdown(10, progress, cookie);

		err = messenger.SendMessage(&msg, &reply, 2000000, 2000000);
		reply.FindBool("_shutdown", &shutdown);
		if (err == B_TIMED_OUT || shutdown == false) {
			if (messenger.IsValid())
				kill_team(mediaServer);
		} else if (err != B_OK)
			return err;

		progress_shutdown(20, progress, cookie);

		int32 rv;
		if (reply.FindInt32("error", &rv) == B_OK && rv != B_OK)
			return rv;
	}

	if (addOnServer != B_ERROR) {
		shutdown = false;
		BMessage reply;
		BMessenger messenger(B_MEDIA_ADDON_SERVER_SIGNATURE, addOnServer);
		progress_shutdown(40, progress, cookie);

		// The media_server usually shutdown the media_addon_server,
		// if not let's do something.
		if (messenger.IsValid()) {
			err = messenger.SendMessage(&msg, &reply, 2000000, 2000000);
			reply.FindBool("_shutdown", &shutdown);
			if (err == B_TIMED_OUT || shutdown == false) {
				if (messenger.IsValid())
					kill_team(addOnServer);
			} else if (err != B_OK)
				return err;

			progress_shutdown(50, progress, cookie);

			int32 rv;
			if (reply.FindInt32("error", &rv) == B_OK && rv != B_OK)
				return rv;
		}
	}

	progress_shutdown(100, progress, cookie);
	return B_OK;
}
Ejemplo n.º 3
0
Archivo: file.c Proyecto: prophile/dim3
bool game_file_save(char *err_str)
{
	int					tick;
	char				path[1024],file_name[256];
	bool				ok;
	file_save_header	head;
	
	progress_initialize("Saving");
	progress_draw(5);
	
		// get saved data file names
		
	tick=game_time_get();

	game_file_create_name(tick,file_name);
	
		// save screen
		
	file_paths_documents(&setup.file_path_setup,path,"Saved Games",file_name,"png");
	view_capture_draw(path);
	
		// start chunks
		
	game_file_sz=0;
	game_file_data=malloc(32);

		// header

	head.tick=tick;
	strcpy(head.version,dim3_version);
	strcpy(head.map_name,map.info.name);
		
	game_file_add_chunk(&head,1,sizeof(file_save_header));
	
		// send scripts save event
		// to backup globals
		
	progress_draw(10);
	
	script_state_save();
	
		// view & server objects
		
	progress_draw(20);
		
	game_file_add_chunk(&view.time,1,sizeof(view_time_type));
	game_file_add_chunk(&view.fps,1,sizeof(view_fps_type));
	game_file_add_chunk(&camera,1,sizeof(camera_type));
	
	game_file_add_chunk(&server.time,1,sizeof(server_time_type));
	game_file_add_chunk(&server.player_obj_uid,1,sizeof(int));
	game_file_add_chunk(&server.skill,1,sizeof(int));
	
	game_file_add_chunk(&server.uid,1,sizeof(server_uid_type));
	game_file_add_chunk(&server.count,1,sizeof(server_count_type));
	
	progress_draw(30);

	game_file_add_chunk(server.objs,server.count.obj,sizeof(obj_type));
	game_file_add_chunk(server.weapons,server.count.weapon,sizeof(weapon_type));
	game_file_add_chunk(server.proj_setups,server.count.proj_setup,sizeof(proj_setup_type));
	
	progress_draw(40);
	
	game_file_add_chunk(server.projs,server.count.proj,sizeof(proj_type));
	game_file_add_chunk(server.effects,server.count.effect,sizeof(effect_type));
	game_file_add_chunk(server.decals,server.count.decal,sizeof(decal_type));
	
	progress_draw(50);
	
	game_file_add_chunk(hud.bitmaps,hud.count.bitmap,sizeof(hud_bitmap_type));
	game_file_add_chunk(hud.texts,hud.count.text,sizeof(hud_text_type));
	game_file_add_chunk(hud.bars,hud.count.bar,sizeof(hud_bar_type));
	game_file_add_chunk(&hud.radar,1,sizeof(hud_radar_type));
	
		// map changes
		
	progress_draw(60);

	game_file_add_chunk(&map.ambient,1,sizeof(map_ambient_type));					
	game_file_add_chunk(&map.rain,1,sizeof(map_rain_type));					
	game_file_add_chunk(&map.background,1,sizeof(map_background_type));					
	game_file_add_chunk(&map.sky,1,sizeof(map_sky_type));
	game_file_add_chunk(&map.fog,1,sizeof(map_fog_type));

	progress_draw(70);

	game_file_add_chunk(map.groups,1,sizeof(group_type)*map.ngroup);
	game_file_add_chunk(map.movements,1,sizeof(movement_type)*map.nmovement);
	
		// script objects
		
	progress_draw(80);
	
	game_file_add_chunk(&js.script_current_uid,1,sizeof(int));
	game_file_add_chunk(&js.count,1,sizeof(script_count_type));
	game_file_add_chunk(&js.time,1,sizeof(script_time_type));
		
	game_file_add_chunk(js.timers,js.count.timer,sizeof(timer_type));
	game_file_add_chunk(js.globals,js.count.global,sizeof(global_type));

		// compress and save
		
	progress_draw(90);
		
	file_paths_documents(&setup.file_path_setup,path,"Saved Games",file_name,"sav");
	ok=game_file_compress_save(path,err_str);
	
	progress_draw(100);
	
	free(game_file_data);
	
		// remember last map
		
	strcpy(game_file_last_save_name,strrchr(path,'/'));
	
		// finished
		
	progress_shutdown();
    
    return(ok);
}