diff --git a/examples/example_0.c b/examples/example_0.c index a59e2bc7..949477bc 100644 --- a/examples/example_0.c +++ b/examples/example_0.c @@ -38,10 +38,10 @@ pl_app_load(plApiRegistryI* ptApiRegistry, void* pAppData) // retrieve the data registry API, this is the API used for sharing data // between extensions & the runtime - const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); + const plDataRegistryI* ptDataRegistry = pl_get_api(ptApiRegistry, plDataRegistryI); // retrieve the IO API required to use plIO for "talking" with runtime) - gptIO = ptApiRegistry->first(PL_API_IO); + gptIO = pl_get_api(ptApiRegistry, plIOI); // return optional application memory return NULL; diff --git a/examples/example_1.c b/examples/example_1.c index 3c464935..9257eb68 100644 --- a/examples/example_1.c +++ b/examples/example_1.c @@ -53,11 +53,11 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) // retrieve the data registry API, this is the API used for sharing data // between extensions & the runtime - const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); + const plDataRegistryI* ptDataRegistry = pl_get_api(ptApiRegistry, plDataRegistryI); // load required apis (NULL if not available) - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); // if "ptAppData" is a valid pointer, then this function is being called // during a hot reload. diff --git a/examples/example_2.c b/examples/example_2.c index a0954354..8abc5cc0 100644 --- a/examples/example_2.c +++ b/examples/example_2.c @@ -93,7 +93,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) // retrieve the data registry API, this is the API used for sharing data // between extensions & the runtime - const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); + const plDataRegistryI* ptDataRegistry = pl_get_api(ptApiRegistry, plDataRegistryI); // set log & profile contexts pl_set_log_context(ptDataRegistry->get_data("log")); @@ -106,12 +106,12 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) // re-retrieve the apis since we are now in // a different dll/so - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptDraw = ptApiRegistry->first(PL_API_DRAW); - gptShader = ptApiRegistry->first(PL_API_SHADER); - gptDrawBackend = ptApiRegistry->first(PL_API_DRAW_BACKEND); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptDraw = pl_get_api(ptApiRegistry, plDrawI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); + gptDrawBackend = pl_get_api(ptApiRegistry, plDrawBackendI); return ptAppData; } @@ -122,18 +122,18 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) memset(ptAppData, 0, sizeof(plAppData)); // retrieve extension registry - const plExtensionRegistryI* ptExtensionRegistry = ptApiRegistry->first(PL_API_EXTENSION_REGISTRY); + const plExtensionRegistryI* ptExtensionRegistry = pl_get_api(ptApiRegistry, plExtensionRegistryI); // load extensions ptExtensionRegistry->load("pilot_light", NULL, NULL, true); // load required apis (NULL if not available) - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptDraw = ptApiRegistry->first(PL_API_DRAW); - gptShader = ptApiRegistry->first(PL_API_SHADER); - gptDrawBackend = ptApiRegistry->first(PL_API_DRAW_BACKEND); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptDraw = pl_get_api(ptApiRegistry, plDrawI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); + gptDrawBackend = pl_get_api(ptApiRegistry, plDrawBackendI); // initialize shader compiler static const plShaderOptions tDefaultShaderOptions = { diff --git a/examples/example_3.c b/examples/example_3.c index 13b9fcfb..4bc3a468 100644 --- a/examples/example_3.c +++ b/examples/example_3.c @@ -94,7 +94,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) // retrieve the data registry API, this is the API used for sharing data // between extensions & the runtime - const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); + const plDataRegistryI* ptDataRegistry = pl_get_api(ptApiRegistry, plDataRegistryI); // set log & profile contexts pl_set_log_context(ptDataRegistry->get_data("log")); @@ -107,13 +107,12 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) // re-retrieve the apis since we are now in // a different dll/so - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptDraw = ptApiRegistry->first(PL_API_DRAW); - gptUi = ptApiRegistry->first(PL_API_UI); - gptShader = ptApiRegistry->first(PL_API_SHADER); - gptDrawBackend = ptApiRegistry->first(PL_API_DRAW_BACKEND); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptDraw = pl_get_api(ptApiRegistry, plDrawI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); + gptDrawBackend = pl_get_api(ptApiRegistry, plDrawBackendI); return ptAppData; } @@ -124,19 +123,18 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) memset(ptAppData, 0, sizeof(plAppData)); // retrieve extension registry - const plExtensionRegistryI* ptExtensionRegistry = ptApiRegistry->first(PL_API_EXTENSION_REGISTRY); + const plExtensionRegistryI* ptExtensionRegistry = pl_get_api(ptApiRegistry, plExtensionRegistryI); // load extensions ptExtensionRegistry->load("pilot_light", NULL, NULL, true); // load required apis (NULL if not available) - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptDraw = ptApiRegistry->first(PL_API_DRAW); - gptUi = ptApiRegistry->first(PL_API_UI); - gptShader = ptApiRegistry->first(PL_API_SHADER); - gptDrawBackend = ptApiRegistry->first(PL_API_DRAW_BACKEND); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptDraw = pl_get_api(ptApiRegistry, plDrawI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); + gptDrawBackend = pl_get_api(ptApiRegistry, plDrawBackendI); // initialize shader compiler static const plShaderOptions tDefaultShaderOptions = { diff --git a/examples/example_4.c b/examples/example_4.c index fbea1dbe..e3bc5e74 100644 --- a/examples/example_4.c +++ b/examples/example_4.c @@ -88,7 +88,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) // retrieve the data registry API, this is the API used for sharing data // between extensions & the runtime - const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); + const plDataRegistryI* ptDataRegistry = pl_get_api(ptApiRegistry, plDataRegistryI); // set log & profile contexts pl_set_log_context(ptDataRegistry->get_data("log")); @@ -100,10 +100,10 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) { // re-retrieve the apis since we are now in // a different dll/so - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptShader = ptApiRegistry->first(PL_API_SHADER); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); return ptAppData; } @@ -114,16 +114,16 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) memset(ptAppData, 0, sizeof(plAppData)); // retrieve extension registry - const plExtensionRegistryI* ptExtensionRegistry = ptApiRegistry->first(PL_API_EXTENSION_REGISTRY); + const plExtensionRegistryI* ptExtensionRegistry = pl_get_api(ptApiRegistry, plExtensionRegistryI); // load extensions ptExtensionRegistry->load("pilot_light", NULL, NULL, true); // load required apis (NULL if not available) - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptShader = ptApiRegistry->first(PL_API_SHADER); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); // use window API to create a window const plWindowDesc tWindowDesc = { diff --git a/examples/example_5.c b/examples/example_5.c index d716f164..e0d1e1dd 100644 --- a/examples/example_5.c +++ b/examples/example_5.c @@ -90,7 +90,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) // retrieve the data registry API, this is the API used for sharing data // between extensions & the runtime - const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); + const plDataRegistryI* ptDataRegistry = pl_get_api(ptApiRegistry, plDataRegistryI); // set log & profile contexts pl_set_log_context(ptDataRegistry->get_data("log")); @@ -102,10 +102,10 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) { // re-retrieve the apis since we are now in // a different dll/so - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptShader = ptApiRegistry->first(PL_API_SHADER); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); return ptAppData; } @@ -116,16 +116,16 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) memset(ptAppData, 0, sizeof(plAppData)); // retrieve extension registry - const plExtensionRegistryI* ptExtensionRegistry = ptApiRegistry->first(PL_API_EXTENSION_REGISTRY); + const plExtensionRegistryI* ptExtensionRegistry = pl_get_api(ptApiRegistry, plExtensionRegistryI); // load extensions ptExtensionRegistry->load("pilot_light", NULL, NULL, true); // load required apis (NULL if not available) - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptShader = ptApiRegistry->first(PL_API_SHADER); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); // use window API to create a window const plWindowDesc tWindowDesc = { diff --git a/examples/example_6.c b/examples/example_6.c index 27c772b5..a3619ad9 100644 --- a/examples/example_6.c +++ b/examples/example_6.c @@ -102,7 +102,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) // retrieve the data registry API, this is the API used for sharing data // between extensions & the runtime - const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); + const plDataRegistryI* ptDataRegistry = pl_get_api(ptApiRegistry, plDataRegistryI); // set log & profile contexts pl_set_log_context(ptDataRegistry->get_data("log")); @@ -114,11 +114,11 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) { // re-retrieve the apis since we are now in // a different dll/so - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptImage = ptApiRegistry->first(PL_API_IMAGE); - gptShader = ptApiRegistry->first(PL_API_SHADER); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); + gptImage = pl_get_api(ptApiRegistry, plImageI); return ptAppData; } @@ -129,17 +129,17 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) memset(ptAppData, 0, sizeof(plAppData)); // retrieve extension registry - const plExtensionRegistryI* ptExtensionRegistry = ptApiRegistry->first(PL_API_EXTENSION_REGISTRY); + const plExtensionRegistryI* ptExtensionRegistry = pl_get_api(ptApiRegistry, plExtensionRegistryI); // load extensions ptExtensionRegistry->load("pilot_light", NULL, NULL, true); // load required apis (NULL if not available) - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptImage = ptApiRegistry->first(PL_API_IMAGE); - gptShader = ptApiRegistry->first(PL_API_SHADER); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); + gptImage = pl_get_api(ptApiRegistry, plImageI); // use window API to create a window const plWindowDesc tWindowDesc = { diff --git a/examples/example_8.c b/examples/example_8.c index 1d3ba786..4b1a6bce 100644 --- a/examples/example_8.c +++ b/examples/example_8.c @@ -125,7 +125,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) // retrieve the data registry API, this is the API used for sharing data // between extensions & the runtime - const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); + const plDataRegistryI* ptDataRegistry = pl_get_api(ptApiRegistry, plDataRegistryI); // set log & profile contexts pl_set_log_context(ptDataRegistry->get_data("log")); @@ -137,12 +137,12 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) { // re-retrieve the apis since we are now in // a different dll/so - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptDraw = ptApiRegistry->first(PL_API_DRAW); - gptShader = ptApiRegistry->first(PL_API_SHADER); - gptDrawBackend = ptApiRegistry->first(PL_API_DRAW_BACKEND); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptDraw = pl_get_api(ptApiRegistry, plDrawI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); + gptDrawBackend = pl_get_api(ptApiRegistry, plDrawBackendI); return ptAppData; } @@ -153,18 +153,18 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) memset(ptAppData, 0, sizeof(plAppData)); // retrieve extension registry - const plExtensionRegistryI* ptExtensionRegistry = ptApiRegistry->first(PL_API_EXTENSION_REGISTRY); + const plExtensionRegistryI* ptExtensionRegistry = pl_get_api(ptApiRegistry, plExtensionRegistryI); // load extensions (makes their APIs available) ptExtensionRegistry->load("pilot_light", NULL, NULL, true); // load required apis (NULL if not available) - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptDraw = ptApiRegistry->first(PL_API_DRAW); - gptShader = ptApiRegistry->first(PL_API_SHADER); - gptDrawBackend = ptApiRegistry->first(PL_API_DRAW_BACKEND); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptDraw = pl_get_api(ptApiRegistry, plDrawI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); + gptDrawBackend = pl_get_api(ptApiRegistry, plDrawBackendI); // use window API to create a window const plWindowDesc tWindowDesc = { diff --git a/examples/example_9.c b/examples/example_9.c index 9c31cc66..9e4736f1 100644 --- a/examples/example_9.c +++ b/examples/example_9.c @@ -142,7 +142,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) // retrieve the data registry API, this is the API used for sharing data // between extensions & the runtime - const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); + const plDataRegistryI* ptDataRegistry = pl_get_api(ptApiRegistry, plDataRegistryI); // set log & profile contexts pl_set_log_context(ptDataRegistry->get_data("log")); @@ -154,12 +154,12 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) { // re-retrieve the apis since we are now in // a different dll/so - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptDraw = ptApiRegistry->first(PL_API_DRAW); - gptShader = ptApiRegistry->first(PL_API_SHADER); - gptDrawBackend = ptApiRegistry->first(PL_API_DRAW_BACKEND); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptDraw = pl_get_api(ptApiRegistry, plDrawI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); + gptDrawBackend = pl_get_api(ptApiRegistry, plDrawBackendI); return ptAppData; } @@ -170,18 +170,18 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) memset(ptAppData, 0, sizeof(plAppData)); // retrieve extension registry - const plExtensionRegistryI* ptExtensionRegistry = ptApiRegistry->first(PL_API_EXTENSION_REGISTRY); + const plExtensionRegistryI* ptExtensionRegistry = pl_get_api(ptApiRegistry, plExtensionRegistryI); // load extensions (makes their APIs available) ptExtensionRegistry->load("pilot_light", NULL, NULL, true); // load required apis (NULL if not available) - gptIO = ptApiRegistry->first(PL_API_IO); - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptDraw = ptApiRegistry->first(PL_API_DRAW); - gptShader = ptApiRegistry->first(PL_API_SHADER); - gptDrawBackend = ptApiRegistry->first(PL_API_DRAW_BACKEND); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptDraw = pl_get_api(ptApiRegistry, plDrawI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); + gptDrawBackend = pl_get_api(ptApiRegistry, plDrawBackendI); // use window API to create a window const plWindowDesc tWindowDesc = { diff --git a/extensions/pl_debug_ext.c b/extensions/pl_debug_ext.c index fddbd676..1007a253 100644 --- a/extensions/pl_debug_ext.c +++ b/extensions/pl_debug_ext.c @@ -8,7 +8,6 @@ Index of this file: // [SECTION] internal structs // [SECTION] global data // [SECTION] internal api -// [SECTION] public api implementation // [SECTION] internal api implementation // [SECTION] extension loading */ @@ -82,19 +81,6 @@ static void pl__show_statistics (bool* bValue); static void pl__show_device_memory (bool* bValue); static void pl__show_logging (bool* bValue); -//----------------------------------------------------------------------------- -// [SECTION] public api implementation -//----------------------------------------------------------------------------- - -static const plDebugApiI* -pl_load_debug_api(void) -{ - static const plDebugApiI tApi = { - .show_debug_windows = pl_show_debug_windows - }; - return &tApi; -} - //----------------------------------------------------------------------------- // [SECTION] internal api implementation //----------------------------------------------------------------------------- @@ -1094,7 +1080,12 @@ pl__show_logging(bool* bValue) static void pl_load_debug_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->add(PL_API_DEBUG, pl_load_debug_api()); + + const plDebugApiI tApi = { + .show_debug_windows = pl_show_debug_windows + }; + pl_set_api(ptApiRegistry, plDebugApiI, &tApi); + if(bReload) { gptDebugCtx = gptDataRegistry->get_data("plDebugContext"); @@ -1112,11 +1103,13 @@ pl_load_debug_ext(plApiRegistryI* ptApiRegistry, bool bReload) static void pl_unload_debug_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_debug_api()); if(bReload) return; - + + const plDebugApiI* ptApi = pl_get_api(ptApiRegistry, plDebugApiI); + ptApiRegistry->remove(ptApi); + pl_sb_free(gptDebugCtx->sbppdValues); pl_sb_free(gptDebugCtx->sbppdFrameValues); pl_sb_free(gptDebugCtx->sbdRawValues); diff --git a/extensions/pl_debug_ext.h b/extensions/pl_debug_ext.h index 6e5c9929..1a293dad 100644 --- a/extensions/pl_debug_ext.h +++ b/extensions/pl_debug_ext.h @@ -29,8 +29,7 @@ Index of this file: // [SECTION] apis //----------------------------------------------------------------------------- -#define PL_API_DEBUG "PL_API_DEBUG" -typedef struct _plDebugApiI plDebugApiI; +#define plDebugApiI_version (plVersion){0, 1, 0} //----------------------------------------------------------------------------- // [SECTION] forward declarations diff --git a/extensions/pl_draw_backend_ext.c b/extensions/pl_draw_backend_ext.c index 494252a6..96bd69d9 100644 --- a/extensions/pl_draw_backend_ext.c +++ b/extensions/pl_draw_backend_ext.c @@ -1005,10 +1005,11 @@ pl_submit_3d_drawlist(plDrawList3D* ptDrawlist, plRenderEncoder* ptEncoder, floa // [SECTION] extension loading //----------------------------------------------------------------------------- -static const plDrawBackendI* -pl_load_draw_backend_api(void) +static void +pl_load_draw_backend_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - static const plDrawBackendI tApi = { + + const plDrawBackendI tApi = { .initialize = pl_initialize_draw_backend, .cleanup = pl_cleanup_draw_backend, .new_frame = pl_new_draw_frame, @@ -1018,14 +1019,8 @@ pl_load_draw_backend_api(void) .submit_3d_drawlist = pl_submit_3d_drawlist, .create_bind_group_for_texture = pl_create_bind_group_for_texture, }; - return &tApi; -} + pl_set_api(ptApiRegistry, plDrawBackendI, &tApi); -static void -pl_load_draw_backend_ext(plApiRegistryI* ptApiRegistry, bool bReload) -{ - ptApiRegistry->add(PL_API_DRAW_BACKEND, pl_load_draw_backend_api()); - if(bReload) gptDrawBackendCtx = gptDataRegistry->get_data("plDrawBackendContext"); else // first load @@ -1039,5 +1034,9 @@ pl_load_draw_backend_ext(plApiRegistryI* ptApiRegistry, bool bReload) static void pl_unload_draw_backend_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_draw_backend_api()); + if(bReload) + return; + + const plDrawBackendI* ptApi = pl_get_api(ptApiRegistry, plDrawBackendI); + ptApiRegistry->remove(ptApi); } \ No newline at end of file diff --git a/extensions/pl_draw_backend_ext.h b/extensions/pl_draw_backend_ext.h index c3a8de75..8fa3e77a 100644 --- a/extensions/pl_draw_backend_ext.h +++ b/extensions/pl_draw_backend_ext.h @@ -17,16 +17,11 @@ Index of this file: #ifndef PL_DRAW_BACKEND_EXT_H #define PL_DRAW_BACKEND_EXT_H -// extension version (format XYYZZ) -#define PL_DRAW_BACKEND_EXT_VERSION "1.0.0" -#define PL_DRAW_BACKEND_EXT_VERSION_NUM 10000 - //----------------------------------------------------------------------------- // [SECTION] apis //----------------------------------------------------------------------------- -#define PL_API_DRAW_BACKEND "PL_API_DRAW_BACKEND" -typedef struct _plDrawBackendI plDrawBackendI; +#define plDrawBackendI_version (plVersion){1, 0, 0} //----------------------------------------------------------------------------- // [SECTION] includes diff --git a/extensions/pl_draw_ext.c b/extensions/pl_draw_ext.c index 10c4aff5..016e99d4 100644 --- a/extensions/pl_draw_ext.c +++ b/extensions/pl_draw_ext.c @@ -3534,10 +3534,10 @@ pl__find_glyph(plFont* ptFont, uint32_t c) // [SECTION] extension loading //----------------------------------------------------------------------------- -static const plDrawI* -pl_load_draw_3d_api(void) +static void +pl_load_draw_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - static const plDrawI tApi = { + const plDrawI tApi = { .initialize = pl_initialize, .cleanup = pl_cleanup, .request_3d_drawlist = pl_request_3d_drawlist, @@ -3608,16 +3608,9 @@ pl_load_draw_3d_api(void) .add_image_ex = pl_add_image_ex, .add_bezier_quad = pl_add_bezier_quad, .add_bezier_cubic = pl_add_bezier_cubic, - }; - return &tApi; -} + pl_set_api(ptApiRegistry, plDrawI, &tApi); -static void -pl_load_draw_ext(plApiRegistryI* ptApiRegistry, bool bReload) -{ - ptApiRegistry->add(PL_API_DRAW, pl_load_draw_3d_api()); - if(bReload) gptDrawCtx = gptDataRegistry->get_data("plDrawContext"); else // first load @@ -3631,5 +3624,9 @@ pl_load_draw_ext(plApiRegistryI* ptApiRegistry, bool bReload) static void pl_unload_draw_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_draw_3d_api()); + if(bReload) + return; + + const plDrawI* ptApi = pl_get_api(ptApiRegistry, plDrawI); + ptApiRegistry->remove(ptApi); } \ No newline at end of file diff --git a/extensions/pl_draw_ext.h b/extensions/pl_draw_ext.h index 3b9134db..7d2dbff7 100644 --- a/extensions/pl_draw_ext.h +++ b/extensions/pl_draw_ext.h @@ -22,18 +22,10 @@ Index of this file: #ifndef PL_DRAW_EXT_H #define PL_DRAW_EXT_H -// extension version (format XYYZZ) -#define PL_DRAW_EXT_VERSION "1.0.0" -#define PL_DRAW_EXT_VERSION_NUM 10000 - //----------------------------------------------------------------------------- // [SECTION] defines //----------------------------------------------------------------------------- -#ifndef PL_MAX_NAME_LENGTH - #define PL_MAX_NAME_LENGTH 1024 -#endif - #define PL_UNICODE_CODEPOINT_INVALID 0xFFFD // invalid Unicode code point (standard value). #define PL_UNICODE_CODEPOINT_MAX 0xFFFF // maximum Unicode code point supported by this build. @@ -41,8 +33,7 @@ Index of this file: // [SECTION] apis //----------------------------------------------------------------------------- -#define PL_API_DRAW "PL_API_DRAW" -typedef struct _plDrawI plDrawI; +#define plDrawI_version (plVersion){1, 0, 0} //----------------------------------------------------------------------------- // [SECTION] includes diff --git a/extensions/pl_ecs_ext.c b/extensions/pl_ecs_ext.c index e2f5c020..1ea561c3 100644 --- a/extensions/pl_ecs_ext.c +++ b/extensions/pl_ecs_ext.c @@ -747,24 +747,13 @@ pl_ecs_create_script(plComponentLibrary* ptLibrary, const char* pcFile, plScript plEntity tNewEntity = pl_ecs_create_tag(ptLibrary, pcFile); plScriptComponent* ptScript = pl_ecs_add_component(ptLibrary, PL_COMPONENT_TYPE_SCRIPT, tNewEntity); ptScript->tFlags = tFlags; - strncpy(ptScript->acFile, pcFile, PL_MAX_NAME_LENGTH); + strncpy(ptScript->acFile, pcFile, PL_MAX_PATH_LENGTH); gptExtensionRegistry->load(pcFile, "pl_load_script", "pl_unload_script", tFlags & PL_SCRIPT_FLAG_RELOADABLE); - const plScriptI* ptScriptApi = gptApiRegistry->first(PL_API_SCRIPT); - if(strncmp(pcFile, ptScriptApi->name(), PL_MAX_NAME_LENGTH) != 0) - { - while(ptScriptApi) - { - ptScriptApi = gptApiRegistry->next(ptScriptApi); - if(strncmp(pcFile, ptScriptApi->name(), PL_MAX_NAME_LENGTH) == 0) - { - break; - } - } - } + const plScriptI* ptScriptApi = gptApiRegistry->get(pcFile, plScriptI_version); ptScript->_ptApi = ptScriptApi; - PL_ASSERT(ptScriptApi); + PL_ASSERT(ptScriptApi->run); if(ptScriptApi->setup) ptScriptApi->setup(ptLibrary, tNewEntity); @@ -784,20 +773,9 @@ pl_ecs_attach_script(plComponentLibrary* ptLibrary, const char* pcFile, plScript gptExtensionRegistry->load(pcFile, "pl_load_script", "pl_unload_script", tFlags & PL_SCRIPT_FLAG_RELOADABLE); - const plScriptI* ptScriptApi = gptApiRegistry->first(PL_API_SCRIPT); - if(strncmp(pcFile, ptScriptApi->name(), PL_MAX_NAME_LENGTH) != 0) - { - while(ptScriptApi) - { - ptScriptApi = gptApiRegistry->next(ptScriptApi); - if(strncmp(pcFile, ptScriptApi->name(), PL_MAX_NAME_LENGTH) == 0) - { - break; - } - } - } + const plScriptI* ptScriptApi = gptApiRegistry->get(pcFile, plScriptI_version); ptScript->_ptApi = ptScriptApi; - PL_ASSERT(ptScriptApi); + PL_ASSERT(ptScriptApi->run); if(ptScriptApi->setup) ptScriptApi->setup(ptLibrary, tEntity); @@ -1712,10 +1690,10 @@ pl_calculate_tangents(plMeshComponent* atMeshes, uint32_t uComponentCount) // [SECTION] extension loading //----------------------------------------------------------------------------- -static const plEcsI* -pl_load_ecs_api(void) +static void +pl_load_ecs_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - static const plEcsI tApi = { + const plEcsI tApi0 = { .init_component_library = pl_ecs_init_component_library, .cleanup_component_library = pl_ecs_cleanup_component_library, .create_entity = pl_ecs_create_entity, @@ -1751,13 +1729,9 @@ pl_load_ecs_api(void) .run_inverse_kinematics_update_system = pl_run_inverse_kinematics_update_system, .run_script_update_system = pl_run_script_update_system }; - return &tApi; -} + pl_set_api(ptApiRegistry, plEcsI, &tApi0); -static const plCameraI* -pl_load_camera_api(void) -{ - static const plCameraI tApi = { + const plCameraI tApi1 = { .set_fov = pl_camera_set_fov, .set_clip_planes = pl_camera_set_clip_planes, .set_aspect = pl_camera_set_aspect, @@ -1768,14 +1742,7 @@ pl_load_camera_api(void) .update = pl_camera_update, .look_at = pl_camera_look_at, }; - return &tApi; -} - -static void -pl_load_ecs_ext(plApiRegistryI* ptApiRegistry, bool bReload) -{ - ptApiRegistry->add(PL_API_ECS, pl_load_ecs_api()); - ptApiRegistry->add(PL_API_CAMERA, pl_load_camera_api()); + pl_set_api(ptApiRegistry, plCameraI, &tApi1); if(bReload) { @@ -1794,6 +1761,12 @@ pl_load_ecs_ext(plApiRegistryI* ptApiRegistry, bool bReload) static void pl_unload_ecs_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_ecs_api()); - ptApiRegistry->remove(pl_load_camera_api()); + if(bReload) + return; + + const plEcsI* ptApi0 = pl_get_api(ptApiRegistry, plEcsI); + ptApiRegistry->remove(ptApi0); + + const plCameraI* ptApi1 = pl_get_api(ptApiRegistry, plCameraI); + ptApiRegistry->remove(ptApi1); } diff --git a/extensions/pl_ecs_ext.h b/extensions/pl_ecs_ext.h index ac4c24e3..bf9da002 100644 --- a/extensions/pl_ecs_ext.h +++ b/extensions/pl_ecs_ext.h @@ -25,20 +25,13 @@ Index of this file: // [SECTION] apis //----------------------------------------------------------------------------- -#define PL_API_ECS "PL_API_ECS" -typedef struct _plEcsI plEcsI; - -#define PL_API_CAMERA "PL_API_CAMERA" -typedef struct _plCameraI plCameraI; +#define plEcsI_version (plVersion){0, 1, 0} +#define plCameraI_version (plVersion){0, 1, 0} //----------------------------------------------------------------------------- // [SECTION] defines //----------------------------------------------------------------------------- -#ifndef PL_MAX_NAME_LENGTH - #define PL_MAX_NAME_LENGTH 1024 -#endif - #define PL_MAX_SHADOW_CASCADES 4 //----------------------------------------------------------------------------- @@ -392,7 +385,7 @@ typedef union _plResourceHandle typedef struct _plTextureMap { - char acName[PL_MAX_NAME_LENGTH]; + char acName[PL_MAX_PATH_LENGTH]; plResourceHandle tResource; uint32_t uUVSet; uint32_t uWidth; @@ -588,7 +581,7 @@ typedef struct _plInverseKinematicsComponent typedef struct _plScriptComponent { plScriptFlags tFlags; - char acFile[PL_MAX_NAME_LENGTH]; + char acFile[PL_MAX_PATH_LENGTH]; const struct _plScriptI* _ptApi; } plScriptComponent; diff --git a/extensions/pl_ext.c b/extensions/pl_ext.c index bc41105a..e499d07d 100644 --- a/extensions/pl_ext.c +++ b/extensions/pl_ext.c @@ -40,20 +40,20 @@ PL_EXPORT void pl_load_ext(plApiRegistryI* ptApiRegistry, bool bReload) { // core apis - gptApiRegistry = ptApiRegistry; - gptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); - gptExtensionRegistry = ptApiRegistry->first(PL_API_EXTENSION_REGISTRY); - gptMemory = ptApiRegistry->first(PL_API_MEMORY); + gptApiRegistry = ptApiRegistry; + gptDataRegistry = pl_get_api(ptApiRegistry, plDataRegistryI); + gptExtensionRegistry = pl_get_api(ptApiRegistry, plExtensionRegistryI); + gptMemory = pl_get_api(ptApiRegistry, plMemoryI); // set contexts pl_set_profile_context(gptDataRegistry->get_data("profile")); pl_set_log_context(gptDataRegistry->get_data("log")); // load os apis - gptIOI = ptApiRegistry->first(PL_API_IO); - gptFile = ptApiRegistry->first(PL_API_FILE); - gptThreads = ptApiRegistry->first(PL_API_THREADS); - gptAtomics = ptApiRegistry->first(PL_API_ATOMICS); + gptIOI = pl_get_api(ptApiRegistry, plIOI); + gptFile = pl_get_api(ptApiRegistry, plFileI); + gptThreads = pl_get_api(ptApiRegistry, plThreadsI); + gptAtomics = pl_get_api(ptApiRegistry, plAtomicsI); gptIO = gptIOI->get_io(); // first batch (standalone APIs) @@ -64,31 +64,31 @@ pl_load_ext(plApiRegistryI* ptApiRegistry, bool bReload) #ifdef PL_CORE_EXTENSION_INCLUDE_SHADER pl_load_shader_ext(ptApiRegistry, bReload); - gptShader = ptApiRegistry->first(PL_API_SHADER); + gptShader = pl_get_api(ptApiRegistry, plShaderI); #endif - gptStats = ptApiRegistry->first(PL_API_STATS); - gptImage = ptApiRegistry->first(PL_API_IMAGE); - gptJob = ptApiRegistry->first(PL_API_JOB); - gptRect = ptApiRegistry->first(PL_API_RECT_PACK); + gptStats = pl_get_api(ptApiRegistry, plStatsI); + gptImage = pl_get_api(ptApiRegistry, plImageI); + gptJob = pl_get_api(ptApiRegistry, plJobI); + gptRect = pl_get_api(ptApiRegistry, plRectPackI); #ifdef PL_CORE_EXTENSION_INCLUDE_GRAPHICS pl_load_graphics_ext(ptApiRegistry, bReload); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); pl_load_gpu_allocators_ext(ptApiRegistry, bReload); - gptGpuAllocators = ptApiRegistry->first(PL_API_GPU_ALLOCATORS); + gptGpuAllocators = pl_get_api(ptApiRegistry, plGPUAllocatorsI); // third batch pl_load_draw_ext(ptApiRegistry, bReload); - gptDraw = ptApiRegistry->first(PL_API_DRAW); + gptDraw = pl_get_api(ptApiRegistry, plDrawI); pl_load_draw_backend_ext(ptApiRegistry, bReload); - gptDrawBackend = ptApiRegistry->first(PL_API_DRAW_BACKEND); + gptDrawBackend = pl_get_api(ptApiRegistry, plDrawBackendI); // fourth batch pl_load_ui_ext(ptApiRegistry, bReload); - gptUI = ptApiRegistry->first(PL_API_UI); + gptUI = pl_get_api(ptApiRegistry, plUiI); #endif } diff --git a/extensions/pl_ext.inc b/extensions/pl_ext.inc index 252bb177..efa5db23 100644 --- a/extensions/pl_ext.inc +++ b/extensions/pl_ext.inc @@ -15,7 +15,6 @@ static const struct _plApiRegistryI* gptApiRegistry = 0; static const struct _plExtensionRegistryI* gptExtensionRegistry = 0; static const struct _plDataRegistryI* gptDataRegistry = 0; static const struct _plGraphicsI* gptGfx = 0; -static const struct _plCameraI* gptCamera = 0; static const struct _plImageI* gptImage = 0; static const struct _plStatsI* gptStats = 0; static const struct _plGPUAllocatorsI* gptGpuAllocators = 0; @@ -32,6 +31,7 @@ static const struct _plFileI* gptFile = 0; static const struct _plMemoryI* gptMemory = 0; // experimental +static const struct _plCameraI* gptCamera = 0; static const struct _plResourceI* gptResource = 0; static const struct _plEcsI* gptECS = 0; diff --git a/extensions/pl_ext_experimental.c b/extensions/pl_ext_experimental.c index 57b86ef1..7d6cd94a 100644 --- a/extensions/pl_ext_experimental.c +++ b/extensions/pl_ext_experimental.c @@ -34,39 +34,39 @@ pl_load_ext(plApiRegistryI* ptApiRegistry, bool bReload) { // core apis gptApiRegistry = ptApiRegistry; - gptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); - gptIOI = ptApiRegistry->first(PL_API_IO); - gptImage = ptApiRegistry->first(PL_API_IMAGE); - gptExtensionRegistry = ptApiRegistry->first(PL_API_EXTENSION_REGISTRY); - gptMemory = ptApiRegistry->first(PL_API_MEMORY); - gptGpuAllocators = ptApiRegistry->first(PL_API_GPU_ALLOCATORS); - gptFile = ptApiRegistry->first(PL_API_FILE); - gptThreads = ptApiRegistry->first(PL_API_THREADS); - gptAtomics = ptApiRegistry->first(PL_API_ATOMICS); + gptDataRegistry = pl_get_api(ptApiRegistry, plDataRegistryI); + gptIOI = pl_get_api(ptApiRegistry, plIOI); + gptImage = pl_get_api(ptApiRegistry, plImageI); + gptExtensionRegistry = pl_get_api(ptApiRegistry, plExtensionRegistryI); + gptMemory = pl_get_api(ptApiRegistry, plMemoryI); + gptGpuAllocators = pl_get_api(ptApiRegistry, plGPUAllocatorsI); + gptFile = pl_get_api(ptApiRegistry, plFileI); + gptThreads = pl_get_api(ptApiRegistry, plThreadsI); + gptAtomics = pl_get_api(ptApiRegistry, plAtomicsI); gptIO = gptIOI->get_io(); - gptStats = ptApiRegistry->first(PL_API_STATS); - gptImage = ptApiRegistry->first(PL_API_IMAGE); - gptJob = ptApiRegistry->first(PL_API_JOB); + gptStats = pl_get_api(ptApiRegistry, plStatsI); + gptImage = pl_get_api(ptApiRegistry, plImageI); + gptJob = pl_get_api(ptApiRegistry, plJobI); // set contexts pl_set_profile_context(gptDataRegistry->get_data("profile")); pl_set_log_context(gptDataRegistry->get_data("log")); pl_load_ecs_ext(ptApiRegistry, bReload); - gptECS = ptApiRegistry->first(PL_API_ECS); - gptCamera = ptApiRegistry->first(PL_API_CAMERA); + gptECS = pl_get_api(ptApiRegistry, plEcsI); + gptCamera = pl_get_api(ptApiRegistry, plCameraI); #ifdef PL_CORE_EXTENSION_INCLUDE_SHADER - gptShader = ptApiRegistry->first(PL_API_SHADER); + gptShader = pl_get_api(ptApiRegistry, plShaderI); #endif #ifdef PL_CORE_EXTENSION_INCLUDE_GRAPHICS - gptDraw = ptApiRegistry->first(PL_API_DRAW); - gptDrawBackend = ptApiRegistry->first(PL_API_DRAW_BACKEND); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptUI = ptApiRegistry->first(PL_API_UI); + gptDraw = pl_get_api(ptApiRegistry, plDrawI); + gptDrawBackend = pl_get_api(ptApiRegistry, plDrawBackendI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptUI = pl_get_api(ptApiRegistry, plUiI); pl_load_resource_ext(ptApiRegistry, bReload); - gptResource = ptApiRegistry->first(PL_API_RESOURCE); + gptResource = pl_get_api(ptApiRegistry, plResourceI); pl_load_model_loader_ext(ptApiRegistry, bReload); pl_load_renderer_ext(ptApiRegistry, bReload); pl_load_debug_ext(ptApiRegistry, bReload); diff --git a/extensions/pl_gpu_allocators_ext.c b/extensions/pl_gpu_allocators_ext.c index e2342f81..42b81e70 100644 --- a/extensions/pl_gpu_allocators_ext.c +++ b/extensions/pl_gpu_allocators_ext.c @@ -7,7 +7,6 @@ Index of this file: // [SECTION] includes // [SECTION] defines // [SECTION] internal api implementation -// [SECTION] public api implementation // [SECTION] extension loading // [SECTION] unity build */ @@ -859,13 +858,13 @@ pl_cleanup_allocators(plDevice* ptDevice) } //----------------------------------------------------------------------------- -// [SECTION] public api implementation +// [SECTION] extension loading //----------------------------------------------------------------------------- -static const plGPUAllocatorsI* -pl_load_gpu_allocators_api(void) +static void +pl_load_gpu_allocators_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - static const plGPUAllocatorsI tApi = { + const plGPUAllocatorsI tApi = { .get_local_dedicated_allocator = pl_get_local_dedicated_allocator, .get_local_buddy_allocator = pl_get_local_buddy_allocator, .get_staging_uncached_allocator = pl_get_staging_uncached_allocator, @@ -874,24 +873,15 @@ pl_load_gpu_allocators_api(void) .get_ranges = pl_get_allocator_ranges, .cleanup = pl_cleanup_allocators }; - return &tApi; -} - -//----------------------------------------------------------------------------- -// [SECTION] extension loading -//----------------------------------------------------------------------------- - -static void -pl_load_gpu_allocators_ext(plApiRegistryI* ptApiRegistry, bool bReload) -{ - ptApiRegistry->add(PL_API_GPU_ALLOCATORS, pl_load_gpu_allocators_api()); + pl_set_api(ptApiRegistry, plGPUAllocatorsI, &tApi); } static void pl_unload_gpu_allocators_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_gpu_allocators_api()); - if(bReload) return; + + const plGPUAllocatorsI* ptApi = pl_get_api(ptApiRegistry, plGPUAllocatorsI); + ptApiRegistry->remove(ptApi); } \ No newline at end of file diff --git a/extensions/pl_gpu_allocators_ext.h b/extensions/pl_gpu_allocators_ext.h index 170a0ef4..1587be9a 100644 --- a/extensions/pl_gpu_allocators_ext.h +++ b/extensions/pl_gpu_allocators_ext.h @@ -6,7 +6,6 @@ Index of this file: // [SECTION] header mess // [SECTION] includes -// [SECTION] defines // [SECTION] forward declarations // [SECTION] APIs // [SECTION] public api structs @@ -20,24 +19,12 @@ Index of this file: #ifndef PL_GPU_ALLOCATORS_EXT_H #define PL_GPU_ALLOCATORS_EXT_H -// extension version (format XYYZZ) -#define PL_GPU_ALLOCATORS_EXT_VERSION "1.0.0" -#define PL_GPU_ALLOCATORS_EXT_VERSION_NUM 10000 - //----------------------------------------------------------------------------- // [SECTION] includes //----------------------------------------------------------------------------- #include -//----------------------------------------------------------------------------- -// [SECTION] defines -//----------------------------------------------------------------------------- - -#ifndef PL_MAX_NAME_LENGTH - #define PL_MAX_NAME_LENGTH 1024 -#endif - //----------------------------------------------------------------------------- // [SECTION] forward declarations //----------------------------------------------------------------------------- @@ -54,8 +41,7 @@ typedef struct _plDevice plDevice; // [SECTION] APIs //----------------------------------------------------------------------------- -#define PL_API_GPU_ALLOCATORS "PL_API_GPU_ALLOCATORS" -typedef struct _plGPUAllocatorsI plGPUAllocatorsI; +#define plGPUAllocatorsI_version (plVersion){1, 0, 0} //----------------------------------------------------------------------------- // [SECTION] public api structs diff --git a/extensions/pl_graphics_ext.c b/extensions/pl_graphics_ext.c index 8665fec7..98b82ead 100644 --- a/extensions/pl_graphics_ext.c +++ b/extensions/pl_graphics_ext.c @@ -661,10 +661,10 @@ pl_get_swapchain_info(plSwapchain* ptSwap) return ptSwap->tInfo; } -static const plGraphicsI* -pl_load_graphics_api(void) +static void +pl_load_graphics_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - static const plGraphicsI tApi = { + const plGraphicsI tApi = { .initialize = pl_initialize_graphics, .set_depth_bias = pl_set_depth_bias, .recreate_swapchain = pl_recreate_swapchain, @@ -769,14 +769,8 @@ pl_load_graphics_api(void) .cleanup_bind_group_pool = pl_cleanup_bind_group_pool, .reset_bind_group_pool = pl_reset_bind_group_pool, }; - return &tApi; -} + pl_set_api(ptApiRegistry, plGraphicsI, &tApi); -static void -pl_load_graphics_ext(plApiRegistryI* ptApiRegistry, bool bReload) -{ - ptApiRegistry->add(PL_API_GRAPHICS, pl_load_graphics_api()); - if(bReload) { gptGraphics = gptDataRegistry->get_data("plGraphics"); @@ -787,5 +781,9 @@ pl_load_graphics_ext(plApiRegistryI* ptApiRegistry, bool bReload) static void pl_unload_graphics_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_graphics_api()); + if(bReload) + return; + + const plGraphicsI* ptApi = pl_get_api(ptApiRegistry, plGraphicsI); + ptApiRegistry->remove(ptApi); } \ No newline at end of file diff --git a/extensions/pl_graphics_ext.h b/extensions/pl_graphics_ext.h index d651a4f1..b8f3057d 100644 --- a/extensions/pl_graphics_ext.h +++ b/extensions/pl_graphics_ext.h @@ -24,10 +24,6 @@ Index of this file: #ifndef PL_GRAPHICS_EXT_H #define PL_GRAPHICS_EXT_H -// extension version (format XYYZZ) -#define PL_GRAPHICS_EXT_VERSION "1.0.0" -#define PL_GRAPHICS_EXT_VERSION_NUM 10000 - //----------------------------------------------------------------------------- // [SECTION] defines //----------------------------------------------------------------------------- @@ -51,8 +47,7 @@ Index of this file: // [SECTION] apis //----------------------------------------------------------------------------- -#define PL_API_GRAPHICS "PL_API_GRAPHICS" -typedef struct _plGraphicsI plGraphicsI; +#define plGraphicsI_version (plVersion){1, 0, 0} //----------------------------------------------------------------------------- // [SECTION] includes diff --git a/extensions/pl_image_ext.c b/extensions/pl_image_ext.c index 4a004496..18ef2f07 100644 --- a/extensions/pl_image_ext.c +++ b/extensions/pl_image_ext.c @@ -6,7 +6,6 @@ Index of this file: // [SECTION] includes // [SECTION] internal api implementation -// [SECTION] public api implementation // [SECTION] extension loading */ @@ -74,13 +73,13 @@ pl_write_image(char const *pcFileName, const void *pData, const plImageWriteInfo } //----------------------------------------------------------------------------- -// [SECTION] public api implementation +// [SECTION] extension loading //----------------------------------------------------------------------------- -static const plImageI* -pl_load_image_api(void) +static void +pl_load_image_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - static const plImageI tApi = { + const plImageI tApi = { .get_info = pl__get_info, .get_info_from_memory = pl__get_info_from_memory, .load_from_memory = stbi_load_from_memory, @@ -96,21 +95,15 @@ pl_load_image_api(void) .set_ldr_to_hdr_gamma = stbi_ldr_to_hdr_gamma, .set_ldr_to_hdr_scale = stbi_ldr_to_hdr_scale }; - return &tApi; -} - -//----------------------------------------------------------------------------- -// [SECTION] extension loading -//----------------------------------------------------------------------------- - -static void -pl_load_image_ext(plApiRegistryI* ptApiRegistry, bool bReload) -{ - ptApiRegistry->add(PL_API_IMAGE, pl_load_image_api()); + pl_set_api(ptApiRegistry, plImageI, &tApi); } static void pl_unload_image_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_image_api()); + if(bReload) + return; + + const plImageI* ptApi = pl_get_api(ptApiRegistry, plImageI); + ptApiRegistry->remove(ptApi); } \ No newline at end of file diff --git a/extensions/pl_image_ext.h b/extensions/pl_image_ext.h index f2a5f244..cf3928ff 100644 --- a/extensions/pl_image_ext.h +++ b/extensions/pl_image_ext.h @@ -19,10 +19,6 @@ Index of this file: #ifndef PL_IMAGE_EXT_H #define PL_IMAGE_EXT_H -// extension version (format XYYZZ) -#define PL_IMAGE_EXT_VERSION "1.0.0" -#define PL_IMAGE_EXT_VERSION_NUM 10000 - //----------------------------------------------------------------------------- // [SECTION] includes //----------------------------------------------------------------------------- @@ -33,8 +29,7 @@ Index of this file: // [SECTION] APIs //----------------------------------------------------------------------------- -#define PL_API_IMAGE "PL_API_IMAGE" -typedef struct _plImageI plImageI; +#define plImageI_version (plVersion){1, 0, 0} //----------------------------------------------------------------------------- // [SECTION] forward declarations & basic types diff --git a/extensions/pl_job_ext.c b/extensions/pl_job_ext.c index 540f07bc..eb6bdd8e 100644 --- a/extensions/pl_job_ext.c +++ b/extensions/pl_job_ext.c @@ -10,7 +10,6 @@ Index of this file: // [SECTION] global data // [SECTION] free list functions // [SECTION] implementation -// [SECTION] public api implementation // [SECTION] extension loading // [SECTION] unity build */ @@ -430,30 +429,21 @@ pl__cleanup(void) } //----------------------------------------------------------------------------- -// [SECTION] public api implementation +// [SECTION] extension loading //----------------------------------------------------------------------------- -static const plJobI* -pl_load_job_api(void) +static void +pl_load_job_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - static const plJobI tApi = { + const plJobI tApi = { .initialize = pl__initialize, .cleanup = pl__cleanup, .wait_for_counter = pl__wait_for_counter, .dispatch_jobs = pl__dispatch_jobs, .dispatch_batch = pl__dispatch_batch }; - return &tApi; -} - -//----------------------------------------------------------------------------- -// [SECTION] extension loading -//----------------------------------------------------------------------------- + pl_set_api(ptApiRegistry, plJobI, &tApi); -static void -pl_load_job_ext(plApiRegistryI* ptApiRegistry, bool bReload) -{ - ptApiRegistry->add(PL_API_JOB, pl_load_job_api()); if(bReload) { gptJobCtx = gptDataRegistry->get_data("plJobContext"); @@ -469,5 +459,9 @@ pl_load_job_ext(plApiRegistryI* ptApiRegistry, bool bReload) static void pl_unload_job_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_job_api()); + if(bReload) + return; + + const plJobI* ptApi = pl_get_api(ptApiRegistry, plJobI); + ptApiRegistry->remove(ptApi); } \ No newline at end of file diff --git a/extensions/pl_job_ext.h b/extensions/pl_job_ext.h index eae8b700..c7bfa5dc 100644 --- a/extensions/pl_job_ext.h +++ b/extensions/pl_job_ext.h @@ -20,10 +20,6 @@ Index of this file: #ifndef PL_JOB_EXT_H #define PL_JOB_EXT_H -// extension version (format XYYZZ) -#define PL_JOB_EXT_VERSION "1.0.0" -#define PL_JOB_EXT_VERSION_NUM 10000 - //----------------------------------------------------------------------------- // [SECTION] includes //----------------------------------------------------------------------------- @@ -34,8 +30,7 @@ Index of this file: // [SECTION] APIs //----------------------------------------------------------------------------- -#define PL_API_JOB "PL_API_JOB" -typedef struct _plJobI plJobI; +#define plJobI_version (plVersion){1, 0, 0} //----------------------------------------------------------------------------- // [SECTION] forward declarations diff --git a/extensions/pl_model_loader_ext.c b/extensions/pl_model_loader_ext.c index ede02521..722fbe26 100644 --- a/extensions/pl_model_loader_ext.c +++ b/extensions/pl_model_loader_ext.c @@ -9,7 +9,6 @@ Index of this file: // [SECTION] internal API // [SECTION] implementation // [SECTION] internal API implementation -// [SECTION] public API implementation // [SECTION] extension loading */ @@ -387,7 +386,7 @@ pl__load_gltf_texture(plTextureSlot tSlot, const cgltf_texture_view* ptTexture, } else { - strncpy(ptMaterial->atTextureMaps[tSlot].acName, ptTexture->texture->image->uri, PL_MAX_NAME_LENGTH); + strncpy(ptMaterial->atTextureMaps[tSlot].acName, ptTexture->texture->image->uri, PL_MAX_PATH_LENGTH); char acFilepath[2048] = {0}; strcpy(acFilepath, pcDirectory); pl_str_concatenate(acFilepath, ptMaterial->atTextureMaps[tSlot].acName, acFilepath, 2048); @@ -972,32 +971,26 @@ pl__refr_load_gltf_object(plModelLoaderData* ptData, plGltfLoadingData* ptSceneD } //----------------------------------------------------------------------------- -// [SECTION] public API implementation +// [SECTION] extension loading //----------------------------------------------------------------------------- -static const plModelLoaderI* -pl_load_model_loader_api(void) +static void +pl_load_model_loader_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - static const plModelLoaderI tApi = { + const plModelLoaderI tApi = { .load_stl = pl__load_stl, .load_gltf = pl__load_gltf, .free_data = pl__free_data }; - return &tApi; -} - -//----------------------------------------------------------------------------- -// [SECTION] extension loading -//----------------------------------------------------------------------------- - -static void -pl_load_model_loader_ext(plApiRegistryI* ptApiRegistry, bool bReload) -{ - ptApiRegistry->add(PL_API_MODEL_LOADER, pl_load_model_loader_api()); + pl_set_api(ptApiRegistry, plModelLoaderI, &tApi); } static void pl_unload_model_loader_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_model_loader_api()); + if(bReload) + return; + + const plModelLoaderI* ptApi = pl_get_api(ptApiRegistry, plModelLoaderI); + ptApiRegistry->remove(ptApi); } diff --git a/extensions/pl_model_loader_ext.h b/extensions/pl_model_loader_ext.h index 517853aa..7d0707eb 100644 --- a/extensions/pl_model_loader_ext.h +++ b/extensions/pl_model_loader_ext.h @@ -31,8 +31,7 @@ Index of this file: // [SECTION] APIs //----------------------------------------------------------------------------- -#define PL_API_MODEL_LOADER "PL_API_MODEL_LOADER" -typedef struct _plModelLoaderI plModelLoaderI; +#define plModelLoaderI_version (plVersion){0, 1, 0} //----------------------------------------------------------------------------- // [SECTION] forward declarations diff --git a/extensions/pl_rect_pack_ext.c b/extensions/pl_rect_pack_ext.c index 7035687c..0d4fc37d 100644 --- a/extensions/pl_rect_pack_ext.c +++ b/extensions/pl_rect_pack_ext.c @@ -6,7 +6,6 @@ Index of this file: // [SECTION] includes // [SECTION] internal api implementation -// [SECTION] public api implementation // [SECTION] extension loading // [SECTION] unity build */ @@ -61,19 +60,6 @@ pl_pack_rects(int iWidth, int iHeight, plPackRect* ptRects, uint32_t uRectCount) stbrp_pack_rects(&gptRectPackCtx->tStbContext, (stbrp_rect*)ptRects, (int)uRectCount); } -//----------------------------------------------------------------------------- -// [SECTION] public api implementation -//----------------------------------------------------------------------------- - -static const plRectPackI* -pl_load_rect_pack_api(void) -{ - static const plRectPackI tApi = { - .pack_rects = pl_pack_rects - }; - return &tApi; -} - //----------------------------------------------------------------------------- // [SECTION] extension loading //----------------------------------------------------------------------------- @@ -81,7 +67,10 @@ pl_load_rect_pack_api(void) static void pl_load_rect_pack_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->add(PL_API_RECT_PACK, pl_load_rect_pack_api()); + const plRectPackI tApi = { + .pack_rects = pl_pack_rects + }; + pl_set_api(ptApiRegistry, plRectPackI, &tApi); if(bReload) gptRectPackCtx = gptDataRegistry->get_data("plRectPackContext"); @@ -96,10 +85,12 @@ pl_load_rect_pack_ext(plApiRegistryI* ptApiRegistry, bool bReload) static void pl_unload_rect_pack_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_rect_pack_api()); if(bReload) return; + const plRectPackI* ptApi = pl_get_api(ptApiRegistry, plRectPackI); + ptApiRegistry->remove(ptApi); + if(gptRectPackCtx->ptNodes) PL_FREE(gptRectPackCtx->ptNodes); } diff --git a/extensions/pl_rect_pack_ext.h b/extensions/pl_rect_pack_ext.h index e353ac24..449fa940 100644 --- a/extensions/pl_rect_pack_ext.h +++ b/extensions/pl_rect_pack_ext.h @@ -18,10 +18,6 @@ Index of this file: #ifndef PL_RECT_PACK_EXT_H #define PL_RECT_PACK_EXT_H -// extension version (format XYYZZ) -#define PL_RECT_PACK_EXT_VERSION "1.0.0" -#define PL_RECT_PACK_EXT_VERSION_NUM 10000 - //----------------------------------------------------------------------------- // [SECTION] includes //----------------------------------------------------------------------------- @@ -32,8 +28,7 @@ Index of this file: // [SECTION] APIs //----------------------------------------------------------------------------- -#define PL_API_RECT_PACK "PL_API_RECT_PACK" -typedef struct _plRectPackI plRectPackI; +#define plRectPackI_version (plVersion){1, 0, 0} //----------------------------------------------------------------------------- // [SECTION] forward declarations diff --git a/extensions/pl_renderer_ext.c b/extensions/pl_renderer_ext.c index 73d1e90d..c56b84c9 100644 --- a/extensions/pl_renderer_ext.c +++ b/extensions/pl_renderer_ext.c @@ -9,7 +9,6 @@ Index of this file: // [SECTION] global data & apis // [SECTION] internal API // [SECTION] implementation -// [SECTION] public API implementation // [SECTION] internal API implementation // [SECTION] extension loading */ @@ -6114,13 +6113,13 @@ pl__get_data_type_size(plDataType tType) } //----------------------------------------------------------------------------- -// [SECTION] public API implementation +// [SECTION] extension loading //----------------------------------------------------------------------------- -static const plRendererI* -pl_load_renderer_api(void) +static void +pl_load_renderer_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - static const plRendererI tApi = { + const plRendererI tApi = { .initialize = pl_refr_initialize, .cleanup = pl_refr_cleanup, .create_scene = pl_refr_create_scene, @@ -6145,17 +6144,7 @@ pl_load_renderer_api(void) .get_command_pool = pl__refr_get_command_pool, .resize = pl_refr_resize, }; - return &tApi; -} - -//----------------------------------------------------------------------------- -// [SECTION] extension loading -//----------------------------------------------------------------------------- - -static void -pl_load_renderer_ext(plApiRegistryI* ptApiRegistry, bool bReload) -{ - ptApiRegistry->add(PL_API_RENDERER, pl_load_renderer_api()); + pl_set_api(ptApiRegistry, plRendererI, &tApi); if(bReload) { gptData = gptDataRegistry->get_data("ref renderer data"); @@ -6165,5 +6154,9 @@ pl_load_renderer_ext(plApiRegistryI* ptApiRegistry, bool bReload) static void pl_unload_renderer_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_renderer_api()); + if(bReload) + return; + + const plRendererI* ptApi = pl_get_api(ptApiRegistry, plRendererI); + ptApiRegistry->remove(ptApi); } diff --git a/extensions/pl_renderer_ext.h b/extensions/pl_renderer_ext.h index 4044b0cb..52cf969f 100644 --- a/extensions/pl_renderer_ext.h +++ b/extensions/pl_renderer_ext.h @@ -21,8 +21,7 @@ Index of this file: // [SECTION] apis //----------------------------------------------------------------------------- -#define PL_API_RENDERER "PL_API_RENDERER" -typedef struct _plRendererI plRendererI; +#define plRendererI_version (plVersion){0, 1, 0} //----------------------------------------------------------------------------- // [SECTION] forward declarations diff --git a/extensions/pl_resource_ext.c b/extensions/pl_resource_ext.c index 0b6e43b8..dd88450b 100644 --- a/extensions/pl_resource_ext.c +++ b/extensions/pl_resource_ext.c @@ -48,25 +48,6 @@ static void pl_unload_resource (plResourceHandle tResourceHa static plResourceManager* gptResourceManager = NULL; -//----------------------------------------------------------------------------- -// [SECTION] public api implementation -//----------------------------------------------------------------------------- - -static const plResourceI* -pl_load_resource_api(void) -{ - static const plResourceI tApi = { - .get_file_data = pl_resource_get_file_data, - .get_buffer_data = pl_resource_get_buffer_data, - .set_buffer_data = pl_set_buffer_data, - .load_resource = pl_load_resource, - .is_resource_loaded = pl_is_resource_loaded, - .is_resource_valid = pl_is_resource_valid, - .unload_resource = pl_unload_resource - }; - return &tApi; -} - //----------------------------------------------------------------------------- // [SECTION] implementation //----------------------------------------------------------------------------- @@ -205,7 +186,17 @@ pl_is_resource_valid(plResourceHandle tResourceHandle) static void pl_load_resource_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - gptApiRegistry->add(PL_API_RESOURCE, pl_load_resource_api()); + const plResourceI tApi = { + .get_file_data = pl_resource_get_file_data, + .get_buffer_data = pl_resource_get_buffer_data, + .set_buffer_data = pl_set_buffer_data, + .load_resource = pl_load_resource, + .is_resource_loaded = pl_is_resource_loaded, + .is_resource_valid = pl_is_resource_valid, + .unload_resource = pl_unload_resource + }; + pl_set_api(ptApiRegistry, plResourceI, &tApi); + if(bReload) { gptResourceManager = gptDataRegistry->get_data("plResourceManager"); @@ -221,11 +212,12 @@ pl_load_resource_ext(plApiRegistryI* ptApiRegistry, bool bReload) static void pl_unload_resource_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - gptApiRegistry->remove(pl_load_resource_api()); - if(bReload) return; - + + const plResourceI* ptApi = pl_get_api(ptApiRegistry, plResourceI); + ptApiRegistry->remove(ptApi); + for(uint32_t i = 0; i < pl_sb_size(gptResourceManager->sbtResources); i++) { if(gptResourceManager->sbtResources[i].tFlags & PL_RESOURCE_LOAD_FLAG_RETAIN_DATA) diff --git a/extensions/pl_resource_ext.h b/extensions/pl_resource_ext.h index 403cc71d..e0135bc9 100644 --- a/extensions/pl_resource_ext.h +++ b/extensions/pl_resource_ext.h @@ -20,8 +20,7 @@ Index of this file: // [SECTION] apis //----------------------------------------------------------------------------- -#define PL_API_RESOURCE "PL_API_RESOURCE" -typedef struct _plResourceI plResourceI; +#define plResourceI_version (plVersion){0, 1, 0} //----------------------------------------------------------------------------- // [SECTION] includes diff --git a/extensions/pl_script_camera.c b/extensions/pl_script_camera.c index 5240dbef..38f06f51 100644 --- a/extensions/pl_script_camera.c +++ b/extensions/pl_script_camera.c @@ -75,41 +75,34 @@ pl_script_run(plComponentLibrary* ptLibrary, plEntity tEntity) gptCamera->update(ptCamera); } -static const char* -pl_script_name(void) -{ - return "pl_script_camera"; -} - //----------------------------------------------------------------------------- // [SECTION] script loading //----------------------------------------------------------------------------- -static const plScriptI* -pl_load_script_api(void) -{ - static const plScriptI tApi = { - .setup = NULL, - .run = pl_script_run, - .name = pl_script_name - }; - return &tApi; -} - PL_EXPORT void pl_load_script(plApiRegistryI* ptApiRegistry, bool bReload) { // load apis - gptEcs = ptApiRegistry->first(PL_API_ECS); - gptCamera = ptApiRegistry->first(PL_API_CAMERA); - gptIO = ptApiRegistry->first(PL_API_IO); - gptUi = ptApiRegistry->first(PL_API_UI); + gptEcs = pl_get_api(ptApiRegistry, plEcsI); + gptCamera = pl_get_api(ptApiRegistry, plCameraI); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptUi = pl_get_api(ptApiRegistry, plUiI); + + const plScriptI tApi = { + .setup = NULL, + .run = pl_script_run + }; - ptApiRegistry->add(PL_API_SCRIPT, pl_load_script_api()); + ptApiRegistry->set("pl_script_camera", plScriptI_version, &tApi, sizeof(plScriptI)); } PL_EXPORT void -pl_unload_script(plApiRegistryI* ptApiRegistry) +pl_unload_script(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_script_api()); + + if(bReload) + return; + + const plScriptI* ptApi = ptApiRegistry->get("pl_script_camera", plScriptI_version); + ptApiRegistry->remove(ptApi); } diff --git a/extensions/pl_script_ext.h b/extensions/pl_script_ext.h index b9aa3318..001ae224 100644 --- a/extensions/pl_script_ext.h +++ b/extensions/pl_script_ext.h @@ -22,8 +22,7 @@ Index of this file: // [SECTION] apis //----------------------------------------------------------------------------- -#define PL_API_SCRIPT "PL_API_SCRIPT" -typedef struct _plScriptI plScriptI; +#define plScriptI_version (plVersion){0, 1, 0} //----------------------------------------------------------------------------- // [SECTION] forward declarations @@ -44,10 +43,6 @@ typedef struct _plScriptI // ran every frame void (*run)(plComponentLibrary*, plEntity); - - // used by entity component system to differentiate between implmentations - // of this interface and must be the dll/so name without an extension - const char* (*name)(void); } plScriptI; #endif // PL_SCRIPT_EXT_H \ No newline at end of file diff --git a/extensions/pl_shader_ext.c b/extensions/pl_shader_ext.c index 514f7e98..4704a31c 100644 --- a/extensions/pl_shader_ext.c +++ b/extensions/pl_shader_ext.c @@ -411,10 +411,10 @@ pl_load_glsl(const char* pcShader, const char* pcEntryFunc, const char* pcFile, // [SECTION] script loading //----------------------------------------------------------------------------- -static const plShaderI* -pl_load_shader_api(void) +static void +pl_load_shader_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - static const plShaderI tApi = { + const plShaderI tApi = { .initialize = pl_initialize_shader_ext, .load_glsl = pl_load_glsl, #ifdef PL_OFFLINE_SHADERS_ONLY @@ -425,13 +425,7 @@ pl_load_shader_api(void) .write_to_disk = pl_write_to_disk, .read_from_disk = pl_read_from_disk, }; - return &tApi; -} - -static void -pl_load_shader_ext(plApiRegistryI* ptApiRegistry, bool bReload) -{ - ptApiRegistry->add(PL_API_SHADER, pl_load_shader_api()); + pl_set_api(ptApiRegistry, plShaderI, &tApi); if(bReload) { gptShaderCtx = gptDataRegistry->get_data("plShaderContext"); @@ -447,11 +441,13 @@ pl_load_shader_ext(plApiRegistryI* ptApiRegistry, bool bReload) static void pl_unload_shader_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_shader_api()); if(bReload) return; + const plShaderI* ptApi = pl_get_api(ptApiRegistry, plShaderI); + ptApiRegistry->remove(ptApi); + #ifndef PL_OFFLINE_SHADERS_ONLY #ifdef PL_METAL_BACKEND spvc_context_destroy(tSpirvCtx); diff --git a/extensions/pl_shader_ext.h b/extensions/pl_shader_ext.h index 2b2f6e31..02f31db0 100644 --- a/extensions/pl_shader_ext.h +++ b/extensions/pl_shader_ext.h @@ -20,10 +20,6 @@ Index of this file: #ifndef PL_SHADER_EXT_H #define PL_SHADER_EXT_H -// extension version (format XYYZZ) -#define PL_SHADER_EXT_VERSION "1.0.0" -#define PL_SHADER_EXT_VERSION_NUM 10000 - // compile-time options // #define PL_OFFLINE_SHADERS_ONLY #ifndef PL_MAX_SHADER_INCLUDE_DIRECTORIES @@ -41,8 +37,7 @@ Index of this file: // [SECTION] APIs //----------------------------------------------------------------------------- -#define PL_API_SHADER "PL_API_SHADER" -typedef struct _plShaderI plShaderI; +#define plShaderI_version (plVersion){1, 0, 0} //----------------------------------------------------------------------------- // [SECTION] forward declarations diff --git a/extensions/pl_stats_ext.c b/extensions/pl_stats_ext.c index 5e51ff68..a0a73ffa 100644 --- a/extensions/pl_stats_ext.c +++ b/extensions/pl_stats_ext.c @@ -10,7 +10,6 @@ Index of this file: // [SECTION] internal structs // [SECTION] global context // [SECTION] internal api -// [SECTION] public api implementation // [SECTION] internal api implementation // [SECTION] extension loading */ @@ -90,24 +89,6 @@ static const char** pl__get_names (uint32_t* puCount); static uint32_t pl__get_max_frames (void); static void pl__set_max_frames (uint32_t); -//----------------------------------------------------------------------------- -// [SECTION] public api implementation -//----------------------------------------------------------------------------- - -static const plStatsI* -pl_load_stats_api(void) -{ - static const plStatsI tApi = { - .get_counter = pl__get_counter, - .new_frame = pl__new_frame, - .get_counter_data = pl__get_counter_data, - .get_names = pl__get_names, - .set_max_frames = pl__set_max_frames, - .get_max_frames = pl__get_max_frames - }; - return &tApi; -} - //----------------------------------------------------------------------------- // [SECTION] internal api implementation //----------------------------------------------------------------------------- @@ -254,7 +235,16 @@ pl__get_counter_data(char const* pcName) static void pl_load_stats_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->add(PL_API_STATS, pl_load_stats_api()); + const plStatsI tApi = { + .get_counter = pl__get_counter, + .new_frame = pl__new_frame, + .get_counter_data = pl__get_counter_data, + .get_names = pl__get_names, + .set_max_frames = pl__set_max_frames, + .get_max_frames = pl__get_max_frames + }; + pl_set_api(ptApiRegistry, plStatsI, &tApi); + if(bReload) { gptStatsCtx = gptDataRegistry->get_data("plStatsContext"); @@ -273,10 +263,13 @@ pl_load_stats_ext(plApiRegistryI* ptApiRegistry, bool bReload) static void pl_unload_stats_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_stats_api()); + if(bReload) return; - + + const plStatsI* ptApi = pl_get_api(ptApiRegistry, plStatsI); + ptApiRegistry->remove(ptApi); + pl_sb_free(gptStatsCtx->sbtBlocks); pl_sb_free(gptStatsCtx->sbtNames); pl_hm_free(gptStatsCtx->ptHashmap); diff --git a/extensions/pl_stats_ext.h b/extensions/pl_stats_ext.h index 19d49c32..c0477574 100644 --- a/extensions/pl_stats_ext.h +++ b/extensions/pl_stats_ext.h @@ -18,10 +18,6 @@ Index of this file: #ifndef PL_STATS_EXT_H #define PL_STATS_EXT_H -// extension version (format XYYZZ) -#define PL_STATS_EXT_VERSION "1.0.0" -#define PL_STATS_EXT_VERSION_NUM 10000 - //----------------------------------------------------------------------------- // [SECTION] includes //----------------------------------------------------------------------------- @@ -32,8 +28,7 @@ Index of this file: // [SECTION] apis //----------------------------------------------------------------------------- -#define PL_API_STATS "PL_API_STATS" -typedef struct _plStatsI plStatsI; +#define plStatsI_version (plVersion){1, 0, 0} //----------------------------------------------------------------------------- // [SECTION] public api diff --git a/extensions/pl_ui_ext.c b/extensions/pl_ui_ext.c index f94705b8..edc7eed5 100644 --- a/extensions/pl_ui_ext.c +++ b/extensions/pl_ui_ext.c @@ -9,10 +9,11 @@ #include "pl_ui_widgets.c" #include "pl_ui_demo.c" -static const plUiI* -pl_load_ui_api(void) + +static void +pl_load_ui_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - static const plUiI tApi = { + const plUiI tApi = { .initialize = pl_ui_initialize, .cleanup = pl_ui_cleanup, .get_draw_list = pl_get_draw_list, @@ -128,13 +129,8 @@ pl_load_ui_api(void) .push_id_uint = pl_push_id_uint, .pop_id = pl_pop_id, }; - return &tApi; -} + pl_set_api(ptApiRegistry, plUiI, &tApi); -static void -pl_load_ui_ext(plApiRegistryI* ptApiRegistry, bool bReload) -{ - ptApiRegistry->add(PL_API_UI, pl_load_ui_api()); if(bReload) { gptCtx = gptDataRegistry->get_data("plUiContext"); @@ -150,8 +146,12 @@ pl_load_ui_ext(plApiRegistryI* ptApiRegistry, bool bReload) static void pl_unload_ui_ext(plApiRegistryI* ptApiRegistry, bool bReload) { - ptApiRegistry->remove(pl_load_ui_api()); + if(bReload) return; + + const plUiI* ptApi = pl_get_api(ptApiRegistry, plUiI); + ptApiRegistry->remove(ptApi); + gptCtx = NULL; } \ No newline at end of file diff --git a/extensions/pl_ui_ext.h b/extensions/pl_ui_ext.h index adec665c..4263a4b3 100644 --- a/extensions/pl_ui_ext.h +++ b/extensions/pl_ui_ext.h @@ -21,10 +21,6 @@ Index of this file: #ifndef PL_UI_EXT_H #define PL_UI_EXT_H -// extension version (format XYYZZ) -#define PL_UI_EXT_VERSION "1.0.0" -#define PL_UI_EXT_VERSION_NUM 10000 - //----------------------------------------------------------------------------- // [SECTION] includes //----------------------------------------------------------------------------- @@ -39,8 +35,7 @@ Index of this file: // [SECTION] api //----------------------------------------------------------------------------- -#define PL_API_UI "PL_API_UI" -typedef struct _plUiI plUiI; +#define plUiI_version (plVersion){1, 0, 0} //----------------------------------------------------------------------------- // [SECTION] forward declarations diff --git a/sandbox/app.c b/sandbox/app.c index 260080c2..22ff28ca 100644 --- a/sandbox/app.c +++ b/sandbox/app.c @@ -30,7 +30,7 @@ Index of this file: PL_EXPORT void* pl_app_load(plApiRegistryI* ptApiRegistry, plEditorData* ptEditorData) { - const plDataRegistryI* ptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); + const plDataRegistryI* ptDataRegistry = pl_get_api(ptApiRegistry, plDataRegistryI); pl_set_log_context(ptDataRegistry->get_data("log")); pl_set_profile_context(ptDataRegistry->get_data("profile")); @@ -39,22 +39,22 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plEditorData* ptEditorData) { // reload global apis - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptStats = ptApiRegistry->first(PL_API_STATS); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptDebug = ptApiRegistry->first(PL_API_DEBUG); - gptEcs = ptApiRegistry->first(PL_API_ECS); - gptCamera = ptApiRegistry->first(PL_API_CAMERA); - gptRenderer = ptApiRegistry->first(PL_API_RENDERER); - gptJobs = ptApiRegistry->first(PL_API_JOB); - gptModelLoader = ptApiRegistry->first(PL_API_MODEL_LOADER); - gptDraw = ptApiRegistry->first(PL_API_DRAW); - gptDrawBackend = ptApiRegistry->first(PL_API_DRAW_BACKEND); - gptUi = ptApiRegistry->first(PL_API_UI); - gptIO = ptApiRegistry->first(PL_API_IO); - gptShader = ptApiRegistry->first(PL_API_SHADER); - gptMemory = ptApiRegistry->first(PL_API_MEMORY); - gptNetwork = ptApiRegistry->first(PL_API_NETWORK); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptStats = pl_get_api(ptApiRegistry, plStatsI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptDebug = pl_get_api(ptApiRegistry, plDebugApiI); + gptEcs = pl_get_api(ptApiRegistry, plEcsI); + gptCamera = pl_get_api(ptApiRegistry, plCameraI); + gptRenderer = pl_get_api(ptApiRegistry, plRendererI); + gptJobs = pl_get_api(ptApiRegistry, plJobI); + gptModelLoader = pl_get_api(ptApiRegistry, plModelLoaderI); + gptDraw = pl_get_api(ptApiRegistry, plDrawI); + gptDrawBackend = pl_get_api(ptApiRegistry, plDrawBackendI); + gptUi = pl_get_api(ptApiRegistry, plUiI); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); + gptMemory = pl_get_api(ptApiRegistry, plMemoryI); + gptNetwork = pl_get_api(ptApiRegistry, plNetworkI); return ptEditorData; } @@ -62,27 +62,27 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plEditorData* ptEditorData) pl_begin_profile_frame(); // load extensions - const plExtensionRegistryI* ptExtensionRegistry = ptApiRegistry->first(PL_API_EXTENSION_REGISTRY); + const plExtensionRegistryI* ptExtensionRegistry = pl_get_api(ptApiRegistry, plExtensionRegistryI); ptExtensionRegistry->load("pilot_light", NULL, NULL, true); ptExtensionRegistry->load("pilot_light_experimental", NULL, NULL, true); // load apis - gptWindows = ptApiRegistry->first(PL_API_WINDOW); - gptStats = ptApiRegistry->first(PL_API_STATS); - gptGfx = ptApiRegistry->first(PL_API_GRAPHICS); - gptDebug = ptApiRegistry->first(PL_API_DEBUG); - gptEcs = ptApiRegistry->first(PL_API_ECS); - gptCamera = ptApiRegistry->first(PL_API_CAMERA); - gptRenderer = ptApiRegistry->first(PL_API_RENDERER); - gptJobs = ptApiRegistry->first(PL_API_JOB); - gptModelLoader = ptApiRegistry->first(PL_API_MODEL_LOADER); - gptDraw = ptApiRegistry->first(PL_API_DRAW); - gptDrawBackend = ptApiRegistry->first(PL_API_DRAW_BACKEND); - gptUi = ptApiRegistry->first(PL_API_UI); - gptIO = ptApiRegistry->first(PL_API_IO); - gptShader = ptApiRegistry->first(PL_API_SHADER); - gptMemory = ptApiRegistry->first(PL_API_MEMORY); - gptNetwork = ptApiRegistry->first(PL_API_NETWORK); + gptWindows = pl_get_api(ptApiRegistry, plWindowI); + gptStats = pl_get_api(ptApiRegistry, plStatsI); + gptGfx = pl_get_api(ptApiRegistry, plGraphicsI); + gptDebug = pl_get_api(ptApiRegistry, plDebugApiI); + gptEcs = pl_get_api(ptApiRegistry, plEcsI); + gptCamera = pl_get_api(ptApiRegistry, plCameraI); + gptRenderer = pl_get_api(ptApiRegistry, plRendererI); + gptJobs = pl_get_api(ptApiRegistry, plJobI); + gptModelLoader = pl_get_api(ptApiRegistry, plModelLoaderI); + gptDraw = pl_get_api(ptApiRegistry, plDrawI); + gptDrawBackend = pl_get_api(ptApiRegistry, plDrawBackendI); + gptUi = pl_get_api(ptApiRegistry, plUiI); + gptIO = pl_get_api(ptApiRegistry, plIOI); + gptShader = pl_get_api(ptApiRegistry, plShaderI); + gptMemory = pl_get_api(ptApiRegistry, plMemoryI); + gptNetwork = pl_get_api(ptApiRegistry, plNetworkI); // add some context to data registry ptEditorData = PL_ALLOC(sizeof(plEditorData)); diff --git a/src/pl.c b/src/pl.c index 5e1d2196..973d0f92 100644 --- a/src/pl.c +++ b/src/pl.c @@ -60,10 +60,14 @@ typedef struct _plExtension void (*pl_unload) (const plApiRegistryI* ptApiRegistry, bool bReload); } plExtension; +typedef struct _plApiEntry plApiEntry; typedef struct _plApiEntry { const char* pcName; - const void* pInterface; + void* apBuffer[PL_MAX_API_FUNCTIONS]; + plVersion tVersion; + plApiEntry* ptNext; + bool bSet; } plApiEntry; typedef struct _plDataRegistryData @@ -175,10 +179,9 @@ void pl_set_buffer(plDataObject*, uint32_t, void*); void pl_commit (plDataObject*); // api registry functions -const void* pl_add_api (const char* pcName, const void* pInterface); -void pl_remove_api(const void* pInterface); -const void* pl_first_api (const char* pcName); -const void* pl_next_api (const void* pPrev); +const void* pl__set_api(const char* pcName, plVersion, const void* pInterface, size_t szInterfaceSize); +const void* pl__get_api(const char* pcName, plVersion); +void pl__remove_api(const void* pInterface); // extension registry functions bool pl_load_extension (const char* pcName, const char* pcLoadFunc, const char* pcUnloadFunc, bool bReloadable); @@ -203,7 +206,7 @@ plDataRegistryData gtDataRegistryData = {0}; plMutex* gptDataMutex = NULL; // api registry -plApiEntry* gsbApiEntries = NULL; +plApiEntry* gptApiHead = NULL; // extension registry plExtension* gsbtExtensions = NULL; @@ -238,66 +241,105 @@ plHashMap* gptMemoryHashMap = NULL; // [SECTION] api registry implementation //----------------------------------------------------------------------------- -const void* -pl_add_api(const char* pcName, const void* pInterface) -{ - plApiEntry tNewApiEntry = { - .pcName = pcName, - .pInterface = pInterface - }; - pl_sb_push(gsbApiEntries, tNewApiEntry); - return pInterface; -} - -void -pl_remove_api(const void* pInterface) +bool +pl__check_apis(void) { - for(uint32_t i = 0; i < pl_sb_size(gsbApiEntries); i++) + bool bResult = true; + plApiEntry* ptCurrentEntry = gptApiHead; + while(ptCurrentEntry) { - if(gsbApiEntries[i].pInterface == pInterface) + + if(!ptCurrentEntry->bSet) { - pl_sb_del_swap(gsbApiEntries, i); - break; + printf("API Not Found: %s\n", ptCurrentEntry->pcName); + bResult = false; } + ptCurrentEntry = ptCurrentEntry->ptNext; } + + return bResult; } const void* -pl_first_api(const char* pcName) +pl__set_api(const char* pcName, plVersion tVersion, const void* pInterface, size_t szInterfaceSize) { - for(uint32_t i = 0; i < pl_sb_size(gsbApiEntries); i++) + // see if entry already exists + plApiEntry* ptCurrentEntry = gptApiHead; + while(ptCurrentEntry) { - if(strcmp(pcName, gsbApiEntries[i].pcName) == 0) + if(strcmp(pcName, ptCurrentEntry->pcName) == 0 && + ptCurrentEntry->tVersion.uMajor == tVersion.uMajor && + ptCurrentEntry->tVersion.uMinor == tVersion.uMinor && + ptCurrentEntry->tVersion.uPatch == tVersion.uPatch) { - return gsbApiEntries[i].pInterface; + memcpy(ptCurrentEntry->apBuffer, pInterface, szInterfaceSize); + ptCurrentEntry->bSet = true; + return ptCurrentEntry->apBuffer; } + + ptCurrentEntry = ptCurrentEntry->ptNext; } - return NULL; + ptCurrentEntry = PL_ALLOC(sizeof(plApiEntry)); + memset(ptCurrentEntry, 0, sizeof(plApiEntry)); + + ptCurrentEntry->pcName = pcName; + ptCurrentEntry->bSet = true; + ptCurrentEntry->tVersion = tVersion; + memcpy(ptCurrentEntry->apBuffer, pInterface, szInterfaceSize); + ptCurrentEntry->ptNext = gptApiHead; + gptApiHead = ptCurrentEntry; + return ptCurrentEntry->apBuffer; } const void* -pl_next_api(const void* pPrev) +pl__get_api(const char* pcName, plVersion tVersion) { - - const char* pcApiName = ""; - const uint32_t uApiCount = pl_sb_size(gsbApiEntries); - for(uint32_t i = 0; i < uApiCount; i++) + + plApiEntry* ptCurrentEntry = gptApiHead; + while(ptCurrentEntry) { - if(strcmp(pcApiName, gsbApiEntries[i].pcName) == 0) + if(strcmp(pcName, ptCurrentEntry->pcName) == 0 && + ptCurrentEntry->tVersion.uMajor == tVersion.uMajor && + ptCurrentEntry->tVersion.uMinor >= tVersion.uMinor) { - return gsbApiEntries[i].pInterface; - } + return ptCurrentEntry->apBuffer; + } - // first need to find name of API so we can then find - // the next API with the same name - if(gsbApiEntries[i].pInterface == pPrev) + ptCurrentEntry = ptCurrentEntry->ptNext; + } + + ptCurrentEntry = PL_ALLOC(sizeof(plApiEntry)); + memset(ptCurrentEntry, 0, sizeof(plApiEntry)); + + ptCurrentEntry->pcName = pcName; + ptCurrentEntry->tVersion = tVersion; + ptCurrentEntry->ptNext = gptApiHead; + gptApiHead = ptCurrentEntry; + return ptCurrentEntry->apBuffer; +} + +void +pl__remove_api(const void* pInterface) +{ + plApiEntry* ptLastEntry = NULL; + plApiEntry* ptCurrentEntry = gptApiHead; + while(ptCurrentEntry) + { + if(ptCurrentEntry->apBuffer == pInterface) { - pcApiName = gsbApiEntries[i].pcName; + if(ptLastEntry) + ptLastEntry->ptNext = ptCurrentEntry->ptNext; + else + gptApiHead = ptCurrentEntry->ptNext; + + PL_FREE(ptCurrentEntry); + return; } - } - return NULL; + ptLastEntry = ptCurrentEntry; + ptCurrentEntry = ptCurrentEntry->ptNext; + } } //----------------------------------------------------------------------------- @@ -523,7 +565,7 @@ pl_load_extension(const char* pcName, const char* pcLoadFunc, const char* pcUnlo plSharedLibrary* ptLibrary = NULL; - const plLibraryI* ptLibraryApi = ptApiRegistry->first(PL_API_LIBRARY); + const plLibraryI* ptLibraryApi = pl_get_api(ptApiRegistry, plLibraryI); const plLibraryDesc tDesc = { .pcName = tExtension.pcLibPath @@ -1300,10 +1342,9 @@ const plApiRegistryI* pl__load_api_registry(void) { static const plApiRegistryI tApiRegistry = { - .add = pl_add_api, - .remove = pl_remove_api, - .first = pl_first_api, - .next = pl_next_api + .get = pl__get_api, + .set = pl__set_api, + .remove = pl__remove_api }; return &tApiRegistry; @@ -1382,16 +1423,16 @@ pl__load_core_apis(void) }; // apis more likely to not be stored, should be first (api registry is not sorted) - ptApiRegistry->add(PL_API_IO, &tIOApi); - ptApiRegistry->add(PL_API_DATA_REGISTRY, &tDataRegistryApi); - ptApiRegistry->add(PL_API_EXTENSION_REGISTRY, &tExtensionRegistryApi); - ptApiRegistry->add(PL_API_MEMORY, &tMemoryApi); + gptMemory = &tMemoryApi; + pl_set_api(ptApiRegistry, plIOI, &tIOApi); + pl_set_api(ptApiRegistry, plDataRegistryI, &tDataRegistryApi); + pl_set_api(ptApiRegistry, plExtensionRegistryI, &tExtensionRegistryApi); + pl_set_api(ptApiRegistry, plMemoryI, &tMemoryApi); // load apis - gptDataRegistry = ptApiRegistry->first(PL_API_DATA_REGISTRY); - gptExtensionRegistry = ptApiRegistry->first(PL_API_EXTENSION_REGISTRY); - gptIOI = ptApiRegistry->first(PL_API_IO); - gptMemory = ptApiRegistry->first(PL_API_MEMORY); + gptDataRegistry = pl_get_api(ptApiRegistry, plDataRegistryI); + gptExtensionRegistry = pl_get_api(ptApiRegistry, plExtensionRegistryI); + gptIOI = pl_get_api(ptApiRegistry, plIOI); gptApiRegistry = ptApiRegistry; plProfileInit tProfileInit = { @@ -1433,7 +1474,13 @@ pl__unload_core_apis(void) pl_hm_free(gptHashmap); // api registry - pl_sb_free(gsbApiEntries); + plApiEntry* ptCurrentEntry = gptApiHead; + while(ptCurrentEntry) + { + plApiEntry* ptOldEntry = ptCurrentEntry; + ptCurrentEntry = ptCurrentEntry->ptNext; + PL_FREE(ptOldEntry); + } // extension registry pl_sb_free(gsbtExtensions); @@ -1551,14 +1598,14 @@ pl__load_os_apis(void) }; #ifndef PL_HEADLESS_APP - gptApiRegistry->add(PL_API_WINDOW, &tWindowApi); + pl_set_api(gptApiRegistry, plWindowI, &tWindowApi); #endif - gptApiRegistry->add(PL_API_LIBRARY, &tLibraryApi); - gptApiRegistry->add(PL_API_FILE, &tFileApi); - gptApiRegistry->add(PL_API_NETWORK, &tNetworkApi); - gptApiRegistry->add(PL_API_THREADS, &tThreadApi); - gptApiRegistry->add(PL_API_ATOMICS, &tAtomicsApi); - gptApiRegistry->add(PL_API_VIRTUAL_MEMORY, &tVirtualMemoryApi); + pl_set_api(gptApiRegistry, plLibraryI, &tLibraryApi); + pl_set_api(gptApiRegistry, plFileI, &tFileApi); + pl_set_api(gptApiRegistry, plNetworkI, &tNetworkApi); + pl_set_api(gptApiRegistry, plThreadsI, &tThreadApi); + pl_set_api(gptApiRegistry, plAtomicsI, &tAtomicsApi); + pl_set_api(gptApiRegistry, plVirtualMemoryI, &tVirtualMemoryApi); } //----------------------------------------------------------------------------- diff --git a/src/pl.h b/src/pl.h index 01991edf..9fea2407 100644 --- a/src/pl.h +++ b/src/pl.h @@ -9,6 +9,7 @@ Index of this file: // [SECTION] apis // [SECTION] includes // [SECTION] forward declarations & basic types +// [SECTION] helper macros // [SECTION] api structs // [SECTION] enums // [SECTION] IO struct @@ -31,19 +32,10 @@ Index of this file: // [SECTION] apis //----------------------------------------------------------------------------- -typedef struct _plApiRegistryI plApiRegistryI; - -#define PL_API_EXTENSION_REGISTRY "PL_API_EXTENSION_REGISTRY" -typedef struct _plExtensionRegistryI plExtensionRegistryI; - -#define PL_API_MEMORY "PL_API_MEMORY" -typedef struct _plMemoryI plMemoryI; - -#define PL_API_IO "PL_API_IO" -typedef struct _plIOI plIOI; - -#define PL_API_DATA_REGISTRY "PL_API_DATA_REGISTRY" -typedef struct _plDataRegistryI plDataRegistryI; +#define plExtensionRegistryI_version (plVersion){1, 0, 0} +#define plMemoryI_version (plVersion){1, 0, 0} +#define plIOI_version (plVersion){1, 0, 0} +#define plDataRegistryI_version (plVersion){1, 0, 0} //----------------------------------------------------------------------------- // [SECTION] includes @@ -59,6 +51,7 @@ typedef struct _plDataRegistryI plDataRegistryI; //----------------------------------------------------------------------------- // types +typedef struct _plVersion plVersion; typedef struct _plAllocationEntry plAllocationEntry; typedef union _plDataID plDataID; typedef struct _plDataObject plDataObject; // opaque type @@ -77,6 +70,13 @@ typedef int plKeyChord; // character types typedef uint16_t plUiWChar; +//----------------------------------------------------------------------------- +// [SECTION] helper macros +//----------------------------------------------------------------------------- + +#define pl_set_api(ptApiReg, TYPE, ptr) { const TYPE* ptTypedPtr = ptr; ptApiReg->set(#TYPE, TYPE##_version, ptTypedPtr, sizeof(TYPE)); } +#define pl_get_api(ptApiReg, TYPE) ptApiReg->get(#TYPE, TYPE ## _version) + //----------------------------------------------------------------------------- // [SECTION] api structs //----------------------------------------------------------------------------- @@ -84,10 +84,9 @@ typedef uint16_t plUiWChar; typedef struct _plApiRegistryI { - const void* (*add) (const char* name, const void* interface); + const void* (*set) (const char* name, plVersion, const void* interface, size_t interfaceSize); + const void* (*get) (const char* name, plVersion); void (*remove)(const void* interface); - const void* (*first) (const char* name); - const void* (*next) (const void* prevInterface); } plApiRegistryI; @@ -418,6 +417,13 @@ typedef struct _plAllocationEntry const char* pcFile; } plAllocationEntry; +typedef struct _plVersion +{ + uint32_t uMajor; + uint32_t uMinor; + uint32_t uPatch; +} plVersion; + //----------------------------------------------------------------------------- // [SECTION] defines //----------------------------------------------------------------------------- @@ -470,15 +476,6 @@ typedef struct _plAllocationEntry #define PL_ASSERT(x) assert((x)) #endif -// settings -#ifndef PL_MAX_NAME_LENGTH - #define PL_MAX_NAME_LENGTH 1024 -#endif - -#ifndef PL_MAX_PATH_LENGTH - #define PL_MAX_PATH_LENGTH 1024 -#endif - // log settings #ifndef PL_GLOBAL_LOG_LEVEL #define PL_GLOBAL_LOG_LEVEL PL_LOG_LEVEL_ALL diff --git a/src/pl_config.h b/src/pl_config.h index 46ffb0cf..2f9f5714 100644 --- a/src/pl_config.h +++ b/src/pl_config.h @@ -16,8 +16,9 @@ // general #define PL_MEMORY_TRACKING_ON #define PL_USE_STB_SPRINTF -//#define PL_MAX_NAME_LENGTH 1024 -//#define PL_MAX_PATH_LENGTH 1024 +#define PL_MAX_API_FUNCTIONS 256 +#define PL_MAX_NAME_LENGTH 1024 +#define PL_MAX_PATH_LENGTH 1024 // profiling #define PL_PROFILE_ON diff --git a/src/pl_internal.h b/src/pl_internal.h index 87165e5e..7ec4023b 100644 --- a/src/pl_internal.h +++ b/src/pl_internal.h @@ -174,6 +174,7 @@ void pl__unload_core_apis(void); void pl__check_for_leaks(void); void pl__garbage_collect_data_reg(void); void pl__load_os_apis(void); +bool pl__check_apis(void); //----------------------------------------------------------------------------- // [SECTION] helpers diff --git a/src/pl_main_macos.m b/src/pl_main_macos.m index 80c7f517..e2d91174 100644 --- a/src/pl_main_macos.m +++ b/src/pl_main_macos.m @@ -325,7 +325,7 @@ int main(int argc, char *argv[]) #endif // load library - const plLibraryI* ptLibraryApi = gptApiRegistry->first(PL_API_LIBRARY); + const plLibraryI* ptLibraryApi = pl_get_api(gptApiRegistry, plLibraryI); gptLibraryApi = ptLibraryApi; const plLibraryDesc tLibraryDesc = { .pcName = pcAppName @@ -345,7 +345,12 @@ int main(int argc, char *argv[]) } gpUserData = pl_app_load(gptApiRegistry, NULL); + bool bApisFound = pl__check_apis(); + if(!bApisFound) + return 3; } + else + return 2; #ifdef PL_HEADLESS_APP diff --git a/src/pl_main_win32.c b/src/pl_main_win32.c index 75801299..f8d1d254 100644 --- a/src/pl_main_win32.c +++ b/src/pl_main_win32.c @@ -261,7 +261,7 @@ int main(int argc, char *argv[]) } // load app library - const plLibraryI* ptLibraryApi = gptApiRegistry->first(PL_API_LIBRARY); + const plLibraryI* ptLibraryApi = pl_get_api(gptApiRegistry, plLibraryI); const plLibraryDesc tLibraryDesc = { .pcName = pcAppName }; @@ -278,9 +278,13 @@ int main(int argc, char *argv[]) if(!pl_app_info(gptApiRegistry)) return 0; } - gpUserData = pl_app_load(gptApiRegistry, NULL); + bool bApisFound = pl__check_apis(); + if(!bApisFound) + return 3; } + else + return 2; // main loop while (gptIOCtx->bRunning) diff --git a/src/pl_main_x11.c b/src/pl_main_x11.c index 4c370ced..cf68aec6 100644 --- a/src/pl_main_x11.c +++ b/src/pl_main_x11.c @@ -293,7 +293,7 @@ int main(int argc, char *argv[]) #endif // load library - const plLibraryI* ptLibraryApi = gptApiRegistry->first(PL_API_LIBRARY); + const plLibraryI* ptLibraryApi = pl_get_api(gptApiRegistry, plLibraryI); const plLibraryDesc tLibraryDesc = { .pcName = pcAppName }; @@ -311,7 +311,12 @@ int main(int argc, char *argv[]) return 0; } gpUserData = pl_app_load(gptApiRegistry, NULL); + bool bApisFound = pl__check_apis(); + if(!bApisFound) + return 3; } + else + return 2; // main loop while (gptIOCtx->bRunning) diff --git a/src/pl_os.h b/src/pl_os.h index 50b7191c..6764b0cb 100644 --- a/src/pl_os.h +++ b/src/pl_os.h @@ -25,26 +25,13 @@ Index of this file: // [SECTION] apis //----------------------------------------------------------------------------- -#define PL_API_WINDOW "PL_API_WINDOW" -typedef struct _plWindowI plWindowI; - -#define PL_API_LIBRARY "PL_API_LIBRARY" -typedef struct _plLibraryI plLibraryI; - -#define PL_API_FILE "PL_API_FILE" -typedef struct _plFileI plFileI; - -#define PL_API_NETWORK "PL_API_NETWORK" -typedef struct _plNetworkI plNetworkI; - -#define PL_API_THREADS "PL_API_THREADS" -typedef struct _plThreadsI plThreadsI; - -#define PL_API_ATOMICS "PL_API_ATOMICS" -typedef struct _plAtomicsI plAtomicsI; - -#define PL_API_VIRTUAL_MEMORY "PL_API_VIRTUAL_MEMORY" -typedef struct _plVirtualMemoryI plVirtualMemoryI; +#define plWindowI_version (plVersion){1, 0, 0} +#define plLibraryI_version (plVersion){1, 0, 0} +#define plFileI_version (plVersion){1, 0, 0} +#define plNetworkI_version (plVersion){1, 0, 0} +#define plThreadsI_version (plVersion){1, 0, 0} +#define plAtomicsI_version (plVersion){1, 0, 0} +#define plVirtualMemoryI_version (plVersion){1, 0, 0} //----------------------------------------------------------------------------- // [SECTION] includes @@ -58,6 +45,15 @@ typedef struct _plVirtualMemoryI plVirtualMemoryI; // [SECTION] forward declarations & basic types //----------------------------------------------------------------------------- +// apis +typedef struct _plWindowI plWindowI; +typedef struct _plLibraryI plLibraryI; +typedef struct _plFileI plFileI; +typedef struct _plNetworkI plNetworkI; +typedef struct _plThreadsI plThreadsI; +typedef struct _plAtomicsI plAtomicsI; +typedef struct _plVirtualMemoryI plVirtualMemoryI; + // types typedef struct _plWindow plWindow; typedef struct _plWindowDesc plWindowDesc;