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


C++ SDL_RWFromFile函数代码示例

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


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

示例1: snprintf

SDL_Surface *GetCIcon(FrameBuf *screen, short cicn_id)
{
	char file[256];
	DataDir data_dir;
	SDL_Surface *cicn;
	SDL_RWops *cicn_src;
	Uint8 *pixels, *mask;
	Uint16 w, h;
	
	/* Open the cicn sprite file.. */
	snprintf(file, sizeof(file), "Images/Maelstrom_Icon#%hd.cicn", cicn_id);
	if ( (cicn_src=SDL_RWFromFile(data_dir.FullPath(file), "r")) == NULL ) {
		error("GetCIcon(%hd): Can't open CICN %s: ",
					cicn_id, data_dir.FullPath(file));
		return(NULL);
	}

	w = SDL_ReadBE16(cicn_src);
	h = SDL_ReadBE16(cicn_src);
        pixels = new Uint8[w*h];
        if ( SDL_RWread(cicn_src, pixels, 1, w*h) != (w*h) ) {
		error("GetCIcon(%hd): Corrupt CICN!\n", cicn_id);
		delete[] pixels;
		SDL_RWclose(cicn_src);
		return(NULL);
	}
        mask = new Uint8[(w/8)*h];
        if ( SDL_RWread(cicn_src, mask, 1, (w/8)*h) != ((w/8)*h) ) {
		error("GetCIcon(%hd): Corrupt CICN!\n", cicn_id);
		delete[] pixels;
		delete[] mask;
		SDL_RWclose(cicn_src);
		return(NULL);
	}
	SDL_RWclose(cicn_src);

	cicn = screen->LoadImage(w, h, pixels, mask);
	delete[] pixels;
	delete[] mask;
	if ( cicn == NULL ) {
		error("GetCIcon(%hd): Couldn't convert CICN!\n", cicn_id);
	}
	return(cicn);
}
开发者ID:MaddTheSane,项目名称:maelstrom,代码行数:44,代码来源:load.cpp

示例2: load_SRAM

/* Given a file_path and buffer, attempts to load save data into the buffer
 * up to the suppled size in bytes. Returns the size of the file if successful, 
 * returns 0 if unsuccessful. Buffer should at least be of length size*/
unsigned long load_SRAM(const char *file_path, unsigned char *data, unsigned long size) {
    
    log_message(LOG_INFO, "Attempting to load SRAM for file: %s\n",file_path);
    
    SDL_RWops *rw = SDL_RWFromFile(file_path, "rb");
    
    if (rw == NULL) {
        log_message(LOG_ERROR, 
            "Error opening file %s: %s\n", file_path, SDL_GetError());       
        return 0;
    }

    Sint64 res_size = SDL_RWsize(rw);
    if (res_size > size) {
        log_message(LOG_ERROR,
            "Error opening file %s: File is too large to be SRAM snapshot\n",
            file_path);
        return 0;
    }

    if (res_size == 0) {
        log_message(LOG_WARN, "File %s has a size of 0 bytes\n", file_path);
        return 0;
    }

    Sint64 nb_read_total = 0, nb_read = 1;
    unsigned char* buf = data;
    while (nb_read_total < res_size && nb_read != 0) {
            nb_read = SDL_RWread(rw, buf, 1, (res_size - nb_read_total));
            nb_read_total += nb_read;
            buf += nb_read;
    }

        SDL_RWclose(rw);
        if (nb_read_total != res_size) {
                log_message(LOG_ERROR, 
                    "Bytes expected (%lu) is not equal to bytes read (%lu)\n",
                    res_size, nb_read_total);
                free(data);
                return 0;
        }
    
    return res_size;
}
开发者ID:RossMeikleham,项目名称:PlutoBoy,代码行数:47,代码来源:files.c

示例3: SDL_RWFromFile

void SdlAudio::BGM_Play(std::string const& file, int volume, int /* pitch */, int fadein) {
	std::string const path = FileFinder::FindMusic(file);
	if (path.empty()) {
		Output::Debug("Music not found: %s", file.c_str());
		return;
	}

	SDL_RWops *rw = SDL_RWFromFile(path.c_str(), "rb");
#if SDL_MIXER_MAJOR_VERSION>1
	bgm.reset(Mix_LoadMUS_RW(rw, 1), &Mix_FreeMusic);
#else
	bgm.reset(Mix_LoadMUS_RW(rw), &Mix_FreeMusic);
#endif
	if (!bgm) {
		Output::Warning("Couldn't load %s BGM.\n%s\n", file.c_str(), Mix_GetError());
		return;
	}
#if SDL_MAJOR_VERSION>1
	// SDL2_mixer produces noise when playing wav.
	// Workaround: Use Mix_LoadWAV
	// https://bugzilla.libsdl.org/show_bug.cgi?id=2094
	if (bgs_playing) {
		BGS_Stop();
	}
	if (Mix_GetMusicType(bgm.get()) == MUS_WAV) {
		BGM_Stop();
		BGS_Play(file, volume, 0, fadein);
		return;
	}
#endif

	BGM_Volume(volume);
	if (!me_stopped_bgm &&
#ifdef _WIN32
	    (Mix_GetMusicType(bgm.get()) == MUS_MID && WindowsUtils::GetWindowsVersion() >= 6
	     ? Mix_PlayMusic(bgm.get(), -1) : Mix_FadeInMusic(bgm.get(), -1, fadein))
#else
	     Mix_FadeInMusic(bgm.get(), -1, fadein)
#endif
	     == -1) {
		Output::Warning("Couldn't play %s BGM.\n%s\n", file.c_str(), Mix_GetError());
		return;
	}
}
开发者ID:glynnc,项目名称:Player,代码行数:44,代码来源:sdl_audio.cpp

示例4: SDL_RWFromFile

    void Map::loadFromFile(const std::string filename){
        this->map = new Tmx::Map();
        this->map->ParseFile(filename);

        if(map->HasError() == true) { throw map->GetErrorText(); }
        if(this->renderer == nullptr) { throw new ExNoRenderer(); }
        
        // Load image files
        const std::vector<Tmx::Tileset*>& tileSets = map->GetTilesets();
        for(int i = 0; i < tileSets.size(); ++i) {
            const Tmx::Tileset * tileSet = tileSets[i];
            const Tmx::Image * image = tileSet->GetImage();
            const std::string source = image->GetSource();
            SDL_RWops * rwop = SDL_RWFromFile(source.c_str(),"r");
            SDL_Surface * surf = IMG_LoadPNG_RW(rwop);
            SDL_Texture * tex = SDL_CreateTextureFromSurface(this->renderer, surf);
            this->images.push_back(tex);
        }
    }
开发者ID:agharbin,项目名称:tiler,代码行数:19,代码来源:tiler.cpp

示例5: init_gaia

int init_gaia(void)
{
  struct SDL_Surface *Z;
  struct SDL_RWops *F;
  Sint32 w;
  int i, x=0;

  
  if( (F = SDL_RWFromFile("data/hblk01.dat","r")) == NULL)
    abend(0);

  for(i=0; i < 256*6; i++) {
    w = SDL_ReadLE32(F);
    w = (w < 6144)? 0: (w - 6144) / 320;
    subtile_table[i] = w;
    x = (w > x)? w : x;
  }
  printf("Gaia tile module:\n  +  %d unique subtiles.\n", x);
  x++;
  
  if(!(Z = CreateZSurface(get_pal("data/hpal01.dat"), 32,16*x)) )
    SDL_RWclose(F), abend(0);

  load_subtiles(F, Z->pixels, x);
  if(1) subtiles = Z;
  else {
    if( (subtiles = SDL_CreateRGBSurface(SDL_HWSURFACE,
					 32,16*x,32,
					 RR,GG,BB,AA)) )
      SDL_BlitSurface(Z, NULL, subtiles, NULL);
    SDL_FreeSurface(Z);
  }

  SDL_RWclose(F);

  lua_pushnumber(L, SCALE); lua_setfield(L, LUA_GLOBALSINDEX, "scale");
  lua_register(L, "s2m", s2m);
  lua_register(L, "m2s", m2s);

  REG_CLASS(L, map);

  return subtiles != NULL;
}
开发者ID:ashur-xx,项目名称:FreeSynd,代码行数:43,代码来源:gaia.c

示例6: SDL_RWFromFile

/*static*/ bool	tqt::is_tqt_file(const char* filename)
// Return true if the given file looks like a .tqt file of our
// appropriate version.  Do this by attempting to read the header.
{
	SDL_RWops*	in = SDL_RWFromFile(filename, "rb");
	if (in == NULL) {
		return false;
	}

	// Read header.
	tqt_header_info	info = read_tqt_header_info(in);
	SDL_RWclose(in);

	if (info.m_version != TQT_VERSION) {
		return false;
	}
	
	return true;
}
开发者ID:moltenguy1,项目名称:deusexmachina,代码行数:19,代码来源:tqt.cpp

示例7: BAIL_IF_MACRO

Sound_Sample *Sound_NewSampleFromFile(const char *filename,
                                      Sound_AudioInfo *desired,
                                      Uint32 bufferSize)
{
    const char *ext;
    SDL_RWops *rw;

    BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
    BAIL_IF_MACRO(filename == NULL, ERR_INVALID_ARGUMENT, NULL);

    ext = strrchr(filename, '.');
    rw = SDL_RWFromFile(filename, "rb");
    BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL);

    if (ext != NULL)
        ext++;

    return(Sound_NewSample(rw, ext, desired, bufferSize));
} /* Sound_NewSampleFromFile */
开发者ID:ptitSeb,项目名称:SDL_sound,代码行数:19,代码来源:SDL_sound.c

示例8: open_font

static int open_font(lua_State * L) {
	const char * filename;
	lua_Integer fontsize;
	TTF_Font * font;
	TTF_Font ** ud;
	char adjusted_filename[MAX_ADJUSTED_FILENAME_LEN];
	SDL_RWops * file;
	
	filename = luaL_checkstring(L, 1);
	prepend_data_path(adjusted_filename, filename, MAX_ADJUSTED_FILENAME_LEN);
	file = SDL_RWFromFile(adjusted_filename, "rt");
	fontsize = luaL_checkinteger(L, 2);
	font = TTF_OpenFontRW(file, 1, fontsize);
	if (!font) fatal(TTF_GetError());
	ud = (TTF_Font **) lua_newuserdata(L, sizeof(TTF_Font *));
	if (ud == NULL) fatal("ud NULL in open_font");
	*ud = font;
	return 1;
}
开发者ID:cbhuber,项目名称:Games,代码行数:19,代码来源:font.c

示例9: SDL_RWFromFile

BaseD::Profile::Profile(const char* spc_filename)
{
  is_profiling = true;
  old_gain_db = BaseD::player->gain_db;
  BaseD::player->pause(1, true, false);
  BaseD::reload();
  BaseD::player->pause(0, false, false);
  BaseD::player->pause(1, false, false);
  //BaseD::player->restart_track();
  // Set Volume to 0
  player->set_gain_db(Music_Player::min_gain_db, true);
  // get pointer to spc_file_t
  // open the SPC File
  //DEBUGLOG("spc file path = %s\n", BaseD::g_cfg.playlist[BaseD::g_cur_entry]);
  //const char *spc_filename = BaseD::g_cfg.playlist[BaseD::g_cur_entry];
  // need to open a file
  SDL_RWops *orig_spc_file = SDL_RWFromFile(spc_filename, "rb");
  if (orig_spc_file == NULL)
  {
    sprintf(BaseD::tmpbuf, "Warning: Unable to open file %s!\n %s", spc_filename, SDL_GetError() );
    SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
                   "Could not open FILE!",
                   BaseD::tmpbuf,
                   NULL);
    //return -1;
    is_profiling=false;
    delete this;
  }

  if (SDL_RWread(orig_spc_file, orig_spc_state, Snes_Spc::spc_file_size, 1) == 0)
  {
    sprintf(BaseD::tmpbuf, "Warning: Unable to read file %s!\n %s", spc_filename, SDL_GetError() );
    SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
                   "Could not read file!",
                   BaseD::tmpbuf,
                   NULL);
    SDL_RWclose(orig_spc_file);
    //return -1;
    is_profiling=false;
    delete this;
  }
  else SDL_RWclose(orig_spc_file);
}
开发者ID:MisterZeus,项目名称:SNES-Tracker,代码行数:43,代码来源:BaseD.cpp

示例10: sizeof

void *inhale_file(const char *name, Uint32 blk, Uint32 off)
{
  struct SDL_RWops *F = NULL;
  Uint32 x, *n;
  void *p;

  if(!(F = SDL_RWFromFile(name,"r"))) abend(0);

  /* determine size */
  x = SDL_RWseek(F, 0, SEEK_END), SDL_RWseek(F, 0, SEEK_SET);
  off += sizeof(Uint32);

  if((n = p = malloc(off+x)) == NULL) abend(0);

  *n = SDL_RWread(F, p+off, blk, x/blk);
  SDL_RWclose(F);

  return p;
}
开发者ID:ashur-xx,项目名称:FreeSynd,代码行数:19,代码来源:munin.c

示例11: raw_save_file

void raw_save_file(terrain* t, char* filename) {
  
  SDL_RWops* file = SDL_RWFromFile(filename, "wb");
  
  if (!file) {
    error("Could not load file %s\n", filename);
  }
  
  uint16_t* pixels = malloc(sizeof(uint16_t) * t->width * t->height);
  
  for(int i = 0; i < t->width * t->height; i++) {
    pixels[i] = t->heightmap[i] * (65536.0 / MAX_HEIGHT);
  }
  
  SDL_RWwrite(file, pixels, sizeof(uint16_t) * t->width * t->height, 1);
  
  SDL_RWclose(file);
  
}
开发者ID:ghosthamlet,项目名称:Corange,代码行数:19,代码来源:terrain.c

示例12: close

void close()
{
	//Open data for writing
	SDL_RWops* file = SDL_RWFromFile( "33_file_reading_and_writing/nums.bin", "w+b" );
	if( file != NULL )
	{
		//Save data
		for( int i = 0; i < TOTAL_DATA; ++i )
		{
			SDL_RWwrite( file, &gData[ i ], sizeof(Sint32), 1 );
		}

		//Close file handler
		SDL_RWclose( file );
	}
	else
	{
		printf( "Error: Unable to save file! %s\n", SDL_GetError() );
	}

	//Free loaded images
	gPromptTextTexture.free();
	for( int i = 0; i < TOTAL_DATA; ++i )
	{
		gDataTextures[ i ].free();
	}

	//Free global font
	TTF_CloseFont( gFont );
	gFont = NULL;

	//Destroy window	
	SDL_DestroyRenderer( gRenderer );
	SDL_DestroyWindow( gWindow );
	gWindow = NULL;
	gRenderer = NULL;

	//Quit SDL subsystems
	TTF_Quit();
	IMG_Quit();
	SDL_Quit();
}
开发者ID:aatwo,项目名称:TestProjects,代码行数:42,代码来源:33_file_reading_and_writing.cpp

示例13: DISKAUD_OpenDevice

static int
DISKAUD_OpenDevice(_THIS, const char *devname, int iscapture)
{
    const char *envr = SDL_getenv(DISKENVR_WRITEDELAY);
    const char *fname = DISKAUD_GetOutputFilename(devname);

    this->hidden = (struct SDL_PrivateAudioData *)
        SDL_malloc(sizeof(*this->hidden));
    if (this->hidden == NULL) {
        SDL_OutOfMemory();
        return 0;
    }
    SDL_memset(this->hidden, 0, sizeof(*this->hidden));

    /* Open the audio device */
    this->hidden->output = SDL_RWFromFile(fname, "wb");
    if (this->hidden->output == NULL) {
        DISKAUD_CloseDevice(this);
        return 0;
    }

    /* Allocate mixing buffer */
    this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
    if (this->hidden->mixbuf == NULL) {
        DISKAUD_CloseDevice(this);
        return 0;
    }
    SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);

    this->hidden->mixlen = this->spec.size;
    this->hidden->write_delay =
        (envr) ? SDL_atoi(envr) : DISKDEFAULT_WRITEDELAY;

#if HAVE_STDIO_H
    fprintf(stderr,
            "WARNING: You are using the SDL disk writer audio driver!\n"
            " Writing to file [%s].\n", fname);
#endif

    /* We're ready to rock and roll. :-) */
    return 1;
}
开发者ID:0xD34D,项目名称:supermariowar-android,代码行数:42,代码来源:SDL_diskaudio.c

示例14: get_standard_rwop

static SDL_RWops* get_standard_rwop(PyObject* obj)
{
	if(PyString_Check(obj) || PyUnicode_Check(obj))
	{
		int result;
		char* name;
		PyObject* tuple = PyTuple_New(1);
		PyTuple_SET_ITEM(tuple, 0, obj);
		Py_INCREF(obj);
		if(!tuple) return NULL;
		result = PyArg_ParseTuple(tuple, "s", &name);
		Py_DECREF(tuple);
		if(!result)
			return NULL;
		return SDL_RWFromFile(name, "rb");
	}
	// else if(PyFile_Check(obj))
        //     return SDL_RWFromFP(PyFile_AsFile(obj), 0);
        return NULL;
}
开发者ID:FractalBobz,项目名称:renpy,代码行数:20,代码来源:rwobject.c

示例15: extract_fork

static void extract_fork(SDL_RWops *fin, int req_id, const char *file_name, const char *fork_name)
{
	long id, fork_start, fork_size;
	int num_entries, fork_found;
	SDL_RWops *fout;

	// Look for fork in source file
	SDL_RWseek(fin, 0x18, SEEK_SET);
	num_entries = SDL_ReadBE16(fin);
	while (num_entries--) {
		Uint32 id = SDL_ReadBE32(fin);
		Sint32 ofs = SDL_ReadBE32(fin);
		Sint32 len = SDL_ReadBE32(fin);
		if (id == req_id) {
			fork_found = 1;
			fork_start = ofs;
			fork_size = len;
		}
	}
	if (!fork_found) {
		fprintf(stderr, "Warning: source file doesn't contain a %s fork.\n", fork_name);
		return;
	}

	// Found, open destination file
	fout = SDL_RWFromFile(file_name, "wb");
	if (fout == NULL) {
		perror("Can't open destination file");
		exit(1);
	}

	// Copy fork
	SDL_RWseek(fin, fork_start, SEEK_SET);
	while (fork_size) {
		long length = fork_size > BUFFER_SIZE ? BUFFER_SIZE : fork_size;
		SDL_RWread(fin, buffer, 1, length);
		SDL_RWwrite(fout, buffer, 1, length);
		fork_size -= length;
	}
	SDL_FreeRW(fout);
}
开发者ID:0x7F800000,项目名称:Aleph-NONE,代码行数:41,代码来源:single2forks.c


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