mirror of
https://github.com/cmosher01/Epple-II.git
synced 2025-08-15 08:27:57 +00:00
start sdl first; run wx in a thread
This commit is contained in:
@@ -97,7 +97,9 @@ bool E2wxApp::OnInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef wxUSE_ON_FATAL_EXCEPTION
|
#ifdef wxUSE_ON_FATAL_EXCEPTION
|
||||||
|
#ifndef __WINDOWS__
|
||||||
wxHandleFatalExceptions();
|
wxHandleFatalExceptions();
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxStandardPaths& stdpaths = wxStandardPaths::Get();
|
wxStandardPaths& stdpaths = wxStandardPaths::Get();
|
||||||
@@ -144,10 +146,6 @@ bool E2wxApp::OnInit() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
StartSdlEpple2();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
E2wxFrame *frame = new E2wxFrame();
|
E2wxFrame *frame = new E2wxFrame();
|
||||||
frame->DoInit();
|
frame->DoInit();
|
||||||
frame->Show();
|
frame->Show();
|
||||||
@@ -158,6 +156,8 @@ bool E2wxApp::OnInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int run(const std::string config_file) {
|
static int run(const std::string config_file) {
|
||||||
|
GUI gui;
|
||||||
|
|
||||||
std::unique_ptr<Emulator> emu(new Emulator());
|
std::unique_ptr<Emulator> emu(new Emulator());
|
||||||
|
|
||||||
Config cfg(config_file);
|
Config cfg(config_file);
|
||||||
@@ -168,17 +168,17 @@ static int run(const std::string config_file) {
|
|||||||
return emu->run();
|
return emu->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void E2wxApp::StartSdlEpple2() {
|
//void E2wxApp::StartSdlEpple2() {
|
||||||
std::cout << "starting sdl thread..." << std::endl;
|
// std::cout << "starting sdl thread..." << std::endl;
|
||||||
this->thread_sdl = new std::thread(run, this->arg_configfile);
|
// this->thread_sdl = new std::thread(run, this->arg_configfile);
|
||||||
std::cout << "started sdl thread." << std::endl;
|
// std::cout << "started sdl thread." << std::endl;
|
||||||
}
|
//}
|
||||||
|
|
||||||
int E2wxApp::OnExit() {
|
int E2wxApp::OnExit() {
|
||||||
std::cout << "stopping sdl thread..." << std::endl;
|
// std::cout << "stopping sdl thread..." << std::endl;
|
||||||
GUI::queueQuit();
|
GUI::queueQuit();
|
||||||
this->thread_sdl->join();
|
// this->thread_sdl->join();
|
||||||
std::cout << "exiting wx application..." << std::endl;
|
// std::cout << "exiting wx application..." << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,33 +192,33 @@ void E2wxApp::OnFatalException() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const wxCmdLineEntryDesc cmdLineDesc[] =
|
//static const wxCmdLineEntryDesc cmdLineDesc[] =
|
||||||
{
|
//{
|
||||||
{ wxCMD_LINE_PARAM, NULL, NULL, "config file", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
|
// { wxCMD_LINE_PARAM, NULL, NULL, "config file", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
|
||||||
wxCMD_LINE_DESC_END
|
// wxCMD_LINE_DESC_END
|
||||||
};
|
//};
|
||||||
|
//
|
||||||
void E2wxApp::OnInitCmdLine(wxCmdLineParser& parser) {
|
//void E2wxApp::OnInitCmdLine(wxCmdLineParser& parser) {
|
||||||
wxApp::OnInitCmdLine(parser);
|
// wxApp::OnInitCmdLine(parser);
|
||||||
parser.SetDesc(cmdLineDesc);
|
// parser.SetDesc(cmdLineDesc);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
bool E2wxApp::OnCmdLineParsed(wxCmdLineParser& parser) {
|
//bool E2wxApp::OnCmdLineParsed(wxCmdLineParser& parser) {
|
||||||
if (!wxApp::OnCmdLineParsed(parser)) {
|
// if (!wxApp::OnCmdLineParsed(parser)) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
const int n = parser.GetParamCount();
|
// const int n = parser.GetParamCount();
|
||||||
|
//
|
||||||
if (n <= 0) {
|
// if (n <= 0) {
|
||||||
std::cout << "no config file specified on the command line; will use config file specified in user-preferences" << std::endl;
|
// std::cout << "no config file specified on the command line; will use config file specified in user-preferences" << std::endl;
|
||||||
} else {
|
// } else {
|
||||||
this->arg_configfile = parser.GetParam(0);
|
// this->arg_configfile = parser.GetParam(0);
|
||||||
std::cout << "using config file specified on the command line: " << this->arg_configfile << std::endl;
|
// std::cout << "using config file specified on the command line: " << this->arg_configfile << std::endl;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return true;
|
// return true;
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
const std::filesystem::path E2wxApp::GetLogFile() const {
|
const std::filesystem::path E2wxApp::GetLogFile() const {
|
||||||
|
@@ -40,12 +40,9 @@ class E2wxApp : public wxApp {
|
|||||||
std::filesystem::path conffile;
|
std::filesystem::path conffile;
|
||||||
std::filesystem::path confdir;
|
std::filesystem::path confdir;
|
||||||
std::filesystem::path docsdir;
|
std::filesystem::path docsdir;
|
||||||
std::string arg_configfile;
|
|
||||||
std::thread *thread_sdl;
|
|
||||||
|
|
||||||
const std::filesystem::path BuildLogFilePath() const;
|
const std::filesystem::path BuildLogFilePath() const;
|
||||||
void InitBoostLog();
|
void InitBoostLog();
|
||||||
void StartSdlEpple2();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
E2wxApp();
|
E2wxApp();
|
||||||
@@ -62,8 +59,8 @@ public:
|
|||||||
virtual bool OnInit() override;
|
virtual bool OnInit() override;
|
||||||
virtual int OnExit() override;
|
virtual int OnExit() override;
|
||||||
virtual void OnFatalException() override;
|
virtual void OnFatalException() override;
|
||||||
virtual void OnInitCmdLine(wxCmdLineParser& parser) override;
|
// virtual void OnInitCmdLine(wxCmdLineParser& parser) override;
|
||||||
virtual bool OnCmdLineParsed(wxCmdLineParser& parser) override;
|
// virtual bool OnCmdLineParsed(wxCmdLineParser& parser) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
wxDECLARE_APP(E2wxApp);
|
wxDECLARE_APP(E2wxApp);
|
||||||
|
57
src/main.cpp
57
src/main.cpp
@@ -17,18 +17,69 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "e2const.h"
|
#include "e2const.h"
|
||||||
|
#include "emulator.h"
|
||||||
|
#include "configep2.h"
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
|
#include "e2const.h"
|
||||||
|
#include "E2wxApp.h"
|
||||||
|
|
||||||
#include <wx/app.h>
|
#include <wx/app.h>
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static std::string parse_args(int argc, char* argv[]) {
|
||||||
|
if (argc > 2) {
|
||||||
|
throw std::runtime_error("usage: epple2 [config-file]" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc <= 1) {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::string(argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int fake_argc(0);
|
||||||
|
static char fake_prog[] = "epple2";
|
||||||
|
static char *fake_argv[] { fake_prog };
|
||||||
|
|
||||||
|
static int runWx() {
|
||||||
|
return wxEntry(fake_argc, fake_argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int runSdl(const std::string config_file) {
|
||||||
|
GUI gui;
|
||||||
|
|
||||||
|
std::thread thread_wx(runWx);
|
||||||
|
|
||||||
|
std::unique_ptr<Emulator> emu(new Emulator());
|
||||||
|
|
||||||
|
Config cfg(config_file);
|
||||||
|
emu->config(cfg);
|
||||||
|
|
||||||
|
emu->init();
|
||||||
|
|
||||||
|
const int ret = emu->run();
|
||||||
|
|
||||||
|
if (wxApp::GetInstance() != nullptr) {
|
||||||
|
wxApp::GetInstance()->ExitMainLoop();
|
||||||
|
}
|
||||||
|
thread_wx.join();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
#endif
|
#endif
|
||||||
@@ -42,9 +93,9 @@ int main(int argc, char *argv[]) {
|
|||||||
throw std::runtime_error("bad constant in e2const.h" );
|
throw std::runtime_error("bad constant in e2const.h" );
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI gui;
|
const std::string config_file = parse_args(argc, argv);
|
||||||
|
|
||||||
wxEntry(argc, argv);
|
const int ret = runSdl(config_file);
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user