Skip to content

Commit

Permalink
UPBGE: Implement range loop for CListValue.
Browse files Browse the repository at this point in the history
With the new features of C++11 loops are now easily to write using
the range loop syntax. But in sources we heavily used CListValue for
lists accesible in python and managed in C++. CListValue wasn't
supporting range loop becuase of a main rason: it was based on
CValue type for item only.
The first modification to allow range loop is to make CListValue
use a subtype of CValue, this was done for the iterator loop with
templates, but with renage loop syntax we could not specify any
template parameter.
To fix this issue the CListValue now use a template argument for the
item type used, e.g
CListValue<KX_GameObject> objects;
In addition CBaseListValue class is shared by all the CListValue type
to expose a common python proxy and store the item at CValue type,
indeed CListValue just allow casting to upper item types.
Once this the CListValue iterator can be get through the functions
begin() and end() defined globally.
  • Loading branch information
panzergame committed Jun 8, 2017
1 parent 48e96c8 commit 4fdab9f
Show file tree
Hide file tree
Showing 27 changed files with 569 additions and 586 deletions.
34 changes: 13 additions & 21 deletions source/gameengine/Converter/BL_ArmatureObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ BL_ArmatureObject::BL_ArmatureObject(void *sgReplicationInfo,
m_drawDebug(false),
m_lastapplyframe(0.0)
{
m_controlledConstraints = new CListValue();
m_poseChannels = new CListValue();
m_controlledConstraints = new CListValue<BL_ArmatureConstraint>();
m_poseChannels = new CListValue<BL_ArmatureChannel>();

// Keep a copy of the original armature so we can fix drivers later
m_origObjArma = armature;
Expand Down Expand Up @@ -320,7 +320,7 @@ size_t BL_ArmatureObject::GetConstraintNumber() const

BL_ArmatureConstraint *BL_ArmatureObject::GetConstraint(const std::string& posechannel, const std::string& constraintname)
{
return m_controlledConstraints->FindIf<BL_ArmatureConstraint>(
return m_controlledConstraints->FindIf(
[&posechannel, &constraintname](BL_ArmatureConstraint *constraint) { return constraint->Match(posechannel, constraintname); });
}

Expand Down Expand Up @@ -353,7 +353,7 @@ size_t BL_ArmatureObject::GetChannelNumber() const
BL_ArmatureChannel *BL_ArmatureObject::GetChannel(bPoseChannel *pchan)
{
LoadChannels();
return m_poseChannels->FindIf<BL_ArmatureChannel>([&pchan](BL_ArmatureChannel *channel) { return channel->m_posechannel == pchan; });
return m_poseChannels->FindIf([&pchan](BL_ArmatureChannel *channel) { return channel->m_posechannel == pchan; });
}

BL_ArmatureChannel *BL_ArmatureObject::GetChannel(const std::string& str)
Expand Down Expand Up @@ -383,7 +383,7 @@ void BL_ArmatureObject::ProcessReplica()
KX_GameObject::ProcessReplica();

// Replicate each constraints.
m_controlledConstraints = static_cast<CListValue *>(m_controlledConstraints->GetReplica());
m_controlledConstraints = static_cast<CListValue<BL_ArmatureConstraint> *>(m_controlledConstraints->GetReplica());
// Share pose channels.
m_poseChannels->AddRef();

Expand All @@ -400,20 +400,16 @@ int BL_ArmatureObject::GetGameObjectType() const

void BL_ArmatureObject::ReParentLogic()
{
for (CListValue::iterator<BL_ArmatureConstraint> it = m_controlledConstraints->GetBegin(), end = m_controlledConstraints->GetEnd();
it != end; ++it)
{
(*it)->ReParent(this);
for (BL_ArmatureConstraint *constraint : m_controlledConstraints) {
constraint->ReParent(this);
}
KX_GameObject::ReParentLogic();
}

void BL_ArmatureObject::Relink(std::map<SCA_IObject *, SCA_IObject *>& obj_map)
{
for (CListValue::iterator<BL_ArmatureConstraint> it = m_controlledConstraints->GetBegin(), end = m_controlledConstraints->GetEnd();
it != end; ++it)
{
(*it)->Relink(obj_map);
for (BL_ArmatureConstraint *constraint : m_controlledConstraints) {
constraint->Relink(obj_map);
}
KX_GameObject::Relink(obj_map);
}
Expand All @@ -422,10 +418,8 @@ bool BL_ArmatureObject::UnlinkObject(SCA_IObject *clientobj)
{
// clientobj is being deleted, make sure we don't hold any reference to it
bool res = false;
for (CListValue::iterator<BL_ArmatureConstraint> it = m_controlledConstraints->GetBegin(), end = m_controlledConstraints->GetEnd();
it != end; ++it)
{
res |= (*it)->UnlinkObject(clientobj);
for (BL_ArmatureConstraint *constraint : m_controlledConstraints) {
res |= constraint->UnlinkObject(clientobj);
}
return res;
}
Expand All @@ -439,10 +433,8 @@ void BL_ArmatureObject::ApplyPose()
//m_scene->r.cfra++;
if (m_lastapplyframe != m_lastframe) {
// update the constraint if any, first put them all off so that only the active ones will be updated
for (CListValue::iterator<BL_ArmatureConstraint> it = m_controlledConstraints->GetBegin(), end = m_controlledConstraints->GetEnd();
it != end; ++it)
{
(*it)->UpdateTarget();
for (BL_ArmatureConstraint *constraint : m_controlledConstraints) {
constraint->UpdateTarget();
}
// update ourself
UpdateBlenderObjectMatrix(m_objArma);
Expand Down
8 changes: 4 additions & 4 deletions source/gameengine/Converter/BL_ArmatureObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class BL_ArmatureObject : public KX_GameObject
Py_Header

protected:
/* list element: BL_ArmatureConstraint. Use SG_DListHead to have automatic list replication */
CListValue *m_controlledConstraints;
/* list element: BL_ArmatureChannel. Use SG_DList to avoid list replication */
CListValue *m_poseChannels;
/// List element: BL_ArmatureConstraint.
CListValue<BL_ArmatureConstraint> *m_controlledConstraints;
/// List element: BL_ArmatureChannel.
CListValue<BL_ArmatureChannel> *m_poseChannels;
Object *m_objArma;
Object *m_origObjArma;
bPose *m_pose;
Expand Down
Loading

0 comments on commit 4fdab9f

Please sign in to comment.