Resource

Functions for managing resource types.

SResourceDescriptor()

Resource descriptor

Resource descriptor

MEMBERS

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


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.

PARAMETERS

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


Get(factory, name, resource)

Get a resource from factory

Get a resource from factory

PARAMETERS

factory - Factory handle

name - Resource name

resource - Created resource

RETURN

result - RESULT_OK on success


Get(factory, name, resource)

Get a resource from factory

Get a resource from factory

PARAMETERS

factory - Factory handle

name - Resource name

resource - Created resource

RETURN

result - RESULT_OK on success


Release(factory, resource)

Release resource

Release resource

PARAMETERS

factory - Factory handle

resource - Resource pointer


PreloadHint(factory, name)

Hint the preloader what to load before Create is c...

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

factory - Preloader handle

name - Resource name

RETURN

result - if successfully invoking preloader.


FDecryptResource

Returns the canonical path hash of a resource

Returns the canonical path hash of a resource

PARAMETERS

buffer - The input/output buffer

buffer_len - The size of the buffer (in bytes)

RETURN

RESULT_OK - on success


RegisterResourceDecryptionFunction(decrypt_resource)

Registers a custom resource decryption function

Registers a custom resource decryption function

PARAMETERS

decrypt_resource - The decryption function


AddFile(factory, path, size, resource)

Adds a file to the resource system Any request for...

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

factory - Factory handle

path - The path of the resource

size - The size of the resource (in bytes)

resource - The resource payload

RETURN

RESULT_OK - on success.


RemoveFile(factory, path)

Removes a previously registered file from the reso...

Removes a previously registered file from the resource system

PARAMETERS

factory - Factory handle

path - The path of the resource

RETURN

RESULT_OK - on success.