Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Stokes <mogurijin@gmail.com>2014-04-07 03:30:59 +0400
committerMitchell Stokes <mogurijin@gmail.com>2014-04-07 03:30:59 +0400
commitfe05f97841c0ee3e2a6e15f2252ad160fefc3509 (patch)
tree2a672e5d82448f43471ddb529a95fa547d5c311e /source/gameengine/Ketsji/BL_Action.cpp
parentbe8b4b8b0c4d4fdeed6ebf88d8a3bd480e4c48ce (diff)
BGE: Multi-threading animation updates and skinning.
This required BL_ArmatureObject to have tighter control over armatures and poses. Also, (Blender) armature objects are now copied instead of shared between BL_ArmatureObjects to avoid race conditions. Also, due to the armature copy, shape key drivers need a bit of extra fiddling to get the correct armature copy. Initially OpenMP was used for threading, but then BLI_task was used due to being less compiler dependent. This commit also places time spent on skinning updates in the Animation profiler category (was previously under the Rasterizer category).
Diffstat (limited to 'source/gameengine/Ketsji/BL_Action.cpp')
-rw-r--r--source/gameengine/Ketsji/BL_Action.cpp57
1 files changed, 28 insertions, 29 deletions
diff --git a/source/gameengine/Ketsji/BL_Action.cpp b/source/gameengine/Ketsji/BL_Action.cpp
index a974ffbf672..e4ab2d5ce28 100644
--- a/source/gameengine/Ketsji/BL_Action.cpp
+++ b/source/gameengine/Ketsji/BL_Action.cpp
@@ -51,10 +51,14 @@ extern "C" {
#include "DNA_material_types.h"
}
+#include "MEM_guardedalloc.h"
+#include "BKE_library.h"
+#include "BKE_global.h"
+
BL_Action::BL_Action(class KX_GameObject* gameobj)
:
m_action(NULL),
- m_pose(NULL),
+ m_tmpaction(NULL),
m_blendpose(NULL),
m_blendinpose(NULL),
m_obj(gameobj),
@@ -77,13 +81,16 @@ BL_Action::BL_Action(class KX_GameObject* gameobj)
BL_Action::~BL_Action()
{
- if (m_pose)
- game_free_pose(m_pose);
if (m_blendpose)
- game_free_pose(m_blendpose);
+ BKE_pose_free(m_blendpose);
if (m_blendinpose)
- game_free_pose(m_blendinpose);
+ BKE_pose_free(m_blendinpose);
ClearControllerList();
+
+ if (m_tmpaction) {
+ BKE_libblock_free(G.main, m_tmpaction);
+ m_tmpaction = NULL;
+ }
}
void BL_Action::ClearControllerList()
@@ -139,6 +146,13 @@ bool BL_Action::Play(const char* name,
&& m_priority == priority && m_speed == playback_speed)
return false;
+ // Keep a copy of the action for threading purposes
+ if (m_tmpaction) {
+ BKE_libblock_free(G.main, m_tmpaction);
+ m_tmpaction = NULL;
+ }
+ m_tmpaction = BKE_action_copy(m_action);
+
// First get rid of any old controllers
ClearControllerList();
@@ -208,7 +222,7 @@ bool BL_Action::Play(const char* name,
if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE)
{
BL_ArmatureObject *obj = (BL_ArmatureObject*)m_obj;
- obj->GetMRDPose(&m_blendinpose);
+ obj->GetPose(&m_blendinpose);
}
else
{
@@ -402,22 +416,12 @@ void BL_Action::Update(float curtime)
if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE)
{
BL_ArmatureObject *obj = (BL_ArmatureObject*)m_obj;
- obj->GetPose(&m_pose);
-
- // Extract the pose from the action
- {
- Object *arm = obj->GetArmatureObject();
- bPose *temp = arm->pose;
-
- arm->pose = m_pose;
- PointerRNA ptrrna;
- RNA_id_pointer_create(&arm->id, &ptrrna);
-
- animsys_evaluate_action(&ptrrna, m_action, NULL, m_localtime);
+ if (m_layer_weight >= 0)
+ obj->GetPose(&m_blendpose);
- arm->pose = temp;
- }
+ // Extract the pose from the action
+ obj->SetPoseByAction(m_tmpaction, m_localtime);
// Handle blending between armature actions
if (m_blendin && m_blendframe<m_blendin)
@@ -428,20 +432,15 @@ void BL_Action::Update(float curtime)
float weight = 1.f - (m_blendframe/m_blendin);
// Blend the poses
- game_blend_poses(m_pose, m_blendinpose, weight, ACT_BLEND_BLEND);
+ obj->BlendInPose(m_blendinpose, weight, ACT_BLEND_BLEND);
}
// Handle layer blending
if (m_layer_weight >= 0)
- {
- obj->GetMRDPose(&m_blendpose);
- game_blend_poses(m_pose, m_blendpose, m_layer_weight, m_blendmode);
- }
-
- obj->SetPose(m_pose);
+ obj->BlendInPose(m_blendpose, m_layer_weight, m_blendmode);
- obj->SetActiveAction(NULL, 0, curtime);
+ obj->UpdateTimestep(curtime);
}
else
{
@@ -456,7 +455,7 @@ void BL_Action::Update(float curtime)
PointerRNA ptrrna;
RNA_id_pointer_create(&key->id, &ptrrna);
- animsys_evaluate_action(&ptrrna, m_action, NULL, m_localtime);
+ animsys_evaluate_action(&ptrrna, m_tmpaction, NULL, m_localtime);
// Handle blending between shape actions
if (m_blendin && m_blendframe < m_blendin)