mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-07-03 22:44:32 +00:00
make dmon optional at compile time, and a dedicated runtime option
it's still experimental and might cause problems, so only enable this if specifically requested, since it's not needed for regular gameplay
This commit is contained in:
parent
5895703ac4
commit
f71c7f5d40
8 changed files with 82 additions and 7 deletions
|
@ -150,7 +150,8 @@ void Mod::load(const std::string &p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dsq->setExtraTexturePath((path + "graphics/").c_str(), dsq->isDeveloperKeys());
|
bool hotReload = dsq->user.system.hotreload;
|
||||||
|
dsq->setExtraTexturePath((path + "graphics/").c_str(), hotReload);
|
||||||
|
|
||||||
dsq->sound->audioPath2 = path + "audio/";
|
dsq->sound->audioPath2 = path + "audio/";
|
||||||
dsq->sound->setVoicePath2(path + "audio/");
|
dsq->sound->setVoicePath2(path + "audio/");
|
||||||
|
|
|
@ -69,6 +69,12 @@ void UserSettings::save()
|
||||||
xml_grabInp->SetAttribute("on", system.grabInput);
|
xml_grabInp->SetAttribute("on", system.grabInput);
|
||||||
}
|
}
|
||||||
xml_system->InsertEndChild(xml_grabInp);
|
xml_system->InsertEndChild(xml_grabInp);
|
||||||
|
|
||||||
|
XMLElement *xml_hotreload = doc.NewElement("HotReloadModGraphics");
|
||||||
|
{
|
||||||
|
xml_hotreload->SetAttribute("on", system.hotreload);
|
||||||
|
}
|
||||||
|
xml_system->InsertEndChild(xml_hotreload);
|
||||||
}
|
}
|
||||||
doc.InsertEndChild(xml_system);
|
doc.InsertEndChild(xml_system);
|
||||||
|
|
||||||
|
@ -385,6 +391,12 @@ bool UserSettings::load(bool doApply, const std::string &overrideFile)
|
||||||
{
|
{
|
||||||
system.grabInput = xml_grabInp->IntAttribute("on");
|
system.grabInput = xml_grabInp->IntAttribute("on");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XMLElement *xml_hotreload = xml_system->FirstChildElement("HotReloadModGraphics");
|
||||||
|
if (xml_hotreload)
|
||||||
|
{
|
||||||
|
system.hotreload = xml_hotreload->IntAttribute("on");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XMLElement *xml_audio = doc.FirstChildElement("Audio");
|
XMLElement *xml_audio = doc.FirstChildElement("Audio");
|
||||||
|
|
|
@ -37,12 +37,13 @@ class UserSettings
|
||||||
public:
|
public:
|
||||||
struct System
|
struct System
|
||||||
{
|
{
|
||||||
System() { debugLogOn = 0; devModeOn = 0; allowDangerousScriptFunctions = 0; grabInput=1; }
|
System() { debugLogOn = 0; devModeOn = 0; allowDangerousScriptFunctions = 0; grabInput=1; hotreload=0; }
|
||||||
int debugLogOn;
|
int debugLogOn;
|
||||||
std::string locale;
|
std::string locale;
|
||||||
int devModeOn;
|
int devModeOn;
|
||||||
int allowDangerousScriptFunctions;
|
int allowDangerousScriptFunctions;
|
||||||
int grabInput;
|
int grabInput;
|
||||||
|
int hotreload;
|
||||||
} system;
|
} system;
|
||||||
|
|
||||||
struct Audio
|
struct Audio
|
||||||
|
|
|
@ -260,6 +260,25 @@ bool exists(const std::string &f, bool makeFatal, bool skipVFS)
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool dirExistsOnDisk(const std::string &f)
|
||||||
|
{
|
||||||
|
#ifdef BBGE_BUILD_VFS
|
||||||
|
return ttvfs::IsDirectory(f.c_str());
|
||||||
|
#elif _WIN32
|
||||||
|
DWORD dwFileAttr = GetFileAttributesA(s);
|
||||||
|
if(dwFileAttr == INVALID_FILE_ATTRIBUTES)
|
||||||
|
return false;
|
||||||
|
return !!(dwFileAttr & FILE_ATTRIBUTE_DIRECTORY);
|
||||||
|
#else
|
||||||
|
if (!access(s, 0))
|
||||||
|
{
|
||||||
|
struct stat status;
|
||||||
|
stat( s, &status );
|
||||||
|
return status.st_mode & S_IFDIR;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string getPathInfoStr()
|
std::string getPathInfoStr()
|
||||||
|
|
|
@ -138,6 +138,7 @@ void stringToLower(std::string &s);
|
||||||
void stringToLowerUserData(std::string &s);
|
void stringToLowerUserData(std::string &s);
|
||||||
float sqr(float x);
|
float sqr(float x);
|
||||||
bool exists(const std::string &f, bool makeFatal = false, bool skipVFS = false);
|
bool exists(const std::string &f, bool makeFatal = false, bool skipVFS = false);
|
||||||
|
bool dirExistsOnDisk(const std::string &f);
|
||||||
void errorLog(const std::string &s);
|
void errorLog(const std::string &s);
|
||||||
void debugLog(const std::string &s);
|
void debugLog(const std::string &s);
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,27 @@
|
||||||
|
|
||||||
|
|
||||||
#include "DirWatcher.h"
|
#include "DirWatcher.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#ifdef AQUARIA_ENABLE_DIR_WATCH
|
||||||
|
|
||||||
#include <SDL_mutex.h>
|
#include <SDL_mutex.h>
|
||||||
|
|
||||||
|
#define DMON_IMPL
|
||||||
|
#define DMON_SLEEP_INTERVAL 250
|
||||||
|
#define DMON_LOG_DEBUG(s) debugLog(s)
|
||||||
|
#define DMON_LOG_ERROR(s) debugLog(s) // no, dmon, you're not allowed to abort() when a directory doesn't exist. grrr.
|
||||||
#include "dmon.h"
|
#include "dmon.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace DirWatcher {
|
namespace DirWatcher {
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef AQUARIA_ENABLE_DIR_WATCH
|
||||||
|
|
||||||
struct WatchEntry
|
struct WatchEntry
|
||||||
{
|
{
|
||||||
|
@ -32,15 +44,25 @@ static std::vector<WatchEntry> s_watches;
|
||||||
static std::vector<Pending> s_pending, s_processing;
|
static std::vector<Pending> s_pending, s_processing;
|
||||||
static SDL_mutex *s_mtx;
|
static SDL_mutex *s_mtx;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
bool Init()
|
bool Init()
|
||||||
{
|
{
|
||||||
|
#ifdef AQUARIA_ENABLE_DIR_WATCH
|
||||||
|
debugLog("DirWatcher: Init");
|
||||||
|
assert(!s_mtx);
|
||||||
s_mtx = SDL_CreateMutex();
|
s_mtx = SDL_CreateMutex();
|
||||||
dmon_init();
|
dmon_init();
|
||||||
return true;
|
return true;
|
||||||
|
#else
|
||||||
|
debugLog("DirWatcher: Not enabled at compile time. Function not available.");
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown()
|
void Shutdown()
|
||||||
{
|
{
|
||||||
|
#ifdef AQUARIA_ENABLE_DIR_WATCH
|
||||||
if(!s_mtx)
|
if(!s_mtx)
|
||||||
return;
|
return;
|
||||||
for(size_t i = 0; i < s_watches.size(); ++i)
|
for(size_t i = 0; i < s_watches.size(); ++i)
|
||||||
|
@ -51,10 +73,12 @@ void Shutdown()
|
||||||
dmon_deinit();
|
dmon_deinit();
|
||||||
SDL_DestroyMutex(s_mtx);
|
SDL_DestroyMutex(s_mtx);
|
||||||
s_mtx = NULL;
|
s_mtx = NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pump()
|
void Pump()
|
||||||
{
|
{
|
||||||
|
#ifdef AQUARIA_ENABLE_DIR_WATCH
|
||||||
if(!s_mtx)
|
if(!s_mtx)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -103,6 +127,7 @@ void Pump()
|
||||||
s_processing.clear();
|
s_processing.clear();
|
||||||
|
|
||||||
debugLog("... callbacks done.");
|
debugLog("... callbacks done.");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _watch_cb(dmon_watch_id watch_id, dmon_action action,
|
static void _watch_cb(dmon_watch_id watch_id, dmon_action action,
|
||||||
|
@ -135,6 +160,13 @@ static void _watch_cb(dmon_watch_id watch_id, dmon_action action,
|
||||||
|
|
||||||
size_t AddWatch(const char* path, Flags flags, Callback cb, void* ud)
|
size_t AddWatch(const char* path, Flags flags, Callback cb, void* ud)
|
||||||
{
|
{
|
||||||
|
#ifdef AQUARIA_ENABLE_DIR_WATCH
|
||||||
|
if(!dirExistsOnDisk(path))
|
||||||
|
{
|
||||||
|
debugLog(std::string("DirWatcher: Path does not exist, ignoring: ") + path);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const size_t N = s_watches.size();
|
const size_t N = s_watches.size();
|
||||||
if(!N && !s_mtx)
|
if(!N && !s_mtx)
|
||||||
if(!Init())
|
if(!Init())
|
||||||
|
@ -160,6 +192,8 @@ size_t AddWatch(const char* path, Flags flags, Callback cb, void* ud)
|
||||||
if(flags & RECURSIVE)
|
if(flags & RECURSIVE)
|
||||||
flg = DMON_WATCHFLAGS_RECURSIVE;
|
flg = DMON_WATCHFLAGS_RECURSIVE;
|
||||||
|
|
||||||
|
debugLog(std::string("DirWatcher: Add watch: ") + path);
|
||||||
|
|
||||||
s_watches[idx].watch = dmon_watch(path, _watch_cb, (dmon_watch_flags_t)flg, (void*)(uintptr_t)idx);
|
s_watches[idx].watch = dmon_watch(path, _watch_cb, (dmon_watch_flags_t)flg, (void*)(uintptr_t)idx);
|
||||||
if(!s_watches[idx].watch.id)
|
if(!s_watches[idx].watch.id)
|
||||||
{
|
{
|
||||||
|
@ -170,17 +204,22 @@ size_t AddWatch(const char* path, Flags flags, Callback cb, void* ud)
|
||||||
}
|
}
|
||||||
s_watches[idx].valid = true;
|
s_watches[idx].valid = true;
|
||||||
return idx + 1;
|
return idx + 1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveWatch(size_t idx)
|
void RemoveWatch(size_t idx)
|
||||||
{
|
{
|
||||||
|
#ifdef AQUARIA_ENABLE_DIR_WATCH
|
||||||
if(!idx)
|
if(!idx)
|
||||||
return;
|
return;
|
||||||
--idx;
|
--idx;
|
||||||
|
|
||||||
assert(s_watches[idx].valid);
|
assert(s_watches[idx].valid);
|
||||||
|
debugLog("DirWatcher: Remove watch: " + s_watches[idx].path);
|
||||||
|
|
||||||
dmon_unwatch(s_watches[idx].watch);
|
dmon_unwatch(s_watches[idx].watch);
|
||||||
s_watches[idx].valid = false;
|
s_watches[idx].valid = false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,8 @@ OPTION(AQUARIA_USE_GLM "Use GLM for matrix math" TRUE)
|
||||||
OPTION(AQUARIA_DEBUG_SHOW_PATHS "Show important paths upon game start to aid in finding path problems" FALSE)
|
OPTION(AQUARIA_DEBUG_SHOW_PATHS "Show important paths upon game start to aid in finding path problems" FALSE)
|
||||||
mark_as_advanced(AQUARIA_DEBUG_SHOW_PATHS)
|
mark_as_advanced(AQUARIA_DEBUG_SHOW_PATHS)
|
||||||
|
|
||||||
|
OPTION(AQUARIA_ENABLE_DIR_WATCH "Enable directory watcher component to hot-reload textures in mods. Must be enabled in the game config to be active." TRUE)
|
||||||
|
|
||||||
#add_compile_options(-fsanitize=address)
|
#add_compile_options(-fsanitize=address)
|
||||||
#add_link_options(-fsanitize=address)
|
#add_link_options(-fsanitize=address)
|
||||||
|
|
||||||
|
@ -136,6 +138,10 @@ if(AQUARIA_DEBUG_SHOW_PATHS)
|
||||||
ADD_DEFINITIONS(-DAQUARIA_DEBUG_SHOW_PATHS)
|
ADD_DEFINITIONS(-DAQUARIA_DEBUG_SHOW_PATHS)
|
||||||
endif(AQUARIA_DEBUG_SHOW_PATHS)
|
endif(AQUARIA_DEBUG_SHOW_PATHS)
|
||||||
|
|
||||||
|
if(AQUARIA_ENABLE_DIR_WATCH)
|
||||||
|
ADD_DEFINITIONS(-DAQUARIA_ENABLE_DIR_WATCH)
|
||||||
|
endif(AQUARIA_ENABLE_DIR_WATCH)
|
||||||
|
|
||||||
# Without #define VFS_ENABLE_C_API this is just stubbed out
|
# Without #define VFS_ENABLE_C_API this is just stubbed out
|
||||||
include_directories(ttvfs_cfileapi)
|
include_directories(ttvfs_cfileapi)
|
||||||
if(AQUARIA_USE_VFS)
|
if(AQUARIA_USE_VFS)
|
||||||
|
|
|
@ -37,7 +37,3 @@ static unsigned char * miniz_stbi_compress(unsigned char *data, int data_len, in
|
||||||
#define QOI_IMPLEMENTATION
|
#define QOI_IMPLEMENTATION
|
||||||
#define QOI_NO_STDIO
|
#define QOI_NO_STDIO
|
||||||
#include "qoi.h"
|
#include "qoi.h"
|
||||||
|
|
||||||
#define DMON_IMPL
|
|
||||||
#define DMON_SLEEP_INTERVAL 250
|
|
||||||
#include "dmon.h"
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue