Resource

Functions for managing resource types.

Namespace: Resource
Include: #include <dmsdk/resource/resource_doc.h>
TYPES
FResourceCreate Resource create function
FResourceDestroy Resource destroy function
FResourcePostCreate Resource postcreate function
FResourcePreload Resource preloading function. This may be called f...
FResourceRecreate Resource recreate function. Recreate resource in-p...
FResourceTypeDeregister Resource type destroy function. Generally used to ...
FResourceTypeRegister Resource type setup function.
FUNCTIONS
dmhash_t ResourceDescriptorGetNameHash(HResourceDescriptor rd) get path hash of resource
void* ResourceDescriptorGetPrevResource(HResourceDescriptor rd) get the previous resource data
void* ResourceDescriptorGetResource(HResourceDescriptor rd) get the resource data
uint32_t ResourceDescriptorGetResourceSize(HResourceDescriptor rd) get the resource data size
HResourceType ResourceDescriptorGetType(HResourceDescriptor rd) get the resource type
void ResourceDescriptorSetPrevResource(HResourceDescriptor rd, void* resource) set the previous resource data
void ResourceDescriptorSetResource(HResourceDescriptor rd, void* resource) set the resource data
void ResourceDescriptorSetResourceSize(HResourceDescriptor rd, uint32_t size) set the resource data size
void* ResourceTypeGetContext(HResourceType type) get context from type
const char* ResourceTypeGetName(HResourceType type) get registered extension name of the type
dmhash_t ResourceTypeGetNameHash(HResourceType type) get registered extension name hash of the type
void ResourceTypeSetContext(HResourceType type, void* context) set context from type
void ResourceTypeSetCreateFn(HResourceType type, FResourceCreate fn) set create function for type
void ResourceTypeSetDestroyFn(HResourceType type, FResourceDestroy fn) set destroy function for type
void ResourceTypeSetPostCreateFn(HResourceType type, FResourcePostCreate fn) set post create function for type
void ResourceTypeSetPreloadFn(HResourceType type, FResourcePreload fn) set preload function for type
void ResourceTypeSetRecreateFn(HResourceType type, FResourceRecreate fn) set recreate function for type
MACROS
DM_DECLARE_RESOURCE_TYPE(symbol, suffix, register_fn, deregister_fn) declare a new resource type

Functions

ResourceDescriptorGetNameHash

dmhash_t ResourceDescriptorGetNameHash(HResourceDescriptor rd)

get path hash of resource

PARAMETERS

HResourceDescriptor rd The resource

RETURNS

dmhash_t The path hash

ResourceDescriptorGetPrevResource

void* ResourceDescriptorGetPrevResource(HResourceDescriptor rd)

get the previous resource data

PARAMETERS

HResourceDescriptor rd The resource handle

RETURNS

void* The resource data

ResourceDescriptorGetResource

void* ResourceDescriptorGetResource(HResourceDescriptor rd)

get the resource data

PARAMETERS

HResourceDescriptor rd The resource handle

RETURNS

void* The resource data

ResourceDescriptorGetResourceSize

uint32_t ResourceDescriptorGetResourceSize(HResourceDescriptor rd)

get the resource data size

PARAMETERS

HResourceDescriptor rd The resource handle

RETURNS

uint32_t The resource data size (in bytes)

ResourceDescriptorGetType

HResourceType ResourceDescriptorGetType(HResourceDescriptor rd)

get the resource type

PARAMETERS

HResourceDescriptor rd The resource handle

RETURNS

HResourceType The resource type

ResourceDescriptorSetPrevResource

void ResourceDescriptorSetPrevResource(HResourceDescriptor rd, void* resource)

set the previous resource data

PARAMETERS

HResourceDescriptor rd The resource handle
void* resource The resource data

ResourceDescriptorSetResource

void ResourceDescriptorSetResource(HResourceDescriptor rd, void* resource)

set the resource data

PARAMETERS

HResourceDescriptor rd The resource handle
void* resource The resource data

ResourceDescriptorSetResourceSize

void ResourceDescriptorSetResourceSize(HResourceDescriptor rd, uint32_t size)

set the resource data size

PARAMETERS

HResourceDescriptor rd The resource handle
uint32_t size The resource data size (in bytes)

ResourceTypeGetContext

void* ResourceTypeGetContext(HResourceType type)

get context from type

PARAMETERS

HResourceType type The type

RETURNS

void* 0 if no context was registered

ResourceTypeGetName

const char* ResourceTypeGetName(HResourceType type)

get registered extension name of the type

PARAMETERS

HResourceType type The type

RETURNS

const char* The name of the type (e.g. "collectionc")

ResourceTypeGetNameHash

dmhash_t ResourceTypeGetNameHash(HResourceType type)

get registered extension name hash of the type

PARAMETERS

HResourceType type The type

RETURNS

dmhash_t The name hash

ResourceTypeSetContext

void ResourceTypeSetContext(HResourceType type, void* context)

set context from type

PARAMETERS

HResourceType type The type
void* context The context to associate with the type

ResourceTypeSetCreateFn

void ResourceTypeSetCreateFn(HResourceType type, FResourceCreate fn)

set create function for type

PARAMETERS

HResourceType type The type
FResourceCreate fn Function to be called to creating the resource

ResourceTypeSetDestroyFn

void ResourceTypeSetDestroyFn(HResourceType type, FResourceDestroy fn)

set destroy function for type

PARAMETERS

HResourceType type The type
FResourceDestroy fn Function to be called to destroy the resource

ResourceTypeSetPostCreateFn

void ResourceTypeSetPostCreateFn(HResourceType type, FResourcePostCreate fn)

set post create function for type

PARAMETERS

HResourceType type The type
FResourcePostCreate fn Function to be called after creating the resource

ResourceTypeSetPreloadFn

void ResourceTypeSetPreloadFn(HResourceType type, FResourcePreload fn)

set preload function for type

PARAMETERS

HResourceType type The type
FResourcePreload fn Function to be called when loading of the resource starts

ResourceTypeSetRecreateFn

void ResourceTypeSetRecreateFn(HResourceType type, FResourceRecreate fn)

set recreate function for type

PARAMETERS

HResourceType type The type
FResourceRecreate fn Function to be called when recreating the resource

Types

FResourceCreate

Resource create function


FResourceDestroy

Resource destroy function


FResourcePostCreate

Resource postcreate function


FResourcePreload

Resource preloading function. This may be called from a separate loading thread but will not keep any mutexes held while executing the call. During this call PreloadHint can be called with the supplied hint_info handle. If RESULT_OK is returned, the resource Create function is guaranteed to be called with the preload_data value supplied.


FResourceRecreate

Resource recreate function. Recreate resource in-place.


FResourceTypeDeregister

Resource type destroy function. Generally used to destroy the registered resource type context.


FResourceTypeRegister

Resource type setup function.


Macros

DM_DECLARE_RESOURCE_TYPE

Declare and register new resource type to the engine. This macro is used to declare the resource type 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:
#include <dmsdk/resource/resource_params.h>
#include <dmsdk/resource/resource_type.h>

static ResourceResult MyResourceTypeScriptCreate(const ResourceCreateParams* params) {}
static ResourceResult MyResourceTypeScriptDestroy(const ResourceDestroyParams* params) {}
static ResourceResult MyResourceTypeScriptRecreate(const ResourceRereateParams* params) {}

struct MyContext
{
    // ...
};

static ResourceResult RegisterResourceTypeBlob(HResourceTypeContext ctx, HResourceType type)
{
    // The engine.cpp creates the contexts for our built in types.
    // Here we register a custom type
    MyContext* context = new MyContext;

    ResourceTypeSetContext(type, (void*)context);
    ResourceTypeSetCreateFn(type, MyResourceTypeScriptCreate);
    ResourceTypeSetDestroyFn(type, MyResourceTypeScriptDestroy);
    ResourceTypeSetRecreateFn(type, MyResourceTypeScriptRecreate);
}

static ResourceResult DeregisterResourceTypeBlob(HResourceTypeContext ctx, HResourceType type)
{
    MyContext** context = (MyContext*)ResourceTypeGetContext(type);
    delete *context;
}

DM_DECLARE_RESOURCE_TYPE(ResourceTypeBlob, "blobc", RegisterResourceTypeBlob, DeregisterResourceTypeBlob);