Show EntityFactory.cpp syntax highlighted
/**
**************************************************************************************
*Palisma - Secrets of the Illuminati is an open-source 2D RPG *
*Copyright (C) 2006, Tony Sparks *
* *
*This library is free software; you can redistribute it and/or *
*modify it under the terms of the GNU Lesser General Public *
*License as published by the Free Software Foundation; either *
*version 2.1 of the License, or (at your option) any later version. *
* *
*This library 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 *
*Lesser General Public License for more details. *
* *
*You should have received a copy of the GNU Lesser General Public *
*License along with this library; if not, write to the Free Software *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
**************************************************************************************
*/
#include "StdAfx.h"
#include "EntityFactory.h"
EntityFactory::EntityFactory(void)
{
}
EntityFactory::~EntityFactory(void)
{
}
/** Create an entity */
template<class T>
T* EntityFactory::CreateEntity( const std::string &ent_type )
{
T* ent = new T;
assert( static_cast<IEntity*>( ent ) && "Trying to create a class that is not an IEntity in EntityFactory" );
EntityManager::GetInstance()->RegisterEntity( static_cast<IEntity*>( ent ) );
return ent;
}
/** Create an entity */
IEntity* EntityFactory::CreatePrefabEntity( const std::string &ent_type )
{
if ( m_entList.find( ent_type ) != m_entList.end() )
{
IEntity* ent = m_entList[ ent_type ];
return CloneEntity( ent );
}
return NULL;
}
/** Clone an entity */
IEntity* EntityFactory::CloneEntity(const IEntity* ent)
{
IEntity *new_ent = new IEntity( *ent );
EntityManager::GetInstance()->RegisterEntity( new_ent );
return new_ent;
}
/** Add to the list of types */
void EntityFactory::AddToList( const std::string &refName, IEntity* ent )
{
// only add if we don't have a reference to this object
if ( m_entList.find( refName ) == m_entList.end() )
m_entList[ refName ] = ent;
}
See more files for this project here