2011-02-20 23:45:14 +01:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2011-02-20 23:45:14 +01:00
|
|
|
|
|
|
|
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"
|
|
|
|
|
2011-04-10 14:16:27 +02:00
|
|
|
/*
|
|
|
|
ClientActiveObject
|
|
|
|
*/
|
|
|
|
|
2017-01-09 20:39:22 +01:00
|
|
|
ClientActiveObject::ClientActiveObject(u16 id, Client *client,
|
2011-12-01 17:23:58 +01:00
|
|
|
ClientEnvironment *env):
|
2011-11-13 23:19:48 +01:00
|
|
|
ActiveObject(id),
|
2017-01-09 20:39:22 +01:00
|
|
|
m_client(client),
|
2011-12-01 17:23:58 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-02-17 11:37:55 +01:00
|
|
|
ClientActiveObject* ClientActiveObject::create(ActiveObjectType type,
|
2017-01-09 20:39:22 +01:00
|
|
|
Client *client, ClientEnvironment *env)
|
2011-02-20 23:45:14 +01:00
|
|
|
{
|
2011-04-07 23:47:14 +02:00
|
|
|
// Find factory function
|
2017-08-17 20:23:54 +02:00
|
|
|
auto n = m_types.find(type);
|
2017-06-04 21:00:04 +02:00
|
|
|
if (n == m_types.end()) {
|
2011-04-07 23:47:14 +02:00
|
|
|
// If factory is not found, just return.
|
2016-10-06 08:48:20 +02:00
|
|
|
warningstream << "ClientActiveObject: No factory for type="
|
|
|
|
<< (int)type << std::endl;
|
2011-02-20 23:45:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-04-07 23:47:14 +02:00
|
|
|
|
2012-12-20 18:19:49 +01:00
|
|
|
Factory f = n->second;
|
2017-01-09 20:39:22 +01:00
|
|
|
ClientActiveObject *object = (*f)(client, env);
|
2011-04-07 23:47:14 +02:00
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientActiveObject::registerType(u16 type, Factory f)
|
|
|
|
{
|
2017-08-17 20:23:54 +02:00
|
|
|
auto n = m_types.find(type);
|
|
|
|
if (n != m_types.end())
|
2011-04-07 23:47:14 +02:00
|
|
|
return;
|
2012-12-20 18:19:49 +01:00
|
|
|
m_types[type] = f;
|
2011-02-20 23:45:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|