From ed57fac3c979d57e7c4259bc7aca6ba61146b33a Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Tue, 8 Jul 2014 23:44:09 +0300 Subject: [PATCH] Cloud save: more stubs, using Biniax as a sample app --- .../googleplaygameservices/CloudSave.java | 29 ++++++++++++++++++- .../biniax2/AndroidAppSettings.cfg | 3 +- project/jni/application/biniax2/src/biniax.c | 17 +++++++++++ project/jni/application/biniax2/src/gfx.c | 24 ++++++++++++++- project/jni/application/biniax2/src/gfx.h | 13 ++++++--- project/jni/application/biniax2/src/inp.c | 24 +++++++++++++++ project/jni/application/biniax2/src/inp.h | 4 +++ project/jni/sdl-1.2/include/SDL_android.h | 23 +++++++++++++++ .../src/video/android/SDL_androidvideo.c | 15 ++++++++++ 9 files changed, 145 insertions(+), 7 deletions(-) diff --git a/project/java/googleplaygameservices/CloudSave.java b/project/java/googleplaygameservices/CloudSave.java index 0baae561c..a6c40df3a 100644 --- a/project/java/googleplaygameservices/CloudSave.java +++ b/project/java/googleplaygameservices/CloudSave.java @@ -29,7 +29,8 @@ public class CloudSave implements GameHelper.GameHelperListener { MainActivity parent; - /** Constructs a BaseGameActivity with default client (GamesClient). */ + // ===== Public API ===== + public CloudSave(MainActivity p) { Log.i("SDL", "CloudSave: initializing"); @@ -51,6 +52,32 @@ public class CloudSave implements GameHelper.GameHelperListener { mHelper.onStop(); } + public boolean save(String filename, String description, String imageFile) + { + return false; + } + + public boolean load (String filename) + { + return false; + } + + public class loadDialogResult + { + public boolean status = false; + public String filename = ""; + } + + public loadDialogResult loadDialog(String filename, String dialogTitle) + { + loadDialogResult res = new loadDialogResult(); + res.status = false; + res.filename = ""; + return res; + } + + // ===== Private API ===== + public void onActivityResult(int request, int response, Intent data) { mHelper.onActivityResult(request, response, data); } diff --git a/project/jni/application/biniax2/AndroidAppSettings.cfg b/project/jni/application/biniax2/AndroidAppSettings.cfg index 32397a694..34f5e982c 100644 --- a/project/jni/application/biniax2/AndroidAppSettings.cfg +++ b/project/jni/application/biniax2/AndroidAppSettings.cfg @@ -72,7 +72,7 @@ CompatibilityHacksForceScreenUpdate=n # Application does not call SDL_Flip() or SDL_UpdateRects() after mouse click (ScummVM and all Amiga emulators do that) - # force screen update by moving mouse cursor a little after each click (y) or (n) -CompatibilityHacksForceScreenUpdateMouseClick=y +CompatibilityHacksForceScreenUpdateMouseClick=n # Application initializes SDL audio/video inside static constructors (which is bad, you won't be able to run ndk-gdb) (y)/(n) CompatibilityHacksStaticInit=n @@ -259,3 +259,4 @@ AdmobBannerSize= # Google Play Game Services application ID, required for cloud saves to work GooglePlayGameServicesId=520035027247 + diff --git a/project/jni/application/biniax2/src/biniax.c b/project/jni/application/biniax2/src/biniax.c index bf9d4499c..6f2d9f5e7 100644 --- a/project/jni/application/biniax2/src/biniax.c +++ b/project/jni/application/biniax2/src/biniax.c @@ -702,6 +702,20 @@ BNX_INT16 gameSession( BNX_GAME *game ) } } } + else if ( inpKeySave() ) + { + if ( game->mode != cModeMultiplayer && game->ingame == BNX_TRUE ) + { + saveGame( &Game ); + } + } + else if ( inpKeyLoad() ) + { + if ( game->mode != cModeMultiplayer && game->ingame == BNX_TRUE ) + { + loadGame( &Game ); + } + } if ( game->ingame == BNX_TRUE ) { @@ -1237,6 +1251,7 @@ BNX_BOOL saveGame( BNX_GAME *game ) sysFPut16( game->level_count, file ); fclose( file ); + SDL_ANDROID_CloudSave( sysGetFullFileName( csSaveGameName ) ); return BNX_TRUE; } @@ -1247,6 +1262,8 @@ BNX_BOOL loadGame( BNX_GAME *game ) BNX_INT32 i; BNX_INT32 j; + SDL_ANDROID_CloudLoad( sysGetFullFileName( csSaveGameName ) ); + if ( sysGetFileLen( sysGetFullFileName( csSaveGameName ) ) != cSaveFileSize ) return BNX_FALSE; file = fopen( sysGetFullFileName( csSaveGameName ), "rb" ); diff --git a/project/jni/application/biniax2/src/gfx.c b/project/jni/application/biniax2/src/gfx.c index 043a894e8..874eff567 100644 --- a/project/jni/application/biniax2/src/gfx.c +++ b/project/jni/application/biniax2/src/gfx.c @@ -291,6 +291,11 @@ void gfxRenderGame( BNX_GAME *game ) /* RENDER CLEARS LEFT */ sprintf( text, " %02d", game->clears ); gfxPrintText( cGfxClearsTX, cGfxClearsTY, text ); + + sprintf( text, "SAVE" ); + gfxPrintText( _BNX_BOXES[ cGfxIndSave ].x1, _BNX_BOXES[ cGfxIndSave ].y1, text ); + sprintf( text, "LOAD" ); + gfxPrintText( _BNX_BOXES[ cGfxIndLoad ].x1, _BNX_BOXES[ cGfxIndLoad ].y1, text ); } else if ( game->mode == cModeRealtime ) { @@ -308,6 +313,11 @@ void gfxRenderGame( BNX_GAME *game ) /* RENDER CLEARS LEFT */ sprintf( text, " %02d", game->clears ); gfxPrintText( cGfxClearsAX, cGfxClearsAY, text ); + + sprintf( text, "SAVE" ); + gfxPrintText( _BNX_BOXES[ cGfxIndSave ].x1, _BNX_BOXES[ cGfxIndSave ].y1, text ); + sprintf( text, "LOAD" ); + gfxPrintText( _BNX_BOXES[ cGfxIndLoad ].x1, _BNX_BOXES[ cGfxIndLoad ].y1, text ); } /* PARTICLES */ @@ -362,9 +372,9 @@ void gfxRenderGame( BNX_GAME *game ) break; } } + gfxPrintText( _BNX_BOXES[ cGfxIndEscape ].x1, _BNX_BOXES[ cGfxIndEscape ].y1, "EXIT" ); } - prevIngame = game->ingame; prevClears = game->clears; } @@ -499,6 +509,8 @@ void gfxRenderHelp( BNX_INT16 *line ) y += cGfxHelpDY; } *line = l; + + gfxPrintText( _BNX_BOXES[ cGfxIndEscape ].x1, _BNX_BOXES[ cGfxIndEscape ].y1, "EXIT" ); } void gfxRenderHof( BNX_HALL *hof, BNX_INT16 hofview ) @@ -568,6 +580,8 @@ void gfxRenderHof( BNX_HALL *hof, BNX_INT16 hofview ) } count ++; + gfxPrintText( _BNX_BOXES[ cGfxIndEscape ].x1, _BNX_BOXES[ cGfxIndEscape ].y1, "EXIT" ); + gfxUpdateParticles(); gfxRenderParticles(); } @@ -919,6 +933,14 @@ void gfxGetVirtualKey( BNX_GAME *game, BNX_INP *inp ) { inp->keyB = BNX_TRUE; } + else if ( gfxInBox( inp->mouseX, inp->mouseY, &(_BNX_BOXES[ cGfxIndSave ]) ) == BNX_TRUE ) + { + inp->keySave = BNX_TRUE; + } + else if ( gfxInBox( inp->mouseX, inp->mouseY, &(_BNX_BOXES[ cGfxIndLoad ]) ) == BNX_TRUE ) + { + inp->keyLoad = BNX_TRUE; + } /* Try to detect Ingame Space press */ else { diff --git a/project/jni/application/biniax2/src/gfx.h b/project/jni/application/biniax2/src/gfx.h index 10bfdb350..7466cad14 100644 --- a/project/jni/application/biniax2/src/gfx.h +++ b/project/jni/application/biniax2/src/gfx.h @@ -67,7 +67,8 @@ GRAPHICS CONSTANTS #define cGfxScoreX 30 #define cGfxScoreY 54 -#define cGfxBestX 330 +#define cGfxBestX 230 +#define cGfxBestY 54 #define cGfxBestY 54 #define cGfxScore1X 30 #define cGfxScore1Y 28 @@ -154,6 +155,8 @@ enum { cGfxIndEscape, cGfxIndSpaceR, cGfxIndSpaceT, + cGfxIndSave, + cGfxIndLoad, cGfxIndMax, }; typedef struct BNX_BOX @@ -165,10 +168,12 @@ typedef struct BNX_BOX } BNX_BOX; static BNX_BOX _BNX_BOXES[ cGfxIndMax ] = { - { 18, 128, 656, 588 }, - { 715, 0, 800, 40 }, + { 18, 128, 656, 588 }, + { 730, 0, 800, 60 }, { 680, 310, 780, 380 }, - { 680, 515, 780, 580 } + { 680, 515, 780, 580 }, + { 430, cGfxScoreY, 530, cGfxScoreY + 50 }, + { 530, cGfxScoreY, 630, cGfxScoreY + 50 }, }; static BNX_BOX _BNX_MENU_BOXES[ cMaxOptions ] = { diff --git a/project/jni/application/biniax2/src/inp.c b/project/jni/application/biniax2/src/inp.c index f7451fc0f..450b356b7 100644 --- a/project/jni/application/biniax2/src/inp.c +++ b/project/jni/application/biniax2/src/inp.c @@ -53,6 +53,8 @@ BNX_BOOL inpInit() _Inp.keyB = BNX_FALSE; _Inp.keyQuit = BNX_FALSE; _Inp.keyDel = BNX_FALSE; + _Inp.keySave = BNX_FALSE; + _Inp.keyLoad = BNX_FALSE; _Inp.mousePress = BNX_FALSE; _Inp.mouseX = 0; @@ -310,6 +312,28 @@ BNX_BOOL inpKeyDel() return BNX_FALSE; } +BNX_BOOL inpKeySave() +{ + if ( _Inp.keySave == BNX_TRUE ) + { + _Inp.keySave = BNX_FALSE; + return BNX_TRUE; + } + + return BNX_FALSE; +} + +BNX_BOOL inpKeyLoad() +{ + if ( _Inp.keyLoad == BNX_TRUE ) + { + _Inp.keyLoad = BNX_FALSE; + return BNX_TRUE; + } + + return BNX_FALSE; +} + BNX_BOOL inpExit() { return _Inp.keyQuit; diff --git a/project/jni/application/biniax2/src/inp.h b/project/jni/application/biniax2/src/inp.h index 89160ccd8..d42add5bc 100644 --- a/project/jni/application/biniax2/src/inp.h +++ b/project/jni/application/biniax2/src/inp.h @@ -58,6 +58,8 @@ typedef struct BNX_INP BNX_BOOL keyC; BNX_BOOL keyQuit; BNX_BOOL keyDel; + BNX_BOOL keySave; + BNX_BOOL keyLoad; BNX_BOOL mousePress; BNX_INT16 mouseX; @@ -93,6 +95,8 @@ BNX_BOOL inpKeyA(); BNX_BOOL inpKeyB(); BNX_BOOL inpKeyC(); BNX_BOOL inpKeyDel(); +BNX_BOOL inpKeySave(); +BNX_BOOL inpKeyLoad(); BNX_BOOL inpExit(); char inpGetChar(); diff --git a/project/jni/sdl-1.2/include/SDL_android.h b/project/jni/sdl-1.2/include/SDL_android.h index 14295a5d8..21afb507e 100644 --- a/project/jni/sdl-1.2/include/SDL_android.h +++ b/project/jni/sdl-1.2/include/SDL_android.h @@ -93,6 +93,29 @@ extern DECLSPEC int SDLCALL SDL_ANDROID_OpenAudioRecording(SDL_AudioSpec *spec); /* Close audio recording device, SDL_Init(SDL_INIT_AUDIO) has to be done before calling this function. */ extern DECLSPEC void SDLCALL SDL_ANDROID_CloseAudioRecording(void); +/* +Save the file to the cloud, filename must be already present on disk. +This function will block, until user signs in to the cloud account, and presses Save button. +Description and imageFile may be NULL. +Returns 1 if save succeeded, 0 if user aborted sign-in, or there was no network available. +*/ +extern DECLSPEC int SDLCALL SDL_ANDROID_CloudSave(const char * filename, const char * description, const char * imageFile); + +/* +Load the specified file from the cloud. +This function will block, until user signs in to the cloud account. +Returns 1 if load succeeded, 0 if user aborted sign-in, or there was no network available. +*/ +extern DECLSPEC int SDLCALL SDL_ANDROID_CloudLoad(const char *filename); + +/* +Show the file loading dialog, to allow user to pick up a file from the cloud. +This function will block, until user signs in to the cloud account, and selects a file. +The resulting filename is written to the filename buffer, which must be 512 bytes or more. +dialogTitle may be NULL. +Returns 1 if load succeeded, 0 if user aborted sign-in, or there was no network available. +*/ +extern DECLSPEC int SDLCALL SDL_ANDROID_CloudLoadDialog(char *filename, int len, const char *dialogTitle); #ifdef __cplusplus } diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c index 3527e404a..d55f6d114 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c @@ -467,6 +467,21 @@ int SDLCALL SDL_ANDROID_RequestNewAdvertisement(void) return 1; } +int SDLCALL SDL_ANDROID_CloudSave(const char * filename, const char * description, const char * imageFile) +{ + return 0; +} + +int SDLCALL SDL_ANDROID_CloudLoad(const char *filename) +{ + return 0; +} + +int SDLCALL SDL_ANDROID_CloudLoadDialog(char *filename, int len, const char *dialogTitle) +{ + return 0; +} + // Dummy callback for SDL2 to satisfy linker extern void SDL_Android_Init(JNIEnv* env, jclass cls); void SDL_Android_Init(JNIEnv* env, jclass cls)