//----------------------------------------------------------------// void MOAIAnim::Apply ( float t0, float t1 ) { if ( t0 == t1 ) { this->Apply ( t0 ); return; } MOAIAttrOp attrOp; u32 total = this->mLinks.Size (); for ( u32 i = 0; i < total; ++i ) { MOAIAnimLink& link = this->mLinks [ i ]; MOAIAnimCurveBase* curve = link.mCurve; MOAINode* target = link.mTarget; if ( curve && target ) { if ( link.mRelative ) { curve->GetDelta ( attrOp, t0, t1 ); target->ApplyAttrOp ( link.mAttrID, attrOp, MOAIAttrOp::ADD ); } else { curve->GetValue ( attrOp, t1 ); target->ApplyAttrOp ( link.mAttrID, attrOp, MOAIAttrOp::SET ); } target->ScheduleUpdate (); } } }
//----------------------------------------------------------------// void MOAIAnim::Apply ( float t0, float t1 ) { if ( t0 == t1 ) { this->Apply ( t0 ); return; } MOAIAttrOp adder; u32 total = this->mLinks.Size (); for ( u32 i = 0; i < total; ++i ) { MOAIAnimLink& link = this->mLinks [ i ]; MOAIAnimCurve* curve = link.mCurve; MOAINode* target = link.mTarget; if ( curve && target ) { if ( link.mRelative ) { float value = curve->GetFloatDelta ( t0, t1 ); adder.SetValue ( value ); target->ApplyAttrOp ( link.mAttrID, adder, MOAIAttrOp::ADD ); } else { float value = curve->GetFloatValue ( t1 ); target->SetAttributeValue < float >( link.mAttrID, value ); } target->ScheduleUpdate (); } } }
//----------------------------------------------------------------// MOAINodeMgr::~MOAINodeMgr () { MOAINode* cursor = this->mUpdateListHead; while ( cursor ) { MOAINode* node = cursor; cursor = cursor->mNext; node->mState = MOAINode::STATE_IDLE; node->Release (); } }
/** @name setAttrLink @text Sets a *pull* attribute connecting an attribute in the note to an attribute in a foreign node. @in MOAINode self @in number attrID ID of attribute to become dependent of foreign node. @in MOAINode sourceNode Foreign node. @in number sourceAttrID Attribute in foreign node to control value of attribue. @out nil */ int MOAINode::_setAttrLink ( lua_State* L ) { MOAI_LUA_SETUP ( MOAINode, "UNUN" ); u32 attrID = state.GetValue < u32 >( 2, 0 ); MOAI_ERROR_UNLESS ( self->AttrExists ( attrID ), state, MOAILogMessages::MOAINode_AttributeNotFound ); MOAINode* srcNode = state.GetLuaObject < MOAINode >( 3 ); if ( !srcNode ) return 0; u32 srcAttrID = state.GetValue < u32 >( 4, 0 ); MOAI_ERROR_UNLESS ( srcNode->AttrExists ( srcAttrID ), state, MOAILogMessages::MOAINode_AttributeNotFound ); self->SetAttrLink ( attrID, srcNode, srcAttrID ); self->ScheduleUpdate (); return 0; }
//----------------------------------------------------------------// void MOAINodeMgr::Update () { for ( u32 iterations = 0; this->mScheduled && ( iterations < this->mMaxIterations ); ++iterations ) { this->mScheduled = false; MOAINode* node = this->mUpdateListHead; for ( ; node ; node = node->mNext ) { node->DepNodeUpdate (); } } if ( !this->mScheduled ) { this->Reset (); } }
//----------------------------------------------------------------// void MOAINode::ActivateOnLink ( MOAINode& srcNode ) { if ( this->mState != STATE_IDLE ) { if ( srcNode.mState == STATE_IDLE ) { srcNode.Activate ( *this ); } else { MOAINodeMgr& depNodeMgr = MOAINodeMgr::Get (); if ( srcNode.IsNodeUpstream ( this )) { depNodeMgr.Remove ( *this ); depNodeMgr.InsertAfter ( srcNode, *this ); } } } }
//----------------------------------------------------------------// void MOAIAnim::Apply ( float t ) { u32 total = this->mLinks.Size (); for ( u32 i = 0; i < total; ++i ) { MOAIAnimLink& link = this->mLinks [ i ]; MOAIAnimCurve* curve = link.mCurve; MOAINode* target = link.mTarget; if ( curve && target ) { if ( !link.mRelative ) { float value = curve->GetFloatValue ( t ); target->SetAttributeValue < float >( link.mAttrID, value ); } target->ScheduleUpdate (); } } }
//----------------------------------------------------------------// void MOAINodeMgr::Update () { MOAINode* node = this->mUpdateListHead; for ( ; node ; node = node->mNext ) { node->DepNodeUpdate (); } // TODO: fix this up later node = this->mUpdateListHead; while ( node ) { MOAINode* temp = node; node = node->mNext; temp->mState = MOAINode::STATE_IDLE; } this->mUpdateListHead = 0; this->mUpdateListTail = 0; }
/** @name setAttrLink @text Sets a *pull* attribute connecting an attribute in the node to an attribute in a foreign node. @in MOAINode self @in number attrID ID of attribute to become dependent of foreign node. @in MOAINode sourceNode Foreign node. @opt number sourceAttrID Attribute in foreign node to control value of attribue. Default value is attrID. @out nil */ int MOAINode::_setAttrLink ( lua_State* L ) { MOAI_LUA_SETUP ( MOAINode, "UNU" ); u32 attrID = state.GetValue < u32 >( 2, 0 ); MOAINode* srcNode = state.GetLuaObject < MOAINode >( 3, true ); if ( !srcNode ) return 0; u32 srcAttrID = state.GetValue < u32 >( 4, attrID ); if ( srcNode->CheckAttrExists ( srcAttrID )) { self->SetAttrLink ( attrID, srcNode, srcAttrID ); self->ScheduleUpdate (); return 0; } MOAILog ( L, MOAILogMessages::MOAINode_AttributeNotFound ); return 0; }
//----------------------------------------------------------------// void MOAIAnim::Apply ( float t ) { MOAIAttrOp attrOp; u32 total = this->mLinks.Size (); for ( u32 i = 0; i < total; ++i ) { MOAIAnimLink& link = this->mLinks [ i ]; MOAIAnimCurveBase* curve = link.mCurve; MOAINode* target = link.mTarget; if ( curve && target ) { if ( !link.mRelative ) { curve->GetValue ( attrOp, t ); target->ApplyAttrOp ( link.mAttrID, attrOp, MOAIAttrOp::SET ); } target->ScheduleUpdate (); } } }
//----------------------------------------------------------------// void MOAINodeMgr::InsertBefore ( MOAINode& cursor, MOAINode& node ) { if ( cursor.mPrev ) { node.mPrev = cursor.mPrev; node.mNext = &cursor; node.mPrev->mNext = &node; node.mNext->mPrev = &node; node.Retain (); } else { this->PushFront ( node ); } }
//----------------------------------------------------------------// void MOAINodeMgr::InsertAfter ( MOAINode& cursor, MOAINode& node ) { if ( cursor.mNext ) { node.mPrev = &cursor; node.mNext = cursor.mNext; node.mPrev->mNext = &node; node.mNext->mPrev = &node; node.Retain (); } else { this->PushBack ( node ); } }
//----------------------------------------------------------------// void MOAINodeMgr::PushFront ( MOAINode& node ) { node.mNext = 0; node.mPrev = 0; if ( !this->mUpdateListHead ) { this->mUpdateListHead = &node; this->mUpdateListTail = &node; } else { node.mNext = this->mUpdateListHead; this->mUpdateListHead->mPrev = &node; this->mUpdateListHead = &node; } node.Retain (); }
//----------------------------------------------------------------// void MOAINodeMgr::PushBack ( MOAINode& node ) { node.mNext = 0; node.mPrev = 0; if ( !this->mUpdateListHead ) { this->mUpdateListHead = &node; this->mUpdateListTail = &node; } else { node.mPrev = this->mUpdateListTail; this->mUpdateListTail->mNext = &node; this->mUpdateListTail = &node; } node.Retain (); }
//----------------------------------------------------------------// void MOAINodeMgr::Remove ( MOAINode& node ) { if ( node.mNext ) { node.mNext->mPrev = node.mPrev; } else { this->mUpdateListTail = node.mPrev; } if ( node.mPrev ) { node.mPrev->mNext = node.mNext; } else { this->mUpdateListHead = node.mNext; } node.Release (); }