mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-25 17:53:47 +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->setVoicePath2(path + "audio/");
|
||||
|
|
|
@ -69,6 +69,12 @@ void UserSettings::save()
|
|||
xml_grabInp->SetAttribute("on", system.grabInput);
|
||||
}
|
||||
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);
|
||||
|
||||
|
@ -385,6 +391,12 @@ bool UserSettings::load(bool doApply, const std::string &overrideFile)
|
|||
{
|
||||
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");
|
||||
|
|
|
@ -37,12 +37,13 @@ class UserSettings
|
|||
public:
|
||||
struct System
|
||||
{
|
||||
System() { debugLogOn = 0; devModeOn = 0; allowDangerousScriptFunctions = 0; grabInput=1; }
|
||||
System() { debugLogOn = 0; devModeOn = 0; allowDangerousScriptFunctions = 0; grabInput=1; hotreload=0; }
|
||||
int debugLogOn;
|
||||
std::string locale;
|
||||
int devModeOn;
|
||||
int allowDangerousScriptFunctions;
|
||||
int grabInput;
|
||||
int hotreload;
|
||||
} system;
|
||||
|
||||
struct Audio
|
||||
|
|
|
@ -260,6 +260,25 @@ bool exists(const std::string &f, bool makeFatal, bool skipVFS)
|
|||
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()
|
||||
|
|
|
@ -138,6 +138,7 @@ void stringToLower(std::string &s);
|
|||
void stringToLowerUserData(std::string &s);
|
||||
float sqr(float x);
|
||||
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 debugLog(const std::string &s);
|
||||
|
||||
|
|
|
@ -1,15 +1,27 @@
|
|||
|
||||
|
||||
#include "DirWatcher.h"
|
||||
#include <string>
|
||||
#include <assert.h>
|
||||
#include <sstream>
|
||||
|
||||
#ifdef AQUARIA_ENABLE_DIR_WATCH
|
||||
|
||||
#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"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
namespace DirWatcher {
|
||||
|
||||
|
||||
|
||||
#ifdef AQUARIA_ENABLE_DIR_WATCH
|
||||
|
||||
struct WatchEntry
|
||||
{
|
||||
|
@ -32,15 +44,25 @@ static std::vector<WatchEntry> s_watches;
|
|||
static std::vector<Pending> s_pending, s_processing;
|
||||
static SDL_mutex *s_mtx;
|
||||
|
||||
#endif
|
||||
|
||||
bool Init()
|
||||
{
|
||||
#ifdef AQUARIA_ENABLE_DIR_WATCH
|
||||
debugLog("DirWatcher: Init");
|
||||
assert(!s_mtx);
|
||||
s_mtx = SDL_CreateMutex();
|
||||
dmon_init();
|
||||
return true;
|
||||
#else
|
||||
debugLog("DirWatcher: Not enabled at compile time. Function not available.");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
{
|
||||
#ifdef AQUARIA_ENABLE_DIR_WATCH
|
||||
if(!s_mtx)
|
||||
return;
|
||||
for(size_t i = 0; i < s_watches.size(); ++i)
|
||||
|
@ -51,10 +73,12 @@ void Shutdown()
|
|||
dmon_deinit();
|
||||
SDL_DestroyMutex(s_mtx);
|
||||
s_mtx = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Pump()
|
||||
{
|
||||
#ifdef AQUARIA_ENABLE_DIR_WATCH
|
||||
if(!s_mtx)
|
||||
return;
|
||||
|
||||
|
@ -103,6 +127,7 @@ void Pump()
|
|||
s_processing.clear();
|
||||
|
||||
debugLog("... callbacks done.");
|
||||
#endif
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
#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();
|
||||
if(!N && !s_mtx)
|
||||
if(!Init())
|
||||
|
@ -160,6 +192,8 @@ size_t AddWatch(const char* path, Flags flags, Callback cb, void* ud)
|
|||
if(flags & 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);
|
||||
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;
|
||||
return idx + 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void RemoveWatch(size_t idx)
|
||||
{
|
||||
#ifdef AQUARIA_ENABLE_DIR_WATCH
|
||||
if(!idx)
|
||||
return;
|
||||
--idx;
|
||||
|
||||
assert(s_watches[idx].valid);
|
||||
debugLog("DirWatcher: Remove watch: " + s_watches[idx].path);
|
||||
|
||||
dmon_unwatch(s_watches[idx].watch);
|
||||
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)
|
||||
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_link_options(-fsanitize=address)
|
||||
|
||||
|
@ -136,6 +138,10 @@ if(AQUARIA_DEBUG_SHOW_PATHS)
|
|||
ADD_DEFINITIONS(-DAQUARIA_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
|
||||
include_directories(ttvfs_cfileapi)
|
||||
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_NO_STDIO
|
||||
#include "qoi.h"
|
||||
|
||||
#define DMON_IMPL
|
||||
#define DMON_SLEEP_INTERVAL 250
|
||||
#include "dmon.h"
|
||||
|
|
Loading…
Reference in a new issue