2011-02-20 23:45:14 +01:00
|
|
|
/*
|
|
|
|
Minetest-c55
|
|
|
|
Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 16:56:56 +02: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 23:45:14 +01: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 16:56:56 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2011-02-20 23:45:14 +01:00
|
|
|
|
2012-06-05 16:56:56 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2011-02-20 23:45:14 +01: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 14:16:27 +02:00
|
|
|
/*
|
|
|
|
ClientActiveObject
|
|
|
|
*/
|
|
|
|
|
2011-12-01 17:23:58 +01:00
|
|
|
ClientActiveObject::ClientActiveObject(u16 id, IGameDef *gamedef,
|
|
|
|
ClientEnvironment *env):
|
2011-11-13 23:19:48 +01:00
|
|
|
ActiveObject(id),
|
2011-12-01 17:23:58 +01:00
|
|
|
m_gamedef(gamedef),
|
|
|
|
m_env(env)
|
2011-02-20 23:45:14 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientActiveObject::~ClientActiveObject()
|
|
|
|
{
|
2012-11-04 22:54:50 +01:00
|
|
|
removeFromScene(true);
|
2011-02-20 23:45:14 +01:00
|
|
|
}
|
|
|
|
|
2011-12-01 17:23:58 +01:00
|
|
|
ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef,
|
|
|
|
ClientEnvironment *env)
|
2011-02-20 23:45:14 +01:00
|
|
|
{
|
2011-04-07 23:47:14 +02:00
|
|
|
// Find factory function
|
|
|
|
core::map<u16, Factory>::Node *n;
|
|
|
|
n = m_types.find(type);
|
|
|
|
if(n == NULL)
|
2011-02-20 23:45:14 +01:00
|
|
|
{
|
2011-04-07 23:47:14 +02:00
|
|
|
// If factory is not found, just return.
|
|
|
|
dstream<<"WARNING: ClientActiveObject: No factory for type="
|
2011-10-15 01:28:57 +02:00
|
|
|
<<(int)type<<std::endl;
|
2011-02-20 23:45:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-04-07 23:47:14 +02:00
|
|
|
|
|
|
|
Factory f = n->getValue();
|
2011-12-01 17:23:58 +01:00
|
|
|
ClientActiveObject *object = (*f)(gamedef, env);
|
2011-04-07 23:47:14 +02: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 23:45:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|