Resource

Functions for managing resource types.

Namespace: dmResource
Include: #include <dmsdk/resource/resource.h>
FUNCTIONS
void SResourceDescriptor() Resource descriptor
dmResource::Result Get(dmResource::HFactory factory, const char* name, void** resource) Get a resource from factory
void Release(dmResource::HFactory factory, void* resource) Release resource
bool PreloadHint(dmResource::HPreloadHintInfo factory, const char* name) Hint the preloader what to load before Create is c...
MACROS
DM_DECLARE_RESOURCE_TYPE(symbol, suffix, register_fn, deregister_fn) declare a new extension

Functions

SResourceDescriptor

void SResourceDescriptor()

Resource descriptor

PARAMETERS


Get

dmResource::Result Get(dmResource::HFactory factory, const char* name, void** resource)

Get a resource from factory

PARAMETERS

dmResource::HFactory factory Factory handle
const char* name Resource name
void** resource Created resource

RETURNS

dmResource::Result RESULT_OK on success

Release

void Release(dmResource::HFactory factory, void* resource)

Release resource

PARAMETERS

dmResource::HFactory factory Factory handle
void* resource Resource pointer

PreloadHint

bool PreloadHint(dmResource::HPreloadHintInfo factory, const char* name)

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.

PARAMETERS

dmResource::HPreloadHintInfo factory Preloader handle
const char* name Resource name

RETURNS

bool if successfully invoking preloader.

Macros

DM_DECLARE_RESOURCE_TYPE

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