preliminary code for retro achievements (cheevos)

This commit is contained in:
Andre Leiradella 2015-10-09 13:29:57 -03:00
parent 1b403105e4
commit fa3f17d219
6 changed files with 1606 additions and 31 deletions

View File

@ -235,7 +235,7 @@ OBJ += libretro-db/bintree.o \
libretro-db/rmsgpack_dom.o \
database_info.o \
tasks/task_database.o \
tasks/task_database_cue.o
tasks/task_database_cue.o
endif
# Miscellaneous
@ -604,7 +604,7 @@ ifeq ($(HAVE_GL_CONTEXT), 1)
OBJ += gfx/drivers_context/wayland_ctx.o
endif
endif
ifeq ($(HAVE_GLES), 1)
LIBS += $(GLES_LIBS)
DEFINES += $(GLES_CFLAGS) -DHAVE_OPENGLES -DHAVE_OPENGLES2
@ -626,7 +626,7 @@ ifeq ($(HAVE_GL_CONTEXT), 1)
LIBS += $(GL_LIBS)
endif
OBJ += gfx/drivers_shader/shader_glsl.o
OBJ += gfx/drivers_shader/shader_glsl.o
DEFINES += -DHAVE_GLSL
endif
@ -696,7 +696,7 @@ endif
ifeq ($(HAVE_XVIDEO), 1)
OBJ += gfx/drivers/xvideo.o
LIBS += $(XVIDEO_LIBS)
LIBS += $(XVIDEO_LIBS)
DEFINES += $(XVIDEO_CFLAGS)
endif
@ -733,7 +733,7 @@ endif
ifeq ($(HAVE_7ZIP),1)
CFLAGS += -I./deps/7zip
HAVE_COMPRESSION = 1
HAVE_COMPRESSION = 1
DEFINES += -DHAVE_7ZIP
7ZOBJ = deps/7zip/7zIn.o \
deps/7zip/7zAlloc.o \
@ -758,7 +758,7 @@ ifeq ($(HAVE_ZLIB), 1)
OBJ += $(ZLIB_OBJS)
DEFINES += -DHAVE_ZLIB
HAVE_RPNG = 1
HAVE_COMPRESSION = 1
HAVE_COMPRESSION = 1
ifeq ($(WANT_ZLIB), 1)
DEFINES += -DWANT_ZLIB
else
@ -776,7 +776,8 @@ ifeq ($(HAVE_RPNG), 1)
libretro-common/formats/png/rpng_encode.o
endif
OBJ += libretro-common/formats/bmp/rbmp_encode.o \
libretro-common/formats/tga/rtga.o
libretro-common/formats/tga/rtga.o \
libretro-common/formats/json/jsonsax.o
ifdef HAVE_COMPRESSION
DEFINES += -DHAVE_COMPRESSION
@ -812,6 +813,18 @@ ifeq ($(HAVE_ZLIB_DEFLATE),1)
DEFINES += -DHAVE_ZLIB_DEFLATE
endif
# Retro Achievements
OBJ += cheevos.o
ifeq ($(HAVE_CHEEVOS), 1)
ifeq ($(HAVE_SMW_CHEEVOS), 1)
DEFINES += -DHAVE_SMW_CHEEVOS
endif
DEFINES += -DHAVE_CHEEVOS
endif
# Camera
ifeq ($(HAVE_V4L2),1)
@ -846,7 +859,7 @@ endif
ifeq ($(HAVE_AVFOUNDATION), 1)
ifeq ($(HAVE_COCOA), 1)
DEFINES += -DHAVE_AVFOUNDATION
DEFINES += -DHAVE_AVFOUNDATION
LIBS += -framework AVFoundation
LIBS += -framework CoreVideo
LIBS += -framework CoreMedia
@ -865,7 +878,7 @@ endif
ifeq ($(HAVE_COMPRESSION), 1)
DEFINES += -DHAVE_COMPRESSION
endif
endif
ifeq ($(HAVE_COCOA),1)
DEFINES += -DHAVE_MAIN

1100
cheevos.c Normal file

File diff suppressed because one or more lines are too long

33
cheevos.h Normal file
View File

@ -0,0 +1,33 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RARCH_CHEEVOS_H
#define __RARCH_CHEEVOS_H
typedef struct
{
unsigned char enable;
unsigned char test_unofficial;
}
cheevos_config_t;
extern cheevos_config_t cheevos_config;
int cheevos_load( const char* json );
void cheevos_test();
void cheevos_unload();
#endif /* __RARCH_CHEEVOS_H */

View File

@ -0,0 +1,362 @@
/* Copyright (C) 2010-2015 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (rxml.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <setjmp.h>
#include <string.h>
#include <ctype.h>
#include <retro_inline.h>
#include <formats/jsonsax.h>
#ifdef JSONSAX_ERRORS
const char* jsonsax_errors[] =
{
"Ok",
"Interrupted",
"Missing key",
"Unterminated key",
"Missing value",
"Unterminated object",
"Unterminated array",
"Unterminated string",
"Invalid value"
};
#endif
typedef struct
{
const jsonsax_handlers_t* handlers;
const char* json;
void* ud;
jmp_buf env;
}
state_t;
static INLINE void skip_spaces( state_t* state )
{
while ( isspace( *state->json ) )
{
state->json++;
}
}
static INLINE void skip_digits( state_t* state )
{
while ( isdigit( *state->json ) )
{
state->json++;
}
}
#define HANDLE_0( event ) \
do { \
if ( state->handlers->event && state->handlers->event( state->ud ) ) \
longjmp( state->env, JSONSAX_INTERRUPTED ); \
} while ( 0 )
#define HANDLE_1( event, arg1 ) \
do { \
if ( state->handlers->event && state->handlers->event( state->ud, arg1 ) ) \
longjmp( state->env, JSONSAX_INTERRUPTED ); \
} while ( 0 )
#define HANDLE_2( event, arg1, arg2 ) \
do { \
if ( state->handlers->event && state->handlers->event( state->ud, arg1, arg2 ) ) \
longjmp( state->env, JSONSAX_INTERRUPTED ); \
} while ( 0 )
static void parse_value( state_t* state );
static void parse_object( state_t* state )
{
state->json++; /* we're sure the current character is a '{' */
skip_spaces( state );
HANDLE_0( start_object );
while ( *state->json != '}' )
{
if ( *state->json != '"' )
{
longjmp( state->env, JSONSAX_MISSING_KEY );
}
const char* name = ++state->json;
for ( ;; )
{
const char* quote = strchr( state->json, '"' );
if ( !quote )
{
longjmp( state->env, JSONSAX_UNTERMINATED_KEY );
}
state->json = quote + 1;
if ( quote[ -1 ] != '\\' )
{
break;
}
}
HANDLE_2( key, name, state->json - name - 1 );
skip_spaces( state );
if ( *state->json != ':' )
{
longjmp( state->env, JSONSAX_MISSING_VALUE );
}
state->json++;
skip_spaces( state );
parse_value( state );
skip_spaces( state );
if ( *state->json != ',' )
{
break;
}
state->json++;
skip_spaces( state );
}
if ( *state->json != '}' )
{
longjmp( state->env, JSONSAX_UNTERMINATED_OBJECT );
}
state->json++;
HANDLE_0( end_object );
}
static void parse_array( state_t* state )
{
unsigned int ndx = 0;
state->json++; /* we're sure the current character is a '[' */
skip_spaces( state );
HANDLE_0( start_array );
while ( *state->json != ']' )
{
HANDLE_1( index, ndx++ );
parse_value( state );
skip_spaces( state );
if ( *state->json != ',' )
{
break;
}
state->json++;
skip_spaces( state );
}
if ( *state->json != ']' )
{
longjmp( state->env, JSONSAX_UNTERMINATED_ARRAY );
}
state->json++;
HANDLE_0( end_array );
}
static void parse_string( state_t* state )
{
const char* string = ++state->json;
for ( ;; )
{
const char* quote = strchr( state->json, '"' );
if ( !quote )
{
longjmp( state->env, JSONSAX_UNTERMINATED_STRING );
}
state->json = quote + 1;
if ( quote[ -1 ] != '\\' )
{
break;
}
}
HANDLE_2( string, string, state->json - string - 1 );
}
static void parse_boolean( state_t* state )
{
if ( !strncmp( state->json, "true", 4 ) )
{
state->json += 4;
HANDLE_1( boolean, 1 );
}
else if ( !strncmp( state->json, "false", 5 ) )
{
state->json += 5;
HANDLE_1( boolean, 0 );
}
else
{
longjmp( state->env, JSONSAX_INVALID_VALUE );
}
}
static void parse_null( state_t* state )
{
if ( !strncmp( state->json + 1, "ull", 3 ) ) /* we're sure the current character is a 'n' */
{
state->json += 4;
HANDLE_0( null );
}
else
{
longjmp( state->env, JSONSAX_INVALID_VALUE );
}
}
static void parse_number( state_t* state )
{
const char* number = state->json;
if ( *state->json == '-' )
{
state->json++;
}
if ( !isdigit( *state->json ) )
{
longjmp( state->env, JSONSAX_INVALID_VALUE );
}
skip_digits( state );
if ( *state->json == '.' )
{
state->json++;
if ( !isdigit( *state->json ) )
{
longjmp( state->env, JSONSAX_INVALID_VALUE );
}
skip_digits( state );
}
if ( *state->json == 'e' || *state->json == 'E' )
{
state->json++;
if ( *state->json == '-' || *state->json == '+' )
{
state->json++;
}
if ( !isdigit( *state->json ) )
{
longjmp( state->env, JSONSAX_INVALID_VALUE );
}
skip_digits( state );
}
HANDLE_2( number, number, state->json - number );
}
static void parse_value( state_t* state )
{
skip_spaces( state );
switch ( *state->json )
{
case '{':
parse_object( state );
break;
case '[':
parse_array( state );
break;
case '"':
parse_string( state );
break;
case 't':
case 'f':
parse_boolean( state );
break;
case 'n':
parse_null( state );
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
parse_number( state );
break;
default:
longjmp( state->env, JSONSAX_INVALID_VALUE );
}
}
int jsonsax_parse( const char* json, const jsonsax_handlers_t* handlers, void* userdata )
{
state_t state;
int res;
state.json = json;
state.handlers = handlers;
state.ud = userdata;
if ( ( res = setjmp( state.env ) ) == 0 )
{
if ( handlers->start_document )
{
handlers->start_document( userdata );
}
parse_value( &state );
if ( handlers->end_document )
{
handlers->end_document( userdata );
}
res = JSONSAX_OK;
}
return res;
}

View File

@ -0,0 +1,64 @@
/* Copyright (C) 2010-2015 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (rxml.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_FORMAT_JSONSAX_H__
#define __LIBRETRO_SDK_FORMAT_JSONSAX_H__
#include <stddef.h>
enum
{
JSONSAX_OK = 0,
JSONSAX_INTERRUPTED,
JSONSAX_MISSING_KEY,
JSONSAX_UNTERMINATED_KEY,
JSONSAX_MISSING_VALUE,
JSONSAX_UNTERMINATED_OBJECT,
JSONSAX_UNTERMINATED_ARRAY,
JSONSAX_UNTERMINATED_STRING,
JSONSAX_INVALID_VALUE
};
#ifdef JSONSAX_ERRORS
extern const char* jsonsax_errors[];
#endif
typedef struct
{
int ( *start_document )( void* userdata );
int ( *end_document )( void* userdata );
int ( *start_object )( void* userdata );
int ( *end_object )( void* userdata );
int ( *start_array )( void* userdata );
int ( *end_array )( void* userdata );
int ( *key )( void* userdata, const char* name, size_t length );
int ( *index )( void* userdata, unsigned int index );
int ( *string )( void* userdata, const char* string, size_t length );
int ( *number )( void* userdata, const char* number, size_t length );
int ( *boolean )( void* userdata, int istrue );
int ( *null )( void* userdata );
}
jsonsax_handlers_t;
int jsonsax_parse( const char* json, const jsonsax_handlers_t* handlers, void* userdata );
#endif /* __LIBRETRO_SDK_FORMAT_JSONSAX_H__ */

View File

@ -22,6 +22,7 @@
#include <compat/strl.h>
#include "cheevos.h"
#include "configuration.h"
#include "performance.h"
#include "retroarch.h"
@ -57,7 +58,7 @@ static retro_time_t frame_limit_minimum_time;
* @pressed : was libretro pause key pressed?
* @frameadvance_pressed : was frameadvance key pressed?
*
* Check if libretro pause key was pressed. If so, pause or
* Check if libretro pause key was pressed. If so, pause or
* unpause the libretro core.
*
* Returns: true if libretro pause key was toggled, otherwise false.
@ -102,7 +103,7 @@ static bool check_pause(driver_t *driver, settings_t *settings,
* @hold_pressed : is fastforward key pressed and held?
* @old_hold_pressed : was fastforward key pressed and held the last frame?
*
* Checks if the fast forward key has been pressed for this frame.
* Checks if the fast forward key has been pressed for this frame.
*
**/
static void check_fast_forward_button(driver_t *driver,
@ -110,7 +111,7 @@ static void check_fast_forward_button(driver_t *driver,
bool hold_pressed, bool old_hold_pressed)
{
/* To avoid continous switching if we hold the button down, we require
* that the button must go from pressed to unpressed back to pressed
* that the button must go from pressed to unpressed back to pressed
* to be able to toggle between then.
*/
if (fastforward_pressed)
@ -128,8 +129,8 @@ static void check_fast_forward_button(driver_t *driver,
* @pressed_increase : is state slot increase key pressed?
* @pressed_decrease : is state slot decrease key pressed?
*
* Checks if the state increase/decrease keys have been pressed
* for this frame.
* Checks if the state increase/decrease keys have been pressed
* for this frame.
**/
static void check_stateslots(settings_t *settings,
bool pressed_increase, bool pressed_decrease)
@ -238,7 +239,7 @@ static void check_rewind(settings_t *settings,
* @pressed_next : was next shader key pressed?
* @pressed_previous : was previous shader key pressed?
*
* Checks if any one of the shader keys has been pressed for this frame:
* Checks if any one of the shader keys has been pressed for this frame:
* a) Next shader index.
* b) Previous shader index.
*
@ -347,7 +348,7 @@ bool rarch_main_ctl(enum rarch_main_ctl_state state, void *data)
}
#endif
check_pause(driver, settings,
check_pause(driver, settings,
cmd->pause_pressed, cmd->frameadvance_pressed);
if (!rarch_main_ctl(RARCH_MAIN_CTL_CHECK_PAUSE_STATE, cmd))
@ -379,7 +380,7 @@ bool rarch_main_ctl(enum rarch_main_ctl_state state, void *data)
else if (cmd->disk_next_pressed)
event_command(EVENT_CMD_DISK_NEXT);
else if (cmd->disk_prev_pressed)
event_command(EVENT_CMD_DISK_PREV);
event_command(EVENT_CMD_DISK_PREV);
if (cmd->reset_pressed)
event_command(EVENT_CMD_RESET);
@ -613,19 +614,19 @@ static bool check_block_hotkey(driver_t *driver, settings_t *settings,
bool enable_hotkey)
{
bool use_hotkey_enable;
const struct retro_keybind *bind =
const struct retro_keybind *bind =
&settings->input.binds[0][RARCH_ENABLE_HOTKEY];
const struct retro_keybind *autoconf_bind =
const struct retro_keybind *autoconf_bind =
&settings->input.autoconf_binds[0][RARCH_ENABLE_HOTKEY];
/* Don't block the check to RARCH_ENABLE_HOTKEY
* unless we're really supposed to. */
driver->block_hotkey =
driver->block_hotkey =
input_driver_keyboard_mapping_is_blocked();
/* If we haven't bound anything to this,
/* If we haven't bound anything to this,
* always allow hotkeys. */
use_hotkey_enable =
use_hotkey_enable =
(bind->key != RETROK_UNKNOWN)
|| (bind->joykey != NO_BTN)
|| (bind->joyaxis != AXIS_NONE)
@ -633,11 +634,11 @@ static bool check_block_hotkey(driver_t *driver, settings_t *settings,
|| (autoconf_bind->joykey != NO_BTN)
|| (autoconf_bind->joyaxis != AXIS_NONE);
driver->block_hotkey =
driver->block_hotkey =
input_driver_keyboard_mapping_is_blocked() ||
(use_hotkey_enable && !enable_hotkey);
/* If we hold ENABLE_HOTKEY button, block all libretro input to allow
/* If we hold ENABLE_HOTKEY button, block all libretro input to allow
* hotkeys to be bound to same keys as RetroPad. */
return (use_hotkey_enable && enable_hotkey);
}
@ -659,7 +660,7 @@ static INLINE retro_input_t input_keys_pressed(driver_t *driver,
unsigned i;
const struct retro_keybind *binds[MAX_USERS];
retro_input_t ret = 0;
for (i = 0; i < MAX_USERS; i++)
binds[i] = settings->input.binds[i];
@ -685,7 +686,7 @@ static INLINE retro_input_t input_keys_pressed(driver_t *driver,
if (!driver->block_libretro_input)
{
for (i = 0; i < settings->input.max_users; i++)
global->turbo.frame_enable[i] = input_driver_state(binds,
global->turbo.frame_enable[i] = input_driver_state(binds,
i, RETRO_DEVICE_JOYPAD, 0, RARCH_TURBO_ENABLE);
}
@ -824,7 +825,7 @@ static void rarch_main_cmd_get_state(driver_t *driver,
RARCH_CHEAT_TOGGLE);
}
/* Time to exit out of the main loop?
/* Time to exit out of the main loop?
* Reasons for exiting:
* a) Shutdown environment callback was invoked.
* b) Quit key was pressed.
@ -851,7 +852,7 @@ static INLINE int rarch_main_iterate_time_to_exit(event_cmd_state_t *cmd)
global->exec = false;
/* Quits out of RetroArch main loop.
* On special case, loads dummy core
* On special case, loads dummy core
* instead of exiting RetroArch completely.
* Aborts core shutdown if invoked.
*/
@ -879,7 +880,7 @@ static INLINE int rarch_main_iterate_time_to_exit(event_cmd_state_t *cmd)
* Run Libretro core in RetroArch for one frame.
*
* Returns: 0 on success, 1 if we have to wait until button input in order
* to wake up the loop, -1 if we forcibly quit out of the RetroArch iteration loop.
* to wake up the loop, -1 if we forcibly quit out of the RetroArch iteration loop.
**/
int rarch_main_iterate(unsigned *sleep_ms)
{
@ -923,7 +924,7 @@ int rarch_main_iterate(unsigned *sleep_ms)
retro_time_t current = retro_get_time_usec();
retro_time_t delta = current - system->frame_time_last;
bool is_locked_fps = (main_is_paused || driver->nonblock_state) |
bool is_locked_fps = (main_is_paused || driver->nonblock_state) |
!!driver->recording_data;
if (!system->frame_time_last || is_locked_fps)
@ -974,7 +975,7 @@ int rarch_main_iterate(unsigned *sleep_ms)
if (ret != 1)
return -1;
#ifdef HAVE_MENU
if (menu_driver_alive())
{
@ -1027,6 +1028,8 @@ int rarch_main_iterate(unsigned *sleep_ms)
/* Run libretro for one frame. */
core.retro_run();
/* Test the achievements. */
cheevos_test();
for (i = 0; i < settings->input.max_users; i++)
{