/*---------------------------------------------------------------------------* Project: NintendoWare File: demo_Utility.h Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision: 28152 $ *---------------------------------------------------------------------------*/ #ifndef NW_DEMO_UTILITY_H_ #define NW_DEMO_UTILITY_H_ #include #include #include #include #include // ファイル名定義ユーティリティマクロです。 #define NW_DEMO_FILE_PATH(name) (L"rom:/" name) namespace nw { namespace demo { namespace internal { bool IsTerminatingImpl(); } // namespace internal //============================================================================ //! @name ユーティリティ //@{ //--------------------------------------------------------------------------- //! @brief デモに使用するユーティリティ関数をまとめたクラスです。 //--------------------------------------------------------------------------- class Utility { public: static const nw::math::VEC3 CAMERA_POSITION; //!< カメラ位置のデフォルト値です。 static const nw::math::VEC3 TARGET_POSITION; //!< カメラターゲットのデフォルト値です。 static const f32 NEAR_CLIP; //!< ニアクリップのデフォルト値です。 static const f32 FAR_CLIP; //!< ファークリップのデフォルト値です。 static const f32 FOVY_RADIAN; //!< FOVのY方向のデフォルト値です。 static const nw::math::VEC2 PROJECTION_CENTER; //!< カメラの投影面の中心位置です。 static const f32 PROJECTION_HEIGHT; //!< カメラの投影面の高さです。 //--------------------------------------------------------------------------- //! @brief アニメーションの種類を表します。 //--------------------------------------------------------------------------- enum AnimationType { SKELETAL_ANIMATION, //!< スケルタルアニメーションを表します。 MATERIAL_ANIMATION, //!< マテリアルアニメーションを表します。 VISIBILITY_ANIMATION, //!< ビジビリティアニメーションを表します。 CAMERA_ANIMATION, //!< カメラアニメーションを表します。 LIGHT_ANIMATION, //!< ライトアニメーションを表します。 FOG_ANIMATION //!< フォグアニメーションを表します。 }; //===================== //! @name 初期化 //@{ //--------------------------------------------------------------------------- //! @brief GraphicsDrawing の初期化を行います。 //! //! @param[in] allocator アロケータです。 //! @param[in] graphicsDrawing 初期化を行う GraphicsDrawing です。 //--------------------------------------------------------------------------- static void InitializeGraphicsDrawing( os::IAllocator* allocator, nw::demo::GraphicsDrawing& graphicsDrawing ); //@} //===================== //! @name ファイル //@{ //--------------------------------------------------------------------------- //! @brief ファイルをロードします。 //! //! @param[in] allocator アロケータです。 //! @param[in] filePath ファイルのパス名です。 //! @param[in] align アライメントです。 //! //! @return ロードしたファイルのバッファを返します。 //--------------------------------------------------------------------------- static ut::MoveArray LoadFile( os::IAllocator* allocator, const wchar_t* filePath, u32 align = 32 ); //--------------------------------------------------------------------------- //! @brief グラフィックスリソースをロードします。 //! //! @param[in] resourceArray 追加を行うリソースの配列です。 //! @param[in] resourcePath ファイルのパス名 //! @param[in] allocator アロケータです。 //! //! @return ロードしたグラフィックス情報を返します。 //--------------------------------------------------------------------------- static ResourceSet* LoadResources(ResourceArray& resourceArray, const wchar_t* resourcePath, os::IAllocator* allocator); //@} //===================== //! @name カメラ //@{ //--------------------------------------------------------------------------- //! @brief カメラを生成します。 //! //! @param[in] allocator 生成に使用するアロケーターです。 //! @param[in] cameraPosition カメラの位置座標です。 //! @param[in] targetPosition カメラターゲットの座標です。 //! @param[in] nearClip ニアクリップの値です。 //! @param[in] farClip ファークリップの値です。 //! @param[in] fovyRadian FOVのY方向の値です。 //! @param[in] pivotDirection 画面の上方向です。 //! @param[in] wScale wScale の値です。 //! //! @return 生成したカメラを返します。 //--------------------------------------------------------------------------- static nw::gfx::Camera* CreateCamera( os::IAllocator* allocator, const nw::math::VEC3& cameraPosition = CAMERA_POSITION, const nw::math::VEC3& targetPosition = TARGET_POSITION, f32 nearClip = NEAR_CLIP, f32 farClip = FAR_CLIP, f32 fovyRadian = FOVY_RADIAN, nw::math::PivotDirection pivotDirection = nw::math::PIVOT_UPSIDE_TO_TOP, f32 wScale = 0.0f ); //--------------------------------------------------------------------------- //! @brief カメラを生成します。 //! //! @param[in] allocator 生成に使用するアロケーターです。 //! @param[in] cameraPosition カメラの位置座標です。 //! @param[in] targetPosition カメラターゲットの座標です。 //! @param[in] nearClip ニアクリップの値です。 //! @param[in] farClip ファークリップの値です。 //! @param[in] fovyRadian FOVのY方向の値です。 //! @param[in] pivotDirection 画面の上方向です。 //! @param[in] wScale wScale の値です。 //! //! @return 生成したカメラを返します。 //--------------------------------------------------------------------------- static nw::gfx::Camera* CreateAimCamera( os::IAllocator* allocator, const nw::math::VEC3& cameraPosition = CAMERA_POSITION, const nw::math::VEC3& targetPosition = TARGET_POSITION, f32 nearClip = NEAR_CLIP, f32 farClip = FAR_CLIP, f32 fovyRadian = FOVY_RADIAN, nw::math::PivotDirection pivotDirection = nw::math::PIVOT_UPSIDE_TO_TOP, f32 wScale = 0.0f ); //--------------------------------------------------------------------------- //! @brief カメラを生成します。 //! //! @param[in] allocator 生成に使用するアロケーターです。 //! @param[in] cameraPosition カメラの位置座標です。 //! @param[in] targetPosition カメラターゲットの座標です。 //! @param[in] nearClip ニアクリップの値です。 //! @param[in] farClip ファークリップの値です。 //! @param[in] projectionCenter 投影面の中心位置です。 //! @param[in] projectionHeight 投影面の高さです。 //! @param[in] pivotDirection 画面の上方向です。 //! @param[in] wScale wScale の値です。 //! //! @return 生成したカメラを返します。 //--------------------------------------------------------------------------- static nw::gfx::Camera* CreateFrustumCamera( os::IAllocator* allocator, const nw::math::VEC3& cameraPosition = CAMERA_POSITION, const nw::math::VEC3& targetPosition = TARGET_POSITION, f32 nearClip = NEAR_CLIP, f32 farClip = FAR_CLIP, const nw::math::VEC2& projectionCenter = PROJECTION_CENTER, f32 projectionHeight = PROJECTION_HEIGHT, nw::math::PivotDirection pivotDirection = nw::math::PIVOT_UPSIDE_TO_TOP, f32 wScale = 0.0f ); //--------------------------------------------------------------------------- //! @brief カメラを生成します。 //! //! @param[in] allocator 生成に使用するアロケーターです。 //! @param[in] cameraPosition カメラの位置座標です。 //! @param[in] targetPosition カメラターゲットの座標です。 //! @param[in] nearClip ニアクリップの値です。 //! @param[in] farClip ファークリップの値です。 //! @param[in] projectionCenter 投影面の中心位置です。 //! @param[in] projectionHeight 投影面の高さです。 //! @param[in] pivotDirection 画面の上方向です。 //! @param[in] wScale wScale の値です。 //! //! @return 生成したカメラを返します。 //--------------------------------------------------------------------------- static nw::gfx::Camera* CreateOrthoCamera( os::IAllocator* allocator, const nw::math::VEC3& cameraPosition = CAMERA_POSITION, const nw::math::VEC3& targetPosition = TARGET_POSITION, f32 nearClip = NEAR_CLIP, f32 farClip = FAR_CLIP, const nw::math::VEC2& projectionCenter = PROJECTION_CENTER, f32 projectionHeight = PROJECTION_HEIGHT, nw::math::PivotDirection pivotDirection = nw::math::PIVOT_UPSIDE_TO_TOP, f32 wScale = 0.0f ); // TODO: 「ベースカメラ」という表現が適切かどうかを確認する。 //--------------------------------------------------------------------------- //! @brief 立体視に使用するベースカメラと左右カメラを生成します。 //! //! 実際は右目用カメラと左目用カメラの区別はありません。 //! //! @param[out] ppBaseCamera 生成したベースカメラを返すためのポインタです。 //! @param[out] ppLeftCamera 生成した右目用カメラを返すためのポインタです。 //! @param[out] ppRightCamera 生成した左目用カメラを返すためのポインタです。 //! @param[in] allocator 生成に使用するアロケーターです。 //! @param[in] cameraPosition カメラの位置座標です。 //! @param[in] targetPosition カメラターゲットの座標です。 //! @param[in] nearClip ニアクリップの値です。 //! @param[in] farClip ファークリップの値です。 //! @param[in] fovyRadian FOVのY方向の値です。 //! @param[in] wScale wScale の値です。 //--------------------------------------------------------------------------- static void CreateStereoCameras( nw::gfx::Camera** ppBaseCamera, nw::gfx::Camera** ppLeftCamera, nw::gfx::Camera** ppRightCamera, os::IAllocator* allocator, const nw::math::VEC3& cameraPosition = CAMERA_POSITION, const nw::math::VEC3& targetPosition = TARGET_POSITION, f32 nearClip = NEAR_CLIP, f32 farClip = FAR_CLIP, f32 fovyRadian = FOVY_RADIAN, f32 wScale = 0.0f ); //--------------------------------------------------------------------------- //! @brief カメラのアスペクト比を設定します。 //! //! 指定したレンダーターゲットに合うように設定されます。 //! カメラがアタッチされているシーンを更新してから実行する必要があります。 //! //! @param[in] camera 設定するカメラです。 //! @param[in] renderTarget アスペクト比を合わせるレンダーターゲットです。 //--------------------------------------------------------------------------- static void SetCameraAspectRatio( nw::gfx::Camera* camera, const nw::gfx::IRenderTarget* renderTarget ) { NW_POINTER_ASSERT(renderTarget); // オンスクリーンバッファは縦と横が逆になっているため、 // 幅と高さを逆にしてアスペクト比を求めています。 SetCameraAspectRatio( camera, static_cast(renderTarget->GetDescription().height) / static_cast(renderTarget->GetDescription().width) ); } //--------------------------------------------------------------------------- //! @brief カメラのアスペクト比を設定します。 //! //! カメラがアタッチされているシーンを更新してから実行する必要があります。 //! //! @param[in] camera 設定するカメラです。 //! @param[in] aspectRatio アスペクト比です。 //--------------------------------------------------------------------------- static void SetCameraAspectRatio( nw::gfx::Camera* camera, f32 aspectRatio ); //@} //===================== //! @name スクリーンバッファの生成 //@{ //--------------------------------------------------------------------------- //! @brief 上画面用のスクリーンバッファを生成します。 //! //! レンダーシステムの設定をもとにバッファサイズなどが決定されます。 //! //! @param[in] allocator 生成に使用するアロケーターです。 //! @param[in] renderDescription レンダーシステムの設定です。 //! //! @return 生成したスクリーンバッファを返します。 //--------------------------------------------------------------------------- static nw::gfx::IRenderTarget* CreateUpperScreenBuffer( os::IAllocator* allocator, nw::demo::RenderSystem::Description& renderDescription ); //--------------------------------------------------------------------------- //! @brief 下画面用のスクリーンバッファを生成します。 //! //! レンダーシステムの設定をもとにバッファサイズなどが決定されます。 //! //! @param[in] allocator 生成に使用するアロケーターです。 //! @param[in] renderDescription レンダーシステムの設定です。 //! //! @return 生成したスクリーンバッファを返します。 //--------------------------------------------------------------------------- static nw::gfx::IRenderTarget* CreateLowerScreenBuffer( os::IAllocator* allocator, nw::demo::RenderSystem::Description& renderDescription ); //@} //===================== //! @name シーンノード関連 //@{ //--------------------------------------------------------------------------- //! @brief シーンオブジェクトのリソースからシーンノードのインスタンスを生成します。 //! //! @param[in] deviceAllocator 生成に使用するデバイスメモリのアロケーターです。 //! @param[in] resource シーンオブジェクトのリソースです。 //! @param[in] isAnimationEnabled アニメーションが有効かどうかを指定します。 //! @param[in] bufferOption バッファの種類です。 //! @param[in] maxAnimObjects AnimBindingが持てるAnimGroupごとのAnimObjectの最大数です。 //! //! @return 生成したインスタンスを返します。 //--------------------------------------------------------------------------- static nw::gfx::SceneNode* CreateSceneNode( os::IAllocator* deviceAllocator, nw::gfx::ResSceneObject resource, bool isAnimationEnabled = true, nw::gfx::Model::BufferOption bufferOption = nw::gfx::Model::FLAG_BUFFER_NOT_USE, s32 maxAnimObjects = 1 ); //--------------------------------------------------------------------------- //! @brief 指定した名前のシーンオブジェクトを検索します。 //! //! コレクションから指定した名前のシーンオブジェクトを探します。 //! 線形探索を行っていますので、要素数の大きなコレクションを対象にする場合は注意が必要です。 //! //! 見つからなければ NULL を返します。 //! また、同じ名前のオブジェクトが複数存在する場合、最初に見つかったオブジェクトを返します。 //! //! @param[in] objects シーンオブジェクトのコレクションです。 //! @param[in] objectName シーンオブジェクトの名前です。 //! //! @return 見つかったシーンオブジェクトを返します。 //--------------------------------------------------------------------------- template static nw::gfx::SceneObject* FindObjectByName( TObjectArray& objects, const char* objectName ) { // 指定した名前を持つシーンオブジェクトを探します。 nw::gfx::SceneObject* targetObject = NULL; typename TObjectArray::iterator objEnd = objects.end(); for (typename TObjectArray::iterator obj = objects.begin(); obj != objEnd; ++obj) { if (std::strcmp(objectName, (*obj)->GetName()) == 0) { targetObject = *obj; break; } } return targetObject; } //@} //===================== //! @name アニメーション //@{ //--------------------------------------------------------------------------- //! @brief 指定した名前のアニメーションリソースを検索します。 //! //! コレクションから指定した名前と種類のアニメーションリソースを探します。 //! コレクションの線形探索を行っていますので、要素数の大きなコレクションを対象にする場合は注意が必要です。 //! //! 見つからなければ無効なリソースを返しますので、IsValid() 関数で戻り値をチェックしてください。 //! また、同じ名前のリソースが複数存在する場合、最初に見つかったリソースを返します。 //! //! @param[in] resources アニメーションリソースのコレクションです。 //! @param[in] animationName アニメーションリソースの名前です。 //! @param[in] animationType アニメーションの種類です。 //! //! @return 見つかったアニメーションリソースを返します。 //--------------------------------------------------------------------------- template static nw::anim::ResAnim FindResAnimByName( TResArray& resources, const char* animationName, AnimationType animationType ) { nw::anim::ResAnim resAnim; typename TResArray::iterator resEnd = resources.end(); for (typename TResArray::iterator res = resources.begin(); res != resEnd; ++res) { switch (animationType) { case SKELETAL_ANIMATION: resAnim = res->GetSkeletalAnims(animationName); break; case MATERIAL_ANIMATION: resAnim = res->GetMaterialAnims(animationName); break; case VISIBILITY_ANIMATION: resAnim = res->GetVisibilityAnims(animationName); break; case CAMERA_ANIMATION: resAnim = res->GetCameraAnims(animationName); break; case LIGHT_ANIMATION: resAnim = res->GetLightAnims(animationName); break; default: NW_FATAL_ERROR("Invalid animation type"); } if (resAnim.IsValid()) { break; } } return resAnim; } //--------------------------------------------------------------------------- //! @brief アニメーションをバインドします。 //! //! アニメーションオブジェクトを生成し、指定したシーンオブジェクトとバインドします。 //! //! シーンオブジェクトに指定した種類のアニメーショングループが存在しない場合や、 //! バインドに失敗した場合にこの関数は失敗し、NULL を返します。 //! //! 生成されるアニメーションオブジェクトは、 //! スケルタルアニメーションの場合は nw::gfx::TransformAnimEvaluator 、 //! その他の場合は nw::gfx::AnimEvaluator です。 //! //! @param[in] allocator アニメーションオブジェクトの生成に使用するアロケータです。 //! @param[in] object シーンオブジェクトです。 //! @param[in] resAnim アニメーションデータを持つアニメーションリソースです。 //! @param[in] animationType アニメーションの種類です。 //! @param[in] allocCache キャッシュバッファを確保してキャッシュを有効にするかどうかを設定します。 //! //! @return 生成したアニメーションオブジェクトを返します。 //! //! @sa BindAnimationByName //! @sa nw::gfx::AnimObject::Bind //! @sa nw::gfx::SkeletalModel::SetSkeletalAnimObject //! @sa nw::gfx::Model::SetMaterialAnimObject //! @sa nw::gfx::Model::SetVisibilityAnimObject //! @sa nw::gfx::Camera::SetAnimObject //! @sa nw::gfx::Light::SetAnimObject //--------------------------------------------------------------------------- static nw::gfx::BaseAnimEvaluator* BindAnimation( os::IAllocator* allocator, nw::gfx::SceneObject* object, nw::anim::ResAnim resAnim, AnimationType animationType, bool allocCache ) { // アニメーショングループを取得します。 nw::gfx::AnimGroup* animGroup = GetAnimGroup(object, animationType); if (!animGroup) { NW_LOG("BindAnimation() : Specified type animation group not found\n"); return NULL; } // アニメーションオブジェクトを生成します。 nw::gfx::BaseAnimEvaluator* animObject; if (animationType == SKELETAL_ANIMATION) { animObject = nw::gfx::TransformAnimEvaluator::Builder() .AnimData(resAnim) .MaxMembers(animGroup->GetMemberCount()) .MaxAnimMembers(resAnim.GetMemberAnimSetCount()) .AllocCache(allocCache) .Create(allocator); } else { animObject = nw::gfx::AnimEvaluator::Builder() .AnimData(resAnim) .MaxMembers(animGroup->GetMemberCount()) .MaxAnimMembers(resAnim.GetMemberAnimSetCount()) .AllocCache(allocCache) .Create(allocator); } NW_NULL_ASSERT(animObject); // スケルタルアニメーションであればであれば // 移動アニメーションの無効化フラグを設定します。 if (animationType == SKELETAL_ANIMATION) { nw::gfx::SkeletalModel* skeletalModel = nw::ut::DynamicCast(object); nw::gfx::ResSkeleton resSkeleton = skeletalModel->GetSkeleton()->GetResSkeleton(); const bool translateAnimEnabled = nw::ut::CheckFlag( resSkeleton.GetFlags(), nw::gfx::ResSkeletonData::FLAG_TRANSLATE_ANIMATION_ENABLED ); reinterpret_cast(animObject) ->SetIsTranslateDisabled(!translateAnimEnabled); } // アニメーションオブジェクトとシーンオブジェクトをバインドします。 if (!BindAnimationObject(object, animObject, animationType)) { NW_LOG("BindAnimation() : Failed to bind animation object\n"); nw::ut::SafeDestroy(animObject); return NULL; } return animObject; } //--------------------------------------------------------------------------- //! @brief アニメーションブレンダーをバインドします。 //! //! アニメーションブレンダーオブジェクトを生成し、指定したシーンオブジェクトとバインドします。 //! //! シーンオブジェクトに指定した種類のアニメーショングループが存在しない場合や、 //! バインドに失敗した場合にこの関数は失敗し、NULL を返します。 //! //! @tparam TAnimObject 生成するアニメーションオブジェクトクラスです。 //! @param[in] allocator アニメーションオブジェクトの生成に使用するアロケータです。 //! @param[in] object シーンオブジェクトです。 //! @param[in] maxAnimObjects 生成するブレンダーの最大アニメーションオブジェクト数です。 //! @param[in] animationType アニメーションの種類です。 //! //! @return 生成したアニメーションブレンダーオブジェクトを返します。 //! //! @sa BindAnimation //! @sa BindAnimationByName //--------------------------------------------------------------------------- template static TAnimObject* BindAnimationBlender( os::IAllocator* allocator, nw::gfx::SceneObject* object, int maxAnimObjects, AnimationType animationType ) { // アニメーショングループを取得します。 nw::gfx::AnimGroup* animGroup = GetAnimGroup(object, animationType); if (!animGroup) { NW_LOG("BindAnimationBlender() : Specified type animation group not found\n"); return NULL; } // アニメーションオブジェクトを生成します。 TAnimObject* animObject = TAnimObject::Builder() .MaxAnimObjects(maxAnimObjects) .Create(allocator); NW_NULL_ASSERT(animObject); // アニメーションオブジェクトとシーンオブジェクトをバインドします。 if (!BindAnimationObject(object, animObject, animationType)) { NW_LOG("BindAnimationBlender() : Failed to bind animation object\n"); nw::ut::SafeDestroy(animObject); return NULL; } return animObject; } //--------------------------------------------------------------------------- //! @brief 名前を指定してアニメーションをバインドします。 //! //! 指定した名前のオブジェクトとアニメーションデータを探してバインドします。 //! 指定した名前のオブジェクトやアニメーションデータが見つからない場合や、 //! オブジェクトに指定した種類のアニメーショングループが存在しない場合、 //! バインドに失敗した場合にこの関数は失敗し、 NULL を返します。 //! //! 同じ名前のオブジェクトやアニメーションデータが存在する場合、 //! 一番最初に見つかったものが使用されます。 //! //! 生成されるアニメーションオブジェクトは、 //! スケルタルアニメーションの場合は nw::gfx::TransformAnimEvaluator 、 //! その他の場合は nw::gfx::AnimEvaluator です。 //! //! @tparam TObjectArray シーンオブジェクトのコレクション型です。 //! @tparam TResArray リソースのコレクション型です。 //! @param[in] allocator アニメーションオブジェクトの生成に使用するアロケータです。 //! @param[in] objects シーンオブジェクトのコレクションです。 //! @param[in] resources リソースのコレクションです。 //! @param[in] objectName オブジェクトの名前です。 //! @param[in] animationName アニメーションデータの名前です。 //! @param[in] animationType アニメーションの種類です。 //! @param[in] allocCache キャッシュバッファを確保してキャッシュを有効にするかどうかを設定します。 //! //! @return 生成したアニメーションオブジェクトを返します。 //! //! @sa BindAnimation //! @sa FindObjectByName //! @sa FindResAnimByName //--------------------------------------------------------------------------- template static nw::gfx::BaseAnimEvaluator* BindAnimationByName( os::IAllocator* allocator, TObjectArray& objects, TResArray& resources, const char* objectName, const char* animationName, AnimationType animationType, bool allocCache ) { nw::gfx::SceneObject* targetObject = FindObjectByName(objects, objectName); if (!targetObject) { // 指定した名前のオブジェクトが見つからなかった場合 NULL を返します。 NW_LOG("BindAnimationByName() : Specified object not found [%s]\n", objectName); return NULL; } // 指定した名前を持つアニメーションデータを探します。 nw::anim::ResAnim resAnim = FindResAnimByName(resources, animationName, animationType); if (!resAnim.IsValid()) { // 指定した種類と名前のアニメーションデータが見つからなかった場合 NULL を返します。 NW_LOG("BindAnimationByName() : Specified animation resource not found [%s]\n", animationName); return NULL; } // アニメーションをバインドします。 nw::gfx::BaseAnimEvaluator* animObject = BindAnimation( allocator, targetObject, resAnim, animationType, allocCache); return animObject; } //--------------------------------------------------------------------------- //! @brief アニメーショングループを取得します。 //! //! シーンオブジェクトから指定した種類のアニメーショングループを取得します。 //! 取得できない場合は NULL を返します。 //! //! @param[in] object シーンオブジェクトです。 //! @param[in] animationType アニメーションの種類です。 //! //! @return 取得したアニメーショングループを返します。 //--------------------------------------------------------------------------- static nw::gfx::AnimGroup* GetAnimGroup( nw::gfx::SceneObject* object, AnimationType animationType ); //@} //===================== //! @name フォント //@{ //--------------------------------------------------------------------------- //! @brief 共有フォントを初期化します。 //! //! 共有フォントを用いてフォントの初期化を行います。 //! //! @param[in] allocator アロケータです。 //! @param[in] graphicsDrawing 初期化を行う GraphicsDrawing です。 //--------------------------------------------------------------------------- static bool InitializeSharedFont( os::IAllocator* allocator, nw::demo::GraphicsDrawing& graphicsDrawing ); //@} //===================== //! @name 状態の取得 //@{ //--------------------------------------------------------------------------- //! @brief デモが終了状態かどうかを取得します。 //! //! NW_DEBUG_CHECK_MEMORY_LEAK マクロが有効な場合は、 //! パッドのスタートボタンでも終了処理をおこなう為に true を返します。 //! この関数はパッドの更新などを行わないので、あらかじめ PadFactory を初期化し、 //! Pad::Update() 関数でパッドの状態を更新しておく必要があります。 //! //! @return 終了状態の場合は true、そうでない場合は false を返します。 //--------------------------------------------------------------------------- static bool IsTerminating() { #if defined(NW_DEBUG_CHECK_MEMORY_LEAK) nw::demo::Pad* pad = nw::demo::PadFactory::GetPad(); if (pad->IsButtonDown(nw::demo::Pad::BUTTON_START)) { return true; } #endif //defined(NW_DEBUG_CHECK_MEMORY_LEAK) return internal::IsTerminatingImpl(); } //@} private: //--------------------------------------------------------------------------- //! @brief アニメーションオブジェクトとシーンオブジェクトをバインドします。 //! //! アニメーションオブジェクトにシーンオブジェクトのアニメーショングループをバインドし、 //! シーンオブジェクトにアニメーションオブジェクトを設定します。 //! //! @param[in] object シーンオブジェクトです。 //! @param[in] animObject アニメーションオブジェクトです。 //! @param[in] animationType アニメーションの種類です。 //! //! @return 成功したら trueを返します。 //--------------------------------------------------------------------------- static bool BindAnimationObject( nw::gfx::SceneObject* object, nw::gfx::AnimObject* animObject, AnimationType animationType ); private: static const wchar_t* FONT_SHADER_FILE_NAME; static const wchar_t* SHAPE_2D_SHADER_FILE_NAME; static bool s_SharedFontAlreadyInitialized; }; //@} //============================================================================ //! @name パーティクルユーティリティ //@{ /*!--------------------------------------------------------------------------* @brief キャッシュをフラッシュするテストコードです。 *---------------------------------------------------------------------------*/ class FlushCache { public: //! @brief FulshCache クラスのインスタンスを生成します。 //! //! @param[in] allocator 生成に使用するアロケーターです。 static FlushCache* Create(nw::demo::DemoAllocator* allocator) { void* memory = allocator->Alloc(sizeof(FlushCache)); NW_NULL_ASSERT(memory); return new (memory) FlushCache(allocator); } //! @brief インスタンスを破棄します。 void Destroy() { nw::os::IAllocator* allocator = m_Allocator; this->~FlushCache(); allocator->Free(this); } //! @brief キャッシュをフラッシュします。 void Execute() { if (m_Buffer != NULL) { ::std::memcpy(m_Buffer + BufferSize / 2, m_Buffer, BufferSize / 2); } } private: //! @brief コンストラクタです。 FlushCache(nw::demo::DemoAllocator* allocator) { m_Allocator = allocator; m_Buffer = NULL; if (m_Allocator != NULL) { m_Buffer = (u8*)m_Allocator->Alloc(BufferSize); NW_ASSERT(nw::os::IsDeviceMemory(m_Buffer)); } } //! @brief デストラクタです。 ~FlushCache() { if (m_Buffer != NULL) { m_Allocator->Free(m_Buffer); } } static const int BufferSize = 16 * 1024 * 2; u8* m_Buffer; nw::demo::DemoAllocator* m_Allocator; }; //@} } // namespace demo } // namespace nw #endif // NW_DEMO_UTILITY_H_