Use std::list for animation data eval buffer..

AnimGraphEditor
Martin Felis 2022-04-18 23:14:34 +02:00
parent 68331467f0
commit 2a8a5a5e40
1 changed files with 13 additions and 27 deletions

View File

@ -12,6 +12,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include <vector> #include <vector>
#include <list>
#include "SyncTrack.h" #include "SyncTrack.h"
#include "ozz/animation/runtime/animation.h" #include "ozz/animation/runtime/animation.h"
@ -34,27 +35,24 @@ struct AnimDataAllocator {
AnimDataList* next = nullptr; AnimDataList* next = nullptr;
}; };
AnimDataList* m_anim_data_list = nullptr; std::list<AnimData*> m_anim_data_list;
size_t m_num_allocations = 0; size_t m_num_allocations = 0;
~AnimDataAllocator() { ~AnimDataAllocator() {
AnimDataList* list_node = m_anim_data_list; while (!m_anim_data_list.empty()) {
while (list_node != nullptr) { AnimData* front = m_anim_data_list.front();
AnimDataList* current_node = list_node;
list_node = list_node->next;
#ifdef ANIM_DATA_ALLOCATOR_DEBUG #ifdef ANIM_DATA_ALLOCATOR_DEBUG
std::cout << "about to delete with size " std::cout << "about to delete with size "
<< current_node->m_anim_data->m_local_matrices.size() << front->m_anim_data->m_local_matrices.size()
<< current_node->m_anim_data << std::endl; << front->m_anim_data << std::endl;
#endif #endif
delete current_node->m_anim_data; delete front;
current_node->m_anim_data = nullptr; m_anim_data_list.pop_front();
delete current_node;
} }
} }
AnimData* allocate(ozz::animation::Skeleton* skeleton) { AnimData* allocate(ozz::animation::Skeleton* skeleton) {
if (m_anim_data_list == nullptr) { if (m_anim_data_list.empty()) {
AnimData* result = new AnimData(); AnimData* result = new AnimData();
result->m_local_matrices.resize(skeleton->num_soa_joints()); result->m_local_matrices.resize(skeleton->num_soa_joints());
#ifdef ANIM_DATA_ALLOCATOR_DEBUG #ifdef ANIM_DATA_ALLOCATOR_DEBUG
@ -65,9 +63,8 @@ struct AnimDataAllocator {
return result; return result;
} }
AnimData* result = m_anim_data_list->m_anim_data; AnimData* result = m_anim_data_list.front();
m_anim_data_list = m_anim_data_list->next; m_anim_data_list.pop_front();
delete m_anim_data_list;
#ifdef ANIM_DATA_ALLOCATOR_DEBUG #ifdef ANIM_DATA_ALLOCATOR_DEBUG
std::cout << "Reusing buffer with size " << result->m_local_matrices.size() std::cout << "Reusing buffer with size " << result->m_local_matrices.size()
@ -83,22 +80,11 @@ struct AnimDataAllocator {
<< " " << anim_data << std::endl; << " " << anim_data << std::endl;
#endif #endif
AnimDataList* list_node = new AnimDataList; m_anim_data_list.push_front(anim_data);
list_node->next = m_anim_data_list;
list_node->m_anim_data = anim_data;
m_anim_data_list = list_node;
} }
size_t size() { size_t size() {
size_t result = 0; return m_anim_data_list.size();
AnimDataList* node = m_anim_data_list;
while (node != nullptr) {
result++;
node = node->next;
}
return result;
} }
}; };