Skip to content

Commit

Permalink
UPBGE: Implement node dirty flag for multiple users.
Browse files Browse the repository at this point in the history
Previously only one flag noticed that the object node trasform changed,
using only one flag is limiting for futur work as occlusion were we would
like to rebuild a BVH tree if a node changed.

To avoid this limitation we use a bitmask where a value of 0 mean not dirty
and a value of 1 dirty. The bitmask is compared through the functions
SG_Node::IsDirty(flag) and cleared thanks to SG_Node::ClearDirty.

The current users are DIRTY_RENDER and DIRTY_CULLING.
  • Loading branch information
panzergame committed Jun 18, 2017
1 parent 0d4ca63 commit 2b06fad
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion source/gameengine/Ketsji/KX_FontObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void KX_FontObject::AddMeshUser()
void KX_FontObject::UpdateBuckets()
{
// Update datas and add mesh slot to be rendered only if the object is not culled.
if (m_pSGNode->IsDirty()) {
if (m_pSGNode->IsDirty(SG_Node::DIRTY_RENDER)) {
NodeGetWorldTransform().getValue(m_meshUser->GetMatrix());
}

Expand Down
3 changes: 2 additions & 1 deletion source/gameengine/Ketsji/KX_GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,9 @@ void KX_GameObject::AddMeshUser()
void KX_GameObject::UpdateBuckets()
{
// Update datas and add mesh slot to be rendered only if the object is not culled.
if (m_pSGNode->IsDirty()) {
if (m_pSGNode->IsDirty(SG_Node::DIRTY_RENDER)) {
NodeGetWorldTransform().getValue(m_meshUser->GetMatrix());
m_pSGNode->ClearDirty(SG_Node::DIRTY_RENDER);
}

m_meshUser->SetColor(m_objectColor);
Expand Down
15 changes: 8 additions & 7 deletions source/gameengine/SceneGraph/SG_Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ SG_Node::SG_Node(void *clientobj, void *clientinfo, SG_Callbacks& callbacks)
m_parent_relation(nullptr),
m_familly(new SG_Familly()),
m_modified(true),
m_ogldirty(false)
m_dirty(DIRTY_NONE)
{
}

Expand All @@ -72,7 +72,7 @@ SG_Node::SG_Node(const SG_Node & other)
m_worldScaling(other.m_worldScaling),
m_parent_relation(other.m_parent_relation->NewCopy()),
m_familly(new SG_Familly()),
m_ogldirty(false)
m_dirty(DIRTY_NONE)
{
}

Expand Down Expand Up @@ -388,7 +388,7 @@ void SG_Node::SetControllerTime(double time)
void SG_Node::ClearModified()
{
m_modified = false;
m_ogldirty = true;
m_dirty = DIRTY_ALL;
}

void SG_Node::SetModified()
Expand All @@ -397,9 +397,9 @@ void SG_Node::SetModified()
ActivateScheduleUpdateCallback();
}

void SG_Node::ClearDirty()
void SG_Node::ClearDirty(DirtyFlag flag)
{
m_ogldirty = false;
m_dirty &= ~flag;
}

void SG_Node::SetParentRelation(SG_ParentRelation *relation)
Expand Down Expand Up @@ -597,9 +597,10 @@ bool SG_Node::IsModified()
{
return m_modified;
}
bool SG_Node::IsDirty()

bool SG_Node::IsDirty(DirtyFlag flag)
{
return m_ogldirty;
return (m_dirty & flag);
}

bool SG_Node::ActivateReplicationCallback(SG_Node *replica)
Expand Down
14 changes: 10 additions & 4 deletions source/gameengine/SceneGraph/SG_Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ typedef std::vector<SG_Node *> NodeList;
class SG_Node : public SG_QList
{
public:
enum DirtyFlag {
DIRTY_NONE = 0,
DIRTY_ALL = 0xFF,
DIRTY_RENDER = (1 << 0),
DIRTY_CULLING = (1 << 1)
};

SG_Node(void *clientobj, void *clientinfo, SG_Callbacks& callbacks);
SG_Node(const SG_Node & other);
virtual ~SG_Node();
Expand All @@ -127,7 +134,6 @@ class SG_Node : public SG_QList
* If the node was not a child of this object no action is performed.
*/
void RemoveChild(SG_Node *child);

/**
* Return true if the node is the ancestor of child
*/
Expand Down Expand Up @@ -284,7 +290,7 @@ class SG_Node : public SG_QList

void ClearModified();
void SetModified();
void ClearDirty();
void ClearDirty(DirtyFlag flag);

/**
* Define the relationship this node has with it's parent
Expand Down Expand Up @@ -339,7 +345,7 @@ class SG_Node : public SG_QList
void SetFamilly(const std::shared_ptr<SG_Familly>& familly);

bool IsModified();
bool IsDirty();
bool IsDirty(DirtyFlag flag);

protected:
friend class SG_Controller;
Expand Down Expand Up @@ -394,7 +400,7 @@ class SG_Node : public SG_QList
CM_ThreadMutex m_mutex;

bool m_modified;
bool m_ogldirty; // true if the openGL matrix for this object must be recomputed
unsigned short m_dirty;
};

#endif // __SG_NODE_H__

0 comments on commit 2b06fad

Please sign in to comment.