mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 22:55:40 +12:00
Format the hydra
This commit is contained in:
parent
d19a00d97d
commit
977ab53b68
2 changed files with 84 additions and 112 deletions
|
@ -60,6 +60,7 @@ class Emulator {
|
||||||
|
|
||||||
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
|
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
|
||||||
HttpServer httpServer;
|
HttpServer httpServer;
|
||||||
|
friend struct HttpServer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PANDA3DS_ENABLE_DISCORD_RPC
|
#ifdef PANDA3DS_ENABLE_DISCORD_RPC
|
||||||
|
|
|
@ -1,151 +1,122 @@
|
||||||
#include <hydra/core.hxx>
|
|
||||||
#include <emulator.hpp>
|
#include <emulator.hpp>
|
||||||
|
#include <hydra/core.hxx>
|
||||||
#include <renderer_gl/renderer_gl.hpp>
|
#include <renderer_gl/renderer_gl.hpp>
|
||||||
|
|
||||||
class HC_GLOBAL HydraCore final : public hydra::IBase, public hydra::IOpenGlRendered, public hydra::IFrontendDriven, public hydra::IInput
|
class HC_GLOBAL HydraCore final : public hydra::IBase, public hydra::IOpenGlRendered, public hydra::IFrontendDriven, public hydra::IInput {
|
||||||
{
|
HYDRA_CLASS
|
||||||
HYDRA_CLASS
|
public:
|
||||||
public:
|
HydraCore();
|
||||||
HydraCore();
|
|
||||||
private:
|
|
||||||
// IBase
|
|
||||||
bool loadFile(const char* type, const char* path) override;
|
|
||||||
void reset() override;
|
|
||||||
hydra::Size getNativeSize() override;
|
|
||||||
void setOutputSize(hydra::Size size) override;
|
|
||||||
|
|
||||||
// IOpenGlRendered
|
private:
|
||||||
void setFbo(unsigned handle) override;
|
// IBase
|
||||||
void setContext(void* context) override;
|
bool loadFile(const char* type, const char* path) override;
|
||||||
void setGetProcAddress(void* function) override;
|
void reset() override;
|
||||||
|
hydra::Size getNativeSize() override;
|
||||||
|
void setOutputSize(hydra::Size size) override;
|
||||||
|
|
||||||
// IFrontendDriven
|
// IOpenGlRendered
|
||||||
void runFrame() override;
|
void setFbo(unsigned handle) override;
|
||||||
|
void setContext(void* context) override;
|
||||||
|
void setGetProcAddress(void* function) override;
|
||||||
|
|
||||||
// IInput
|
// IFrontendDriven
|
||||||
void setPollInputCallback(void(*callback)()) override;
|
void runFrame() override;
|
||||||
void setCheckButtonCallback(int32_t(*callback)(uint32_t player, hydra::ButtonType button)) override;
|
|
||||||
|
|
||||||
std::unique_ptr<Emulator> emulator;
|
// IInput
|
||||||
RendererGL* renderer;
|
void setPollInputCallback(void (*callback)()) override;
|
||||||
void (*pollInputCallback)() = nullptr;
|
void setCheckButtonCallback(int32_t (*callback)(uint32_t player, hydra::ButtonType button)) override;
|
||||||
int32_t (*checkButtonCallback)(uint32_t player, hydra::ButtonType button) = nullptr;
|
|
||||||
|
std::unique_ptr<Emulator> emulator;
|
||||||
|
RendererGL* renderer;
|
||||||
|
void (*pollInputCallback)() = nullptr;
|
||||||
|
int32_t (*checkButtonCallback)(uint32_t player, hydra::ButtonType button) = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
HydraCore::HydraCore() : emulator(new Emulator)
|
HydraCore::HydraCore() : emulator(new Emulator) {
|
||||||
{
|
if (emulator->getRendererType() != RendererType::OpenGL) {
|
||||||
if (emulator->getRendererType() != RendererType::OpenGL)
|
throw std::runtime_error("HydraCore: Renderer is not OpenGL");
|
||||||
{
|
}
|
||||||
throw std::runtime_error("HydraCore: Renderer is not OpenGL");
|
renderer = static_cast<RendererGL*>(emulator->getRenderer());
|
||||||
}
|
|
||||||
renderer = static_cast<RendererGL*>(emulator->getRenderer());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HydraCore::loadFile(const char* type, const char* path)
|
bool HydraCore::loadFile(const char* type, const char* path) {
|
||||||
{
|
if (std::string(type) == "rom") {
|
||||||
if (std::string(type) == "rom")
|
return emulator->loadROM(path);
|
||||||
{
|
} else {
|
||||||
return emulator->loadROM(path);
|
return false;
|
||||||
} else {
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HydraCore::runFrame()
|
void HydraCore::runFrame() {
|
||||||
{
|
renderer->resetStateManager();
|
||||||
renderer->resetStateManager();
|
|
||||||
|
|
||||||
pollInputCallback();
|
pollInputCallback();
|
||||||
HIDService& hid = emulator->getServiceManager().getHID();
|
HIDService& hid = emulator->getServiceManager().getHID();
|
||||||
hid.setKey(HID::Keys::A, checkButtonCallback(0, hydra::ButtonType::A));
|
hid.setKey(HID::Keys::A, checkButtonCallback(0, hydra::ButtonType::A));
|
||||||
hid.setKey(HID::Keys::B, checkButtonCallback(0, hydra::ButtonType::B));
|
hid.setKey(HID::Keys::B, checkButtonCallback(0, hydra::ButtonType::B));
|
||||||
hid.setKey(HID::Keys::X, checkButtonCallback(0, hydra::ButtonType::X));
|
hid.setKey(HID::Keys::X, checkButtonCallback(0, hydra::ButtonType::X));
|
||||||
hid.setKey(HID::Keys::Y, checkButtonCallback(0, hydra::ButtonType::Y));
|
hid.setKey(HID::Keys::Y, checkButtonCallback(0, hydra::ButtonType::Y));
|
||||||
hid.setKey(HID::Keys::L, checkButtonCallback(0, hydra::ButtonType::L1));
|
hid.setKey(HID::Keys::L, checkButtonCallback(0, hydra::ButtonType::L1));
|
||||||
hid.setKey(HID::Keys::R, checkButtonCallback(0, hydra::ButtonType::R1));
|
hid.setKey(HID::Keys::R, checkButtonCallback(0, hydra::ButtonType::R1));
|
||||||
hid.setKey(HID::Keys::Start, checkButtonCallback(0, hydra::ButtonType::Start));
|
hid.setKey(HID::Keys::Start, checkButtonCallback(0, hydra::ButtonType::Start));
|
||||||
hid.setKey(HID::Keys::Select, checkButtonCallback(0, hydra::ButtonType::Select));
|
hid.setKey(HID::Keys::Select, checkButtonCallback(0, hydra::ButtonType::Select));
|
||||||
hid.setKey(HID::Keys::Up, checkButtonCallback(0, hydra::ButtonType::Keypad1Up));
|
hid.setKey(HID::Keys::Up, checkButtonCallback(0, hydra::ButtonType::Keypad1Up));
|
||||||
hid.setKey(HID::Keys::Down, checkButtonCallback(0, hydra::ButtonType::Keypad1Down));
|
hid.setKey(HID::Keys::Down, checkButtonCallback(0, hydra::ButtonType::Keypad1Down));
|
||||||
hid.setKey(HID::Keys::Left, checkButtonCallback(0, hydra::ButtonType::Keypad1Left));
|
hid.setKey(HID::Keys::Left, checkButtonCallback(0, hydra::ButtonType::Keypad1Left));
|
||||||
hid.setKey(HID::Keys::Right, checkButtonCallback(0, hydra::ButtonType::Keypad1Right));
|
hid.setKey(HID::Keys::Right, checkButtonCallback(0, hydra::ButtonType::Keypad1Right));
|
||||||
|
|
||||||
int x = !!checkButtonCallback(0, hydra::ButtonType::Analog1Right) - !!checkButtonCallback(0, hydra::ButtonType::Analog1Left);
|
int x = !!checkButtonCallback(0, hydra::ButtonType::Analog1Right) - !!checkButtonCallback(0, hydra::ButtonType::Analog1Left);
|
||||||
int y = !!checkButtonCallback(0, hydra::ButtonType::Analog1Up) - !!checkButtonCallback(0, hydra::ButtonType::Analog1Down);
|
int y = !!checkButtonCallback(0, hydra::ButtonType::Analog1Up) - !!checkButtonCallback(0, hydra::ButtonType::Analog1Down);
|
||||||
hid.setCirclepadX(x * 0x9C);
|
hid.setCirclepadX(x * 0x9C);
|
||||||
hid.setCirclepadY(y * 0x9C);
|
hid.setCirclepadY(y * 0x9C);
|
||||||
|
|
||||||
emulator->runFrame();
|
emulator->runFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HydraCore::reset()
|
void HydraCore::reset() { emulator->reset(Emulator::ReloadOption::Reload); }
|
||||||
{
|
|
||||||
emulator->reset(Emulator::ReloadOption::Reload);
|
|
||||||
}
|
|
||||||
|
|
||||||
hydra::Size HydraCore::getNativeSize()
|
hydra::Size HydraCore::getNativeSize() { return {400, 480}; }
|
||||||
{
|
|
||||||
return { 400, 480 };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Size doesn't matter as the glBlitFramebuffer call is commented out for the core
|
// Size doesn't matter as the glBlitFramebuffer call is commented out for the core
|
||||||
void HydraCore::setOutputSize(hydra::Size size) {}
|
void HydraCore::setOutputSize(hydra::Size size) {}
|
||||||
|
|
||||||
void HydraCore::setGetProcAddress(void* function)
|
void HydraCore::setGetProcAddress(void* function) {
|
||||||
{
|
#ifdef __ANDROID__
|
||||||
#ifdef __ANDROID__
|
|
||||||
if (!gladLoadGLES2Loader(reinterpret_cast<GLADloadproc>(function))) {
|
if (!gladLoadGLES2Loader(reinterpret_cast<GLADloadproc>(function))) {
|
||||||
Helpers::panic("OpenGL ES init failed");
|
Helpers::panic("OpenGL ES init failed");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (!gladLoadGLLoader(reinterpret_cast<GLADloadproc>(function))) {
|
if (!gladLoadGLLoader(reinterpret_cast<GLADloadproc>(function))) {
|
||||||
Helpers::panic("OpenGL init failed");
|
Helpers::panic("OpenGL init failed");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// SDL_Window is not used, so we pass nullptr
|
// SDL_Window is not used, so we pass nullptr
|
||||||
emulator->initGraphicsContext(nullptr);
|
emulator->initGraphicsContext(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HydraCore::setContext(void*) {}
|
void HydraCore::setContext(void*) {}
|
||||||
|
|
||||||
void HydraCore::setFbo(unsigned handle)
|
void HydraCore::setFbo(unsigned handle) { renderer->setFBO(handle); }
|
||||||
{
|
|
||||||
renderer->setFBO(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HydraCore::setPollInputCallback(void(*callback)())
|
void HydraCore::setPollInputCallback(void (*callback)()) { pollInputCallback = callback; }
|
||||||
{
|
|
||||||
pollInputCallback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HydraCore::setCheckButtonCallback(int32_t(*callback)(uint32_t player, hydra::ButtonType button))
|
void HydraCore::setCheckButtonCallback(int32_t (*callback)(uint32_t player, hydra::ButtonType button)) { checkButtonCallback = callback; }
|
||||||
{
|
|
||||||
checkButtonCallback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
HC_API hydra::IBase* createEmulator()
|
HC_API hydra::IBase* createEmulator() { return new HydraCore; }
|
||||||
{
|
|
||||||
return new HydraCore;
|
|
||||||
}
|
|
||||||
|
|
||||||
HC_API void destroyEmulator(hydra::IBase* emulator)
|
HC_API void destroyEmulator(hydra::IBase* emulator) { delete emulator; }
|
||||||
{
|
|
||||||
delete emulator;
|
|
||||||
}
|
|
||||||
|
|
||||||
HC_API const char* getInfo(hydra::InfoType type)
|
HC_API const char* getInfo(hydra::InfoType type) {
|
||||||
{
|
switch (type) {
|
||||||
switch (type)
|
case hydra::InfoType::CoreName: return "Panda3DS";
|
||||||
{
|
case hydra::InfoType::SystemName: return "Nintendo 3DS";
|
||||||
case hydra::InfoType::CoreName: return "Panda3DS";
|
case hydra::InfoType::Description: return "HLE 3DS emulator. There's a little Alber in your computer and he runs Nintendo 3DS games.";
|
||||||
case hydra::InfoType::SystemName: return "Nintendo 3DS";
|
case hydra::InfoType::Author: return "wheremyfoodat (Peach)";
|
||||||
case hydra::InfoType::Description: return "HLE 3DS emulator. There's a little Alber in your computer and he runs Nintendo 3DS games.";
|
case hydra::InfoType::Version: return "0.7";
|
||||||
case hydra::InfoType::Author: return "wheremyfoodat (Peach)";
|
case hydra::InfoType::License: return "GPLv3";
|
||||||
case hydra::InfoType::Version: return "0.7";
|
case hydra::InfoType::Website: return "https://panda3ds.com/";
|
||||||
case hydra::InfoType::License: return "GPLv3";
|
case hydra::InfoType::Extensions: return "3ds,cci,cxi,app,3dsx,elf,axf";
|
||||||
case hydra::InfoType::Website: return "https://panda3ds.com/";
|
case hydra::InfoType::Firmware: return "";
|
||||||
case hydra::InfoType::Extensions: return "3ds,cci,cxi,app,3dsx,elf,axf";
|
default: return nullptr;
|
||||||
case hydra::InfoType::Firmware: return "";
|
}
|
||||||
default: return nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue