mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-06 17:41:04 +00:00
Working version before block send priorization update
This commit is contained in:
parent
4e249fb3fb
commit
24c4b7c68d
17 changed files with 716 additions and 200 deletions
|
@ -14,10 +14,6 @@
|
|||
#define sleep_ms(x) usleep(x*1000)
|
||||
#endif
|
||||
|
||||
/*
|
||||
FIXME: This thread can access the environment at any time
|
||||
*/
|
||||
|
||||
void * ClientUpdateThread::Thread()
|
||||
{
|
||||
ThreadStarted();
|
||||
|
@ -144,6 +140,22 @@ void Client::step(float dtime)
|
|||
m_con.RunTimeouts(dtime);
|
||||
}
|
||||
|
||||
/*
|
||||
Packet counter
|
||||
*/
|
||||
{
|
||||
static float counter = -0.001;
|
||||
counter -= dtime;
|
||||
if(counter <= 0.0)
|
||||
{
|
||||
counter = 10.0;
|
||||
|
||||
dout_client<<"Client packetcounter:"<<std::endl;
|
||||
m_packetcounter.print(dout_client);
|
||||
m_packetcounter.clear();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
/*
|
||||
Delete unused sectors
|
||||
|
@ -171,7 +183,9 @@ void Client::step(float dtime)
|
|||
|
||||
if(num > 0)
|
||||
{
|
||||
dstream<<DTIME<<"Client: Deleted blocks of "<<num
|
||||
/*dstream<<DTIME<<"Client: Deleted blocks of "<<num
|
||||
<<" unused sectors"<<std::endl;*/
|
||||
dstream<<DTIME<<"Client: Deleted "<<num
|
||||
<<" unused sectors"<<std::endl;
|
||||
|
||||
/*
|
||||
|
@ -433,11 +447,18 @@ void Client::Receive()
|
|||
void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
||||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
|
||||
// Ignore packets that don't even fit a command
|
||||
if(datasize < 2)
|
||||
{
|
||||
m_packetcounter.add(60000);
|
||||
return;
|
||||
}
|
||||
|
||||
ToClientCommand command = (ToClientCommand)readU16(&data[0]);
|
||||
|
||||
//dstream<<"Client: received command="<<command<<std::endl;
|
||||
m_packetcounter.add((u16)command);
|
||||
|
||||
/*
|
||||
If this check is removed, be sure to change the queue
|
||||
|
|
|
@ -266,6 +266,8 @@ private:
|
|||
bool m_inventory_updated;
|
||||
|
||||
core::map<v3s16, bool> m_active_blocks;
|
||||
|
||||
PacketCounter m_packetcounter;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
enum ToClientCommand
|
||||
{
|
||||
TOCLIENT_INIT=0x10,
|
||||
TOCLIENT_INIT = 0x10,
|
||||
/*
|
||||
Server's reply to TOSERVER_INIT.
|
||||
Sent second after connected.
|
||||
|
@ -15,11 +15,11 @@ enum ToClientCommand
|
|||
[3] v3s16 player's position + v3f(0,BS/2,0) floatToInt'd
|
||||
*/
|
||||
|
||||
TOCLIENT_BLOCKDATA=0x20, //TODO: Multiple blocks
|
||||
TOCLIENT_ADDNODE,
|
||||
TOCLIENT_REMOVENODE,
|
||||
TOCLIENT_BLOCKDATA = 0x20, //TODO: Multiple blocks
|
||||
TOCLIENT_ADDNODE = 0x21,
|
||||
TOCLIENT_REMOVENODE = 0x22,
|
||||
|
||||
TOCLIENT_PLAYERPOS,
|
||||
TOCLIENT_PLAYERPOS = 0x23,
|
||||
/*
|
||||
[0] u16 command
|
||||
// Followed by an arbitary number of these:
|
||||
|
@ -31,7 +31,7 @@ enum ToClientCommand
|
|||
[N+2+12+12+4] s32 yaw*100
|
||||
*/
|
||||
|
||||
TOCLIENT_PLAYERINFO,
|
||||
TOCLIENT_PLAYERINFO = 0x24,
|
||||
/*
|
||||
[0] u16 command
|
||||
// Followed by an arbitary number of these:
|
||||
|
@ -40,22 +40,22 @@ enum ToClientCommand
|
|||
[N] char[20] name
|
||||
*/
|
||||
|
||||
TOCLIENT_OPT_BLOCK_NOT_FOUND, // Not used
|
||||
TOCLIENT_OPT_BLOCK_NOT_FOUND = 0x25, // Not used
|
||||
|
||||
TOCLIENT_SECTORMETA,
|
||||
TOCLIENT_SECTORMETA = 0x26, // Not used
|
||||
/*
|
||||
[0] u16 command
|
||||
[2] u8 sector count
|
||||
[3...] v2s16 pos + sector metadata
|
||||
*/
|
||||
|
||||
TOCLIENT_INVENTORY,
|
||||
TOCLIENT_INVENTORY = 0x27,
|
||||
/*
|
||||
[0] u16 command
|
||||
[2] serialized inventory
|
||||
*/
|
||||
|
||||
TOCLIENT_OBJECTDATA,
|
||||
TOCLIENT_OBJECTDATA = 0x28,
|
||||
/*
|
||||
Sent as unreliable.
|
||||
|
||||
|
@ -84,7 +84,7 @@ enum ToServerCommand
|
|||
[3] u8[20] player_name
|
||||
*/
|
||||
|
||||
TOSERVER_INIT2,
|
||||
TOSERVER_INIT2 = 0x11,
|
||||
/*
|
||||
Sent as an ACK for TOCLIENT_INIT.
|
||||
After this, the server can send data.
|
||||
|
@ -93,10 +93,10 @@ enum ToServerCommand
|
|||
*/
|
||||
|
||||
TOSERVER_GETBLOCK=0x20, // Not used
|
||||
TOSERVER_ADDNODE, // Not used
|
||||
TOSERVER_REMOVENODE, // deprecated
|
||||
TOSERVER_ADDNODE = 0x21, // Not used
|
||||
TOSERVER_REMOVENODE = 0x22, // deprecated
|
||||
|
||||
TOSERVER_PLAYERPOS,
|
||||
TOSERVER_PLAYERPOS = 0x23,
|
||||
/*
|
||||
[0] u16 command
|
||||
[2] v3s32 position*100
|
||||
|
@ -105,7 +105,7 @@ enum ToServerCommand
|
|||
[2+12+12+4] s32 yaw*100
|
||||
*/
|
||||
|
||||
TOSERVER_GOTBLOCKS,
|
||||
TOSERVER_GOTBLOCKS = 0x24,
|
||||
/*
|
||||
[0] u16 command
|
||||
[2] u8 count
|
||||
|
@ -114,7 +114,7 @@ enum ToServerCommand
|
|||
...
|
||||
*/
|
||||
|
||||
TOSERVER_DELETEDBLOCKS,
|
||||
TOSERVER_DELETEDBLOCKS = 0x25,
|
||||
/*
|
||||
[0] u16 command
|
||||
[2] u8 count
|
||||
|
@ -123,14 +123,14 @@ enum ToServerCommand
|
|||
...
|
||||
*/
|
||||
|
||||
TOSERVER_ADDNODE_FROM_INVENTORY, // deprecated
|
||||
TOSERVER_ADDNODE_FROM_INVENTORY = 0x26, // deprecated
|
||||
/*
|
||||
[0] u16 command
|
||||
[2] v3s16 pos
|
||||
[8] u16 i
|
||||
*/
|
||||
|
||||
TOSERVER_CLICK_OBJECT,
|
||||
TOSERVER_CLICK_OBJECT = 0x27,
|
||||
/*
|
||||
length: 13
|
||||
[0] u16 command
|
||||
|
@ -140,7 +140,7 @@ enum ToServerCommand
|
|||
[11] u16 item
|
||||
*/
|
||||
|
||||
TOSERVER_CLICK_GROUND,
|
||||
TOSERVER_CLICK_GROUND = 0x28,
|
||||
/*
|
||||
length: 17
|
||||
[0] u16 command
|
||||
|
@ -150,14 +150,14 @@ enum ToServerCommand
|
|||
[15] u16 item
|
||||
*/
|
||||
|
||||
TOSERVER_RELEASE,
|
||||
TOSERVER_RELEASE = 0x29,
|
||||
/*
|
||||
length: 3
|
||||
[0] u16 command
|
||||
[2] u8 button
|
||||
*/
|
||||
|
||||
TOSERVER_SIGNTEXT,
|
||||
TOSERVER_SIGNTEXT = 0x30,
|
||||
/*
|
||||
u16 command
|
||||
v3s16 blockpos
|
||||
|
|
|
@ -23,9 +23,6 @@
|
|||
#define SERVERMAP_DELETE_UNUSED_SECTORS_TIMEOUT (60*10)
|
||||
#define SERVER_MAP_SAVE_INTERVAL (60)
|
||||
|
||||
//#define SERVERMAP_DELETE_UNUSED_SECTORS_TIMEOUT (5)
|
||||
//#define SERVER_MAP_SAVE_INTERVAL (5)
|
||||
|
||||
#define FOV_ANGLE (PI/2.5)
|
||||
|
||||
// The absolute working limit is (2^15 - viewing_range).
|
||||
|
@ -44,29 +41,29 @@
|
|||
#define FPS_DEFAULT_WANTED 30
|
||||
#define FPS_DEFAULT_MAX 60
|
||||
|
||||
#define FORCEDFETCH_RANGE 80
|
||||
|
||||
#define HEIGHTMAP_RANGE_NODES 300
|
||||
|
||||
// The freetime ratio is dynamically kept high enough to make this
|
||||
// dtime jitter possible
|
||||
// Allow 50% = 0.1
|
||||
/*#define DTIME_JITTER_MAX_FRACTION 0.5
|
||||
#define FREETIME_RATIO_MIN 0.05
|
||||
#define FREETIME_RATIO_MAX 0.4*/
|
||||
|
||||
//#define FREETIME_RATIO 0.2
|
||||
#define FREETIME_RATIO 0.15
|
||||
|
||||
// Sectors are split to SECTOR_HEIGHTMAP_SPLIT^2 heightmaps
|
||||
#define SECTOR_HEIGHTMAP_SPLIT 2
|
||||
|
||||
#define PLAYER_INVENTORY_SIZE (8*4)
|
||||
|
||||
#define SIGN_TEXT_MAX_LENGTH 50
|
||||
|
||||
#define ACTIVE_OBJECT_D_BLOCKS 2
|
||||
// The distance of how far objects will be sent to client
|
||||
//#define ACTIVE_OBJECT_D_BLOCKS 2
|
||||
|
||||
// Wether to catch all std::exceptions
|
||||
#define CATCH_UNJANDLED_EXCEPTIONS 1
|
||||
|
||||
/*
|
||||
Collecting active blocks is stopped after object data
|
||||
size reaches this
|
||||
*/
|
||||
#define MAX_OBJECTDATA_SIZE 450
|
||||
|
||||
#endif
|
||||
|
||||
|
|
57
src/debug.h
57
src/debug.h
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
Debug stack and assertion
|
||||
Debug stuff
|
||||
*/
|
||||
|
||||
#ifndef DEBUG_HEADER
|
||||
|
@ -172,5 +172,58 @@ private:
|
|||
DEBUG_STACK_TEXT_SIZE, __VA_ARGS__);\
|
||||
DebugStacker __debug_stacker(__buf);
|
||||
|
||||
#endif
|
||||
/*
|
||||
Packet counter
|
||||
*/
|
||||
|
||||
class PacketCounter
|
||||
{
|
||||
public:
|
||||
PacketCounter()
|
||||
{
|
||||
}
|
||||
|
||||
void add(u16 command)
|
||||
{
|
||||
core::map<u16, u16>::Node *n = m_packets.find(command);
|
||||
if(n == NULL)
|
||||
{
|
||||
m_packets[command] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
n->setValue(n->getValue()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
for(core::map<u16, u16>::Iterator
|
||||
i = m_packets.getIterator();
|
||||
i.atEnd() == false; i++)
|
||||
{
|
||||
i.getNode()->setValue(0);
|
||||
}
|
||||
}
|
||||
|
||||
void print(std::ostream &o)
|
||||
{
|
||||
for(core::map<u16, u16>::Iterator
|
||||
i = m_packets.getIterator();
|
||||
i.atEnd() == false; i++)
|
||||
{
|
||||
o<<"cmd "<<i.getNode()->getKey()
|
||||
<<" count "<<i.getNode()->getValue()
|
||||
<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// command, count
|
||||
core::map<u16, u16> m_packets;
|
||||
};
|
||||
|
||||
|
||||
#endif // DEBUG_HEADER
|
||||
|
||||
|
||||
|
|
112
src/main.cpp
112
src/main.cpp
|
@ -1,7 +1,24 @@
|
|||
/*
|
||||
(c) 2010 Perttu Ahola <celeron55@gmail.com>
|
||||
Minetest-c55
|
||||
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
|
||||
Minetest
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(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
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
=============================== NOTES ==============================
|
||||
|
||||
NOTE: VBO cannot be turned on for fast-changing stuff because there
|
||||
is an apparanet memory leak in irrlicht when using it
|
||||
|
@ -137,43 +154,39 @@ TODO: Make fetching sector's blocks more efficient when rendering
|
|||
|
||||
TODO: Make the video backend selectable
|
||||
|
||||
TODO: A timestamp to blocks
|
||||
|
||||
TODO: Client side:
|
||||
- The server sends all active objects of the active blocks
|
||||
at constant intervals. They should fit in a few packets.
|
||||
- The client keeps track of what blocks at the moment are
|
||||
having active objects in them.
|
||||
- All blocks going in and out of the active buffer are recorded.
|
||||
- For outgoing blocks, objects are removed from the blocks
|
||||
and from the scene
|
||||
- For incoming blocks, objects are added to the blocks and
|
||||
to the scene.
|
||||
|
||||
TODO: Server side:
|
||||
Block object server side:
|
||||
- A "near blocks" buffer, in which some nearby blocks are stored.
|
||||
- For all blocks in the buffer, objects are stepped(). This
|
||||
means they are active.
|
||||
- All blocks going in and out of the buffer are recorded.
|
||||
- For outgoing blocks, a timestamp is written.
|
||||
- For incoming blocks, the time difference is calculated and
|
||||
- TODO All blocks going in and out of the buffer are recorded.
|
||||
- TODO For outgoing blocks, a timestamp is written.
|
||||
- TODO For incoming blocks, the time difference is calculated and
|
||||
objects are stepped according to it.
|
||||
TODO: A timestamp to blocks
|
||||
|
||||
TODO: Add config parameters for server's sending and generating distance
|
||||
|
||||
TODO: Make amount of trees and other plants configurable
|
||||
- Save to a metafile
|
||||
|
||||
TODO: Copy the text of the last picked sign to inventory in creative
|
||||
mode
|
||||
|
||||
TODO: Untie client network operations from framerate
|
||||
|
||||
TODO: Make a copy of close-range environment on client for showing
|
||||
SUGG: Make a copy of close-range environment on client for showing
|
||||
on screen, with minimal mutexes to slow the main loop down
|
||||
|
||||
TODO: Make a PACKET_COMBINED which contains many subpackets. Utilize
|
||||
SUGG: Make a PACKET_COMBINED which contains many subpackets. Utilize
|
||||
it by sending more stuff in a single packet.
|
||||
- Add a packet queue to RemoteClient, from which packets will be
|
||||
combined with object data packets
|
||||
- This is not exactly trivial: the object data packets are
|
||||
sometimes very big by themselves
|
||||
|
||||
SUGG: Split MapBlockObject serialization to to-client and to-disk
|
||||
- This will allow saving ages of rats on disk but not sending
|
||||
them to clients
|
||||
|
||||
TODO: Fix the long-lived Server Block Emerge Jam bug
|
||||
- Is it related to the client deleting blocks?
|
||||
|
||||
Doing now:
|
||||
======================================================================
|
||||
|
@ -261,10 +274,6 @@ video::SMaterial g_materials[MATERIALS_COUNT];
|
|||
// All range-related stuff below is locked behind this
|
||||
JMutex g_range_mutex;
|
||||
|
||||
// Blocks are generated in this range from the player
|
||||
// This is limited vertically to half by Client::fetchBlocks()
|
||||
s16 g_forcedfetch_range_nodes = FORCEDFETCH_RANGE;
|
||||
|
||||
// Blocks are viewed in this range from the player
|
||||
s16 g_viewing_range_nodes = 60;
|
||||
|
||||
|
@ -305,7 +314,10 @@ float g_client_delete_unused_sectors_timeout = 1200;
|
|||
|
||||
// Server stuff
|
||||
bool g_creative_mode = false;
|
||||
MapgenParams g_mapgen_params;
|
||||
HMParams g_hm_params;
|
||||
MapParams g_map_params;
|
||||
float g_objectdata_interval = 0.2;
|
||||
u16 g_active_object_range = 2;
|
||||
|
||||
/*
|
||||
Random stuff
|
||||
|
@ -395,21 +407,11 @@ bool parseConfigObject(std::istream &is)
|
|||
}
|
||||
else if(name == "viewing_range_nodes_max")
|
||||
{
|
||||
s32 v = atoi(value.c_str());
|
||||
if(v < 0)
|
||||
v = 0;
|
||||
if(v > 32767)
|
||||
v = 32767;
|
||||
g_viewing_range_nodes_max = v;
|
||||
g_viewing_range_nodes_max = stoi(value, 0, 32767);
|
||||
}
|
||||
else if(name == "viewing_range_nodes_min")
|
||||
{
|
||||
s32 v = atoi(value.c_str());
|
||||
if(v < 0)
|
||||
v = 0;
|
||||
if(v > 32767)
|
||||
v = 32767;
|
||||
g_viewing_range_nodes_min = v;
|
||||
g_viewing_range_nodes_min = stoi(value, 0, 32767);
|
||||
}
|
||||
else if(name=="screenW")
|
||||
g_screenW = value;
|
||||
|
@ -439,19 +441,29 @@ bool parseConfigObject(std::istream &is)
|
|||
{
|
||||
s32 d = atoi(value.c_str());
|
||||
if(d > 0 && (d & (d-1)) == 0)
|
||||
g_mapgen_params.heightmap_blocksize = d;
|
||||
g_hm_params.heightmap_blocksize = d;
|
||||
else
|
||||
dstream<<"Invalid value in config file: \""
|
||||
<<line<<"\""<<std::endl;
|
||||
}
|
||||
else if(name == "mapgen_height_randmax")
|
||||
g_mapgen_params.height_randmax = value;
|
||||
g_hm_params.height_randmax = value;
|
||||
else if(name == "mapgen_height_randfactor")
|
||||
g_mapgen_params.height_randfactor = value;
|
||||
g_hm_params.height_randfactor = value;
|
||||
else if(name == "mapgen_height_base")
|
||||
g_mapgen_params.height_base = value;
|
||||
g_hm_params.height_base = value;
|
||||
else if(name == "mapgen_plants_amount")
|
||||
g_mapgen_params.plants_amount = value;
|
||||
{
|
||||
std::istringstream vis(value);
|
||||
vis>>g_map_params.plants_amount;
|
||||
}
|
||||
else if(name == "objectdata_inverval")
|
||||
{
|
||||
std::istringstream vis(value);
|
||||
vis>>g_objectdata_interval;
|
||||
}
|
||||
else if(name == "active_object_range")
|
||||
g_active_object_range = stoi(value, 0, 65535);
|
||||
|
||||
else
|
||||
{
|
||||
|
@ -1161,7 +1173,9 @@ int main(int argc, char *argv[])
|
|||
std::cout<<"========================"<<std::endl;
|
||||
std::cout<<std::endl;
|
||||
|
||||
Server server("../map", g_creative_mode, g_mapgen_params);
|
||||
Server server("../map", g_creative_mode, g_hm_params,
|
||||
g_map_params, g_objectdata_interval,
|
||||
g_active_object_range);
|
||||
server.start(port);
|
||||
|
||||
for(;;)
|
||||
|
@ -1429,7 +1443,9 @@ int main(int argc, char *argv[])
|
|||
*/
|
||||
SharedPtr<Server> server;
|
||||
if(hosting){
|
||||
server = new Server("../map", g_creative_mode, g_mapgen_params);
|
||||
server = new Server("../map", g_creative_mode, g_hm_params,
|
||||
g_map_params, g_objectdata_interval,
|
||||
g_active_object_range);
|
||||
server->start(port);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ extern std::string getTimestamp();
|
|||
#include <jmutex.h>
|
||||
|
||||
extern JMutex g_range_mutex;
|
||||
extern s16 g_forcedfetch_range_nodes;
|
||||
extern s16 g_viewing_range_nodes;
|
||||
//extern s16 g_actual_viewing_range_nodes;
|
||||
extern bool g_viewing_range_all;
|
||||
|
@ -42,9 +41,5 @@ extern video::SMaterial g_materials[MATERIALS_COUNT];
|
|||
|
||||
extern IrrlichtDevice *g_device;
|
||||
|
||||
// Settings
|
||||
#include "map.h"
|
||||
extern MapgenParams g_mapgen_params;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
20
src/map.cpp
20
src/map.cpp
|
@ -1160,7 +1160,7 @@ void Map::PrintInfo(std::ostream &out)
|
|||
ServerMap
|
||||
*/
|
||||
|
||||
ServerMap::ServerMap(std::string savedir, MapgenParams params):
|
||||
ServerMap::ServerMap(std::string savedir, HMParams hmp, MapParams mp):
|
||||
Map(dout_server),
|
||||
m_heightmap(NULL)
|
||||
{
|
||||
|
@ -1212,15 +1212,19 @@ ServerMap::ServerMap(std::string savedir, MapgenParams params):
|
|||
}
|
||||
|
||||
dstream<<DTIME<<"Initializing new map."<<std::endl;
|
||||
|
||||
|
||||
// Create master heightmap
|
||||
ValueGenerator *maxgen =
|
||||
ValueGenerator::deSerialize(params.height_randmax);
|
||||
ValueGenerator::deSerialize(hmp.height_randmax);
|
||||
ValueGenerator *factorgen =
|
||||
ValueGenerator::deSerialize(params.height_randfactor);
|
||||
ValueGenerator::deSerialize(hmp.height_randfactor);
|
||||
ValueGenerator *basegen =
|
||||
ValueGenerator::deSerialize(params.height_base);
|
||||
ValueGenerator::deSerialize(hmp.height_base);
|
||||
m_heightmap = new UnlimitedHeightmap
|
||||
(params.heightmap_blocksize, maxgen, factorgen, basegen);
|
||||
(hmp.heightmap_blocksize, maxgen, factorgen, basegen);
|
||||
|
||||
// Set map parameters
|
||||
m_params = mp;
|
||||
|
||||
// Create zero sector
|
||||
emergeSector(v2s16(0,0));
|
||||
|
@ -1386,7 +1390,7 @@ MapSector * ServerMap::emergeSector(v2s16 p2d)
|
|||
{
|
||||
// Avgslope is the derivative of a hill
|
||||
float t = avgslope * avgslope;
|
||||
float a = MAP_BLOCKSIZE * 2;
|
||||
float a = MAP_BLOCKSIZE * 2 * m_params.plants_amount;
|
||||
u32 tree_max;
|
||||
if(t > 0.03)
|
||||
tree_max = a / (t/0.03);
|
||||
|
@ -1408,7 +1412,7 @@ MapSector * ServerMap::emergeSector(v2s16 p2d)
|
|||
{
|
||||
// Pitness usually goes at around -0.5...0.5
|
||||
u32 bush_max = 0;
|
||||
u32 a = MAP_BLOCKSIZE * 3;
|
||||
u32 a = MAP_BLOCKSIZE * 3.0 * m_params.plants_amount;
|
||||
if(pitness > 0)
|
||||
bush_max = (pitness*a*4);
|
||||
if(bush_max > a)
|
||||
|
|
23
src/map.h
23
src/map.h
|
@ -242,21 +242,32 @@ public:
|
|||
virtual void PrintInfo(std::ostream &out);
|
||||
};
|
||||
|
||||
struct MapgenParams
|
||||
// Master heightmap parameters
|
||||
struct HMParams
|
||||
{
|
||||
MapgenParams()
|
||||
HMParams()
|
||||
{
|
||||
heightmap_blocksize = 64;
|
||||
height_randmax = "constant 70.0";
|
||||
height_randfactor = "constant 0.6";
|
||||
height_base = "linear 0 80 0";
|
||||
plants_amount = "1.0";
|
||||
}
|
||||
s16 heightmap_blocksize;
|
||||
std::string height_randmax;
|
||||
std::string height_randfactor;
|
||||
std::string height_base;
|
||||
std::string plants_amount;
|
||||
};
|
||||
|
||||
// Map parameters
|
||||
struct MapParams
|
||||
{
|
||||
MapParams()
|
||||
{
|
||||
plants_amount = 1.0;
|
||||
//max_objects_in_block = 30;
|
||||
}
|
||||
float plants_amount;
|
||||
//u16 max_objects_in_block;
|
||||
};
|
||||
|
||||
class ServerMap : public Map
|
||||
|
@ -265,7 +276,7 @@ public:
|
|||
/*
|
||||
savedir: directory to which map data should be saved
|
||||
*/
|
||||
ServerMap(std::string savedir, MapgenParams params);
|
||||
ServerMap(std::string savedir, HMParams hmp, MapParams mp);
|
||||
~ServerMap();
|
||||
|
||||
s32 mapType() const
|
||||
|
@ -346,6 +357,8 @@ public:
|
|||
|
||||
private:
|
||||
UnlimitedHeightmap *m_heightmap;
|
||||
MapParams m_params;
|
||||
|
||||
std::string m_savedir;
|
||||
bool m_map_saving_enabled;
|
||||
};
|
||||
|
|
|
@ -352,6 +352,11 @@ public:
|
|||
m_objects.getObjects(origin, max_d, dest);
|
||||
}
|
||||
|
||||
s32 getObjectCount()
|
||||
{
|
||||
return m_objects.getCount();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/*
|
||||
|
|
|
@ -879,6 +879,12 @@ public:
|
|||
// origin is relative to block
|
||||
void getObjects(v3f origin, f32 max_d,
|
||||
core::array<DistanceSortedObject> &dest);
|
||||
|
||||
// Number of objects
|
||||
s32 getCount()
|
||||
{
|
||||
return m_objects.size();
|
||||
}
|
||||
|
||||
private:
|
||||
JMutex m_mutex;
|
||||
|
|
135
src/server.cpp
135
src/server.cpp
|
@ -284,56 +284,8 @@ void RemoteClient::SendBlocks(Server *server, float dtime)
|
|||
v3s16 center = getNodeBlockPos(center_nodepos);
|
||||
|
||||
/*
|
||||
Find out what block the player is going to next and set
|
||||
center to it.
|
||||
|
||||
Don't react to speeds under the initial value of highest_speed
|
||||
Get the starting value of the block finder radius.
|
||||
*/
|
||||
/*f32 highest_speed = 0.1 * BS;
|
||||
v3s16 dir(0,0,0);
|
||||
if(abs(playerspeed.X) > highest_speed)
|
||||
{
|
||||
highest_speed = playerspeed.X;
|
||||
if(playerspeed.X > 0)
|
||||
dir = v3s16(1,0,0);
|
||||
else
|
||||
dir = v3s16(-1,0,0);
|
||||
}
|
||||
if(abs(playerspeed.Y) > highest_speed)
|
||||
{
|
||||
highest_speed = playerspeed.Y;
|
||||
if(playerspeed.Y > 0)
|
||||
dir = v3s16(0,1,0);
|
||||
else
|
||||
dir = v3s16(0,-1,0);
|
||||
}
|
||||
if(abs(playerspeed.Z) > highest_speed)
|
||||
{
|
||||
highest_speed = playerspeed.Z;
|
||||
if(playerspeed.Z > 0)
|
||||
dir = v3s16(0,0,1);
|
||||
else
|
||||
dir = v3s16(0,0,-1);
|
||||
}
|
||||
|
||||
center += dir;*/
|
||||
|
||||
/*
|
||||
Calculate the starting value of the block finder radius.
|
||||
|
||||
The radius shall be the last used value minus the
|
||||
maximum moved distance.
|
||||
*/
|
||||
/*s16 d_start = m_last_block_find_d;
|
||||
if(max_moved >= d_start)
|
||||
{
|
||||
d_start = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
d_start -= max_moved;
|
||||
}*/
|
||||
|
||||
s16 last_nearest_unsent_d;
|
||||
s16 d_start;
|
||||
{
|
||||
|
@ -382,10 +334,6 @@ void RemoteClient::SendBlocks(Server *server, float dtime)
|
|||
|
||||
/*
|
||||
TODO: Get this from somewhere
|
||||
TODO: Values more than 7 make placing and removing blocks very
|
||||
sluggish when the map is being generated. This is
|
||||
because d is looped every time from 0 to d_max if no
|
||||
blocks are found for sending.
|
||||
*/
|
||||
//s16 d_max = 7;
|
||||
s16 d_max = 8;
|
||||
|
@ -659,6 +607,10 @@ void RemoteClient::SendObjectData(
|
|||
in memory):
|
||||
- Set blocks changed
|
||||
- Add blocks to emerge queue if they are not found
|
||||
|
||||
SUGGESTION: These could be ignored from the backside of the player
|
||||
|
||||
TODO: Keep track of total size of packet and stop when it is too big
|
||||
*/
|
||||
|
||||
Player *player = server->m_env.getPlayer(peer_id);
|
||||
|
@ -669,9 +621,14 @@ void RemoteClient::SendObjectData(
|
|||
v3s16 center_nodepos = floatToInt(playerpos);
|
||||
v3s16 center = getNodeBlockPos(center_nodepos);
|
||||
|
||||
s16 d_max = ACTIVE_OBJECT_D_BLOCKS;
|
||||
//s16 d_max = ACTIVE_OBJECT_D_BLOCKS;
|
||||
s16 d_max = server->m_active_object_range;
|
||||
|
||||
// Number of blocks whose objects were written to bos
|
||||
u16 blockcount = 0;
|
||||
|
||||
core::map<v3s16, MapBlock*> blocks;
|
||||
//core::map<v3s16, MapBlock*> blocks;
|
||||
std::ostringstream bos(std::ios_base::binary);
|
||||
|
||||
for(s16 d = 0; d <= d_max; d++)
|
||||
{
|
||||
|
@ -691,13 +648,18 @@ void RemoteClient::SendObjectData(
|
|||
if(m_blocks_sent.find(p) == NULL)
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Try stepping block and add it to a send queue
|
||||
try
|
||||
{
|
||||
|
||||
// Get block
|
||||
MapBlock *block = server->m_env.getMap().getBlockNoCreate(p);
|
||||
|
||||
// Skip block if there are no objects
|
||||
if(block->getObjectCount() == 0)
|
||||
continue;
|
||||
|
||||
// Step block if not in stepped_blocks and add to stepped_blocks
|
||||
if(stepped_blocks.find(p) == NULL)
|
||||
{
|
||||
|
@ -705,9 +667,28 @@ void RemoteClient::SendObjectData(
|
|||
stepped_blocks.insert(p, true);
|
||||
block->setChangedFlag();
|
||||
}
|
||||
|
||||
// Add block to queue
|
||||
blocks.insert(p, block);
|
||||
|
||||
/*
|
||||
Write objects
|
||||
*/
|
||||
|
||||
// Write blockpos
|
||||
writeV3S16(buf, p);
|
||||
bos.write((char*)buf, 6);
|
||||
|
||||
// Write objects
|
||||
block->serializeObjects(bos, serialization_version);
|
||||
|
||||
blockcount++;
|
||||
|
||||
/*
|
||||
Stop collecting objects if data is already too big
|
||||
*/
|
||||
// Sum of player and object data sizes
|
||||
s32 sum = (s32)os.tellp() + 2 + (s32)bos.tellp();
|
||||
// break out if data too big
|
||||
if(sum > MAX_OBJECTDATA_SIZE)
|
||||
d = d_max+1;
|
||||
|
||||
} //try
|
||||
catch(InvalidPositionException &e)
|
||||
|
@ -729,12 +710,11 @@ void RemoteClient::SendObjectData(
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
Write objects
|
||||
*/
|
||||
|
||||
u16 blockcount = blocks.size();
|
||||
|
||||
// Write block count
|
||||
writeU16(buf, blockcount);
|
||||
os.write((char*)buf, 2);
|
||||
|
@ -751,11 +731,21 @@ void RemoteClient::SendObjectData(
|
|||
MapBlock *block = i.getNode()->getValue();
|
||||
block->serializeObjects(os, serialization_version);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Write block count
|
||||
writeU16(buf, blockcount);
|
||||
os.write((char*)buf, 2);
|
||||
|
||||
// Write block objects
|
||||
os<<bos.str();
|
||||
|
||||
/*
|
||||
Send data
|
||||
*/
|
||||
|
||||
//dstream<<"Server: Sending object data to "<<peer_id<<std::endl;
|
||||
|
||||
// Make data buffer
|
||||
std::string s = os.str();
|
||||
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
|
||||
|
@ -898,13 +888,18 @@ u32 PIChecksum(core::list<PlayerInfo> &l)
|
|||
Server::Server(
|
||||
std::string mapsavedir,
|
||||
bool creative_mode,
|
||||
MapgenParams mapgen_params
|
||||
HMParams hm_params,
|
||||
MapParams map_params,
|
||||
float objectdata_interval,
|
||||
u16 active_object_range
|
||||
):
|
||||
m_env(new ServerMap(mapsavedir, mapgen_params), dout_server),
|
||||
m_env(new ServerMap(mapsavedir, hm_params, map_params), dout_server),
|
||||
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this),
|
||||
m_thread(this),
|
||||
m_emergethread(this),
|
||||
m_creative_mode(creative_mode)
|
||||
m_creative_mode(creative_mode),
|
||||
m_objectdata_interval(objectdata_interval),
|
||||
m_active_object_range(active_object_range)
|
||||
{
|
||||
m_env_mutex.Init();
|
||||
m_con_mutex.Init();
|
||||
|
@ -980,6 +975,7 @@ void Server::step(float dtime)
|
|||
void Server::AsyncRunStep()
|
||||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
|
||||
float dtime;
|
||||
{
|
||||
JMutexAutoLock lock1(m_step_dtime_mutex);
|
||||
|
@ -1033,7 +1029,7 @@ void Server::AsyncRunStep()
|
|||
|
||||
// Run time- and client- related stuff
|
||||
// NOTE: If you intend to add something here, check that it
|
||||
// doesn't fit in RemoteClient::SendBlocks for exampel.
|
||||
// doesn't fit in RemoteClient::SendBlocks for example.
|
||||
/*{
|
||||
// Clients are behind connection lock
|
||||
JMutexAutoLock lock(m_con_mutex);
|
||||
|
@ -1055,8 +1051,7 @@ void Server::AsyncRunStep()
|
|||
{
|
||||
static float counter = 0.0;
|
||||
counter += dtime;
|
||||
//TODO: Get value from somewhere
|
||||
if(counter >= 0.1)
|
||||
if(counter >= m_objectdata_interval)
|
||||
{
|
||||
JMutexAutoLock lock1(m_env_mutex);
|
||||
JMutexAutoLock lock2(m_con_mutex);
|
||||
|
@ -1930,12 +1925,12 @@ void Server::peerAdded(con::Peer *peer)
|
|||
bool r = player->inventory.addItem(item);
|
||||
assert(r == true);
|
||||
}
|
||||
// Rat
|
||||
/*// Rat
|
||||
{
|
||||
InventoryItem *item = new MapBlockObjectItem("Rat");
|
||||
bool r = player->inventory.addItem(item);
|
||||
assert(r == true);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
43
src/server.h
43
src/server.h
|
@ -201,6 +201,28 @@ struct PlayerInfo
|
|||
|
||||
u32 PIChecksum(core::list<PlayerInfo> &l);
|
||||
|
||||
/*
|
||||
Used for queueing and sorting block transfers in containers
|
||||
|
||||
Lower priority number means higher priority.
|
||||
*/
|
||||
struct PrioritySortedBlockTransfer
|
||||
{
|
||||
PrioritySortedBlockTransfer(float a_priority, v3s16 a_pos, u16 a_dest_peer)
|
||||
{
|
||||
priority = a_priority;
|
||||
pos = a_pos;
|
||||
dest_peer = a_dest_peer;
|
||||
}
|
||||
bool operator < (PrioritySortedBlockTransfer &other)
|
||||
{
|
||||
return priority < other.priority;
|
||||
}
|
||||
float priority;
|
||||
v3s16 pos;
|
||||
u16 a_dest_peer;
|
||||
};
|
||||
|
||||
class RemoteClient
|
||||
{
|
||||
public:
|
||||
|
@ -252,6 +274,8 @@ public:
|
|||
void BlockEmerged();
|
||||
|
||||
// Increments timeouts and removes timed-out blocks from list
|
||||
// NOTE: This doesn't fix the server-not-sending-block bug
|
||||
// because it is related to emerging, not sending.
|
||||
//void RunSendingTimeouts(float dtime, float timeout);
|
||||
|
||||
void PrintInfo(std::ostream &o)
|
||||
|
@ -310,6 +334,15 @@ private:
|
|||
JMutex m_blocks_sending_mutex;
|
||||
};
|
||||
|
||||
/*struct ServerSettings
|
||||
{
|
||||
ServerSettings()
|
||||
{
|
||||
creative_mode = false;
|
||||
}
|
||||
bool creative_mode;
|
||||
};*/
|
||||
|
||||
class Server : public con::PeerHandler
|
||||
{
|
||||
public:
|
||||
|
@ -319,7 +352,10 @@ public:
|
|||
Server(
|
||||
std::string mapsavedir,
|
||||
bool creative_mode,
|
||||
MapgenParams mapgen_params
|
||||
HMParams hm_params,
|
||||
MapParams map_params,
|
||||
float objectdata_inverval,
|
||||
u16 active_object_range
|
||||
);
|
||||
~Server();
|
||||
void start(unsigned short port);
|
||||
|
@ -377,8 +413,11 @@ private:
|
|||
EmergeThread m_emergethread;
|
||||
|
||||
BlockEmergeQueue m_emerge_queue;
|
||||
|
||||
|
||||
// Settings
|
||||
bool m_creative_mode;
|
||||
float m_objectdata_interval;
|
||||
u16 m_active_object_range;
|
||||
|
||||
friend class EmergeThread;
|
||||
friend class RemoteClient;
|
||||
|
|
|
@ -603,5 +603,15 @@ inline bool is_yes(std::string s)
|
|||
return false;
|
||||
}
|
||||
|
||||
inline s32 stoi(std::string s, s32 min, s32 max)
|
||||
{
|
||||
s32 i = atoi(s.c_str());
|
||||
if(i < min)
|
||||
i = min;
|
||||
if(i > max)
|
||||
i = max;
|
||||
return i;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue