Add pythonL_Reg struct list for emulib and loop in binding
This commit is contained in:
parent
a415977089
commit
e01f0977cb
|
@ -3,14 +3,13 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include <pybind11/embed.h>
|
#include <pybind11/embed.h>
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
|
|
||||||
#include "fceupython.h"
|
#include "fceupython.h"
|
||||||
|
|
||||||
#define SetCurrentDir chdir
|
|
||||||
|
|
||||||
// Are we running any code right now?
|
// Are we running any code right now?
|
||||||
static char* pythonScriptName = NULL;
|
static char* pythonScriptName = NULL;
|
||||||
bool pythonRunning = false;
|
bool pythonRunning = false;
|
||||||
|
@ -24,28 +23,13 @@ static std::atomic_bool inFrameBoundry = false;
|
||||||
std::mutex mtx;
|
std::mutex mtx;
|
||||||
std::condition_variable cv;
|
std::condition_variable cv;
|
||||||
|
|
||||||
// Python thread object
|
|
||||||
// std::thread python_thread;
|
|
||||||
|
|
||||||
|
typedef struct pythonL_Reg {
|
||||||
|
const char* name;
|
||||||
|
void (*func)();
|
||||||
|
} pythonL_Reg;
|
||||||
|
|
||||||
void FCEU_PythonFrameBoundary()
|
static void emu_frameadvance()
|
||||||
{
|
|
||||||
std::cout << "in FCEU_PythonFrameBoundary" << std::endl;
|
|
||||||
|
|
||||||
if(!pythonRunning)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Notify Python thread the main thread is in the frame boundry
|
|
||||||
inFrameBoundry = true;
|
|
||||||
cv.notify_all();
|
|
||||||
|
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(mtx);
|
|
||||||
cv.wait(lock, [] { return bool(frameAdvanceWaiting); });
|
|
||||||
frameAdvanceWaiting = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void emu_frameadvance()
|
|
||||||
{
|
{
|
||||||
// Can't call if a frameAdvance is already waiting
|
// Can't call if a frameAdvance is already waiting
|
||||||
if (frameAdvanceWaiting)
|
if (frameAdvanceWaiting)
|
||||||
|
@ -62,10 +46,32 @@ void emu_frameadvance()
|
||||||
cv.wait(lock, [] { return bool(inFrameBoundry); });
|
cv.wait(lock, [] { return bool(inFrameBoundry); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct pythonL_Reg emulib [] = {
|
||||||
|
{"frameadvance", &emu_frameadvance}
|
||||||
|
};
|
||||||
|
|
||||||
PYBIND11_EMBEDDED_MODULE(emu, m)
|
PYBIND11_EMBEDDED_MODULE(emu, m)
|
||||||
{
|
{
|
||||||
m.def("frameadvance", &emu_frameadvance);
|
for (pythonL_Reg libReg : emulib) {
|
||||||
// m.def("framecount", [] { return emu_framecount; });
|
m.def(libReg.name, libReg.func);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FCEU_PythonFrameBoundary()
|
||||||
|
{
|
||||||
|
std::cout << "in FCEU_PythonFrameBoundary" << std::endl;
|
||||||
|
|
||||||
|
if(!pythonRunning)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Notify Python thread the main thread is in the frame boundry
|
||||||
|
inFrameBoundry = true;
|
||||||
|
cv.notify_all();
|
||||||
|
|
||||||
|
|
||||||
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
|
cv.wait(lock, [] { return bool(frameAdvanceWaiting); });
|
||||||
|
frameAdvanceWaiting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pythonStart(std::string filename)
|
void pythonStart(std::string filename)
|
||||||
|
|
Loading…
Reference in New Issue