当前位置: 首页>>代码示例>>C++>>正文


C++ OpenedFile::GetLength方法代码示例

本文整理汇总了C++中OpenedFile::GetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ OpenedFile::GetLength方法的具体用法?C++ OpenedFile::GetLength怎么用?C++ OpenedFile::GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenedFile的用法示例。


在下文中一共展示了OpenedFile::GetLength方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: stop_recording

void stop_recording(
	void)
{
	if (replay.game_is_being_recorded)
	{
		replay.game_is_being_recorded = false;
		
		short player_index;
		int32 total_length;

		assert(replay.valid);
		for (player_index= 0; player_index<dynamic_world->player_count; player_index++)
		{
			save_recording_queue_chunk(player_index);
		}

		/* Rewrite the header, since it has the new length */
		FilmFile.SetPosition(0);
		byte Header[SIZEOF_recording_header];
		pack_recording_header(Header,&replay.header,1);

		// ZZZ: removing code that does stuff from assert() argument.  BUT...
		// should we really be asserting on this anyway?  I mean, the write could fail
		// in 'normal operation' too, not just when we screwed something up in writing the program?
		bool successfulWrite = FilmFile.Write(SIZEOF_recording_header,Header);
		assert(successfulWrite);
		
		FilmFile.GetLength(total_length);
		assert(total_length==replay.header.length);
		
		FilmFile.Close();
	}

	replay.valid= false;
}
开发者ID:MaddTheSane,项目名称:alephone,代码行数:35,代码来源:vbl.cpp

示例2: header_stream

static void import_m1_physics_data()
{
	OpenedFile PhysicsFile;
	if (!PhysicsFileSpec.Open(PhysicsFile)) 
	{
		return;
	}

	int32 position  = 0;
	int32 length;
	PhysicsFile.GetLength(length);

	while (position < length)
	{
		std::vector<uint8> header(12);
		PhysicsFile.Read(header.size(), &header[0]);
		AIStreamBE header_stream(&header[0], header.size());

		uint32 tag;
		uint16 count;
		uint16 size;

		header_stream >> tag;
		header_stream.ignore(4); // unused
		header_stream >> count;
		header_stream >> size;

		std::vector<uint8> data(count * size);
		PhysicsFile.Read(data.size(), &data[0]);
		switch (tag) 
		{
		case M1_MONSTER_PHYSICS_TAG:
			unpack_m1_monster_definition(&data[0], count);
			break;
		case M1_EFFECTS_PHYSICS_TAG:
			unpack_m1_effect_definition(&data[0], count);
			break;
		case M1_PROJECTILE_PHYSICS_TAG:
			unpack_m1_projectile_definition(&data[0], count);
			break;
		case M1_PHYSICS_PHYSICS_TAG:
			unpack_m1_physics_constants(&data[0], count);
			break;
		case M1_WEAPONS_PHYSICS_TAG:
			unpack_m1_weapon_definition(&data[0], count);
			break;
		}

		PhysicsFile.GetPosition(position);
	}
}
开发者ID:pfhore-github,项目名称:alephone_jp,代码行数:51,代码来源:import_definitions.cpp

示例3:

void *get_network_physics_buffer(
	int32 *physics_length)
{
	if (physics_file_is_m1())
	{
		bool success = false;
		uint8 *data = NULL;
		OpenedFile PhysicsFile;
		if (PhysicsFileSpec.Open(PhysicsFile) &&
		    PhysicsFile.GetLength(*physics_length))
		{
			data = (uint8 *)malloc(*physics_length + 4);
            SDL_RWops *ops = SDL_RWFromMem(data, *physics_length + 4);
            success = SDL_WriteBE32(ops, uint32(M1_PHYSICS_MAGIC_COOKIE));
            if (success)
                success = SDL_WriteBE32(ops, uint32(*physics_length));
            SDL_RWclose(ops);
            if (success)
                success = PhysicsFile.Read(*physics_length, &data[8]);
			if (!success)
				free(data);
		}
		if (!success)
		{
			*physics_length = 0;
			return NULL;
		}
		return data;
	}
	
	short SavedType, SavedError = get_game_error(&SavedType);
	void *data= get_flat_data(PhysicsFileSpec, false, 0);
	set_game_error(SavedType, SavedError);
	
	if(data)
	{
		*physics_length= get_flat_data_length(data);
	} else {
		*physics_length= 0;
	}
	
	return data;
}
开发者ID:pfhore-github,项目名称:alephone_jp,代码行数:43,代码来源:import_definitions.cpp

示例4: image_to_new_name

std::string WadImageCache::image_to_new_name(SDL_Surface *image, int32 *filesize) const
{
	// create name
	boost::uuids::random_generator gen;
	boost::uuids::uuid u = gen();
	std::string ustr = boost::uuids::to_string(u);
	
	FileSpecifier File;
	File.SetToImageCacheDir();
	File.AddPart(ustr);
	
	FileSpecifier TempFile;
	TempFile.SetTempName(File);
	
	int ret;
//#if defined(HAVE_PNG) && defined(HAVE_SDL_IMAGE)
//	ret = aoIMG_SavePNG(TempFile.GetPath(), image, IMG_COMPRESS_DEFAULT, NULL, 0);
#ifdef HAVE_SDL_IMAGE
	ret = IMG_SavePNG(image, TempFile.GetPath());
#else
	ret = SDL_SaveBMP(image, TempFile.GetPath());
#endif
	if (ret == 0 && TempFile.Rename(File))
	{
		if (filesize)
		{
			OpenedFile of;
			if (File.Open(of))
				of.GetLength(*filesize);
		}
		return ustr;
	}
	
	if (filesize)
		*filesize = 0;
	return "";
}
开发者ID:blezek,项目名称:marathon-ios,代码行数:37,代码来源:WadImageCache.cpp

示例5: GetType

// Determine file type
Typecode FileSpecifier::GetType()
{

	// if there's an extension, assume it's correct
	const char *extension = strrchr(GetPath(), '.');
	if (extension) {
		extension_mapping *mapping = extensions;
		while (mapping->extension)
		{ 
			if (( mapping->case_sensitive && (strcmp(extension + 1, mapping->extension) == 0)) ||
			    (!mapping->case_sensitive && (strcasecmp(extension + 1, mapping->extension) == 0)))
			{
				return mapping->typecode;
			}
			++mapping;
		}
	}

	// Open file
	OpenedFile f;
	if (!Open(f))
		return _typecode_unknown;
	SDL_RWops *p = f.GetRWops();
	int32 file_length = 0;
	f.GetLength(file_length);

	// Check for Sounds file
	{
		f.SetPosition(0);
		uint32 version = SDL_ReadBE32(p);
		uint32 tag = SDL_ReadBE32(p);
		if ((version == 0 || version == 1) && tag == FOUR_CHARS_TO_INT('s', 'n', 'd', '2'))
			return _typecode_sounds;
	}

	// Check for Map/Physics file
	{
		f.SetPosition(0);
		int version = SDL_ReadBE16(p);
		int data_version = SDL_ReadBE16(p);
		if ((version == 0 || version == 1 || version == 2 || version == 4) && (data_version == 0 || data_version == 1 || data_version == 2)) {
			SDL_RWseek(p, 68, SEEK_CUR);
			int32 directory_offset = SDL_ReadBE32(p);
			if (directory_offset >= file_length)
				goto not_map;
			f.SetPosition(128);
			uint32 tag = SDL_ReadBE32(p);
			// ghs: I do not believe this list is comprehensive
			//      I think it's just what we've seen so far?
			switch (tag) {
			case LINE_TAG:
			case POINT_TAG:
			case SIDE_TAG:
				return _typecode_scenario;
				break;
			case MONSTER_PHYSICS_TAG:
				return _typecode_physics;
				break;
			}
				
		}
not_map: ;
	}

	// Check for Shapes file
	{
		f.SetPosition(0);
		for (int i=0; i<32; i++) {
			uint32 status_flags = SDL_ReadBE32(p);
			int32 offset = SDL_ReadBE32(p);
			int32 length = SDL_ReadBE32(p);
			int32 offset16 = SDL_ReadBE32(p);
			int32 length16 = SDL_ReadBE32(p);
			if (status_flags != 0
			 || (offset != NONE && (offset >= file_length || offset + length > file_length))
			 || (offset16 != NONE && (offset16 >= file_length || offset16 + length16 > file_length)))
				goto not_shapes;
			SDL_RWseek(p, 12, SEEK_CUR);
		}
		return _typecode_shapes;
not_shapes: ;
	}

	// Not identified
	return _typecode_unknown;
}
开发者ID:logue,项目名称:alephone_jp,代码行数:87,代码来源:FileHandler.cpp

示例6: vblFSRead

/* This is gross, (Alain wrote it, not me!) but I don't have time to clean it up */
static bool vblFSRead(
	OpenedFile& File,
	int32 *count, 
	void *dest,
	bool& HitEOF)
{
	int32 fsread_count;
	bool status = true;
	
	assert(replay.fsread_buffer);
	
	// LP: way for testing whether hitting end-of-file;
	// doing that by testing for whether a read was complete.
	HitEOF = false;

	if (replay.bytes_in_cache < *count)
	{
		assert(replay.bytes_in_cache + *count < int(DISK_CACHE_SIZE));
		if (replay.bytes_in_cache)
		{
			memcpy(replay.fsread_buffer, replay.location_in_cache, replay.bytes_in_cache);
		}
		replay.location_in_cache = replay.fsread_buffer;
		fsread_count= DISK_CACHE_SIZE - replay.bytes_in_cache;
		int32 PrevPos;
		File.GetPosition(PrevPos);
		int32 replay_left= replay.header.length - PrevPos;
		if(replay_left < fsread_count)
			fsread_count= replay_left;
		if(fsread_count > 0)
		{
			assert(fsread_count > 0);
			// LP: wrapped the routines with some for finding out the file positions;
			// this finds out how much is read indirectly
			status = File.Read(fsread_count,replay.fsread_buffer+replay.bytes_in_cache);
			int32 CurrPos;
			File.GetPosition(CurrPos);
			int32 new_fsread_count = CurrPos - PrevPos;
			int32 FileLen;
			File.GetLength(FileLen);
			HitEOF = (new_fsread_count < fsread_count) && (CurrPos == FileLen);
			fsread_count = new_fsread_count;
			if(status) replay.bytes_in_cache += fsread_count;
		}
	}

	// If we're still low, then we've consumed the disk cache
	if(replay.bytes_in_cache < *count)
	{
		HitEOF = true;
	}

	// Ignore EOF if we still have cache
	if (HitEOF && replay.bytes_in_cache < *count)
	{
		*count= replay.bytes_in_cache;
	}
	else
	{
		status = true;
		HitEOF = false;
	}
	
	memcpy(dest, replay.location_in_cache, *count);
	replay.bytes_in_cache -= *count;
	replay.location_in_cache += *count;
	
	return status;
}
开发者ID:MaddTheSane,项目名称:alephone,代码行数:70,代码来源:vbl.cpp


注:本文中的OpenedFile::GetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。