/* ** core.cpp ** ** This file is part of mkxp. ** ** Copyright (C) 2013 - 2021 Amaryllis Kulla ** ** mkxp is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 2 of the License, or ** (at your option) any later version. ** ** mkxp is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with mkxp. If not, see . */ #include #include #include #include #include #include #include "mkxp-polyfill.h" #include #include #include #include "git-hash.h" #include "sandbox.h" #include "binding-sandbox.h" #include "core.h" #include "filesystem.h" #include "gl-fun.h" #include "glstate.h" #include "sharedmidistate.h" #include "eventthread.h" using namespace mkxp_retro; using namespace mkxp_sandbox; static uint64_t frame_count; extern const uint8_t mkxp_retro_dist_zip[]; extern const size_t mkxp_retro_dist_zip_len; static bool initialized = false; static ALCdevice *al_device = NULL; static ALCcontext *al_context = NULL; static LPALCRENDERSAMPLESSOFT alcRenderSamplesSOFT = NULL; static LPALCLOOPBACKOPENDEVICESOFT alcLoopbackOpenDeviceSOFT = NULL; static uint32_t frame_rate; static uint32_t frame_rate_remainder; static uint32_t samples_per_frame; static uint32_t samples_per_frame_remainder; static int16_t *sound_buf = NULL; static bool retro_framebuffer_supported; static bool shared_state_initialized; static PHYSFS_File *rgssad = NULL; static retro_system_av_info av_info; namespace mkxp_retro { retro_log_printf_t log_printf; retro_video_refresh_t video_refresh; retro_audio_sample_batch_t audio_sample_batch; retro_environment_t environment; retro_input_poll_t input_poll; retro_input_state_t input_state; struct retro_perf_callback perf; retro_hw_render_callback hw_render; uint64_t get_ticks() noexcept { return (frame_count * 1000) / shState->graphics().getFrameRate(); } } static void fallback_log(enum retro_log_level level, const char *fmt, ...) { std::va_list va; va_start(va, fmt); std::vfprintf(stderr, fmt, va); va_end(va); } static void fluid_log(int level, const char *message, void *data) { switch (level) { case FLUID_PANIC: log_printf(RETRO_LOG_ERROR, "fluidsynth: panic: %s\n", message); break; case FLUID_ERR: log_printf(RETRO_LOG_ERROR, "fluidsynth: error: %s\n", message); break; case FLUID_WARN: log_printf(RETRO_LOG_WARN, "fluidsynth: warning: %s\n", message); break; case FLUID_INFO: log_printf(RETRO_LOG_INFO, "fluidsynth: %s\n", message); break; case FLUID_DBG: log_printf(RETRO_LOG_DEBUG, "fluidsynth: debug: %s\n", message); break; } } static uint32_t *frame_buf; boost::optional mkxp_retro::sandbox; boost::optional