mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-28 23:49:12 +00:00
rwops: Reworked RWops for SDL3.
- SDL_RWops is now an opaque struct. - SDL_AllocRW is gone. If an app is creating a custom RWops, they pass the function pointers to SDL_CreateRW(), which are stored internally. - SDL_RWclose is gone, there is only SDL_DestroyRW(), which calls the implementation's `->close` method before freeing other things. - There is only one path to create and use RWops now, so we don't have to worry about whether `->close` will call SDL_DestroyRW, or if this will risk any Properties not being released, etc. - SDL_RWFrom* still works as expected, for getting a RWops without having to supply your own implementation. Objects from these functions are also destroyed with SDL_DestroyRW. - Lots of other cleanup and SDL3ization of the library code.
This commit is contained in:
parent
495e432fb9
commit
525919b315
22 changed files with 424 additions and 470 deletions
|
@ -1956,11 +1956,12 @@ static void Internal_Android_Destroy_AssetManager()
|
|||
}
|
||||
}
|
||||
|
||||
int Android_JNI_FileOpen(SDL_RWops *ctx,
|
||||
const char *fileName, const char *mode)
|
||||
int Android_JNI_FileOpen(void **puserdata, const char *fileName, const char *mode)
|
||||
{
|
||||
SDL_assert(puserdata != NULL);
|
||||
|
||||
AAsset *asset = NULL;
|
||||
ctx->hidden.androidio.asset = NULL;
|
||||
*puserdata = NULL;
|
||||
|
||||
if (!asset_manager) {
|
||||
Internal_Android_Create_AssetManager();
|
||||
|
@ -1975,14 +1976,13 @@ int Android_JNI_FileOpen(SDL_RWops *ctx,
|
|||
return SDL_SetError("Couldn't open asset '%s'", fileName);
|
||||
}
|
||||
|
||||
ctx->hidden.androidio.asset = (void *)asset;
|
||||
*puserdata = (void *)asset;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t Android_JNI_FileRead(SDL_RWops *ctx, void *buffer, size_t size)
|
||||
size_t Android_JNI_FileRead(void *userdata, void *buffer, size_t size)
|
||||
{
|
||||
AAsset *asset = (AAsset *)ctx->hidden.androidio.asset;
|
||||
int bytes = AAsset_read(asset, buffer, size);
|
||||
const int bytes = AAsset_read((AAsset *)userdata, buffer, size);
|
||||
if (bytes < 0) {
|
||||
SDL_SetError("AAsset_read() failed");
|
||||
return 0;
|
||||
|
@ -1990,31 +1990,24 @@ size_t Android_JNI_FileRead(SDL_RWops *ctx, void *buffer, size_t size)
|
|||
return (size_t)bytes;
|
||||
}
|
||||
|
||||
size_t Android_JNI_FileWrite(SDL_RWops *ctx, const void *buffer, size_t size)
|
||||
size_t Android_JNI_FileWrite(void *userdata, const void *buffer, size_t size)
|
||||
{
|
||||
return SDL_SetError("Cannot write to Android package filesystem");
|
||||
}
|
||||
|
||||
Sint64 Android_JNI_FileSize(SDL_RWops *ctx)
|
||||
Sint64 Android_JNI_FileSize(void *userdata)
|
||||
{
|
||||
off64_t result;
|
||||
AAsset *asset = (AAsset *)ctx->hidden.androidio.asset;
|
||||
result = AAsset_getLength64(asset);
|
||||
return result;
|
||||
return (Sint64) AAsset_getLength64((AAsset *)userdata);
|
||||
}
|
||||
|
||||
Sint64 Android_JNI_FileSeek(SDL_RWops *ctx, Sint64 offset, int whence)
|
||||
Sint64 Android_JNI_FileSeek(void *userdata, Sint64 offset, int whence)
|
||||
{
|
||||
off64_t result;
|
||||
AAsset *asset = (AAsset *)ctx->hidden.androidio.asset;
|
||||
result = AAsset_seek64(asset, offset, whence);
|
||||
return result;
|
||||
return (Sint64) AAsset_seek64((AAsset *)userdata, offset, whence);
|
||||
}
|
||||
|
||||
int Android_JNI_FileClose(SDL_RWops *ctx)
|
||||
int Android_JNI_FileClose(void *userdata)
|
||||
{
|
||||
AAsset *asset = (AAsset *)ctx->hidden.androidio.asset;
|
||||
AAsset_close(asset);
|
||||
AAsset_close((AAsset *)userdata);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue