Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Oct 13, 2024
1 parent c6c2adb commit ab15660
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 74 deletions.
2 changes: 1 addition & 1 deletion games/Repixture
Submodule Repixture updated from ee527c to 473995
2 changes: 1 addition & 1 deletion games/default
4 changes: 2 additions & 2 deletions src/client/fm_farmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ uint8_t FarMesh::update(v3opos_t camera_pos,

m_speed = speed;

const auto camera_pos_aligned_int =
playerBlockAlign(*m_control, floatToInt(camera_pos, BS * 16)) * MAP_BLOCKSIZE;
//const auto camera_pos_aligned_int = playerBlockAlign(*m_control, floatToInt(camera_pos, BS * 16)) * MAP_BLOCKSIZE;
const auto camera_pos_aligned_int = floatToInt(camera_pos, BS); // no aligned
const auto distance_max =
(std::min<unsigned int>(render_range, 1.2 * m_client->fog_range / BS) >> 7)
<< 7;
Expand Down
32 changes: 17 additions & 15 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4549,21 +4549,23 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,

if (farmesh) {
thread_local static const auto farmesh_range = g_settings->getS32("farmesh");
farmesh_async.step([&, farmesh_range = farmesh_range,
//yaw = player->getYaw(),
//pitch = player->getPitch(),
camera_pos = camera->getPosition(),
camera_offset = camera->getOffset(),
speed = player->getSpeed().getLength()]() {
const auto processed = farmesh->update(camera_pos,
//camera->getDirection(), camera->getFovMax(), camera->getCameraMode(), pitch, yaw,
camera_offset,
//sky->getBrightness(),
farmesh_range, speed);
if (!processed) {
std::this_thread::sleep_for(std::chrono::milliseconds(300));
}
});
thread_local static uint8_t processed{};
thread_local static u64 next_run_time{};
if (processed || porting::getTimeMs() > next_run_time) {
next_run_time = porting::getTimeMs() + 300;
farmesh_async.step([&, farmesh_range = farmesh_range,
//yaw = player->getYaw(),
//pitch = player->getPitch(),
camera_pos = camera->getPosition(),
camera_offset = camera->getOffset(),
speed = player->getSpeed().getLength()]() {
processed = farmesh->update(camera_pos,
//camera->getDirection(), camera->getFovMax(), camera->getCameraMode(), pitch, yaw,
camera_offset,
//sky->getBrightness(),
farmesh_range, speed);
});
}
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/clientiface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ void RemoteClient::SetBlocksNotSent(std::map<v3s16, MapBlock*> &blocks)
*/
}

void RemoteClient::SetBlockDeleted(v3bpos_t p) {
void RemoteClient::SetBlockDeleted(const v3bpos_t & p) {
m_blocks_sent.erase(p);
}

Expand Down
29 changes: 10 additions & 19 deletions src/clientiface.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,27 +250,27 @@ class RemoteClient
std::atomic_ushort net_proto_version = 0;

// fm:
u16 net_proto_version_fm = 0;
u16 net_proto_version_fm{};
//std::atomic_int m_nearest_unsent_reset {0};
std::atomic_uint wanted_range{10};
std::atomic_int range_all{0};
std::atomic_int farmesh = {0};
float fov = 72;
std::atomic_int range_all{};
std::atomic_int farmesh = {};
float fov{72};
//bool block_overflow;
ServerEnvironment *m_env = nullptr;
ServerEnvironment *m_env{};
u32 getSendingCount() const { return 0; }
std::map<uint16_t, std::pair<double, int32_t>> m_objects_last_pos_sent;
v3f m_last_direction;
float m_nearest_unsent_reset_timer;
float m_nearest_unsent_reset_timer{};
std::unordered_map<v3bpos_t, uint8_t> blocks;
void SetBlocksNotSent();
void SetBlockDeleted(v3bpos_t p);
std::vector<std::unordered_map<v3bpos_t, std::pair<uint8_t, uint32_t>>>
void SetBlockDeleted(const v3bpos_t &p);
std::vector<std::unordered_map<v3bpos_t, std::pair<uint8_t, int32_t>>>
far_blocks_requested{FARMESH_STEP_MAX};
std::mutex far_blocks_requested_mutex;
int GetNextBlocksFm(ServerEnvironment *env, EmergeManager *emerge, float dtime,
std::vector<PrioritySortedBlockTransfer> &dest, double m_uptime, u64 max_ms);

uint32_t SendFarBlocks();
// ==

/* Authentication information */
Expand Down Expand Up @@ -513,16 +513,7 @@ class ClientInterface {
void sendToAll(u16 channelnum, SharedBuffer<u8> data, bool reliable);
void sendToAll(u16 channelnum, msgpack::sbuffer const &buffer, bool reliable);
RemoteClientPtr getClient(u16 peer_id, ClientState state_min = CS_Active);
RemoteClientVector getClientList() {
RemoteClientVector clients;
auto lock = m_clients.lock_unique_rec();
for(auto & ir : m_clients) {
auto c = ir.second;
if (c)
clients.emplace_back(c);
}
return clients;
}
RemoteClientVector getClientList();
// ==


Expand Down
2 changes: 1 addition & 1 deletion src/external/jsoncpp
Submodule jsoncpp updated 43 files
+1 −1 .clang-format
+20 −0 .github/workflows/clang-format.yml
+18 −0 .github/workflows/cmake.yml
+65 −0 .github/workflows/meson.yml
+0 −71 .travis.yml
+0 −130 .travis_scripts/cmake_builder.sh
+0 −83 .travis_scripts/meson_builder.sh
+0 −356 .travis_scripts/run-clang-format.py
+0 −4 .travis_scripts/run-clang-format.sh
+0 −8 .travis_scripts/travis.before_install.linux.sh
+0 −0 .travis_scripts/travis.before_install.osx.sh
+0 −5 .travis_scripts/travis.install.linux.sh
+0 −1 .travis_scripts/travis.install.osx.sh
+12 −18 CMakeLists.txt
+1 −1 CONTRIBUTING.md
+17 −0 SECURITY.md
+3 −3 amalgamate.py
+1 −1 example/readFromString/readFromString.cpp
+2 −2 include/PreventInSourceBuilds.cmake
+5 −2 include/json/allocator.h
+2 −1 include/json/json_features.h
+38 −6 include/json/reader.h
+39 −7 include/json/value.h
+4 −5 include/json/version.h
+9 −10 include/json/writer.h
+9 −7 jsoncpp-namespaced-targets.cmake
+1 −1 jsoncppConfig.cmake.in
+8 −0 jsoncppConfig.cmake.meson.in
+41 −4 meson.build
+5 −2 src/jsontestrunner/main.cpp
+2 −5 src/lib_json/CMakeLists.txt
+105 −81 src/lib_json/json_reader.cpp
+6 −4 src/lib_json/json_value.cpp
+10 −5 src/lib_json/json_writer.cpp
+1 −1 src/test_lib_json/jsontest.h
+59 −6 src/test_lib_json/main.cpp
+4 −0 test/data/fail_strict_comment_01.json
+4 −0 test/data/fail_strict_comment_02.json
+3 −0 test/data/fail_strict_comment_03.json
+1 −0 test/data/fail_test_object_02.json
+3 −0 test/data/legacy_test_real_13.expected
+1 −0 test/data/legacy_test_real_13.json
+6 −3 test/runjsontests.py
36 changes: 31 additions & 5 deletions src/fm_clientiface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,42 +562,68 @@ int RemoteClient::GetNextBlocksFm(ServerEnvironment *env, EmergeManager *emerge,
}
}

return num_blocks_selected - num_blocks_sending;
}

uint32_t RemoteClient::SendFarBlocks()
{
uint16_t sent_cnt{};
TRY_UNIQUE_LOCK(far_blocks_requested_mutex)
{
std::multimap<int32_t, MapBlockP> ordered;
constexpr uint16_t send_max = 50;
uint16_t sent_cnt = 0;
constexpr uint16_t send_max{50};
for (auto &far_blocks : far_blocks_requested) {
for (auto &[bpos, step_sent] : far_blocks) {
auto &[step, sent_ts] = step_sent;
if (!sent_ts) {
if (sent_ts <= 0) {
continue;
}
if (step >= FARMESH_STEP_MAX - 1) {
sent_ts = -1;
continue;
}
const auto dbase = m_env->m_server->GetFarDatabase(step);
if (!dbase) {
sent_ts = -1;
continue;
}
const auto block = m_env->m_server->loadBlockNoStore(dbase, bpos);
if (!block) {
sent_ts = -1;
continue;
}

g_profiler->add("Server: Far blocks sent", 1);

block->far_step = step;
step_sent.second = 0;
sent_ts = 0;
ordered.emplace(sent_ts - step, block);

if (++sent_cnt > send_max) {
break;
}
}
}

// First with larger iteration and smaller step

for (const auto &[key, block] : std::views::reverse(ordered)) {
m_env->m_server->SendBlockFm(
peer_id, block, serialization_version, net_proto_version);
}
}
return sent_cnt;
}

return num_blocks_selected - num_blocks_sending;
RemoteClientVector ClientInterface::getClientList()
{
auto lock = m_clients.lock_unique_rec();
RemoteClientVector clients;
for (const auto &ir : m_clients) {
const auto &c = ir.second;
if (!c)
continue;
clients.emplace_back(c);
}
return clients;
}
65 changes: 63 additions & 2 deletions src/fm_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,46 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#include "debug/stacktrace.h"
#include "util/timetaker.h"

ServerThread::ServerThread(Server *server) : thread_vector("Server", 40), m_server(server)
ServerThreadBase::ServerThreadBase(Server *server, const std::string &name,
int priority) : thread_vector{name, 2}, m_server{server}
{
}

void *ServerThreadBase::run()
{
// If something wrong with init order
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_start));

BEGIN_DEBUG_EXCEPTION_HANDLER

auto time_last = porting::getTimeMs();

while (!stopRequested()) {
DUMP("");
try {
const auto time_now = porting::getTimeMs();
const auto result = step(time_now - time_last);
time_last = time_now;
std::this_thread::sleep_for(
std::chrono::milliseconds(result ? sleep_result : sleep_nothing));
#if !EXCEPTION_DEBUG
} catch (const std::exception &e) {
errorstream << m_name << ": exception: " << e.what() << std::endl
<< stacktrace() << std::endl;
} catch (...) {
errorstream << m_name << ": Unknown unhandled exception at "
<< __PRETTY_FUNCTION__ << ":" << __LINE__ << std::endl
<< stacktrace() << std::endl;
#else
} catch (int) { // nothing
#endif
}
}
END_DEBUG_EXCEPTION_HANDLER
return nullptr;
}

ServerThread::ServerThread(Server *server) : thread_vector{"Server", 40}, m_server{server}
{
}

Expand Down Expand Up @@ -169,8 +208,18 @@ void *MapThread::run()
return nullptr;
}

SendFarBlocksThread::SendFarBlocksThread(Server *server) :
ServerThreadBase(server, "SendFarBlocks", 1)
{
}

size_t SendFarBlocksThread::step(float dtime)
{
return m_server->SendFarBlocks(dtime);
}

SendBlocksThread::SendBlocksThread(Server *server) :
thread_vector("SendBlocks", 30), m_server(server)
thread_vector{"SendBlocks", 30}, m_server{server}
{
}

Expand Down Expand Up @@ -623,3 +672,15 @@ void Server::SendBlockFm(session_t peer_id, MapBlockP block, u8 ver,
auto s = std::string{pkt.getString(0), pkt.getSize()};
Send(&pkt);
}

uint32_t Server::SendFarBlocks(float dtime)
{
ScopeProfiler sp(g_profiler, "Server send far blocks");
uint32_t sent{};
for (const auto &client : m_clients.getClientList()) {
if (!client)
continue;
sent += client->SendFarBlocks();
}
return sent;
}
43 changes: 35 additions & 8 deletions src/fm_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.

class Server;

class ServerThreadBase : public thread_vector
{
protected:
Server *const m_server;

public:
int sleep_start{1000};
int sleep_result{10};
int sleep_nothing{1000};

ServerThreadBase(
Server *server, const std::string &name = "Unnamed", int priority = 0);
void *run();

virtual size_t step(float dtime) = 0;
};

class ServerThread : public thread_vector
{
public:
Expand All @@ -33,12 +50,12 @@ class ServerThread : public thread_vector
void *run();

private:
Server *m_server;
Server *const m_server;
};

class MapThread : public thread_vector
{
Server *m_server;
Server *const m_server;

public:
MapThread(Server *server);
Expand All @@ -48,17 +65,27 @@ class MapThread : public thread_vector

class SendBlocksThread : public thread_vector
{
Server *m_server;
Server *const m_server;

public:
SendBlocksThread(Server *server);

void *run();
};

class SendFarBlocksThread : public ServerThreadBase
{
public:
//using ServerThreadBase::ServerThreadBase;
SendFarBlocksThread(Server *server);

private:
size_t step(float dtime) override;
};

class LiquidThread : public thread_vector
{
Server *m_server;
Server *const m_server;

public:
LiquidThread(Server *server);
Expand All @@ -68,7 +95,7 @@ class LiquidThread : public thread_vector

class EnvThread : public thread_vector
{
Server *m_server;
Server *const m_server;

public:
EnvThread(Server *server);
Expand All @@ -78,7 +105,7 @@ class EnvThread : public thread_vector

class AbmThread : public thread_vector
{
Server *m_server;
Server *const m_server;

public:
AbmThread(Server *server);
Expand All @@ -88,7 +115,7 @@ class AbmThread : public thread_vector

class AbmWorldThread : public thread_vector
{
Server *m_server;
Server *const m_server;

public:
AbmWorldThread(Server *server);
Expand All @@ -98,7 +125,7 @@ class AbmWorldThread : public thread_vector

class WorldMergeThread : public thread_vector
{
Server *m_server;
Server *const m_server;

public:
WorldMergeThread(Server *server);
Expand Down
Loading

0 comments on commit ab15660

Please sign in to comment.