diff --git a/ai/game_ai.cpp b/ai/game_ai.c similarity index 64% rename from ai/game_ai.cpp rename to ai/game_ai.c index 43886554fb5..5d204573633 100644 --- a/ai/game_ai.cpp +++ b/ai/game_ai.c @@ -1,6 +1,6 @@ #include "game_ai.h" #include -#include +#include #include #include @@ -10,28 +10,30 @@ #include #endif +#include + #include "../deps/game_ai_lib/GameAI.h" #define GAME_AI_MAX_PLAYERS 2 -void * ga = nullptr; -volatile void * g_ram_ptr = nullptr; +void * ga = NULL; +volatile void * g_ram_ptr = NULL; volatile int g_ram_size = 0; volatile signed short int g_buttons_bits[GAME_AI_MAX_PLAYERS] = {0}; volatile int g_frameCount = 0; volatile char game_ai_lib_path[1024] = {0}; volatile char g_game_name[1024] = {0}; -retro_log_printf_t g_log = nullptr; +retro_log_printf_t g_log = NULL; /* GameAI Lib API*/ -create_game_ai_t create_game_ai = nullptr; -game_ai_lib_init_t game_ai_lib_init = nullptr; -game_ai_lib_think_t game_ai_lib_think = nullptr; -game_ai_lib_set_show_debug_t game_ai_lib_set_show_debug = nullptr; -game_ai_lib_set_debug_log_t game_ai_lib_set_debug_log = nullptr; +create_game_ai_t create_game_ai = NULL; +game_ai_lib_init_t game_ai_lib_init = NULL; +game_ai_lib_think_t game_ai_lib_think = NULL; +game_ai_lib_set_show_debug_t game_ai_lib_set_show_debug = NULL; +game_ai_lib_set_debug_log_t game_ai_lib_set_debug_log = NULL; /* Helper functions */ -extern "C" void game_ai_debug_log(int level, const char *fmt, ...) +void game_ai_debug_log(int level, const char *fmt, ...) { va_list vp; va_start(vp, fmt); @@ -44,19 +46,19 @@ extern "C" void game_ai_debug_log(int level, const char *fmt, ...) va_end(vp); } -void array_to_bits_16(volatile signed short & result, const bool b[16]) +void array_to_bits_16(volatile signed short * result, const bool b[16]) { for (int bit = 0; bit <= 15; bit++) { - result |= b[bit] ? (1 << bit) : 0; + *result |= b[bit] ? (1 << bit) : 0; } } /* Interface to RA */ -extern "C" signed short int game_ai_input(unsigned int port, unsigned int device, unsigned int idx, unsigned int id, signed short int result) +extern signed short int game_ai_input(unsigned int port, unsigned int device, unsigned int idx, unsigned int id, signed short int result) { - if (ga == nullptr) + if (ga == NULL) return 0; if (port < GAME_AI_MAX_PLAYERS) @@ -65,11 +67,9 @@ extern "C" signed short int game_ai_input(unsigned int port, unsigned int device return 0; } -extern "C" void game_ai_init() +extern void game_ai_init() { - printf("GameAIManager::Init()\n"); - - if (create_game_ai == nullptr) + if (create_game_ai == NULL) { #ifdef _WIN32 HINSTANCE hinstLib; @@ -106,29 +106,27 @@ extern "C" void game_ai_init() { dlinfo(myso, RTLD_DI_ORIGIN, (void *) &game_ai_lib_path); - create_game_ai = reinterpret_cast(dlsym(myso, "create_game_ai")); + create_game_ai = (create_game_ai_t)(dlsym(myso, "create_game_ai")); retro_assert(create_game_ai); - game_ai_lib_init = reinterpret_cast(dlsym(myso, "game_ai_lib_init")); + game_ai_lib_init = (game_ai_lib_init_t)(dlsym(myso, "game_ai_lib_init")); retro_assert(game_ai_lib_init); - game_ai_lib_think = reinterpret_cast(dlsym(myso, "game_ai_lib_think")); + game_ai_lib_think = (game_ai_lib_think_t)(dlsym(myso, "game_ai_lib_think")); retro_assert(game_ai_lib_think); - game_ai_lib_set_show_debug = reinterpret_cast(dlsym(myso, "game_ai_lib_set_show_debug")); + game_ai_lib_set_show_debug = (game_ai_lib_set_show_debug_t)(dlsym(myso, "game_ai_lib_set_show_debug")); retro_assert(game_ai_lib_set_show_debug); - game_ai_lib_set_debug_log = reinterpret_cast(dlsym(myso, "game_ai_lib_set_debug_log")); + game_ai_lib_set_debug_log = (game_ai_lib_set_debug_log_t)(dlsym(myso, "game_ai_lib_set_debug_log")); retro_assert(game_ai_lib_set_debug_log); } #endif } } -extern "C" void game_ai_load(const char * name, void * ram_ptr, int ram_size, retro_log_printf_t log) +extern void game_ai_load(const char * name, void * ram_ptr, int ram_size, retro_log_printf_t log) { - printf("GameAIManager::Load\n"); - strcpy((char *) &g_game_name[0], name); g_ram_ptr = ram_ptr; @@ -137,12 +135,12 @@ extern "C" void game_ai_load(const char * name, void * ram_ptr, int ram_size, re g_log = log; } -extern "C" void game_ai_think(bool override_p1, bool override_p2, bool show_debug, const void *frame_data, unsigned int frame_width, unsigned int frame_height, unsigned int frame_pitch, unsigned int pixel_format) +extern void game_ai_think(bool override_p1, bool override_p2, bool show_debug, const void *frame_data, unsigned int frame_width, unsigned int frame_height, unsigned int frame_pitch, unsigned int pixel_format) { if (ga) game_ai_lib_set_show_debug(ga, show_debug); - if (ga == nullptr && g_ram_ptr != nullptr) + if (ga == NULL && g_ram_ptr != NULL) { ga = create_game_ai((char *) &g_game_name[0]); retro_assert(ga); @@ -154,9 +152,7 @@ extern "C" void game_ai_think(bool override_p1, bool override_p2, bool show_debu strcat(&data_path[0], "/data/"); strcat(&data_path[0], (char *)g_game_name); - game_ai_lib_init(ga, (void *) g_ram_ptr, g_ram_size); - game_ai_lib_set_debug_log(ga, game_ai_debug_log); } } @@ -173,13 +169,13 @@ extern "C" void game_ai_think(bool override_p1, bool override_p2, bool show_debu if (override_p1) { game_ai_lib_think(ga, b, 0, frame_data, frame_width, frame_height, frame_pitch, pixel_format); - array_to_bits_16(g_buttons_bits[0], b); + array_to_bits_16(&g_buttons_bits[0], b); } if (override_p2) { game_ai_lib_think(ga, b, 1, frame_data, frame_width, frame_height, frame_pitch, pixel_format); - array_to_bits_16(g_buttons_bits[1], b); + array_to_bits_16(&g_buttons_bits[1], b); } } g_frameCount=0; diff --git a/deps/game_ai_lib/GameAI.h b/deps/game_ai_lib/GameAI.h index 549174167fa..db0b9c6570b 100644 --- a/deps/game_ai_lib/GameAI.h +++ b/deps/game_ai_lib/GameAI.h @@ -1,16 +1,22 @@ #pragma once +#ifdef __cplusplus + #include #include #include #include #include +#endif + + typedef void (*debug_log_t)(int level, const char *fmt, ...); #define GAMEAI_MAX_BUTTONS 16 #define GAMEAI_SKIPFRAMES 4 + #ifdef __cplusplus class GameAI { diff --git a/griffin/griffin.c b/griffin/griffin.c index 570746d4d4c..eaec707b882 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -1682,3 +1682,10 @@ CLOUD SYNC #include "../network/cloud_sync_driver.c" #include "../network/cloud_sync/webdav.c" #endif + +/*============================================================ +GAME AI +============================================================ */ +#if defined(HAVE_GAME_AI) +#include "../ai/game_ai.c" +#endif \ No newline at end of file diff --git a/griffin/griffin_cpp.cpp b/griffin/griffin_cpp.cpp index 70a32df66c4..c22442a7ba8 100644 --- a/griffin/griffin_cpp.cpp +++ b/griffin/griffin_cpp.cpp @@ -121,10 +121,3 @@ FONTS #endif #endif - -/*============================================================ -GAME AI -============================================================ */ -#if defined(HAVE_GAME_AI) -#include "../ai/game_ai.cpp" -#endif