From 391af170b617b6c7a3f21904c7d344326959842c Mon Sep 17 00:00:00 2001 From: Robear Selwans Date: Wed, 9 Jun 2021 09:21:34 +0200 Subject: [PATCH] Added mount watching Signed-off-by: Robear Selwans --- meson.build | 3 ++- meta/evmod.namespaces | 4 ++++ src/mod.c | 46 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index d90383f..e0639f1 100644 --- a/meson.build +++ b/meson.build @@ -30,8 +30,9 @@ mod_deps = [ evmod_deps, dependency('threads'), - dependency('assetsys'), + dependency('cute_filewatch'), + dependency('evmod_ecs'), ] diff --git a/meta/evmod.namespaces b/meta/evmod.namespaces index e33a1c4..1979a94 100644 --- a/meta/evmod.namespaces +++ b/meta/evmod.namespaces @@ -7,6 +7,10 @@ EV_NS_DEF_END(Asset) EV_NS_DEF_BEGIN(AssetManager) EV_NS_DEF_FN(void, mount, (evstring *, path), (evstring *, as)) +EV_NS_DEF_FN(void, update, (,)) +EV_NS_DEF_FN(void, watch, (CONST_STR, path), (FN_PTR, callback)) +EV_NS_DEF_FN(void, watchRecursively, (CONST_STR, path), (FN_PTR, callback)) +EV_NS_DEF_FN(void, stopWatching, (CONST_STR, path)) EV_NS_DEF_END(AssetManager) /* #include LOADERS_NAMESPACES_H */ diff --git a/src/mod.c b/src/mod.c index b8911b7..63ec6bc 100644 --- a/src/mod.c +++ b/src/mod.c @@ -1,6 +1,8 @@ #define EV_MODULE_DEFINE #include #include +#include + #include #define IMPORT_MODULE evmod_ecs @@ -21,12 +23,15 @@ struct { assetsys_t *sys; + filewatch_t *fwatch; evolmodule_t ecs_mod; ECSAssetWorldHandle world; AssetComponentID assetcomponent_id; -} AssetManagerData = {NULL}; +} AssetManagerData = { + NULL, NULL, NULL, + 0, 0}; void onRemoveAssetComponent( @@ -85,6 +90,7 @@ EV_CONSTRUCTOR static_assert(sizeof(AssetEntityID) == sizeof(AssetHandle), "AssetEntityID not the same size of AssetHandle"); AssetManagerData.sys = assetsys_create( 0 ); + AssetManagerData.fwatch = filewatch_create(AssetManagerData.sys, NULL); AssetManagerData.ecs_mod = evol_loadmodule("ecs"); if(AssetManagerData.ecs_mod) { @@ -117,6 +123,7 @@ EV_CONSTRUCTOR EV_DESTRUCTOR { + filewatch_free(AssetManagerData.fwatch); assetsys_destroy(AssetManagerData.sys); if(AssetManagerData.world) { @@ -179,7 +186,31 @@ ev_assetmanager_mount( evstring *as) { evstring_pushstr(as, ":/"); - AssetSysCheck("Failed to mount %s as %s. ", (*path, *as), assetsys_mount(AssetManagerData.sys, *path, *as)); + /* AssetSysCheck("Failed to mount %s as %s. ", (*path, *as), assetsys_mount(AssetManagerData.sys, *path, *as)); */ + filewatch_mount(AssetManagerData.fwatch, *path, *as); +} + +void +ev_assetmanager_watch( + const char *path, + FN_PTR callback) +{ + filewatch_start_watching(AssetManagerData.fwatch, path, callback, NULL, 0); +} + +void +ev_assetmanager_watchrecursively( + const char *path, + FN_PTR callback) +{ + filewatch_start_watching(AssetManagerData.fwatch, path, callback, NULL, 1); +} + +void +ev_assetmanager_stopwatching( + const char *path) +{ + filewatch_stop_watching(AssetManagerData.fwatch, path); } const Asset * @@ -198,10 +229,21 @@ ev_asset_markas( AssetECS->setComponent(AssetManagerData.world, handle, assetType, data); } +void +ev_assetmanager_update() +{ + filewatch_update(AssetManagerData.fwatch); + filewatch_notify(AssetManagerData.fwatch); +} + EV_BINDINGS { ev_log_debug("Binding functions in evmod_asset"); EV_NS_BIND_FN(AssetManager, mount, ev_assetmanager_mount); + EV_NS_BIND_FN(AssetManager, watch, ev_assetmanager_watch); + EV_NS_BIND_FN(AssetManager, watchRecursively, ev_assetmanager_watchrecursively); + EV_NS_BIND_FN(AssetManager, stopWatching, ev_assetmanager_stopwatching); + EV_NS_BIND_FN(AssetManager, update, ev_assetmanager_update); EV_NS_BIND_FN(Asset, load, ev_asset_load); EV_NS_BIND_FN(Asset, cloneHandle, ev_asset_clonehandle);