add mutex for animation updates
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include <filament/Scene.h>
|
#include <filament/Scene.h>
|
||||||
|
|
||||||
#include <gltfio/AssetLoader.h>
|
#include <gltfio/AssetLoader.h>
|
||||||
@@ -82,6 +84,7 @@ namespace polyvox {
|
|||||||
gltfio::ResourceLoader* _gltfResourceLoader = nullptr;
|
gltfio::ResourceLoader* _gltfResourceLoader = nullptr;
|
||||||
gltfio::TextureProvider* _stbDecoder = nullptr;
|
gltfio::TextureProvider* _stbDecoder = nullptr;
|
||||||
gltfio::TextureProvider* _ktxDecoder = nullptr;
|
gltfio::TextureProvider* _ktxDecoder = nullptr;
|
||||||
|
std::mutex _animationMutex;
|
||||||
|
|
||||||
vector<SceneAsset> _assets;
|
vector<SceneAsset> _assets;
|
||||||
tsl::robin_map<EntityId, int> _entityIdLookup;
|
tsl::robin_map<EntityId, int> _entityIdLookup;
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ FilamentAsset* AssetManager::getAssetByEntityId(EntityId entityId) {
|
|||||||
|
|
||||||
void AssetManager::updateAnimations() {
|
void AssetManager::updateAnimations() {
|
||||||
|
|
||||||
|
std::lock_guard lock(_animationMutex);
|
||||||
RenderableManager &rm = _engine->getRenderableManager();
|
RenderableManager &rm = _engine->getRenderableManager();
|
||||||
|
|
||||||
for (auto& asset : _assets) {
|
for (auto& asset : _assets) {
|
||||||
@@ -467,7 +467,8 @@ bool AssetManager::setMorphAnimationBuffer(
|
|||||||
int numMorphTargets,
|
int numMorphTargets,
|
||||||
int numFrames,
|
int numFrames,
|
||||||
float frameLengthInMs) {
|
float frameLengthInMs) {
|
||||||
|
std::lock_guard lock(_animationMutex);
|
||||||
|
|
||||||
const auto& pos = _entityIdLookup.find(entityId);
|
const auto& pos = _entityIdLookup.find(entityId);
|
||||||
if(pos == _entityIdLookup.end()) {
|
if(pos == _entityIdLookup.end()) {
|
||||||
Log("ERROR: asset not found for entity.");
|
Log("ERROR: asset not found for entity.");
|
||||||
@@ -543,7 +544,8 @@ bool AssetManager::setBoneAnimationBuffer(
|
|||||||
const char** const meshNames,
|
const char** const meshNames,
|
||||||
int numMeshTargets,
|
int numMeshTargets,
|
||||||
float frameLengthInMs) {
|
float frameLengthInMs) {
|
||||||
|
std::lock_guard lock(_animationMutex);
|
||||||
|
|
||||||
const auto& pos = _entityIdLookup.find(entityId);
|
const auto& pos = _entityIdLookup.find(entityId);
|
||||||
if(pos == _entityIdLookup.end()) {
|
if(pos == _entityIdLookup.end()) {
|
||||||
Log("ERROR: asset not found for entity.");
|
Log("ERROR: asset not found for entity.");
|
||||||
@@ -632,6 +634,8 @@ bool AssetManager::setBoneAnimationBuffer(
|
|||||||
|
|
||||||
|
|
||||||
void AssetManager::playAnimation(EntityId e, int index, bool loop, bool reverse, bool replaceActive, float crossfade) {
|
void AssetManager::playAnimation(EntityId e, int index, bool loop, bool reverse, bool replaceActive, float crossfade) {
|
||||||
|
std::lock_guard lock(_animationMutex);
|
||||||
|
|
||||||
if(index < 0) {
|
if(index < 0) {
|
||||||
Log("ERROR: glTF animation index must be greater than zero.");
|
Log("ERROR: glTF animation index must be greater than zero.");
|
||||||
return;
|
return;
|
||||||
@@ -686,6 +690,8 @@ void AssetManager::playAnimation(EntityId e, int index, bool loop, bool reverse,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AssetManager::stopAnimation(EntityId entityId, int index) {
|
void AssetManager::stopAnimation(EntityId entityId, int index) {
|
||||||
|
std::lock_guard lock(_animationMutex);
|
||||||
|
|
||||||
const auto& pos = _entityIdLookup.find(entityId);
|
const auto& pos = _entityIdLookup.find(entityId);
|
||||||
if(pos == _entityIdLookup.end()) {
|
if(pos == _entityIdLookup.end()) {
|
||||||
Log("ERROR: asset not found for entity.");
|
Log("ERROR: asset not found for entity.");
|
||||||
|
|||||||
Reference in New Issue
Block a user