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


C++ SDL_RWops类代码示例

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


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

示例1: load

//-------------------------------------------------------------------
// WavePool members.
//-------------------------------------------------------------------
void WavePool::load(char *f)
{
   myFile   myfile;
   int      i;
   SDL_RWops *memSample = NULL;

// read in header
   if (!myfile.open(f)) error("WavPool not found: ", f);

   myfile.read(&nsamples, sizeof(long));

// Just quit if empty library.
   if (nsamples == 0) {
      myfile.close();
      return;
   }

   sample = new Sample[nsamples];
   myfile.read(sample, nsamples * sizeof(Sample));

   fseek(myfile.getFILE(), myfile.getbase(), SEEK_SET);
   memSample = SDL_RWFromMem(myfile.getMemory(), myfile.getsize());

// Load WAVES.
   for (i = 0; i < nsamples; i++) {
#ifndef NO_SOUND
      memSample->seek(memSample, (long)sample[i].sample, RW_SEEK_SET);

      if((sample[i].sample = Mix_LoadWAV_RW(memSample, SDL_FALSE)) == NULL) error("Error loading sample. ", (char *)Mix_GetError());
#endif
   }

   SDL_RWclose(memSample);
   myfile.close();
}
开发者ID:sigt44,项目名称:ravage-sdl,代码行数:38,代码来源:SOUND.CPP

示例2: Dx_FileRead_size

int64_t Dx_FileRead_size(const char *filename) {
    SDL_RWops *rwops = Dx_File_OpenStream(filename);
    if (rwops != NULL) {
        int64_t size = rwops->size(rwops);
        rwops->close(rwops);
        return size;
    }
    return 0;
}
开发者ID:mauvecow,项目名称:DxPortLib,代码行数:9,代码来源:DxFile.c

示例3: graphics_AndroidTextureReader

static int graphics_AndroidTextureReader(void* buffer, size_t bytes, void* userdata) {
    SDL_RWops* ops = (SDL_RWops*)userdata;
#ifndef NOTHREADEDSDLRW
    int i = ops->read(ops, buffer, 1, bytes);
#else
    // workaround for http:// bugzilla.libsdl.org/show_bug.cgi?id=1422
    int i = main_NoThreadedRWopsRead(ops, buffer, 1, bytes);
#endif
    return i;
}
开发者ID:eledot,项目名称:Blitwizard,代码行数:10,代码来源:graphics.c

示例4: initLoad

void initLoad(){
	/*ファイルオープン*/
	ARCHIVE archive;
	openArchive(&archive,LOAD_ARCHIVE);
	/*背景取得*/
	SDL_RWops* bgData = getGraphixFile(&archive,LOAD_BG);
	getSpriteFromOPS(&LoadBGSprite,bgData);
	bgData->close(bgData);					//メモリ開放は忘れずに
	closeArchive(&archive);
	
}
开发者ID:ledyba,项目名称:20060910-C-Stg,代码行数:11,代码来源:load.c

示例5: LoadArchivePics

static void LoadArchivePics(
	PicManager *pm, const char *archive, const char *dirname)
{
	char *buf = NULL;

	char path[CDOGS_PATH_MAX];
	sprintf(path, "%s/%s", archive, dirname);
	tinydir_dir dir;
	if (tinydir_open(&dir, path) != 0)
	{
		LOG(LM_MAP, LL_DEBUG, "no pic dir(%s): %s", path, strerror(errno));
		goto bail;
	}
	while (dir.has_next)
	{
		tinydir_file file;
		if (tinydir_readfile(&dir, &file) != 0)
		{
			LOG(LM_MAP, LL_WARN, "cannot read file: %s", strerror(errno));
			break;
		}
		if (!file.is_reg) goto nextFile;
		long len;
		buf = ReadFileIntoBuf(file.path, "rb", &len);
		if (buf == NULL) goto nextFile;
		SDL_RWops *rwops = SDL_RWFromMem(buf, len);
		bool isPng = IMG_isPNG(rwops);
		if (isPng)
		{
			SDL_Surface *data = IMG_Load_RW(rwops, 0);
			if (data != NULL)
			{
				char nameBuf[CDOGS_FILENAME_MAX];
				PathGetBasenameWithoutExtension(nameBuf, file.path);
				PicManagerAdd(&pm->customPics, &pm->customSprites, nameBuf, data);
			}
		}
		rwops->close(rwops);
	nextFile:
		CFREE(buf);
		buf = NULL;
		if (tinydir_next(&dir) != 0)
		{
			printf(
				"Could not go to next file in dir %s: %s\n",
				path, strerror(errno));
			goto bail;
		}
	}

bail:
	CFREE(buf);
	tinydir_close(&dir);
}
开发者ID:FlyingTarrasque,项目名称:cdogs-sdl,代码行数:54,代码来源:map_archive.c

示例6: LoadArchiveSounds

static void LoadArchiveSounds(
	SoundDevice *device, const char *archive, const char *dirname)
{
	char *buf = NULL;

	char path[CDOGS_PATH_MAX];
	sprintf(path, "%s/%s", archive, dirname);
	tinydir_dir dir;
	if (tinydir_open(&dir, path) != 0)
	{
		LOG(LM_MAP, LL_DEBUG, "no sound dir(%s): %s", path, strerror(errno));
		goto bail;
	}
	while (dir.has_next)
	{
		tinydir_file file;
		tinydir_readfile(&dir, &file);
		if (!file.is_reg) goto nextFile;
		long len;
		buf = ReadFileIntoBuf(file.path, "rb", &len);
		if (buf == NULL) goto nextFile;
		SDL_RWops *rwops = SDL_RWFromMem(buf, len);
		Mix_Chunk *data = Mix_LoadWAV_RW(rwops, 0);
		if (data != NULL)
		{
			char nameBuf[CDOGS_FILENAME_MAX];
			strcpy(nameBuf, file.name);
			// Remove extension
			char *dot = strrchr(nameBuf, '.');
			if (dot != NULL)
			{
				*dot = '\0';
			}
			SoundAdd(&device->customSounds, nameBuf, data);
		}
		rwops->close(rwops);
	nextFile:
		CFREE(buf);
		buf = NULL;
		if (tinydir_next(&dir) != 0)
		{
			printf(
				"Could not go to next file in dir %s: %s\n",
				path, strerror(errno));
			goto bail;
		}
	}

bail:
	CFREE(buf);
	tinydir_close(&dir);
}
开发者ID:FlyingTarrasque,项目名称:cdogs-sdl,代码行数:52,代码来源:map_archive.c

示例7: AddResource

void AddResource(ResourceManager resourceManager, std::string identifier, ResourceType resourceType) {
    ResourceHandle resourceHandle = CreateResourceHandle(resourceType);

    switch (resourceType) {
    case TEXTURE: {
        std::string strId =  resourceManager->assetBaseDir + identifier;
        resourceHandle->textureRes->texture = IMG_LoadTexture(resourceManager->renderer, strId.c_str());
        if(!resourceHandle->textureRes->texture) {
            LOGE("Unable to load resource: %s\n", strId.c_str());
            FreeResourceHandle(resourceManager, resourceHandle);
            assert(0);
        }
        resourceHandle->textureRes->name = identifier; }
        break;
    case TMX_MAP: {
        std::string strId = resourceManager->assetBaseDir + identifier;
        resourceHandle->tmxMapResource->map.ParseFile(strId);
        break;
    }
    case ENTITY: {
        std::string strId = resourceManager->assetBaseDir + identifier;
        SDL_RWops * file = SDL_RWFromFile (strId.c_str(), "rb");

        if (!file) {
            assert(0);
        }

        int fileSize = file->size(file);

        if (fileSize <= 0) {
            assert(0);
        }

        char* fileText = new char[fileSize + 1];
        fileText[fileSize] = 0;
        file->read(file, fileText, 1, fileSize);

        file->close(file);

        std::string text(fileText, fileText+fileSize);
        delete [] fileText;

        resourceHandle->entityTemplateResource->xml.Parse(text.c_str());

        break;
    }
    default:
        assert(0);
    }

    resourceManager->resources[identifier] = resourceHandle;
}
开发者ID:rmaloney77,项目名称:crimson,代码行数:52,代码来源:ResourceManager.cpp

示例8: SDL_RWFromFile

extern warp_result_t save_file
(const char *path, const char *data, size_t size) {
    SDL_RWops *io = SDL_RWFromFile(path, "w");
    if (io == NULL) {
        return warp_failure("Cannot open the file: %s.", path);
    }
    const size_t saved_count = io->write(io, data, size, 1);
    io->close(io);
    if (saved_count != 1) {
        warp_log_e("Expected to save single object,"
                   " number of saved objects: %zu", saved_count);
    }
    return warp_success();
}
开发者ID:mbelicki,项目名称:warp,代码行数:14,代码来源:io.c

示例9: ini_parse

/* See documentation in header file. */
int ini_parse(const char* filename,
              int (*handler)(void*, const char*, const char*, const char*),
              void* user)
{
    SDL_RWops* file = SDL_RWFromFile(filename, "r");
    int error;

    if (!file)
        return -1;
    error = ini_parse_file(file, handler, user);

    file->close(file);

    return error;
}
开发者ID:TapkaiNKooH,项目名称:Purity2D,代码行数:16,代码来源:ini.c

示例10: LoadAllText

std::string LoadAllText(std::string file)
{
	SDL_RWops *rw = SDL_RWFromFile(file.c_str(), "r");

	auto size = rw->size(rw);
	char* script = new char[size + 1];
	memset(script, 0, size + 1);
	rw->read(rw, script, sizeof(char), size);
	rw->close(rw);

	std::string result = script;
	delete[] script;

	return result;
}
开发者ID:davidsiaw,项目名称:aldebaran,代码行数:15,代码来源:utils.cpp

示例11: SDL_RWFromFile

void Purity::LuaManager::doFile(const std::string& luaFileName)
{
    SDL_RWops* file = SDL_RWFromFile(luaFileName.c_str(), "rb");

    int fileSize = file->size(file);
    char* fileContents = new char[fileSize + 1];

    file->read(file, fileContents, 1, fileSize);
    fileContents[fileSize] = '\0';

    file->close(file);

    luaL_dostring(mLuaState, fileContents);

    delete [] fileContents;
}
开发者ID:swloper,项目名称:Purity2D,代码行数:16,代码来源:luamanager.cpp

示例12: SDL_RWFromFile

void Purity::Font::loadFont()
{
    SDL_RWops* fontFile = SDL_RWFromFile(mFontFileName.c_str(), "rb");

    if (fontFile == nullptr)
    {
        std::cerr << "Error loading font file"
                  << ": " << SDL_GetError() << std::endl;
    }

    const auto fontFileSize = fontFile->size(fontFile);
    mFontData.reserve(fontFileSize);

    fontFile->read(fontFile, &mFontData[0], 1, fontFileSize);

    fontFile->close(fontFile);
}
开发者ID:TapkaiNKooH,项目名称:Purity2D,代码行数:17,代码来源:font.cpp

示例13: SDLJBN_AddMappingsFromFile

int SDLJBN_AddMappingsFromFile(const char *file)
{
	int ret = 0;
	char *s = NULL;

	SDLJBN_Init();
	SDL_RWops *rwops = SDL_RWFromFile(file, "r");
	if (rwops == NULL)
	{
		err = "Cannot open file";
		ret = -1;
		goto bail;
	}

	// Read file into memory
	const Sint64 fsize = rwops->size(rwops);
	if (fsize == -1)
	{
		err = "Cannot find file size";
		ret = -1;
		goto bail;
	}
	s = SDL_malloc((size_t)fsize + 1);
	if (s == NULL)
	{
		err = "Out of memory";
		ret = -1;
		goto bail;
	}
	if (SDL_RWread(rwops, s, (size_t)fsize, 1) == 0)
	{
		err = "Cannot read file";
		ret = -1;
		goto bail;
	}
	s[fsize] = '\0';

	ret = ReadMappingsString(s);

bail:
	SDL_RWclose(rwops);
	SDL_free(s);
	return ret;
}
开发者ID:wutipong,项目名称:SDL_JoystickButtonNames,代码行数:44,代码来源:SDL_joystickbuttonnames.c

示例14: calloc

SDL_RWops *SDL_RWFromBundle(Bundle *bundle, const char *filename)
{
	SDL_RWops *rwops;
	RWOpsBundle * b = calloc(1, sizeof(RWOpsBundle));
	b->handle = bundle->handle;
	
	for (int i = 0 ; i < bundle->n_files ; ++i)
	{
		if (strcmp(bundle->file[i].name, filename) == 0)
		{
			b->file = &bundle->file[i];
			break;
		}
	}
	
	if (!b->file)
	{
		free(b);
		return NULL;
	}
		
	rwops = SDL_AllocRW();
	
	if (rwops != NULL) 
	{
		rwops->seek = bnd_seek;
		rwops->read = bnd_read;
		rwops->write = NULL;
		rwops->close = bnd_close;
		rwops->hidden.unknown.data1 = b;
		
		rwops->seek(rwops, 0, SEEK_SET);
	}
	else
	{
		free(b);
	}
	
	return rwops;
}
开发者ID:laanwj,项目名称:klystron,代码行数:40,代码来源:bundle.c

示例15: read_file

extern warp_result_t read_file(const char *path, warp_array_t *out_buffer) {
    SDL_RWops *io = SDL_RWFromFile(path, "r");
    if (io == NULL) {
        return warp_failure("Cannot open the file: %s.", path);
    }
    Sint64 size = io->size(io);
    char *content = malloc(sizeof (char) * (size + 1));
    if (content == NULL) {
        io->close(io);
        return warp_failure("Cannot allocate file buffer for file: %s", path);
    }
    if (io->read(io, content, size, 1) == 0) {
        free(content);
        io->close(io);
        return warp_failure("Error while reading file: %s.", path);
    }
    io->close(io);

    content[size] = '\0';
    *out_buffer = warp_array_create_from_buffer(content, sizeof (char), size + 1, NULL);
    free(content);

    return warp_success();
}
开发者ID:mbelicki,项目名称:warp,代码行数:24,代码来源:io.c


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