1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: lyt_TextureContainer.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/lyt/lyt_Layout.h>
21 #include <nw/lyt/lyt_TextureContainer.h>
22 #include <nw/lyt/lyt_Util.h>
23
24 namespace nw
25 {
26 namespace lyt
27 {
28
TextureRefLink()29 TextureRefLink::TextureRefLink()
30 {
31 m_Name[0] = '\0';
32 }
33
~TextureRefLink()34 TextureRefLink::~TextureRefLink()
35 {
36 lyt::DeleteTexture(m_TexInfo);
37 }
38
39 void
Set(const char * name,const TextureInfo & texInfo)40 TextureRefLink::Set(
41 const char* name,
42 const TextureInfo& texInfo)
43 {
44 NW_NULL_ASSERT(name);
45
46 // TODO: バイナリコンバータでファイル名の長さをチェックする。
47 ut::strcpy(m_Name, sizeof(m_Name), name);
48 m_TexInfo = texInfo;
49 }
50
~TextureContainer()51 TextureContainer::~TextureContainer()
52 {
53 this->Finalize();
54 }
55
56 void
Finalize()57 TextureContainer::Finalize()
58 {
59 while (!this->empty())
60 {
61 TextureRefLink* pLink = &this->front();
62 this->erase(pLink);
63 Layout::DeleteObj(pLink);
64 }
65 }
66
67 const TextureInfo
FindTextureByName(const char * name)68 TextureContainer::FindTextureByName(const char* name)
69 {
70 for (Iterator it = this->GetBeginIter(); it != this->GetEndIter(); ++it)
71 {
72 if (0 == std::strcmp(name, it->GetResourceName()))
73 {
74 return it->GetTextureInfo();
75 }
76 }
77
78 return TextureInfo();
79 }
80
81 const TextureInfo
FindTextureByKey(TextureKey key)82 TextureContainer::FindTextureByKey(TextureKey key)
83 {
84 NW_NULL_ASSERT(key);
85 TextureRefLink* pLink = (TextureRefLink*)(key);
86
87 for (Iterator it = this->GetBeginIter(); it != this->GetEndIter(); ++it)
88 {
89 if (&(*it) == pLink)
90 {
91 return it->GetTextureInfo();
92 }
93 }
94
95 return TextureInfo();
96 }
97
98 TextureKey
RegistTexture(const char * name,const TextureInfo & textureInfo)99 TextureContainer::RegistTexture(const char* name, const TextureInfo& textureInfo)
100 {
101 NW_ASSERT(name);
102
103 TextureRefLink* pLink = Layout::NewObj<TextureRefLink>();
104 if (pLink == NULL)
105 {
106 return NULL;
107 }
108
109 pLink->Set(name, textureInfo);
110
111 this->push_back(pLink);
112
113 return (TextureKey) pLink;
114 }
115
116 void
UnregistTexture(TextureKey key)117 TextureContainer::UnregistTexture(TextureKey key)
118 {
119 NW_NULL_ASSERT(key);
120
121 TextureRefLink* pLink = (TextureRefLink*)(key);
122 this->erase(pLink);
123 Layout::DeleteObj(pLink);
124 }
125
126 } // namespace nw::lyt
127 } // namespace nw
128