1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     gfx_AnimOverrider.cpp
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: 31311 $
16  *---------------------------------------------------------------------------*/
17 
18 #include "precompiled.h"
19 
20 #include <nw/anim/anim_AnimBlend.h>
21 #include <nw/gfx/gfx_AnimGroup.h>
22 #include <nw/gfx/gfx_AnimOverrider.h>
23 
24 namespace nw
25 {
26 namespace gfx
27 {
28 
29 NW_UT_RUNTIME_TYPEINFO_DEFINITION(AnimOverrider    , AnimBlender);
30 
31 //----------------------------------------------------------
32 const anim::AnimResult*
GetResult(void * target,int memberIdx) const33 AnimOverrider::GetResult(
34     void* target,
35     int memberIdx
36 ) const
37 {
38     //----------------------------------------------------------
39     // ブレンドオペレーションがない場合および
40     // ブレンドオペレーションにブレンド処理がない場合は上書き処理
41     const anim::AnimBlendOp* blendOp = m_AnimGroup->GetBlendOperation(memberIdx);
42     if (blendOp == NULL || !blendOp->HasBlend())
43     {
44         for (int animIdx = m_AnimObjects.Size() - 1; animIdx >= 0; --animIdx)
45         {
46             if (m_AnimObjects[animIdx] == NULL)
47             {
48                 continue;
49             }
50             const anim::AnimResult* childResult =
51                 m_AnimObjects[animIdx]->GetResult(target, memberIdx);
52             if (childResult != NULL)
53             {
54                 return childResult;
55             }
56         }
57         return NULL;
58     }
59 
60     //----------------------------------------------------------
61     // すべての子アニメーションについてループ
62     anim::AnimResult* result = reinterpret_cast<anim::AnimResult*>(target);
63     anim::AnimResult workResult;
64     bool written = false;
65     for (int animIdx = m_AnimObjects.Size() - 1; animIdx >= 0; --animIdx)
66     {
67         if (m_AnimObjects[animIdx] == NULL)
68         {
69             continue;
70         }
71         const anim::AnimResult* childResult =
72             m_AnimObjects[animIdx]->GetResult(&workResult, memberIdx);
73         if (childResult != NULL)
74         {
75             written = true;
76             if (blendOp->Override(result, childResult)) // 全成分を上書きしたら true が返る
77             {
78                 return result;
79             }
80         }
81     }
82 
83     if (!written) // 有効な子アニメーションなし
84     {
85         return NULL;
86     }
87 
88     return result;
89 }
90 
91 } // namespace gfx
92 } // namespace nw
93