Functions for managing resource types.
Resource descriptor
m_NameHash - Hash of resource name
m_Resource - Resource pointer. Must be unique and not NULL.
m_PrevResource - Resource pointer. Resource pointer to a previous version of the resource, iff it exists. Only used when recreating resources.
m_ResourceSize - Resource size in memory. I.e. the payload of m_Resource
Declare and register new extension to the engine. This macro is used to declare the extension callback functions used by the engine to communicate with the extension.
symbol - external extension symbol description (no quotes).
suffix - The file resource suffix, without a ".".
register_fn - type register function
ctx
ResourceTypeRegisterContext
structure.deregister_fn - type deregister function. May be null.
ctx
ResourceTypeRegisterContext
structure.Register a new type:
static dmResource::Result ResourceTypeScriptCreate(...) {}
static dmResource::Result ResourceTypeScriptDestroy(...) {}
static dmResource::Result ResourceTypeScriptRecreate(...) {}
struct BlobContext
{
...
};
static dmResource::Result RegisterResourceTypeBlob(ResourceTypeRegisterContext& ctx)
{
// The engine.cpp creates the contexts for our built in types.
// Here we register a custom type
BlobContext* context = new BlobContext;
ctx.m_Contexts.Put(ctx.m_NameHash, (void*)context);
return dmResource::RegisterType(ctx.m_Factory,
ctx.m_Name,
context,
0,
ResourceTypeScriptCreate,
0,
ResourceTypeScriptDestroy,
ResourceTypeScriptRecreate);
}
static dmResource::Result DeregisterResourceTypeScript(ResourceTypeRegisterContext& ctx)
{
BlobContext** context = (BlobContext**)ctx.m_Contexts.Get(ctx.m_NameHash);
delete *context;
}
DM_DECLARE_RESOURCE_TYPE(ResourceTypeBlob, "blobc", RegisterResourceTypeBlob, DeregisterResourceTypeScript);
Get a resource from factory
factory - Factory handle
name - Resource name
resource - Created resource
result - RESULT_OK on success
Get a resource from factory
factory - Factory handle
name - Resource name
resource - Created resource
result - RESULT_OK on success
Release resource
factory - Factory handle
resource - Resource pointer
Hint the preloader what to load before Create is called on the resource. The resources are not guaranteed to be loaded before Create is called. This function can be called from a worker thread.
factory - Preloader handle
name - Resource name
result - if successfully invoking preloader.
Returns the canonical path hash of a resource
buffer - The input/output buffer
buffer_len - The size of the buffer (in bytes)
RESULT_OK - on success
Registers a custom resource decryption function
decrypt_resource - The decryption function
Adds a file to the resource system Any request for this path will go through any existing mounts first. If you wish to provide file overrides, please use the LiveUpdate feature for that. The file isn't persisted between sessions.
factory - Factory handle
path - The path of the resource
size - The size of the resource (in bytes)
resource - The resource payload
RESULT_OK - on success.
Removes a previously registered file from the resource system
factory - Factory handle
path - The path of the resource
RESULT_OK - on success.