@@ -182,7 +182,7 @@ std::vector<Player*> Environment::getPlayers(bool ignore_disconnected)
182
182
i = m_players.begin ();
183
183
i != m_players.end (); ++i) {
184
184
Player *player = *i;
185
-
185
+
186
186
if (ignore_disconnected) {
187
187
// Ignore disconnected players
188
188
if (player->peer_id == 0 )
@@ -239,7 +239,7 @@ void Environment::stepTimeOfDay(float dtime)
239
239
{
240
240
// getTimeOfDaySpeed lock the value we need to prevent MT problems
241
241
float day_speed = getTimeOfDaySpeed ();
242
-
242
+
243
243
m_time_counter += dtime;
244
244
f32 speed = day_speed * 24000 ./(24 .*3600 );
245
245
u32 units = (u32)(m_time_counter*speed);
@@ -453,41 +453,43 @@ void ServerEnvironment::savePlayer(const std::string &playername)
453
453
454
454
Player *ServerEnvironment::loadPlayer (const std::string &playername)
455
455
{
456
- std::string players_path = m_path_world + DIR_DELIM " players" DIR_DELIM;
457
-
458
- RemotePlayer *player = static_cast <RemotePlayer*>(getPlayer (playername.c_str ()));
459
456
bool newplayer = false ;
460
457
bool found = false ;
458
+ std::string players_path = m_path_world + DIR_DELIM " players" DIR_DELIM;
459
+ std::string path = players_path + playername;
460
+
461
+ RemotePlayer *player = static_cast <RemotePlayer *>(getPlayer (playername.c_str ()));
461
462
if (!player) {
462
- player = new RemotePlayer (m_gamedef, playername. c_str () );
463
+ player = new RemotePlayer (m_gamedef, " " );
463
464
newplayer = true ;
464
465
}
465
466
466
- RemotePlayer testplayer (m_gamedef, " " );
467
- std::string path = players_path + playername;
468
467
for (u32 i = 0 ; i < PLAYER_FILE_ALTERNATE_TRIES; i++) {
469
- // Open file and deserialize
468
+ // // Open file and deserialize
470
469
std::ifstream is (path.c_str (), std::ios_base::binary);
471
- if (!is.good ()) {
472
- return NULL ;
473
- }
474
- testplayer.deSerialize (is, path);
470
+ if (!is.good ())
471
+ continue ;
472
+ player->deSerialize (is, path);
475
473
is.close ();
476
- if (testplayer. getName () == playername) {
477
- * player = testplayer;
474
+
475
+ if ( player-> getName () == playername) {
478
476
found = true ;
479
477
break ;
480
478
}
479
+
481
480
path = players_path + playername + itos (i);
482
481
}
482
+
483
483
if (!found) {
484
484
infostream << " Player file for player " << playername
485
485
<< " not found" << std::endl;
486
+ if (newplayer)
487
+ delete player;
486
488
return NULL ;
487
489
}
488
- if (newplayer) {
490
+
491
+ if (newplayer)
489
492
addPlayer (player);
490
- }
491
493
player->setModified (false );
492
494
return player;
493
495
}
@@ -746,7 +748,7 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
746
748
747
749
/* infostream<<"ServerEnvironment::activateBlock(): block is "
748
750
<<dtime_s<<" seconds old."<<std::endl;*/
749
-
751
+
750
752
// Activate stored objects
751
753
activateObjects (block, dtime_s);
752
754
@@ -990,7 +992,7 @@ void ServerEnvironment::clearAllObjects()
990
992
void ServerEnvironment::step (float dtime)
991
993
{
992
994
DSTACK (__FUNCTION_NAME);
993
-
995
+
994
996
// TimeTaker timer("ServerEnv step");
995
997
996
998
/* Step time of day */
@@ -1010,7 +1012,7 @@ void ServerEnvironment::step(float dtime)
1010
1012
m_game_time += inc_i;
1011
1013
m_game_time_fraction_counter -= (float )inc_i;
1012
1014
}
1013
-
1015
+
1014
1016
/*
1015
1017
Handle players
1016
1018
*/
@@ -1020,11 +1022,11 @@ void ServerEnvironment::step(float dtime)
1020
1022
i != m_players.end (); ++i)
1021
1023
{
1022
1024
Player *player = *i;
1023
-
1025
+
1024
1026
// Ignore disconnected players
1025
1027
if (player->peer_id == 0 )
1026
1028
continue ;
1027
-
1029
+
1028
1030
// Move
1029
1031
player->move (dtime, this , 100 *BS);
1030
1032
}
@@ -1052,7 +1054,7 @@ void ServerEnvironment::step(float dtime)
1052
1054
floatToInt (player->getPosition (), BS));
1053
1055
players_blockpos.push_back (blockpos);
1054
1056
}
1055
-
1057
+
1056
1058
/*
1057
1059
Update list of active blocks, collecting changes
1058
1060
*/
@@ -1068,7 +1070,7 @@ void ServerEnvironment::step(float dtime)
1068
1070
1069
1071
// Convert active objects that are no more in active blocks to static
1070
1072
deactivateFarObjects (false );
1071
-
1073
+
1072
1074
for (std::set<v3s16>::iterator
1073
1075
i = blocks_removed.begin ();
1074
1076
i != blocks_removed.end (); ++i)
@@ -1077,11 +1079,11 @@ void ServerEnvironment::step(float dtime)
1077
1079
1078
1080
/* infostream<<"Server: Block " << PP(p)
1079
1081
<< " became inactive"<<std::endl; */
1080
-
1082
+
1081
1083
MapBlock *block = m_map->getBlockNoCreateNoEx (p);
1082
1084
if (block==NULL )
1083
1085
continue ;
1084
-
1086
+
1085
1087
// Set current time as timestamp (and let it set ChangedFlag)
1086
1088
block->setTimestamp (m_game_time);
1087
1089
}
@@ -1114,15 +1116,15 @@ void ServerEnvironment::step(float dtime)
1114
1116
if (m_active_blocks_nodemetadata_interval.step (dtime, 1.0 ))
1115
1117
{
1116
1118
ScopeProfiler sp (g_profiler, " SEnv: mess in act. blocks avg /1s" , SPT_AVG);
1117
-
1119
+
1118
1120
float dtime = 1.0 ;
1119
1121
1120
1122
for (std::set<v3s16>::iterator
1121
1123
i = m_active_blocks.m_list .begin ();
1122
1124
i != m_active_blocks.m_list .end (); ++i)
1123
1125
{
1124
1126
v3s16 p = *i;
1125
-
1127
+
1126
1128
/* infostream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
1127
1129
<<") being handled"<<std::endl;*/
1128
1130
@@ -1132,7 +1134,7 @@ void ServerEnvironment::step(float dtime)
1132
1134
1133
1135
// Reset block usage timer
1134
1136
block->resetUsageTimer ();
1135
-
1137
+
1136
1138
// Set current time as timestamp
1137
1139
block->setTimestampNoChangedFlag (m_game_time);
1138
1140
// If time has changed much from the one on disk,
@@ -1157,7 +1159,7 @@ void ServerEnvironment::step(float dtime)
1157
1159
}
1158
1160
}
1159
1161
}
1160
-
1162
+
1161
1163
const float abm_interval = 1.0 ;
1162
1164
if (m_active_block_modifier_interval.step (dtime, abm_interval))
1163
1165
do { // breakable
@@ -1168,7 +1170,7 @@ void ServerEnvironment::step(float dtime)
1168
1170
}
1169
1171
ScopeProfiler sp (g_profiler, " SEnv: modify in blocks avg /1s" , SPT_AVG);
1170
1172
TimeTaker timer (" modify in active blocks" );
1171
-
1173
+
1172
1174
// Initialize handling of ActiveBlockModifiers
1173
1175
ABMHandler abmhandler (m_abms, abm_interval, this , true );
1174
1176
@@ -1177,14 +1179,14 @@ void ServerEnvironment::step(float dtime)
1177
1179
i != m_active_blocks.m_list .end (); ++i)
1178
1180
{
1179
1181
v3s16 p = *i;
1180
-
1182
+
1181
1183
/* infostream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
1182
1184
<<") being handled"<<std::endl;*/
1183
1185
1184
1186
MapBlock *block = m_map->getBlockNoCreateNoEx (p);
1185
1187
if (block == NULL )
1186
1188
continue ;
1187
-
1189
+
1188
1190
// Set current time as timestamp
1189
1191
block->setTimestampNoChangedFlag (m_game_time);
1190
1192
@@ -1201,7 +1203,7 @@ void ServerEnvironment::step(float dtime)
1201
1203
m_active_block_interval_overload_skip = (time_ms / max_time_ms) + 1 ;
1202
1204
}
1203
1205
}while (0 );
1204
-
1206
+
1205
1207
/*
1206
1208
Step script environment (run global on_step())
1207
1209
*/
@@ -1215,7 +1217,7 @@ void ServerEnvironment::step(float dtime)
1215
1217
// TimeTaker timer("Step active objects");
1216
1218
1217
1219
g_profiler->avg (" SEnv: num of objects" , m_active_objects.size ());
1218
-
1220
+
1219
1221
// This helps the objects to send data at the same time
1220
1222
bool send_recommended = false ;
1221
1223
m_send_recommended_timer += dtime;
@@ -1244,7 +1246,7 @@ void ServerEnvironment::step(float dtime)
1244
1246
}
1245
1247
}
1246
1248
}
1247
-
1249
+
1248
1250
/*
1249
1251
Manage active objects
1250
1252
*/
@@ -1287,7 +1289,7 @@ u16 getFreeServerActiveObjectId(
1287
1289
last_used_id ++;
1288
1290
if (isFreeServerActiveObjectId (last_used_id, objects))
1289
1291
return last_used_id;
1290
-
1292
+
1291
1293
if (last_used_id == startid)
1292
1294
return 0 ;
1293
1295
}
@@ -1443,7 +1445,7 @@ void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius,
1443
1445
removed_objects.insert (id);
1444
1446
continue ;
1445
1447
}
1446
-
1448
+
1447
1449
f32 distance_f = object->getBasePosition ().getDistanceFrom (pos_f);
1448
1450
if (object->getType () == ACTIVEOBJECT_TYPE_PLAYER) {
1449
1451
if (distance_f <= player_radius_f || player_radius_f == 0 )
@@ -1460,7 +1462,7 @@ ActiveObjectMessage ServerEnvironment::getActiveObjectMessage()
1460
1462
{
1461
1463
if (m_active_object_messages.empty ())
1462
1464
return ActiveObjectMessage (0 );
1463
-
1465
+
1464
1466
ActiveObjectMessage message = m_active_object_messages.front ();
1465
1467
m_active_object_messages.pop_front ();
1466
1468
return message;
@@ -1500,19 +1502,19 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
1500
1502
}
1501
1503
/* infostream<<"ServerEnvironment::addActiveObjectRaw(): "
1502
1504
<<"added (id="<<object->getId()<<")"<<std::endl;*/
1503
-
1505
+
1504
1506
m_active_objects[object->getId ()] = object;
1505
-
1507
+
1506
1508
verbosestream<<" ServerEnvironment::addActiveObjectRaw(): "
1507
1509
<<" Added id=" <<object->getId ()<<" ; there are now "
1508
1510
<<m_active_objects.size ()<<" active objects."
1509
1511
<<std::endl;
1510
-
1512
+
1511
1513
// Register reference in scripting api (must be done before post-init)
1512
1514
m_script->addObjectReference (object);
1513
1515
// Post-initialize object
1514
1516
object->addedToEnvironment (dtime_s);
1515
-
1517
+
1516
1518
// Add static data to block
1517
1519
if (object->isStaticAllowed ())
1518
1520
{
@@ -1538,7 +1540,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
1538
1540
<<" statically (pos=" <<PP (p)<<" )" <<std::endl;
1539
1541
}
1540
1542
}
1541
-
1543
+
1542
1544
return object->getId ();
1543
1545
}
1544
1546
@@ -1712,7 +1714,7 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
1712
1714
<<" in block " <<PP (s_obj.pos /BS)
1713
1715
<<" type=" <<(int )s_obj.type <<" data:" <<std::endl;
1714
1716
print_hexdump (verbosestream, s_obj.data );
1715
-
1717
+
1716
1718
new_stored.push_back (s_obj);
1717
1719
continue ;
1718
1720
}
@@ -1773,7 +1775,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
1773
1775
i != m_active_objects.end (); ++i) {
1774
1776
ServerActiveObject* obj = i->second ;
1775
1777
assert (obj);
1776
-
1778
+
1777
1779
// Do not deactivate if static data creation not allowed
1778
1780
if (!force_delete && !obj->isStaticAllowed ())
1779
1781
continue ;
@@ -1849,7 +1851,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
1849
1851
// Create new static object
1850
1852
std::string staticdata_new = obj->getStaticData ();
1851
1853
StaticObject s_obj (obj->getType (), objectpos, staticdata_new);
1852
-
1854
+
1853
1855
bool stays_in_same_block = false ;
1854
1856
bool data_changed = true ;
1855
1857
@@ -1858,7 +1860,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
1858
1860
stays_in_same_block = true ;
1859
1861
1860
1862
MapBlock *block = m_map->emergeBlock (obj->m_static_block , false );
1861
-
1863
+
1862
1864
std::map<u16, StaticObject>::iterator n =
1863
1865
block->m_static_objects .m_active .find (id);
1864
1866
if (n != block->m_static_objects .m_active .end ()){
@@ -1878,7 +1880,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
1878
1880
}
1879
1881
1880
1882
bool shall_be_written = (!stays_in_same_block || data_changed);
1881
-
1883
+
1882
1884
// Delete old static object
1883
1885
if (obj->m_static_exists )
1884
1886
{
@@ -1933,13 +1935,13 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
1933
1935
// Store static data
1934
1936
u16 store_id = pending_delete ? id : 0 ;
1935
1937
block->m_static_objects .insert (store_id, s_obj);
1936
-
1938
+
1937
1939
// Only mark block as modified if data changed considerably
1938
1940
if (shall_be_written)
1939
1941
block->raiseModified (MOD_STATE_WRITE_NEEDED,
1940
1942
" deactivateFarObjects: Static data "
1941
1943
" changed considerably" );
1942
-
1944
+
1943
1945
obj->m_static_exists = true ;
1944
1946
obj->m_static_block = block->getPos ();
1945
1947
}
@@ -1969,7 +1971,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
1969
1971
obj->m_pending_deactivation = true ;
1970
1972
continue ;
1971
1973
}
1972
-
1974
+
1973
1975
verbosestream<<" ServerEnvironment::deactivateFarObjects(): "
1974
1976
<<" object id=" <<id<<" is not known by clients"
1975
1977
<<" ; deleting" <<std::endl;
@@ -2084,14 +2086,14 @@ void ClientEnvironment::step(float dtime)
2084
2086
assert (lplayer);
2085
2087
// collision info queue
2086
2088
std::vector<CollisionInfo> player_collisions;
2087
-
2089
+
2088
2090
/*
2089
2091
Get the speed the player is going
2090
2092
*/
2091
2093
bool is_climbing = lplayer->is_climbing ;
2092
-
2094
+
2093
2095
f32 player_speed = lplayer->getSpeed ().getLength ();
2094
-
2096
+
2095
2097
/*
2096
2098
Maximum position increment
2097
2099
*/
@@ -2103,15 +2105,15 @@ void ClientEnvironment::step(float dtime)
2103
2105
f32 dtime_max_increment = 1 ;
2104
2106
if (player_speed > 0.001 )
2105
2107
dtime_max_increment = position_max_increment / player_speed;
2106
-
2108
+
2107
2109
// Maximum time increment is 10ms or lower
2108
2110
if (dtime_max_increment > 0.01 )
2109
2111
dtime_max_increment = 0.01 ;
2110
-
2112
+
2111
2113
// Don't allow overly huge dtime
2112
2114
if (dtime > 0.5 )
2113
2115
dtime = 0.5 ;
2114
-
2116
+
2115
2117
f32 dtime_downcount = dtime;
2116
2118
2117
2119
/*
@@ -2139,11 +2141,11 @@ void ClientEnvironment::step(float dtime)
2139
2141
*/
2140
2142
dtime_downcount = 0 ;
2141
2143
}
2142
-
2144
+
2143
2145
/*
2144
2146
Handle local player
2145
2147
*/
2146
-
2148
+
2147
2149
{
2148
2150
// Apply physics
2149
2151
if (free_move == false && is_climbing == false )
@@ -2169,10 +2171,10 @@ void ClientEnvironment::step(float dtime)
2169
2171
if (dl > lplayer->movement_liquid_fluidity_smooth )
2170
2172
dl = lplayer->movement_liquid_fluidity_smooth ;
2171
2173
dl *= (lplayer->liquid_viscosity * viscosity_factor) + (1 - viscosity_factor);
2172
-
2174
+
2173
2175
v3f d = d_wanted.normalize () * dl;
2174
2176
speed += d;
2175
-
2177
+
2176
2178
#if 0 // old code
2177
2179
if(speed.X > lplayer->movement_liquid_fluidity + lplayer->movement_liquid_fluidity_smooth) speed.X -= lplayer->movement_liquid_fluidity_smooth;
2178
2180
if(speed.X < -lplayer->movement_liquid_fluidity - lplayer->movement_liquid_fluidity_smooth) speed.X += lplayer->movement_liquid_fluidity_smooth;
@@ -2195,9 +2197,9 @@ void ClientEnvironment::step(float dtime)
2195
2197
}
2196
2198
}
2197
2199
while (dtime_downcount > 0.001 );
2198
-
2200
+
2199
2201
// std::cout<<"Looped "<<loopcount<<" times."<<std::endl;
2200
-
2202
+
2201
2203
for (std::vector<CollisionInfo>::iterator i = player_collisions.begin ();
2202
2204
i != player_collisions.end (); ++i) {
2203
2205
CollisionInfo &info = *i;
@@ -2232,14 +2234,14 @@ void ClientEnvironment::step(float dtime)
2232
2234
}
2233
2235
}
2234
2236
}
2235
-
2237
+
2236
2238
/*
2237
2239
A quick draft of lava damage
2238
2240
*/
2239
2241
if (m_lava_hurt_interval.step (dtime, 1.0 ))
2240
2242
{
2241
2243
v3f pf = lplayer->getPosition ();
2242
-
2244
+
2243
2245
// Feet, middle and head
2244
2246
v3s16 p1 = floatToInt (pf + v3f (0 , BS*0.1 , 0 ), BS);
2245
2247
MapNode n1 = m_map->getNodeNoEx (p1);
@@ -2255,7 +2257,7 @@ void ClientEnvironment::step(float dtime)
2255
2257
m_gamedef->ndef ()->get (n2).damage_per_second );
2256
2258
damage_per_second = MYMAX (damage_per_second,
2257
2259
m_gamedef->ndef ()->get (n3).damage_per_second );
2258
-
2260
+
2259
2261
if (damage_per_second != 0 )
2260
2262
{
2261
2263
damageLocalPlayer (damage_per_second, true );
@@ -2317,7 +2319,7 @@ void ClientEnvironment::step(float dtime)
2317
2319
for (std::vector<Player*>::iterator i = m_players.begin ();
2318
2320
i != m_players.end (); ++i) {
2319
2321
Player *player = *i;
2320
-
2322
+
2321
2323
/*
2322
2324
Handle non-local players
2323
2325
*/
@@ -2349,7 +2351,7 @@ void ClientEnvironment::step(float dtime)
2349
2351
/*
2350
2352
Step active objects and update lighting of them
2351
2353
*/
2352
-
2354
+
2353
2355
g_profiler->avg (" CEnv: num of objects" , m_active_objects.size ());
2354
2356
bool update_lighting = m_active_object_light_update_interval.step (dtime, 0.21 );
2355
2357
for (std::map<u16, ClientActiveObject*>::iterator
@@ -2397,7 +2399,7 @@ void ClientEnvironment::step(float dtime)
2397
2399
}
2398
2400
}
2399
2401
}
2400
-
2402
+
2401
2403
void ClientEnvironment::addSimpleObject (ClientSimpleObject *simple)
2402
2404
{
2403
2405
m_simple_objects.push_back (simple);
@@ -2432,7 +2434,7 @@ u16 getFreeClientActiveObjectId(
2432
2434
last_used_id ++;
2433
2435
if (isFreeClientActiveObjectId (last_used_id, objects))
2434
2436
return last_used_id;
2435
-
2437
+
2436
2438
if (last_used_id == startid)
2437
2439
return 0 ;
2438
2440
}
@@ -2493,7 +2495,7 @@ void ClientEnvironment::addActiveObject(u16 id, u8 type,
2493
2495
<<std::endl;
2494
2496
return ;
2495
2497
}
2496
-
2498
+
2497
2499
obj->setId (id);
2498
2500
2499
2501
try
@@ -2588,7 +2590,7 @@ void ClientEnvironment::updateLocalPlayerBreath(u16 breath)
2588
2590
/*
2589
2591
Client likes to call these
2590
2592
*/
2591
-
2593
+
2592
2594
void ClientEnvironment::getActiveObjects (v3f origin, f32 max_d,
2593
2595
std::vector<DistanceSortedActiveObject> &dest)
2594
2596
{
0 commit comments