Unverified Commit 334e08af authored by RobLoach's avatar RobLoach Committed by GitHub
Browse files

0.21.0 (#243)

### Chores
- Switched to [libretro-deps](https://github.com/libretro/libretro-deps) for freetype and zlib
- Clean up of image and audio memory allocation
- Updated documentation

### Features
- `love.system.execute()` to execute a operating system shell command
- `love.audio.newSource()` now has an optional `type` parameter
- `love.joystick` comes with a cleaner API
- `exit()` callback, which is called when is quitting the game
- `love.filesystem` now mounts `libretro/assets`, `libretro/system` and `libretro/saves`
parent e19269c2
...@@ -24,9 +24,6 @@ ...@@ -24,9 +24,6 @@
[submodule "vendor/Snippets"] [submodule "vendor/Snippets"]
path = vendor/Snippets path = vendor/Snippets
url = https://github.com/DanielGibson/Snippets.git url = https://github.com/DanielGibson/Snippets.git
[submodule "vendor/zlib"]
path = vendor/zlib
url = https://github.com/madler/zlib.git
[submodule "vendor/libretro-deps"] [submodule "vendor/libretro-deps"]
path = vendor/libretro-deps path = vendor/libretro-deps
url = https://github.com/libretro/libretro-deps.git url = https://github.com/libretro/libretro-deps.git
...@@ -43,10 +40,6 @@ ...@@ -43,10 +40,6 @@
[submodule "vendor/random"] [submodule "vendor/random"]
path = vendor/random path = vendor/random
url = https://github.com/effolkronium/random.git url = https://github.com/effolkronium/random.git
[submodule "vendor/freetype2"]
path = vendor/freetype2
url = https://git.savannah.gnu.org/git/freetype/freetype2.git
ignore = dirty
[submodule "vendor/semver"] [submodule "vendor/semver"]
path = vendor/semver path = vendor/semver
url = https://github.com/h2non/semver.c.git url = https://github.com/h2non/semver.c.git
......
...@@ -4,38 +4,51 @@ All notable changes to [ChaiLove](https://github.com/RobLoach/ChaiLove) will be ...@@ -4,38 +4,51 @@ 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/) 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). and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## 0.21.0 - 2018-05-02
### Chores
- Switched to [libretro-deps](https://github.com/libretro/libretro-deps) for freetype and zlib
- Clean up of image and audio memory allocation
- Updated documentation
### Features
- `love.system.execute()` to execute a operating system shell command
- `love.audio.newSource()` now has an optional `type` parameter
- `love.joystick` comes with a cleaner API
- `exit()` callback, which is called when is quitting the game
- `love.filesystem` now mounts `libretro/assets`, `libretro/system` and `libretro/saves`
## 0.20.1 - 2018-04-24 ## 0.20.1 - 2018-04-24
### Fixed ### Bug Fixes
- Better memory usage - Better memory usage
- Compilation warnings - Compilation warnings
## 0.20.0 - 2018-04-22 ## 0.20.0 - 2018-04-22
### Added ### Features
- No Game demo when ChaiLove is loaded without content - No Game demo when ChaiLove is loaded without content
- Version mismatch warning when content's ChaiLove version doesn't match core's - Version mismatch warning when content's ChaiLove version doesn't match core's
- `love.data.hash()` `sha1` support - `love.data.hash()` `sha1` support
- `love.system.getUsername()` - `love.system.getUsername()`
## 0.19.0 - 2018-04-13 ## 0.19.0 - 2018-04-13
### Added ### Features
- Android build - Android build
- By [@webgeek1234](https://github.com/webgeek1234) - By [@webgeek1234](https://github.com/webgeek1234)
- `love.data.hash()` to retrieve MD5 hashes from content - `love.data.hash()` to retrieve MD5 hashes from content
- Windows automated testing with [Appveyor](https://ci.appveyor.com/project/RobLoach/libretro-chailove) - Windows automated testing with [Appveyor](https://ci.appveyor.com/project/RobLoach/libretro-chailove)
## 0.18.1 - 2018-04-09 ## 0.18.1 - 2018-04-09
### Added ### Chores
- Documentation - Documentation
## 0.18.0 - 2018-04-03 ## 0.18.0 - 2018-04-03
### Added ### Features
- [Semantic Versioning](https://semver.org/) checks - [Semantic Versioning](https://semver.org/) checks
- Use `t.version = "0.18.0"` in `conf(t)` to specify which ChaiLove version you're targeting - Use `t.version = "0.18.0"` in `conf(t)` to specify which ChaiLove version you're targeting
- `love.graphics.getDimensions()` - `love.graphics.getDimensions()`
- `love.filesystem.getInfo()` - `love.filesystem.getInfo()`
- `love.filesystem.isSymlink()` - `love.filesystem.isSymlink()`
### Updated ### Breaking Changes
- `love.math.compress()` is now `love.data.compress()` - `love.math.compress()` is now `love.data.compress()`
- Documentation - Documentation
......
...@@ -10,7 +10,7 @@ SOURCES_CXX := $(wildcard \ ...@@ -10,7 +10,7 @@ SOURCES_CXX := $(wildcard \
) )
# semver # semver
FLAGS := -I$(CORE_DIR)/vendor/semver FLAGS += -I$(CORE_DIR)/vendor/semver
SOURCES_C := $(CORE_DIR)/vendor/semver/semver.c SOURCES_C := $(CORE_DIR)/vendor/semver/semver.c
# random # random
...@@ -24,21 +24,22 @@ FLAGS += -I$(CORE_DIR)/vendor/libretro-common/include ...@@ -24,21 +24,22 @@ FLAGS += -I$(CORE_DIR)/vendor/libretro-common/include
# zlib # zlib
SOURCES_C += \ SOURCES_C += \
$(CORE_DIR)/vendor/zlib/zutil.c \ $(CORE_DIR)/vendor/libretro-deps/libz/zutil.c \
$(CORE_DIR)/vendor/zlib/adler32.c \ $(CORE_DIR)/vendor/libretro-deps/libz/adler32.c \
$(CORE_DIR)/vendor/zlib/crc32.c \ $(CORE_DIR)/vendor/libretro-deps/libz/crc32.c \
$(CORE_DIR)/vendor/zlib/compress.c \ $(CORE_DIR)/vendor/libretro-deps/libz/compress.c \
$(CORE_DIR)/vendor/zlib/deflate.c \ $(CORE_DIR)/vendor/libretro-deps/libz/deflate.c \
$(CORE_DIR)/vendor/zlib/gzclose.c \ $(CORE_DIR)/vendor/libretro-deps/libz/gzclose.c \
$(CORE_DIR)/vendor/zlib/gzlib.c \ $(CORE_DIR)/vendor/libretro-deps/libz/gzlib.c \
$(CORE_DIR)/vendor/zlib/gzread.c \ $(CORE_DIR)/vendor/libretro-deps/libz/gzread.c \
$(CORE_DIR)/vendor/zlib/gzwrite.c \ $(CORE_DIR)/vendor/libretro-deps/libz/gzwrite.c \
$(CORE_DIR)/vendor/zlib/infback.c \ $(CORE_DIR)/vendor/libretro-deps/libz/infback.c \
$(CORE_DIR)/vendor/zlib/inffast.c \ $(CORE_DIR)/vendor/libretro-deps/libz/inffast.c \
$(CORE_DIR)/vendor/zlib/inftrees.c \ $(CORE_DIR)/vendor/libretro-deps/libz/inftrees.c \
$(CORE_DIR)/vendor/zlib/inflate.c \ $(CORE_DIR)/vendor/libretro-deps/libz/inflate.c \
$(CORE_DIR)/vendor/zlib/trees.c $(CORE_DIR)/vendor/libretro-deps/libz/trees.c
FLAGS += -I$(CORE_DIR)/vendor/zlib FLAGS += -I$(CORE_DIR)/vendor/libretro-deps/libz
FLAGS += -I$(CORE_DIR)/vendor/libretro-common/compat
FLAGS += -DWANT_ZLIB FLAGS += -DWANT_ZLIB
# PhysFS # PhysFS
...@@ -71,7 +72,7 @@ SOURCES_C += $(wildcard \ ...@@ -71,7 +72,7 @@ SOURCES_C += $(wildcard \
# FreeType2 # FreeType2
# See https://github.com/emscripten-ports/FreeType/blob/master/builds/amiga/makefile # See https://github.com/emscripten-ports/FreeType/blob/master/builds/amiga/makefile
FLAGS += -I$(CORE_DIR)/vendor/freetype2/include FLAGS += -I$(CORE_DIR)/vendor/libretro-deps/freetype/include
FLAGS += -DFT2_BUILD_LIBRARY \ FLAGS += -DFT2_BUILD_LIBRARY \
-DFT_USE_AUTOFIT \ -DFT_USE_AUTOFIT \
-DFT_USE_RASTER \ -DFT_USE_RASTER \
...@@ -85,48 +86,48 @@ FLAGS += -DFT2_BUILD_LIBRARY \ ...@@ -85,48 +86,48 @@ FLAGS += -DFT2_BUILD_LIBRARY \
-DFT_USE_GXV -DFT_USE_GXV
SOURCES_C += \ SOURCES_C += \
$(CORE_DIR)/vendor/freetype2/src/base/ftbase.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftbase.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftinit.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftinit.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftsystem.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftsystem.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftdebug.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftdebug.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftbbox.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftbbox.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftbdf.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftbdf.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftstroke.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftstroke.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftbitmap.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftbitmap.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftcid.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftcid.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftfntfmt.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftfntfmt.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftfstype.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftfstype.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftgasp.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftgasp.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftglyph.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftglyph.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftgxval.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftgxval.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftlcdfil.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftlcdfil.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftmm.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftmm.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftotval.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftotval.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftpatent.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftpatent.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftpfr.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftpfr.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftsynth.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftsynth.c \
$(CORE_DIR)/vendor/freetype2/src/base/fttype1.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/fttype1.c \
$(CORE_DIR)/vendor/freetype2/src/base/ftwinfnt.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/base/ftwinfnt.c \
$(CORE_DIR)/vendor/freetype2/src/autofit/autofit.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/autofit/autofit.c \
$(CORE_DIR)/vendor/freetype2/src/pshinter/pshinter.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/pshinter/pshinter.c \
$(CORE_DIR)/vendor/freetype2/src/psaux/psaux.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/psaux/psaux.c \
$(CORE_DIR)/vendor/freetype2/src/psnames/psnames.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/psnames/psnames.c \
$(CORE_DIR)/vendor/freetype2/src/raster/raster.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/raster/raster.c \
$(CORE_DIR)/vendor/freetype2/src/smooth/smooth.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/smooth/smooth.c \
$(CORE_DIR)/vendor/freetype2/src/cache/ftcache.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/cache/ftcache.c \
$(CORE_DIR)/vendor/freetype2/src/bdf/bdf.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/bdf/bdf.c \
$(CORE_DIR)/vendor/freetype2/src/cff/cff.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/cff/cff.c \
$(CORE_DIR)/vendor/freetype2/src/pcf/pcf.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/pcf/pcf.c \
$(CORE_DIR)/vendor/freetype2/src/winfonts/winfnt.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/winfonts/winfnt.c \
$(CORE_DIR)/vendor/freetype2/src/sfnt/sfnt.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/sfnt/sfnt.c \
$(CORE_DIR)/vendor/freetype2/src/pfr/pfr.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/pfr/pfr.c \
$(CORE_DIR)/vendor/freetype2/src/truetype/truetype.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/truetype/truetype.c \
$(CORE_DIR)/vendor/freetype2/src/type1/type1.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/type1/type1.c \
$(CORE_DIR)/vendor/freetype2/src/type42/type42.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/type42/type42.c \
$(CORE_DIR)/vendor/freetype2/src/cid/type1cid.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/cid/type1cid.c \
$(CORE_DIR)/vendor/freetype2/src/gzip/ftgzip.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/gzip/ftgzip.c \
$(CORE_DIR)/vendor/freetype2/src/bzip2/ftbzip2.c \ $(CORE_DIR)/vendor/libretro-deps/freetype/src/bzip2/ftbzip2.c \
$(CORE_DIR)/vendor/freetype2/src/lzw/ftlzw.c $(CORE_DIR)/vendor/libretro-deps/freetype/src/lzw/ftlzw.c
# SDL_ttf # SDL_ttf
FLAGS += -I$(CORE_DIR)/vendor/sdl-libretro/tests/SDL_ttf-2.0.11/VisualC/external/include FLAGS += -I$(CORE_DIR)/vendor/sdl-libretro/tests/SDL_ttf-2.0.11/VisualC/external/include
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
[![platform libretro](https://img.shields.io/badge/platform-libretro-brightgreen.svg)](http://buildbot.fiveforty.net/admin/buildbot/build/?name=chailove) [![platform libretro](https://img.shields.io/badge/platform-libretro-brightgreen.svg)](http://buildbot.fiveforty.net/admin/buildbot/build/?name=chailove)
[![Documentation](https://img.shields.io/badge/docs-doxygen-blue.svg)](https://rawgit.com/libretro/libretro-chailove/docs/) [![Documentation](https://img.shields.io/badge/docs-doxygen-blue.svg)](https://rawgit.com/libretro/libretro-chailove/docs/)
ChaiLove is an awesome framework you can use to make 2D games in [ChaiScript](http://chaiscript.com/). It's free, open-source, and works on Windows, Mac OS X, Linux, and ARM through [libretro](https://www.libretro.com)/[RetroArch](http://retroarch.com). ChaiLove is an awesome framework you can use to make 2D games in [ChaiScript](http://chaiscript.com/). It's free, open-source, and works on Windows, Mac OS X, Linux, Android, and ARM through [libretro](https://www.libretro.com)/[RetroArch](http://retroarch.com).
[![Floppy Bird Gameplay](docs/screenshot.png)](https://www.youtube.com/watch?v=RLVwTh6qDFI&hd=1) [![Floppy Bird Gameplay](docs/screenshot.png)](https://www.youtube.com/watch?v=RLVwTh6qDFI&hd=1)
...@@ -66,7 +66,7 @@ Behind ChaiLove, there's the documentation, compiling it, along with testing. ...@@ -66,7 +66,7 @@ Behind ChaiLove, there's the documentation, compiling it, along with testing.
### Compiling ### Compiling
Use the following command to compile the core: Use the following command to compile the core, with at least `g++ >=5.2`:
``` ```
make make
......
#!/bin/sh #!/bin/sh
# ChaiLove configure
# This ./configure file is set up to allow use of the standard make build practices.
#
# Here be dragons.
PACKAGE_NAME=libretro-chailove PACKAGE_NAME=libretro-chailove
...@@ -23,7 +23,7 @@ PROJECT_NAME = "ChaiLove API" ...@@ -23,7 +23,7 @@ PROJECT_NAME = "ChaiLove API"
# This could be handy for archiving the generated documentation or # This could be handy for archiving the generated documentation or
# if some version control system is used. # if some version control system is used.
PROJECT_NUMBER = "0.20.1" PROJECT_NUMBER = "0.21.0"
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put. # base path where the generated documentation will be put.
......
...@@ -37,12 +37,17 @@ ChaiLove::~ChaiLove() { ...@@ -37,12 +37,17 @@ ChaiLove::~ChaiLove() {
} }
void ChaiLove::quit(void) { void ChaiLove::quit(void) {
// Enforce the should close flag.
event.m_shouldclose = true; event.m_shouldclose = true;
// Destroy all the subsystems.
// Disengage the scripting language.
if (script) { if (script) {
script->exit();
delete script; delete script;
script = NULL; script = NULL;
} }
// Unload all the other sub-systems.
joystick.unload(); joystick.unload();
font.unload(); font.unload();
image.unload(); image.unload();
...@@ -66,6 +71,8 @@ bool ChaiLove::load(const std::string& file) { ...@@ -66,6 +71,8 @@ bool ChaiLove::load(const std::string& file) {
return false; return false;
} }
filesystem.mountlibretro();
// Initialize the scripting system. // Initialize the scripting system.
script = new love::script(file); script = new love::script(file);
if (!script->mainLoaded) { if (!script->mainLoaded) {
......
...@@ -23,8 +23,20 @@ ...@@ -23,8 +23,20 @@
* This is the full source for "hello world" in ChaiLove, using a `main.chai` file. Running this code will cause an 640 by 480 window to appear, and display white text on a black background. * This is the full source for "hello world" in ChaiLove, using a `main.chai` file. Running this code will cause an 640 by 480 window to appear, and display white text on a black background.
* *
* @code * @code
* global logo
* global x = 10.0f
*
* def load() {
* logo = love.graphics.newImage("logo.png")
* }
*
* def draw() { * def draw() {
* love.graphics.print("Hello World!", 200, 250) * love.graphics.print("Hello World!", 400, 300)
* love.graphics.draw(logo, x, 100)
* }
*
* def update(dt) {
* x = x + 20.0f * dt
* } * }
* @endcode * @endcode
* *
...@@ -35,9 +47,9 @@ ...@@ -35,9 +47,9 @@
#define SRC_CHAILOVE_H_ #define SRC_CHAILOVE_H_
#define CHAILOVE_VERSION_MAJOR 0 #define CHAILOVE_VERSION_MAJOR 0
#define CHAILOVE_VERSION_MINOR 20 #define CHAILOVE_VERSION_MINOR 21
#define CHAILOVE_VERSION_PATCH 1 #define CHAILOVE_VERSION_PATCH 0
#define CHAILOVE_VERSION_STRING "0.20.1" #define CHAILOVE_VERSION_STRING "0.21.0"
#include "SDL.h" #include "SDL.h"
#include "libretro.h" #include "libretro.h"
......
...@@ -6,9 +6,6 @@ ...@@ -6,9 +6,6 @@
#include "libretro.h" #include "libretro.h"
#include "ChaiLove.h" #include "ChaiLove.h"
const char *retro_save_directory;
const char *retro_system_directory;
const char *retro_content_directory;
static bool use_audio_cb; static bool use_audio_cb;
int16_t audio_buffer[2 * (44100 / 60)]; int16_t audio_buffer[2 * (44100 / 60)];
static retro_video_refresh_t video_cb; static retro_video_refresh_t video_cb;
...@@ -94,28 +91,7 @@ void retro_set_environment(retro_environment_t cb) { ...@@ -94,28 +91,7 @@ void retro_set_environment(retro_environment_t cb) {
* libretro callback; Updates the core option variables. * libretro callback; Updates the core option variables.
*/ */
static void update_variables(void) { static void update_variables(void) {
ChaiLove* game = ChaiLove::getInstance(); std::cout << "[ChaiLove] [libretro] update_variables()" << std::endl;
struct retro_variable var = {0};
// Alpha Blending
var.key = "chailove_alphablending";
var.value = NULL;
if (ChaiLove::environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
std::string varvalue(var.value);
if (varvalue == "disabled") {
game->config.options["alphablending"] = false;
}
}
// High Quality
var.key = "chailove_highquality";
var.value = NULL;
if (ChaiLove::environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
std::string varvalue(var.value);
if (varvalue == "disabled") {
game->config.options["highquality"] = false;
}
}
} }
#ifdef __cplusplus #ifdef __cplusplus
...@@ -421,28 +397,6 @@ size_t retro_get_memory_size(unsigned id) { ...@@ -421,28 +397,6 @@ size_t retro_get_memory_size(unsigned id) {
* libretro callback; Initialize the core. * libretro callback; Initialize the core.
*/ */
void retro_init(void) { void retro_init(void) {
const char *system_dir = NULL;
// System Directory
if (ChaiLove::environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_dir) && system_dir) {
retro_system_directory = system_dir;
}
// Content Directory
const char *content_dir = NULL;
if (ChaiLove::environ_cb(RETRO_ENVIRONMENT_GET_CONTENT_DIRECTORY, &content_dir) && content_dir) {
retro_content_directory = content_dir;
}
// Save Directory
const char *save_dir = NULL;
if (ChaiLove::environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &save_dir) && save_dir) {
// If save directory is defined use it, otherwise use system directory
retro_save_directory = *save_dir ? save_dir : retro_system_directory;
} else {
retro_save_directory = retro_system_directory;
}
// Pixel Format // Pixel Format
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888; enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888;
if (!ChaiLove::environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) { if (!ChaiLove::environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) {
......
...@@ -86,7 +86,7 @@ bool SoundData::stop() { ...@@ -86,7 +86,7 @@ bool SoundData::stop() {
} }
bool SoundData::isLoaded() { bool SoundData::isLoaded() {
return sndta.fp != NULL && ChaiLove::hasInstance(); return sndta.fp != NULL;
} }
bool SoundData::isPlaying() { bool SoundData::isPlaying() {
......
...@@ -23,7 +23,7 @@ bool Image::loaded() { ...@@ -23,7 +23,7 @@ bool Image::loaded() {
bool Image::loadFromRW(SDL_RWops* rw) { bool Image::loadFromRW(SDL_RWops* rw) {
surface = STBIMG_Load_RW(rw, 1); surface = STBIMG_Load_RW(rw, 1);
if (!surface) { if (!loaded()) {
const char* errorChar = SDL_GetError(); const char* errorChar = SDL_GetError();
std::string errString(""); std::string errString("");
if (errorChar != NULL) { if (errorChar != NULL) {
...@@ -44,8 +44,8 @@ bool Image::loadFromRW(SDL_RWops* rw) { ...@@ -44,8 +44,8 @@ bool Image::loadFromRW(SDL_RWops* rw) {
optimizedImage = SDL_DisplayFormat(surface); optimizedImage = SDL_DisplayFormat(surface);
} }
if (!optimizedImage) { if (optimizedImage == NULL) {
std::cout << "[ChaiLove] [graphics] SDL_DisplayFormat failed to optimize the image." << std::endl; std::cout << "[ChaiLove] [graphics] Warning: SDL_DisplayFormat failed to optimize the image." << std::endl;
} else { } else {
SDL_FreeSurface(surface); SDL_FreeSurface(surface);
surface = optimizedImage; surface = optimizedImage;
...@@ -54,7 +54,7 @@ bool Image::loadFromRW(SDL_RWops* rw) { ...@@ -54,7 +54,7 @@ bool Image::loadFromRW(SDL_RWops* rw) {
} }
bool Image::destroy() { bool Image::destroy() {
if (!surface) { if (loaded()) {
SDL_FreeSurface(surface); SDL_FreeSurface(surface);
surface = NULL; surface = NULL;
} }
...@@ -71,14 +71,14 @@ Image::Image(const std::string& filename) { ...@@ -71,14 +71,14 @@ Image::Image(const std::string& filename) {
} }
int Image::getWidth() { int Image::getWidth() {
if (surface != NULL) { if (loaded()) {
return surface->w; return surface->w;
} }
return 0; return 0;
} }
int Image::getHeight() { int Image::getHeight() {
if (surface != NULL) { if (loaded()) {
return surface->h; return surface->h;
} }
return 0; return 0;
......
...@@ -11,35 +11,22 @@ std::string Joystick::getName() { ...@@ -11,35 +11,22 @@ std::string Joystick::getName() {
return name; return name;
} }
/* Joystick::Joystick() {
Joystick::Joystick(SDL_Joystick* joystick) { clearStates();
joy = joystick;
}
*/
/*
Joystick::Joystick(int num, SDL_Joystick* joystick) {
index = index;
joy = joystick;
}
*/
bool Joystick::isOpen() {
return true;
} }
Joystick::Joystick() { Joystick::Joystick(int i) : m_index(i) {
name = "RetroPad"; clearStates();
index = 0;
} }
Joystick::Joystick(int i) { void Joystick::clearStates() {
index = i; for (int i = 0; i < 14; i++) {
name = "RetroPad"; m_state[i] = 0;
}
} }
bool Joystick::isDown(int button) { bool Joystick::isDown(int button) {
return static_cast<bool>(ChaiLove::getInstance()->joystick.joystick_cache[index][button]); return static_cast<bool>(m_state[button]);
} }
bool Joystick::isDown(const std::string& button) { bool Joystick::isDown(const std::string& button) {
...@@ -47,8 +34,37 @@ bool Joystick::isDown(const std::string& button) { ...@@ -47,8 +34,37 @@ bool Joystick::isDown(const std::string& button) {
return isDown(key); return isDown(key);
} }