Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to defold 1.9.0 #177

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions defold-spine/src/comp_spine_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" {
#include <dmsdk/gameobject/component.h>
#include <dmsdk/gamesys/property.h>
#include <dmsdk/gamesys/resources/res_textureset.h>
#include <dmsdk/resource/resource.h>
#include <dmsdk/resource/resource.hpp>
#include <gameobject/gameobject_ddf.h>

#include <common/vertices.h>
Expand All @@ -67,7 +67,7 @@ namespace dmSpine

static const uint32_t INVALID_ANIMATION_INDEX = 0xFFFFFFFF;

static void ResourceReloadedCallback(const dmResource::ResourceReloadedParams& params);
static void ResourceReloadedCallback(const dmResource::ResourceReloadedParams* params);
static void DestroyComponent(struct SpineModelWorld* world, uint32_t index);

struct SpineModelWorld
Expand Down Expand Up @@ -1314,7 +1314,7 @@ namespace dmSpine
return dmGameSystem::SetMaterialConstant(GetMaterial(component), params.m_PropertyId, params.m_Value, params.m_Options.m_Index, CompSpineModelSetConstantCallback, component);
}

static void ResourceReloadedCallback(const dmResource::ResourceReloadedParams& params)
static void ResourceReloadedCallback(const dmResource::ResourceReloadedParams* params)
{
// E.g. if the Spine json or atlas has changed, we may need to update things here

Expand Down
44 changes: 25 additions & 19 deletions defold-spine/src/res_spine_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
#include <string.h>
#include <stdio.h>

#ifdef __MACH__
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif

#include <dmsdk/dlib/log.h>
#include <dmsdk/resource/resource.h>

Expand Down Expand Up @@ -31,35 +37,35 @@ namespace dmSpine
delete resource;
}

static dmResource::Result ResourceTypeJson_Create(const dmResource::ResourceCreateParams& params)
static dmResource::Result ResourceTypeJson_Create(const dmResource::ResourceCreateParams* params)
{
SpineJsonResource* resource = CreateResource(params.m_Buffer, params.m_BufferSize);
SpineJsonResource* resource = CreateResource(params->m_Buffer, params->m_BufferSize);
if (!resource)
{
return dmResource::RESULT_OUT_OF_RESOURCES;
}

params.m_Resource->m_Resource = (void*)resource;
params.m_Resource->m_ResourceSize = resource->m_Length;
dmResource::SetResource(params->m_Resource, resource);
dmResource::SetResourceSize(params->m_Resource, resource->m_Length);
return dmResource::RESULT_OK;
}

static dmResource::Result ResourceTypeJson_Destroy(const dmResource::ResourceDestroyParams& params)
static dmResource::Result ResourceTypeJson_Destroy(const dmResource::ResourceDestroyParams* params)
{
SpineJsonResource* resource = (SpineJsonResource*)params.m_Resource->m_Resource;
SpineJsonResource* resource = (SpineJsonResource*)dmResource::GetResource(params->m_Resource);
DestroyResource(resource);
return dmResource::RESULT_OK;
}

static dmResource::Result ResourceTypeJson_Recreate(const dmResource::ResourceRecreateParams& params)
static dmResource::Result ResourceTypeJson_Recreate(const dmResource::ResourceRecreateParams* params)
{
SpineJsonResource* new_resource = CreateResource(params.m_Buffer, params.m_BufferSize);
SpineJsonResource* new_resource = CreateResource(params->m_Buffer, params->m_BufferSize);
if (!new_resource)
{
return dmResource::RESULT_OUT_OF_RESOURCES;
}

SpineJsonResource* old_resource = (SpineJsonResource*) params.m_Resource->m_Resource;
SpineJsonResource* old_resource = (SpineJsonResource*) dmResource::GetResource(params->m_Resource);

// swap the internals
// we wish to keep the "old" resource, since that pointer might be shared in the system
Expand All @@ -70,20 +76,20 @@ namespace dmSpine
new_resource->m_Json = tmp;
DestroyResource(new_resource);

params.m_Resource->m_ResourceSize = old_resource->m_Length;
dmResource::SetResourceSize(params->m_Resource, old_resource->m_Length);
return dmResource::RESULT_OK;
}

static dmResource::Result ResourceTypeJson_Register(dmResource::ResourceTypeRegisterContext& ctx)
static ResourceResult ResourceTypeJson_Register(HResourceTypeContext ctx, HResourceType type)
{
return dmResource::RegisterType(ctx.m_Factory,
ctx.m_Name,
0, // context
0, // preload
ResourceTypeJson_Create,
0, // post create
ResourceTypeJson_Destroy,
ResourceTypeJson_Recreate);
return (ResourceResult)dmResource::SetupType(ctx,
type,
0, // context
0, // preload
ResourceTypeJson_Create,
0, // post create
ResourceTypeJson_Destroy,
ResourceTypeJson_Recreate);

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

static dmResource::Result ResourceTypeModel_Preload(const dmResource::ResourcePreloadParams& params)
static dmResource::Result ResourceTypeModel_Preload(const dmResource::ResourcePreloadParams* params)
{
dmGameSystemDDF::SpineModelDesc* ddf;
dmDDF::Result e = dmDDF::LoadMessage(params.m_Buffer, params.m_BufferSize, &dmGameSystemDDF_SpineModelDesc_DESCRIPTOR, (void**) &ddf);
dmDDF::Result e = dmDDF::LoadMessage(params->m_Buffer, params->m_BufferSize, &dmGameSystemDDF_SpineModelDesc_DESCRIPTOR, (void**) &ddf);
if (e != dmDDF::RESULT_OK)
{
return dmResource::RESULT_DDF_ERROR;
}

dmResource::PreloadHint(params.m_HintInfo, ddf->m_SpineScene);
dmResource::PreloadHint(params.m_HintInfo, ddf->m_Material);
dmResource::PreloadHint(params->m_HintInfo, ddf->m_SpineScene);
dmResource::PreloadHint(params->m_HintInfo, ddf->m_Material);

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

static dmResource::Result ResourceTypeModel_Create(const dmResource::ResourceCreateParams& params)
static dmResource::Result ResourceTypeModel_Create(const dmResource::ResourceCreateParams* params)
{
SpineModelResource* model_resource = new SpineModelResource();
model_resource->m_Ddf = (dmGameSystemDDF::SpineModelDesc*) params.m_PreloadData;
dmResource::Result r = AcquireResources(params.m_Factory, model_resource, params.m_Filename);
model_resource->m_Ddf = (dmGameSystemDDF::SpineModelDesc*) params->m_PreloadData;
dmResource::Result r = AcquireResources(params->m_Factory, model_resource, params->m_Filename);
if (r == dmResource::RESULT_OK)
{
params.m_Resource->m_Resource = (void*) model_resource;
dmResource::SetResource(params->m_Resource, model_resource);
}
else
{
ReleaseResources(params.m_Factory, model_resource);
ReleaseResources(params->m_Factory, model_resource);
delete model_resource;
}
return r;
}

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

static dmResource::Result ResourceTypeModel_Recreate(const dmResource::ResourceRecreateParams& params)
static dmResource::Result ResourceTypeModel_Recreate(const dmResource::ResourceRecreateParams* params)
{
dmGameSystemDDF::SpineModelDesc* ddf;
dmDDF::Result e = dmDDF::LoadMessage(params.m_Buffer, params.m_BufferSize, &dmGameSystemDDF_SpineModelDesc_DESCRIPTOR, (void**) &ddf);
dmDDF::Result e = dmDDF::LoadMessage(params->m_Buffer, params->m_BufferSize, &dmGameSystemDDF_SpineModelDesc_DESCRIPTOR, (void**) &ddf);
if (e != dmDDF::RESULT_OK)
{
return dmResource::RESULT_DDF_ERROR;
}
SpineModelResource* model_resource = (SpineModelResource*)params.m_Resource->m_Resource;
ReleaseResources(params.m_Factory, model_resource);
SpineModelResource* model_resource = (SpineModelResource*)dmResource::GetResource(params->m_Resource);
ReleaseResources(params->m_Factory, model_resource);
model_resource->m_Ddf = ddf;
return AcquireResources(params.m_Factory, model_resource, params.m_Filename);
return AcquireResources(params->m_Factory, model_resource, params->m_Filename);
}

static dmResource::Result ResourceTypeModel_Register(dmResource::ResourceTypeRegisterContext& ctx)
static ResourceResult ResourceTypeModel_Register(HResourceTypeContext ctx, HResourceType type)
{
return dmResource::RegisterType(ctx.m_Factory,
ctx.m_Name,
0, // context
ResourceTypeModel_Preload,
ResourceTypeModel_Create,
0, // post create
ResourceTypeModel_Destroy,
ResourceTypeModel_Recreate);
return (ResourceResult)dmResource::SetupType(ctx,
type,
0, // context
ResourceTypeModel_Preload,
ResourceTypeModel_Create,
0, // post create
ResourceTypeModel_Destroy,
ResourceTypeModel_Recreate);

}
}
Expand Down
54 changes: 27 additions & 27 deletions defold-spine/src/res_spine_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,71 +133,71 @@ namespace dmSpine
delete[] resource->m_Regions;
}

static dmResource::Result ResourceTypeScene_Preload(const dmResource::ResourcePreloadParams& params)
static dmResource::Result ResourceTypeScene_Preload(const dmResource::ResourcePreloadParams* params)
{
dmGameSystemDDF::SpineSceneDesc* ddf;
dmDDF::Result e = dmDDF::LoadMessage(params.m_Buffer, params.m_BufferSize, &dmGameSystemDDF_SpineSceneDesc_DESCRIPTOR, (void**) &ddf);
dmDDF::Result e = dmDDF::LoadMessage(params->m_Buffer, params->m_BufferSize, &dmGameSystemDDF_SpineSceneDesc_DESCRIPTOR, (void**) &ddf);
if (e != dmDDF::RESULT_OK)
{
return dmResource::RESULT_DDF_ERROR;
}

dmResource::PreloadHint(params.m_HintInfo, ddf->m_SpineJson);
dmResource::PreloadHint(params.m_HintInfo, ddf->m_Atlas);
dmResource::PreloadHint(params->m_HintInfo, ddf->m_SpineJson);
dmResource::PreloadHint(params->m_HintInfo, ddf->m_Atlas);

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

static dmResource::Result ResourceTypeScene_Create(const dmResource::ResourceCreateParams& params)
static dmResource::Result ResourceTypeScene_Create(const dmResource::ResourceCreateParams* params)
{
SpineSceneResource* scene_resource = new SpineSceneResource();
scene_resource->m_Ddf = (dmGameSystemDDF::SpineSceneDesc*) params.m_PreloadData;
dmResource::Result r = AcquireResources(params.m_Factory, scene_resource, params.m_Filename);
scene_resource->m_Ddf = (dmGameSystemDDF::SpineSceneDesc*) params->m_PreloadData;
dmResource::Result r = AcquireResources(params->m_Factory, scene_resource, params->m_Filename);
if (r == dmResource::RESULT_OK)
{
params.m_Resource->m_Resource = (void*) scene_resource;
dmResource::SetResource(params->m_Resource, scene_resource);
}
else
{
ReleaseResources(params.m_Factory, scene_resource);
ReleaseResources(params->m_Factory, scene_resource);
delete scene_resource;
}
return r;
}

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

static dmResource::Result ResourceTypeScene_Recreate(const dmResource::ResourceRecreateParams& params)
static dmResource::Result ResourceTypeScene_Recreate(const dmResource::ResourceRecreateParams* params)
{
dmGameSystemDDF::SpineSceneDesc* ddf;
dmDDF::Result e = dmDDF::LoadMessage(params.m_Buffer, params.m_BufferSize, &dmGameSystemDDF_SpineSceneDesc_DESCRIPTOR, (void**) &ddf);
dmDDF::Result e = dmDDF::LoadMessage(params->m_Buffer, params->m_BufferSize, &dmGameSystemDDF_SpineSceneDesc_DESCRIPTOR, (void**) &ddf);
if (e != dmDDF::RESULT_OK)
{
return dmResource::RESULT_DDF_ERROR;
}
SpineSceneResource* resource = (SpineSceneResource*)params.m_Resource->m_Resource;
ReleaseResources(params.m_Factory, resource);
SpineSceneResource* resource = (SpineSceneResource*)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 ResourceTypeScene_Register(dmResource::ResourceTypeRegisterContext& ctx)
static ResourceResult ResourceTypeScene_Register(HResourceTypeContext ctx, HResourceType type)
{
return dmResource::RegisterType(ctx.m_Factory,
ctx.m_Name,
0, // context
ResourceTypeScene_Preload,
ResourceTypeScene_Create,
0, // post create
ResourceTypeScene_Destroy,
ResourceTypeScene_Recreate);
return (ResourceResult)dmResource::SetupType(ctx,
type,
0, // context
ResourceTypeScene_Preload,
ResourceTypeScene_Create,
0, // post create
ResourceTypeScene_Destroy,
ResourceTypeScene_Recreate);

}
}
Expand Down
Loading