/*---------------------------------------------------------------------------* Project: NintendoWare File: lyt_TextureContainer.cpp Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include #include namespace nw { namespace lyt { TextureRefLink::TextureRefLink() { m_Name[0] = '\0'; } TextureRefLink::~TextureRefLink() { lyt::DeleteTexture(m_TexInfo); } void TextureRefLink::Set( const char* name, const TextureInfo& texInfo) { NW_NULL_ASSERT(name); // TODO: バイナリコンバータでファイル名の長さをチェックする。 ut::strcpy(m_Name, sizeof(m_Name), name); m_TexInfo = texInfo; } TextureContainer::~TextureContainer() { this->Finalize(); } void TextureContainer::Finalize() { while (!this->empty()) { TextureRefLink* pLink = &this->front(); this->erase(pLink); Layout::DeleteObj(pLink); } } const TextureInfo TextureContainer::FindTextureByName(const char* name) { for (Iterator it = this->GetBeginIter(); it != this->GetEndIter(); ++it) { if (0 == std::strcmp(name, it->GetResourceName())) { return it->GetTextureInfo(); } } return TextureInfo(); } const TextureInfo TextureContainer::FindTextureByKey(TextureKey key) { NW_NULL_ASSERT(key); TextureRefLink* pLink = (TextureRefLink*)(key); for (Iterator it = this->GetBeginIter(); it != this->GetEndIter(); ++it) { if (&(*it) == pLink) { return it->GetTextureInfo(); } } return TextureInfo(); } TextureKey TextureContainer::RegistTexture(const char* name, const TextureInfo& textureInfo) { NW_ASSERT(name); TextureRefLink* pLink = Layout::NewObj(); if (pLink == NULL) { return NULL; } pLink->Set(name, textureInfo); this->push_back(pLink); return (TextureKey) pLink; } void TextureContainer::UnregistTexture(TextureKey key) { NW_NULL_ASSERT(key); TextureRefLink* pLink = (TextureRefLink*)(key); this->erase(pLink); Layout::DeleteObj(pLink); } } // namespace nw::lyt } // namespace nw