1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: snd_PlayerHeapDataManager.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 "precompiled.h"
19
20 #include <nw/snd/snd_PlayerHeapDataManager.h>
21
22 namespace nw {
23 namespace snd {
24 namespace internal {
25
PlayerHeapDataManager()26 PlayerHeapDataManager::PlayerHeapDataManager()
27 : m_IsInitialized( false ),
28 m_IsFinalized ( true )
29 {
30 }
31
~PlayerHeapDataManager()32 PlayerHeapDataManager::~PlayerHeapDataManager()
33 {
34 Finalize();
35 }
36
Initialize(const SoundArchive * arc)37 void PlayerHeapDataManager::Initialize( const SoundArchive* arc )
38 {
39 if ( m_IsInitialized )
40 {
41 return;
42 }
43 m_IsInitialized = true;
44 m_IsFinalized = false;
45
46 for ( int i = 0; i < FILE_ADDRESS_COUNT; i++ )
47 {
48 m_FileAddress[i].fileId = SoundArchive::INVALID_ID;
49 m_FileAddress[i].address = NULL;
50 }
51 SetSoundArchive( arc );
52 }
53
Finalize()54 void PlayerHeapDataManager::Finalize()
55 {
56 if ( m_IsFinalized )
57 {
58 return;
59 }
60 m_IsInitialized = false;
61 m_IsFinalized = true;
62 SetSoundArchive( NULL );
63 }
64
SetFileAddress(SoundArchive::FileId fileId,const void * address)65 const void* PlayerHeapDataManager::SetFileAddress(
66 SoundArchive::FileId fileId, const void* address )
67 {
68 return SetFileAddressToTable( fileId, address );
69 }
GetFileAddress(SoundArchive::FileId fileId) const70 const void* PlayerHeapDataManager::GetFileAddress( SoundArchive::FileId fileId ) const
71 {
72 // ファイルの検索順は、SoundDataManager → PlayerHeapDataManager。
73 // サウンドアーカイブ内からの検索は、SoundDataManager で行っているので、
74 // ここでは、PlayerHeapDataManager 内の検索だけでよい。
75 return GetFileAddressFromTable( fileId );
76 }
77
InvalidateData(const void *,const void *)78 void PlayerHeapDataManager::InvalidateData( const void* /*start*/, const void* /*end*/ )
79 {
80 // ファイルアドレステーブルから破棄
81 for ( int i = 0; i < FILE_ADDRESS_COUNT; i++ )
82 {
83 m_FileAddress[i].fileId = SoundArchive::INVALID_ID;
84 m_FileAddress[i].address = NULL;
85 }
86 }
87
SetFileAddressToTable(SoundArchive::FileId fileId,const void * address)88 const void* PlayerHeapDataManager::SetFileAddressToTable(
89 SoundArchive::FileId fileId, const void* address )
90 {
91 // 同じ fileId がある場合
92 for ( int i = 0; i< FILE_ADDRESS_COUNT; i++ )
93 {
94 if ( m_FileAddress[i].fileId == fileId )
95 {
96 const void* prev = m_FileAddress[i].address;
97 m_FileAddress[i].address = address;
98 return prev;
99 }
100 }
101
102 // ない場合
103 for ( int i = 0; i< FILE_ADDRESS_COUNT; i++ )
104 {
105 if ( m_FileAddress[i].fileId == SoundArchive::INVALID_ID )
106 {
107 m_FileAddress[i].fileId = fileId;
108 m_FileAddress[i].address = address;
109 return NULL;
110 }
111 }
112
113 // ここにくることは無いはず
114 NW_ASSERTMSG( false, "invalid PlayerHeap" );
115 return NULL;
116 }
117
GetFileAddressFromTable(SoundArchive::FileId fileId) const118 const void* PlayerHeapDataManager::GetFileAddressFromTable( SoundArchive::FileId fileId ) const
119 {
120 for ( int i = 0; i< FILE_ADDRESS_COUNT; i++ )
121 {
122 if ( m_FileAddress[i].fileId == fileId )
123 {
124 return m_FileAddress[i].address;
125 }
126 }
127 return NULL;
128 }
129
GetFileAddressImpl(SoundArchive::FileId fileId) const130 const void* PlayerHeapDataManager::GetFileAddressImpl( SoundArchive::FileId fileId ) const
131 {
132 return GetFileAddressFromTable( fileId );
133 }
134
135
136 } // namespace nw::snd::internal
137 } // namespace nw::snd
138 } // namespace nw
139
140