1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: demo_Pad.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: $ 16 *---------------------------------------------------------------------------*/ 17 18 #include <nw/demo/demo_Pad.h> 19 20 namespace nw { 21 namespace demo { 22 23 Pad* PadFactory::s_pPad = NULL; 24 25 //-------------------------------------------------------------------------- 26 Pad* Create(os::IAllocator * allocator)27Pad::Create(os::IAllocator* allocator) 28 { 29 NW_NULL_ASSERT( allocator ); 30 31 void* memory = allocator->Alloc( sizeof(Pad) ); 32 NW_ASSERT( memory != NULL ); 33 Pad* pad = new(memory) Pad(); 34 35 pad->m_Allocator = allocator; 36 37 return pad; 38 } 39 40 //-------------------------------------------------------------------------- 41 void Destroy()42Pad::Destroy() 43 { 44 os::IAllocator* allocator = this->m_Allocator; 45 46 NW_ASSERT( allocator != NULL ); 47 48 this->~Pad(); 49 allocator->Free(this); 50 } 51 52 //-------------------------------------------------------------------------- 53 void Initialize()54Pad::Initialize() 55 { 56 57 nn::Result result = nn::hid::CTR::Initialize(); 58 // 下記マクロを使用すると、他所でnn::hid::CTR::Initialize()が呼ばれると 59 // エラーを出すため、コメントアウトしています。 60 //NN_UTIL_PANIC_IF_FAILED( result ); 61 62 Reset(); 63 } 64 65 //-------------------------------------------------------------------------- 66 void Finalize()67Pad::Finalize() 68 { 69 // 注意:PadをFinalizeすると、hidのFinalize()を行うため、 70 // これ以降でhidを使用できなくなります。 71 nn::hid::CTR::Finalize(); 72 } 73 74 //-------------------------------------------------------------------------- 75 void Update()76Pad::Update() 77 { 78 if (m_IsTestMode) 79 { 80 m_PadButton.Update( m_TestPadStatus ); 81 82 m_AnalogStickX = 0; 83 m_AnalogStickY = 0; 84 m_AnalogStick.x = 0; 85 m_AnalogStick.y = 0; 86 } 87 else 88 { 89 nn::hid::PadReader padReader; 90 padReader.ReadLatest( &m_PadStatus ); 91 m_PadButton.Update( static_cast<u32>( m_PadStatus.hold ) ); 92 93 m_AnalogStickX = m_PadStatus.stick.x; 94 m_AnalogStickY = m_PadStatus.stick.y; 95 m_AnalogStick.x = static_cast<f32>( m_PadStatus.stick.x ) / nn::hid::CTR::LIMIT_OF_STICK_CLAMP_MAX; 96 m_AnalogStick.y = static_cast<f32>( m_PadStatus.stick.y ) / nn::hid::CTR::LIMIT_OF_STICK_CLAMP_MAX; 97 } 98 } 99 100 //-------------------------------------------------------------------------- 101 void Reset()102Pad::Reset() 103 { 104 m_PadButton.Reset(); 105 } 106 107 //-------------------------------------------------------------------------- 108 bool IsButtonPress(Button button) const109Pad::IsButtonPress( Button button ) const 110 { 111 return m_PadButton.IsButtonPress( button ); 112 } 113 114 //-------------------------------------------------------------------------- 115 bool IsButtonDown(Button button) const116Pad::IsButtonDown( Button button ) const 117 { 118 return m_PadButton.IsButtonDown( button ); 119 } 120 121 //-------------------------------------------------------------------------- 122 bool IsButtonUp(Button button) const123Pad::IsButtonUp( Button button ) const 124 { 125 return m_PadButton.IsButtonUp( button ); 126 } 127 128 //-------------------------------------------------------------------------- 129 bool IsButtonRepeat(Button button) const130Pad::IsButtonRepeat( Button button ) const 131 { 132 return m_PadButton.IsButtonRepeat( button ); 133 } 134 135 //-------------------------------------------------------------------------- 136 bool IsButtonRepeatFast(Button button) const137Pad::IsButtonRepeatFast( Button button ) const 138 { 139 return m_PadButton.IsButtonRepeatFast( button ); 140 } 141 142 143 //-------------------------------------------------------------------------- 144 void Initialize(os::IAllocator * allocator)145PadFactory::Initialize(os::IAllocator* allocator) 146 { 147 NW_ASSERT( s_pPad == NULL ); 148 149 s_pPad = Pad::Create( allocator ); 150 s_pPad->Initialize(); 151 } 152 153 //-------------------------------------------------------------------------- 154 void Finalize()155PadFactory::Finalize() 156 { 157 NW_NULL_ASSERT( s_pPad ); 158 159 s_pPad->Finalize(); 160 161 s_pPad->Destroy(); 162 s_pPad = NULL; 163 } 164 165 //-------------------------------------------------------------------------- 166 Pad* GetPad()167PadFactory::GetPad() 168 { 169 NW_NULL_ASSERT( s_pPad ); 170 171 return s_pPad; 172 } 173 174 } // namespace nw::demo 175 } // namespace nw 176