Skip to content

Commit

Permalink
Updated to Defold 1.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JCash committed Jun 11, 2024
1 parent c442096 commit 71ea8ce
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 95 deletions.
13 changes: 7 additions & 6 deletions defold-rive/src/comp_rive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace dmRive

static float g_DisplayFactor = 1.0f;

static void ResourceReloadedCallback(const dmResource::ResourceReloadedParams& params);
static void ResourceReloadedCallback(const dmResource::ResourceReloadedParams* params);
static void DestroyComponent(struct RiveWorld* world, uint32_t index);
static void CompRiveAnimationReset(RiveComponent* component);
static bool CreateBones(struct RiveWorld* world, RiveComponent* component);
Expand Down Expand Up @@ -1222,9 +1222,9 @@ namespace dmRive
return dmGameSystem::SetMaterialConstant(GetMaterial(component, component->m_Resource), params.m_PropertyId, params.m_Value, params.m_Options.m_Index, CompRiveSetConstantCallback, component);
}

static void ResourceReloadedCallback(const dmResource::ResourceReloadedParams& params)
static void ResourceReloadedCallback(const dmResource::ResourceReloadedParams* params)
{
RiveWorld* world = (RiveWorld*) params.m_UserData;
RiveWorld* world = (RiveWorld*) params->m_UserData;
dmArray<RiveComponent*>& components = world->m_Components.GetRawObjects();
uint32_t n = components.Size();
for (uint32_t i = 0; i < n; ++i)
Expand All @@ -1234,9 +1234,10 @@ namespace dmRive
if (!component->m_Enabled || !resource)
continue;

if (resource == params.m_Resource->m_Resource ||
resource->m_Scene == params.m_Resource->m_Resource ||
resource->m_Scene->m_Scene == params.m_Resource->m_Resource)
void* current_resource = dmResource::GetResource(params->m_Resource);
if (resource == current_resource ||
resource->m_Scene == current_resource ||
resource->m_Scene->m_Scene == current_resource)
{
OnResourceReloaded(world, component, i);
}
Expand Down
67 changes: 32 additions & 35 deletions defold-rive/src/res_rive_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ namespace dmRive
}
}

static dmResource::Result ResourceType_RiveData_Create(const dmResource::ResourceCreateParams& params)
static dmResource::Result ResourceType_RiveData_Create(const dmResource::ResourceCreateParams* params)
{
HRenderContext render_context_res = (HRenderContext) params.m_Context;
HRenderContext render_context_res = (HRenderContext) params->m_Context;

rive::Factory* rive_factory = GetRiveFactory(render_context_res);

rive::Span<const uint8_t> data((const uint8_t*)params.m_Buffer, params.m_BufferSize);
rive::Span<const uint8_t> data((const uint8_t*)params->m_Buffer, params->m_BufferSize);

// Creates DefoldRenderImage with a hashed name for each image resource
AtlasNameResolver atlas_resolver = AtlasNameResolver(render_context_res);
Expand All @@ -87,16 +87,16 @@ namespace dmRive

if (result != rive::ImportResult::success)
{
params.m_Resource->m_Resource = 0;
return dmResource::RESULT_INVALID_DATA;
dmResource::SetResource(params->m_Resource, 0);
return dmResource::RESULT_INVALID_DATA;
}

RiveSceneData* scene_data = new RiveSceneData();

SetupData(scene_data, file.release(), params.m_Filename, render_context_res);
SetupData(scene_data, file.release(), params->m_Filename, render_context_res);

params.m_Resource->m_Resource = (void*) scene_data;
params.m_Resource->m_ResourceSize = 0;
dmResource::SetResource(params->m_Resource, scene_data);
dmResource::SetResourceSize(params->m_Resource, 0);

return dmResource::RESULT_OK;
}
Expand All @@ -107,17 +107,17 @@ namespace dmRive
delete scene_data;
}

static dmResource::Result ResourceType_RiveData_Destroy(const dmResource::ResourceDestroyParams& params)
static dmResource::Result ResourceType_RiveData_Destroy(const dmResource::ResourceDestroyParams* params)
{
RiveSceneData* scene_data = (RiveSceneData*)params.m_Resource->m_Resource;
RiveSceneData* scene_data = (RiveSceneData*)dmResource::GetResource(params->m_Resource);
DeleteData(scene_data);
return dmResource::RESULT_OK;
}

static dmResource::Result ResourceType_RiveData_Recreate(const dmResource::ResourceRecreateParams& params)
static dmResource::Result ResourceType_RiveData_Recreate(const dmResource::ResourceRecreateParams* params)
{
HRenderContext render_context_res = (HRenderContext) params.m_Context;
rive::Span<uint8_t> data((uint8_t*)params.m_Buffer, params.m_BufferSize);
HRenderContext render_context_res = (HRenderContext) params->m_Context;
rive::Span<uint8_t> data((uint8_t*)params->m_Buffer, params->m_BufferSize);

rive::Factory* rive_factory = GetRiveFactory(render_context_res);

Expand All @@ -135,46 +135,43 @@ namespace dmRive
return dmResource::RESULT_INVALID_DATA;
}

if (params.m_Resource->m_Resource != 0)
RiveSceneData* old_data = (RiveSceneData*)dmResource::GetResource(params->m_Resource);
if (old_data != 0)
{
RiveSceneData* data = (RiveSceneData*) params.m_Resource->m_Resource;
params.m_Resource->m_Resource = 0;
DeleteData(data);
dmResource::SetResource(params->m_Resource, 0);
DeleteData(old_data);
}

RiveSceneData* scene_data = new RiveSceneData();

SetupData(scene_data, file.release(), params.m_Filename, render_context_res);
SetupData(scene_data, file.release(), params->m_Filename, render_context_res);

params.m_Resource->m_Resource = (void*) scene_data;
params.m_Resource->m_ResourceSize = 0;
dmResource::SetResource(params->m_Resource, scene_data);
dmResource::SetResourceSize(params->m_Resource, 0);

return dmResource::RESULT_OK;
}

static dmResource::Result RegisterResourceType_RiveData(dmResource::ResourceTypeRegisterContext& ctx)
static ResourceResult RegisterResourceType_RiveData(HResourceTypeContext ctx, HResourceType type)
{
HRenderContext rive_render_context = NewRenderContext();

ctx.m_Contexts->Put(ctx.m_NameHash, rive_render_context);
return dmResource::RegisterType(ctx.m_Factory,
ctx.m_Name,
rive_render_context,
0, // preload
ResourceType_RiveData_Create,
0, // post create
ResourceType_RiveData_Destroy,
ResourceType_RiveData_Recreate);
return (ResourceResult)dmResource::SetupType(ctx,
type,
rive_render_context,
0, // preload
ResourceType_RiveData_Create,
0, // post create
ResourceType_RiveData_Destroy,
ResourceType_RiveData_Recreate);

}

static dmResource::Result DeregisterResourceType_RiveData(dmResource::ResourceTypeRegisterContext& ctx)
static ResourceResult DeregisterResourceType_RiveData(HResourceTypeContext ctx, HResourceType type)
{
HRenderContext* context = (HRenderContext*) ctx.m_Contexts->Get(ctx.m_NameHash);
HRenderContext context = (HRenderContext)ResourceTypeGetContext(type);
DeleteRenderContext(context);

// delete *context;
return dmResource::RESULT_OK;
return RESOURCE_RESULT_OK;
}
}

Expand Down
54 changes: 27 additions & 27 deletions defold-rive/src/res_rive_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,71 +46,71 @@ namespace dmRive
dmResource::Release(factory, resource->m_Material);
}

static dmResource::Result ResourceType_RiveModel_Preload(const dmResource::ResourcePreloadParams& params)
static dmResource::Result ResourceType_RiveModel_Preload(const dmResource::ResourcePreloadParams* params)
{
dmRiveDDF::RiveModelDesc* ddf;
dmDDF::Result e = dmDDF::LoadMessage(params.m_Buffer, params.m_BufferSize, &dmRiveDDF_RiveModelDesc_DESCRIPTOR, (void**) &ddf);
dmDDF::Result e = dmDDF::LoadMessage(params->m_Buffer, params->m_BufferSize, &dmRiveDDF_RiveModelDesc_DESCRIPTOR, (void**) &ddf);
if (e != dmDDF::RESULT_OK)
{
return dmResource::RESULT_DDF_ERROR;
}

dmResource::PreloadHint(params.m_HintInfo, ddf->m_Scene); // the .rivescenec file
dmResource::PreloadHint(params.m_HintInfo, ddf->m_Material);
dmResource::PreloadHint(params->m_HintInfo, ddf->m_Scene); // the .rivescenec file
dmResource::PreloadHint(params->m_HintInfo, ddf->m_Material);

*params.m_PreloadData = ddf;
*params->m_PreloadData = ddf;
return dmResource::RESULT_OK;
}

static dmResource::Result ResourceType_RiveModel_Create(const dmResource::ResourceCreateParams& params)
static dmResource::Result ResourceType_RiveModel_Create(const dmResource::ResourceCreateParams* params)
{
RiveModelResource* resource = new RiveModelResource();
resource->m_DDF = (dmRiveDDF::RiveModelDesc*) params.m_PreloadData;
dmResource::Result r = AcquireResources(params.m_Factory, resource, params.m_Filename);
resource->m_DDF = (dmRiveDDF::RiveModelDesc*) params->m_PreloadData;
dmResource::Result r = AcquireResources(params->m_Factory, resource, params->m_Filename);
if (r == dmResource::RESULT_OK)
{
params.m_Resource->m_Resource = (void*) resource;
dmResource::SetResource(params->m_Resource, resource);
}
else
{
ReleaseResources(params.m_Factory, resource);
ReleaseResources(params->m_Factory, resource);
delete resource;
}
return r;
}

static dmResource::Result ResourceType_RiveModel_Destroy(const dmResource::ResourceDestroyParams& params)
static dmResource::Result ResourceType_RiveModel_Destroy(const dmResource::ResourceDestroyParams* params)
{
RiveModelResource* resource = (RiveModelResource*)params.m_Resource->m_Resource;
ReleaseResources(params.m_Factory, resource);
RiveModelResource* resource = (RiveModelResource*)dmResource::GetResource(params->m_Resource);
ReleaseResources(params->m_Factory, resource);
delete resource;
return dmResource::RESULT_OK;
}

static dmResource::Result ResourceType_RiveModel_Recreate(const dmResource::ResourceRecreateParams& params)
static dmResource::Result ResourceType_RiveModel_Recreate(const dmResource::ResourceRecreateParams* params)
{
dmRiveDDF::RiveModelDesc* ddf;
dmDDF::Result e = dmDDF::LoadMessage(params.m_Buffer, params.m_BufferSize, &dmRiveDDF_RiveModelDesc_DESCRIPTOR, (void**) &ddf);
dmDDF::Result e = dmDDF::LoadMessage(params->m_Buffer, params->m_BufferSize, &dmRiveDDF_RiveModelDesc_DESCRIPTOR, (void**) &ddf);
if (e != dmDDF::RESULT_OK)
{
return dmResource::RESULT_DDF_ERROR;
}
RiveModelResource* resource = (RiveModelResource*)params.m_Resource->m_Resource;
ReleaseResources(params.m_Factory, resource);
RiveModelResource* resource = (RiveModelResource*)dmResource::GetResource(params->m_Resource);
ReleaseResources(params->m_Factory, resource);
resource->m_DDF = ddf;
return AcquireResources(params.m_Factory, resource, params.m_Filename);
return AcquireResources(params->m_Factory, resource, params->m_Filename);
}

static dmResource::Result RegisterResourceType_RiveModel(dmResource::ResourceTypeRegisterContext& ctx)
static ResourceResult RegisterResourceType_RiveModel(HResourceTypeContext ctx, HResourceType type)
{
return dmResource::RegisterType(ctx.m_Factory,
ctx.m_Name,
0, // context
ResourceType_RiveModel_Preload,
ResourceType_RiveModel_Create,
0, // post create
ResourceType_RiveModel_Destroy,
ResourceType_RiveModel_Recreate);
return (ResourceResult)dmResource::SetupType(ctx,
type,
0, // context
ResourceType_RiveModel_Preload,
ResourceType_RiveModel_Create,
0, // post create
ResourceType_RiveModel_Destroy,
ResourceType_RiveModel_Recreate);

}
}
Expand Down
54 changes: 27 additions & 27 deletions defold-rive/src/res_rive_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,76 +57,76 @@ namespace dmRive
ReleaseShaders(factory, &resource->m_Shaders);
}

static dmResource::Result ResourceTypePreload(const dmResource::ResourcePreloadParams& params)
static dmResource::Result ResourceTypePreload(const dmResource::ResourcePreloadParams* params)
{
dmRiveDDF::RiveSceneDesc* ddf;
dmDDF::Result e = dmDDF::LoadMessage(params.m_Buffer, params.m_BufferSize, &dmRiveDDF_RiveSceneDesc_DESCRIPTOR, (void**) &ddf);
dmDDF::Result e = dmDDF::LoadMessage(params->m_Buffer, params->m_BufferSize, &dmRiveDDF_RiveSceneDesc_DESCRIPTOR, (void**) &ddf);
if (e != dmDDF::RESULT_OK)
{
return dmResource::RESULT_DDF_ERROR;
}

dmResource::PreloadHint(params.m_HintInfo, ddf->m_Scene); // the .riv file
dmResource::PreloadHint(params->m_HintInfo, ddf->m_Scene); // the .riv file

// Will throw error if we don't check this here
if (ddf->m_Atlas[0] != 0)
{
dmResource::PreloadHint(params.m_HintInfo, ddf->m_Atlas);
dmResource::PreloadHint(params->m_HintInfo, ddf->m_Atlas);
}

*params.m_PreloadData = ddf;
*params->m_PreloadData = ddf;
return dmResource::RESULT_OK;
}

static dmResource::Result ResourceTypeCreate(const dmResource::ResourceCreateParams& params)
static dmResource::Result ResourceTypeCreate(const dmResource::ResourceCreateParams* params)
{
RiveSceneResource* resource = new RiveSceneResource();
resource->m_DDF = (dmRiveDDF::RiveSceneDesc*) params.m_PreloadData;
dmResource::Result r = AcquireResources(params.m_Factory, resource, params.m_Filename);
resource->m_DDF = (dmRiveDDF::RiveSceneDesc*) params->m_PreloadData;
dmResource::Result r = AcquireResources(params->m_Factory, resource, params->m_Filename);
if (r == dmResource::RESULT_OK)
{
params.m_Resource->m_Resource = (void*) resource;
dmResource::SetResource(params->m_Resource, resource);
}
else
{
ReleaseResources(params.m_Factory, resource);
ReleaseResources(params->m_Factory, resource);
delete resource;
}
return r;
}

static dmResource::Result ResourceTypeDestroy(const dmResource::ResourceDestroyParams& params)
static dmResource::Result ResourceTypeDestroy(const dmResource::ResourceDestroyParams* params)
{
RiveSceneResource* resource = (RiveSceneResource*)params.m_Resource->m_Resource;
ReleaseResources(params.m_Factory, resource);
RiveSceneResource* resource = (RiveSceneResource*)dmResource::GetResource(params->m_Resource);
ReleaseResources(params->m_Factory, resource);
delete resource;
return dmResource::RESULT_OK;
}

static dmResource::Result ResourceTypeRecreate(const dmResource::ResourceRecreateParams& params)
static dmResource::Result ResourceTypeRecreate(const dmResource::ResourceRecreateParams* params)
{
dmRiveDDF::RiveSceneDesc* ddf;
dmDDF::Result e = dmDDF::LoadMessage(params.m_Buffer, params.m_BufferSize, &dmRiveDDF_RiveSceneDesc_DESCRIPTOR, (void**) &ddf);
dmDDF::Result e = dmDDF::LoadMessage(params->m_Buffer, params->m_BufferSize, &dmRiveDDF_RiveSceneDesc_DESCRIPTOR, (void**) &ddf);
if (e != dmDDF::RESULT_OK)
{
return dmResource::RESULT_DDF_ERROR;
}
RiveSceneResource* resource = (RiveSceneResource*)params.m_Resource->m_Resource;
ReleaseResources(params.m_Factory, resource);
RiveSceneResource* resource = (RiveSceneResource*)dmResource::GetResource(params->m_Resource);
ReleaseResources(params->m_Factory, resource);
resource->m_DDF = ddf;
return AcquireResources(params.m_Factory, resource, params.m_Filename);
return AcquireResources(params->m_Factory, resource, params->m_Filename);
}

static dmResource::Result RegisterResourceType(dmResource::ResourceTypeRegisterContext& ctx)
static ResourceResult RegisterResourceType(HResourceTypeContext ctx, HResourceType type)
{
return dmResource::RegisterType(ctx.m_Factory,
ctx.m_Name,
0, // context
ResourceTypePreload,
ResourceTypeCreate,
0, // post create
ResourceTypeDestroy,
ResourceTypeRecreate);
return (ResourceResult)dmResource::SetupType(ctx,
type,
0, // context
ResourceTypePreload,
ResourceTypeCreate,
0, // post create
ResourceTypeDestroy,
ResourceTypeRecreate);

}
}
Expand Down

0 comments on commit 71ea8ce

Please sign in to comment.