// Ryzom - MMORPG Framework
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
#include "stdpch.h"
/////////////
// INCLUDE //
/////////////
// client
#include "entity_animation_manager.h"
#include "animation_misc.h"
#include "animation_set.h"
#include "debug_client.h"
#include "sheet_manager.h"
#include "time_client.h"
#include "global.h"
// misc
#include "nel/misc/path.h"
#include "nel/misc/smart_ptr.h"
#include "nel/misc/file.h"
#include "nel/misc/progress_callback.h"
// 3d
#include "nel/3d/u_skeleton.h"
#include "nel/3d/u_driver.h"
#include "nel/3d/u_scene.h"
#include "nel/3d/u_track.h"
#include "nel/3d/u_play_list.h"
#include "nel/3d/u_play_list_manager.h"
#include "nel/3d/u_animation_set.h"
///////////
// USING //
///////////
using namespace NLMISC;
using namespace std;
using namespace NLGEORGES;
////////////
// EXTERN //
////////////
extern NL3D::UScene * Scene;
////////////
// GLOBAL //
////////////
// Hierarchical timer
H_AUTO_DECL ( RZ_Client_Entity_Animation_Mngr )
////////////////////
// STATIC MEMBERS //
////////////////////
CEntityAnimationManager *CEntityAnimationManager::_Instance = 0;
NL3D::UPlayListManager *CEntityAnimationManager::_PlayListManager = 0;
////////////////////
// STATIC METHODS //
////////////////////
//---------------------------------------------------
// getInstance :
// Instanciate CEntityAnimationManager. There can be only one instance (singleton)
// \return CEntityAnimationManager * : Pointer on CEntityAnimationManager.
//---------------------------------------------------
CEntityAnimationManager * CEntityAnimationManager::getInstance()
{
if(_Instance == 0)
{
_Instance = new CEntityAnimationManager();
if(Scene)
_PlayListManager = Scene->createPlayListManager();
else
nlwarning("CEntityAnimationManager::getInstance : Scene is not allocated.");
}
return _Instance;
}// instance //
//-----------------------------------------------
// delInstance :
// Release the current instance
// \warning If you the kept the pointer given by getInstance, it will be invalid.
//-----------------------------------------------
void CEntityAnimationManager::delInstance()
{
// Release the singleton
if(_Instance)
{
delete _Instance;
_Instance = 0;
}
}// delInstance //
/////////////
// METHODS //
/////////////
//---------------------------------------------------
// CEntityAnimationManager :
// Constructor.
//---------------------------------------------------
CEntityAnimationManager::CEntityAnimationManager()
{
_AnimationSet = NULL;
_AutomatonList = NULL;
_EmotList = NULL;
}// CEntityAnimationManager //
//---------------------------------------------------
// ~CEntityAnimationManager :
// Destructor.
//---------------------------------------------------
CEntityAnimationManager::~CEntityAnimationManager()
{
// Delete the playlist manager
if(_PlayListManager)
{
// if(Scene)
// Scene->deletePlayListManager(_PlayListManager);
_PlayListManager = 0;
}
// Release all things initialized by the load method.
release();
}// ~CEntityAnimationManager //
//-----------------------------------------------
// release
// Release all things initialized by the load method.
//-----------------------------------------------
void CEntityAnimationManager::release()
{
// Animation set cache
_AnimationSetPosCache.clear();
_AnimationSetRotCache.clear();
// Release animsets.
_AnimSet.clear();
// Release Automatons and Release the emots list
// Nothing to release here : all is in the sheet manager so kept during all the time the game is running
// Release the AnimationSet.
if(_AnimationSet)
{
Driver->deleteAnimationSet(_AnimationSet);
_AnimationSet = 0;
}
// owned by CSheetManager
_AutomatonList = NULL;
}// release //
//---------------------------------------------------
// load :
//---------------------------------------------------
void CEntityAnimationManager::load(NLMISC::IProgressCallback &/* progress */, bool /* forceRepack */ /* = false */)
{
// Whole initInGame profile
NLMISC::TTime initStart;
initStart = ryzomGetLocalTime ();
// Before loading, release the old stuff.
release();
// Log in the animation file.
//setDebugOutput(getLogDirectory() + "animation.dbg");
setDebugOutput(""); // no log
// Create the animation set for all entities.
_AnimationSet = Driver->createAnimationSet();
if(_AnimationSet == 0)
pushDebugStr("_AnimationSet is Null !.");
// Loading Emots
pushInfoStr("COMPUTING EMOTS ...");
// Initialize the emot list
_EmotList = dynamic_cast(SheetMngr.get(CSheetId("list.emot")));
nlassert(_EmotList != NULL);
pushInfoStr("COMPUTING AUTOMATON ...");
// Initialize the automaton.
_AutomatonList = dynamic_cast(SheetMngr.get(CSheetId("automaton.automaton_list")));
nlassert(_AutomatonList != NULL);
pushInfoStr("COMPUTING ANIMATION SET ...");
// Initialize the list of animsets
CAnimationSetListSheet *pASLS = dynamic_cast(SheetMngr.get(CSheetId("entities.animset_list")));
nlassert(pASLS != NULL);
for (uint32 i = 0; i < pASLS->AnimSetList.size(); ++i)
{
CAnimationSet as;
string sTmp = strlwr(pASLS->AnimSetList[i].Name);
sTmp = sTmp.substr(0,sTmp.rfind('.'));
pair