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


C++ SDL_AllocRW函数代码示例

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


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

示例1: SDL_RWFromFile

SDL_RWops *
SDL_RWFromFile(const char *file, const char *mode)
{
    SDL_RWops *rwops = NULL;
#ifdef HAVE_STDIO_H
    FILE *fp = NULL;
#endif
    if (!file || !*file || !mode || !*mode) {
        SDL_SetError("SDL_RWFromFile(): No file or no mode specified");
        return NULL;
    }
#if defined(ANDROID) && 0

    rwops = SDL_AllocRW();
    if (!rwops)
        return NULL;            /* SDL_SetError already setup by SDL_AllocRW() */
    if (Android_JNI_FileOpen(rwops, file, mode) < 0) {
        SDL_FreeRW(rwops);
        return NULL;
    }
    rwops->seek = Android_JNI_FileSeek;
    rwops->read = Android_JNI_FileRead;
    rwops->write = Android_JNI_FileWrite;
    rwops->close = Android_JNI_FileClose;

#elif defined(__WIN32__)
    rwops = SDL_AllocRW();
    if (!rwops)
        return NULL;            /* SDL_SetError already setup by SDL_AllocRW() */
    if (windows_file_open(rwops, file, mode) < 0) {
        SDL_FreeRW(rwops);
        return NULL;
    }
    rwops->seek = windows_file_seek;
    rwops->read = windows_file_read;
    rwops->write = windows_file_write;
    rwops->close = windows_file_close;

#elif HAVE_STDIO_H
	#ifdef __APPLE__
	fp = SDL_OpenFPFromBundleOrFallback(file, mode);
    #else
	fp = fopen(file, mode);
	#endif
	if (fp == NULL) {
        SDL_SetError("Couldn't open %s", file);
    } else {
        rwops = SDL_RWFromFP(fp, 1);
    }
#else
    SDL_SetError("SDL not compiled with stdio support");
#endif /* !HAVE_STDIO_H */

    return (rwops);
}
开发者ID:knepe,项目名称:cdogs-sdl-android,代码行数:55,代码来源:SDL_rwops.c

示例2: common_alloc

static SDL_RWops* common_alloc(SDL_RWops *wrapped, size_t bufsize, bool autoclose) {
	SDL_RWops *rw = SDL_AllocRW();

	if(!rw) {
		return NULL;
	}

	if(bufsize < MIN_CHUNK_SIZE) {
		bufsize = MIN_CHUNK_SIZE;
	}

	memset(rw, 0, sizeof(SDL_RWops));

	rw->type = SDL_RWOPS_UNKNOWN;
	rw->size = common_size;
	rw->seek = common_seek;
	rw->close = common_close;

	ZData *z = calloc(1, sizeof(ZData));
	z->stream = calloc(1, sizeof(z_stream));
	z->buffer_size = bufsize;
	z->buffer = z->buffer_ptr = calloc(1, bufsize);

	z->wrapped = wrapped;
	z->autoclose = autoclose;

	rw->hidden.unknown.data1 = z;

	return rw;
}
开发者ID:laochailan,项目名称:taisei,代码行数:30,代码来源:rwops_zlib.c

示例3: getFileForSDL

static SDL_RWops* getFileForSDL(const char * filename)
{
    filesystem::ReadFile * file = new filesystem::ReadFile(filename);

    if ( ! file->isOpen() )
    {
        delete file;
        return 0;
    }

    SDL_RWops * rwops = SDL_AllocRW();
    if ( ! rwops )
    {
        delete file;
        return 0;
    }

    rwops->seek =RWOps_Seek;
    rwops->read =RWOps_Read;
    rwops->write=RWOps_Write;
    rwops->close=RWOps_Close;
    rwops->type =0xdeadbeef;
    rwops->hidden.unknown.data1 = file;

    return rwops;
}
开发者ID:BackupTheBerlios,项目名称:netpanzer-svn,代码行数:26,代码来源:SDLSound.cpp

示例4: SDL_RWFromFile

SDL_RWops *SDL_RWFromZZIP(const char* file, const char* mode)
{
    register SDL_RWops* rwops;
    register ZZIP_FILE* zzip_file;

    if (! strchr (mode, 'r'))
        return SDL_RWFromFile(file, mode);

    zzip_file = zzip_fopen (file, mode);
    if (! zzip_file) return 0;

    rwops = SDL_AllocRW ();
    if (! rwops) {
        errno=ENOMEM;
        zzip_close (zzip_file);
        return 0;
    }

    SDL_RWOPS_ZZIP_DATA(rwops) = zzip_file;
    rwops->read = _zzip_read;
    rwops->write = _zzip_write;
    rwops->seek = _zzip_seek;
    rwops->close = _zzip_close;
    return rwops;
}
开发者ID:Bracket-,项目名称:psp-ports,代码行数:25,代码来源:SDL_rwops_zzip.c

示例5: RWopsFromPythonThreaded

SDL_RWops* RWopsFromPythonThreaded(PyObject* obj)
{
	SDL_RWops* rw;
	RWHelper* helper;
        PyInterpreterState* interp;
        PyThreadState* thread;

	if(!obj)
		return (SDL_RWops*)RAISE(PyExc_TypeError, "Invalid filetype object");

        rw = get_standard_rwop(obj);
        if(rw)
                return rw;

#ifndef WITH_THREAD
        return (SDL_RWops*)RAISE(PyExc_NotImplementedError, "Python built without thread support");
#else
        helper = PyMem_New(RWHelper, 1);
        fetch_object_methods(helper, obj);

        rw = SDL_AllocRW();
        rw->hidden.unknown.data1 = (void*)helper;
        rw->seek = rw_seek_th;
        rw->read = rw_read_th;
        rw->write = rw_write_th;
        rw->close = rw_close_th;

        PyEval_InitThreads();
        thread = PyThreadState_Get();
        interp = thread->interp;
        helper->thread = PyThreadState_New(interp);

	return rw;
#endif
}
开发者ID:FractalBobz,项目名称:renpy,代码行数:35,代码来源:rwobject.c

示例6: throw

	Music::Music(asset::istream stream) throw(Music_loading_failed) :
	    _handle(nullptr, Mix_FreeMusic), _stream(std::make_unique<asset::istream>(std::move(stream))){

		auto id = _stream->aid();

#ifndef EMSCRIPTEN
		SDL_RWops *rwops = SDL_AllocRW();
		INVARIANT(rwops, "SDL_AllocRW failed");

		rwops->seek = istream_seek;
		rwops->read = istream_read;
		rwops->write = NULL;
		rwops->close = istream_close;
		rwops->hidden.unknown.data1 = _stream.get();

		_handle.reset(Mix_LoadMUS_RW(rwops, 1));

#else
		auto location = _stream->physical_location();
		_stream.reset();

		if(location.is_nothing())
			return;

		_handle.reset(Mix_LoadMUS(location.get_or_throw().c_str()));
#endif

		if(!_handle){
			WARN("Mix_LoadMUS_RW ("<<id.str()<<") failed: " << Mix_GetError());
		}

	}
开发者ID:lowkey42,项目名称:teamproject,代码行数:32,代码来源:music.cpp

示例7: SDL_RWFromConstMem

SDL_RWops *
SDL_RWFromConstMem(const void *mem, int size)
{
    SDL_RWops *rwops = NULL;
    if (!mem) {
      SDL_InvalidParamError("mem");
      return rwops;
    }
    if (!size) {
      SDL_InvalidParamError("size");
      return rwops;
    }

    rwops = SDL_AllocRW();
    if (rwops != NULL) {
        rwops->size = mem_size;
        rwops->seek = mem_seek;
        rwops->read = mem_read;
        rwops->write = mem_writeconst;
        rwops->close = mem_close;
        rwops->hidden.mem.base = (Uint8 *) mem;
        rwops->hidden.mem.here = rwops->hidden.mem.base;
        rwops->hidden.mem.stop = rwops->hidden.mem.base + size;
        rwops->type = SDL_RWOPS_MEMORY_RO;
    }
    return rwops;
}
开发者ID:Derek-OBrien,项目名称:DsdlEngine,代码行数:27,代码来源:SDL_rwops.c

示例8: SDL_SetError

SDL_RWops *SDL_RWFromFP(FILE *fp, int autoclose)
{
	SDL_RWops *rwops;

#ifdef WIN32
	if ( ! in_sdl ) {
		SDL_SetError("You can't pass a FILE pointer to a DLL (??)");
		/*return(NULL);*/
	}
#endif
	rwops = SDL_AllocRW();
	if ( rwops != NULL ) {
		rwops->seek = stdio_seek;
		rwops->read = stdio_read;
		rwops->write = stdio_write;
		rwops->close = stdio_close;
		rwops->Getc = stdio_getc; //maks
		rwops->Putc = stdio_putc; //maks
		rwops->hidden.stdio.fp = fp;
		rwops->hidden.stdio.autoclose = autoclose;

		//maks
		rwops->filePosition = rwops->stdioFilePosition = ftell(rwops->hidden.stdio.fp);
	}
	return(rwops);
}
开发者ID:Goettsch,项目名称:game-editor,代码行数:26,代码来源:SDL_rwops.c

示例9: fileIntForPath

static VALUE
fileIntForPath(const char *path, bool rubyExc)
{
	SDL_RWops *ops = SDL_AllocRW();

	try
	{
		shState->fileSystem().openRead(*ops, path);
	}
	catch (const Exception &e)
	{
		SDL_FreeRW(ops);

		if (rubyExc)
			raiseRbExc(e);
		else
			throw e;
	}

	VALUE klass = rb_const_get(rb_cObject, rb_intern("FileInt"));

	VALUE obj = rb_obj_alloc(klass);

	setPrivateData(obj, ops);

	return obj;
}
开发者ID:AlexandreSousa,项目名称:mkxp,代码行数:27,代码来源:filesystem-binding.cpp

示例10: key

_TTF_Font *SharedFontState::getFont(std::string family,
                                    int size)
{
	/* Check for substitutions */
	if (p->subs.contains(family))
		family = p->subs[family];

	/* Find out if the font asset exists */
	const FontSet &req = p->sets[family];

	if (req.regular.empty() && req.other.empty())
	{
		/* Doesn't exist; use built-in font */
		family = "";
	}

	FontKey key(family, size);

	TTF_Font *font = p->pool.value(key);

	if (font)
		return font;

	/* Not in pool; open new handle */
	SDL_RWops *ops;

	if (family.empty())
	{
		/* Built-in font */
		ops = openBundledFont();
	}
	else
	{
		/* Use 'other' path as alternative in case
		 * we have no 'regular' styled font asset */
		const char *path = !req.regular.empty()
		                 ? req.regular.c_str() : req.other.c_str();

		ops = SDL_AllocRW();
		shState->fileSystem().openReadRaw(*ops, path, true);
	}

	// FIXME 0.9 is guesswork at this point
//	float gamma = (96.0/45.0)*(5.0/14.0)*(size-5);
//	font = TTF_OpenFontRW(ops, 1, gamma /** .90*/);
	font = TTF_OpenFontRW(ops, 1, size* .90);

	if (!font)
		throw Exception(Exception::SDLError, "%s", SDL_GetError());

	p->pool.insert(key, font);

	return font;
}
开发者ID:AlexandreSousa,项目名称:mkxp,代码行数:54,代码来源:font.cpp

示例11: SDL_AllocRW

SDL_RWops *stream::rwops()
{
    SDL_RWops *rw = SDL_AllocRW();
    if(!rw) return NULL;
    rw->hidden.unknown.data1 = this;
    rw->seek = rwopsseek;
    rw->read = rwopsread;
    rw->write = rwopswrite;
    rw->close = rwopsclose;
    return rw;
}
开发者ID:Ajusa,项目名称:Sauerbraten,代码行数:11,代码来源:stream.cpp

示例12: PyRWops_NewRW

static SDL_RWops*
PyRWops_NewRW (PyObject *obj, int *canautoclose)
{
    _RWWrapper *wrapper;
    SDL_RWops *ops;
    
    if (!obj || !canautoclose)
    {
        PyErr_SetString (PyExc_TypeError, "argument is NULL");
        return NULL;
    }
    
    /* If we have a text object, assume it is a file, which is automatically
     * closed. */
    if (IsTextObj (obj))
    {
        PyObject *tmp;
        char *filename;
        if (!UTF8FromObj (obj, &filename, &tmp))
            return NULL;
        Py_XDECREF (tmp);
        *canautoclose = 1;
        ops = SDL_RWFromFile ((const char *)filename, "wb");
        if (!ops)
            PyErr_SetString (PyExc_PyGameError, SDL_GetError ());
        return ops;

    }

    /* No text object, so its a buffer or something like that. Try to get the
     * necessary information. */
    ops = SDL_AllocRW ();
    if (!ops)
    {
        PyErr_SetString (PyExc_PyGameError, SDL_GetError ());
        return NULL;
    }
    wrapper = PyMem_New (_RWWrapper, 1);
    if (!wrapper)
    {
        SDL_FreeRW (ops);
        return NULL;
    }
    _bind_python_methods (wrapper, obj);
    ops->read = _pyobj_read;
    ops->write = _pyobj_write;
    ops->seek = _pyobj_seek;
    ops->close = _pyobj_close;
    ops->hidden.unknown.data1 = (void*) wrapper;
    *canautoclose = 0;
    return ops;
}
开发者ID:gdos,项目名称:pgreloaded.sdl12,代码行数:52,代码来源:rwopsmod.c

示例13: SDL_AllocRW

	SDL_RWops* UUT_API Stream::CreatReadRWops(Stream* source)
	{
		SDL_RWops* ops = SDL_AllocRW();

		ops->hidden.unknown.data1 = source;
		ops->size = &funcRWopsSize;
		ops->seek = &funcRWopsSeek;
		ops->read = &funcRWopsRead;
		ops->write = &funcRWopsWrite;
		ops->close = &funcRWopsClose;

		return ops;
	}
开发者ID:kolyden,项目名称:engine-old,代码行数:13,代码来源:uutStream.cpp

示例14: fileIntForPath

static VALUE
fileIntForPath(const char *path)
{
    SDL_RWops *ops = SDL_AllocRW();
    shState->fileSystem().openRead(*ops, path);

    VALUE klass = rb_const_get(rb_cObject, rb_intern("FileInt"));

    VALUE obj = rb_obj_alloc(klass);

    setPrivateData(obj, ops);

    return obj;
}
开发者ID:BlackLotus,项目名称:mkxp,代码行数:14,代码来源:filesystem-binding.cpp

示例15: SDL_AllocRW

SDL_RWops *SDL_RWFromFP(FILE *fp, int autoclose)
{
    SDL_RWops *rwops = NULL;

    rwops = SDL_AllocRW();
    if ( rwops != NULL ) {
        rwops->seek = stdio_seek;
        rwops->read = stdio_read;
        rwops->write = stdio_write;
        rwops->close = stdio_close;
        rwops->hidden.stdio.fp = fp;
        rwops->hidden.stdio.autoclose = autoclose;
    }
    return(rwops);
}
开发者ID:RDCH106,项目名称:n64oid,代码行数:15,代码来源:SDL_rwops.c


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