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