Added mount watching
Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
@@ -30,8 +30,9 @@ mod_deps = [
|
|||||||
evmod_deps,
|
evmod_deps,
|
||||||
|
|
||||||
dependency('threads'),
|
dependency('threads'),
|
||||||
|
|
||||||
dependency('assetsys'),
|
dependency('assetsys'),
|
||||||
|
dependency('cute_filewatch'),
|
||||||
|
|
||||||
dependency('evmod_ecs'),
|
dependency('evmod_ecs'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ EV_NS_DEF_END(Asset)
|
|||||||
|
|
||||||
EV_NS_DEF_BEGIN(AssetManager)
|
EV_NS_DEF_BEGIN(AssetManager)
|
||||||
EV_NS_DEF_FN(void, mount, (evstring *, path), (evstring *, as))
|
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)
|
EV_NS_DEF_END(AssetManager)
|
||||||
|
|
||||||
/* #include LOADERS_NAMESPACES_H */
|
/* #include LOADERS_NAMESPACES_H */
|
||||||
|
|||||||
46
src/mod.c
46
src/mod.c
@@ -1,6 +1,8 @@
|
|||||||
#define EV_MODULE_DEFINE
|
#define EV_MODULE_DEFINE
|
||||||
#include <evol/evolmod.h>
|
#include <evol/evolmod.h>
|
||||||
#include <assetsys/assetsys.h>
|
#include <assetsys/assetsys.h>
|
||||||
|
#include <cute_filewatch.h>
|
||||||
|
|
||||||
#include <evol/utils/aligned_alloc.h>
|
#include <evol/utils/aligned_alloc.h>
|
||||||
|
|
||||||
#define IMPORT_MODULE evmod_ecs
|
#define IMPORT_MODULE evmod_ecs
|
||||||
@@ -21,12 +23,15 @@
|
|||||||
|
|
||||||
struct {
|
struct {
|
||||||
assetsys_t *sys;
|
assetsys_t *sys;
|
||||||
|
filewatch_t *fwatch;
|
||||||
|
|
||||||
evolmodule_t ecs_mod;
|
evolmodule_t ecs_mod;
|
||||||
ECSAssetWorldHandle world;
|
ECSAssetWorldHandle world;
|
||||||
AssetComponentID assetcomponent_id;
|
AssetComponentID assetcomponent_id;
|
||||||
|
|
||||||
} AssetManagerData = {NULL};
|
} AssetManagerData = {
|
||||||
|
NULL, NULL, NULL,
|
||||||
|
0, 0};
|
||||||
|
|
||||||
void
|
void
|
||||||
onRemoveAssetComponent(
|
onRemoveAssetComponent(
|
||||||
@@ -85,6 +90,7 @@ EV_CONSTRUCTOR
|
|||||||
static_assert(sizeof(AssetEntityID) == sizeof(AssetHandle), "AssetEntityID not the same size of AssetHandle");
|
static_assert(sizeof(AssetEntityID) == sizeof(AssetHandle), "AssetEntityID not the same size of AssetHandle");
|
||||||
|
|
||||||
AssetManagerData.sys = assetsys_create( 0 );
|
AssetManagerData.sys = assetsys_create( 0 );
|
||||||
|
AssetManagerData.fwatch = filewatch_create(AssetManagerData.sys, NULL);
|
||||||
|
|
||||||
AssetManagerData.ecs_mod = evol_loadmodule("ecs");
|
AssetManagerData.ecs_mod = evol_loadmodule("ecs");
|
||||||
if(AssetManagerData.ecs_mod) {
|
if(AssetManagerData.ecs_mod) {
|
||||||
@@ -117,6 +123,7 @@ EV_CONSTRUCTOR
|
|||||||
|
|
||||||
EV_DESTRUCTOR
|
EV_DESTRUCTOR
|
||||||
{
|
{
|
||||||
|
filewatch_free(AssetManagerData.fwatch);
|
||||||
assetsys_destroy(AssetManagerData.sys);
|
assetsys_destroy(AssetManagerData.sys);
|
||||||
|
|
||||||
if(AssetManagerData.world) {
|
if(AssetManagerData.world) {
|
||||||
@@ -179,7 +186,31 @@ ev_assetmanager_mount(
|
|||||||
evstring *as)
|
evstring *as)
|
||||||
{
|
{
|
||||||
evstring_pushstr(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 *
|
const Asset *
|
||||||
@@ -198,10 +229,21 @@ ev_asset_markas(
|
|||||||
AssetECS->setComponent(AssetManagerData.world, handle, assetType, data);
|
AssetECS->setComponent(AssetManagerData.world, handle, assetType, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ev_assetmanager_update()
|
||||||
|
{
|
||||||
|
filewatch_update(AssetManagerData.fwatch);
|
||||||
|
filewatch_notify(AssetManagerData.fwatch);
|
||||||
|
}
|
||||||
|
|
||||||
EV_BINDINGS
|
EV_BINDINGS
|
||||||
{
|
{
|
||||||
ev_log_debug("Binding functions in evmod_asset");
|
ev_log_debug("Binding functions in evmod_asset");
|
||||||
EV_NS_BIND_FN(AssetManager, mount, ev_assetmanager_mount);
|
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, load, ev_asset_load);
|
||||||
EV_NS_BIND_FN(Asset, cloneHandle, ev_asset_clonehandle);
|
EV_NS_BIND_FN(Asset, cloneHandle, ev_asset_clonehandle);
|
||||||
|
|||||||
Reference in New Issue
Block a user