Resource

Functions for managing resource types.

Namespace: dmResource
Include: #include <dmsdk/resource/resource.h>
MACROS
DM_DECLARE_RESOURCE_TYPE(symbol, suffix, register_fn, deregister_fn) declare a new extension

Macros

DM_DECLARE_RESOURCE_TYPE

declare a new extension

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
dmResource::ResourceTypeRegisterContext& Reference to an ResourceTypeRegisterContext structure.
deregister_fn type deregister function. May be null.
ctx
dmResource::ResourceTypeRegisterContext& Reference to an ResourceTypeRegisterContext structure.

EXAMPLES

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);