void IncAnimFrameNum(SuperAnimHandler &theMainDefHandler, float theDeltaTime, bool &hitNewLabel){ if (!theMainDefHandler.IsValid()) { return; } int aLastFrameNum = (int)theMainDefHandler.mCurFrameNum; theMainDefHandler.mCurFrameNum += theDeltaTime * theMainDefHandler.mAnimRate; int aCurFrame = (int)theMainDefHandler.mCurFrameNum; if (aCurFrame != aLastFrameNum) // Reach new frame { // Check whether reach a new label frame bool aIsNewLabel = false; SuperAnimMainDef *aMainDef = SuperAnimDefMgr::GetInstance()->Load_GetSuperAnimMainDef(theMainDefHandler.mMainDefKey); if (aCurFrame >= aMainDef->mEndFrameNum)// reach the end?? { theMainDefHandler.mCurFrameNum = aMainDef->mEndFrameNum; aIsNewLabel = true; } else { std::string aTempLabel; int aMaxFrameNum = -1; for (StringToIntMap::const_iterator it = aMainDef->mLabels.begin(); it != aMainDef->mLabels.end(); ++it) { if (aCurFrame >= it->second && it->second > aMaxFrameNum) { aMaxFrameNum = it->second; aTempLabel = it->first; } } if (aTempLabel != theMainDefHandler.mCurLabel) { aIsNewLabel = true; } } hitNewLabel = aIsNewLabel; } }
void IncAnimFrameNum(SuperAnimHandler &theMainDefHandler, float theDeltaTime, bool &hitNewLabel){ if (!theMainDefHandler.IsValid()) { return; } int aLastFrameNum = (int)theMainDefHandler.mCurFrameNum; theMainDefHandler.mCurFrameNum += theDeltaTime * theMainDefHandler.mAnimRate; int aCurFrame = (int)theMainDefHandler.mCurFrameNum; if (aCurFrame != aLastFrameNum) // Reach new frame { // Check whether reach a new label frame bool aIsNewLabel = false; if (aCurFrame >= theMainDefHandler.mLastFrameNumOfCurLabel) { theMainDefHandler.mCurFrameNum = theMainDefHandler.mLastFrameNumOfCurLabel; aIsNewLabel = true; } hitNewLabel = aIsNewLabel; } }
bool IterateAnimObjDrawInfo(const SuperAnimHandler &theHandler, SuperAnimObjDrawInfo& theOutputObjDrawInfo){ if (!sShouldStartAnimObjDrawItr) { assert(false && "Forgot to call BeginIterateAnimObjDrawInfo?"); return false; } if (!theHandler.IsValid()) { assert(false && "The Animation handler is not valid."); return false; } SuperAnimMainDef *aMainDef = SuperAnimDefMgr::GetInstance()->Load_GetSuperAnimMainDef(theHandler.mMainDefKey); if (aMainDef == NULL) { assert(false && "I can't find the Animation definition."); return false; } int aCurFrameNum = (int)theHandler.mCurFrameNum; SuperAnimFrame *aCurFrame = &aMainDef->mFrames[aCurFrameNum]; if (sAnimObjIndex >= aCurFrame->mObjectVector.size()) { // we have iterated all objects in this frame sShouldStartAnimObjDrawItr = false; return false; } SuperAnimObject *aCurObject = &aCurFrame->mObjectVector[sAnimObjIndex]; // find the image, fill the sprite id SuperAnimImage *aSuperAnimImage = &aMainDef->mImageVector[aCurObject->mResNum]; theOutputObjDrawInfo.mSpriteId = aSuperAnimImage->mSpriteId; // do the interpolateion to next frame for transform & color if (aCurFrameNum == aMainDef->mEndFrameNum) { // reach the end frame, don't need to do any interpolation theOutputObjDrawInfo.mTransform = aCurObject->mTransform; theOutputObjDrawInfo.mColor = aCurObject->mColor; } else { int aNextFrameNum = aCurFrameNum + 1; bool finishedInterp = false; SuperAnimFrame *aNextFrame = &aMainDef->mFrames[aNextFrameNum]; for (int i = 0; i < aNextFrame->mObjectVector.size(); ++i) { SuperAnimObject *anObj = &aNextFrame->mObjectVector[i]; if (anObj->mObjectNum == aCurObject->mObjectNum) { float anInterp = theHandler.mCurFrameNum - aCurFrameNum; theOutputObjDrawInfo.mTransform = aCurObject->mTransform.InterpolateTo(anObj->mTransform, anInterp); theOutputObjDrawInfo.mColor = aCurObject->mColor.InterpolateTo(anObj->mColor, anInterp); finishedInterp = true; break; } } if (!finishedInterp) { // we miss the object in next frame? // never mind theOutputObjDrawInfo.mTransform = aCurObject->mTransform; theOutputObjDrawInfo.mColor = aCurObject->mColor; } } theOutputObjDrawInfo.mTransform = theOutputObjDrawInfo.mTransform.TransformSrc(aSuperAnimImage->mTransform); SuperAnimMatrix3 aMatrix; aMatrix.LoadIdentity(); aMatrix.m02 = aSuperAnimImage->mWidth * 0.5f; aMatrix.m12 = aSuperAnimImage->mHeight * 0.5f; theOutputObjDrawInfo.mTransform.mMatrix = theOutputObjDrawInfo.mTransform.mMatrix * aMatrix; sAnimObjIndex++; return true; }