Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Reshuffle lua loading into a modpack loading system, separate from th… #1708

Open
wants to merge 3 commits into
base: alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ ant.properties
.externalNativeBuild
gradle.properties
shell/android-studio/reicast/src/main/assets/build

# CMake
/CMakeFiles
/reicast.dir
/ALL_BUILD.*
/ZERO_CHECK.*
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ configure_file(${reicast_core_path}/version.h.in ${reicast_core_path}/version.h




## reicast build modules #
#

Expand All @@ -53,9 +52,9 @@ file(GLOB imgread_SRCS ${d_core}/imgread/*.cpp ${d_core}/imgread/*.h)
file(GLOB profiler_SRCS ${d_core}/profiler/*.cpp ${d_core}/profiler/*.h)
file(GLOB archive_SRCS ${d_core}/archive/*.cpp ${d_core}/archive/*.h)
file(GLOB glwrap_SRCS ${d_core}/glwrap/*.cpp ${d_core}/glwrap/*.h)
file(GLOB scripting_SRCS ${d_core}/scripting/*.cpp ${d_core}/scripting/*.h)
file(GLOB utils_SRCS ${d_core}/utils/*.cpp ${d_core}/utils/*.h)
file(GLOB gui_SRCS ${d_core}/gui/*.cpp ${d_core}/gui/*.h)
file(GLOB mods_SRCS ${d_core}/mods/*.cpp ${d_core}/mods/*.h)
file(GLOB utils_SRCS ${d_core}/utils/*.cpp ${d_core}/utils/*.h)
file(GLOB gui_SRCS ${d_core}/gui/*.cpp ${d_core}/gui/*.h)
file(GLOB wgl_SRCS ${d_core}/utils/glinit/wgl/*.cpp )

#### option(rend)
Expand All @@ -79,7 +78,7 @@ set(core_SRCS
${reios_SRCS}
${imgread_SRCS}
${profiler_SRCS}
${scripting_SRCS}
${mods_SRCS}
${utils_SRCS}
${gui_SRCS}
${wgl_SRCS}
Expand Down
5 changes: 2 additions & 3 deletions libswirl/core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ RZDCY_MODULES := cfg/ hw/arm7/ hw/aica/ hw/holly/ hw/ hw/gdrom/ hw/maple/ \
hw/mem/ hw/pvr/ hw/sh4/ hw/sh4/interpr/ hw/sh4/modules/ plugins/ profiler/ oslib/ \
hw/extdev/ hw/arm/ hw/naomi/ imgread/ ./ deps/coreio/ deps/zlib/ deps/chdr/ deps/crypto/ \
deps/libelf/ deps/cdipsr/ arm_emitter/ rend/ reios/ deps/libpng/ deps/xbrz/ \
deps/xxhash/ deps/libzip/ deps/imgui/ archive/ input/ glwrap/ utils/ gui/

deps/xxhash/ deps/libzip/ deps/imgui/ archive/ input/ glwrap/ utils/ gui/ mods/
ifdef SCRIPTING
RZDCY_MODULES += scripting/
RZDCY_MODULES += deps/lua/
endif

Expand Down
4 changes: 2 additions & 2 deletions libswirl/hw/pvr/Renderer_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "deps/crypto/md5.h"

#include "scripting/lua_bindings.h"
#include "mods/mods.h"

#if FEAT_HAS_NIXPROF
#include "profiler/profiler.h"
Expand Down Expand Up @@ -282,7 +282,7 @@ bool rend_single_frame()
// FIXME not here
os_DoEvents();

luabindings_onframe();
modpack_onframe();

#if !defined(TARGET_NO_THREADS)
if (gui_is_open() || gui_state == VJoyEdit)
Expand Down
19 changes: 6 additions & 13 deletions libswirl/libswirl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@
#include "profiler/profiler.h"
#include "input/gamepad_device.h"
#include "rend/TexCache.h"
#include "mods/mods.h"

#define fault_printf(...)

#ifdef SCRIPTING
#include "scripting/lua_bindings.h"
#endif

void FlushCache();
void LoadCustom();

Expand Down Expand Up @@ -403,6 +400,8 @@ int dc_start_game(const char *path)
#endif
init_done = true;

modpack_gamestart();

dc_reset();

game_started = true;
Expand All @@ -425,9 +424,7 @@ void* dc_run(void*)

InitAudio();

#ifdef SCRIPTING
luabindings_onstart();
#endif
modpack_onstart();

if (settings.dynarec.Enable)
{
Expand All @@ -448,15 +445,11 @@ void* dc_run(void*)
if (reset_requested)
{
dc_reset();
#ifdef SCRIPTING
luabindings_onreset();
#endif
modpack_onreset();
}
} while (reset_requested);

#ifdef SCRIPTING
luabindings_onstop();
#endif
modpack_onstop();

TermAudio();

Expand Down
166 changes: 166 additions & 0 deletions libswirl/mods/CustomTexture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*
Copyright 2018 flyinghead

This file is part of reicast.

reicast 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.

reicast 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 reicast. If not, see <https://www.gnu.org/licenses/>.
*/
#include "CustomTexture.h"

#include <algorithm>
#include <sstream>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef _MSC_VER
#include "dirent/dirent.h"
#else
#include <dirent.h>
#endif

#include "deps/libpng/png.h"
#include "reios/reios.h"

#include "hw/pvr/Renderer_if.h"

#include "mods/mods.h"

void CustomTexture::LoaderThread()
{
while (initialized)
{
TextureCacheData *texture;

do {
texture = NULL;

work_queue_mutex.Lock();
if (!work_queue.empty())
{
texture = work_queue.back();
work_queue.pop_back();
}
work_queue_mutex.Unlock();

if (texture != NULL)
{
texture->ComputeHash();
if (texture->custom_image_data != NULL)
{
delete [] texture->custom_image_data;
texture->custom_image_data = NULL;
}
if (!texture->dirty)
{
int width, height;
u8 *image_data = LoadCustomTexture(texture->texture_hash, width, height);
if (image_data == NULL)
{
image_data = LoadCustomTexture(texture->old_texture_hash, width, height);
}
if (image_data != NULL)
{
texture->custom_width = width;
texture->custom_height = height;
texture->custom_image_data = image_data;
}
}
texture->custom_load_in_progress--;
}

} while (texture != NULL);

wakeup_thread.Wait();
}
}

bool CustomTexture::Init(std::string path)
{
if (!initialized)
{
initialized = true;
custom_textures_available = false;
#ifndef TARGET_NO_THREADS
textures_path = path + "/textures";

DIR* dir = opendir(textures_path.c_str());
if (dir != NULL)
{
printf("Found custom textures directory: %s\n", textures_path.c_str());
custom_textures_available = true;
closedir(dir);
loader_thread.Start();
}
#endif
}
return custom_textures_available;
}

void CustomTexture::Terminate()
{
if (initialized)
{
initialized = false;
custom_textures_available = false;
work_queue_mutex.Lock();
work_queue.clear();
work_queue_mutex.Unlock();
wakeup_thread.Set();
#ifndef TARGET_NO_THREADS
loader_thread.WaitToEnd();
#endif
}
}

u8* CustomTexture::LoadCustomTexture(u32 hash, int& width, int& height)
{
if (unknown_hashes.find(hash) != unknown_hashes.end())
return NULL;
std::stringstream path;
path << textures_path << std::hex << hash << ".png";

u8 *image_data = loadPNGData(path.str(), width, height);
if (image_data == NULL)
unknown_hashes.insert(hash);

return image_data;
}

void CustomTexture::LoadCustomTextureAsync(TextureCacheData *texture_data)
{
if (!custom_textures_available)
return;

texture_data->custom_load_in_progress++;
work_queue_mutex.Lock();
work_queue.insert(work_queue.begin(), texture_data);
work_queue_mutex.Unlock();
wakeup_thread.Set();
}

CustomTexture custom_texture;

static bool customtexture_detect(std::string path) {
return custom_texture.Init(path);
}

static void customtexture_close() {
custom_texture.Terminate();
}

static mod_handlers customtexturemod = {
customtexture_detect,
customtexture_close,
nullptr
};
static bool registered = mod_handler_register(customtexturemod);
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

#include <string>
#include <set>
#include "gles.h"
#include "types.h"
#include "rend/gles/gles.h"

class CustomTexture {
public:
Expand All @@ -35,13 +36,12 @@ class CustomTexture {
~CustomTexture() { Terminate(); }
u8* LoadCustomTexture(u32 hash, int& width, int& height);
void LoadCustomTextureAsync(TextureCacheData *texture_data);
void DumpTexture(u32 hash, int w, int h, GLuint textype, void *temp_tex_buffer);

private:
bool Init();
bool Init(std::string path);
void Terminate();

private:
void LoaderThread();
std::string GetGameId();

static void *loader_thread_func(void *param) { ((CustomTexture *)param)->LoaderThread(); return NULL; }

Expand All @@ -57,4 +57,6 @@ class CustomTexture {
cMutex work_queue_mutex;
};

extern CustomTexture custom_texture;

#endif /* CORE_REND_GLES_CUSTOMTEXTURE_H_ */
7 changes: 7 additions & 0 deletions libswirl/mods/lua_bindings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include "lua/lua.hpp"
#include <string>

void emulib_expose(lua_State* L);

Loading