From b7a6543c0785e4bc0d4896dbcfb3e991f486665b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Mon, 18 Sep 2023 12:00:16 +0200 Subject: [PATCH] wip asset reload --- demos/art/shadertoys/Mss3WN.fs | 8 ++++---- engine/joint/v4k.h | 7 +++++-- engine/split/v4k_file.c | 7 +++++-- engine/v4k.c | 7 +++++-- workbench/pluginapi.h | 2 ++ workbench/workbench.c | 22 ++++++++++++++-------- 6 files changed, 35 insertions(+), 18 deletions(-) diff --git a/demos/art/shadertoys/Mss3WN.fs b/demos/art/shadertoys/Mss3WN.fs index f77de2a..60a25e2 100644 --- a/demos/art/shadertoys/Mss3WN.fs +++ b/demos/art/shadertoys/Mss3WN.fs @@ -15,16 +15,16 @@ #define occlusion_enabled #define occlusion_quality 4 -//#define occlusion_preview +// #define occlusion_preview #define noise_use_smoothstep -#define light_color vec3(0.1,0.4,0.6) +#define light_color vec3(0.3,0.4,0.6) #define light_direction normalize(vec3(.2,1.0,-0.2)) #define light_speed_modifier 1.0 -#define object_color vec3(0.9,0.1,0.1) -#define object_count 9 +#define object_color vec3(0.93,0.2,0.1) +#define object_count 19 #define object_speed_modifier 1.0 #define render_steps 33 diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index 1560d29..9896071 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -334108,6 +334108,10 @@ const char *vfs_resolve(const char *pathfile) { return pathfile; } +#ifndef VFS_ALWAYS_PACK +#define VFS_ALWAYS_PACK flag("--vfs-always-pack") +#endif + char* vfs_load(const char *pathfile, int *size_out) { // @todo: fix leaks, vfs_unpack() // @fixme: handle \\?\ absolute path (win) if (!pathfile[0]) return file_load(pathfile, size_out); @@ -334179,8 +334183,7 @@ if( found && *found == 0 ) { ptr = vfs_unpack(pathfile, &size); // asset not found? maybe it has not been cooked yet at this point (see --cook-on-demand) - if( !ptr && COOK_ON_DEMAND ) { - + if( (!ptr && COOK_ON_DEMAND) || VFS_ALWAYS_PACK ) { static thread_mutex_t mutex, *init = 0; if(!init) thread_mutex_init(init = &mutex); thread_mutex_lock(&mutex); diff --git a/engine/split/v4k_file.c b/engine/split/v4k_file.c index d93a935..1f1cdbd 100644 --- a/engine/split/v4k_file.c +++ b/engine/split/v4k_file.c @@ -681,6 +681,10 @@ const char *vfs_resolve(const char *pathfile) { return pathfile; } +#ifndef VFS_ALWAYS_PACK +#define VFS_ALWAYS_PACK flag("--vfs-always-pack") +#endif + char* vfs_load(const char *pathfile, int *size_out) { // @todo: fix leaks, vfs_unpack() // @fixme: handle \\?\ absolute path (win) if (!pathfile[0]) return file_load(pathfile, size_out); @@ -752,8 +756,7 @@ if( found && *found == 0 ) { ptr = vfs_unpack(pathfile, &size); // asset not found? maybe it has not been cooked yet at this point (see --cook-on-demand) - if( !ptr && COOK_ON_DEMAND ) { - + if( (!ptr && COOK_ON_DEMAND) || VFS_ALWAYS_PACK ) { static thread_mutex_t mutex, *init = 0; if(!init) thread_mutex_init(init = &mutex); thread_mutex_lock(&mutex); diff --git a/engine/v4k.c b/engine/v4k.c index 43a1fa9..e37cbba 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -4803,6 +4803,10 @@ const char *vfs_resolve(const char *pathfile) { return pathfile; } +#ifndef VFS_ALWAYS_PACK +#define VFS_ALWAYS_PACK flag("--vfs-always-pack") +#endif + char* vfs_load(const char *pathfile, int *size_out) { // @todo: fix leaks, vfs_unpack() // @fixme: handle \\?\ absolute path (win) if (!pathfile[0]) return file_load(pathfile, size_out); @@ -4874,8 +4878,7 @@ if( found && *found == 0 ) { ptr = vfs_unpack(pathfile, &size); // asset not found? maybe it has not been cooked yet at this point (see --cook-on-demand) - if( !ptr && COOK_ON_DEMAND ) { - + if( (!ptr && COOK_ON_DEMAND) || VFS_ALWAYS_PACK ) { static thread_mutex_t mutex, *init = 0; if(!init) thread_mutex_init(init = &mutex); thread_mutex_lock(&mutex); diff --git a/workbench/pluginapi.h b/workbench/pluginapi.h index 2055371..b01bff5 100644 --- a/workbench/pluginapi.h +++ b/workbench/pluginapi.h @@ -21,6 +21,8 @@ typedef struct { editor_t *ed; int slot; //<< internal, used by plugin + bool opened; + uint64_t last_modified; } asset_t; #define PLUG_DECLARE(name) editor_vtable_t name##__procs = { name##_init, name##_tick, name##_quit, name##_ext }; diff --git a/workbench/workbench.c b/workbench/workbench.c index 801ad38..204f306 100644 --- a/workbench/workbench.c +++ b/workbench/workbench.c @@ -1,4 +1,6 @@ #define COOK_ON_DEMAND 1 +#define MAX_CACHED_FILES 0 +#define VFS_ALWAYS_PACK 1 #include "v4k.c" #include "pluginapi.h" @@ -13,11 +15,9 @@ array(asset_t) assets = 0; #undef X void load_editor(char *pname, editor_vtable_t f) { - char *name = STRDUP(pname); // @leak - editor_t ed = {0}; ed.f = f; - ed.name = file_base(STRDUP(name)); // @leak + ed.name = file_base(STRDUP(pname)); // @leak PRINTF("loaded plugin: '%s'\n", ed.name); array_push(editors, ed); } @@ -62,6 +62,8 @@ void load_asset(const char *fname) { asset_t asset = {0}; asset.name = STRDUP(fname); asset.ed = *ed; + asset.opened = 1; + asset.last_modified = file_stamp(fname); array_push(assets, asset); if (asset.ed->f.init((struct asset_t*)array_back(assets))) { FREE(asset.name); @@ -100,19 +102,23 @@ int main() { for (int i=0; iname, &open)) { + if (ui_window(f->name, &f->opened)) { f->ed->f.tick(f); + // was the asset modified? + bool modified = f->last_modified != file_stamp(f->name); + ui_separator(); - if (ui_button("reload asset") || !open) { + + if (ui_button("reload asset") || modified) { + f->last_modified = file_stamp(f->name); f->ed->f.quit(f); f->ed->f.init(f); } - if (ui_button("edit asset") || !open) { + if (ui_button("edit asset")) { edit_asset(assets[i].name); } - if (ui_button("close asset") || !open) { + if (ui_button("close asset") || !f->opened) { f->ed->f.quit(f); FREE(assets[i].name); array_erase(assets, i);