OSDN Git Service

[QT][EMU][OSD] Adjust emulation sequence.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 19 Apr 2019 10:29:50 +0000 (19:29 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 19 Apr 2019 10:29:50 +0000 (19:29 +0900)
[QT][MENU_FLAGS] Fix TYPO.

source/src/qt/common/emu_thread.cpp
source/src/qt/common/emu_thread.h
source/src/qt/common/qt_utils.cpp
source/src/qt/gui/CMakeLists.txt
source/src/qt/gui/emu_thread_tmpl.cpp
source/src/qt/gui/emu_thread_tmpl.h
source/src/qt/gui/joy_thread.cpp
source/src/qt/gui/menu_flags.h
source/src/qt/osd_sound.cpp

index 81b1e77..842f886 100644 (file)
@@ -305,9 +305,43 @@ void EmuThreadClass::get_bubble_string(void)
 
 extern QStringList virtualMediaList; // {TYPE, POSITION}
 
+void EmuThreadClass::resetEmu()
+{
+       clear_key_queue();
+       p_emu->reset();
+}
+
+void EmuThreadClass::specialResetEmu()
+{
+#ifdef USE_SPECIAL_RESET
+       p_emu->special_reset();
+#endif
+}
+
+void EmuThreadClass::loadState()
+{
+#ifdef USE_STATE
+       if(!lStateFile.isEmpty()) {
+               p_emu->load_state(lStateFile.toLocal8Bit().constData());
+               lStateFile.clear();
+       }
+#endif
+}
+
+void EmuThreadClass::saveState()
+{
+#ifdef USE_STATE
+       if(!sStateFile.isEmpty()) {
+               p_emu->save_state(sStateFile.toLocal8Bit().constData());
+               sStateFile.clear();
+       }
+#endif
+}
+
 void EmuThreadClass::doWork(const QString &params)
 {
-       int interval = 0, sleep_period = 0;
+       int interval = 0;
+       int64_t sleep_period = 0;
        int run_frames;
        qint64 current_time;
        bool first = true;
@@ -343,8 +377,12 @@ void EmuThreadClass::doWork(const QString &params)
        bStopRecordSoundReq = false;
        bStartRecordMovieReq = false;
        sStateFile.clear();
+       lStateFile.clear();
        record_fps = -1;
 
+       tick_timer.start();
+       update_fps_time = tick_timer.elapsed();
+       //update_fps_time = SDL_GetTicks();
        next_time = 0;
        mouse_flag = false;
 
@@ -374,6 +412,8 @@ void EmuThreadClass::doWork(const QString &params)
        for(int i = 0; i < using_flags->get_max_bubble(); i++) bubble_text[i].clear();
 
        _queue_begin = parse_command_queue(virtualMediaList, 0);
+       //SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "2");
+       
        do {
                //p_emu->SetHostCpus(this->idealThreadCount());
                if(MainWindow == NULL) {
@@ -381,6 +421,7 @@ void EmuThreadClass::doWork(const QString &params)
                                goto _exit;
                        }
                        msleep(10);
+                       //SDL_Delay(10);
                        continue;
                }
                if(first) {
@@ -394,48 +435,37 @@ void EmuThreadClass::doWork(const QString &params)
                sleep_period = 0;
                if(p_emu) {
                        // drive machine
-#ifdef USE_STATE
                        if(bLoadStateReq != false) {
-                               if(!sStateFile.isEmpty()) {
-                                       p_emu->load_state(sStateFile.toLocal8Bit().constData());
-                                       sStateFile.clear();
-                               }
+                               loadState();
                                bLoadStateReq = false;
                                req_draw = true;
                        }
-#endif                 
+
                        if(bResetReq != false) {
-                               clear_key_queue();
-                               p_emu->reset();
+                               resetEmu();
                                bResetReq = false;
                                req_draw = true;
                        }
-#ifdef USE_SPECIAL_RESET
                        if(bSpecialResetReq != false) {
-                               p_emu->special_reset();
+                               specialResetEmu();
                                bSpecialResetReq = false;
                        }
-#endif
-
-#ifdef USE_STATE
                        if(bSaveStateReq != false) {
-                               if(!sStateFile.isEmpty()) {
-                                       p_emu->save_state(sStateFile.toLocal8Bit().constData());
-                                       sStateFile.clear();
-                               }
+                               saveState();
                                bSaveStateReq = false;
                        }
-#endif
-#if defined(USE_MINIMUM_RENDERING)
-                       if((vert_line_bak != config.opengl_scanline_vert) ||
-                          (horiz_line_bak != config.opengl_scanline_horiz) ||
-                          (gl_crt_filter_bak != config.use_opengl_filters) ||
-                          (opengl_filter_num_bak != config.opengl_filter_num)) req_draw = true;
-                       vert_line_bak = config.opengl_scanline_vert;
-                       horiz_line_bak = config.opengl_scanline_horiz;
-                       gl_crt_filter_bak = config.use_opengl_filters;
-                       opengl_filter_num_bak = config.opengl_filter_num;
-#endif
+
+                       if(using_flags->is_use_minimum_rendering()) {
+                               if((vert_line_bak != config.opengl_scanline_vert) ||
+                                  (horiz_line_bak != config.opengl_scanline_horiz) ||
+                                  (gl_crt_filter_bak != config.use_opengl_filters) ||
+                                  (opengl_filter_num_bak != config.opengl_filter_num)) req_draw = true;
+                               vert_line_bak = config.opengl_scanline_vert;
+                               horiz_line_bak = config.opengl_scanline_horiz;
+                               gl_crt_filter_bak = config.use_opengl_filters;
+                               opengl_filter_num_bak = config.opengl_filter_num;
+                       }
+
                        if(bStartRecordSoundReq != false) {
                                p_emu->start_record_sound();
                                bStartRecordSoundReq = false;
@@ -525,11 +555,16 @@ void EmuThreadClass::doWork(const QString &params)
                        }
                        run_frames = p_emu->run();
                        total_frames += run_frames;
+                       if(using_flags->is_use_minimum_rendering()) {
 #if defined(USE_MINIMUM_RENDERING)
-                       req_draw |= p_emu->is_screen_changed();
+                               req_draw |= p_emu->is_screen_changed();
 #else
-                       req_draw = true;
+                               req_draw = true;
 #endif
+                       } else {
+                               req_draw = true;
+                       }
+
 #if defined(USE_KEY_LOCKED) && !defined(INDEPENDENT_CAPS_KANA_LED)
                        led_data = p_emu->get_caps_locked() ? 0x01 : 0x00;
                        led_data |= (p_emu->get_kana_locked() ? 0x02 : 0x00);
@@ -550,19 +585,39 @@ void EmuThreadClass::doWork(const QString &params)
                        }
 #endif
                        sample_access_drv();
-
-                       interval += get_interval();
                        now_skip = p_emu->is_frame_skippable() && !p_emu->is_video_recording();
-                       if(config.full_speed) interval = 1; 
+                       if(config.full_speed) {
+                               interval = 1;
+                       } else {
+                               interval = get_interval();
+                       }
                        if((prev_skip && !now_skip) || next_time == 0) {
                                next_time = tick_timer.elapsed();
+                               //next_time = SDL_GetTicks();
                        }
                        if(!now_skip) {
                                next_time += interval;
                        }
                        prev_skip = now_skip;
-                       //printf("p_emu::RUN Frames = %d SKIP=%d Interval = %d NextTime = %d\n", run_frames, now_skip, interval, next_time);
+#if 0
+                       {
+                               struct tm *timedat;
+                               time_t nowtime;
+                               char strbuf2[256];
+                               char strbuf3[24];
+                               struct timeval tv;
+                               nowtime = time(NULL);
+                               gettimeofday(&tv, NULL);
+                               memset(strbuf2, 0x00, sizeof(strbuf2));
+                               memset(strbuf3, 0x00, sizeof(strbuf3));
+                               timedat = localtime(&nowtime);
+                               strftime(strbuf2, 255, "%Y-%m-%d %H:%M:%S", timedat);
+                               snprintf(strbuf3, 23, ".%06ld", tv.tv_usec);
+                               printf("%s%s[EMU]::RUN Frames = %d SKIP=%d Interval = %d NextTime = %d SRC = %d\n", strbuf2, strbuf3, run_frames, now_skip, interval, next_time, tick_timer.clockType());
+                       }
+#endif                 
                        if(next_time > tick_timer.elapsed()) {
+                               //if(next_time > SDL_GetTicks()) {
                                //  update window if enough time
                                if(!req_draw) {
                                        no_draw_count++;
@@ -596,8 +651,12 @@ void EmuThreadClass::doWork(const QString &params)
                        
                                // sleep 1 frame priod if need
                                current_time = tick_timer.elapsed();
-                               if((int)(next_time - current_time) >= 10) {
-                                       sleep_period = next_time - current_time;
+                               //current_time = SDL_GetTicks();
+                               sleep_period = 0;
+                               if(next_time > current_time) {
+                                       if((int)(next_time - current_time) >= 1) {
+                                               sleep_period = next_time - current_time;
+                                       }
                                }
                        } else if(++skip_frames > MAX_SKIP_FRAMES) {
                                // update window at least once per 10 frames
@@ -616,20 +675,31 @@ void EmuThreadClass::doWork(const QString &params)
                                no_draw_count = 0;
                                skip_frames = 0;
                                qint64 tt = tick_timer.elapsed();
+                               //quint32 tt = SDL_GetTicks();
+                               if(next_time > tt) {
+                                       sleep_period = next_time - tt;
+                               } else {
+                                       sleep_period = 0;
+                               }
                                if(config.full_speed) {
                                        next_time = tt + 1;
                                } else {
-                                       next_time = tt + get_interval();
+                                       next_time = tt;// + get_interval();
+                                       next_time = next_time + get_interval();
                                }
-                               sleep_period = next_time - tt;
+                               sleep_period = 0;
                        }
                }
                req_draw = false;
                if(bRunThread == false){
                        goto _exit;
                }
-               if(sleep_period <= 0) sleep_period = 1;
-               msleep(sleep_period);
+               if(sleep_period > 0) {
+                       //sleep_period = 1;
+                       msleep(sleep_period);
+                       //SDL_Delay(sleep_period);
+               }
+               //SDL_Delay(sleep_period);
        } while(1);
 _exit:
        //emit quit_draw_thread();
index 9a7aded..db41244 100644 (file)
@@ -62,6 +62,10 @@ protected:
        void dec_message_count(void);
        const _TCHAR *get_device_name(void);
        bool get_power_state(void);
+       void resetEmu();
+       void specialResetEmu();
+       void loadState();
+       void saveState();
        
 public:
        EmuThreadClass(Ui_MainWindowBase *rootWindow, USING_FLAGS *p, QObject *parent = 0);
index adb33a4..6d675c5 100644 (file)
@@ -1136,11 +1136,12 @@ void SetupSDL(void)
                }
        }
 #if defined(USE_SDL2)
-       SDL_Init(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
+       //SDL_Init(SDL_INIT_AUDIO | SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK);
+       SDL_Init(SDL_INIT_AUDIO | SDL_INIT_EVENTS);
 #else
        SDL_Init(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_VIDEO);
 #endif
-       csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Audio and JOYSTICK subsystem was initialised.");
+       csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Audio subsystem was initialised.");
 }
 
 
index 431dbdf..1a46900 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/gui")
 
-set(THIS_LIB_VERSION 2.18.4)
+set(THIS_LIB_VERSION 2.18.5)
 #include(cotire)
 #include(PrecompiledHeader)
 
index a49feed..84735d8 100644 (file)
@@ -49,9 +49,9 @@ EmuThreadClassBase::EmuThreadClassBase(Ui_MainWindowBase *rootWindow, USING_FLAG
        
        bRunThread = true;
        prev_skip = false;
-       tick_timer.start();
-       update_fps_time = tick_timer.elapsed();
-       next_time = update_fps_time;
+       //tick_timer.start();
+       //update_fps_time = tick_timer.elapsed();
+       //next_time = update_fps_time;
        total_frames = 0;
        draw_frames = 0;
        skip_frames = 0;
@@ -261,7 +261,7 @@ void EmuThreadClassBase::do_special_reset()
 
 void EmuThreadClassBase::do_load_state(QString s)
 {
-       sStateFile = s;
+       lStateFile = s;
        bLoadStateReq = true;
 }
 
@@ -406,6 +406,8 @@ void EmuThreadClassBase::print_framerate(int frames)
        if(frames >= 0) draw_frames += frames;
        if(calc_message) {
                qint64 current_time = tick_timer.elapsed();
+               //qint64        current_time = SDL_GetTicks();
+
                if(update_fps_time <= current_time && update_fps_time != 0) {
                        _TCHAR buf[256];
                        QString message;
index 9bce1ee..8b1d799 100644 (file)
@@ -85,6 +85,7 @@ protected:
        bool bStopRecordSoundReq;
        bool bStartRecordMovieReq;
        QString sStateFile;
+       QString lStateFile;
 
 //     bool draw_timing;
        bool doing_debug_command;
@@ -129,7 +130,12 @@ protected:
        virtual void dec_message_count(void);
        virtual const _TCHAR *get_device_name(void);
        virtual bool get_power_state(void);
-       
+
+       virtual void resetEmu() { }
+       virtual void specialResetEmu() { }
+       virtual void loadState() { }
+       virtual void saveState() { }
+
        void enqueue_key_up(key_queue_t s) {
                keyMutex->lock();
                key_fifo->write(KEY_QUEUE_UP);
index 04e3b64..bce8e68 100644 (file)
@@ -34,6 +34,9 @@ JoyThreadClass::JoyThreadClass(EMU *p, OSD *o, USING_FLAGS *pflags, config_t *cf
        
        if(using_flags->is_use_joystick()) {
 # if defined(USE_SDL2)
+               int result = SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK);
+               //int result = 0;
+               csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_JOYSTICK, "Joystick/Game controller subsystem was %s.", (result == 0) ? "initialized" : "not initialized");
                for(i = 0; i < 16; i++) {
                        controller_table[i] = NULL;
                }
@@ -55,7 +58,7 @@ JoyThreadClass::JoyThreadClass(EMU *p, OSD *o, USING_FLAGS *pflags, config_t *cf
                } else {
                        csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "JoyThread : Any joysticks were not connected.");
                }
-               bRunThread = true;
+               bRunThread = (result == 0) ? true : false;
        } else {
                for(i = 0; i < 16; i++) {
                        joyhandle[i] = NULL;
@@ -76,14 +79,13 @@ JoyThreadClass::~JoyThreadClass()
                        SDL_GameControllerClose(controller_table[i]);
                        controller_table[i] = NULL;
                }
-               csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "JoyThread : EXIT");
 # else
                for(i = 0; i < 16; i++) {
                        SDL_JoystickClose(joyhandle[i]);
                        joyhandle[i] = NULL;
                }
-               csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "JoyThread : EXIT");
 # endif
+               csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "JoyThread : EXIT");
        }
 }
  
@@ -99,7 +101,7 @@ void JoyThreadClass::joystick_plugged(int num)
                joyhandle[num] = SDL_GameControllerGetJoystick(controller_table[num]);
                if(controller_table[num] != NULL) {
                        names[num] = QString::fromUtf8(SDL_GameControllerNameForIndex(num));
-                       csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "JoyThread : Controller %d : %s : is plugged.", num, names[num].toUtf8().constData());
+                       csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_JOYSTICK, "JoyThread : Controller %d : %s : is plugged.", num, names[num].toUtf8().constData());
                        strncpy(p_config->assigned_joystick_name[num], names[num].toUtf8().constData(),
                                        (sizeof(p_config->assigned_joystick_name)  / sizeof(char)) - 1);
                        joy_num[num] = num;
@@ -115,7 +117,7 @@ void JoyThreadClass::joystick_plugged(int num)
                                        joyhandle[i] = SDL_JoystickOpen(num);
                                        joy_num[i] = SDL_JoystickInstanceID(joyhandle[i]);
                                        names[i] = QString::fromUtf8(SDL_JoystickNameForIndex(num));
-                                       csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "JoyThread : Joystick %d : %s : is plugged.", num, names[i].toUtf8().data());
+                                       csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_JOYSTICK, "JoyThread : Joystick %d : %s : is plugged.", num, names[i].toUtf8().data());
                                        strncpy(p_config->assigned_joystick_name[num], names[num].toUtf8().constData(),
                                                        (sizeof(p_config->assigned_joystick_name)  / sizeof(char)) - 1);
                                        break;
@@ -134,7 +136,7 @@ void JoyThreadClass::joystick_unplugged(int num)
                if(controller_table[num] != NULL) {
                        SDL_GameControllerClose(controller_table[num]);
                        controller_table[num] = NULL;
-                       csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "JoyThread : Controller %d : %s : is removed.", num, names[num].toUtf8().data());
+                       csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_JOYSTICK, "JoyThread : Controller %d : %s : is removed.", num, names[num].toUtf8().data());
                        joy_num[num] = -1;
                }
                joyhandle[num] = NULL;
@@ -144,7 +146,7 @@ void JoyThreadClass::joystick_unplugged(int num)
                if(joyhandle[num] != NULL) {
                        SDL_JoystickClose(joyhandle[num]);
                        joyhandle[num] = NULL;
-                       csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "JoyThread : Joystick %d : %s : is removed.", num, names[num].toUtf8().data());
+                       csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_JOYSTICK, "JoyThread : Joystick %d : %s : is removed.", num, names[num].toUtf8().data());
                        joy_num[num] = -1;
                }
        }
index 9b29746..f4a7cbe 100644 (file)
@@ -257,7 +257,7 @@ public:
 
        int get_max_memcard() { return max_memcard; }
        
-       bool is_use_minimum_rendaring() { return use_minimum_rendering; }
+       bool is_use_minimum_rendering() { return use_minimum_rendering; }
        bool is_use_dig_resolution() { return use_dig_resolution; }
 
        int get_use_monitor_type() { return use_monitor_type; }
index 43b6f1a..501f1dd 100644 (file)
@@ -147,8 +147,6 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int*
                                  "Audio Device #%d: %s", i, tmps.toLocal8Bit().constData());
                sound_device_list.append(tmps);
        }
-#endif   
-#if defined(USE_SDL2)
        
        //QString sdev = QString::fromUtf8("\"") + sound_device_list.at(audio_dev_id) + QString::fromUtf8("\"");
        //audio_dev_id = SDL_OpenAudioDevice(NULL, 0, &snd_spec_req, &snd_spec_presented, SDL_AUDIO_ALLOW_ANY_CHANGE);
@@ -157,7 +155,7 @@ void OSD_BASE::initialize_sound(int rate, int samples, int* presented_rate, int*
     audio_dev_id = SDL_OpenAudioDevice(sdev.toUtf8().constData(), 0,
                                                                           &snd_spec_req, &snd_spec_presented,
                                                                           0);
-       debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND, "Try to openDEVICE #%d: %s -> %s: DEVID=%d\n",
+       debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_SOUND, "Try to open DEVICE #%d: %s -> %s: DEVID=%d\n",
                          p_config->sound_device_num, sdev.toUtf8().constData(), (audio_dev_id <= 0) ? "FAIL" : "SUCCESS", audio_dev_id);
 #else
        audio_dev_id = 1;