1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: snd_PlayerHeap.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/snd/snd_PlayerHeap.h>
21 #include <nw/snd/snd_SoundThread.h>
22 #include <nw/snd/snd_DisposeCallbackManager.h>
23
24 namespace nw {
25 namespace snd {
26 namespace internal {
27
28 /*---------------------------------------------------------------------------*
29 Name: SoundHeap
30
31 Description: コンストラクタ
32
33 Arguments: 無し
34
35 Returns: 無し
36 *---------------------------------------------------------------------------*/
PlayerHeap()37 PlayerHeap::PlayerHeap()
38 : m_pSound( NULL ),
39 m_pPlayer( NULL ),
40 m_pStartAddress( NULL ),
41 m_pEndAddress( NULL ),
42 m_pAllocAddress( NULL )
43 {
44 }
45
46 /*---------------------------------------------------------------------------*
47 Name: ~PlayerHeap
48
49 Description: デストラクタ
50
51 Arguments: 無し
52
53 Returns: 無し
54 *---------------------------------------------------------------------------*/
~PlayerHeap()55 PlayerHeap::~PlayerHeap()
56 {
57 Destroy();
58 }
59
60 /*---------------------------------------------------------------------------*
61 Name: Create
62
63 Description:
64
65 Arguments: startAddress -
66 size -
67
68 Returns:
69 *---------------------------------------------------------------------------*/
Create(void * startAddress,size_t size)70 bool PlayerHeap::Create( void* startAddress, size_t size )
71 {
72 void* endAddress = ut::AddOffsetToPtr( startAddress, size );
73 startAddress = ut::RoundUp( startAddress, 32 );
74 if ( startAddress > endAddress )
75 {
76 return false;
77 }
78
79 m_pStartAddress = startAddress;
80 m_pEndAddress = endAddress;
81 m_pAllocAddress = m_pStartAddress;
82
83 return true;
84 }
85
86 /*---------------------------------------------------------------------------*
87 Name: Destroy
88
89 Description:
90
91 Arguments: なし
92
93 Returns: なし
94 *---------------------------------------------------------------------------*/
Destroy()95 void PlayerHeap::Destroy()
96 {
97 Clear();
98 m_pAllocAddress = NULL;
99 }
100
101 /*---------------------------------------------------------------------------*
102 Name: Alloc
103
104 Description:
105
106 Arguments: size -
107
108 Returns:
109 *---------------------------------------------------------------------------*/
Alloc(size_t size)110 void* PlayerHeap::Alloc( size_t size )
111 {
112 NW_ALIGN32_ASSERT( m_pAllocAddress );
113
114 void* endp = ut::AddOffsetToPtr( m_pAllocAddress, size );
115 if ( endp > m_pEndAddress )
116 {
117 return NULL;
118 }
119
120 void* allocAddress = m_pAllocAddress;
121 m_pAllocAddress = ut::RoundUp( endp, 32 );
122 return allocAddress;
123 }
124
125 /*---------------------------------------------------------------------------*
126 Name: Clear
127
128 Description:
129
130 Arguments: なし
131
132 Returns: なし
133 *---------------------------------------------------------------------------*/
Clear()134 void PlayerHeap::Clear()
135 {
136 internal::DriverCommandManager& cmdmgr = internal::DriverCommandManager::GetInstance();
137
138 internal::DriverCommandInvalidateData* command =
139 cmdmgr.AllocCommand<internal::DriverCommandInvalidateData>();
140 command->id = internal::DRIVER_COMMAND_INVALIDATE_DATA;
141 command->mem = m_pStartAddress;
142 command->size = static_cast<unsigned long>( ut::GetOffsetFromPtr( m_pStartAddress, m_pAllocAddress ) );
143 cmdmgr.PushCommand(command);
144
145 m_pAllocAddress = m_pStartAddress;
146 }
147
148 /*---------------------------------------------------------------------------*
149 Name: GetFreeSize
150
151 Description:
152
153 Arguments: なし
154
155 Returns:
156 *---------------------------------------------------------------------------*/
GetFreeSize() const157 size_t PlayerHeap::GetFreeSize() const
158 {
159 size_t offset = ut::GetOffsetFromPtr( m_pAllocAddress, m_pEndAddress );
160 NW_ASSERT( offset >= 0 );
161 // return static_cast<size_t>( offset );
162 return offset;
163 }
164
165 /*---------------------------------------------------------------------------*
166 Name: AttachSound
167
168 Description: サウンドと結びつける
169
170 Arguments: sound - 結びつけるサウンド
171
172 Returns: None.
173 *---------------------------------------------------------------------------*/
AttachSound(BasicSound * sound)174 void PlayerHeap::AttachSound( BasicSound* sound )
175 {
176 NW_NULL_ASSERT( sound );
177 NW_ASSERT( m_pSound == NULL );
178
179 m_pSound = sound;
180 }
181
182 /*---------------------------------------------------------------------------*
183 Name: DetachSound
184
185 Description: サウンドと切り離す
186
187 Arguments: sound - 切り離すサウンド
188
189 Returns: None.
190 *---------------------------------------------------------------------------*/
DetachSound(BasicSound * sound)191 void PlayerHeap::DetachSound( BasicSound* sound )
192 {
193 NW_NULL_ASSERT( sound );
194 NW_ASSERT( sound == m_pSound );
195 (void)sound;
196
197 m_pSound = NULL;
198 }
199
200
201 } // namespace nw::snd::internal
202 } // namespace nw::snd
203 } // namespace nw
204
205