android: allow starting games with intent while a game is running
stops and unload the current game then starts the new one
This commit is contained in:
parent
19a160695c
commit
329e5ed467
|
@ -78,7 +78,8 @@ static GameScanner scanner;
|
|||
static BackgroundGameLoader gameLoader;
|
||||
static Boxart boxart;
|
||||
static Chat chat;
|
||||
static std::mutex guiMutex;
|
||||
static std::recursive_mutex guiMutex;
|
||||
using LockGuard = std::lock_guard<std::recursive_mutex>;
|
||||
|
||||
static void emuEventCallback(Event event, void *)
|
||||
{
|
||||
|
@ -447,7 +448,7 @@ void gui_plot_render_time(int width, int height)
|
|||
|
||||
void gui_open_settings()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(guiMutex);
|
||||
const LockGuard lock(guiMutex);
|
||||
if (gui_state == GuiState::Closed)
|
||||
{
|
||||
if (!ggpo::active())
|
||||
|
@ -477,6 +478,7 @@ void gui_open_settings()
|
|||
|
||||
void gui_start_game(const std::string& path)
|
||||
{
|
||||
const LockGuard lock(guiMutex);
|
||||
emu.unloadGame();
|
||||
reset_vmus();
|
||||
chat.reset();
|
||||
|
@ -488,6 +490,7 @@ void gui_start_game(const std::string& path)
|
|||
|
||||
void gui_stop_game(const std::string& message)
|
||||
{
|
||||
const LockGuard lock(guiMutex);
|
||||
if (!commandLineStart)
|
||||
{
|
||||
// Exit to main menu
|
||||
|
@ -2725,7 +2728,7 @@ static void gui_display_loadscreen()
|
|||
void gui_display_ui()
|
||||
{
|
||||
FC_PROFILE_SCOPE;
|
||||
std::lock_guard<std::mutex> lock(guiMutex);
|
||||
const LockGuard lock(guiMutex);
|
||||
|
||||
if (gui_state == GuiState::Closed || gui_state == GuiState::VJoyEdit)
|
||||
return;
|
||||
|
|
|
@ -286,21 +286,36 @@ extern "C" JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_setExterna
|
|||
gui_refresh_files();
|
||||
}
|
||||
|
||||
static void stopEmu()
|
||||
{
|
||||
if (!emu.running())
|
||||
game_started = false;
|
||||
else
|
||||
emu.stop();
|
||||
// in single-threaded mode, stopping is delayed
|
||||
while (game_started)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_setGameUri(JNIEnv *env,jobject obj,jstring fileName)
|
||||
{
|
||||
if (fileName != NULL)
|
||||
{
|
||||
if (fileName == nullptr)
|
||||
return;
|
||||
|
||||
// Get filename string from Java
|
||||
const char* file_path = env->GetStringUTFChars(fileName, 0);
|
||||
if (file_path[0] != '\0')
|
||||
{
|
||||
NOTICE_LOG(BOOT, "Game Disk URI: '%s'", file_path);
|
||||
settings.content.path = strlen(file_path) >= 7 && !memcmp(file_path, "file://", 7) ? file_path + 7 : file_path;
|
||||
if (game_started)
|
||||
{
|
||||
stopEmu();
|
||||
gui_stop_game();
|
||||
}
|
||||
std::string path = strlen(file_path) >= 7 && !memcmp(file_path, "file://", 7) ? file_path + 7 : file_path;
|
||||
gui_start_game(path);
|
||||
}
|
||||
env->ReleaseStringUTFChars(fileName, file_path);
|
||||
// TODO game paused/settings/...
|
||||
if (game_started) {
|
||||
emu.unloadGame();
|
||||
gui_state = GuiState::Main;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//stuff for microphone
|
||||
|
@ -324,17 +339,6 @@ extern "C" JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_setupMic(J
|
|||
stopRecordingMid = env->GetMethodID(env->GetObjectClass(sipemu),"stopRecording","()V");
|
||||
}
|
||||
|
||||
static void stopEmu()
|
||||
{
|
||||
if (!emu.running())
|
||||
game_started = false;
|
||||
else
|
||||
emu.stop();
|
||||
// in single-threaded mode, stopping is delayed
|
||||
while (game_started)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_pause(JNIEnv *env,jobject obj)
|
||||
{
|
||||
if (emu.running())
|
||||
|
|
Loading…
Reference in New Issue