2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : SkeletonAnimManager.cpp
|
|
|
|
* Project : 0 A.D.
|
|
|
|
* Description : Owner of all skeleton animations
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2004-06-03 20:38:14 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2007-03-01 19:52:53 +01:00
|
|
|
#include "SkeletonAnimManager.h"
|
|
|
|
|
|
|
|
#include "graphics/ColladaManager.h"
|
|
|
|
#include "graphics/Model.h"
|
|
|
|
#include "graphics/SkeletonAnimDef.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/CLogger.h"
|
2008-02-04 12:40:42 +01:00
|
|
|
#include "ps/FileIo.h"
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2004-08-15 22:57:31 +02:00
|
|
|
#define LOG_CATEGORY "graphics"
|
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CSkeletonAnimManager constructor
|
2007-03-01 19:52:53 +01:00
|
|
|
CSkeletonAnimManager::CSkeletonAnimManager(CColladaManager& colladaManager)
|
|
|
|
: m_ColladaManager(colladaManager)
|
2004-05-30 02:46:58 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CSkeletonAnimManager destructor
|
|
|
|
CSkeletonAnimManager::~CSkeletonAnimManager()
|
|
|
|
{
|
|
|
|
typedef std::map<CStr,CSkeletonAnimDef*>::iterator Iter;
|
2007-03-01 19:52:53 +01:00
|
|
|
for (Iter i = m_Animations.begin(); i != m_Animations.end(); ++i)
|
2004-05-30 02:46:58 +02:00
|
|
|
delete i->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// GetAnimation: return a given animation by filename; return null if filename
|
|
|
|
// doesn't refer to valid animation file
|
2007-03-01 19:52:53 +01:00
|
|
|
CSkeletonAnimDef* CSkeletonAnimManager::GetAnimation(const CStr& filename)
|
2004-05-30 02:46:58 +02:00
|
|
|
{
|
2007-03-01 19:52:53 +01:00
|
|
|
// Strip a three-letter file extension (if there is one) from the filename
|
|
|
|
CStr name;
|
|
|
|
if (filename.length() > 4 && filename[filename.length()-4] == '.')
|
|
|
|
name = filename.substr(0, filename.length()-4);
|
|
|
|
else
|
|
|
|
name = filename;
|
|
|
|
|
|
|
|
// Find if it's already been loaded
|
|
|
|
std::map<CStr, CSkeletonAnimDef*>::iterator iter = m_Animations.find(name);
|
|
|
|
if (iter != m_Animations.end())
|
2004-05-30 02:46:58 +02:00
|
|
|
return iter->second;
|
|
|
|
|
2007-03-01 19:52:53 +01:00
|
|
|
CSkeletonAnimDef* def = NULL;
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2007-03-01 19:52:53 +01:00
|
|
|
// Find the file to load
|
2008-01-07 21:03:19 +01:00
|
|
|
VfsPath psaFilename = m_ColladaManager.GetLoadableFilename(name, CColladaManager::PSA);
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2007-03-01 19:52:53 +01:00
|
|
|
if (psaFilename.empty())
|
|
|
|
{
|
2007-12-29 17:22:23 +01:00
|
|
|
LOG(CLogger::Error, LOG_CATEGORY, "Could not load animation '%s'", filename.c_str());
|
2007-03-01 19:52:53 +01:00
|
|
|
def = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
def = CSkeletonAnimDef::Load(psaFilename);
|
|
|
|
}
|
|
|
|
catch (PSERROR_File&)
|
|
|
|
{
|
|
|
|
// ignore errors (they'll be logged elsewhere)
|
|
|
|
}
|
2004-05-30 02:46:58 +02:00
|
|
|
}
|
2007-03-01 19:52:53 +01:00
|
|
|
|
|
|
|
if (def)
|
2007-12-29 17:22:23 +01:00
|
|
|
LOG(CLogger::Normal, LOG_CATEGORY, "CSkeletonAnimManager::GetAnimation(%s): Loaded successfully", filename.c_str());
|
2007-03-01 19:52:53 +01:00
|
|
|
else
|
2007-12-29 17:22:23 +01:00
|
|
|
LOG(CLogger::Error, LOG_CATEGORY, "CSkeletonAnimManager::GetAnimation(%s): Failed loading, marked file as bad", filename.c_str());
|
2007-03-01 19:52:53 +01:00
|
|
|
|
|
|
|
// Add to map
|
|
|
|
m_Animations[name] = def; // NULL if failed to load - we won't try loading it again
|
|
|
|
return def;
|
2004-05-30 02:46:58 +02:00
|
|
|
}
|