Skip to content

Commit 8df1a72

Browse files
committed
UPBGE: Move SG_Controller entirely in BL_Action. (#708)
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.
1 parent aac6b53 commit 8df1a72

File tree

10 files changed

+31
-190
lines changed

10 files changed

+31
-190
lines changed

source/blender/editors/space_logic/logic_window.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,8 +1415,6 @@ static void draw_actuator_action(uiLayout *layout, PointerRNA *ptr)
14151415
uiItemR(row, ptr, "frame_end", 0, NULL, ICON_NONE);
14161416
}
14171417

1418-
uiItemR(row, ptr, "apply_to_children", 0, NULL, ICON_NONE);
1419-
14201418
row = uiLayoutRow(layout, false);
14211419
uiItemR(row, ptr, "frame_blend_in", 0, NULL, ICON_NONE);
14221420
uiItemR(row, ptr, "priority", 0, NULL, ICON_NONE);

source/blender/makesdna/DNA_actuator_types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ typedef struct bActuator {
392392
#define ACT_IPOFORCE (1 << 0)
393393
#define ACT_IPOEND (1 << 1)
394394
#define ACT_IPOLOCAL (1 << 2)
395-
#define ACT_IPOCHILD (1 << 4)
396395
#define ACT_IPOADD (1 << 5)
397396

398397
/* property actuator->type */

source/blender/makesrna/intern/rna_actuator.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,11 +693,6 @@ static void rna_def_action_actuator(BlenderRNA *brna)
693693
RNA_def_property_ui_text(prop, "L", "Let the Action act in local coordinates, used in Force and Add mode");
694694
RNA_def_property_update(prop, NC_LOGIC, NULL);
695695

696-
prop = RNA_def_property(srna, "apply_to_children", PROP_BOOLEAN, PROP_NONE);
697-
RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_IPOCHILD);
698-
RNA_def_property_ui_text(prop, "Child", "Update Action on all children Objects as well");
699-
RNA_def_property_update(prop, NC_LOGIC, NULL);
700-
701696
prop = RNA_def_property(srna, "blend_mode", PROP_ENUM, PROP_NONE);
702697
RNA_def_property_enum_sdna(prop, NULL, "blend_mode");
703698
RNA_def_property_enum_items(prop, prop_blend_items);

source/gameengine/Converter/BL_ConvertActuators.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,6 @@ void BL_ConvertActuators(const char *maggiename,
221221
if (actact->flag & ACT_IPOADD) {
222222
ipo_flags |= BL_Action::ACT_IPOFLAG_ADD;
223223
}
224-
if (actact->flag & ACT_IPOCHILD) {
225-
ipo_flags |= BL_Action::ACT_IPOFLAG_CHILD;
226-
}
227224

228225
BL_ActionActuator *tmpbaseact = new BL_ActionActuator(
229226
gameobj,

source/gameengine/Ketsji/BL_Action.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extern "C" {
5959
#include "BKE_library.h"
6060
#include "BKE_global.h"
6161

62-
BL_Action::BL_Action(class KX_GameObject *gameobj)
62+
BL_Action::BL_Action(KX_GameObject *gameobj)
6363
:m_action(nullptr),
6464
m_tmpaction(nullptr),
6565
m_blendpose(nullptr),
@@ -106,21 +106,17 @@ void BL_Action::AddController(SG_Controller *cont)
106106
return;
107107
}
108108

109-
m_sg_contr_list.push_back(cont);
110-
m_obj->GetNode()->AddController(cont);
109+
m_controllers.push_back(cont);
111110
}
112111

113112
void BL_Action::ClearControllerList()
114113
{
115-
SG_Node *node = m_obj->GetNode();
116-
117114
// Clear out the controller list
118-
for (SG_Controller *cont : m_sg_contr_list) {
119-
node->RemoveController(cont);
115+
for (SG_Controller *cont : m_controllers) {
120116
delete cont;
121117
}
122118

123-
m_sg_contr_list.clear();
119+
m_controllers.clear();
124120
}
125121

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

177-
SG_Node *node = m_obj->GetNode();
178-
179173
// Create an SG_Controller
180174
AddController(BL_CreateIPO(m_action, m_obj, kxscene));
181175
// World
@@ -251,7 +245,7 @@ bool BL_Action::IsDone()
251245
void BL_Action::InitIPO()
252246
{
253247
// Initialize the IPOs
254-
for (SG_Controller *cont : m_sg_contr_list) {
248+
for (SG_Controller *cont : m_controllers) {
255249
cont->SetOption(SG_Controller::SG_CONTR_IPO_RESET, true);
256250
cont->SetOption(SG_Controller::SG_CONTR_IPO_IPO_AS_FORCE, m_ipo_flags & ACT_IPOFLAG_FORCE);
257251
cont->SetOption(SG_Controller::SG_CONTR_IPO_IPO_ADD, m_ipo_flags & ACT_IPOFLAG_ADD);
@@ -415,6 +409,13 @@ void BL_Action::Update(float curtime, bool applyToObject)
415409

416410
m_requestIpo = true;
417411

412+
SG_Node *node = m_obj->GetNode();
413+
// Update controllers time.
414+
for (SG_Controller *cont : m_controllers) {
415+
cont->SetSimulatedTime(m_localframe); // update spatial controllers
416+
cont->Update(node);
417+
}
418+
418419
if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) {
419420
BL_ArmatureObject *obj = (BL_ArmatureObject *)m_obj;
420421

@@ -482,22 +483,17 @@ void BL_Action::Update(float curtime, bool applyToObject)
482483
shape_deformer->SetLastFrame(curtime);
483484
}
484485
}
486+
487+
// If the action is done we can remove its scene graph IPO controller.
488+
if (m_done) {
489+
ClearControllerList();
490+
}
485491
}
486492

487493
void BL_Action::UpdateIPOs()
488494
{
489-
if (m_sg_contr_list.empty()) {
490-
// Nothing to update or remove.
491-
return;
492-
}
493-
494495
if (m_requestIpo) {
495-
m_obj->UpdateIPO(m_localframe, m_ipo_flags & ACT_IPOFLAG_CHILD);
496+
m_obj->GetNode()->UpdateWorldDataThread();
496497
m_requestIpo = false;
497498
}
498-
499-
// If the action is done we can remove its scene graph IPO controller.
500-
if (m_done) {
501-
ClearControllerList();
502-
}
503499
}

source/gameengine/Ketsji/BL_Action.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,21 @@
3030
#include <string>
3131
#include <vector>
3232

33+
class KX_GameObject;
34+
class SG_Controller;
35+
36+
struct bAction;
37+
struct bPose;
38+
3339
class BL_Action
3440
{
3541
private:
36-
struct bAction* m_action;
37-
struct bAction* m_tmpaction;
38-
struct bPose* m_blendpose;
39-
struct bPose* m_blendinpose;
40-
std::vector<class SG_Controller*> m_sg_contr_list;
41-
class KX_GameObject* m_obj;
42+
bAction* m_action;
43+
bAction* m_tmpaction;
44+
bPose* m_blendpose;
45+
bPose* m_blendinpose;
46+
std::vector<SG_Controller *> m_controllers;
47+
KX_GameObject* m_obj;
4248
std::vector<float> m_blendshape;
4349
std::vector<float> m_blendinshape;
4450

@@ -146,7 +152,6 @@ class BL_Action
146152
ACT_IPOFLAG_FORCE = 1,
147153
ACT_IPOFLAG_LOCAL = 2,
148154
ACT_IPOFLAG_ADD = 4,
149-
ACT_IPOFLAG_CHILD = 8,
150155
};
151156
};
152157

source/gameengine/Ketsji/KX_GameObject.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -870,26 +870,6 @@ void KX_GameObject::SynchronizeTransformFunc(SG_Node *node, void *gameobj, void
870870
((KX_GameObject *)gameobj)->SynchronizeTransform();
871871
}
872872

873-
void KX_GameObject::InitIPO(bool ipo_as_force,
874-
bool ipo_add,
875-
bool ipo_local)
876-
{
877-
for (SG_Controller *cont : m_sgNode->GetControllerList()) {
878-
cont->SetOption(SG_Controller::SG_CONTR_IPO_RESET, true);
879-
cont->SetOption(SG_Controller::SG_CONTR_IPO_IPO_AS_FORCE, ipo_as_force);
880-
cont->SetOption(SG_Controller::SG_CONTR_IPO_IPO_ADD, ipo_add);
881-
cont->SetOption(SG_Controller::SG_CONTR_IPO_LOCAL, ipo_local);
882-
}
883-
}
884-
885-
void KX_GameObject::UpdateIPO(float curframetime,
886-
bool recurse)
887-
{
888-
// just the 'normal' update procedure.
889-
m_sgNode->SetSimulatedTimeThread(curframetime, recurse);
890-
m_sgNode->UpdateWorldDataThread();
891-
}
892-
893873
bool KX_GameObject::GetVisible(void)
894874
{
895875
return m_bVisible;

source/gameengine/Ketsji/KX_GameObject.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -620,25 +620,6 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator
620620

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

623-
/**
624-
* Function to set IPO option at start of IPO
625-
*/
626-
void
627-
InitIPO(
628-
bool ipo_as_force,
629-
bool ipo_add,
630-
bool ipo_local
631-
);
632-
633-
/**
634-
* Odd function to update an ipo. ???
635-
*/
636-
void
637-
UpdateIPO(
638-
float curframetime,
639-
bool recurse
640-
);
641-
642623
/**
643624
* \section Mesh accessor functions.
644625
*/

source/gameengine/SceneGraph/SG_Node.cpp

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ SG_Node::SG_Node(const SG_Node & other)
8080

8181
SG_Node::~SG_Node()
8282
{
83-
for (SG_Controller *cont : m_controllers) {
84-
delete cont;
85-
}
8683
}
8784

8885
SG_Node *SG_Node::GetReplica()
@@ -261,35 +258,6 @@ void SG_Node::UpdateWorldDataThreadSchedule(bool parentUpdated)
261258
}
262259
}
263260

264-
void SG_Node::SetSimulatedTime(double time, bool recurse)
265-
{
266-
// update the controllers of this node.
267-
SetControllerTime(time);
268-
269-
// update children's simulate time.
270-
if (recurse) {
271-
for (SG_Node *childnode : m_children) {
272-
childnode->SetSimulatedTime(time, recurse);
273-
}
274-
}
275-
}
276-
277-
void SG_Node::SetSimulatedTimeThread(double time, bool recurse)
278-
{
279-
CM_ThreadSpinLock& famillyMutex = m_familly->GetMutex();
280-
famillyMutex.Lock();
281-
// update the controllers of this node.
282-
SetControllerTime(time);
283-
284-
// update children's simulate time.
285-
if (recurse) {
286-
for (SG_Node *childnode : m_children) {
287-
childnode->SetSimulatedTime(time, recurse);
288-
}
289-
}
290-
famillyMutex.Unlock();
291-
}
292-
293261
bool SG_Node::Schedule(SG_QList& head)
294262
{
295263
scheduleMutex.Lock();
@@ -329,28 +297,6 @@ SG_Node *SG_Node::GetNextRescheduled(SG_QList& head)
329297
return result;
330298
}
331299

332-
void SG_Node::AddController(SG_Controller *cont)
333-
{
334-
m_controllers.push_back(cont);
335-
}
336-
337-
void SG_Node::RemoveController(SG_Controller *cont)
338-
{
339-
m_mutex.Lock();
340-
CM_ListRemoveIfFound(m_controllers, cont);
341-
m_mutex.Unlock();
342-
}
343-
344-
void SG_Node::RemoveAllControllers()
345-
{
346-
m_controllers.clear();
347-
}
348-
349-
SGControllerList& SG_Node::GetControllerList()
350-
{
351-
return m_controllers;
352-
}
353-
354300
SG_Callbacks& SG_Node::GetCallBackFunctions()
355301
{
356302
return m_callbacks;
@@ -375,13 +321,6 @@ void SG_Node::SetClientInfo(void *clientInfo)
375321
m_clientInfo = clientInfo;
376322
}
377323

378-
void SG_Node::SetControllerTime(double time)
379-
{
380-
for (SG_Controller *cont : m_controllers) {
381-
cont->SetSimulatedTime(time);
382-
}
383-
}
384-
385324
void SG_Node::ClearModified()
386325
{
387326
m_modified = false;
@@ -416,11 +355,6 @@ SG_ParentRelation *SG_Node::GetParentRelation()
416355
*/
417356
void SG_Node::UpdateSpatialData(const SG_Node *parent, bool& parentUpdated)
418357
{
419-
// update spatial controllers
420-
for (SG_Controller *cont : m_controllers) {
421-
cont->Update(this);
422-
}
423-
424358
// Ask the parent_relation object owned by this class to update our world coordinates.
425359
ComputeWorldTransforms(parent, parentUpdated);
426360
}

0 commit comments

Comments
 (0)