Skip to content

Commit

Permalink
cloean up
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach committed Jan 25, 2025
1 parent b1a678b commit f302448
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
12 changes: 10 additions & 2 deletions src/love/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,18 @@ std::string graphics::getDefaultFilter() {


int graphics::getWidth() {
return getScreen()->width;
pntr_image* screen = getScreen();
if (screen != NULL) {
return screen->width;
}
return 800;
}
int graphics::getHeight() {
return getScreen()->height;
pntr_image* screen = getScreen();
if (screen != NULL) {
return screen->height;
}
return 600;
}

Point graphics::getDimensions() {
Expand Down
31 changes: 31 additions & 0 deletions src/love/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,41 @@ std::string script::evalString(const std::string& code, const std::string& filen
return chai.eval<std::string>(contents, Exception_Handler(), filename);
}

void chailove_print(const std::string& message) {
pntr_app_log(PNTR_APP_LOG_INFO, message.c_str());
}

void chailove_dofile(const std::string& filename) {
ChaiLove* chailove = ChaiLove::getInstance();
const std::string& contents = chailove->filesystem.read(filename);
if (!contents.empty()) {
chailove->script->evalString(contents, filename);
}
else {
pntr_app_log_ex(PNTR_APP_LOG_ERROR, "[ChaiLove] dofile() script is empty: %s", filename.c_str());
}
}

void chailove_error(const std::string& message) {
pntr_app_log(PNTR_APP_LOG_ERROR, message.c_str());
}

void chailove_error_level(const std::string& message, int level) {
(void)level;
pntr_app_log(PNTR_APP_LOG_ERROR, message.c_str());
}

script::script(const std::string& file) {
#ifdef __HAVE_CHAISCRIPT__
ChaiLove* app = ChaiLove::getInstance();

// Override some of the global Lua functions
// https://www.lua.org/manual/5.4/manual.html#6.1
chai.add(fun(&chailove_print), "print");
chai.add(fun(&chailove_dofile), "dofile");
chai.add(fun(&chailove_error), "error");
chai.add(fun(&chailove_error_level), "error");

// ChaiScript Standard Library Additions
// This adds some basic type definitions to ChaiScript.
chai.add(bootstrap::standard_library::vector_type<std::vector<int>>("VectorInt"));
Expand Down
14 changes: 0 additions & 14 deletions src/love/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ using love::Types::Audio::SoundData;
namespace love {

bool sound::load(pntr_app* application) {
//audio_mixer_init(44100);
app = application;
m_loaded = true;
return true;
Expand All @@ -36,25 +35,12 @@ void sound::unload() {
}
sounds.clear();

// Close the audio mixer.
//audio_mixer_done();
m_loaded = false;
app = NULL;
}


SoundData* sound::newSoundData(const std::string& filename) {
return ChaiLove::getInstance()->audio.newSource(filename);
}

void sound::update() {
// int bufferSize = 44100 / 60;
// float samples[1470] = { 0 }; // 44100 / 60 * 2
// int16_t samples2[1470] = { 0 }; // 44100 / 60 * 2
// audio_mixer_mix(samples, bufferSize, 1.0, false);
// convert_float_to_s16(samples2, samples, 2 * bufferSize);
// audio_batch_cb(samples2, bufferSize);
}


} // namespace love
1 change: 0 additions & 1 deletion src/love/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class sound {
bool isLoaded();
bool hasAudio();
void unload();
void update();

~sound();

Expand Down

0 comments on commit f302448

Please sign in to comment.