Skip to content

Commit

Permalink
refac: simplify core APIs for 1.0 & add platform backend helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Sep 26, 2024
1 parent de39e81 commit 91ece99
Show file tree
Hide file tree
Showing 6 changed files with 547 additions and 985 deletions.
84 changes: 35 additions & 49 deletions src/pl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Index of this file:
// [SECTION] apis
// [SECTION] includes
// [SECTION] forward declarations & basic types
// [SECTION] public api
// [SECTION] api structs
// [SECTION] enums
// [SECTION] IO struct
Expand All @@ -24,24 +23,25 @@ Index of this file:
#ifndef PL_H
#define PL_H

#define PILOT_LIGHT_VERSION "0.1.0"
#define PILOT_LIGHT_VERSION_NUM 001000
// framework version XYYZZ
#define PILOT_LIGHT_VERSION "1.0.0 WIP"
#define PILOT_LIGHT_VERSION_NUM 10000

//-----------------------------------------------------------------------------
// [SECTION] apis
//-----------------------------------------------------------------------------

typedef struct _plApiRegistryI plApiRegistryI;

#define PL_API_DATA_REGISTRY "PL_API_DATA_REGISTRY"
typedef struct _plDataRegistryI plDataRegistryI;

#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_DATA_REGISTRY "PL_API_DATA_REGISTRY"
typedef struct _plDataRegistryI plDataRegistryI;

#define PL_API_IO "PL_API_IO"
typedef struct _plIOI plIOI;

Expand All @@ -58,9 +58,6 @@ typedef struct _plIOI plIOI;
// [SECTION] forward declarations & basic types
//-----------------------------------------------------------------------------

// forward declarations
typedef void (*ptApiUpdateCallback)(const void*, const void*, void*);

// types
typedef struct _plAllocationEntry plAllocationEntry;
typedef struct _plDataObject plDataObject;
Expand All @@ -69,9 +66,6 @@ typedef struct _plIO plIO; // configuration & IO between ap
typedef struct _plKeyData plKeyData; // individual key status (down, down duration, etc.)
typedef struct _plInputEvent plInputEvent; // holds data for input events (opaque structure)

// external forward declarations
typedef struct plHashMap plHashMap; // pl_ds.h

// enums
typedef int plKey; // -> enum plKey_ // Enum: A key identifier (PL_KEY_XXX or PL_KEY_MOD_XXX value)
typedef int plMouseButton; // -> enum plMouseButton_ // Enum: A mouse button identifier (PL_MOUSE_BUTTON_XXX)
Expand All @@ -85,38 +79,42 @@ typedef int plKeyChord;
// character types
typedef uint16_t plUiWChar;

//-----------------------------------------------------------------------------
// [SECTION] public api
//-----------------------------------------------------------------------------

// API registry
const plApiRegistryI* pl_load_core_apis (void); // only called once by backend
void pl_unload_core_apis(void); // only called once by backend

//-----------------------------------------------------------------------------
// [SECTION] api structs
//-----------------------------------------------------------------------------

typedef struct _plApiRegistryI
{
const void* (*add) (const char* pcName, const void* pInterface);
void (*remove) (const void* pInterface);
void (*replace) (const void* pOldInterface, const void* pNewInterface);
void (*subscribe) (const void* pInterface, ptApiUpdateCallback, void* pUserData);
const void* (*first) (const char* pcName);
const void* (*next) (const void* pPrev);
const void* (*add) (const char* pcName, const void* pInterface);
void (*remove)(const void* pInterface);
const void* (*first) (const char* pcName);
const void* (*next) (const void* pPrevInterface);
} plApiRegistryI;

typedef struct _plExtensionRegistryI
{
bool (*load) (const char* pcName, const char* pcLoadFunc, const char* pcUnloadFunc, bool bReloadable);
bool (*unload)(const char* pcName);
} plExtensionRegistryI;

typedef struct _plMemoryI
{
void* (*realloc)(void*, size_t, const char* pcFile, int iLine);

// stats
size_t (*get_memory_usage)(void);
size_t (*get_allocation_count)(void);
size_t (*get_free_count)(void);
plAllocationEntry* (*get_allocations)(size_t* pszCount);
} plMemoryI;

typedef struct _plDataRegistryI
{

// for convience, only use for infrequent operations (i.e. global extension data)
void (*set_data)(const char* pcName, void* pData);
void* (*get_data)(const char* pcName);

// called by backend
void (*garbage_collect)(void);

//~~~~~~~~~~~~~~~~~~~~~~~~~do not use below here yet~~~~~~~~~~~~~~~~~~~~~~~~~~~

// future type system, current default type property 0 is a string (name) and property 1 is buffer (pointer)
Expand All @@ -139,26 +137,6 @@ typedef struct _plDataRegistryI
void (*commit) (plDataObject*);
} plDataRegistryI;

typedef struct _plExtensionRegistryI
{
void (*reload) (void);
void (*unload_all)(void);
bool (*load) (const char* pcName, const char* pcLoadFunc, const char* pcUnloadFunc, bool bReloadable);
bool (*unload) (const char* pcName);
} plExtensionRegistryI;

typedef struct _plMemoryI
{
void* (*realloc)(void*, size_t, const char* pcFile, int iLine);

// stats
size_t (*get_memory_usage)(void);
size_t (*get_allocation_count)(void);
size_t (*get_free_count)(void);
plAllocationEntry* (*get_allocations)(size_t* pszCount);
void (*check_for_leaks)(void);
} plMemoryI;

typedef struct _plIOI
{
void (*new_frame)(void);
Expand Down Expand Up @@ -342,6 +320,8 @@ typedef struct _plIO
int iArgc;
char** apArgv;

void* pBackendPlatformData;

//------------------------------------------------------------------
// Input/Output
//------------------------------------------------------------------
Expand Down Expand Up @@ -435,20 +415,26 @@ typedef struct _plAllocationEntry
#ifdef __cplusplus
#if defined(_MSC_VER) // Microsoft
#define PL_EXPORT extern "C" __declspec(dllexport)
#define PL_CALL_CONVENTION (__cdecl *)
#elif defined(__GNUC__) // GCC
#define PL_EXPORT extern "C" __attribute__((visibility("default")))
#define PL_CALL_CONVENTION (__attribute__(()) *)
#else // do nothing and hope for the best?
#define PL_EXPORT
#define PL_CALL_CONVENTION
#pragma warning Unknown dynamic link import/export semantics.
#endif
#else

#if defined(_MSC_VER) // Microsoft
#define PL_EXPORT __declspec(dllexport)
#define PL_CALL_CONVENTION (__cdecl *)
#elif defined(__GNUC__) // GCC
#define PL_EXPORT __attribute__((visibility("default")))
#define PL_CALL_CONVENTION (__attribute__(()) *)
#else // do nothing and hope for the best?
#define PL_EXPORT
#define PL_CALL_CONVENTION
#pragma warning Unknown dynamic link import/export semantics.
#endif
#endif
Expand Down
Loading

0 comments on commit 91ece99

Please sign in to comment.