1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: snd_FrameHeap.h 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 #ifndef NW_SND_FRAME_HEAP_H_ 19 #define NW_SND_FRAME_HEAP_H_ 20 21 #include <nw/ut/ut_LinkList.h> 22 #include <nw/ut/ut_FrameHeap.h> 23 #include <nw/snd/snd_SoundDataManager.h> 24 25 namespace nw { 26 namespace snd { 27 namespace internal { 28 29 /* ======================================================================== 30 class definition 31 ======================================================================== */ 32 33 class FrameHeap 34 { 35 /* ------------------------------------------------------------------------ 36 type definition 37 ------------------------------------------------------------------------ */ 38 public: 39 typedef void (*DisposeCallback)( void* mem, unsigned long size, void* userArg ); 40 41 struct Block 42 { 43 public: BlockBlock44 Block( void* buffer, u32 size, DisposeCallback callback, void* callbackArg ) 45 : m_pBuffer( buffer ), m_Size( size ), m_Callback( callback ), m_pCallbackArg( callbackArg ) {} ~BlockBlock46 ~Block() { if ( m_Callback != NULL ) m_Callback( m_pBuffer, m_Size, m_pCallbackArg ); } 47 GetBufferAddrBlock48 void* GetBufferAddr(){ return m_pBuffer; } GetBufferAddrBlock49 const void* GetBufferAddr() const { return m_pBuffer; } GetBufferSizeBlock50 u32 GetBufferSize() const { return m_Size; } GetDisposeCallbackBlock51 DisposeCallback GetDisposeCallback() const { return m_Callback; } 52 /* const DisposeCallback を返そうとすると、RVCT で、 53 "type qualifier on return type is meaningless" の警告 */ GetDisposeCallbackArgBlock54 const void* GetDisposeCallbackArg() const { return m_pCallbackArg; } 55 56 public: 57 ut::LinkListNode m_Link; 58 private: 59 void* m_pBuffer; 60 u32 m_Size; 61 DisposeCallback m_Callback; 62 void* m_pCallbackArg; 63 }; 64 65 typedef ut::LinkList< Block, offsetof(Block,m_Link)> BlockList; 66 67 class Section 68 { 69 public: 70 ~Section(); AppendBlock(Block * block)71 void AppendBlock( Block* block ) { m_BlockList.PushBack( block ); } GetBlockList()72 const BlockList& GetBlockList() const { return m_BlockList; } 73 74 void Dump( nw::snd::SoundDataManager& mgr, nw::snd::SoundArchive& arc ); 75 76 public: 77 ut::LinkListNode m_Link; 78 private: 79 BlockList m_BlockList; 80 }; 81 82 typedef ut::LinkList< Section, offsetof(Section,m_Link)> SectionList; 83 84 /* ------------------------------------------------------------------------ 85 constant declaration 86 ------------------------------------------------------------------------ */ 87 private: 88 static const int HEAP_ALIGN = 32; 89 90 /* ------------------------------------------------------------------------ 91 static member 92 ------------------------------------------------------------------------ */ 93 private: 94 static void InitHeapSection( FrameHeap::Section* section ); 95 96 /* ------------------------------------------------------------------------ 97 class member 98 ------------------------------------------------------------------------ */ 99 public: 100 FrameHeap(); 101 ~FrameHeap(); 102 bool Create( void* startAddress, u32 size ); 103 void Destroy(); 104 105 void* Alloc( 106 u32 size, 107 FrameHeap::DisposeCallback callback, 108 void* callbackArg 109 ); 110 void Clear(); 111 112 int SaveState(); 113 void LoadState( int level ); 114 int GetCurrentLevel() const; 115 116 u32 GetSize() const; 117 u32 GetFreeSize() const; 118 IsValid()119 bool IsValid() const { return m_pHeap != NULL; } 120 121 // TODO: 不要? 122 // const SectionList& GetSectionList() const { return m_SectionList; } 123 124 void Dump( nw::snd::SoundDataManager& mgr, nw::snd::SoundArchive& arc ); 125 126 private: 127 ut::FrameHeap* m_pHeap; 128 SectionList m_SectionList; 129 130 bool NewSection(); 131 void ClearSection(); 132 }; 133 134 } // namespace nw::snd::internal 135 } // namespace nw::snd 136 } // namespace nw 137 138 139 #endif /* NW_SND_FRAME_HEAP_H_ */ 140 141