Resource

Functions for managing resource types.

Namespace: dmResource
Include: #include <dmsdk/resource/resource.h>
TYPES
FDecryptResource Returns the canonical path hash of a resource
FUNCTIONS
 AddFile(dmResource::HFactory factory, const char* path, uint32_t size, const void* resource) Adds a file to the resource system Any request for...
dmResource::Result Get(dmResource::HFactory factory, const char* name, void** resource) Get a resource from factory
dmResource::Result Get(dmResource::HFactory factory, dmhash_t name, void** resource) Get a resource from factory
bool PreloadHint(dmResource::HPreloadHintInfo factory, const char* name) Hint the preloader what to load before Create is c...
void RegisterResourceDecryptionFunction(dmResource::FDecryptResource decrypt_resource) Registers a custom resource decryption function
void Release(dmResource::HFactory factory, void* resource) Release resource
 RemoveFile(dmResource::HFactory factory, const char* path) Removes a previously registered file from the reso...
void SResourceDescriptor() Resource descriptor
MACROS
DM_DECLARE_RESOURCE_TYPE(symbol, suffix, register_fn, deregister_fn) declare a new extension

Functions

AddFile

 AddFile(dmResource::HFactory factory, const char* path, uint32_t size, const void* resource)

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.

PARAMETERS

dmResource::HFactory factory Factory handle
const char* path The path of the resource
uint32_t size The size of the resource (in bytes)
const void* resource The resource payload

RETURNS

on success.

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

Get

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

Get a resource from factory

PARAMETERS

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

RETURNS

dmResource::Result RESULT_OK on success

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.

RegisterResourceDecryptionFunction

void RegisterResourceDecryptionFunction(dmResource::FDecryptResource decrypt_resource)

Registers a custom resource decryption function

PARAMETERS

dmResource::FDecryptResource decrypt_resource The decryption function

Release

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

Release resource

PARAMETERS

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

RemoveFile

 RemoveFile(dmResource::HFactory factory, const char* path)

Removes a previously registered file from the resource system

PARAMETERS

dmResource::HFactory factory Factory handle
const char* path The path of the resource

RETURNS

on success.

SResourceDescriptor

void SResourceDescriptor()

Resource descriptor

PARAMETERS


Types

FDecryptResource

Returns the canonical path hash of a resource


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