From 9387b907c23b7684dd28c1d9e8924fbfcd8abfa5 Mon Sep 17 00:00:00 2001 From: "Christopher A. Mosher" Date: Mon, 5 Dec 2022 16:11:25 -0500 Subject: [PATCH] start sdl first; run wx in a thread --- src/E2wxApp.cpp | 78 ++++++++++++++++++++++++------------------------- src/E2wxApp.h | 7 ++--- src/main.cpp | 57 ++++++++++++++++++++++++++++++++++-- 3 files changed, 95 insertions(+), 47 deletions(-) diff --git a/src/E2wxApp.cpp b/src/E2wxApp.cpp index cb87b7e..d4e8a54 100644 --- a/src/E2wxApp.cpp +++ b/src/E2wxApp.cpp @@ -97,7 +97,9 @@ bool E2wxApp::OnInit() { } #ifdef wxUSE_ON_FATAL_EXCEPTION +#ifndef __WINDOWS__ wxHandleFatalExceptions(); +#endif #endif wxStandardPaths& stdpaths = wxStandardPaths::Get(); @@ -144,10 +146,6 @@ bool E2wxApp::OnInit() { - StartSdlEpple2(); - - - E2wxFrame *frame = new E2wxFrame(); frame->DoInit(); frame->Show(); @@ -158,6 +156,8 @@ bool E2wxApp::OnInit() { } static int run(const std::string config_file) { + GUI gui; + std::unique_ptr emu(new Emulator()); Config cfg(config_file); @@ -168,17 +168,17 @@ static int run(const std::string config_file) { return emu->run(); } -void E2wxApp::StartSdlEpple2() { - std::cout << "starting sdl thread..." << std::endl; - this->thread_sdl = new std::thread(run, this->arg_configfile); - std::cout << "started sdl thread." << std::endl; -} +//void E2wxApp::StartSdlEpple2() { +// std::cout << "starting sdl thread..." << std::endl; +// this->thread_sdl = new std::thread(run, this->arg_configfile); +// std::cout << "started sdl thread." << std::endl; +//} int E2wxApp::OnExit() { - std::cout << "stopping sdl thread..." << std::endl; +// std::cout << "stopping sdl thread..." << std::endl; GUI::queueQuit(); - this->thread_sdl->join(); - std::cout << "exiting wx application..." << std::endl; +// this->thread_sdl->join(); +// std::cout << "exiting wx application..." << std::endl; return 0; } @@ -192,33 +192,33 @@ void E2wxApp::OnFatalException() { } } -static const wxCmdLineEntryDesc cmdLineDesc[] = -{ - { wxCMD_LINE_PARAM, NULL, NULL, "config file", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, - wxCMD_LINE_DESC_END -}; - -void E2wxApp::OnInitCmdLine(wxCmdLineParser& parser) { - wxApp::OnInitCmdLine(parser); - parser.SetDesc(cmdLineDesc); -} - -bool E2wxApp::OnCmdLineParsed(wxCmdLineParser& parser) { - if (!wxApp::OnCmdLineParsed(parser)) { - return false; - } - - const int n = parser.GetParamCount(); - - if (n <= 0) { - std::cout << "no config file specified on the command line; will use config file specified in user-preferences" << std::endl; - } else { - this->arg_configfile = parser.GetParam(0); - std::cout << "using config file specified on the command line: " << this->arg_configfile << std::endl; - } - - return true; -} +//static const wxCmdLineEntryDesc cmdLineDesc[] = +//{ +// { wxCMD_LINE_PARAM, NULL, NULL, "config file", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, +// wxCMD_LINE_DESC_END +//}; +// +//void E2wxApp::OnInitCmdLine(wxCmdLineParser& parser) { +// wxApp::OnInitCmdLine(parser); +// parser.SetDesc(cmdLineDesc); +//} +// +//bool E2wxApp::OnCmdLineParsed(wxCmdLineParser& parser) { +// if (!wxApp::OnCmdLineParsed(parser)) { +// return false; +// } +// +// const int n = parser.GetParamCount(); +// +// if (n <= 0) { +// std::cout << "no config file specified on the command line; will use config file specified in user-preferences" << std::endl; +// } else { +// this->arg_configfile = parser.GetParam(0); +// std::cout << "using config file specified on the command line: " << this->arg_configfile << std::endl; +// } +// +// return true; +//} const std::filesystem::path E2wxApp::GetLogFile() const { diff --git a/src/E2wxApp.h b/src/E2wxApp.h index b8eaa18..cf9d6d0 100644 --- a/src/E2wxApp.h +++ b/src/E2wxApp.h @@ -40,12 +40,9 @@ class E2wxApp : public wxApp { std::filesystem::path conffile; std::filesystem::path confdir; std::filesystem::path docsdir; - std::string arg_configfile; - std::thread *thread_sdl; const std::filesystem::path BuildLogFilePath() const; void InitBoostLog(); - void StartSdlEpple2(); public: E2wxApp(); @@ -62,8 +59,8 @@ public: virtual bool OnInit() override; virtual int OnExit() override; virtual void OnFatalException() override; - virtual void OnInitCmdLine(wxCmdLineParser& parser) override; - virtual bool OnCmdLineParsed(wxCmdLineParser& parser) override; +// virtual void OnInitCmdLine(wxCmdLineParser& parser) override; +// virtual bool OnCmdLineParsed(wxCmdLineParser& parser) override; }; wxDECLARE_APP(E2wxApp); diff --git a/src/main.cpp b/src/main.cpp index 476f3d9..a63ae1d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,18 +17,69 @@ */ #include "e2const.h" +#include "emulator.h" +#include "configep2.h" #include "gui.h" +#include "e2const.h" +#include "E2wxApp.h" #include +#include #include #include #include +#include #include #include +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 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 extern "C" #endif @@ -42,9 +93,9 @@ int main(int argc, char *argv[]) { 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; }