2011-02-20 17:45:14 -05:00
|
|
|
/*
|
2013-02-24 12:40:43 -05:00
|
|
|
Minetest
|
2013-02-24 13:38:45 -05:00
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2011-02-20 17:45:14 -05:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 10:56:56 -04:00
|
|
|
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
|
2011-02-20 17:45:14 -05:00
|
|
|
(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
|
2012-06-05 10:56:56 -04:00
|
|
|
GNU Lesser General Public License for more details.
|
2011-02-20 17:45:14 -05:00
|
|
|
|
2012-06-05 10:56:56 -04:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2011-02-20 17:45:14 -05:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "clientobject.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "porting.h"
|
|
|
|
#include "constants.h"
|
|
|
|
|
2011-04-10 08:16:27 -04:00
|
|
|
/*
|
|
|
|
ClientActiveObject
|
|
|
|
*/
|
|
|
|
|
2011-12-01 11:23:58 -05:00
|
|
|
ClientActiveObject::ClientActiveObject(u16 id, IGameDef *gamedef,
|
|
|
|
ClientEnvironment *env):
|
2011-11-13 17:19:48 -05:00
|
|
|
ActiveObject(id),
|
2011-12-01 11:23:58 -05:00
|
|
|
m_gamedef(gamedef),
|
|
|
|
m_env(env)
|
2011-02-20 17:45:14 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientActiveObject::~ClientActiveObject()
|
|
|
|
{
|
2012-11-04 16:54:50 -05:00
|
|
|
removeFromScene(true);
|
2011-02-20 17:45:14 -05:00
|
|
|
}
|
|
|
|
|
2011-12-01 11:23:58 -05:00
|
|
|
ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef,
|
|
|
|
ClientEnvironment *env)
|
2011-02-20 17:45:14 -05:00
|
|
|
{
|
2011-04-07 17:47:14 -04:00
|
|
|
// Find factory function
|
|
|
|
core::map<u16, Factory>::Node *n;
|
|
|
|
n = m_types.find(type);
|
|
|
|
if(n == NULL)
|
2011-02-20 17:45:14 -05:00
|
|
|
{
|
2011-04-07 17:47:14 -04:00
|
|
|
// If factory is not found, just return.
|
|
|
|
dstream<<"WARNING: ClientActiveObject: No factory for type="
|
2011-10-14 19:28:57 -04:00
|
|
|
<<(int)type<<std::endl;
|
2011-02-20 17:45:14 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-04-07 17:47:14 -04:00
|
|
|
|
|
|
|
Factory f = n->getValue();
|
2011-12-01 11:23:58 -05:00
|
|
|
ClientActiveObject *object = (*f)(gamedef, env);
|
2011-04-07 17:47:14 -04:00
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientActiveObject::registerType(u16 type, Factory f)
|
|
|
|
{
|
|
|
|
core::map<u16, Factory>::Node *n;
|
|
|
|
n = m_types.find(type);
|
|
|
|
if(n)
|
|
|
|
return;
|
|
|
|
m_types.insert(type, f);
|
2011-02-20 17:45:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|