Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach committed Jan 19, 2025
1 parent 4773c55 commit 605df2b
Show file tree
Hide file tree
Showing 21 changed files with 470 additions and 404 deletions.
23 changes: 12 additions & 11 deletions src/ChaiLove.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
#include <libretro.h>
#include <string>
#include "ChaiLove.h"
#include "LibretroLog.h"

ChaiLove* ChaiLove::m_instance = NULL;
retro_input_state_t ChaiLove::input_state_cb = NULL;
retro_input_poll_t ChaiLove::input_poll_cb = NULL;
retro_environment_t ChaiLove::environ_cb = NULL;

void ChaiLove::destroy() {
//LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] Attempting to destroy ChaiLove" << std::endl;
LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] Attempting to destroy ChaiLove" << std::endl;
if (hasInstance()) {
//LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] Destroying ChaiLove" << std::endl;
LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] Destroying ChaiLove" << std::endl;
m_instance->quit();
delete m_instance;
m_instance = NULL;
}
//LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] Destroyed ChaiLove" << std::endl;
LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] Destroyed ChaiLove" << std::endl;
}

ChaiLove* ChaiLove::getInstance() {
if (!hasInstance()) {
//LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] Initializing ChaiLove" << std::endl;
LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] Initializing ChaiLove" << std::endl;
m_instance = new ChaiLove;
}
return m_instance;
Expand Down Expand Up @@ -60,14 +61,14 @@ bool ChaiLove::load(const std::string& file, const void* data, unsigned int data
#define GIT_VERSION ""
#endif
std::string version = CHAILOVE_VERSION_STRING GIT_VERSION;
//LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] ChaiLove " << version.c_str() << std::endl;
LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] ChaiLove " << version.c_str() << std::endl;

// Iniitalize some of the initial subsystems.
sound.load(app);

// Initalize the file system.
if (!filesystem.init(file, data, dataSize)) {
//LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error loading " << file << std::endl;
LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error loading " << file << std::endl;
return false;
}

Expand All @@ -76,7 +77,7 @@ bool ChaiLove::load(const std::string& file, const void* data, unsigned int data
// Initialize the scripting system.
script = new love::script(file);
if (!script->mainLoaded) {
//LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Error loading " << file << std::endl;
LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Error loading " << file << std::endl;
return false;
}
script->conf(config);
Expand All @@ -88,9 +89,9 @@ bool ChaiLove::load(const std::string& file, const void* data, unsigned int data
graphics.load();
image.load();
keyboard.load();
joystick.load();
joystick.load(app);
math.load(app);
mouse.load();
mouse.load(app);
font.load();

// Now that all subsystems are loaded, start the script.
Expand Down Expand Up @@ -119,7 +120,7 @@ void ChaiLove::update() {
*/
void ChaiLove::reset() {
// Tell the script that we are to reset the game.
//LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] Reset" << std::endl;
LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] Reset" << std::endl;
if (script != NULL) {
script->reset();
}
Expand All @@ -143,7 +144,7 @@ void ChaiLove::draw() {
// Flip the buffer.
// if (SDL_Flip(screen) == -1) {
// std::string out("[ChaiLove] Failed to swap the buffers: ");
// //LibretroLog::log(RETRO_LOG_ERROR) << out << SDL_GetError() << std::endl;
// LibretroLog::log(RETRO_LOG_ERROR) << out << SDL_GetError() << std::endl;
// }
}

Expand Down
2 changes: 2 additions & 0 deletions src/ChaiLove.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
#include "pntr_app.h"

#include "libretro.h"
#include "LibretroLog.h"

#include "love/keyboard.h"
#include "love/config.h"
#include "love/data.h"
Expand Down
2 changes: 0 additions & 2 deletions src/LibretroLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#include "libretro.h"

extern retro_log_printf_t log_cb;

#ifdef __cplusplus

#include <ostream>
Expand Down
2 changes: 1 addition & 1 deletion src/love/Types/Graphics/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool Image::loadFromRW(const unsigned char* data, unsigned int size) {
if (errorChar != NULL) {
errString = errorChar;
}
//LibretroLog::log(RETRO_LOG_ERROR) << "STBIMG_Load_RW failed to load data: " << errString << std::endl;
LibretroLog::log(RETRO_LOG_ERROR) << "STBIMG_Load_RW failed to load data: " << errString << std::endl;
return false;
}

Expand Down
60 changes: 24 additions & 36 deletions src/love/Types/Input/Joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,14 @@ namespace love {
namespace Types {
namespace Input {

std::string Joystick::getName() {
return name;
}

Joystick::Joystick() {
clearStates();
}

Joystick::Joystick(int i) : m_index(i) {
clearStates();
}

void Joystick::clearStates() {
for (int i = 0; i < 14; i++) {
m_state[i] = 0;
}
Joystick::Joystick(pntr_app* app, int i) : m_index(i), m_app(app) {
}

bool Joystick::isDown(int button) {
return static_cast<bool>(m_state[button]);
return pntr_app_gamepad_button_down(m_app, m_index, (pntr_app_gamepad_button)button);
}

bool Joystick::isDown(const std::string& button) {
Expand All @@ -43,28 +31,28 @@ int Joystick::getID() {
}

void Joystick::update() {
if (!isConnected()) {
return;
}

int16_t state;
// Loop through each button.
for (int u = 0; u < 14; u++) {
// Retrieve the state of the button.
state = ChaiLove::input_state_cb(m_index, RETRO_DEVICE_JOYPAD, 0, u);

// Check if there's a change of state.
if (m_state[u] != state) {
m_state[u] = state;

std::string name = ChaiLove::getInstance()->joystick.getButtonName(u);
if (state == 1) {
ChaiLove::getInstance()->script->joystickpressed(m_index, name);
} else if (state == 0) {
ChaiLove::getInstance()->script->joystickreleased(m_index, name);
}
}
}
// if (!isConnected()) {
// return;
// }

// int16_t state;
// // Loop through each button.
// for (int u = 0; u < 14; u++) {
// // Retrieve the state of the button.
// state = ChaiLove::input_state_cb(m_index, RETRO_DEVICE_JOYPAD, 0, u);

// // Check if there's a change of state.
// if (m_state[u] != state) {
// m_state[u] = state;

// std::string name = ChaiLove::getInstance()->joystick.getButtonName(u);
// if (state == 1) {
// ChaiLove::getInstance()->script->joystickpressed(m_index, name);
// } else if (state == 0) {
// ChaiLove::getInstance()->script->joystickreleased(m_index, name);
// }
// }
// }
}

} // namespace Input
Expand Down
8 changes: 4 additions & 4 deletions src/love/Types/Input/Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <string>

#include "pntr_app.h"

namespace love {
namespace Types {
namespace Input {
Expand All @@ -13,7 +15,7 @@ namespace Input {
class Joystick {
public:
Joystick();
Joystick(int index);
Joystick(pntr_app* app, int index);

/**
* Gets the name of the joystick.
Expand All @@ -22,7 +24,7 @@ class Joystick {
*/
std::string getName();

void clearStates();
pntr_app* m_app;

/**
* Checks if a button on the Joystick is pressed.
Expand Down Expand Up @@ -60,8 +62,6 @@ class Joystick {

private:
int m_index = 0;
std::string name = "RetroPad";
int16_t m_state[14];
bool m_connected = true;
};

Expand Down
11 changes: 6 additions & 5 deletions src/love/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "TinySHA1.hpp"
#include <cppcodec/base64_default_rfc4648.hpp>
#include <cppcodec/hex_default_lower.hpp>
#include "../LibretroLog.h"

namespace love {

Expand All @@ -26,7 +27,7 @@ std::string data::compress(const std::string& str, int compressionlevel) {
memset(&zs, 0, sizeof(zs));

if (deflateInit(&zs, compressionlevel) != Z_OK) {
//LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [data] deflateInit failed while compressing." << std::endl;
LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [data] deflateInit failed while compressing." << std::endl;
return str;
}

Expand All @@ -52,7 +53,7 @@ std::string data::compress(const std::string& str, int compressionlevel) {
deflateEnd(&zs);

if (ret != Z_STREAM_END) {
//LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [data] Exception during zlib compression: (" << ret << ") " << zs.msg << std::endl;
LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [data] Exception during zlib compression: (" << ret << ") " << zs.msg << std::endl;
return str;
}

Expand Down Expand Up @@ -107,7 +108,7 @@ std::string data::encode(const std::string& containerType, const std::string& fo
return encoded;
}

//LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] Warning: love.data.encode format not found: " << format << "." << std::endl;
LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] Warning: love.data.encode format not found: " << format << "." << std::endl;
return sourceString;
}

Expand All @@ -124,7 +125,7 @@ std::string data::decode(const std::string& containerType, const std::string& fo
return decoded;
}

//LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] Warning: love.data.decode format not found: " << format << "." << std::endl;
LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] Warning: love.data.decode format not found: " << format << "." << std::endl;
return sourceString;
}

Expand All @@ -137,7 +138,7 @@ std::string data::hash(const std::string& hashFunction, const std::string& data)
return hash_sha1(data);
}

//LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] Error: Hash function not found: " << hashFunction << "." << std::endl;
LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] Error: Hash function not found: " << hashFunction << "." << std::endl;
return "";
}

Expand Down
6 changes: 3 additions & 3 deletions src/love/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ void event::quit() {
}

void event::update() {
if (ChaiLove::hasInstance()) {
//if (ChaiLove::hasInstance()) {
// Poll all the inputs.
ChaiLove::input_poll_cb();
//ChaiLove::input_poll_cb();

// TODO(RobLoach): Is polling the SDL events required?
/*
Expand All @@ -23,7 +23,7 @@ void event::update() {
}
}
*/
}
//}
}

} // namespace love
Loading

0 comments on commit 605df2b

Please sign in to comment.