Resource

Namespace: dmResource Language: C++ Type: Defold C++ File: resource_gen.hpp Source: engine/resource/src/dmsdk/resource/resource_gen.hpp Include: dmsdk/resource/resource_gen.hpp

Functions for managing resource types.

API

AddFile

Type: FUNCTION 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

Returns

DM_DECLARE_RESOURCE_TYPE

Type: MACRO 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.

Examples

Register a new type:

#include
#include

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

struct MyContext
{
    // ...
};

static ResourceResult RegisterResourceTypeBlob(HResourceTypeRegisterContext 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(ResourceTypeRegisterContext& ctx)
{
    MyContext** context = (MyContext*)ResourceTypeGetContext(type);
    delete *context;
}

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

FReloadedCallback

Type: FUNCTION Function called when a resource has been reloaded.

FResourceDecrypt

Type: TYPEDEF Encrypts a resource in-place

Parameters

Returns

FResourceReloadedCallback

Type: FUNCTION Function called when a resource has been reloaded.

Get

Type: FUNCTION Get a resource from factory

Parameters

Returns

GetByHash

Type: FUNCTION Get a resource from factory

Parameters

Returns

GetDescriptor

Type: FUNCTION Get resource descriptor from resource (name)

Parameters

Returns

GetDescriptorByHash

Type: FUNCTION Get resource descriptor from resource (name)

Parameters

Returns

GetPath

Type: FUNCTION Returns the canonical path hash of a resource

Parameters

Returns

GetRaw

Type: FUNCTION Get raw resource data. Unregistered resources can be loaded with this function. If successful, the returned resource data must be deallocated with free()

Parameters

Returns

HDescriptor

Type: TYPEDEF Holds information about a currently loaded resource.

HFactory

Type: TYPEDEF Resource factory handle. Holds references to all currently loaded resources.

HPreloadHintInfo

Type: TYPEDEF Holds information about preloading resources

HResourceDescriptor

Type: TYPEDEF Holds information about a currently loaded resource.

HResourceFactory

Type: TYPEDEF Resource factory handle. Holds references to all currently loaded resources.

HResourcePreloadHintInfo

Type: TYPEDEF Holds information about preloading resources

HResourceType

Type: TYPEDEF Represents a resource type, with a context and type functions for creation and destroying a resource.

HResourceTypeContext

Type: TYPEDEF Holds the resource types, as well as extra in engine contexts that can be shared across type functions.

PreloadHint

Type: FUNCTION 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

Returns

Release

Type: FUNCTION Release resource

Notes

Parameters

RemoveFile

Type: FUNCTION Removes a previously registered file from the resource system

Parameters

Returns

ResourceAddFile

Type: FUNCTION 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

Returns

ResourceCreateParams

Type: FUNCTION Parameters to ResourceCreate function of the resource type

ResourceDestroyParams

Type: FUNCTION Parameters to ResourceDestroy function of the resource type

ResourceGet

Type: FUNCTION Get a resource from factory

Parameters

Returns

ResourceGetByHash

Type: FUNCTION Get a resource from factory

Parameters

Returns

ResourceGetPath

Type: FUNCTION Returns the canonical path hash of a resource

Parameters

Returns

ResourceGetRaw

Type: FUNCTION Get raw resource data. Unregistered resources can be loaded with this function. If successful, the returned resource data must be deallocated with free()

Parameters

Returns

ResourcePostCreateParams

Type: FUNCTION Parameters to ResourcePostCreate function of the resource type

ResourcePreloadHint

Type: FUNCTION 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

Returns

ResourcePreloadParams

Type: FUNCTION Parameters to ResourcePreload function of the resource type

ResourceRecreateParams

Type: FUNCTION Parameters to ResourceRecreate function of the resource type

ResourceRegisterDecryptionFunction

Type: FUNCTION Registers a custom resource decryption function

Parameters

ResourceRelease

Type: FUNCTION Release resource

Notes

Parameters

ResourceReloadedParams

Type: FUNCTION Parameters to ResourceReloaded function of the resource type

ResourceReloadedParams

Type: FUNCTION Parameters to ResourceReloaded function of the resource type

ResourceRemoveFile

Type: FUNCTION Removes a previously registered file from the resource system

Parameters

Returns

ResourceResult

Type: ENUM ResourceResult

Members

ResourceTypeCreatorDescBufferSize

Type: FUNCTION Resource type creator desc byte size declaration. The registered description data passeed to ResourceRegisterTypeCreatorDesc must be of at least this size.

Result

Type: ENUM ResourceResult

Members