Skip to content

Commit

Permalink
UPBGE: Move SG_Controller entirely in BL_Action. (#708)
Browse files Browse the repository at this point in the history
Previously SG_Controller were owned and updated by SG_Node. This class
is not the best place for it as SG_Controller are not always modifying spatial,
for example Light or Camera controllers.
The best place is in BL_Action as this class was setting the simulation time
and updating the controllers indirectly.

In the same time the option "child" in action actuator which enabled recursive
time update for controllers is removed. Indeed every call to SetSimulatedTime
was followed by Update for the controllers in BL_Action.
  • Loading branch information
panzergame committed Jul 4, 2018
1 parent aac6b53 commit 8df1a72
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 190 deletions.
2 changes: 0 additions & 2 deletions source/blender/editors/space_logic/logic_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -1415,8 +1415,6 @@ static void draw_actuator_action(uiLayout *layout, PointerRNA *ptr)
uiItemR(row, ptr, "frame_end", 0, NULL, ICON_NONE);
}

uiItemR(row, ptr, "apply_to_children", 0, NULL, ICON_NONE);

row = uiLayoutRow(layout, false);
uiItemR(row, ptr, "frame_blend_in", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "priority", 0, NULL, ICON_NONE);
Expand Down
1 change: 0 additions & 1 deletion source/blender/makesdna/DNA_actuator_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ typedef struct bActuator {
#define ACT_IPOFORCE (1 << 0)
#define ACT_IPOEND (1 << 1)
#define ACT_IPOLOCAL (1 << 2)
#define ACT_IPOCHILD (1 << 4)
#define ACT_IPOADD (1 << 5)

/* property actuator->type */
Expand Down
5 changes: 0 additions & 5 deletions source/blender/makesrna/intern/rna_actuator.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,6 @@ static void rna_def_action_actuator(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "L", "Let the Action act in local coordinates, used in Force and Add mode");
RNA_def_property_update(prop, NC_LOGIC, NULL);

prop = RNA_def_property(srna, "apply_to_children", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_IPOCHILD);
RNA_def_property_ui_text(prop, "Child", "Update Action on all children Objects as well");
RNA_def_property_update(prop, NC_LOGIC, NULL);

prop = RNA_def_property(srna, "blend_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "blend_mode");
RNA_def_property_enum_items(prop, prop_blend_items);
Expand Down
3 changes: 0 additions & 3 deletions source/gameengine/Converter/BL_ConvertActuators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,6 @@ void BL_ConvertActuators(const char *maggiename,
if (actact->flag & ACT_IPOADD) {
ipo_flags |= BL_Action::ACT_IPOFLAG_ADD;
}
if (actact->flag & ACT_IPOCHILD) {
ipo_flags |= BL_Action::ACT_IPOFLAG_CHILD;
}

BL_ActionActuator *tmpbaseact = new BL_ActionActuator(
gameobj,
Expand Down
40 changes: 18 additions & 22 deletions source/gameengine/Ketsji/BL_Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extern "C" {
#include "BKE_library.h"
#include "BKE_global.h"

BL_Action::BL_Action(class KX_GameObject *gameobj)
BL_Action::BL_Action(KX_GameObject *gameobj)
:m_action(nullptr),
m_tmpaction(nullptr),
m_blendpose(nullptr),
Expand Down Expand Up @@ -106,21 +106,17 @@ void BL_Action::AddController(SG_Controller *cont)
return;
}

m_sg_contr_list.push_back(cont);
m_obj->GetNode()->AddController(cont);
m_controllers.push_back(cont);
}

void BL_Action::ClearControllerList()
{
SG_Node *node = m_obj->GetNode();

// Clear out the controller list
for (SG_Controller *cont : m_sg_contr_list) {
node->RemoveController(cont);
for (SG_Controller *cont : m_controllers) {
delete cont;
}

m_sg_contr_list.clear();
m_controllers.clear();
}

bool BL_Action::Play(const std::string& name,
Expand Down Expand Up @@ -174,8 +170,6 @@ bool BL_Action::Play(const std::string& name,
// First get rid of any old controllers
ClearControllerList();

SG_Node *node = m_obj->GetNode();

// Create an SG_Controller
AddController(BL_CreateIPO(m_action, m_obj, kxscene));
// World
Expand Down Expand Up @@ -251,7 +245,7 @@ bool BL_Action::IsDone()
void BL_Action::InitIPO()
{
// Initialize the IPOs
for (SG_Controller *cont : m_sg_contr_list) {
for (SG_Controller *cont : m_controllers) {
cont->SetOption(SG_Controller::SG_CONTR_IPO_RESET, true);
cont->SetOption(SG_Controller::SG_CONTR_IPO_IPO_AS_FORCE, m_ipo_flags & ACT_IPOFLAG_FORCE);
cont->SetOption(SG_Controller::SG_CONTR_IPO_IPO_ADD, m_ipo_flags & ACT_IPOFLAG_ADD);
Expand Down Expand Up @@ -415,6 +409,13 @@ void BL_Action::Update(float curtime, bool applyToObject)

m_requestIpo = true;

SG_Node *node = m_obj->GetNode();
// Update controllers time.
for (SG_Controller *cont : m_controllers) {
cont->SetSimulatedTime(m_localframe); // update spatial controllers
cont->Update(node);
}

if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) {
BL_ArmatureObject *obj = (BL_ArmatureObject *)m_obj;

Expand Down Expand Up @@ -482,22 +483,17 @@ void BL_Action::Update(float curtime, bool applyToObject)
shape_deformer->SetLastFrame(curtime);
}
}

// If the action is done we can remove its scene graph IPO controller.
if (m_done) {
ClearControllerList();
}
}

void BL_Action::UpdateIPOs()
{
if (m_sg_contr_list.empty()) {
// Nothing to update or remove.
return;
}

if (m_requestIpo) {
m_obj->UpdateIPO(m_localframe, m_ipo_flags & ACT_IPOFLAG_CHILD);
m_obj->GetNode()->UpdateWorldDataThread();
m_requestIpo = false;
}

// If the action is done we can remove its scene graph IPO controller.
if (m_done) {
ClearControllerList();
}
}
19 changes: 12 additions & 7 deletions source/gameengine/Ketsji/BL_Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,21 @@
#include <string>
#include <vector>

class KX_GameObject;
class SG_Controller;

struct bAction;
struct bPose;

class BL_Action
{
private:
struct bAction* m_action;
struct bAction* m_tmpaction;
struct bPose* m_blendpose;
struct bPose* m_blendinpose;
std::vector<class SG_Controller*> m_sg_contr_list;
class KX_GameObject* m_obj;
bAction* m_action;
bAction* m_tmpaction;
bPose* m_blendpose;
bPose* m_blendinpose;
std::vector<SG_Controller *> m_controllers;
KX_GameObject* m_obj;
std::vector<float> m_blendshape;
std::vector<float> m_blendinshape;

Expand Down Expand Up @@ -146,7 +152,6 @@ class BL_Action
ACT_IPOFLAG_FORCE = 1,
ACT_IPOFLAG_LOCAL = 2,
ACT_IPOFLAG_ADD = 4,
ACT_IPOFLAG_CHILD = 8,
};
};

Expand Down
20 changes: 0 additions & 20 deletions source/gameengine/Ketsji/KX_GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,26 +870,6 @@ void KX_GameObject::SynchronizeTransformFunc(SG_Node *node, void *gameobj, void
((KX_GameObject *)gameobj)->SynchronizeTransform();
}

void KX_GameObject::InitIPO(bool ipo_as_force,
bool ipo_add,
bool ipo_local)
{
for (SG_Controller *cont : m_sgNode->GetControllerList()) {
cont->SetOption(SG_Controller::SG_CONTR_IPO_RESET, true);
cont->SetOption(SG_Controller::SG_CONTR_IPO_IPO_AS_FORCE, ipo_as_force);
cont->SetOption(SG_Controller::SG_CONTR_IPO_IPO_ADD, ipo_add);
cont->SetOption(SG_Controller::SG_CONTR_IPO_LOCAL, ipo_local);
}
}

void KX_GameObject::UpdateIPO(float curframetime,
bool recurse)
{
// just the 'normal' update procedure.
m_sgNode->SetSimulatedTimeThread(curframetime, recurse);
m_sgNode->UpdateWorldDataThread();
}

bool KX_GameObject::GetVisible(void)
{
return m_bVisible;
Expand Down
19 changes: 0 additions & 19 deletions source/gameengine/Ketsji/KX_GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -620,25 +620,6 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator

static void SynchronizeTransformFunc(SG_Node* node, void* gameobj, void* scene);

/**
* Function to set IPO option at start of IPO
*/
void
InitIPO(
bool ipo_as_force,
bool ipo_add,
bool ipo_local
);

/**
* Odd function to update an ipo. ???
*/
void
UpdateIPO(
float curframetime,
bool recurse
);

/**
* \section Mesh accessor functions.
*/
Expand Down
66 changes: 0 additions & 66 deletions source/gameengine/SceneGraph/SG_Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ SG_Node::SG_Node(const SG_Node & other)

SG_Node::~SG_Node()
{
for (SG_Controller *cont : m_controllers) {
delete cont;
}
}

SG_Node *SG_Node::GetReplica()
Expand Down Expand Up @@ -261,35 +258,6 @@ void SG_Node::UpdateWorldDataThreadSchedule(bool parentUpdated)
}
}

void SG_Node::SetSimulatedTime(double time, bool recurse)
{
// update the controllers of this node.
SetControllerTime(time);

// update children's simulate time.
if (recurse) {
for (SG_Node *childnode : m_children) {
childnode->SetSimulatedTime(time, recurse);
}
}
}

void SG_Node::SetSimulatedTimeThread(double time, bool recurse)
{
CM_ThreadSpinLock& famillyMutex = m_familly->GetMutex();
famillyMutex.Lock();
// update the controllers of this node.
SetControllerTime(time);

// update children's simulate time.
if (recurse) {
for (SG_Node *childnode : m_children) {
childnode->SetSimulatedTime(time, recurse);
}
}
famillyMutex.Unlock();
}

bool SG_Node::Schedule(SG_QList& head)
{
scheduleMutex.Lock();
Expand Down Expand Up @@ -329,28 +297,6 @@ SG_Node *SG_Node::GetNextRescheduled(SG_QList& head)
return result;
}

void SG_Node::AddController(SG_Controller *cont)
{
m_controllers.push_back(cont);
}

void SG_Node::RemoveController(SG_Controller *cont)
{
m_mutex.Lock();
CM_ListRemoveIfFound(m_controllers, cont);
m_mutex.Unlock();
}

void SG_Node::RemoveAllControllers()
{
m_controllers.clear();
}

SGControllerList& SG_Node::GetControllerList()
{
return m_controllers;
}

SG_Callbacks& SG_Node::GetCallBackFunctions()
{
return m_callbacks;
Expand All @@ -375,13 +321,6 @@ void SG_Node::SetClientInfo(void *clientInfo)
m_clientInfo = clientInfo;
}

void SG_Node::SetControllerTime(double time)
{
for (SG_Controller *cont : m_controllers) {
cont->SetSimulatedTime(time);
}
}

void SG_Node::ClearModified()
{
m_modified = false;
Expand Down Expand Up @@ -416,11 +355,6 @@ SG_ParentRelation *SG_Node::GetParentRelation()
*/
void SG_Node::UpdateSpatialData(const SG_Node *parent, bool& parentUpdated)
{
// update spatial controllers
for (SG_Controller *cont : m_controllers) {
cont->Update(this);
}

// Ask the parent_relation object owned by this class to update our world coordinates.
ComputeWorldTransforms(parent, parentUpdated);
}
Expand Down
Loading

0 comments on commit 8df1a72

Please sign in to comment.