Skip to content

Commit

Permalink
Create id lists as pointers instead (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhonnyg authored Nov 15, 2024
1 parent 45a4813 commit 9a1ec35
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
4 changes: 2 additions & 2 deletions defold-rive/src/comp_rive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ namespace dmRive

for (int i = 0; i < data->m_ArtboardIdLists.Size(); ++i)
{
if (data->m_ArtboardIdLists[i].m_ArtboardNameHash == artboard_id)
if (data->m_ArtboardIdLists[i]->m_ArtboardNameHash == artboard_id)
{
return &data->m_ArtboardIdLists[i];
return data->m_ArtboardIdLists[i];
}
}
return 0x0;
Expand Down
30 changes: 13 additions & 17 deletions defold-rive/src/res_rive_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,44 +48,36 @@ namespace dmRive
{
rive::Artboard* artboard = scene_data->m_File->artboard(i);

scene_data->m_ArtboardIdLists[i].m_ArtboardNameHash = dmHashString64(artboard->name().c_str());
RiveArtboardIdList* id_list = new RiveArtboardIdList();
scene_data->m_ArtboardIdLists[i] = id_list;

#if 0
dmLogInfo("Artboard[%d]: %s", i, artboard->name().c_str());
#endif
id_list->m_ArtboardNameHash = dmHashString64(artboard->name().c_str());

// Setup state machine ID lists
uint32_t state_machine_count = (uint32_t)artboard->stateMachineCount();
if (state_machine_count)
{
scene_data->m_ArtboardIdLists[i].m_StateMachines.SetCapacity(state_machine_count);
scene_data->m_ArtboardIdLists[i].m_StateMachines.SetSize(state_machine_count);
id_list->m_StateMachines.SetCapacity(state_machine_count);
id_list->m_StateMachines.SetSize(state_machine_count);

for (int j = 0; j < state_machine_count; ++j)
{
rive::StateMachine* state_machine = artboard->stateMachine(j);
scene_data->m_ArtboardIdLists[i].m_StateMachines[j] = dmHashString64(state_machine->name().c_str());
#if 0
dmLogInfo(" State machine[%d]: %s", j, state_machine->name().c_str());
#endif
id_list->m_StateMachines[j] = dmHashString64(state_machine->name().c_str());
}
}

// Setup animation ID lists
uint32_t animation_count = (uint32_t)artboard->animationCount();
if (animation_count)
{
scene_data->m_ArtboardIdLists[i].m_LinearAnimations.SetCapacity(animation_count);
scene_data->m_ArtboardIdLists[i].m_LinearAnimations.SetSize(animation_count);
id_list->m_LinearAnimations.SetCapacity(animation_count);
id_list->m_LinearAnimations.SetSize(animation_count);

for (int j = 0; j < animation_count; ++j)
{
rive::LinearAnimation* animation = artboard->animation(j);
scene_data->m_ArtboardIdLists[i].m_LinearAnimations[j] = dmHashString64(animation->name().c_str());

#if 0
dmLogInfo(" Animation[%d]: %s", j, animation->name().c_str());
#endif
id_list->m_LinearAnimations[j] = dmHashString64(animation->name().c_str());
}
}
}
Expand Down Expand Up @@ -127,6 +119,10 @@ namespace dmRive

static void DeleteData(RiveSceneData* scene_data)
{
for (int i = 0; i < scene_data->m_ArtboardIdLists.Size(); ++i)
{
delete scene_data->m_ArtboardIdLists[i];
}
delete scene_data->m_File;
delete scene_data;
}
Expand Down
2 changes: 1 addition & 1 deletion defold-rive/src/res_rive_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace dmRive
rive::File* m_File;
HRenderContext m_RiveRenderContext;
std::unique_ptr<rive::ArtboardInstance> m_ArtboardDefault;
dmArray<RiveArtboardIdList> m_ArtboardIdLists;
dmArray<RiveArtboardIdList*> m_ArtboardIdLists;
};
}

Expand Down

0 comments on commit 9a1ec35

Please sign in to comment.