Skip to content

Commit 5146086

Browse files
committedApr 11, 2020
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
1 parent 894a34a commit 5146086

25 files changed

+125
-294
lines changed
 

‎build/android/jni/Android.mk

+3-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ LOCAL_SRC_FILES := \
161161
jni/src/content/mods.cpp \
162162
jni/src/content_nodemeta.cpp \
163163
jni/src/content/packages.cpp \
164-
jni/src/content_sao.cpp \
165164
jni/src/content/subgames.cpp \
166165
jni/src/convert_json.cpp \
167166
jni/src/craftdef.cpp \
@@ -258,8 +257,11 @@ LOCAL_SRC_FILES := \
258257
jni/src/server.cpp \
259258
jni/src/serverenvironment.cpp \
260259
jni/src/serverlist.cpp \
260+
jni/src/server/luaentity_sao.cpp \
261261
jni/src/server/mods.cpp \
262+
jni/src/server/player_sao.cpp \
262263
jni/src/server/serveractiveobject.cpp \
264+
jni/src/server/unit_sao.cpp \
263265
jni/src/settings.cpp \
264266
jni/src/staticobject.cpp \
265267
jni/src/tileanimation.cpp \

‎src/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ set(common_SRCS
375375
collision.cpp
376376
content_mapnode.cpp
377377
content_nodemeta.cpp
378-
content_sao.cpp
379378
convert_json.cpp
380379
craftdef.cpp
381380
debug.cpp

‎src/clientiface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1919

2020
#include <sstream>
2121
#include "clientiface.h"
22-
#include "content_sao.h"
2322
#include "network/connection.h"
2423
#include "network/serveropcodes.h"
2524
#include "remoteplayer.h"
@@ -28,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2827
#include "serverenvironment.h"
2928
#include "map.h"
3029
#include "emerge.h"
30+
#include "server/luaentity_sao.h"
3131
#include "server/player_sao.h"
3232
#include "log.h"
3333
#include "util/srp.h"

‎src/mapgen/mapgen.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828
#include "mapblock.h"
2929
#include "mapnode.h"
3030
#include "map.h"
31-
#include "content_sao.h"
3231
#include "nodedef.h"
3332
#include "emerge.h"
3433
#include "voxelalgorithms.h"

‎src/mapgen/mapgen_carpathian.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2626
#include "mapblock.h"
2727
#include "mapnode.h"
2828
#include "map.h"
29-
#include "content_sao.h"
3029
#include "nodedef.h"
3130
#include "voxelalgorithms.h"
3231
//#include "profiler.h" // For TimeTaker

‎src/mapgen/mapgen_flat.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2525
#include "mapblock.h"
2626
#include "mapnode.h"
2727
#include "map.h"
28-
#include "content_sao.h"
2928
#include "nodedef.h"
3029
#include "voxelalgorithms.h"
3130
//#include "profiler.h" // For TimeTaker

‎src/mapgen/mapgen_fractal.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2626
#include "mapblock.h"
2727
#include "mapnode.h"
2828
#include "map.h"
29-
#include "content_sao.h"
3029
#include "nodedef.h"
3130
#include "voxelalgorithms.h"
3231
//#include "profiler.h" // For TimeTaker

‎src/mapgen/mapgen_v5.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2525
#include "mapblock.h"
2626
#include "mapnode.h"
2727
#include "map.h"
28-
#include "content_sao.h"
2928
#include "nodedef.h"
3029
#include "voxelalgorithms.h"
3130
//#include "profiler.h" // For TimeTaker

‎src/mapgen/mapgen_v6.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2727
#include "mapblock.h"
2828
#include "mapnode.h"
2929
#include "map.h"
30-
#include "content_sao.h"
3130
#include "nodedef.h"
3231
#include "voxelalgorithms.h"
3332
//#include "profiler.h" // For TimeTaker

‎src/mapgen/mapgen_v7.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2626
#include "mapblock.h"
2727
#include "mapnode.h"
2828
#include "map.h"
29-
#include "content_sao.h"
3029
#include "nodedef.h"
3130
#include "voxelalgorithms.h"
3231
//#include "profiler.h" // For TimeTaker

‎src/script/cpp_api/s_base.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ extern "C" {
4343
#include <cstdio>
4444
#include <cstdarg>
4545
#include "script/common/c_content.h"
46-
#include "content_sao.h"
4746
#include <sstream>
4847

4948

‎src/script/lua_api/l_env.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3333
#include "nodedef.h"
3434
#include "daynightratio.h"
3535
#include "util/pointedthing.h"
36-
#include "content_sao.h"
3736
#include "mapgen/treegen.h"
3837
#include "emerge.h"
3938
#include "pathfinder.h"
4039
#include "face_position_cache.h"
4140
#include "remoteplayer.h"
41+
#include "server/luaentity_sao.h"
4242
#include "server/player_sao.h"
4343
#ifndef SERVER
4444
#include "client/client.h"

‎src/script/lua_api/l_item.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2525
#include "itemdef.h"
2626
#include "nodedef.h"
2727
#include "server.h"
28-
#include "content_sao.h"
2928
#include "inventory.h"
3029
#include "log.h"
3130

‎src/script/lua_api/l_object.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2727
#include "common/c_content.h"
2828
#include "log.h"
2929
#include "tool.h"
30-
#include "content_sao.h"
3130
#include "remoteplayer.h"
3231
#include "server.h"
3332
#include "hud.h"
3433
#include "scripting_server.h"
34+
#include "server/luaentity_sao.h"
3535
#include "server/player_sao.h"
3636

3737
/*

‎src/server/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(server_SRCS
22
${CMAKE_CURRENT_SOURCE_DIR}/activeobjectmgr.cpp
3+
${CMAKE_CURRENT_SOURCE_DIR}/luaentity_sao.cpp
34
${CMAKE_CURRENT_SOURCE_DIR}/mods.cpp
45
${CMAKE_CURRENT_SOURCE_DIR}/player_sao.cpp
56
${CMAKE_CURRENT_SOURCE_DIR}/serveractiveobject.cpp

‎src/content_sao.cpp ‎src/server/luaentity_sao.cpp

+46-146
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
Minetest
33
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
Copyright (C) 2013-2020 Minetest core developers & community
45
56
This program is free software; you can redistribute it and/or modify
67
it under the terms of the GNU Lesser General Public License as published by
@@ -17,114 +18,65 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1718
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1819
*/
1920

20-
#include "content_sao.h"
21-
#include "util/serialize.h"
21+
#include "luaentity_sao.h"
2222
#include "collision.h"
23-
#include "environment.h"
24-
#include "tool.h" // For ToolCapabilities
25-
#include "gamedef.h"
26-
#include "nodedef.h"
27-
#include "remoteplayer.h"
28-
#include "server.h"
23+
#include "constants.h"
24+
#include "player_sao.h"
2925
#include "scripting_server.h"
30-
#include "server/player_sao.h"
31-
#include "settings.h"
32-
#include <algorithm>
33-
#include <cmath>
34-
35-
std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
36-
37-
/*
38-
TestSAO
39-
*/
26+
#include "server.h"
27+
#include "serverenvironment.h"
4028

41-
class TestSAO : public ServerActiveObject
29+
LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data)
30+
: UnitSAO(env, pos)
4231
{
43-
public:
44-
TestSAO(ServerEnvironment *env, v3f pos):
45-
ServerActiveObject(env, pos),
46-
m_timer1(0),
47-
m_age(0)
48-
{
49-
ServerActiveObject::registerType(getType(), create);
50-
}
51-
ActiveObjectType getType() const
52-
{ return ACTIVEOBJECT_TYPE_TEST; }
32+
std::string name;
33+
std::string state;
34+
u16 hp = 1;
35+
v3f velocity;
36+
v3f rotation;
5337

54-
static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
55-
const std::string &data)
56-
{
57-
return new TestSAO(env, pos);
58-
}
38+
while (!data.empty()) { // breakable, run for one iteration
39+
std::istringstream is(data, std::ios::binary);
40+
// 'version' does not allow to incrementally extend the parameter list thus
41+
// we need another variable to build on top of 'version=1'. Ugly hack but works™
42+
u8 version2 = 0;
43+
u8 version = readU8(is);
5944

60-
void step(float dtime, bool send_recommended)
61-
{
62-
m_age += dtime;
63-
if(m_age > 10)
64-
{
65-
m_pending_removal = true;
66-
return;
67-
}
45+
name = deSerializeString(is);
46+
state = deSerializeLongString(is);
6847

69-
m_base_position.Y += dtime * BS * 2;
70-
if(m_base_position.Y > 8*BS)
71-
m_base_position.Y = 2*BS;
48+
if (version < 1)
49+
break;
7250

73-
if (!send_recommended)
74-
return;
51+
hp = readU16(is);
52+
velocity = readV3F1000(is);
53+
// yaw must be yaw to be backwards-compatible
54+
rotation.Y = readF1000(is);
7555

76-
m_timer1 -= dtime;
77-
if(m_timer1 < 0.0)
78-
{
79-
m_timer1 += 0.125;
56+
if (is.good()) // EOF for old formats
57+
version2 = readU8(is);
8058

81-
std::string data;
59+
if (version2 < 1) // PROTOCOL_VERSION < 37
60+
break;
8261

83-
data += itos(0); // 0 = position
84-
data += " ";
85-
data += itos(m_base_position.X);
86-
data += " ";
87-
data += itos(m_base_position.Y);
88-
data += " ";
89-
data += itos(m_base_position.Z);
62+
// version2 >= 1
63+
rotation.X = readF1000(is);
64+
rotation.Z = readF1000(is);
9065

91-
ActiveObjectMessage aom(getId(), false, data);
92-
m_messages_out.push(aom);
93-
}
66+
// if (version2 < 2)
67+
// break;
68+
// <read new values>
69+
break;
9470
}
71+
// create object
72+
infostream << "LuaEntitySAO::create(name=\"" << name << "\" state=\""
73+
<< state << "\")" << std::endl;
9574

96-
bool getCollisionBox(aabb3f *toset) const { return false; }
97-
98-
virtual bool getSelectionBox(aabb3f *toset) const { return false; }
99-
100-
bool collideWithObjects() const { return false; }
101-
102-
private:
103-
float m_timer1;
104-
float m_age;
105-
};
106-
107-
// Prototype (registers item for deserialization)
108-
TestSAO proto_TestSAO(NULL, v3f(0,0,0));
109-
110-
/*
111-
LuaEntitySAO
112-
*/
113-
114-
// Prototype (registers item for deserialization)
115-
LuaEntitySAO proto_LuaEntitySAO(NULL, v3f(0,0,0), "_prototype", "");
116-
117-
LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos,
118-
const std::string &name, const std::string &state):
119-
UnitSAO(env, pos),
120-
m_init_name(name),
121-
m_init_state(state)
122-
{
123-
// Only register type if no environment supplied
124-
if(env == NULL){
125-
ServerActiveObject::registerType(getType(), create);
126-
return;
127-
}
75+
m_init_name = name;
76+
m_init_state = state;
77+
m_hp = hp;
78+
m_velocity = velocity;
79+
m_rotation = rotation;
12880
}
12981

13082
LuaEntitySAO::~LuaEntitySAO()
@@ -160,58 +112,6 @@ void LuaEntitySAO::addedToEnvironment(u32 dtime_s)
160112
}
161113
}
162114

163-
ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos,
164-
const std::string &data)
165-
{
166-
std::string name;
167-
std::string state;
168-
u16 hp = 1;
169-
v3f velocity;
170-
v3f rotation;
171-
172-
while (!data.empty()) { // breakable, run for one iteration
173-
std::istringstream is(data, std::ios::binary);
174-
// 'version' does not allow to incrementally extend the parameter list thus
175-
// we need another variable to build on top of 'version=1'. Ugly hack but works™
176-
u8 version2 = 0;
177-
u8 version = readU8(is);
178-
179-
name = deSerializeString(is);
180-
state = deSerializeLongString(is);
181-
182-
if (version < 1)
183-
break;
184-
185-
hp = readU16(is);
186-
velocity = readV3F1000(is);
187-
// yaw must be yaw to be backwards-compatible
188-
rotation.Y = readF1000(is);
189-
190-
if (is.good()) // EOF for old formats
191-
version2 = readU8(is);
192-
193-
if (version2 < 1) // PROTOCOL_VERSION < 37
194-
break;
195-
196-
// version2 >= 1
197-
rotation.X = readF1000(is);
198-
rotation.Z = readF1000(is);
199-
200-
// if (version2 < 2)
201-
// break;
202-
// <read new values>
203-
break;
204-
}
205-
// create object
206-
infostream << "LuaEntitySAO::create(name=\"" << name << "\" state=\""
207-
<< state << "\")" << std::endl;
208-
LuaEntitySAO *sao = new LuaEntitySAO(env, pos, name, state);
209-
sao->m_hp = hp;
210-
sao->m_velocity = velocity;
211-
sao->m_rotation = rotation;
212-
return sao;
213-
}
214-
215115
void LuaEntitySAO::step(float dtime, bool send_recommended)
216116
{
217117
if(!m_properties_sent)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
Minetest
33
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
Copyright (C) 2013-2020 Minetest core developers & community
45
56
This program is free software; you can redistribute it and/or modify
67
it under the terms of the GNU Lesser General Public License as published by
@@ -19,38 +20,32 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1920

2021
#pragma once
2122

22-
#include "network/networkprotocol.h"
23-
#include "util/numeric.h"
24-
#include "server/unit_sao.h"
25-
#include "itemgroup.h"
26-
#include "constants.h"
27-
28-
/*
29-
LuaEntitySAO needs some internals exposed.
30-
*/
23+
#include "unit_sao.h"
3124

3225
class LuaEntitySAO : public UnitSAO
3326
{
3427
public:
35-
LuaEntitySAO(ServerEnvironment *env, v3f pos,
36-
const std::string &name, const std::string &state);
28+
LuaEntitySAO() = delete;
29+
// Used by the environment to load SAO
30+
LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data);
31+
// Used by the Lua API
32+
LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &name,
33+
const std::string &state) :
34+
UnitSAO(env, pos),
35+
m_init_name(name), m_init_state(state)
36+
{
37+
}
3738
~LuaEntitySAO();
38-
ActiveObjectType getType() const
39-
{ return ACTIVEOBJECT_TYPE_LUAENTITY; }
40-
ActiveObjectType getSendType() const
41-
{ return ACTIVEOBJECT_TYPE_GENERIC; }
39+
ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_LUAENTITY; }
40+
ActiveObjectType getSendType() const { return ACTIVEOBJECT_TYPE_GENERIC; }
4241
virtual void addedToEnvironment(u32 dtime_s);
43-
static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
44-
const std::string &data);
4542
void step(float dtime, bool send_recommended);
4643
std::string getClientInitializationData(u16 protocol_version);
47-
bool isStaticAllowed() const
48-
{ return m_prop.static_save; }
44+
bool isStaticAllowed() const { return m_prop.static_save; }
4945
void getStaticData(std::string *result) const;
50-
u16 punch(v3f dir,
51-
const ToolCapabilities *toolcap = nullptr,
52-
ServerActiveObject *puncher = nullptr,
53-
float time_from_last_punch = 1000000.0f);
46+
u16 punch(v3f dir, const ToolCapabilities *toolcap = nullptr,
47+
ServerActiveObject *puncher = nullptr,
48+
float time_from_last_punch = 1000000.0f);
5449
void rightClick(ServerActiveObject *clicker);
5550
void setPos(const v3f &pos);
5651
void moveTo(v3f pos, bool continuous);
@@ -61,10 +56,7 @@ class LuaEntitySAO : public UnitSAO
6156

6257
/* LuaEntitySAO-specific */
6358
void setVelocity(v3f velocity);
64-
void addVelocity(v3f velocity)
65-
{
66-
m_velocity += velocity;
67-
}
59+
void addVelocity(v3f velocity) { m_velocity += velocity; }
6860
v3f getVelocity();
6961
void setAcceleration(v3f acceleration);
7062
v3f getAcceleration();
@@ -77,12 +69,13 @@ class LuaEntitySAO : public UnitSAO
7769
bool getCollisionBox(aabb3f *toset) const;
7870
bool getSelectionBox(aabb3f *toset) const;
7971
bool collideWithObjects() const;
72+
8073
private:
8174
std::string getPropertyPacket();
8275
void sendPosition(bool do_interpolate, bool is_movement_end);
8376
std::string generateSetTextureModCommand() const;
84-
static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames, f32 framelength,
85-
bool select_horiz_by_yawpitch);
77+
static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames,
78+
f32 framelength, bool select_horiz_by_yawpitch);
8679

8780
std::string m_init_name;
8881
std::string m_init_state;
@@ -98,4 +91,3 @@ class LuaEntitySAO : public UnitSAO
9891
float m_last_sent_move_precision = 0.0f;
9992
std::string m_current_texture_modifier = "";
10093
};
101-

‎src/server/player_sao.h

+29-54
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
Minetest
43
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.,
1918
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2019
*/
2120

21+
#pragma once
22+
2223
#include "constants.h"
2324
#include "network/networkprotocol.h"
2425
#include "unit_sao.h"
@@ -32,33 +33,31 @@ class LagPool
3233
{
3334
float m_pool = 15.0f;
3435
float m_max = 15.0f;
36+
3537
public:
3638
LagPool() = default;
3739

3840
void setMax(float new_max)
3941
{
4042
m_max = new_max;
41-
if(m_pool > new_max)
43+
if (m_pool > new_max)
4244
m_pool = new_max;
4345
}
4446

4547
void add(float dtime)
4648
{
4749
m_pool -= dtime;
48-
if(m_pool < 0)
50+
if (m_pool < 0)
4951
m_pool = 0;
5052
}
5153

52-
void empty()
53-
{
54-
m_pool = m_max;
55-
}
54+
void empty() { m_pool = m_max; }
5655

5756
bool grab(float dtime)
5857
{
59-
if(dtime <= 0)
58+
if (dtime <= 0)
6059
return true;
61-
if(m_pool + dtime > m_max)
60+
if (m_pool + dtime > m_max)
6261
return false;
6362
m_pool += dtime;
6463
return true;
@@ -73,10 +72,8 @@ class PlayerSAO : public UnitSAO
7372
PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_,
7473
bool is_singleplayer);
7574

76-
ActiveObjectType getType() const
77-
{ return ACTIVEOBJECT_TYPE_PLAYER; }
78-
ActiveObjectType getSendType() const
79-
{ return ACTIVEOBJECT_TYPE_GENERIC; }
75+
ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_PLAYER; }
76+
ActiveObjectType getSendType() const { return ACTIVEOBJECT_TYPE_GENERIC; }
8077
std::string getDescription();
8178

8279
/*
@@ -111,10 +108,8 @@ class PlayerSAO : public UnitSAO
111108
Interaction interface
112109
*/
113110

114-
u16 punch(v3f dir,
115-
const ToolCapabilities *toolcap,
116-
ServerActiveObject *puncher,
117-
float time_from_last_punch);
111+
u16 punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher,
112+
float time_from_last_punch);
118113
void rightClick(ServerActiveObject *clicker) {}
119114
void setHP(s32 hp, const PlayerHPChangeReason &reason);
120115
void setHPRaw(u16 hp) { m_hp = hp; }
@@ -144,10 +139,7 @@ class PlayerSAO : public UnitSAO
144139

145140
// Cheat prevention
146141

147-
v3f getLastGoodPosition() const
148-
{
149-
return m_last_good_position;
150-
}
142+
v3f getLastGoodPosition() const { return m_last_good_position; }
151143
float resetTimeFromLastPunch()
152144
{
153145
float r = m_time_from_last_punch;
@@ -159,30 +151,17 @@ class PlayerSAO : public UnitSAO
159151
m_nocheat_dig_pos = p;
160152
m_nocheat_dig_time = 0;
161153
}
162-
v3s16 getNoCheatDigPos()
163-
{
164-
return m_nocheat_dig_pos;
165-
}
166-
float getNoCheatDigTime()
167-
{
168-
return m_nocheat_dig_time;
169-
}
170-
void noCheatDigEnd()
171-
{
172-
m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
173-
}
174-
LagPool& getDigPool()
175-
{
176-
return m_dig_pool;
177-
}
154+
v3s16 getNoCheatDigPos() { return m_nocheat_dig_pos; }
155+
float getNoCheatDigTime() { return m_nocheat_dig_time; }
156+
void noCheatDigEnd() { m_nocheat_dig_pos = v3s16(32767, 32767, 32767); }
157+
LagPool &getDigPool() { return m_dig_pool; }
178158
void setMaxSpeedOverride(const v3f &vel);
179159
// Returns true if cheated
180160
bool checkMovementCheat();
181161

182162
// Other
183163

184-
void updatePrivileges(const std::set<std::string> &privs,
185-
bool is_singleplayer)
164+
void updatePrivileges(const std::set<std::string> &privs, bool is_singleplayer)
186165
{
187166
m_privs = privs;
188167
m_is_singleplayer = is_singleplayer;
@@ -236,6 +215,7 @@ class PlayerSAO : public UnitSAO
236215
s16 m_wanted_range = 0.0f;
237216

238217
Metadata m_meta;
218+
239219
public:
240220
float m_physics_override_speed = 1.0f;
241221
float m_physics_override_jump = 1.0f;
@@ -246,9 +226,10 @@ class PlayerSAO : public UnitSAO
246226
bool m_physics_override_sent = false;
247227
};
248228

249-
250-
struct PlayerHPChangeReason {
251-
enum Type : u8 {
229+
struct PlayerHPChangeReason
230+
{
231+
enum Type : u8
232+
{
252233
SET_HP,
253234
PLAYER_PUNCH,
254235
FALL,
@@ -266,10 +247,7 @@ struct PlayerHPChangeReason {
266247
// For NODE_DAMAGE
267248
std::string node;
268249

269-
inline bool hasLuaReference() const
270-
{
271-
return lua_reference >= 0;
272-
}
250+
inline bool hasLuaReference() const { return lua_reference >= 0; }
273251

274252
bool setTypeFromString(const std::string &typestr)
275253
{
@@ -311,15 +289,12 @@ struct PlayerHPChangeReason {
311289
}
312290
}
313291

314-
PlayerHPChangeReason(Type type):
315-
type(type)
316-
{}
292+
PlayerHPChangeReason(Type type) : type(type) {}
317293

318-
PlayerHPChangeReason(Type type, ServerActiveObject *object):
294+
PlayerHPChangeReason(Type type, ServerActiveObject *object) :
319295
type(type), object(object)
320-
{}
296+
{
297+
}
321298

322-
PlayerHPChangeReason(Type type, std::string node):
323-
type(type), node(node)
324-
{}
299+
PlayerHPChangeReason(Type type, std::string node) : type(type), node(node) {}
325300
};

‎src/server/serveractiveobject.cpp

-33
Original file line numberDiff line numberDiff line change
@@ -30,39 +30,6 @@ ServerActiveObject::ServerActiveObject(ServerEnvironment *env, v3f pos):
3030
{
3131
}
3232

33-
ServerActiveObject* ServerActiveObject::create(ActiveObjectType type,
34-
ServerEnvironment *env, u16 id, v3f pos,
35-
const std::string &data)
36-
{
37-
// Find factory function
38-
std::map<u16, Factory>::iterator n;
39-
n = m_types.find(type);
40-
if(n == m_types.end()) {
41-
// These are 0.3 entity types, return without error.
42-
if (ACTIVEOBJECT_TYPE_ITEM <= type && type <= ACTIVEOBJECT_TYPE_MOBV2) {
43-
return NULL;
44-
}
45-
46-
// If factory is not found, just return.
47-
warningstream<<"ServerActiveObject: No factory for type="
48-
<<type<<std::endl;
49-
return NULL;
50-
}
51-
52-
Factory f = n->second;
53-
ServerActiveObject *object = (*f)(env, pos, data);
54-
return object;
55-
}
56-
57-
void ServerActiveObject::registerType(u16 type, Factory f)
58-
{
59-
std::map<u16, Factory>::iterator n;
60-
n = m_types.find(type);
61-
if(n != m_types.end())
62-
return;
63-
m_types[type] = f;
64-
}
65-
6633
float ServerActiveObject::getMinimumSavedMovement()
6734
{
6835
return 2.0*BS;

‎src/server/serveractiveobject.h

-10
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,6 @@ class ServerActiveObject : public ActiveObject
244244
virtual void onAttach(int parent_id) {}
245245
virtual void onDetach(int parent_id) {}
246246

247-
// Used for creating objects based on type
248-
typedef ServerActiveObject* (*Factory)
249-
(ServerEnvironment *env, v3f pos,
250-
const std::string &data);
251-
static void registerType(u16 type, Factory f);
252-
253247
ServerEnvironment *m_env;
254248
v3f m_base_position;
255249
std::unordered_set<u32> m_attached_particle_spawners;
@@ -258,8 +252,4 @@ class ServerActiveObject : public ActiveObject
258252
Queue of messages to be sent to the client
259253
*/
260254
std::queue<ActiveObjectMessage> m_messages_out;
261-
262-
private:
263-
// Used for creating objects based on type
264-
static std::map<u16, Factory> m_types;
265255
};

‎src/serverenvironment.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
4444
#if USE_POSTGRESQL
4545
#include "database/database-postgresql.h"
4646
#endif
47+
#include "server/luaentity_sao.h"
4748
#include "server/player_sao.h"
4849

4950
#define LBM_NAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_:"
@@ -1778,6 +1779,18 @@ static void print_hexdump(std::ostream &o, const std::string &data)
17781779
}
17791780
}
17801781

1782+
ServerActiveObject* ServerEnvironment::createSAO(ActiveObjectType type, v3f pos,
1783+
const std::string &data)
1784+
{
1785+
switch (type) {
1786+
case ACTIVEOBJECT_TYPE_LUAENTITY:
1787+
return new LuaEntitySAO(this, pos, data);
1788+
default:
1789+
warningstream << "ServerActiveObject: No factory for type=" << type << std::endl;
1790+
}
1791+
return nullptr;
1792+
}
1793+
17811794
/*
17821795
Convert stored objects from blocks near the players to active.
17831796
*/
@@ -1811,10 +1824,10 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
18111824
std::vector<StaticObject> new_stored;
18121825
for (const StaticObject &s_obj : block->m_static_objects.m_stored) {
18131826
// Create an active object from the data
1814-
ServerActiveObject *obj = ServerActiveObject::create
1815-
((ActiveObjectType) s_obj.type, this, 0, s_obj.pos, s_obj.data);
1827+
ServerActiveObject *obj = createSAO((ActiveObjectType) s_obj.type, s_obj.pos,
1828+
s_obj.data);
18161829
// If couldn't create object, store static data back.
1817-
if(obj == NULL) {
1830+
if (!obj) {
18181831
errorstream<<"ServerEnvironment::activateObjects(): "
18191832
<<"failed to create active object from static object "
18201833
<<"in block "<<PP(s_obj.pos/BS)

‎src/serverenvironment.h

+2
Original file line numberDiff line numberDiff line change
@@ -468,4 +468,6 @@ class ServerEnvironment : public Environment
468468
IntervalLimiter m_particle_management_interval;
469469
std::unordered_map<u32, float> m_particle_spawners;
470470
std::unordered_map<u32, u16> m_particle_spawner_attachments;
471+
472+
ServerActiveObject* createSAO(ActiveObjectType type, v3f pos, const std::string &data);
471473
};

‎src/staticobject.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1919

2020
#include "staticobject.h"
2121
#include "util/serialize.h"
22-
#include "content_sao.h"
22+
#include "server/serveractiveobject.h"
2323

2424
StaticObject::StaticObject(const ServerActiveObject *s_obj, const v3f &pos_):
2525
type(s_obj->getType()),

‎src/unittest/test_player.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2121

2222
#include "exceptions.h"
2323
#include "remoteplayer.h"
24-
#include "content_sao.h"
2524
#include "server.h"
2625

2726
class TestPlayer : public TestBase

‎util/travis/clang-format-whitelist.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ src/content_mapblock.h
118118
src/content_mapnode.cpp
119119
src/content_nodemeta.cpp
120120
src/content_nodemeta.h
121-
src/content_sao.cpp
122-
src/content_sao.h
123121
src/convert_json.cpp
124122
src/convert_json.h
125123
src/craftdef.cpp
@@ -408,6 +406,8 @@ src/serverenvironment.h
408406
src/server.h
409407
src/serverlist.cpp
410408
src/serverlist.h
409+
src/server/luaentity_sao.cpp
410+
src/server/player_sao.cpp
411411
src/server/serveractiveobject.cpp
412412
src/server/serveractiveobject.h
413413
src/settings.cpp

0 commit comments

Comments
 (0)
Please sign in to comment.