From 6abad6b15b84f97007dff394c20ff4e3ae931fa7 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Fri, 3 Jan 2025 02:21:04 -0500 Subject: [PATCH 1/3] Update to pntr --- Makefile.common | 108 +----- README.md | 12 +- docs/Doxyfile | 2 +- src/ChaiLove.cpp | 32 +- src/ChaiLove.h | 15 +- src/libretro.cpp | 511 ----------------------------- src/love/Types/Audio/SoundData.cpp | 102 +----- src/love/Types/Audio/SoundData.h | 42 +-- src/love/Types/Graphics/Color.cpp | 4 +- src/love/Types/Graphics/Color.h | 20 +- src/love/Types/Graphics/Font.cpp | 126 ++----- src/love/Types/Graphics/Font.h | 12 +- src/love/Types/Graphics/Image.cpp | 43 +-- src/love/Types/Graphics/Image.h | 8 +- src/love/Types/Graphics/Quad.cpp | 10 +- src/love/Types/Graphics/Quad.h | 4 +- src/love/Types/Input/Joystick.cpp | 2 +- src/love/audio.cpp | 2 +- src/love/config.cpp | 1 - src/love/config.h | 16 - src/love/console.cpp | 214 ------------ src/love/console.h | 55 ---- src/love/data.cpp | 10 +- src/love/event.cpp | 1 - src/love/event.h | 2 - src/love/filesystem.cpp | 54 ++- src/love/filesystem.h | 4 +- src/love/font.cpp | 18 +- src/love/graphics.cpp | 131 ++++---- src/love/graphics.h | 10 +- src/love/joystick.cpp | 7 +- src/love/joystick.h | 2 +- src/love/keyboard.cpp | 13 +- src/love/math.cpp | 20 +- src/love/math.h | 6 +- src/love/script.cpp | 105 +++--- src/love/script.h | 3 - src/love/sound.cpp | 26 +- src/love/sound.h | 4 +- src/love/system.cpp | 14 +- src/love/system.h | 1 - src/love/window.cpp | 101 +++--- src/main.cpp | 108 ++++++ vendor/noarch | 2 +- 44 files changed, 458 insertions(+), 1525 deletions(-) delete mode 100644 src/libretro.cpp delete mode 100644 src/love/console.cpp delete mode 100644 src/love/console.h create mode 100644 src/main.cpp diff --git a/Makefile.common b/Makefile.common index 143d8dcfe..6c54baedc 100644 --- a/Makefile.common +++ b/Makefile.common @@ -11,8 +11,15 @@ SOURCES_CXX := $(wildcard \ SOURCES_S = FLAGS += -Wfatal-errors -# random -FLAGS += -I$(CORE_DIR)/vendor/random/include +# pntr +FLAGS += -I$(CORE_DIR)/vendor/pntr +FLAGS += -I$(CORE_DIR)/vendor/pntr_app/include +FLAGS += \ + -DPNTR_CUTE_PNG \ + -DPNTR_ENABLE_VARGS + +# pntr_physfs +FLAGS += -I$(CORE_DIR)/vendor/pntr_physfs # libretro-common FLAGS += -I$(CORE_DIR)/vendor/libretro-common/include \ @@ -47,13 +54,12 @@ ifneq ($(STATIC_LINKING), 1) SOURCES_C += $(CORE_DIR)/vendor/libretro-common/string/stdstring.c SOURCES_C += $(CORE_DIR)/vendor/libretro-common/time/rtime.c SOURCES_C += $(CORE_DIR)/vendor/libretro-common/vfs/vfs_implementation.c - SOURCES_C += $(CORE_DIR)/vendor/libretro-common/compat/fopen_utf8.c + #SOURCES_C += $(CORE_DIR)/vendor/libretro-common/compat/fopen_utf8.c # Ensure the sinc_resampler_neon is available for ARM NEON devices. SOURCES_S += $(CORE_DIR)/vendor/libretro-common/audio/resampler/drivers/sinc_resampler_neon.S # MD5 - FLAGS += -I$(CORE_DIR)/vendor/libretro-common/include SOURCES_C += $(CORE_DIR)/vendor/libretro-common/utils/md5.c endif @@ -94,14 +100,13 @@ FLAGS += -DWANT_ZLIB # PhysFS PHYSFS_DIR = $(CORE_DIR)/vendor/physfs-libretro FLAGS += -I$(PHYSFS_DIR)/src -FLAGS += -I$(PHYSFS_DIR)/extras + FLAGS += -DPHYSFS_NO_CDROM_SUPPORT=1 \ -DPHYSFS_SUPPORTS_DEFAULT=0 \ -DPHYSFS_SUPPORTS_ZIP=1 \ -DPHYSFS_PLATFORM_LIBRETRO SOURCES_C += $(wildcard \ - $(PHYSFS_DIR)/extras/physfsrwops.c \ $(PHYSFS_DIR)/src/*.c \ ) ifeq ($(platform), osx) @@ -112,88 +117,6 @@ ifeq ($(platform), osx) FLAGS += -D__MACH__ -D__APPLE__ endif -# SDL_tty -FLAGS += -I$(CORE_DIR)/vendor/SDL_tty/include/SDL_tty -SOURCES_C += $(wildcard \ - $(CORE_DIR)/vendor/SDL_tty/src/SDL_fnt.c \ - $(CORE_DIR)/vendor/SDL_tty/src/SDL_tty.c \ -) - -# SDL_gfx -FLAGS += -I$(CORE_DIR)/vendor/sdl-libretro/tests/SDL_gfx-2.0.26 -SOURCES_C += $(wildcard \ - $(CORE_DIR)/vendor/sdl-libretro/tests/SDL_gfx-2.0.26/*.c \ -) - -# FreeType2 -# See https://github.com/emscripten-ports/FreeType/blob/master/builds/amiga/makefile -FLAGS += -I$(CORE_DIR)/vendor/libretro-deps/freetype/include -FLAGS += -DFT2_BUILD_LIBRARY \ - -DFT_USE_AUTOFIT \ - -DFT_USE_RASTER \ - -DFT_USE_SMOOTH \ - -DFT_USE_TT \ - -DFT_USE_T1 \ - -DFT_USE_T42 \ - -DFT_USE_T1CID \ - -DFT_USE_CFF \ - -DFT_USE_OTV \ - -DFT_USE_GXV - -SOURCES_C += \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/autofit/autofit.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftbase.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftbbox.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftbdf.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftbitmap.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftcid.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftdebug.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftfntfmt.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftfstype.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftgasp.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftglyph.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftgxval.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftinit.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftlcdfil.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftmm.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftotval.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftpatent.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftpfr.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftstroke.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftsynth.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftsystem.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/fttype1.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftwinfnt.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/bdf/bdf.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/bzip2/ftbzip2.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/cache/ftcache.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/cff/cff.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/cid/type1cid.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/gzip/ftgzip.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/lzw/ftlzw.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/pcf/pcf.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/pfr/pfr.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/psaux/psaux.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/pshinter/pshinter.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/psnames/psnames.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/raster/raster.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/sfnt/sfnt.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/smooth/smooth.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/truetype/truetype.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/type1/type1.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/type42/type42.c \ - $(CORE_DIR)/vendor/libretro-deps/freetype/src/winfonts/winfnt.c - -# SDL_ttf -FLAGS += -I$(CORE_DIR)/vendor/sdl-libretro/tests/SDL_ttf-2.0.11/VisualC/external/include -SOURCES_C += $(CORE_DIR)/vendor/sdl-libretro/tests/SDL_ttf-2.0.11/SDL_ttf.c - -# SDL_stbimage -FLAGS += -I$(CORE_DIR)/vendor/Snippets - -# STB -FLAGS += -I$(CORE_DIR)/vendor/stb - # TinySHA1 FLAGS += -I$(CORE_DIR)/vendor/TinySHA1 @@ -209,15 +132,6 @@ ifeq ($(HAVE_CHAISCRIPT),) FLAGS += -DCHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED endif -# SDL -ifeq ($(platform), win) - SOURCES_C += $(wildcard ./vendor/sdl-libretro/src/*.c ./vendor/sdl-libretro/src/audio/*.c ./vendor/sdl-libretro/src/cdrom/dummy/*.c ./vendor/sdl-libretro/src/cdrom/*.c ./vendor/sdl-libretro/src/cpuinfo/*.c ./vendor/sdl-libretro/src/events/*.c ./vendor/sdl-libretro/src/file/*.c ./vendor/sdl-libretro/src/stdlib/*.c ./vendor/sdl-libretro/src/thread/*.c ./vendor/sdl-libretro/src/timer/*.c ./vendor/sdl-libretro/src/video/*.c ./vendor/sdl-libretro/src/joystick/*.c ./vendor/sdl-libretro/src/video/libretro/*.c ./vendor/sdl-libretro/src/joystick/libretro/*.c ./vendor/sdl-libretro/src/timer/libretro/*.c ./vendor/sdl-libretro/src/audio/libretro/*.c ./vendor/sdl-libretro/src/thread/win32/SDL_sysmutex.c ./vendor/sdl-libretro/src/thread/win32/SDL_syssem.c ./vendor/sdl-libretro/src/thread/win32/SDL_systhread.c ./vendor/sdl-libretro/src/thread/generic/SDL_syscond.c ./vendor/sdl-libretro/src/loadso/dummy/*.c) -else - SOURCES_C += $(wildcard $(CORE_DIR)/vendor/sdl-libretro/src/*.c $(CORE_DIR)/vendor/sdl-libretro/src/audio/*.c $(CORE_DIR)/vendor/sdl-libretro/src/cdrom/dummy/*.c $(CORE_DIR)/vendor/sdl-libretro/src/cdrom/*.c $(CORE_DIR)/vendor/sdl-libretro/src/cpuinfo/*.c $(CORE_DIR)/vendor/sdl-libretro/src/events/*.c $(CORE_DIR)/vendor/sdl-libretro/src/file/*.c $(CORE_DIR)/vendor/sdl-libretro/src/stdlib/*.c $(CORE_DIR)/vendor/sdl-libretro/src/thread/*.c $(CORE_DIR)/vendor/sdl-libretro/src/timer/*.c $(CORE_DIR)/vendor/sdl-libretro/src/video/*.c $(CORE_DIR)/vendor/sdl-libretro/src/joystick/*.c $(CORE_DIR)/vendor/sdl-libretro/src/video/libretro/*.c $(CORE_DIR)/vendor/sdl-libretro/src/thread/generic/*.c $(CORE_DIR)/vendor/sdl-libretro/src/joystick/libretro/*.c $(CORE_DIR)/vendor/sdl-libretro/src/timer/libretro/*.c $(CORE_DIR)/vendor/sdl-libretro/src/audio/libretro/*.c $(CORE_DIR)/vendor/sdl-libretro/src/loadso/dummy/*.c) -endif -FLAGS += -DSDL_THREADS_DISABLED -DSDL_CDROM_DISABLED -FLAGS += -I$(CORE_DIR)/vendor/sdl-libretro/include - OBJECTS += $(SOURCES_CXX:.cpp=.o) $(SOURCES_C:.c=.o) $(SOURCES_S:.S=.o) $(SOURCES_M:.m=.o) LDFLAGS += $(fpic) $(SHARED) $(EXTRA_LDF) diff --git a/README.md b/README.md index 4d9595611..0ed4e1fe5 100644 --- a/README.md +++ b/README.md @@ -108,12 +108,20 @@ make docs The following individuals contributed to ChaiLove in some way: - [@RobLoach](http://github.com/robloach) +- [@phcoder](https://github.com/phcoder) for the many builtbot fixes - [@webgeek1234](http://github.com/webgeek1234) for the Android support -- [@r-type](https://github.com/r-type) for his work on [sdl-libretro](https://github.com/r-type/sdl-libretro) -- [@mudlord](https://github.com/mudlord) for his work on the [libretro-common](https://github.com/libretro/libretro-common) audio system +- [@r-type](https://github.com/r-type) for [sdl-libretro](https://github.com/r-type/sdl-libretro) +- [@mudlord](https://github.com/mudlord) for the [libretro-common](https://github.com/libretro/libretro-common) audio system - [@orbea](http://github.com/orbea) - [@fetzerch](http://github.com/fetzerch) - [@bparker06](https://github.com/bparker06) - [@twinaphex](http://github.com/twinaphex) - [@ToKe79](https://github.com/ToKe79) +- [@konsumer](https://github.com/konsumer) - [@baxysquare](https://github.com/baxysquare) for the [Logo](docs/chailove.png) + +And many others! + +## License + +[MIT](COPYING) diff --git a/docs/Doxyfile b/docs/Doxyfile index 18a4a7b24..47301eed3 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -23,7 +23,7 @@ PROJECT_NAME = "ChaiLove API" # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = "1.0.0" +PROJECT_NUMBER = "2.0.0" # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. diff --git a/src/ChaiLove.cpp b/src/ChaiLove.cpp index c32a22d04..6dd40f7c9 100644 --- a/src/ChaiLove.cpp +++ b/src/ChaiLove.cpp @@ -1,7 +1,6 @@ #include "ChaiLove.h" #include "LibretroLog.h" #include -#include #include ChaiLove* ChaiLove::m_instance = NULL; @@ -10,19 +9,19 @@ 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; @@ -62,15 +61,15 @@ bool ChaiLove::load(const std::string& file, const void* 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(); + sound.load(app); // Initalize the file system. bool loaded = filesystem.init(file, data); if (!loaded) { - 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; } @@ -79,7 +78,7 @@ bool ChaiLove::load(const std::string& file, const void* 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); @@ -88,12 +87,11 @@ bool ChaiLove::load(const std::string& file, const void* data) { // Load up the window dimensions. window.load(config); - console.load(config); graphics.load(); image.load(); keyboard.load(); joystick.load(); - math.load(); + math.load(app); mouse.load(); font.load(); @@ -123,7 +121,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(); } @@ -146,13 +144,13 @@ void ChaiLove::draw() { } // Render the in-game console. - console.draw(); + //console.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; - } + // if (SDL_Flip(screen) == -1) { + // std::string out("[ChaiLove] Failed to swap the buffers: "); + // //LibretroLog::log(RETRO_LOG_ERROR) << out << SDL_GetError() << std::endl; + // } } /** diff --git a/src/ChaiLove.h b/src/ChaiLove.h index 408abb5ba..dca6c6e9c 100644 --- a/src/ChaiLove.h +++ b/src/ChaiLove.h @@ -44,12 +44,13 @@ #ifndef SRC_CHAILOVE_H_ #define SRC_CHAILOVE_H_ -#define CHAILOVE_VERSION_MAJOR 1 -#define CHAILOVE_VERSION_MINOR 3 +#define CHAILOVE_VERSION_MAJOR 2 +#define CHAILOVE_VERSION_MINOR 0 #define CHAILOVE_VERSION_PATCH 0 -#define CHAILOVE_VERSION_STRING "1.3.0" +#define CHAILOVE_VERSION_STRING "2.0.0-pre" + +#include "pntr_app.h" -#include "SDL.h" #include "libretro.h" #include "love/keyboard.h" #include "love/config.h" @@ -68,7 +69,6 @@ #include "love/window.h" #include "love/math.h" #include "love/event.h" -#include "love/console.h" class ChaiLove { public: @@ -82,7 +82,6 @@ class ChaiLove { static retro_environment_t environ_cb; love::config config; - love::console console; love::keyboard keyboard; love::script* script = NULL; love::data data; @@ -111,8 +110,8 @@ class ChaiLove { void cheatreset(); void cheatset(int index, bool enabled, const std::string& code); - uint32_t *videoBuffer = NULL; - SDL_Surface* screen = NULL; + pntr_image* screen = NULL; + pntr_app* app = NULL; }; #endif // SRC_CHAILOVE_H_ diff --git a/src/libretro.cpp b/src/libretro.cpp deleted file mode 100644 index 9378d85f7..000000000 --- a/src/libretro.cpp +++ /dev/null @@ -1,511 +0,0 @@ -#include -#include -#include -#include -#include "libretro.h" -#include "libretro_core_options.h" -#define __STDC_FORMAT_MACROS -#include "ChaiLove.h" -#include "LibretroLog.h" - -static void fallback_log(enum retro_log_level level, - const char *fmt, ...); - -static retro_video_refresh_t video_cb; -retro_log_printf_t log_cb = fallback_log; - -// This is needed to allow SDL-libretro to compile. -// @see SDL_LIBRETROaudio.c:37 -retro_audio_sample_t audio_cb; - -void retro_set_video_refresh(retro_video_refresh_t cb) { - video_cb = cb; -} - -void retro_set_audio_sample(retro_audio_sample_t cb) { - ChaiLove::getInstance()->sound.audio_cb = cb; -} - -void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { - ChaiLove::getInstance()->sound.audio_batch_cb = cb; -} - -void retro_set_input_poll(retro_input_poll_t cb) { - ChaiLove::input_poll_cb = cb; -} - -void retro_set_input_state(retro_input_state_t cb) { - ChaiLove::input_state_cb = cb; -} - -static void fallback_log(enum retro_log_level level, - const char *fmt, ...) { - va_list args; - - (void) level; - - va_start(args, fmt); - vfprintf(stderr, fmt, args); - va_end(args); -} - -#ifdef __cplusplus -extern "C" { -#endif - -void libretro_audio_cb(int16_t left, int16_t right) { - // Nothing, since we're using libretro-common. - // audio_cb(left, right); -} - -/** - * libretro-sdl callback; Send through the input state. - */ -short int libretro_input_state_cb(unsigned port, unsigned device, unsigned index, unsigned id) { - return ChaiLove::input_state_cb(port, device, index, id); -} -#ifdef __cplusplus -} -#endif - -/** - * libretro callback; Sets up the environment based on the system variables. - */ -void retro_set_environment(retro_environment_t cb) { - // Set the environment callback. - ChaiLove::environ_cb = cb; - - // The core requires content. - bool no_rom = false; - cb(RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME, &no_rom); - - // Configure the core options. - libretro_set_core_options(cb); - - struct retro_log_callback log; - - if (cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log)) { - log_cb = log.log; - } -} - -/** - * libretro callback; Updates the core option variables. - */ -static void update_variables(void) { - ChaiLove* app = ChaiLove::getInstance(); - app->system.updateVariables(app->config); -} - -#ifdef __cplusplus -extern "C" { -#endif -/** - * libretro callback; Load the labels for the input buttons. - */ -void init_descriptors() { - struct retro_input_descriptor desc[] = { - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Left Shoulder" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Right Shoulder" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Left Shoulder" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Right Shoulder" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Left Shoulder" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Right Shoulder" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Left Shoulder" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Right Shoulder" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Left Shoulder" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Right Shoulder" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - { 0 }, - }; - - ChaiLove::environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc); -} -#ifdef __cplusplus -} -#endif - -/** - * libretro callback; Retrieve information about the core. - */ -void retro_get_system_info(struct retro_system_info *info) { - memset(info, 0, sizeof(*info)); - - // The name of the core. - info->library_name = "ChaiLove"; -#ifndef GIT_VERSION -#define GIT_VERSION "" -#endif - - // The ChaiLove version. - info->library_version = CHAILOVE_VERSION_STRING GIT_VERSION; - - // When loading a game, request the full path to the game. - info->need_fullpath = true; - - // File extensions that are used. - info->valid_extensions = "chai|chailove"; - - // Do not extract .zip files. - info->block_extract = true; -} - -/** - * libretro callback; Set the audio/video settings. - */ -void retro_get_system_av_info(struct retro_system_av_info *info) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] retro_get_system_av_info" << std::endl; - if (!ChaiLove::hasInstance()) { - return; - } - unsigned int width = 640; - unsigned int height = 480; - - ChaiLove* app = ChaiLove::getInstance(); - if (app != NULL) { - width = app->config.window.width; - height = app->config.window.height; - } - - info->geometry.base_width = width; - info->geometry.base_height = height; - info->geometry.max_width = width; - info->geometry.max_height = height; - info->geometry.aspect_ratio = static_cast(width) / static_cast(height); - - info->timing.fps = 60.0; - info->timing.sample_rate = 44100.0; -} - -void retro_set_controller_port_device(unsigned port, unsigned device) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] retro_set_controller_port_device" << std::endl; - (void)port; - (void)device; -} - -/** - * libretro callback; Return the amount of bytes required to save a state. - */ -size_t retro_serialize_size(void) { - // Save states will be 8 KB. - return 8192; -} - -/** - * libretro callback; Serialize the current state to save a slot. - */ -bool retro_serialize(void *data, size_t size) { - if (!ChaiLove::hasInstance()) { - return false; - } - - // Ask ChaiLove for save data. - ChaiLove* app = ChaiLove::getInstance(); - std::string state = app->savestate(); - if (state.empty()) { - return false; - } - - // Encode the JSON state data. Disabled for speed. - // state = app->data.encode("string", "base64", state); - // state = app->data.compress(state); - - // Save the information to the state data. - std::copy(state.begin(), state.end(), reinterpret_cast(data)); - return true; -} - -/** - * libretro callback; Unserialize the given data and load the state. - */ -bool retro_unserialize(const void *data, size_t size) { - if (!ChaiLove::hasInstance() || size <= 0) { - return false; - } - - // Create a string stream from the data. - std::stringstream ss(std::string( - reinterpret_cast(data), - reinterpret_cast(data) + size)); - - // Port the string stream to a straight string. - std::string loadData = ss.str(); - - // Pass the string to the script. - ChaiLove* app = ChaiLove::getInstance(); - - // Decompress the state data. Disabled for speed. - // loadData = app->data.decode("string", "base64", loadData); - // loadData = app->data.decompress(loadData); - - // Finally, load the string. - return app->loadstate(loadData); -} - -/** - * libretro callback; Reset the enabled cheats. - */ -void retro_cheat_reset(void) { - if (ChaiLove::hasInstance()) { - ChaiLove::getInstance()->cheatreset(); - } -} - -/** - * libretro callback; Set the given cheat. - */ -void retro_cheat_set(unsigned index, bool enabled, const char *code) { - if (ChaiLove::hasInstance()) { - std::string codeString(code); - ChaiLove::getInstance()->cheatset(index, enabled, codeString); - } -} - -/** - * libretro callback; Step the core forwards a step. - */ -void frame_time_cb(retro_usec_t usec) { - if (ChaiLove::hasInstance()) { - float delta = (float)usec / 1000000.0f; - ChaiLove::getInstance()->timer.step(delta); - } -} - -/** - * libretro callback; Step the audio forwards a step. - */ -void retro_audio_cb() { - // Update the sound system. - ChaiLove::getInstance()->sound.update(); -} - -/** - * libretro callback; Set the current state of the audio. - */ -void audio_set_state(bool enabled) { - // TODO(RobLoach): Act on whether or not audio is enabled/disabled? - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] audio_set_state(" << (enabled ? "true" : "false") << ")" << std::endl; -} - -/** - * libretro callback; Load the given game. - */ -bool retro_load_game(const struct retro_game_info *info) { - // Update the core options. - update_variables(); - - // Update the input button descriptions. - init_descriptors(); - - // Set the frame rate callback. - struct retro_frame_time_callback frame_cb = { frame_time_cb, 1000000 / 60 }; - ChaiLove::environ_cb(RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK, &frame_cb); - - // Set the audio callback. - struct retro_audio_callback retro_audio = { retro_audio_cb, audio_set_state }; - ChaiLove::environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK, &retro_audio); - - // Find the game path. - std::string gamePath(info ? info->path : ""); - if (gamePath == ".") { - gamePath = "main.chai"; - } - void* data = NULL; - if (info != NULL) { - data = (void*)info->data; - } - return ChaiLove::getInstance()->load(gamePath, data); -} - -/** - * libretro callback; Loads the given special game. - */ -bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] retro_load_game_special" << std::endl; - return retro_load_game(info); -} - -/** - * libretro callback; Unload the current game. - */ -void retro_unload_game(void) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] retro_unload_game()" << std::endl; - - // Invoke the quit event. - if (ChaiLove::hasInstance()) { - ChaiLove::getInstance()->event.m_shouldclose = true; - } -} - -/** - * libretro callback; Retrieve the active region. - */ -unsigned retro_get_region(void) { - return RETRO_REGION_NTSC; -} - -/** - * libretro callback; Get the libretro API version. - */ -unsigned retro_api_version(void) { - return RETRO_API_VERSION; -} - -/** - * libretro callback; Get the given memory ID. - */ -void *retro_get_memory_data(unsigned id) { - return NULL; -} - -/** - * libretro callback; Get the size of the given memory ID. - */ -size_t retro_get_memory_size(unsigned id) { - return 0; -} - -/** - * libretro callback; Initialize the core. - */ -void retro_init(void) { - // Pixel Format - enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888; - if (!ChaiLove::environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] Pixel format XRGB8888 not supported by platform, cannot use." << std::endl; - } -} - -/** - * libretro callback; Deinitialize the core. - */ -void retro_deinit(void) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] retro_deinit()" << std::endl; - ChaiLove::destroy(); -} - -/** - * libretro callback; The frontend requested to reset the game. - */ -void retro_reset(void) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] retro_reset()" << std::endl; - if (ChaiLove::hasInstance()) { - ChaiLove::getInstance()->reset(); - } -} - -int LibretroLog::LoggerBuf::sync() { - const std::string &s = str(); - if (!s.empty()) { - if (s[s.length() - 1] == '\n') - log_cb(level, "%s", s.c_str()); - else - log_cb(level, "%s\n", s.c_str()); - } - str() = ""; - return 0; -} - -std::ostream &LibretroLog::log(enum retro_log_level level) { - static LibretroLog::LoggerBuf *bufs[RETRO_LOG_ERROR + 1] = {0}; - static std::ostream *streams[RETRO_LOG_ERROR + 1] = {0}; - if (!bufs[level]) { - bufs[level] = new LibretroLog::LoggerBuf(level); - streams[level] = new std::ostream(bufs[level]); - } - return *streams[level]; -} - -/** - * libretro callback; Run a game loop in the core. - */ -void retro_run(void) { - // Ensure there is a game running. - if (!ChaiLove::hasInstance()) { - return; - } - - // Check if the game should be closed. - ChaiLove* app = ChaiLove::getInstance(); - if (app->event.m_shouldclose) { - return; - } - - bool updated = false; - if (ChaiLove::environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) { - update_variables(); - } - - // Update the game. - app->update(); - - // Render the game. - app->draw(); - - // Copy the video buffer to the screen. - video_cb(app->videoBuffer, app->config.window.width, app->config.window.height, app->config.window.width << 2); - - // See if the game requested to close itself. - if (app->event.m_shouldclose) { - ChaiLove::environ_cb(RETRO_ENVIRONMENT_SHUTDOWN, 0); - } -} - -#ifdef _3DS -extern "C" int nanosleep(const struct timespec *req, struct timespec *rem) { - return 0; -} -#endif diff --git a/src/love/Types/Audio/SoundData.cpp b/src/love/Types/Audio/SoundData.cpp index bf5fe2bcd..8a425842c 100644 --- a/src/love/Types/Audio/SoundData.cpp +++ b/src/love/Types/Audio/SoundData.cpp @@ -13,83 +13,23 @@ namespace Audio { SoundData::SoundData(const std::string& filename) { // Check the extension. ChaiLove* app = ChaiLove::getInstance(); - std::string extension = app->filesystem.newFileData(filename).getExtension(); - if (extension != "wav" && extension != "ogg") { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [SoundData] Unknown extension " << extension << " for file " << filename << "." << std::endl; - return; - } - - // Load the file. - int size = 0; - buffer = app->filesystem.readBuffer(filename, size); - if (buffer == NULL) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [SoundData] Failed to load file " << filename << std::endl; - return; - } - - // Load the audio from the file. - if (extension == "wav") { - m_sound = audio_mixer_load_wav(buffer, size, "audio", RESAMPLER_QUALITY_DONTCARE); - // Wav files don't need the buffer anymore. - free(buffer); - buffer = NULL; - } else if (extension == "ogg") { - m_sound = audio_mixer_load_ogg(buffer, size); - } - - // Finally, if it failed, report as such. - if (m_sound == NULL) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [SoundData] Failed to load audio for " << filename << std::endl; - if (buffer != NULL) { - free(buffer); - buffer = NULL; - } - } + m_sound = pntr_load_sound(filename.c_str()); } SoundData::~SoundData() { unload(); } -float SoundData::getVolume() { - if (m_voice != NULL) { - m_volume = audio_mixer_voice_get_volume(m_voice); - } - - return m_volume; -} - -SoundData& SoundData::setVolume(float volume) { - if (volume > 1.0f) { - volume = 1.0f; - } else if (volume < 0.0f) { - volume = 0.0f; - } - m_volume = volume; - if (m_voice != NULL) { - audio_mixer_voice_set_volume(m_voice, m_volume); - } - - return *this; -} - void SoundData::unload() { - if (m_voice != NULL) { - audio_mixer_stop(m_voice); - m_voice = NULL; - } if (m_sound != NULL) { - audio_mixer_destroy(m_sound); + pntr_unload_sound(m_sound); m_sound = NULL; } } bool SoundData::play() { if (isLoaded()) { - m_voice = audio_mixer_play(m_sound, m_loop, m_volume, "audio", RESAMPLER_QUALITY_DONTCARE, audioCallback); - if (m_voice != NULL) { - m_playing = true; - } + pntr_play_sound(m_sound, m_loop); return true; } return false; @@ -97,9 +37,7 @@ bool SoundData::play() { bool SoundData::stop() { if (isLoaded()) { - if (m_voice != NULL) { - audio_mixer_stop(m_voice); - } + pntr_stop_sound(m_sound); } return true; } @@ -108,10 +46,6 @@ bool SoundData::isLoaded() { return m_sound != NULL; } -bool SoundData::isPlaying() { - return m_playing; -} - bool SoundData::isLooping() { return m_loop; } @@ -121,34 +55,6 @@ SoundData& SoundData::setLooping(bool looping) { return *this; } -void SoundData::audioCallback(audio_mixer_sound_t* sound, unsigned reason) { - // This is called when an audio finishes. - ChaiLove* app = ChaiLove::getInstance(); - - // Loop through all sounds, and find the given one. - std::vector v = app->sound.sounds; - for(std::vector::iterator it = v.begin(); it != v.end(); ++it) { - SoundData* currentsound = *it; - if (currentsound == NULL) { - continue; - } - // We found the active sound. - if (currentsound->m_sound == sound) { - switch (reason) { - case AUDIO_MIXER_SOUND_FINISHED: - case AUDIO_MIXER_SOUND_STOPPED: - currentsound->m_playing = false; - break; - case AUDIO_MIXER_SOUND_REPEATED: - currentsound->m_playing = true; - break; - } - break; - } - } -} - - } // namespace Audio } // namespace Types } // namespace love diff --git a/src/love/Types/Audio/SoundData.h b/src/love/Types/Audio/SoundData.h index 5939cfcfd..9abe004a6 100644 --- a/src/love/Types/Audio/SoundData.h +++ b/src/love/Types/Audio/SoundData.h @@ -4,6 +4,8 @@ #include #include "audio/audio_mixer.h" +#include "pntr_app.h" + namespace love { namespace Types { namespace Audio { @@ -29,33 +31,6 @@ class SoundData { void unload(); bool isLoaded(); - /** - * Gets the current volume of the Source. - * - * @return The volume of the source, from 0.0f to 1.0f. - * - * @see setVolume - */ - float getVolume(); - - /** - * Sets the current volume of the Source. - * - * @param volume The volume to set the source at, from 0.0f to 1.0f. - * - * @return The SoundData object iself, to allow for method chaining. - * - * @see getVolume - */ - SoundData& setVolume(float volume); - - /** - * Returns whether the Source is playing. - * - * @return True if the sound is playing. - */ - bool isPlaying(); - /** * Returns whether the Source will loop. * @@ -70,17 +45,8 @@ class SoundData { */ SoundData& setLooping(bool loop); - // The audio callback for when a sound finishes. - static void audioCallback(audio_mixer_sound_t* sound, unsigned reason); - - // Properties - bool m_playing = false; - bool m_loop = false; - float m_volume = 1.0f; - void* buffer = NULL; - audio_mixer_sound* m_sound = NULL; - // TODO(RobLoach): Make voice a vector? - audio_mixer_voice_t* m_voice = NULL; + pntr_sound* m_sound; + bool m_loop; }; } // namespace Audio diff --git a/src/love/Types/Graphics/Color.cpp b/src/love/Types/Graphics/Color.cpp index 7cfb7b8db..c09492c38 100644 --- a/src/love/Types/Graphics/Color.cpp +++ b/src/love/Types/Graphics/Color.cpp @@ -4,7 +4,9 @@ namespace love { namespace Types { namespace Graphics { -// Nothing. +pntr_color Color::to_pntr_color() { + return pntr_new_color(r, g, b, a); +} } // namespace Graphics } // namespace Types diff --git a/src/love/Types/Graphics/Color.h b/src/love/Types/Graphics/Color.h index b4c581710..8e388d4ff 100644 --- a/src/love/Types/Graphics/Color.h +++ b/src/love/Types/Graphics/Color.h @@ -1,7 +1,7 @@ #ifndef SRC_LOVE_TYPES_GRAPHICS_COLOR_H_ #define SRC_LOVE_TYPES_GRAPHICS_COLOR_H_ -#include "SDL.h" +#include "pntr_app.h" namespace love { namespace Types { @@ -32,6 +32,15 @@ struct Color { // Nothing. } + Color(pntr_color color) { + r = pntr_color_r(color); + g = pntr_color_g(color); + b = pntr_color_b(color); + a = pntr_color_a(color); + } + + pntr_color to_pntr_color(); + /** * The amount of red. */ @@ -51,15 +60,6 @@ struct Color { * The amount of alpha. */ int a; - - SDL_Color toSDLColor() { - SDL_Color c; - c.r = r; - c.g = g; - c.b = b; - c.unused = a; - return c; - } }; } // namespace Graphics diff --git a/src/love/Types/Graphics/Font.cpp b/src/love/Types/Graphics/Font.cpp index 38f39718d..f3a3e72d7 100644 --- a/src/love/Types/Graphics/Font.cpp +++ b/src/love/Types/Graphics/Font.cpp @@ -1,9 +1,6 @@ #include "Font.h" -#include "SDL.h" +#include "pntr_app.h" #include -#include "SDL_ttf.h" -#include -#include #include "../../../ChaiLove.h" #include "../../../LibretroLog.h" #include "Image.h" @@ -13,40 +10,15 @@ namespace Types { namespace Graphics { Font::Font() { - // Nothing. + font = pntr_load_font_default(); } Font::Font(const std::string& filename, int glyphWidth, int glyphHeight, const std::string& letters) { - m_image = new Image(filename); - if (m_image->loaded()) { - TTY_Font* newFont = FNT_Create(m_image->surface, glyphWidth, glyphHeight, letters.c_str()); - if (newFont == NULL) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] Error creating FNT_Create()" << std::endl; - return; - } - - ttyFont = newFont; - ttyFontWidth = glyphWidth; - ttyFontHeight = glyphHeight; - } + font = pntr_load_font_tty(filename.c_str(), glyphWidth, glyphHeight, letters.c_str()); } Font::Font(const std::string& filename, int ptsize) { - SDL_RWops* rwops = ChaiLove::getInstance()->filesystem.openRW(filename); - if (rwops) { - TTF_Font* newFont = TTF_OpenFontRW(rwops, 1, ptsize); - if (!newFont) { - const char* errorChar = TTF_GetError(); - std::string errString(""); - if (errorChar != NULL) { - errString = errorChar; - } - LibretroLog::log(RETRO_LOG_ERROR) << "TTF_OpenFontRW: " << errString << std::endl; - return; - } - - ttfFont = newFont; - } + font = pntr_load_font_ttf(filename.c_str(), ptsize); } Font::~Font() { @@ -54,100 +26,50 @@ Font::~Font() { } bool Font::loaded() { - return ttfFont != NULL || ttyFont != NULL; + return font != NULL; } bool Font::destroy() { - if (ttfFont != NULL) { - TTF_CloseFont(ttfFont); - ttfFont = NULL; - } - - if (ttyFont != NULL) { - FNT_Free(ttyFont); - ttyFont = NULL; - } - - if (m_image != NULL) { - delete m_image; - m_image = NULL; + if (font != NULL) { + pntr_unload_font(font); + font = NULL; } return true; } int Font::getHeight(const std::string& text) { - if (ttfFont != NULL) { - return TTF_FontHeight(ttfFont); - } - if (ttyFont != NULL) { - return FNT_GetTextHeight(ttyFont, text.c_str()); - } - - return 12; + pntr_vector size = pntr_measure_text_ex(font, text.c_str(), text.length()); + return size.y; } int Font::getHeight() { - if (ttfFont != NULL) { - return TTF_FontHeight(ttfFont); - } - if (ttyFont != NULL) { - return ttyFontHeight; - } - - return 12; + return getHeight("A"); } int Font::getWidth(const std::string& text) { - if (ttfFont != NULL) { - int w; - if (TTF_SizeText(ttfFont, text.c_str(), &w, NULL) == 0) { - return w; - } - } - - if (ttyFont != NULL) { - return FNT_GetTextWidth(ttyFont, text.c_str()); - } - - return text.length() * 12; + return pntr_measure_text(font, text.c_str()); } void Font::print(const std::string& text, int x, int y, int r, int g, int b, int a) { - SDL_Surface* screen = ChaiLove::getInstance()->screen; - - // Attempt to render the TTF Font. - if (ttfFont != NULL) { - SDL_Color color = {(Uint8)r, (Uint8)g, (Uint8)b}; - SDL_Surface* surface = TTF_RenderText_Blended(ttfFont, text.c_str(), color); - if (!surface) { - const char* errorChar = TTF_GetError(); - std::string errString(""); - if (errorChar != NULL) { - errString = errorChar; - } - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] Font::print - %s" << errString << std::endl; - return; - } - - SDL_Rect* dstrect = new SDL_Rect(); - dstrect->x = x; - dstrect->y = y; - SDL_BlitSurface(surface, NULL, screen, dstrect); - - // TODO(RobLoach): Allow re-use of text renderings. - SDL_FreeSurface(surface); + pntr_image* screen = ChaiLove::getInstance()->screen; + + if (font == NULL || screen == NULL) { return; } - // Use TTY to print the bitmap font? - if (ttyFont != NULL) { - FNT_Print(ttyFont, screen, x, y, FNT_ALIGN_LEFT, text.c_str()); + pntr_color color = pntr_new_color((unsigned char)r, (unsigned char)g, (unsigned char)b, (unsigned char)a); + pntr_draw_text(screen, font, text.c_str(), x, y, color); +} + +void Font::print(const std::string& text, int x, int y, pntr_color color) { + pntr_image* screen = ChaiLove::getInstance()->screen; + + if (font == NULL || screen == NULL) { return; } - // Fall back to SDL_gfx primitives. - stringRGBA(screen, x, y, text.c_str(), r, g, b, a); + pntr_draw_text(screen, font, text.c_str(), x, y, color); } } // namespace Graphics diff --git a/src/love/Types/Graphics/Font.h b/src/love/Types/Graphics/Font.h index fbda109cb..dd402f36b 100644 --- a/src/love/Types/Graphics/Font.h +++ b/src/love/Types/Graphics/Font.h @@ -1,10 +1,9 @@ #ifndef SRC_LOVE_TYPES_GRAPHICS_FONT_H_ #define SRC_LOVE_TYPES_GRAPHICS_FONT_H_ -#include "SDL.h" -#include "SDL_ttf.h" +#include "pntr_app.h" +#include "pntr.h" #include -#include #include "Image.h" namespace love { @@ -27,9 +26,8 @@ class Font { bool loaded(); bool destroy(); void print(const std::string& text, int x, int y, int r, int g, int b, int a); - TTF_Font* ttfFont = NULL; - TTY_Font* ttyFont = NULL; - int ttyFontWidth, ttyFontHeight; + void print(const std::string& text, int x, int y, pntr_color color); + pntr_font* font = NULL; /** * Determines the vertical size the given text needs. @@ -45,8 +43,6 @@ class Font { * Determines the horizontal size a line of text needs. */ int getWidth(const std::string& text); - - Image* m_image = NULL; }; } // namespace Graphics diff --git a/src/love/Types/Graphics/Image.cpp b/src/love/Types/Graphics/Image.cpp index 7a9566599..db045bfcf 100644 --- a/src/love/Types/Graphics/Image.cpp +++ b/src/love/Types/Graphics/Image.cpp @@ -1,61 +1,41 @@ #include "Image.h" -#include "SDL.h" -#define SDL_STBIMAGE_IMPLEMENTATION -#include +#include "pntr.h" #include #include "../../../ChaiLove.h" #include "../../../LibretroLog.h" - namespace love { namespace Types { namespace Graphics { -Image::Image(SDL_RWops* rw) { - loadFromRW(rw); +Image::Image(const unsigned char* data, unsigned int size) { + loadFromRW(data, size); } bool Image::loaded() { return surface != NULL; } -bool Image::loadFromRW(SDL_RWops* rw) { - surface = STBIMG_Load_RW(rw, 1); +bool Image::loadFromRW(const unsigned char* data, unsigned int size) { + surface = pntr_load_image_from_memory(PNTR_IMAGE_TYPE_PNG, data, size); if (!loaded()) { - const char* errorChar = SDL_GetError(); + const char* errorChar = pntr_get_error(); std::string errString(""); 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; } - // Optimize the image to the display format. - ChaiLove* game = ChaiLove::getInstance(); - SDL_Surface* optimizedImage = NULL; - if (game->config.options["alphablending"]) { - optimizedImage = SDL_DisplayFormatAlpha(surface); - } else { - Uint32 colorkey = SDL_MapRGBA(surface->format, 0, 0, 0, 0xFF); - SDL_SetColorKey(surface, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey); - optimizedImage = SDL_DisplayFormat(surface); - } - - if (optimizedImage == NULL) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [graphics] Warning: SDL_DisplayFormat failed to optimize the image." << std::endl; - } else { - SDL_FreeSurface(surface); - surface = optimizedImage; - } return true; } bool Image::destroy() { if (loaded()) { - SDL_FreeSurface(surface); + pntr_unload_image(surface); surface = NULL; } return true; @@ -66,20 +46,19 @@ Image::~Image() { } Image::Image(const std::string& filename) { - SDL_RWops* image = ChaiLove::getInstance()->filesystem.openRW(filename); - loadFromRW(image); + surface = pntr_load_image(filename.c_str()); } int Image::getWidth() { if (loaded()) { - return surface->w; + return surface->width; } return 0; } int Image::getHeight() { if (loaded()) { - return surface->h; + return surface->height; } return 0; } diff --git a/src/love/Types/Graphics/Image.h b/src/love/Types/Graphics/Image.h index 0672bbb54..563661d7e 100644 --- a/src/love/Types/Graphics/Image.h +++ b/src/love/Types/Graphics/Image.h @@ -1,7 +1,7 @@ #ifndef SRC_LOVE_TYPES_GRAPHICS_IMAGE_H_ #define SRC_LOVE_TYPES_GRAPHICS_IMAGE_H_ -#include +#include "pntr.h" #include namespace love { @@ -15,12 +15,12 @@ namespace Graphics { */ class Image { public: - SDL_Surface* surface; - Image(SDL_RWops* rw); + pntr_image* surface; + Image(const unsigned char* data, unsigned int size); Image(const std::string& filename); ~Image(); bool loaded(); - bool loadFromRW(SDL_RWops* rw); + bool loadFromRW(const unsigned char* data, unsigned int size); bool destroy(); /** diff --git a/src/love/Types/Graphics/Quad.cpp b/src/love/Types/Graphics/Quad.cpp index 4de88624a..29fd036a5 100644 --- a/src/love/Types/Graphics/Quad.cpp +++ b/src/love/Types/Graphics/Quad.cpp @@ -1,5 +1,5 @@ #include "Quad.h" -#include "SDL.h" +#include "pntr_app.h" namespace love { namespace Types { @@ -18,12 +18,12 @@ Quad::Quad() { // Nothing. } -SDL_Rect Quad::toRect() { - SDL_Rect rect; +pntr_rectangle Quad::toRect() { + pntr_rectangle rect; rect.x = x; rect.y = y; - rect.w = width; - rect.h = height; + rect.width = width; + rect.height = height; return rect; } diff --git a/src/love/Types/Graphics/Quad.h b/src/love/Types/Graphics/Quad.h index 8e107039f..6b4815232 100644 --- a/src/love/Types/Graphics/Quad.h +++ b/src/love/Types/Graphics/Quad.h @@ -1,7 +1,7 @@ #ifndef SRC_LOVE_TYPES_GRAPHICS_QUAD_H_ #define SRC_LOVE_TYPES_GRAPHICS_QUAD_H_ -#include "SDL.h" +#include "pntr_app.h" namespace love { namespace Types { @@ -37,7 +37,7 @@ class Quad { Quad(); Quad(int x, int y, int width, int height, int sw, int sh); Quad(int x, int y, int width, int height); - SDL_Rect toRect(); + pntr_rectangle toRect(); }; } // namespace Graphics diff --git a/src/love/Types/Input/Joystick.cpp b/src/love/Types/Input/Joystick.cpp index 829187610..0a8608db0 100644 --- a/src/love/Types/Input/Joystick.cpp +++ b/src/love/Types/Input/Joystick.cpp @@ -1,5 +1,5 @@ #include "Joystick.h" -#include "SDL.h" +#include "pntr_app.h" #include "../../../ChaiLove.h" #include diff --git a/src/love/audio.cpp b/src/love/audio.cpp index 81077d967..5cbfd817c 100644 --- a/src/love/audio.cpp +++ b/src/love/audio.cpp @@ -3,7 +3,7 @@ #include "Types/Audio/SoundData.h" #include "../ChaiLove.h" #include "sound.h" -//#include "audio/conversion/float_to_s16.h" +#include "audio/conversion/float_to_s16.h" using love::Types::Audio::SoundData; diff --git a/src/love/config.cpp b/src/love/config.cpp index 746c7d253..abfeb3d3a 100644 --- a/src/love/config.cpp +++ b/src/love/config.cpp @@ -7,7 +7,6 @@ config::config() { options["alphablending"] = true; options["highquality"] = true; version = CHAILOVE_VERSION_STRING; - console = false; } } // namespace love diff --git a/src/love/config.h b/src/love/config.h index 2abe7fcf7..f5479fc20 100644 --- a/src/love/config.h +++ b/src/love/config.h @@ -24,7 +24,6 @@ namespace love { * t.window.title = "My Game" // Human-readable name * t.window.width = 1024 // Game width * t.window.height = 768 // Game height - * t.console = false // Developer console, toggle with tilde * } * @endcode */ @@ -86,21 +85,6 @@ class config { * @endcode */ std::map options; - - /** - * Attach the in-game console. - * - * When `t.console = true`, will allow use of the in-game console. Use the tilde key to display. - * - * ## Example - * - * @code - * t.console = true - * @endcode - * - * @see love.console - */ - bool console = false; }; } // namespace love diff --git a/src/love/console.cpp b/src/love/console.cpp deleted file mode 100644 index bd0525801..000000000 --- a/src/love/console.cpp +++ /dev/null @@ -1,214 +0,0 @@ -#include "console.h" -#include "../ChaiLove.h" -#include "Types/Graphics/Font.h" - -#include -#include - -using love::Types::Graphics::Font; - -namespace love { - -bool console::load(const config& conf) { - // Use ` for the toggling key. - m_togglescancode = 96; - m_enabled = conf.console; - m_shown = false; - return true; -} - -bool console::isShown() { - return m_shown; -} - -void console::keypressed(std::string key, int scancode) { - // Test scancode and key input. - // ChaiLove::log(RETRO_LOG_DEBUG) << "Key: " << key << std::endl << "Cod: " << scancode << std::endl << m_togglescancode; - - // Only use the console if it is available. - if (!isEnabled()) { - return; - } - - // Toggle the console. - if (scancode == m_togglescancode) { - m_shown = !m_shown; - return; - } - - // Don't act on key presses if the console is not shown. - if (!isShown()) { - return; - } - - // Interpret a key press as ascii character entry. - ChaiLove* app = ChaiLove::getInstance(); - bool shiftDown = app->keyboard.isDown("shift") || app->keyboard.isDown("lshift") || app->keyboard.isDown("rshift"); - if (key.size() == 1) { - if (scancode >= 97 && scancode <= 122) { - if (shiftDown) { - m_input += (char)(scancode - 32); - } else { - m_input += key; - } - } else if (scancode == 43) { - // Nothing. - } else if (scancode == 61) { - if (!shiftDown) { - m_input += "="; - } else { - m_input += "+"; - } - } else if (scancode == 45) { - // Nothing. - } else if (scancode == 95) { - if (!shiftDown) { - m_input += "-"; - } else { - m_input += "_"; - } - } else if (scancode == 33 || scancode == 64 || scancode == 35 || scancode == 36 || scancode == 38 || scancode == 42) { - // Nothing. - } else if (scancode >= 48 && scancode <= 57) { - if (!shiftDown) { - m_input += key; - } else { - switch (scancode) { - case 48: - m_input += ")"; - break; - case 49: - m_input += "!"; - break; - case 50: - m_input += "@"; - break; - case 51: - m_input += "#"; - break; - case 52: - m_input += "$"; - break; - case 53: - m_input += "%"; - break; - case 54: - m_input += "^"; - break; - case 55: - m_input += "&"; - break; - case 56: - m_input += "*"; - break; - case 57: - m_input += "("; - break; - } - } - } else if (scancode == 39) { - // Nothing - } else if (scancode == 34) { - if (shiftDown) { - m_input += '"'; - } else { - m_input += '\''; - } - } else if (scancode == 47) { - // Nothing. - } else if (scancode == 63) { - if (shiftDown) { - m_input += '?'; - } else { - m_input += '/'; - } - } else if (scancode == 46) { - // Nothing. - } else if (scancode == 62) { - if (shiftDown) { - m_input += '>'; - } else { - m_input += '.'; - } - } else if (scancode == 58) { - // Nothing. - } else if (scancode == 59) { - if (shiftDown) { - m_input += ':'; - } else { - m_input += ';'; - } - } else if (scancode == 91) { - if (shiftDown) { - m_input += "{"; - } else { - m_input += "["; - } - } else if (scancode == 93) { - if (shiftDown) { - m_input += "}"; - } else { - m_input += "]"; - } - } else { - m_input += key; - } - } else if (key == "space") { - m_input += " "; - } else if (key == "backspace") { - if (m_input.size() > 0) { - m_input.pop_back(); - } - } else if (key == "return") { - execute(m_input); - m_input = ""; - } -} - -void console::draw() { - if (!isShown()) { - return; - } - - ChaiLove* app = ChaiLove::getInstance(); - int bottom = app->graphics.getHeight() - app->graphics.getHeight() / 3; - - // Retrieve the detault font. - Font* font = app->graphics.setFont().getFont(); - app->graphics.setColor(0, 0, 0, 200); - app->graphics.rectangle("fill", 0, 0, app->graphics.getWidth(), bottom); - app->graphics.setColor(255, 255, 255); - app->graphics.print("> " + m_input, 0, bottom - font->getHeight()); - - // Display the log, starting 2 lines up from the bottom. - int numEntry = 2; - for (std::vector::reverse_iterator i = m_log.rbegin(); i != m_log.rend(); ++i) { - app->graphics.print(*i, 0, bottom - font->getHeight() * numEntry++); - } -} - -void console::execute(const std::string& entry) { - m_log.push_back(entry); - ChaiLove* app = ChaiLove::getInstance(); - try { - std::string out = app->script->evalString(entry, "__EVAL__"); - if (!out.empty()) { - m_log.push_back(out); - } - } - catch (const chaiscript::exception::eval_error &e) { - m_log.push_back(e.what()); - } catch (const std::exception &e) { - m_log.push_back(e.what()); - } -} - -bool console::isEnabled() { - return m_enabled; -} - -bool console::setEnabled(bool enabled) { - return m_enabled = enabled; -} - -} // namespace love diff --git a/src/love/console.h b/src/love/console.h deleted file mode 100644 index 034e87f59..000000000 --- a/src/love/console.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef SRC_LOVE_CONSOLE_H_ -#define SRC_LOVE_CONSOLE_H_ - -#include -#include -#include "config.h" - -namespace love { - -/** - * In-game console for ChaiLove. - * - * To enable the console, you must trigger: `love.console.setEnabled(true)` or toggle the console in `love.conf`. - * - * Once enabled, display the console by pressing the tilde key on your keyboard. Running commands will execute ChaiScript. For example, try running `love.system.getOS()`. - * - * @see love.config - */ -class console { - public: - std::vector m_log; - std::string m_input = std::string(""); - bool m_enabled = false; - bool m_shown = false; - int m_togglescancode; - bool load(const config& conf); - - void keypressed(std::string key, int scancode); - void draw(); - - /** - * Checks to see if the console is enabled. - * - * @see setEnabled - */ - bool isEnabled(); - - /** - * Enable or disable the console. - * - * @see isEnabled - */ - bool setEnabled(bool enabled); - - /** - * Checks whether or not the console is being displayed. - */ - bool isShown(); - - void execute(const std::string& entry); -}; - -} // namespace love - -#endif // SRC_LOVE_CONSOLE_H_ diff --git a/src/love/data.cpp b/src/love/data.cpp index b4f165f0e..0dbd1e68e 100644 --- a/src/love/data.cpp +++ b/src/love/data.cpp @@ -27,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; } @@ -53,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; } @@ -108,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; } @@ -125,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; } @@ -138,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 ""; } diff --git a/src/love/event.cpp b/src/love/event.cpp index 1b527221b..1b494a127 100644 --- a/src/love/event.cpp +++ b/src/love/event.cpp @@ -1,7 +1,6 @@ #include "event.h" #include "../ChaiLove.h" -#include namespace love { diff --git a/src/love/event.h b/src/love/event.h index b3f427135..82035a4e9 100644 --- a/src/love/event.h +++ b/src/love/event.h @@ -1,8 +1,6 @@ #ifndef SRC_LOVE_EVENT_H_ #define SRC_LOVE_EVENT_H_ -#include - namespace love { /** * Manages events, like keypresses. diff --git a/src/love/filesystem.cpp b/src/love/filesystem.cpp index ed2f2cc49..18cd97034 100644 --- a/src/love/filesystem.cpp +++ b/src/love/filesystem.cpp @@ -3,7 +3,6 @@ #include "libretro.h" #include "physfs.h" #include "filesystem.h" -#include "physfsrwops.h" #include "../ChaiLove.h" #include "../LibretroLog.h" #include "Types/FileSystem/FileInfo.h" @@ -20,7 +19,7 @@ bool filesystem::init(const std::string& file, const void* data) { // Initialize PhysFS if (PHYSFS_isInit() == 0) { if (PHYSFS_init((const char*)ChaiLove::getInstance()->environ_cb) == 0) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error loading PhysFS - " << getLastError() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error loading PhysFS - " << getLastError() << std::endl; return false; } } @@ -134,11 +133,11 @@ PHYSFS_sint64 filesystem::getSize(PHYSFS_File* file) { if (file) { size = PHYSFS_fileLength(file); if (size < 0) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Could not get size of file " << getLastError() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Could not get size of file " << getLastError() << std::endl; return -1; } } else { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] The file is not currently open." << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] The file is not currently open." << std::endl; } return size; } @@ -150,24 +149,19 @@ bool filesystem::unload() { return true; } -SDL_RWops* filesystem::openRW(const std::string& filename) { - SDL_RWops* rw = PHYSFSRWOPS_openRead(filename.c_str()); - if (rw == NULL) { - const char* errorChar = SDL_GetError(); - std::string sdlErr(""); - if (errorChar != NULL) { - sdlErr = errorChar; - } - - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error loading file " << filename << getLastError() << sdlErr << std::endl; +void* filesystem::openRW(const std::string& filename) { + unsigned int size; + void* data = pntr_load_file(filename.c_str(), &size); + if (data == NULL) { + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error loading file " << filename << getLastError() << std::endl; } - return rw; + return data; } PHYSFS_file* filesystem::openFile(const std::string& filename) { PHYSFS_file* myfile = PHYSFS_openRead(filename.c_str()); if (myfile == NULL) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error opening file " << filename << getLastError() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error opening file " << filename << getLastError() << std::endl; return NULL; } return myfile; @@ -185,14 +179,14 @@ char* filesystem::readChar(const std::string& filename) { output = new char[file_size + 1]; int length_read = PHYSFS_readBytes(myfile, output, file_size); if (length_read != file_size) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] File System error while reading from file " << filename << getLastError() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] File System error while reading from file " << filename << getLastError() << std::endl; output = NULL; } else { // Make sure there is a null terminating character at the end of the string. output[file_size] = '\0'; } } else { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error getting filesize of " << filename << getLastError() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error getting filesize of " << filename << getLastError() << std::endl; } PHYSFS_close(myfile); @@ -225,7 +219,7 @@ void* filesystem::readBuffer(const std::string& filename, int& size) { // Create the buffer. void* buffer = (void*)malloc(size + 1); if (!buffer) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Failed to allocate buffer of size " << size + 1 << "." << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Failed to allocate buffer of size " << size + 1 << "." << std::endl; PHYSFS_close(file); return NULL; } @@ -233,7 +227,7 @@ void* filesystem::readBuffer(const std::string& filename, int& size) { // Read the file into the buffer. int result = PHYSFS_readBytes(file, buffer, size); if (result < 0) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Failed to load SoundData " << filename << getLastError() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Failed to load SoundData " << filename << getLastError() << std::endl; free(buffer); PHYSFS_close(file); return NULL; @@ -244,10 +238,10 @@ void* filesystem::readBuffer(const std::string& filename, int& size) { } bool filesystem::unmount(const std::string& archive) { - LibretroLog::log(RETRO_LOG_INFO) << "[filesystem] Unmounting " << archive << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[filesystem] Unmounting " << archive << std::endl; int returnValue = PHYSFS_unmount(archive.c_str()); if (returnValue == 0) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error unmounting: " << getLastError() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error unmounting: " << getLastError() << std::endl; return false; } return true; @@ -272,18 +266,18 @@ bool filesystem::mount(const std::string& archive, const std::string& mountpoint // Protect against empty archive/mount points. int append = appendToPath ? 1 : 0; if (archive.length() <= 0) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [filesystem] Mounting failed because archive was empty." << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [filesystem] Mounting failed because archive was empty." << std::endl; return false; } // Display a message. - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [filesystem] Mounting " << archive << " as " << mountpoint << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [filesystem] Mounting " << archive << " as " << mountpoint << std::endl; // Use the simple mount method if we're mounting the root directory. if (mountpoint == "/") { int returnValue = PHYSFS_mount(archive.c_str(), mountpoint.c_str(), append); if (returnValue == 0) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error mounting /: " << getLastError() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error mounting /: " << getLastError() << std::endl; return false; } return true; @@ -295,7 +289,7 @@ bool filesystem::mount(const std::string& archive, const std::string& mountpoint PHYSFS_File* file = openFile(archive); if (file != NULL) { if (PHYSFS_mountHandle(file, archive.c_str(), mountpoint.c_str(), append) == 0) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error mounting file: " << getLastError() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error mounting file: " << getLastError() << std::endl; return false; } return true; @@ -306,7 +300,7 @@ bool filesystem::mount(const std::string& archive, const std::string& mountpoint // Check if we're mounting a directory. int returnVal = PHYSFS_mount(archive.c_str(), mountpoint.c_str(), append); if (returnVal == 0) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error mounting directory: " << getLastError() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error mounting directory: " << getLastError() << std::endl; return false; } return true; @@ -330,7 +324,7 @@ std::vector filesystem::getDirectoryItems(const std::string& dir) { } PHYSFS_freeList(rc); } else { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error enumerating files from " << dir << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error enumerating files from " << dir << std::endl; } return result; @@ -426,7 +420,7 @@ std::string filesystem::getSaveDirectory() { bool filesystem::createDirectory(const std::string& name) { int ret = PHYSFS_mkdir(name.c_str()); if (ret == 0) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Failed to create directory: " << getLastError() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Failed to create directory: " << getLastError() << std::endl; return false; } return true; @@ -435,7 +429,7 @@ bool filesystem::createDirectory(const std::string& name) { bool filesystem::write(const std::string& name, const std::string& data) { PHYSFS_File* file = PHYSFS_openWrite(name.c_str()); if (file == NULL) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error opening file for writing: " << getLastError() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error opening file for writing: " << getLastError() << std::endl; return false; } const char* buffer = data.c_str(); diff --git a/src/love/filesystem.h b/src/love/filesystem.h index bd6e4fad6..352fa73e1 100644 --- a/src/love/filesystem.h +++ b/src/love/filesystem.h @@ -4,7 +4,7 @@ #include #include -#include "SDL.h" +#include "pntr_app.h" #include "physfs.h" #include "Types/FileSystem/FileInfo.h" #include "Types/FileSystem/FileData.h" @@ -37,7 +37,7 @@ class filesystem { bool init(const std::string& file, const void* data); bool unload(); - SDL_RWops* openRW(const std::string& filename); + void* openRW(const std::string& filename); char* readChar(const std::string& filename); /** diff --git a/src/love/font.cpp b/src/love/font.cpp index cf341b51a..e079ad8e8 100644 --- a/src/love/font.cpp +++ b/src/love/font.cpp @@ -1,6 +1,5 @@ #include -#include "SDL.h" -#include "SDL_ttf.h" +#include "pntr_app.h" #include "font.h" #include "Types/Graphics/Font.h" #include "../LibretroLog.h" @@ -12,28 +11,15 @@ font::~font() { } bool font::load() { - int result = TTF_Init(); - if(result == -1) { - const char* errorChar = TTF_GetError(); - std::string errString(""); - if (errorChar != NULL) { - errString = errorChar; - } - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] TTF_Init failed to initialize font system: {}" << errString << std::endl; - return false; - } return true; } bool font::unload() { - if (isOpen()) { - TTF_Quit(); - } return true; } bool font::isOpen() { - return TTF_WasInit(); + return true; } } // namespace love diff --git a/src/love/graphics.cpp b/src/love/graphics.cpp index be2c01053..60d413825 100644 --- a/src/love/graphics.cpp +++ b/src/love/graphics.cpp @@ -1,9 +1,5 @@ #include "graphics.h" -#include -#include -#include -#include #include "../ChaiLove.h" #include "../LibretroLog.h" #include "Types/Graphics/Image.h" @@ -22,7 +18,7 @@ graphics::graphics() { setFont(); } -SDL_Surface* graphics::getScreen() { +pntr_image* graphics::getScreen() { if (ChaiLove::hasInstance()) { return ChaiLove::getInstance()->screen; } @@ -31,11 +27,11 @@ SDL_Surface* graphics::getScreen() { bool graphics::load() { // Enable alpha blending. - if (ChaiLove::getInstance()->config.options["alphablending"]) { - if (SDL_SetAlpha(getScreen(), SDL_SRCALPHA, 0) == -1) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] Enabling alpha blending failed" << std::endl; - } - } + // if (ChaiLove::getInstance()->config.options["alphablending"]) { + // if (SDL_SetAlpha(getScreen(), SDL_SRCALPHA, 0) == -1) { + // //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] Enabling alpha blending failed" << std::endl; + // } + // } // Set the default font. graphics::setFont(); @@ -43,13 +39,12 @@ bool graphics::load() { } graphics& graphics::clear() { - return clear(backR, backG, backB, backA); + pntr_clear_background(getScreen(), color_back); + return *this; } graphics& graphics::clear(int r, int g, int b, int a) { - SDL_Surface* screen = getScreen(); - Uint32 color = SDL_MapRGBA(screen->format, r, g, b, a); - SDL_FillRect(screen, NULL, color); + pntr_clear_background(getScreen(), pntr_new_color(r, g, b, a)); return *this; } @@ -58,7 +53,7 @@ graphics& graphics::clear(int r, int g, int b) { } graphics& graphics::point(int x, int y) { - pixelRGBA(getScreen(), x, y, r, g, b, a); + pntr_draw_point(getScreen(), x, y, color_front); return *this; } @@ -83,16 +78,16 @@ void graphics::points(std::vector points) { graphics& graphics::rectangle(const std::string& drawmode, int x, int y, int width, int height) { if (drawmode == "line") { - rectangleRGBA(getScreen(), x, y, x + width, y + height, r, g, b, a); + pntr_draw_rectangle(getScreen(), x, y, width, height, color_front); } else { - boxRGBA(getScreen(), x, y, x + width, y + height, r, g, b, a); + pntr_draw_rectangle_fill(getScreen(), x, y, width, height, color_front); } return *this; } graphics& graphics::line(int x1, int y1, int x2, int y2) { - lineRGBA(getScreen(), x1, y1, x2, y2, r, g, b, a); + pntr_draw_line(getScreen(), x1, y1, x2, y2, color_front); return *this; } @@ -102,10 +97,7 @@ graphics& graphics::draw(Image* image) { graphics& graphics::draw(Image* image, int x, int y) { if (image && image->loaded()) { - SDL_Rect dstrect; - dstrect.x = x; - dstrect.y = y; - SDL_BlitSurface(image->surface, NULL, getScreen(), &dstrect); + pntr_draw_image(getScreen(), image->surface, x, y); } return *this; @@ -117,13 +109,12 @@ graphics& graphics::draw(Image* image, Quad quad) { graphics& graphics::draw(Image* image, Quad quad, int x, int y) { if (image && image->loaded()) { - SDL_Rect dest; - dest.x = x; - dest.y = y; - dest.w = x + quad.width; - dest.h = y + quad.height; - SDL_Rect src = quad.toRect(); - SDL_BlitSurface(image->surface, &src, getScreen(), &dest); + pntr_rectangle srcRect; + srcRect.x = quad.x; + srcRect.y = quad.x; + srcRect.width = quad.sw; + srcRect.height = quad.sh; + pntr_draw_image_rec(getScreen(), image->surface, quad.toRect(), x, y); } return *this; @@ -131,18 +122,20 @@ graphics& graphics::draw(Image* image, Quad quad, int x, int y) { graphics& graphics::draw(Image* image, int x, int y, float r, float sx, float sy, float ox, float oy) { if (image && image->loaded()) { - ChaiLove* app = ChaiLove::getInstance(); - float angle = app->math.degrees(r); - SDL_Surface* tempSurface = rotozoomSurfaceXY(image->surface, angle, sx, sy, m_smooth); - if (tempSurface) { - float aspectX = ox / image->getWidth(); - float aspectY = oy / image->getHeight(); - SDL_Rect dstrect; - dstrect.x = x - aspectX * tempSurface->w; - dstrect.y = y - aspectY * tempSurface->h; - SDL_BlitSurface(tempSurface, NULL, getScreen(), &dstrect); - SDL_FreeSurface(tempSurface); - } + // TODO: Implement rotozoomSurfaceXY + + // ChaiLove* app = ChaiLove::getInstance(); + // float angle = app->math.degrees(r); + // SDL_Surface* tempSurface = rotozoomSurfaceXY(image->surface, angle, sx, sy, m_smooth); + // if (tempSurface) { + // float aspectX = ox / image->getWidth(); + // float aspectY = oy / image->getHeight(); + // SDL_Rect dstrect; + // dstrect.x = x - aspectX * tempSurface->w; + // dstrect.y = y - aspectY * tempSurface->h; + // SDL_BlitSurface(tempSurface, NULL, getScreen(), &dstrect); + // SDL_FreeSurface(tempSurface); + // } } return *this; @@ -177,20 +170,17 @@ Quad graphics::newQuad(int x, int y, int width, int height, int sw, int sh) { } graphics& graphics::print(const std::string& text) { - activeFont->print(text, 0, 0, r, g, b, a); + activeFont->print(text, 0, 0, color_front); return *this; } graphics& graphics::print(const std::string& text, int x, int y) { - activeFont->print(text, x, y, r, g, b, a); + activeFont->print(text, x, y, color_front); return *this; } graphics& graphics::setColor(int red, int green, int blue, int alpha) { - r = red; - g = green; - b = blue; - a = alpha; + color_front = pntr_new_color(red, green, blue, alpha); return *this; } @@ -199,26 +189,17 @@ graphics& graphics::setColor(int red, int green, int blue) { } Color graphics::getColor() { - return Color(r, g, b, a); + return color_front; } Color graphics::getBackgroundColor() { - Color c; - c.r = backR; - c.g = backG; - c.b = backB; - c.a = backA; - return c; + return color_back; } graphics& graphics::setBackgroundColor(int red, int green, int blue) { return setBackgroundColor(red, green, blue, 255); } graphics& graphics::setBackgroundColor(int red, int green, int blue, int alpha) { - backR = red; - backG = green; - backB = blue; - backA = alpha; - + color_back = pntr_new_color(red, green, blue, alpha); return *this; } @@ -227,9 +208,9 @@ graphics& graphics::setBackgroundColor(int red, int green, int blue, int alpha) */ graphics& graphics::setDefaultFilter(const std::string& filter) { if (filter == "linear") { - m_smooth = 1; + m_smooth = PNTR_FILTER_BILINEAR; } else if (filter == "nearest") { - m_smooth = 0; + m_smooth = PNTR_FILTER_NEARESTNEIGHBOR; } return *this; @@ -240,9 +221,9 @@ graphics& graphics::setDefaultFilter(const std::string& filter) { */ std::string graphics::getDefaultFilter() { switch (m_smooth) { - case 0: + case PNTR_FILTER_NEARESTNEIGHBOR: return "nearest"; - case 1: + case PNTR_FILTER_BILINEAR: return "linear"; } @@ -251,10 +232,10 @@ std::string graphics::getDefaultFilter() { int graphics::getWidth() { - return getScreen()->w; + return getScreen()->width; } int graphics::getHeight() { - return getScreen()->h; + return getScreen()->height; } Point graphics::getDimensions() { @@ -263,9 +244,9 @@ Point graphics::getDimensions() { graphics& graphics::circle(const std::string& drawmode, int x, int y, int radius) { if (drawmode == "line") { - circleRGBA(getScreen(), x, y, radius, r, g, b, a); + pntr_draw_circle(getScreen(), x, y, radius, color_front); } else { - filledCircleRGBA(getScreen(), x, y, radius, r, g, b, a); + pntr_draw_circle_fill(getScreen(), x, y, radius, color_front); } return *this; @@ -273,9 +254,9 @@ graphics& graphics::circle(const std::string& drawmode, int x, int y, int radius graphics& graphics::arc(const std::string& drawmode, int x, int y, int radius, int angle1, int angle2) { if (drawmode == "line") { - arcRGBA(getScreen(), x, y, radius, angle1, angle2, r, g, b, a); + pntr_draw_arc(getScreen(), x, y, radius, angle1, angle2, radius * 2, color_front); } else { - filledPieRGBA(getScreen(), x, y, radius, angle1, angle2, r, g, b, a); + pntr_draw_arc_fill(getScreen(), x, y, radius, angle1, angle2, radius * 2, color_front); } return *this; @@ -283,9 +264,9 @@ graphics& graphics::arc(const std::string& drawmode, int x, int y, int radius, i graphics& graphics::ellipse(const std::string& drawmode, int x, int y, int radiusx, int radiusy) { if (drawmode == "line") { - ellipseRGBA(getScreen(), x, y, radiusx, radiusy, r, g, b, a); + pntr_draw_ellipse(getScreen(), x, y, radiusx, radiusy, color_front); } else { - filledEllipseRGBA(getScreen(), x, y, radiusx, radiusy, r, g, b, a); + pntr_draw_ellipse_fill(getScreen(), x, y, radiusx, radiusy, color_front); } return *this; @@ -299,12 +280,12 @@ Font* graphics::newFont(const std::string& filename, int size) { return new Font(filename, size); } -Font* graphics::newFont() { - return new Font(); +Font* graphics::newFont(const std::string& filename) { + return new Font(filename, 12); } -Font* graphics::newFont(const std::string& filename) { - return newFont(filename, 12); +Font* graphics::newFont() { + return new Font(); } graphics& graphics::setFont(Font* font) { diff --git a/src/love/graphics.h b/src/love/graphics.h index e5d45a205..ce789af61 100644 --- a/src/love/graphics.h +++ b/src/love/graphics.h @@ -3,8 +3,7 @@ #include -#include "SDL.h" -#include "SDL_gfxPrimitives.h" +#include "pntr_app.h" #include "Types/Graphics/Image.h" #include "Types/Graphics/Quad.h" #include "Types/Graphics/Font.h" @@ -301,9 +300,10 @@ class graphics { */ graphics& arc(const std::string& drawmode, int x, int y, int radius, int angle1, int angle2); - Uint8 r = 255, g = 255, b = 255, a = 255; - Uint8 backR = 0, backG = 0, backB = 0, backA = 255; - SDL_Surface* getScreen(); + pntr_color color_front; + pntr_color color_back; + + pntr_image* getScreen(); Font* activeFont = NULL; Font defaultFont; diff --git a/src/love/joystick.cpp b/src/love/joystick.cpp index 8213f2487..1e77152e2 100644 --- a/src/love/joystick.cpp +++ b/src/love/joystick.cpp @@ -1,5 +1,5 @@ #include "joystick.h" -#include "SDL.h" +#include "pntr_app.h" #include #include #include @@ -49,11 +49,6 @@ bool joystick::isDown(int joystick, const std::string& button) { } void joystick::update() { - // Ignore Joypad input when the console is shown. - if (ChaiLove::getInstance()->console.isShown()) { - return; - } - for (std::vector::iterator it = m_joysticks.begin(); it != m_joysticks.end(); ++it) { (*it)->update(); } diff --git a/src/love/joystick.h b/src/love/joystick.h index 6339e2bf7..efaa5c484 100644 --- a/src/love/joystick.h +++ b/src/love/joystick.h @@ -5,7 +5,7 @@ #include #include "Types/Input/Joystick.h" -#include "SDL.h" +#include "pntr_app.h" using love::Types::Input::Joystick; diff --git a/src/love/keyboard.cpp b/src/love/keyboard.cpp index 2ea791428..bbb1e16b6 100644 --- a/src/love/keyboard.cpp +++ b/src/love/keyboard.cpp @@ -215,22 +215,13 @@ bool keyboard::update() { void keyboard::eventKeyPressed(int scancode) { std::string key = getKeyFromScancode(scancode); ChaiLove* app = ChaiLove::getInstance(); - - // Trigger the keypress in the in-game console and the game. - app->console.keypressed(key, scancode); - if (!app->console.isShown()) { - app->script->keypressed(key, scancode); - } + app->script->keypressed(key, scancode); } void keyboard::eventKeyReleased(int scancode) { std::string key = getKeyFromScancode(scancode); ChaiLove* app = ChaiLove::getInstance(); - - // Only trigger the event in the game if the console is not being used. - if (!app->console.isShown()) { - app->script->keyreleased(key, scancode); - } + app->script->keyreleased(key, scancode); } } // namespace love diff --git a/src/love/math.cpp b/src/love/math.cpp index 6a46da791..d7a51c0d1 100644 --- a/src/love/math.cpp +++ b/src/love/math.cpp @@ -1,11 +1,9 @@ #include "math.h" -#include "effolkronium/random.hpp" - -using Random = effolkronium::random_static; namespace love { -bool math::load() { +bool math::load(pntr_app* application) { + app = application; return true; } @@ -18,7 +16,7 @@ float math::random(float max) { } float math::random(float min, float max) { - return Random::get(min, max); + return pntr_app_random_float(app, min, max); } int math::random(int max) { @@ -26,14 +24,11 @@ int math::random(int max) { } int math::random(int min, int max) { - return Random::get(min, max); -} -double math::random(double max) { - return random(0.0, max); + return pntr_app_random(app, min, max); } double math::random(double min, double max) { - return Random::get(min, max); + return (double)pntr_app_random_float(app, (float)min, (float)max); } math& math::setRandomSeed(int min, int max) { @@ -41,13 +36,12 @@ math& math::setRandomSeed(int min, int max) { } math& math::setRandomSeed(int seed) { - Random::seed(seed); - m_seed = seed; + pntr_app_random_set_seed(app, seed); return *this; } int math::getRandomSeed() { - return m_seed; + return (int)pntr_app_random_seed(app); } float math::rad(float degress) { diff --git a/src/love/math.h b/src/love/math.h index 7157b1d6c..2497a09be 100644 --- a/src/love/math.h +++ b/src/love/math.h @@ -2,6 +2,7 @@ #define SRC_LOVE_MATH_H_ #include +#include "pntr_app.h" namespace love { /** @@ -9,7 +10,7 @@ namespace love { */ class math { public: - bool load(); + bool load(pntr_app* app); /** * Get uniformly distributed pseudo-random number, between the given numbers. @@ -31,7 +32,6 @@ class math { int random(int min, int max); int random(int max); double random(double min, double max); - double random(double max); /** * Sets the random seed to a random seed between the given min and max values. @@ -93,6 +93,8 @@ class math { private: int m_seed = 0; + + pntr_app* app; }; } // namespace love diff --git a/src/love/script.cpp b/src/love/script.cpp index 4a343ce6d..4a73ea25b 100644 --- a/src/love/script.cpp +++ b/src/love/script.cpp @@ -14,7 +14,7 @@ using love::Types::Graphics::Point; using love::Types::Graphics::Image; using love::Types::Graphics::Font; using love::Types::Graphics::Point; -using love::Types::Graphics::Color; +//using love::Types::Graphics::Color; using love::Types::Input::Joystick; using love::Types::Config::WindowConfig; using love::Types::Config::ModuleConfig; @@ -51,14 +51,14 @@ bool script::loadModule(const std::string& moduleName) { // Ensure we're loading a valid module name. if (moduleName.empty()) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] loadModule was called with an empty moduleName." << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] loadModule was called with an empty moduleName." << std::endl; return false; } // Store a filename for the module. std::string filename = findModule(moduleName); if (filename.empty()) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] Module " << moduleName << " not found." << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] Module " << moduleName << " not found." << std::endl; return false; } @@ -67,7 +67,7 @@ bool script::loadModule(const std::string& moduleName) { // Make sure it was not empty. if (contents.empty()) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Module " << filename << " was loaded, but empty." << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Module " << filename << " was loaded, but empty." << std::endl; return false; } @@ -136,7 +136,6 @@ script::script(const std::string& file) { ChaiLove* app = ChaiLove::getInstance(); love["audio"] = var(std::ref(app->audio)); love["config"] = var(std::ref(app->config)); - love["console"] = var(std::ref(app->console)); love["data"] = var(std::ref(app->data)); love["event"] = var(std::ref(app->event)); love["filesystem"] = var(std::ref(app->filesystem)); @@ -191,14 +190,14 @@ script::script(const std::string& file) { chai.add(constructor(), "FileData"); // Color Object. - chai.add(user_type(), "Color"); - chai.add(fun(&Color::r), "r"); - chai.add(fun(&Color::g), "g"); - chai.add(fun(&Color::b), "b"); - chai.add(fun(&Color::a), "a"); - chai.add(constructor(), "Color"); - chai.add(constructor(), "Color"); - chai.add(constructor(), "Color"); + // chai.add(user_type(), "Color"); + // chai.add(fun(&Color::r), "r"); + // chai.add(fun(&Color::g), "g"); + // chai.add(fun(&Color::b), "b"); + // chai.add(fun(&Color::a), "a"); + // chai.add(constructor(), "Color"); + // chai.add(constructor(), "Color"); + // chai.add(constructor(), "Color"); // Image Object. chai.add(user_type(), "Image"); @@ -208,12 +207,12 @@ script::script(const std::string& file) { // SoundData Object. chai.add(user_type(), "SoundData"); chai.add(fun(&SoundData::isLooping), "isLooping"); - chai.add(fun(&SoundData::isPlaying), "isPlaying"); + //chai.add(fun(&SoundData::isPlaying), "isPlaying"); chai.add(fun(&SoundData::setLooping), "setLooping"); chai.add(fun(&SoundData::stop), "stop"); chai.add(fun(&SoundData::play), "play"); - chai.add(fun(&SoundData::setVolume), "setVolume"); - chai.add(fun(&SoundData::getVolume), "getVolume"); + //chai.add(fun(&SoundData::setVolume), "setVolume"); + //chai.add(fun(&SoundData::getVolume), "getVolume"); // Font. chai.add(user_type(), "Font"); @@ -239,12 +238,6 @@ script::script(const std::string& file) { chai.add(fun(&config::window), "window"); chai.add(fun(&config::modules), "modules"); chai.add(fun(&config::options), "options"); - chai.add(fun(&config::console), "console"); - - // Console - chai.add(fun(&console::isEnabled), "isEnabled"); - chai.add(fun(&console::setEnabled), "setEnabled"); - chai.add(fun(&console::isShown), "isShown"); // Joystick chai.add(user_type(), "Joystick"); @@ -434,119 +427,119 @@ script::script(const std::string& file) { chaiload = chai.eval >("load"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] load() " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] load() " << e.what() << std::endl; hasload = false; } try { chaireset = chai.eval >("reset"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] reset() " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] reset() " << e.what() << std::endl; hasreset = false; } try { chaiupdate = chai.eval >("update"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] update(delta) " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] update(delta) " << e.what() << std::endl; hasUpdate = false; } try { chaiconf = chai.eval >("conf"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] conf(t) " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] conf(t) " << e.what() << std::endl; hasconf = false; } try { chaidraw = chai.eval >("draw"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] draw() " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] draw() " << e.what() << std::endl; hasDraw = false; } try { chaijoystickpressed = chai.eval >("joystickpressed"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] joystickpressed() " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] joystickpressed() " << e.what() << std::endl; hasjoystickpressed = false; } try { chaijoystickreleased = chai.eval >("joystickreleased"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] joystickreleased() " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] joystickreleased() " << e.what() << std::endl; hasjoystickreleased = false; } try { chaimousepressed = chai.eval >("mousepressed"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] mousepressed() " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] mousepressed() " << e.what() << std::endl; hasmousepressed = false; } try { chaimousereleased = chai.eval >("mousereleased"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] mousereleased() " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] mousereleased() " << e.what() << std::endl; hasmousereleased = false; } try { chaimousemoved = chai.eval >("mousemoved"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] mousemoved() " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] mousemoved() " << e.what() << std::endl; hasmousemoved = false; } try { chaikeypressed = chai.eval >("keypressed"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] keypressed() " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] keypressed() " << e.what() << std::endl; haskeypressed = false; } try { chaikeyreleased = chai.eval >("keyreleased"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] keyreleased() " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] keyreleased() " << e.what() << std::endl; haskeyreleased = false; } try { chailoadstate = chai.eval >("loadstate"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] loadstate() " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] loadstate() " << e.what() << std::endl; hasloadstate = false; } try { chaisavestate = chai.eval >("savestate"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] savestate() " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] savestate() " << e.what() << std::endl; hassavestate = false; } try { chaicheatreset = chai.eval >("cheatreset"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] cheatreset() Warning: " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] cheatreset() Warning: " << e.what() << std::endl; hascheatreset = false; } try { chaicheatset = chai.eval >("cheatset"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] cheatset() Warning: " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] cheatset() Warning: " << e.what() << std::endl; hascheatset = false; } try { chaiexit = chai.eval >("exit"); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] exit() Warning: " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [script] exit() Warning: " << e.what() << std::endl; hasexit = false; } #endif @@ -559,7 +552,7 @@ void script::conf(config& t) { chaiconf(t); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to invoke conf(t): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to invoke conf(t): " << e.what() << std::endl; hasconf = false; } } @@ -573,7 +566,7 @@ void script::load() { chaiload(); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call load(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call load(): " << e.what() << std::endl; hasload = false; } } @@ -587,7 +580,7 @@ void script::reset() { chaireset(); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call reset(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call reset(): " << e.what() << std::endl; hasreset = false; } } @@ -602,7 +595,7 @@ void script::update(float delta) { } catch (const std::exception& e) { hasUpdate = false; - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call update(delta): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call update(delta): " << e.what() << std::endl; } } #endif @@ -615,7 +608,7 @@ void script::draw() { chaidraw(); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call draw(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call draw(): " << e.what() << std::endl; hasDraw = false; } } else { @@ -631,7 +624,7 @@ void script::joystickpressed(int joystick, const std::string& button) { chaijoystickpressed(joystick, button); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call joystickpressed(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call joystickpressed(): " << e.what() << std::endl; hasjoystickpressed = false; } } @@ -645,7 +638,7 @@ void script::joystickreleased(int joystick, const std::string& button) { chaijoystickreleased(joystick, button); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call joystickreleased(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call joystickreleased(): " << e.what() << std::endl; hasjoystickreleased = false; } } @@ -659,7 +652,7 @@ void script::mousepressed(int x, int y, const std::string& button) { chaimousepressed(x, y, button); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call mousepressed(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call mousepressed(): " << e.what() << std::endl; hasmousepressed = false; } } @@ -673,7 +666,7 @@ void script::mousereleased(int x, int y, const std::string& button) { chaimousereleased(x, y, button); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call mousereleased(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call mousereleased(): " << e.what() << std::endl; hasmousereleased = false; } } @@ -687,7 +680,7 @@ void script::mousemoved(int x, int y, int dx, int dy) { chaimousemoved(x, y, dx, dy); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call mousemoved(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call mousemoved(): " << e.what() << std::endl; hasmousemoved = false; } } @@ -701,7 +694,7 @@ void script::keypressed(const std::string& key, int scancode) { chaikeypressed(key, scancode); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call keypressed(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call keypressed(): " << e.what() << std::endl; haskeypressed = false; } } @@ -715,7 +708,7 @@ void script::keyreleased(const std::string& key, int scancode) { chaikeyreleased(key, scancode); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call keyreleased(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call keyreleased(): " << e.what() << std::endl; haskeyreleased = false; } } @@ -732,7 +725,7 @@ std::string script::savestate() { return chaisavestate(); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call savestate(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call savestate(): " << e.what() << std::endl; hassavestate = false; } } @@ -752,7 +745,7 @@ bool script::loadstate(const std::string& data) { return chailoadstate(data); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call loadstate(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call loadstate(): " << e.what() << std::endl; hasloadstate = false; } } @@ -769,7 +762,7 @@ void script::cheatreset() { chaicheatreset(); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call cheatreset(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call cheatreset(): " << e.what() << std::endl; hascheatreset = false; } } @@ -783,7 +776,7 @@ void script::cheatset(int index, bool enabled, const std::string& code) { chaicheatset(index, enabled, code); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call cheatset(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call cheatset(): " << e.what() << std::endl; hascheatset = false; } } @@ -797,7 +790,7 @@ void script::exit() { chaiexit(); } catch (const std::exception& e) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call exit(): " << e.what() << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [script] Failed to call exit(): " << e.what() << std::endl; hasexit = false; } } diff --git a/src/love/script.h b/src/love/script.h index 3ee3262c8..66e1e87c5 100644 --- a/src/love/script.h +++ b/src/love/script.h @@ -51,9 +51,6 @@ class script { * * @code * def conf(t) { - * // Attach a development console, toggle with `. - * t.console = false - * * // The ChaiLove version this game was made for. * t.version = "0.29.0" * diff --git a/src/love/sound.cpp b/src/love/sound.cpp index d262b7d1c..3df32c477 100644 --- a/src/love/sound.cpp +++ b/src/love/sound.cpp @@ -1,11 +1,11 @@ #include #include #include "sound.h" -#include "SDL.h" +#include "pntr_app.h" #include "../ChaiLove.h" #include "Types/Audio/SoundData.h" -#include "audio/audio_mixer.h" -#include "audio/conversion/float_to_s16.h" +//#include "audio/audio_mixer.h" +//#include "audio/conversion/float_to_s16.h" #include "libretro.h" using ::ChaiLove; @@ -13,8 +13,9 @@ using love::Types::Audio::SoundData; namespace love { -bool sound::load() { - audio_mixer_init(44100); +bool sound::load(pntr_app* application) { + //audio_mixer_init(44100); + app = application; m_loaded = true; return true; } @@ -36,8 +37,9 @@ void sound::unload() { sounds.clear(); // Close the audio mixer. - audio_mixer_done(); + //audio_mixer_done(); m_loaded = false; + app = NULL; } @@ -46,12 +48,12 @@ SoundData* sound::newSoundData(const std::string& 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); + // 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); } diff --git a/src/love/sound.h b/src/love/sound.h index 607e0d2bb..3e53bb534 100644 --- a/src/love/sound.h +++ b/src/love/sound.h @@ -12,7 +12,7 @@ namespace love { */ class sound { public: - bool load(); + bool load(pntr_app* application); bool isLoaded(); bool hasAudio(); void unload(); @@ -49,6 +49,8 @@ class sound { bool m_loaded = false; retro_audio_sample_t audio_cb = NULL; retro_audio_sample_batch_t audio_batch_cb = NULL; + + pntr_app* app = NULL; }; } // namespace love diff --git a/src/love/system.cpp b/src/love/system.cpp index cc49d2791..83c888dbe 100644 --- a/src/love/system.cpp +++ b/src/love/system.cpp @@ -107,26 +107,28 @@ std::string system::getUsername() { bool system::execute(const std::string& command) { #ifdef CHAILOVE_DISABLE_LOVE_SYSTEM_EXECUTE - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [system] love.system.execute() is disabled." << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [system] love.system.execute() is disabled." << std::endl; return false; #else - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [system] love.system.execute(\"" << command << "\")" << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [system] love.system.execute(\"" << command << "\")" << std::endl; int result = std::system(command.c_str()); if (result != 0) { - LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [system] Failed to execute " << command << std::endl; + //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [system] Failed to execute " << command << std::endl; return false; } - LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [system] Finished " << command << std::endl; + //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] [system] Finished " << command << std::endl; return true; #endif } std::string system::getClipboardText() { - return m_clipboardtext; + pntr_app* app = ChaiLove::getInstance()->app; + + return pntr_app_clipboard(app); } system& system::setClipboardText(const std::string& text) { - m_clipboardtext = text; + pntr_app_set_clipboard(ChaiLove::getInstance()->app, text.c_str(), text.length()); return *this; } diff --git a/src/love/system.h b/src/love/system.h index a35a18f6b..4d21956d1 100644 --- a/src/love/system.h +++ b/src/love/system.h @@ -127,7 +127,6 @@ class system { bool load(config& t); - std::string m_clipboardtext; std::string m_username; bool m_usernameInitialized = false; }; diff --git a/src/love/window.cpp b/src/love/window.cpp index 5202d76c7..e1a4b0f8a 100644 --- a/src/love/window.cpp +++ b/src/love/window.cpp @@ -3,7 +3,7 @@ #include "../ChaiLove.h" #include "../LibretroLog.h" -#include "SDL.h" +#include "pntr_app.h" #include "config.h" #include "libretro.h" #include "Types/Graphics/Point.h" @@ -16,72 +16,69 @@ namespace love { bool window::load(const config& conf) { ChaiLove* app = ChaiLove::getInstance(); - // Initialize SDL. - if (SDL_Init(SDL_INIT_VIDEO) == -1) { - const char* errorChar = SDL_GetError(); - std::string errString(""); - if (errorChar != NULL) { - errString = errorChar; - } - LibretroLog::log(RETRO_LOG_ERROR) << "[game] Unable to initialize SDL " << errString << std::endl; - return false; - } + // // Initialize SDL. + // if (SDL_Init(SDL_INIT_VIDEO) == -1) { + // const char* errorChar = SDL_GetError(); + // std::string errString(""); + // if (errorChar != NULL) { + // errString = errorChar; + // } + // //LibretroLog::log(RETRO_LOG_ERROR) << "[game] Unable to initialize SDL " << errString << std::endl; + // return false; + // } - // Build the Screen. - Uint32 flags; - if (conf.window.hwsurface) { - flags = SDL_HWSURFACE; - } else { - flags = SDL_SWSURFACE; - } - if (conf.window.asyncblit) { - flags |= SDL_ASYNCBLIT; - } - if (conf.window.doublebuffering) { - flags |= SDL_DOUBLEBUF; - } - app->screen = SDL_SetVideoMode(conf.window.width, conf.window.height, conf.window.bbp, flags); - if (app->screen == NULL) { - const char* errorChar = SDL_GetError(); - std::string errString(""); - if (errorChar != NULL) { - errString = errorChar; - } - LibretroLog::log(RETRO_LOG_ERROR) << "[game] Unable to initialize SDL" << errString << std::endl; - SDL_Quit(); - return false; - } + // // Build the Screen. + // Uint32 flags; + // if (conf.window.hwsurface) { + // flags = SDL_HWSURFACE; + // } else { + // flags = SDL_SWSURFACE; + // } + // if (conf.window.asyncblit) { + // flags |= SDL_ASYNCBLIT; + // } + // if (conf.window.doublebuffering) { + // flags |= SDL_DOUBLEBUF; + // } + // app->screen = SDL_SetVideoMode(conf.window.width, conf.window.height, conf.window.bbp, flags); + // if (app->screen == NULL) { + // const char* errorChar = SDL_GetError(); + // std::string errString(""); + // if (errorChar != NULL) { + // errString = errorChar; + // } + // //LibretroLog::log(RETRO_LOG_ERROR) << "[game] Unable to initialize SDL" << errString << std::endl; + // SDL_Quit(); + // return false; + // } - // Enable video buffering. - app->videoBuffer = (uint32_t *)app->screen->pixels; + // // Enable video buffering. + // //app->videoBuffer = (uint32_t *)app->screen->pixels; - // Set the title. - setTitle(conf.window.title); + // // Set the title. + // setTitle(conf.window.title); return true; } bool window::unload() { - // Destroy the screen. - ChaiLove* app = ChaiLove::getInstance(); - if (app->screen != NULL) { - SDL_FreeSurface(app->screen); - app->screen = NULL; - } + // // Destroy the screen. + // ChaiLove* app = ChaiLove::getInstance(); + // if (app->screen != NULL) { + // SDL_FreeSurface(app->screen); + // app->screen = NULL; + // } - // Close SDL. - SDL_Quit(); + // // Close SDL. + // SDL_Quit(); return true; } std::string window::getTitle() { - char* titleChar; - SDL_WM_GetCaption(&titleChar, NULL); - return std::string(titleChar); + return pntr_app_title(ChaiLove::getInstance()->app); } window& window::setTitle(const std::string& title) { - ChaiLove::getInstance()->config.window.title = title; - SDL_WM_SetCaption(title.c_str(), 0); + pntr_app_set_title(ChaiLove::getInstance()->app, title.c_str()); return *this; } diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 000000000..c2436e3c6 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,108 @@ +#define PNTR_PHYSFS_IMPLEMENTATION +#include "pntr_physfs.h" + +#define PNTR_APP_IMPLEMENTATION +#define PNTR_ENABLE_DEFAULT_FONT +#define PNTR_ENABLE_TTF +//#define PNTR_ENABLE_VARGS +#define PNTR_ENABLE_MATH +#define PNTR_NO_STDIO +#define PNTR_NO_SAVE_IMAGE +#include "pntr_app.h" + +#include "ChaiLove.h" + +typedef struct AppData { + pntr_image* image; + ChaiLove* chailove; +} AppData; + +bool Init(pntr_app* app) { + // Initialize PhysFS + const char* physfs_input = + #ifdef PNTR_APP_LIBRETRO + (const char*)pntr_app_libretro_environ_cb(app); + #else + app->argv[0]; + #endif + + if (PHYSFS_init(physfs_input) == 0) { + pntr_app_log(PNTR_APP_LOG_ERROR, "PHYSFS_init() failed"); + return false; + } + + // if (PHYSFS_mount("examples", "ex", 1) == 0) { + // pntr_app_log(PNTR_APP_LOG_ERROR, "PHYSFS_mount() failed"); + // return false; + // }; + + AppData* appData = (AppData*)pntr_load_memory(sizeof(AppData)); + pntr_app_set_userdata(app, appData); + + // Load the given file. + unsigned int size; + void* fileData = pntr_app_load_arg_file(app, &size); + if (fileData == NULL) { + pntr_app_log(PNTR_APP_LOG_ERROR, "Failed to load file"); + return false; + } + + if (PHYSFS_mountMemory((const char*)fileData, (PHYSFS_uint64)size, &pntr_unload_memory, "chailove.zip", NULL, 1) == 0) { + + pntr_unload_memory(fileData); + } + if (fileData) { + appData->image = pntr_load_image_from_memory(PNTR_IMAGE_TYPE_PNG, (const unsigned char*)fileData, size); + } + else { + pntr_app_log(PNTR_APP_LOG_ERROR, "Failed to load file"); + } + // Find the game path. + // std::string gamePath(info ? info->path : ""); + // if (gamePath == ".") { + // gamePath = "main.chai"; + // } + // void* data = NULL; + // if (info != NULL) { + // data = (void*)info->data; + // } + + return true; +} + +bool Update(pntr_app* app, pntr_image* screen) { + AppData* appData = (AppData*)pntr_app_userdata(app); + + // Clear the screen + pntr_clear_background(screen, PNTR_RAYWHITE); + + pntr_draw_image(screen, appData->image, 0, 0); + + // Draw some text + //pntr_draw_text(screen, appData->font, "Congrats! You created your first pntr_app!", 35, screen->height - 30, PNTR_DARKGRAY); + + return true; +} + +void Close(pntr_app* app) { + AppData* appData = (AppData*)pntr_app_userdata(app); + + //pntr_unload_font(appData->font); + + pntr_unload_memory(appData); + PHYSFS_deinit(); +} + +pntr_app Main(int argc, char* argv[]) { + (void)argc; + (void)argv; + return (pntr_app) { + .width = 640, + .height = 480, + .title = "libretro_chailove", + .init = Init, + .update = Update, + .close = Close, + .fps = 0 + }; +} diff --git a/vendor/noarch b/vendor/noarch index 3e3e71429..3c12f25e3 160000 --- a/vendor/noarch +++ b/vendor/noarch @@ -1 +1 @@ -Subproject commit 3e3e7142948aa83abb7b8b4bcd94c6efeedf0bc7 +Subproject commit 3c12f25e393affbeacfededd6ef708f3c36c4dde From 4b17ee73811348d20432e6fa605be6134e996fa7 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Fri, 3 Jan 2025 03:15:02 -0500 Subject: [PATCH 2/3] Update --- .github/workflows/build.yml | 5 +++-- .gitmodules | 15 +++++++++++++++ CHANGELOG.md | 4 ++++ Makefile | 12 ++++-------- src/main.cpp | 23 +++++++++-------------- vendor/pntr | 1 + vendor/pntr_app | 1 + vendor/pntr_physfs | 1 + 8 files changed, 38 insertions(+), 24 deletions(-) create mode 160000 vendor/pntr create mode 160000 vendor/pntr_app create mode 160000 vendor/pntr_physfs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bf37d85d8..c715c3ad8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,5 +22,6 @@ jobs: - name: Build run: make - - name: Test - run: make test + # TODO: Restore unit test framework + # - name: Test + # run: make test diff --git a/.gitmodules b/.gitmodules index 54087a113..551add260 100644 --- a/.gitmodules +++ b/.gitmodules @@ -73,3 +73,18 @@ url = https://github.com/RobLoach/physfs.git ignore = dirty branch = libretro-support +[submodule "vendor/pntr"] + path = vendor/pntr + url = https://github.com/RobLoach/pntr.git + ignore = dirty + branch = master +[submodule "vendor/pntr_app"] + path = vendor/pntr_app + url = https://github.com/RobLoach/pntr_app.git + ignore = dirty + branch = master +[submodule "vendor/pntr_physfs"] + path = vendor/pntr_physfs + url = https://github.com/RobLoach/pntr_physfs.git + ignore = dirty + branch = master diff --git a/CHANGELOG.md b/CHANGELOG.md index 731c0dc9d..50a0cc688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to [ChaiLove](https://github.com/RobLoach/ChaiLove) will be The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 2.0.0 - WIP +### Changed +- Moved from [sdl-libretro](https://github.com/libretro/sdl-libretro) to [pntr](https://github.com/robloach/pntr) and [pntr_app](https://github.com/robloach/pntr) + ## 1.3.0 - 2024-05-11 ### Fixes - Fix playing empty ogg files through `libretro-common`, by @phcoder diff --git a/Makefile b/Makefile index 72384587c..f9b4ae036 100644 --- a/Makefile +++ b/Makefile @@ -46,15 +46,11 @@ clean: test: unittest unittest-chailove @echo "Run the testing suite by using:\n\n retroarch -L $(TARGET) test/main.chai\n\n" -vendor/noarch/noarch: - cd vendor/noarch && cmake . - @$(MAKE) -C vendor/noarch +unittest: all + @retroarch -L $(CORE_DIR)/$(TARGET) test/unittests/main.chai -unittest: vendor/noarch/noarch all - vendor/noarch/noarch $(CORE_DIR)/$(TARGET) test/unittests/main.chai - -unittest-chailove: vendor/noarch/noarch all - vendor/noarch/noarch $(CORE_DIR)/$(TARGET) test/test.chailove +unittest-chailove: all + @retroarch -L $(CORE_DIR)/$(TARGET) test/test.chailove examples: all @retroarch -L $(TARGET) examples/benchmark/main.chai diff --git a/src/main.cpp b/src/main.cpp index c2436e3c6..5d0387135 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,15 +18,14 @@ typedef struct AppData { } AppData; bool Init(pntr_app* app) { + // Set up the initial app data. + AppData* appData = (AppData*)pntr_load_memory(sizeof(AppData)); + pntr_app_set_userdata(app, appData); + + + // Initialize PhysFS - const char* physfs_input = - #ifdef PNTR_APP_LIBRETRO - (const char*)pntr_app_libretro_environ_cb(app); - #else - app->argv[0]; - #endif - - if (PHYSFS_init(physfs_input) == 0) { + if (PHYSFS_init((const char*)pntr_app_libretro_environ_cb(app)) == 0) { pntr_app_log(PNTR_APP_LOG_ERROR, "PHYSFS_init() failed"); return false; } @@ -36,9 +35,6 @@ bool Init(pntr_app* app) { // return false; // }; - AppData* appData = (AppData*)pntr_load_memory(sizeof(AppData)); - pntr_app_set_userdata(app, appData); - // Load the given file. unsigned int size; void* fileData = pntr_app_load_arg_file(app, &size); @@ -87,10 +83,9 @@ bool Update(pntr_app* app, pntr_image* screen) { void Close(pntr_app* app) { AppData* appData = (AppData*)pntr_app_userdata(app); - //pntr_unload_font(appData->font); - pntr_unload_memory(appData); - PHYSFS_deinit(); + + ChaiLove::destroy(); } pntr_app Main(int argc, char* argv[]) { diff --git a/vendor/pntr b/vendor/pntr new file mode 160000 index 000000000..051633706 --- /dev/null +++ b/vendor/pntr @@ -0,0 +1 @@ +Subproject commit 0516337064d7c09fc84e6233549b15e8e768d035 diff --git a/vendor/pntr_app b/vendor/pntr_app new file mode 160000 index 000000000..87ae12bfd --- /dev/null +++ b/vendor/pntr_app @@ -0,0 +1 @@ +Subproject commit 87ae12bfd5a5466f13a9a2b2138796286a7fec1a diff --git a/vendor/pntr_physfs b/vendor/pntr_physfs new file mode 160000 index 000000000..0376b71c3 --- /dev/null +++ b/vendor/pntr_physfs @@ -0,0 +1 @@ +Subproject commit 0376b71c3b24902bc4463b49c491bb73d7ebcdd1 From 4773c554e192fa176b0eb158df07f81a9ec4202c Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 4 Jan 2025 03:57:46 -0500 Subject: [PATCH 3/3] Update --- src/ChaiLove.cpp | 18 +++---- src/ChaiLove.h | 4 +- src/love/Types/Audio/SoundData.cpp | 1 - src/love/Types/Graphics/Font.cpp | 1 - src/love/Types/Graphics/Image.cpp | 1 - src/love/data.cpp | 1 - src/love/filesystem.cpp | 24 ++++----- src/love/filesystem.h | 3 +- src/love/font.cpp | 1 - src/love/graphics.cpp | 1 - src/love/math.cpp | 4 ++ src/love/math.h | 1 + src/love/script.cpp | 3 +- src/love/system.cpp | 1 - src/love/window.cpp | 1 - src/main.cpp | 81 +++++++++++------------------- 16 files changed, 57 insertions(+), 89 deletions(-) diff --git a/src/ChaiLove.cpp b/src/ChaiLove.cpp index 6dd40f7c9..6e6aa4b28 100644 --- a/src/ChaiLove.cpp +++ b/src/ChaiLove.cpp @@ -1,7 +1,6 @@ -#include "ChaiLove.h" -#include "LibretroLog.h" #include #include +#include "ChaiLove.h" ChaiLove* ChaiLove::m_instance = NULL; retro_input_state_t ChaiLove::input_state_cb = NULL; @@ -55,11 +54,11 @@ void ChaiLove::quit(void) { window.unload(); } -bool ChaiLove::load(const std::string& file, const void* data) { +bool ChaiLove::load(const std::string& file, const void* data, unsigned int dataSize) { // Display a welcome message from ChaiLove. -#ifndef GIT_VERSION -#define GIT_VERSION "" -#endif + #ifndef GIT_VERSION + #define GIT_VERSION "" + #endif std::string version = CHAILOVE_VERSION_STRING GIT_VERSION; //LibretroLog::log(RETRO_LOG_INFO) << "[ChaiLove] ChaiLove " << version.c_str() << std::endl; @@ -67,8 +66,7 @@ bool ChaiLove::load(const std::string& file, const void* data) { sound.load(app); // Initalize the file system. - bool loaded = filesystem.init(file, data); - if (!loaded) { + if (!filesystem.init(file, data, dataSize)) { //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error loading " << file << std::endl; return false; } @@ -131,10 +129,6 @@ void ChaiLove::reset() { * Render the ChaiLove. */ void ChaiLove::draw() { - if (event.m_shouldclose) { - return; - } - // Clear the screen. graphics.clear(); diff --git a/src/ChaiLove.h b/src/ChaiLove.h index dca6c6e9c..ff076a56e 100644 --- a/src/ChaiLove.h +++ b/src/ChaiLove.h @@ -49,6 +49,8 @@ #define CHAILOVE_VERSION_PATCH 0 #define CHAILOVE_VERSION_STRING "2.0.0-pre" +#include + #include "pntr_app.h" #include "libretro.h" @@ -101,7 +103,7 @@ class ChaiLove { ~ChaiLove(); void quit(void); - bool load(const std::string& file, const void* data); + bool load(const std::string& file, const void* data, unsigned int dataSize); void update(); void draw(); void reset(); diff --git a/src/love/Types/Audio/SoundData.cpp b/src/love/Types/Audio/SoundData.cpp index 8a425842c..b00696819 100644 --- a/src/love/Types/Audio/SoundData.cpp +++ b/src/love/Types/Audio/SoundData.cpp @@ -4,7 +4,6 @@ #include #include "../../../ChaiLove.h" -#include "../../../LibretroLog.h" namespace love { namespace Types { diff --git a/src/love/Types/Graphics/Font.cpp b/src/love/Types/Graphics/Font.cpp index f3a3e72d7..2de034187 100644 --- a/src/love/Types/Graphics/Font.cpp +++ b/src/love/Types/Graphics/Font.cpp @@ -2,7 +2,6 @@ #include "pntr_app.h" #include #include "../../../ChaiLove.h" -#include "../../../LibretroLog.h" #include "Image.h" namespace love { diff --git a/src/love/Types/Graphics/Image.cpp b/src/love/Types/Graphics/Image.cpp index db045bfcf..db490f7d7 100644 --- a/src/love/Types/Graphics/Image.cpp +++ b/src/love/Types/Graphics/Image.cpp @@ -3,7 +3,6 @@ #include #include "../../../ChaiLove.h" -#include "../../../LibretroLog.h" namespace love { namespace Types { diff --git a/src/love/data.cpp b/src/love/data.cpp index 0dbd1e68e..ddb36d324 100644 --- a/src/love/data.cpp +++ b/src/love/data.cpp @@ -11,7 +11,6 @@ #include "TinySHA1.hpp" #include #include -#include "../LibretroLog.h" namespace love { diff --git a/src/love/filesystem.cpp b/src/love/filesystem.cpp index 18cd97034..a3a9ccef9 100644 --- a/src/love/filesystem.cpp +++ b/src/love/filesystem.cpp @@ -4,7 +4,6 @@ #include "physfs.h" #include "filesystem.h" #include "../ChaiLove.h" -#include "../LibretroLog.h" #include "Types/FileSystem/FileInfo.h" using love::Types::FileSystem::FileInfo; @@ -15,15 +14,7 @@ namespace love { /** * Initialize the file system. */ -bool filesystem::init(const std::string& file, const void* data) { - // Initialize PhysFS - if (PHYSFS_isInit() == 0) { - if (PHYSFS_init((const char*)ChaiLove::getInstance()->environ_cb) == 0) { - //LibretroLog::log(RETRO_LOG_ERROR) << "[ChaiLove] [filesystem] Error loading PhysFS - " << getLastError() << std::endl; - return false; - } - } - +bool filesystem::init(const std::string& file, const void* data, unsigned int dataSize) { // Check if we are simply running ChaiLove. if (file.empty()) { return mount(".", "/", false); @@ -34,7 +25,7 @@ bool filesystem::init(const std::string& file, const void* data) { // Allow loading from an Archive. if (extension == "chaigame" || extension == "chailove" || extension == "zip") { - return mount(file.c_str(), "/", false); + return mount(data, dataSize, "/"); } // If we are just running the core, load the base path. @@ -143,9 +134,6 @@ PHYSFS_sint64 filesystem::getSize(PHYSFS_File* file) { } bool filesystem::unload() { - if (PHYSFS_isInit() != 0) { - PHYSFS_deinit(); - } return true; } @@ -262,6 +250,14 @@ bool filesystem::mount(const std::string& archive, const std::string& mountpoint return mount(archive, mountpoint, true); } +bool filesystem::mount(const void *data, unsigned int size, const std::string& mountpoint) { + // TODO: Do we need to register del() callback? + if (PHYSFS_mountMemory(data, (PHYSFS_uint64)size, NULL, "chailove.zip", mountpoint.c_str(), 1) == 0) { + return false; + } + return true; +} + bool filesystem::mount(const std::string& archive, const std::string& mountpoint, bool appendToPath) { // Protect against empty archive/mount points. int append = appendToPath ? 1 : 0; diff --git a/src/love/filesystem.h b/src/love/filesystem.h index 352fa73e1..f50d12457 100644 --- a/src/love/filesystem.h +++ b/src/love/filesystem.h @@ -35,7 +35,7 @@ class filesystem { bool load(const std::string& file); void mountlibretro(); - bool init(const std::string& file, const void* data); + bool init(const std::string& file, const void* data, unsigned int dataSize); bool unload(); void* openRW(const std::string& filename); char* readChar(const std::string& filename); @@ -141,6 +141,7 @@ class filesystem { bool mount(const std::string& archive, const std::string& mountpoint, bool appendToPath); bool mount(const std::string& archive, const std::string& mountpoint); bool mount(const char *archive, const std::string& mountpoint); + bool mount(const void *data, unsigned int size, const std::string& mountpoint); /** * Gets the path to the designated save directory. diff --git a/src/love/font.cpp b/src/love/font.cpp index e079ad8e8..d194cd7b3 100644 --- a/src/love/font.cpp +++ b/src/love/font.cpp @@ -2,7 +2,6 @@ #include "pntr_app.h" #include "font.h" #include "Types/Graphics/Font.h" -#include "../LibretroLog.h" namespace love { diff --git a/src/love/graphics.cpp b/src/love/graphics.cpp index 60d413825..a560112b5 100644 --- a/src/love/graphics.cpp +++ b/src/love/graphics.cpp @@ -1,7 +1,6 @@ #include "graphics.h" #include "../ChaiLove.h" -#include "../LibretroLog.h" #include "Types/Graphics/Image.h" #include "Types/Graphics/Font.h" #include "Types/Graphics/Color.h" diff --git a/src/love/math.cpp b/src/love/math.cpp index d7a51c0d1..26c34a68f 100644 --- a/src/love/math.cpp +++ b/src/love/math.cpp @@ -31,6 +31,10 @@ double math::random(double min, double max) { return (double)pntr_app_random_float(app, (float)min, (float)max); } +double math::random(double max) { + return (double)pntr_app_random_float(app, 0.0f, (float)max); +} + math& math::setRandomSeed(int min, int max) { return setRandomSeed(random(min, max)); } diff --git a/src/love/math.h b/src/love/math.h index 2497a09be..38c2a6227 100644 --- a/src/love/math.h +++ b/src/love/math.h @@ -32,6 +32,7 @@ class math { int random(int min, int max); int random(int max); double random(double min, double max); + double random(double max); /** * Sets the random seed to a random seed between the given min and max values. diff --git a/src/love/script.cpp b/src/love/script.cpp index 4a73ea25b..7374d8ada 100644 --- a/src/love/script.cpp +++ b/src/love/script.cpp @@ -1,6 +1,5 @@ #include "script.h" #include "../ChaiLove.h" -#include "../LibretroLog.h" #include #ifdef __HAVE_CHAISCRIPT__ @@ -395,8 +394,8 @@ script::script(const std::string& file) { chai.add(fun(&math::random), "random"); chai.add(fun(&math::random), "random"); chai.add(fun(&math::random), "random"); - chai.add(fun(&math::setRandomSeed), "setRandomSeed"); chai.add(fun(&math::setRandomSeed), "setRandomSeed"); + chai.add(fun(&math::setRandomSeed), "setRandomSeed"); chai.add(fun(&math::getRandomSeed), "getRandomSeed"); // Data diff --git a/src/love/system.cpp b/src/love/system.cpp index 83c888dbe..136851fac 100644 --- a/src/love/system.cpp +++ b/src/love/system.cpp @@ -1,6 +1,5 @@ #include "system.h" #include "../ChaiLove.h" -#include "../LibretroLog.h" #include #include diff --git a/src/love/window.cpp b/src/love/window.cpp index e1a4b0f8a..5ac432dde 100644 --- a/src/love/window.cpp +++ b/src/love/window.cpp @@ -1,7 +1,6 @@ #include "window.h" #include #include "../ChaiLove.h" -#include "../LibretroLog.h" #include "pntr_app.h" #include "config.h" diff --git a/src/main.cpp b/src/main.cpp index 5d0387135..35e012d36 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,12 @@ +#include +#include // TODO: Remove this + #define PNTR_PHYSFS_IMPLEMENTATION #include "pntr_physfs.h" #define PNTR_APP_IMPLEMENTATION #define PNTR_ENABLE_DEFAULT_FONT #define PNTR_ENABLE_TTF -//#define PNTR_ENABLE_VARGS #define PNTR_ENABLE_MATH #define PNTR_NO_STDIO #define PNTR_NO_SAVE_IMAGE @@ -12,80 +14,57 @@ #include "ChaiLove.h" -typedef struct AppData { - pntr_image* image; - ChaiLove* chailove; -} AppData; - bool Init(pntr_app* app) { - // Set up the initial app data. - AppData* appData = (AppData*)pntr_load_memory(sizeof(AppData)); - pntr_app_set_userdata(app, appData); - - + ChaiLove::environ_cb = pntr_app_libretro_environ_cb(app); // Initialize PhysFS - if (PHYSFS_init((const char*)pntr_app_libretro_environ_cb(app)) == 0) { + if (PHYSFS_init((const char*)ChaiLove::environ_cb) == 0) { pntr_app_log(PNTR_APP_LOG_ERROR, "PHYSFS_init() failed"); return false; } - // if (PHYSFS_mount("examples", "ex", 1) == 0) { - // pntr_app_log(PNTR_APP_LOG_ERROR, "PHYSFS_mount() failed"); - // return false; - // }; - - // Load the given file. - unsigned int size; - void* fileData = pntr_app_load_arg_file(app, &size); - if (fileData == NULL) { - pntr_app_log(PNTR_APP_LOG_ERROR, "Failed to load file"); + // Set up the chailove instance. + ChaiLove* chailove = ChaiLove::getInstance(); + if (chailove == NULL) { + PHYSFS_deinit(); return false; } - if (PHYSFS_mountMemory((const char*)fileData, (PHYSFS_uint64)size, &pntr_unload_memory, "chailove.zip", NULL, 1) == 0) { - - pntr_unload_memory(fileData); - } - if (fileData) { - appData->image = pntr_load_image_from_memory(PNTR_IMAGE_TYPE_PNG, (const unsigned char*)fileData, size); - } - else { - pntr_app_log(PNTR_APP_LOG_ERROR, "Failed to load file"); + // Load + std::string argFile = app->argFile == NULL ? "" : app->argFile; + if (!chailove->load(argFile, app->argFileData, app->argFileDataSize)) { + ChaiLove::destroy(); + PHYSFS_deinit(); + return false; } - // Find the game path. - // std::string gamePath(info ? info->path : ""); - // if (gamePath == ".") { - // gamePath = "main.chai"; - // } - // void* data = NULL; - // if (info != NULL) { - // data = (void*)info->data; - // } + pntr_app_set_userdata(app, (void*)chailove); return true; } bool Update(pntr_app* app, pntr_image* screen) { - AppData* appData = (AppData*)pntr_app_userdata(app); + ChaiLove* chailove = (ChaiLove*)pntr_app_userdata(app); + chailove->screen = screen; + if (chailove == NULL) { + return false; + } - // Clear the screen - pntr_clear_background(screen, PNTR_RAYWHITE); + // Update the game. + chailove->update(); - pntr_draw_image(screen, appData->image, 0, 0); + if (chailove->event.m_shouldclose) { + return false; + } - // Draw some text - //pntr_draw_text(screen, appData->font, "Congrats! You created your first pntr_app!", 35, screen->height - 30, PNTR_DARKGRAY); + // Render the game. + chailove->draw(); return true; } void Close(pntr_app* app) { - AppData* appData = (AppData*)pntr_app_userdata(app); - - - ChaiLove::destroy(); + PHYSFS_deinit(); } pntr_app Main(int argc, char* argv[]) { @@ -94,7 +73,7 @@ pntr_app Main(int argc, char* argv[]) { return (pntr_app) { .width = 640, .height = 480, - .title = "libretro_chailove", + .title = "ChaiLove", .init = Init, .update = Update, .close = Close,