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


C++ PHYSFS_seek函数代码示例

本文整理汇总了C++中PHYSFS_seek函数的典型用法代码示例。如果您正苦于以下问题:C++ PHYSFS_seek函数的具体用法?C++ PHYSFS_seek怎么用?C++ PHYSFS_seek使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: switch

int OSBasics::seek(OSFILE * stream, long int offset, int origin ) {
	switch(stream->fileType) {
		case OSFILE::TYPE_FILE:
			return fseek(stream->file, offset, origin);
			break;
		case OSFILE::TYPE_ARCHIVE_FILE:
			switch(origin) {
				case SEEK_SET:
					return PHYSFS_seek(stream->physFSFile, offset);
				break;
				case SEEK_CUR: {
					PHYSFS_sint64 curoffset = PHYSFS_tell(stream->physFSFile);					
					return PHYSFS_seek(stream->physFSFile, curoffset+offset);				
				}
				break;
				case SEEK_END: {
					PHYSFS_sint64 fileLength =  PHYSFS_fileLength(stream->physFSFile);
					return PHYSFS_seek(stream->physFSFile, fileLength-offset);
				}
				break;
			}
			break;			
	}
	return 0;	
}
开发者ID:RobLach,项目名称:Polycode,代码行数:25,代码来源:OSBasics.cpp

示例2: switch

int
OggSoundFile::cb_seek(void* source, ogg_int64_t offset, int whence)
{
  PHYSFS_file* file = reinterpret_cast<PHYSFS_file*> (source);

  switch(whence) {
    case SEEK_SET:
      if(PHYSFS_seek(file, static_cast<PHYSFS_uint64> (offset)) == 0)
        return -1;
      break;
    case SEEK_CUR:
      if(PHYSFS_seek(file, PHYSFS_tell(file) + offset) == 0)
        return -1;
      break;
    case SEEK_END:
      if(PHYSFS_seek(file, PHYSFS_fileLength(file) + offset) == 0)
        return -1;
      break;
    default:
#ifdef DEBUG
      assert(false);
#else
      return -1;
#endif
  }
  return 0;
}
开发者ID:slackstone,项目名称:tuxjunior,代码行数:27,代码来源:sound_file.cpp

示例3: funcSeek

static int funcSeek(struct SDL_RWops* context, int offset, int whence)
{
    PHYSFS_file* file = (PHYSFS_file*) context->hidden.unknown.data1;
    int res;
    switch(whence) {
        case SEEK_SET:
            res = PHYSFS_seek(file, offset);
            break;
        case SEEK_CUR:
            res = PHYSFS_seek(file, PHYSFS_tell(file) + offset);
            break;
        case SEEK_END:
            res = PHYSFS_seek(file, PHYSFS_fileLength(file) + offset);
            break;
        default:
            res = 0;
            assert(false);
            break;
    }
    if(res == 0) {
        std::cerr << "Error seeking in file: " << PHYSFS_getLastError() << "\n";
        return -1;
    }

    return (int) PHYSFS_tell(file);
}
开发者ID:BackupTheBerlios,项目名称:lincity-ng-svn,代码行数:26,代码来源:PhysfsSDL.cpp

示例4: state_get_game_id

int state_get_game_id(char *filename)
{
	int version;
	PHYSFS_file *fp;
	int between_levels;
	char mission[16];
	char desc[DESC_LENGTH+1];
	char id[5];
	int dumbint;

mprintf((0, "Restoring multigame from [%s]\n", filename));

	fp = PHYSFS_openRead(filename);
	if (!fp) return 0;

//Read id
	//FIXME: check for swapped file, react accordingly...
	PHYSFS_read(fp, id, sizeof(char) * 4, 1);
	if ( memcmp( id, dgss_id, 4 )) {
		PHYSFS_close(fp);
		return 0;
	}

//Read version
	PHYSFS_read(fp, &version, sizeof(int), 1);
	if (version < STATE_COMPATIBLE_VERSION)	{
		PHYSFS_close(fp);
		return 0;
	}

// Read description
	PHYSFS_read(fp, desc, sizeof(char) * DESC_LENGTH, 1);

// Skip the current screen shot...
	PHYSFS_seek(fp, PHYSFS_tell(fp) + THUMBNAIL_W * THUMBNAIL_H);

// And now...skip the palette stuff that somebody forgot to add
	PHYSFS_seek(fp, PHYSFS_tell(fp) + 768);

// Read the Between levels flag...
	PHYSFS_read(fp, &between_levels, sizeof(int), 1);

	Assert(between_levels == 0);	//between levels save ripped out

// Read the mission info...
	PHYSFS_read(fp, mission, sizeof(char) * 9, 1);
//Read level info
	PHYSFS_read(fp, &dumbint, sizeof(int), 1);
	PHYSFS_read(fp, &dumbint, sizeof(int), 1);

//Restore GameTime
	PHYSFS_read(fp, &dumbint, sizeof(fix), 1);

	PHYSFS_read(fp, &state_game_id, sizeof(int), 1);

	return (state_game_id);
 }
开发者ID:btb,项目名称:d2x,代码行数:57,代码来源:state.c

示例5: SDL_RWopsSeek

static Sint64 SDL_RWopsSeek(SDL_RWops *ops, int64_t offset, int whence)
{
	PHYSFS_File *f = sdlPHYS(ops);

	if (!f)
		return -1;

	int64_t base;

	switch (whence)
	{
	default:
	case RW_SEEK_SET :
		base = 0;
		break;
	case RW_SEEK_CUR :
		base = PHYSFS_tell(f);
		break;
	case RW_SEEK_END :
		base = PHYSFS_fileLength(f);
		break;
	}

	int result = PHYSFS_seek(f, base + offset);

	return (result != 0) ? PHYSFS_tell(f) : -1;
}
开发者ID:AlexandreSousa,项目名称:mkxp,代码行数:27,代码来源:filesystem.cpp

示例6: ReadWholeFile

void File::ReadWholeFile(std::vector<char>& bytes)
{
   if (PHYSFS_seek(impl->physfsFileHandle, 0) == 0)
   {
      throw Exception(std::string("Seek failed on file ") + mountedFilePath.path + "\n" + PHYSFS_getLastError());
   }

   int64_t fileSizeInBytes = SizeInBytes();

   if (fileSizeInBytes == -1)
   {
      throw Exception(std::string("File sizing failed on file") + mountedFilePath.path + "\n" + PHYSFS_getLastError());
   }

   std::size_t bytesToRead = static_cast<size_t>(fileSizeInBytes);

   std::size_t maxBytesToRead = std::numeric_limits<std::size_t>::max();

   if (static_cast<uint64_t>(fileSizeInBytes) > maxBytesToRead)
   {
      bytesToRead = maxBytesToRead;
   }

   bytes.resize(bytesToRead);

   int64_t bytesRead = Read(bytes.data(), bytesToRead);

   if (static_cast<uint64_t>(bytesRead) != bytesToRead)
   {
      throw Exception(std::string("Failed to read whole file") + mountedFilePath.path + "\n" + PHYSFS_getLastError());
   }
}
开发者ID:ShacharAvni,项目名称:Locus-Game-Engine,代码行数:32,代码来源:File.cpp

示例7: switch

bool File::Seek(std::size_t offset, DataStream::SeekType seekType)
{
   std::size_t seekPosition = 0;

   switch (seekType)
   {
   case SeekType::Beginning:
      seekPosition = offset;
      break;

   case SeekType::Current:
      seekPosition = CurrentPosition() + offset;
      break;

   case SeekType::End:
      {
         std::size_t sizeInBytes = SizeInBytes();

         if (offset > sizeInBytes)
         {
            return false;
         }
            
         seekPosition = (sizeInBytes - offset);
      }
      break;

   default:
      return false;
   }

   return (PHYSFS_seek(impl->physfsFileHandle, seekPosition) != 0);
}
开发者ID:ShacharAvni,项目名称:Locus-Game-Engine,代码行数:33,代码来源:File.cpp

示例8: load_sound_file

SoundFile* load_sound_file(const std::string& filename)
{
  if(filename.length() > 6
      && filename.compare(filename.length()-6, 6, ".music") == 0) {
    return load_music_file(filename);
  }

  PHYSFS_file* file = PHYSFS_openRead(filename.c_str());
  if(!file) {
    std::stringstream msg;
    msg << "Couldn't open '" << filename << "': " << PHYSFS_getLastError();
    throw std::runtime_error(msg.str());
  }

  try {
    char magic[4];
    if(PHYSFS_read(file, magic, sizeof(magic), 1) != 1)
      throw std::runtime_error("Couldn't read magic, file too short");
    PHYSFS_seek(file, 0);
    if(strncmp(magic, "RIFF", 4) == 0)
      return new WavSoundFile(file);
    else if(strncmp(magic, "OggS", 4) == 0)
      return new OggSoundFile(file, 0, -1);
    else
      throw std::runtime_error("Unknown file format");
  } catch(std::exception& e) {
    std::stringstream msg;
    msg << "Couldn't read '" << filename << "': " << e.what();
    throw std::runtime_error(msg.str());
  }
}
开发者ID:slackstone,项目名称:tuxjunior,代码行数:31,代码来源:sound_file.cpp

示例9: PHYSFS_tell

        bool FileReadObject::seek(long finalPos, bool relativeMovement)
        {
            if (relativeMovement)
                finalPos += PHYSFS_tell(mFileHandle);

            return PHYSFS_seek(mFileHandle, finalPos);
        }
开发者ID:DraconicEnt,项目名称:KGE,代码行数:7,代码来源:CFileReader.cpp

示例10: tell

sf::Int64 VFile::seek(sf::Int64 position)
{
    auto ipos = static_cast<PHYSFS_uint64>(position);
    if (!m_f || !check(PHYSFS_seek(m_f, ipos), 1, "seek"))
        return -1;
    return tell();
}
开发者ID:Oberon00,项目名称:jd,代码行数:7,代码来源:FileSystem.cpp

示例11: fs_seek

int fs_seek(fs_file fh, long offset, int whence)
{
    PHYSFS_uint64 pos = 0;
    PHYSFS_sint64 cur = PHYSFS_tell(fh->handle);
    PHYSFS_sint64 len = PHYSFS_fileLength(fh->handle);

    switch (whence)
    {
    case SEEK_SET:
        pos = offset;
        break;

    case SEEK_CUR:
        if (cur < 0)
            return -1;
        pos = cur + offset;
        break;

    case SEEK_END:
        if (len < 0)
            return -1;
        pos = len + offset;
        break;
    }

    return PHYSFS_seek(fh->handle, pos);
}
开发者ID:L0rdK,项目名称:neverball-sdl2,代码行数:27,代码来源:fs_physfs.c

示例12:

sf::Int64 PhysFSInputStream::seek(sf::Int64 position)
{
	if ( File ) 
	{
		if ( PHYSFS_seek(File, (PHYSFS_uint64)position) == 0 ) return -1;
	}
	return position;
}
开发者ID:StevenChristy,项目名称:JSGameClient,代码行数:8,代码来源:PhysFSInputStream.cpp

示例13: PHYSFS_tell

bool physfsFile::prepareRead() {
	PHYSFS_uint64 pos = PHYSFS_tell(fhandle);
	PHYSFS_close(fhandle);
	fhandle = PHYSFS_openRead(pname);
	PHYSFS_seek(fhandle, pos);
	//LOG_MSG("Goto read (%s at %i)",pname,PHYSFS_tell(fhandle));
    return true;
}
开发者ID:Cliff-F,项目名称:Boxer,代码行数:8,代码来源:drive_physfs.cpp

示例14: PHYSFS_getWriteDir

bool physfsFile::prepareWrite() {
	const char *wdir = PHYSFS_getWriteDir();
	if (wdir == NULL) {
		LOG_MSG("PHYSFS could not fulfill write request: no write directory set.");
		return false;
	}
	//LOG_MSG("Goto write (%s at %i)",pname,PHYSFS_tell(fhandle));
	const char *fdir = PHYSFS_getRealDir(pname);
	PHYSFS_uint64 pos = PHYSFS_tell(fhandle);
	char *slash = strrchr(pname,'/');
	if (slash && slash != pname) {
		*slash = 0;
		PHYSFS_mkdir(pname);
		*slash = '/';
	}
	if (strcmp(fdir,wdir)) { /* we need COW */
		//LOG_MSG("COW",pname,PHYSFS_tell(fhandle));
		PHYSFS_file *whandle = PHYSFS_openWrite(pname);
		if (whandle == NULL) {
			LOG_MSG("PHYSFS copy-on-write failed: %s.",PHYSFS_getLastError());
			return false;
		}
		char buffer[65536];
		PHYSFS_sint64 size;
		PHYSFS_seek(fhandle, 0);
		while ((size = PHYSFS_read(fhandle,buffer,1,65536)) > 0) {
			if (PHYSFS_write(whandle,buffer,1,(PHYSFS_uint32)size) != size) {
				LOG_MSG("PHYSFS copy-on-write failed: %s.",PHYSFS_getLastError());
				PHYSFS_close(whandle);
				return false;
			}
		}
		PHYSFS_seek(whandle, pos);
		PHYSFS_close(fhandle);
		fhandle = whandle;
	} else { // megayuck - physfs on posix platforms uses O_APPEND. We illegally access the fd directly and clear that flag.
		//LOG_MSG("noCOW",pname,PHYSFS_tell(fhandle));
		PHYSFS_close(fhandle);
		fhandle = PHYSFS_openAppend(pname);
#ifndef WIN32
		fcntl(**(int**)fhandle->opaque,F_SETFL,0);
#endif
		PHYSFS_seek(fhandle, pos);
	}
	return true;
}
开发者ID:Cliff-F,项目名称:Boxer,代码行数:46,代码来源:drive_physfs.cpp

示例15:

sf::Int64 sf::PhysFSStream::seek(sf::Int64 position)
{
	if (PHYSFS_seek(file, position) == 0)
	{
		return -1;
	}
	return position;
}
开发者ID:mewbak,项目名称:DGEngine,代码行数:8,代码来源:PhysFSStream.cpp


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