start sdl first; run wx in a thread

This commit is contained in:
Christopher A. Mosher 2022-12-05 16:11:25 -05:00
parent e55e3f4c1d
commit 9387b907c2
3 changed files with 95 additions and 47 deletions

View File

@ -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<Emulator> 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 {

View File

@ -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);

View File

@ -17,18 +17,69 @@
*/
#include "e2const.h"
#include "emulator.h"
#include "configep2.h"
#include "gui.h"
#include "e2const.h"
#include "E2wxApp.h"
#include <wx/app.h>
#include <thread>
#include <iostream>
#include <ostream>
#include <stdexcept>
#include <string>
#include <cstdio>
#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
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;
}