Drop content_sao.{cpp,h}

Move LuaEntitySAO to a new dedicated file
Drop TestSAO (useless object)
Drop the old static startup initialized SAO factory, which was pretty useless.
This factory was using a std::map for 2 elements, now just use a simple condition owned by ServerEnvironment, which will be lightweight, that will also drop a one time useful test on each LuaEntitySAO creation. This should reduce server load on massive SAO creation
This commit is contained in:
Loic Blot 2020-04-11 11:22:15 +02:00 committed by Loïc Blot
parent 894a34aef4
commit 5146086a64
25 changed files with 126 additions and 295 deletions

@ -161,7 +161,6 @@ LOCAL_SRC_FILES := \
jni/src/content/mods.cpp \ jni/src/content/mods.cpp \
jni/src/content_nodemeta.cpp \ jni/src/content_nodemeta.cpp \
jni/src/content/packages.cpp \ jni/src/content/packages.cpp \
jni/src/content_sao.cpp \
jni/src/content/subgames.cpp \ jni/src/content/subgames.cpp \
jni/src/convert_json.cpp \ jni/src/convert_json.cpp \
jni/src/craftdef.cpp \ jni/src/craftdef.cpp \
@ -258,8 +257,11 @@ LOCAL_SRC_FILES := \
jni/src/server.cpp \ jni/src/server.cpp \
jni/src/serverenvironment.cpp \ jni/src/serverenvironment.cpp \
jni/src/serverlist.cpp \ jni/src/serverlist.cpp \
jni/src/server/luaentity_sao.cpp \
jni/src/server/mods.cpp \ jni/src/server/mods.cpp \
jni/src/server/player_sao.cpp \
jni/src/server/serveractiveobject.cpp \ jni/src/server/serveractiveobject.cpp \
jni/src/server/unit_sao.cpp \
jni/src/settings.cpp \ jni/src/settings.cpp \
jni/src/staticobject.cpp \ jni/src/staticobject.cpp \
jni/src/tileanimation.cpp \ jni/src/tileanimation.cpp \

@ -375,7 +375,6 @@ set(common_SRCS
collision.cpp collision.cpp
content_mapnode.cpp content_mapnode.cpp
content_nodemeta.cpp content_nodemeta.cpp
content_sao.cpp
convert_json.cpp convert_json.cpp
craftdef.cpp craftdef.cpp
debug.cpp debug.cpp

@ -19,7 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <sstream> #include <sstream>
#include "clientiface.h" #include "clientiface.h"
#include "content_sao.h"
#include "network/connection.h" #include "network/connection.h"
#include "network/serveropcodes.h" #include "network/serveropcodes.h"
#include "remoteplayer.h" #include "remoteplayer.h"
@ -28,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serverenvironment.h" #include "serverenvironment.h"
#include "map.h" #include "map.h"
#include "emerge.h" #include "emerge.h"
#include "server/luaentity_sao.h"
#include "server/player_sao.h" #include "server/player_sao.h"
#include "log.h" #include "log.h"
#include "util/srp.h" #include "util/srp.h"

@ -28,7 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h" #include "mapblock.h"
#include "mapnode.h" #include "mapnode.h"
#include "map.h" #include "map.h"
#include "content_sao.h"
#include "nodedef.h" #include "nodedef.h"
#include "emerge.h" #include "emerge.h"
#include "voxelalgorithms.h" #include "voxelalgorithms.h"

@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h" #include "mapblock.h"
#include "mapnode.h" #include "mapnode.h"
#include "map.h" #include "map.h"
#include "content_sao.h"
#include "nodedef.h" #include "nodedef.h"
#include "voxelalgorithms.h" #include "voxelalgorithms.h"
//#include "profiler.h" // For TimeTaker //#include "profiler.h" // For TimeTaker

@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h" #include "mapblock.h"
#include "mapnode.h" #include "mapnode.h"
#include "map.h" #include "map.h"
#include "content_sao.h"
#include "nodedef.h" #include "nodedef.h"
#include "voxelalgorithms.h" #include "voxelalgorithms.h"
//#include "profiler.h" // For TimeTaker //#include "profiler.h" // For TimeTaker

@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h" #include "mapblock.h"
#include "mapnode.h" #include "mapnode.h"
#include "map.h" #include "map.h"
#include "content_sao.h"
#include "nodedef.h" #include "nodedef.h"
#include "voxelalgorithms.h" #include "voxelalgorithms.h"
//#include "profiler.h" // For TimeTaker //#include "profiler.h" // For TimeTaker

@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h" #include "mapblock.h"
#include "mapnode.h" #include "mapnode.h"
#include "map.h" #include "map.h"
#include "content_sao.h"
#include "nodedef.h" #include "nodedef.h"
#include "voxelalgorithms.h" #include "voxelalgorithms.h"
//#include "profiler.h" // For TimeTaker //#include "profiler.h" // For TimeTaker

@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h" #include "mapblock.h"
#include "mapnode.h" #include "mapnode.h"
#include "map.h" #include "map.h"
#include "content_sao.h"
#include "nodedef.h" #include "nodedef.h"
#include "voxelalgorithms.h" #include "voxelalgorithms.h"
//#include "profiler.h" // For TimeTaker //#include "profiler.h" // For TimeTaker

@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h" #include "mapblock.h"
#include "mapnode.h" #include "mapnode.h"
#include "map.h" #include "map.h"
#include "content_sao.h"
#include "nodedef.h" #include "nodedef.h"
#include "voxelalgorithms.h" #include "voxelalgorithms.h"
//#include "profiler.h" // For TimeTaker //#include "profiler.h" // For TimeTaker

@ -43,7 +43,6 @@ extern "C" {
#include <cstdio> #include <cstdio>
#include <cstdarg> #include <cstdarg>
#include "script/common/c_content.h" #include "script/common/c_content.h"
#include "content_sao.h"
#include <sstream> #include <sstream>

@ -33,12 +33,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "nodedef.h" #include "nodedef.h"
#include "daynightratio.h" #include "daynightratio.h"
#include "util/pointedthing.h" #include "util/pointedthing.h"
#include "content_sao.h"
#include "mapgen/treegen.h" #include "mapgen/treegen.h"
#include "emerge.h" #include "emerge.h"
#include "pathfinder.h" #include "pathfinder.h"
#include "face_position_cache.h" #include "face_position_cache.h"
#include "remoteplayer.h" #include "remoteplayer.h"
#include "server/luaentity_sao.h"
#include "server/player_sao.h" #include "server/player_sao.h"
#ifndef SERVER #ifndef SERVER
#include "client/client.h" #include "client/client.h"

@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "itemdef.h" #include "itemdef.h"
#include "nodedef.h" #include "nodedef.h"
#include "server.h" #include "server.h"
#include "content_sao.h"
#include "inventory.h" #include "inventory.h"
#include "log.h" #include "log.h"

@ -27,11 +27,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "common/c_content.h" #include "common/c_content.h"
#include "log.h" #include "log.h"
#include "tool.h" #include "tool.h"
#include "content_sao.h"
#include "remoteplayer.h" #include "remoteplayer.h"
#include "server.h" #include "server.h"
#include "hud.h" #include "hud.h"
#include "scripting_server.h" #include "scripting_server.h"
#include "server/luaentity_sao.h"
#include "server/player_sao.h" #include "server/player_sao.h"
/* /*

@ -1,5 +1,6 @@
set(server_SRCS set(server_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/activeobjectmgr.cpp ${CMAKE_CURRENT_SOURCE_DIR}/activeobjectmgr.cpp
${CMAKE_CURRENT_SOURCE_DIR}/luaentity_sao.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mods.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mods.cpp
${CMAKE_CURRENT_SOURCE_DIR}/player_sao.cpp ${CMAKE_CURRENT_SOURCE_DIR}/player_sao.cpp
${CMAKE_CURRENT_SOURCE_DIR}/serveractiveobject.cpp ${CMAKE_CURRENT_SOURCE_DIR}/serveractiveobject.cpp

@ -1,6 +1,7 @@
/* /*
Minetest Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com> Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
Copyright (C) 2013-2020 Minetest core developers & community
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
@ -17,151 +18,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "content_sao.h" #include "luaentity_sao.h"
#include "util/serialize.h"
#include "collision.h" #include "collision.h"
#include "environment.h" #include "constants.h"
#include "tool.h" // For ToolCapabilities #include "player_sao.h"
#include "gamedef.h"
#include "nodedef.h"
#include "remoteplayer.h"
#include "server.h"
#include "scripting_server.h" #include "scripting_server.h"
#include "server/player_sao.h" #include "server.h"
#include "settings.h" #include "serverenvironment.h"
#include <algorithm>
#include <cmath>
std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types; LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data)
: UnitSAO(env, pos)
/*
TestSAO
*/
class TestSAO : public ServerActiveObject
{
public:
TestSAO(ServerEnvironment *env, v3f pos):
ServerActiveObject(env, pos),
m_timer1(0),
m_age(0)
{
ServerActiveObject::registerType(getType(), create);
}
ActiveObjectType getType() const
{ return ACTIVEOBJECT_TYPE_TEST; }
static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
const std::string &data)
{
return new TestSAO(env, pos);
}
void step(float dtime, bool send_recommended)
{
m_age += dtime;
if(m_age > 10)
{
m_pending_removal = true;
return;
}
m_base_position.Y += dtime * BS * 2;
if(m_base_position.Y > 8*BS)
m_base_position.Y = 2*BS;
if (!send_recommended)
return;
m_timer1 -= dtime;
if(m_timer1 < 0.0)
{
m_timer1 += 0.125;
std::string data;
data += itos(0); // 0 = position
data += " ";
data += itos(m_base_position.X);
data += " ";
data += itos(m_base_position.Y);
data += " ";
data += itos(m_base_position.Z);
ActiveObjectMessage aom(getId(), false, data);
m_messages_out.push(aom);
}
}
bool getCollisionBox(aabb3f *toset) const { return false; }
virtual bool getSelectionBox(aabb3f *toset) const { return false; }
bool collideWithObjects() const { return false; }
private:
float m_timer1;
float m_age;
};
// Prototype (registers item for deserialization)
TestSAO proto_TestSAO(NULL, v3f(0,0,0));
/*
LuaEntitySAO
*/
// Prototype (registers item for deserialization)
LuaEntitySAO proto_LuaEntitySAO(NULL, v3f(0,0,0), "_prototype", "");
LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos,
const std::string &name, const std::string &state):
UnitSAO(env, pos),
m_init_name(name),
m_init_state(state)
{
// Only register type if no environment supplied
if(env == NULL){
ServerActiveObject::registerType(getType(), create);
return;
}
}
LuaEntitySAO::~LuaEntitySAO()
{
if(m_registered){
m_env->getScriptIface()->luaentity_Remove(m_id);
}
for (u32 attached_particle_spawner : m_attached_particle_spawners) {
m_env->deleteParticleSpawner(attached_particle_spawner, false);
}
}
void LuaEntitySAO::addedToEnvironment(u32 dtime_s)
{
ServerActiveObject::addedToEnvironment(dtime_s);
// Create entity from name
m_registered = m_env->getScriptIface()->
luaentity_Add(m_id, m_init_name.c_str());
if(m_registered){
// Get properties
m_env->getScriptIface()->
luaentity_GetProperties(m_id, this, &m_prop);
// Initialize HP from properties
m_hp = m_prop.hp_max;
// Activate entity, supplying serialized state
m_env->getScriptIface()->
luaentity_Activate(m_id, m_init_state, dtime_s);
} else {
m_prop.infotext = m_init_name;
}
}
ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos,
const std::string &data)
{ {
std::string name; std::string name;
std::string state; std::string state;
@ -205,11 +71,45 @@ ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos,
// create object // create object
infostream << "LuaEntitySAO::create(name=\"" << name << "\" state=\"" infostream << "LuaEntitySAO::create(name=\"" << name << "\" state=\""
<< state << "\")" << std::endl; << state << "\")" << std::endl;
LuaEntitySAO *sao = new LuaEntitySAO(env, pos, name, state);
sao->m_hp = hp; m_init_name = name;
sao->m_velocity = velocity; m_init_state = state;
sao->m_rotation = rotation; m_hp = hp;
return sao; m_velocity = velocity;
m_rotation = rotation;
}
LuaEntitySAO::~LuaEntitySAO()
{
if(m_registered){
m_env->getScriptIface()->luaentity_Remove(m_id);
}
for (u32 attached_particle_spawner : m_attached_particle_spawners) {
m_env->deleteParticleSpawner(attached_particle_spawner, false);
}
}
void LuaEntitySAO::addedToEnvironment(u32 dtime_s)
{
ServerActiveObject::addedToEnvironment(dtime_s);
// Create entity from name
m_registered = m_env->getScriptIface()->
luaentity_Add(m_id, m_init_name.c_str());
if(m_registered){
// Get properties
m_env->getScriptIface()->
luaentity_GetProperties(m_id, this, &m_prop);
// Initialize HP from properties
m_hp = m_prop.hp_max;
// Activate entity, supplying serialized state
m_env->getScriptIface()->
luaentity_Activate(m_id, m_init_state, dtime_s);
} else {
m_prop.infotext = m_init_name;
}
} }
void LuaEntitySAO::step(float dtime, bool send_recommended) void LuaEntitySAO::step(float dtime, bool send_recommended)

@ -1,6 +1,7 @@
/* /*
Minetest Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com> Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
Copyright (C) 2013-2020 Minetest core developers & community
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
@ -19,36 +20,30 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once #pragma once
#include "network/networkprotocol.h" #include "unit_sao.h"
#include "util/numeric.h"
#include "server/unit_sao.h"
#include "itemgroup.h"
#include "constants.h"
/*
LuaEntitySAO needs some internals exposed.
*/
class LuaEntitySAO : public UnitSAO class LuaEntitySAO : public UnitSAO
{ {
public: public:
LuaEntitySAO(ServerEnvironment *env, v3f pos, LuaEntitySAO() = delete;
const std::string &name, const std::string &state); // Used by the environment to load SAO
LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data);
// Used by the Lua API
LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &name,
const std::string &state) :
UnitSAO(env, pos),
m_init_name(name), m_init_state(state)
{
}
~LuaEntitySAO(); ~LuaEntitySAO();
ActiveObjectType getType() const ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_LUAENTITY; }
{ return ACTIVEOBJECT_TYPE_LUAENTITY; } ActiveObjectType getSendType() const { return ACTIVEOBJECT_TYPE_GENERIC; }
ActiveObjectType getSendType() const
{ return ACTIVEOBJECT_TYPE_GENERIC; }
virtual void addedToEnvironment(u32 dtime_s); virtual void addedToEnvironment(u32 dtime_s);
static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
const std::string &data);
void step(float dtime, bool send_recommended); void step(float dtime, bool send_recommended);
std::string getClientInitializationData(u16 protocol_version); std::string getClientInitializationData(u16 protocol_version);
bool isStaticAllowed() const bool isStaticAllowed() const { return m_prop.static_save; }
{ return m_prop.static_save; }
void getStaticData(std::string *result) const; void getStaticData(std::string *result) const;
u16 punch(v3f dir, u16 punch(v3f dir, const ToolCapabilities *toolcap = nullptr,
const ToolCapabilities *toolcap = nullptr,
ServerActiveObject *puncher = nullptr, ServerActiveObject *puncher = nullptr,
float time_from_last_punch = 1000000.0f); float time_from_last_punch = 1000000.0f);
void rightClick(ServerActiveObject *clicker); void rightClick(ServerActiveObject *clicker);
@ -61,10 +56,7 @@ public:
/* LuaEntitySAO-specific */ /* LuaEntitySAO-specific */
void setVelocity(v3f velocity); void setVelocity(v3f velocity);
void addVelocity(v3f velocity) void addVelocity(v3f velocity) { m_velocity += velocity; }
{
m_velocity += velocity;
}
v3f getVelocity(); v3f getVelocity();
void setAcceleration(v3f acceleration); void setAcceleration(v3f acceleration);
v3f getAcceleration(); v3f getAcceleration();
@ -77,12 +69,13 @@ public:
bool getCollisionBox(aabb3f *toset) const; bool getCollisionBox(aabb3f *toset) const;
bool getSelectionBox(aabb3f *toset) const; bool getSelectionBox(aabb3f *toset) const;
bool collideWithObjects() const; bool collideWithObjects() const;
private: private:
std::string getPropertyPacket(); std::string getPropertyPacket();
void sendPosition(bool do_interpolate, bool is_movement_end); void sendPosition(bool do_interpolate, bool is_movement_end);
std::string generateSetTextureModCommand() const; std::string generateSetTextureModCommand() const;
static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames, f32 framelength, static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames,
bool select_horiz_by_yawpitch); f32 framelength, bool select_horiz_by_yawpitch);
std::string m_init_name; std::string m_init_name;
std::string m_init_state; std::string m_init_state;
@ -98,4 +91,3 @@ private:
float m_last_sent_move_precision = 0.0f; float m_last_sent_move_precision = 0.0f;
std::string m_current_texture_modifier = ""; std::string m_current_texture_modifier = "";
}; };

@ -1,4 +1,3 @@
/* /*
Minetest Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com> Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
@ -19,6 +18,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#pragma once
#include "constants.h" #include "constants.h"
#include "network/networkprotocol.h" #include "network/networkprotocol.h"
#include "unit_sao.h" #include "unit_sao.h"
@ -32,33 +33,31 @@ class LagPool
{ {
float m_pool = 15.0f; float m_pool = 15.0f;
float m_max = 15.0f; float m_max = 15.0f;
public: public:
LagPool() = default; LagPool() = default;
void setMax(float new_max) void setMax(float new_max)
{ {
m_max = new_max; m_max = new_max;
if(m_pool > new_max) if (m_pool > new_max)
m_pool = new_max; m_pool = new_max;
} }
void add(float dtime) void add(float dtime)
{ {
m_pool -= dtime; m_pool -= dtime;
if(m_pool < 0) if (m_pool < 0)
m_pool = 0; m_pool = 0;
} }
void empty() void empty() { m_pool = m_max; }
{
m_pool = m_max;
}
bool grab(float dtime) bool grab(float dtime)
{ {
if(dtime <= 0) if (dtime <= 0)
return true; return true;
if(m_pool + dtime > m_max) if (m_pool + dtime > m_max)
return false; return false;
m_pool += dtime; m_pool += dtime;
return true; return true;
@ -73,10 +72,8 @@ public:
PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_, PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_,
bool is_singleplayer); bool is_singleplayer);
ActiveObjectType getType() const ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_PLAYER; }
{ return ACTIVEOBJECT_TYPE_PLAYER; } ActiveObjectType getSendType() const { return ACTIVEOBJECT_TYPE_GENERIC; }
ActiveObjectType getSendType() const
{ return ACTIVEOBJECT_TYPE_GENERIC; }
std::string getDescription(); std::string getDescription();
/* /*
@ -111,9 +108,7 @@ public:
Interaction interface Interaction interface
*/ */
u16 punch(v3f dir, u16 punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher,
const ToolCapabilities *toolcap,
ServerActiveObject *puncher,
float time_from_last_punch); float time_from_last_punch);
void rightClick(ServerActiveObject *clicker) {} void rightClick(ServerActiveObject *clicker) {}
void setHP(s32 hp, const PlayerHPChangeReason &reason); void setHP(s32 hp, const PlayerHPChangeReason &reason);
@ -144,10 +139,7 @@ public:
// Cheat prevention // Cheat prevention
v3f getLastGoodPosition() const v3f getLastGoodPosition() const { return m_last_good_position; }
{
return m_last_good_position;
}
float resetTimeFromLastPunch() float resetTimeFromLastPunch()
{ {
float r = m_time_from_last_punch; float r = m_time_from_last_punch;
@ -159,30 +151,17 @@ public:
m_nocheat_dig_pos = p; m_nocheat_dig_pos = p;
m_nocheat_dig_time = 0; m_nocheat_dig_time = 0;
} }
v3s16 getNoCheatDigPos() v3s16 getNoCheatDigPos() { return m_nocheat_dig_pos; }
{ float getNoCheatDigTime() { return m_nocheat_dig_time; }
return m_nocheat_dig_pos; void noCheatDigEnd() { m_nocheat_dig_pos = v3s16(32767, 32767, 32767); }
} LagPool &getDigPool() { return m_dig_pool; }
float getNoCheatDigTime()
{
return m_nocheat_dig_time;
}
void noCheatDigEnd()
{
m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
}
LagPool& getDigPool()
{
return m_dig_pool;
}
void setMaxSpeedOverride(const v3f &vel); void setMaxSpeedOverride(const v3f &vel);
// Returns true if cheated // Returns true if cheated
bool checkMovementCheat(); bool checkMovementCheat();
// Other // Other
void updatePrivileges(const std::set<std::string> &privs, void updatePrivileges(const std::set<std::string> &privs, bool is_singleplayer)
bool is_singleplayer)
{ {
m_privs = privs; m_privs = privs;
m_is_singleplayer = is_singleplayer; m_is_singleplayer = is_singleplayer;
@ -236,6 +215,7 @@ private:
s16 m_wanted_range = 0.0f; s16 m_wanted_range = 0.0f;
Metadata m_meta; Metadata m_meta;
public: public:
float m_physics_override_speed = 1.0f; float m_physics_override_speed = 1.0f;
float m_physics_override_jump = 1.0f; float m_physics_override_jump = 1.0f;
@ -246,9 +226,10 @@ public:
bool m_physics_override_sent = false; bool m_physics_override_sent = false;
}; };
struct PlayerHPChangeReason
struct PlayerHPChangeReason { {
enum Type : u8 { enum Type : u8
{
SET_HP, SET_HP,
PLAYER_PUNCH, PLAYER_PUNCH,
FALL, FALL,
@ -266,10 +247,7 @@ struct PlayerHPChangeReason {
// For NODE_DAMAGE // For NODE_DAMAGE
std::string node; std::string node;
inline bool hasLuaReference() const inline bool hasLuaReference() const { return lua_reference >= 0; }
{
return lua_reference >= 0;
}
bool setTypeFromString(const std::string &typestr) bool setTypeFromString(const std::string &typestr)
{ {
@ -311,15 +289,12 @@ struct PlayerHPChangeReason {
} }
} }
PlayerHPChangeReason(Type type): PlayerHPChangeReason(Type type) : type(type) {}
type(type)
{}
PlayerHPChangeReason(Type type, ServerActiveObject *object): PlayerHPChangeReason(Type type, ServerActiveObject *object) :
type(type), object(object) type(type), object(object)
{} {
}
PlayerHPChangeReason(Type type, std::string node): PlayerHPChangeReason(Type type, std::string node) : type(type), node(node) {}
type(type), node(node)
{}
}; };

@ -30,39 +30,6 @@ ServerActiveObject::ServerActiveObject(ServerEnvironment *env, v3f pos):
{ {
} }
ServerActiveObject* ServerActiveObject::create(ActiveObjectType type,
ServerEnvironment *env, u16 id, v3f pos,
const std::string &data)
{
// Find factory function
std::map<u16, Factory>::iterator n;
n = m_types.find(type);
if(n == m_types.end()) {
// These are 0.3 entity types, return without error.
if (ACTIVEOBJECT_TYPE_ITEM <= type && type <= ACTIVEOBJECT_TYPE_MOBV2) {
return NULL;
}
// If factory is not found, just return.
warningstream<<"ServerActiveObject: No factory for type="
<<type<<std::endl;
return NULL;
}
Factory f = n->second;
ServerActiveObject *object = (*f)(env, pos, data);
return object;
}
void ServerActiveObject::registerType(u16 type, Factory f)
{
std::map<u16, Factory>::iterator n;
n = m_types.find(type);
if(n != m_types.end())
return;
m_types[type] = f;
}
float ServerActiveObject::getMinimumSavedMovement() float ServerActiveObject::getMinimumSavedMovement()
{ {
return 2.0*BS; return 2.0*BS;

@ -244,12 +244,6 @@ protected:
virtual void onAttach(int parent_id) {} virtual void onAttach(int parent_id) {}
virtual void onDetach(int parent_id) {} virtual void onDetach(int parent_id) {}
// Used for creating objects based on type
typedef ServerActiveObject* (*Factory)
(ServerEnvironment *env, v3f pos,
const std::string &data);
static void registerType(u16 type, Factory f);
ServerEnvironment *m_env; ServerEnvironment *m_env;
v3f m_base_position; v3f m_base_position;
std::unordered_set<u32> m_attached_particle_spawners; std::unordered_set<u32> m_attached_particle_spawners;
@ -258,8 +252,4 @@ protected:
Queue of messages to be sent to the client Queue of messages to be sent to the client
*/ */
std::queue<ActiveObjectMessage> m_messages_out; std::queue<ActiveObjectMessage> m_messages_out;
private:
// Used for creating objects based on type
static std::map<u16, Factory> m_types;
}; };

@ -44,6 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#if USE_POSTGRESQL #if USE_POSTGRESQL
#include "database/database-postgresql.h" #include "database/database-postgresql.h"
#endif #endif
#include "server/luaentity_sao.h"
#include "server/player_sao.h" #include "server/player_sao.h"
#define LBM_NAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_:" #define LBM_NAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_:"
@ -1778,6 +1779,18 @@ static void print_hexdump(std::ostream &o, const std::string &data)
} }
} }
ServerActiveObject* ServerEnvironment::createSAO(ActiveObjectType type, v3f pos,
const std::string &data)
{
switch (type) {
case ACTIVEOBJECT_TYPE_LUAENTITY:
return new LuaEntitySAO(this, pos, data);
default:
warningstream << "ServerActiveObject: No factory for type=" << type << std::endl;
}
return nullptr;
}
/* /*
Convert stored objects from blocks near the players to active. Convert stored objects from blocks near the players to active.
*/ */
@ -1811,10 +1824,10 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
std::vector<StaticObject> new_stored; std::vector<StaticObject> new_stored;
for (const StaticObject &s_obj : block->m_static_objects.m_stored) { for (const StaticObject &s_obj : block->m_static_objects.m_stored) {
// Create an active object from the data // Create an active object from the data
ServerActiveObject *obj = ServerActiveObject::create ServerActiveObject *obj = createSAO((ActiveObjectType) s_obj.type, s_obj.pos,
((ActiveObjectType) s_obj.type, this, 0, s_obj.pos, s_obj.data); s_obj.data);
// If couldn't create object, store static data back. // If couldn't create object, store static data back.
if(obj == NULL) { if (!obj) {
errorstream<<"ServerEnvironment::activateObjects(): " errorstream<<"ServerEnvironment::activateObjects(): "
<<"failed to create active object from static object " <<"failed to create active object from static object "
<<"in block "<<PP(s_obj.pos/BS) <<"in block "<<PP(s_obj.pos/BS)

@ -468,4 +468,6 @@ private:
IntervalLimiter m_particle_management_interval; IntervalLimiter m_particle_management_interval;
std::unordered_map<u32, float> m_particle_spawners; std::unordered_map<u32, float> m_particle_spawners;
std::unordered_map<u32, u16> m_particle_spawner_attachments; std::unordered_map<u32, u16> m_particle_spawner_attachments;
ServerActiveObject* createSAO(ActiveObjectType type, v3f pos, const std::string &data);
}; };

@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "staticobject.h" #include "staticobject.h"
#include "util/serialize.h" #include "util/serialize.h"
#include "content_sao.h" #include "server/serveractiveobject.h"
StaticObject::StaticObject(const ServerActiveObject *s_obj, const v3f &pos_): StaticObject::StaticObject(const ServerActiveObject *s_obj, const v3f &pos_):
type(s_obj->getType()), type(s_obj->getType()),

@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "exceptions.h" #include "exceptions.h"
#include "remoteplayer.h" #include "remoteplayer.h"
#include "content_sao.h"
#include "server.h" #include "server.h"
class TestPlayer : public TestBase class TestPlayer : public TestBase

@ -118,8 +118,6 @@ src/content_mapblock.h
src/content_mapnode.cpp src/content_mapnode.cpp
src/content_nodemeta.cpp src/content_nodemeta.cpp
src/content_nodemeta.h src/content_nodemeta.h
src/content_sao.cpp
src/content_sao.h
src/convert_json.cpp src/convert_json.cpp
src/convert_json.h src/convert_json.h
src/craftdef.cpp src/craftdef.cpp
@ -408,6 +406,8 @@ src/serverenvironment.h
src/server.h src/server.h
src/serverlist.cpp src/serverlist.cpp
src/serverlist.h src/serverlist.h
src/server/luaentity_sao.cpp
src/server/player_sao.cpp
src/server/serveractiveobject.cpp src/server/serveractiveobject.cpp
src/server/serveractiveobject.h src/server/serveractiveobject.h
src/settings.cpp src/settings.cpp