Skip to content

Commit

Permalink
General code refactoring/improvements in server, treegen and connection
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Mar 20, 2024
1 parent 24f2c38 commit bc4ab8b
Show file tree
Hide file tree
Showing 34 changed files with 332 additions and 441 deletions.
10 changes: 3 additions & 7 deletions src/client/clientmap.h
Expand Up @@ -57,18 +57,11 @@ class ClientMap : public Map, public scene::ISceneNode
s32 id
);

virtual ~ClientMap();

bool maySaveBlocks() override
{
return false;
}

void drop() override
{
ISceneNode::drop(); // calls destructor
}

void updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset, video::SColor light_color);

/*
Expand Down Expand Up @@ -122,6 +115,9 @@ class ClientMap : public Map, public scene::ISceneNode
void onSettingChanged(const std::string &name);

protected:
// use drop() instead
virtual ~ClientMap();

void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) override;
private:
bool isMeshOccluded(MapBlock *mesh_block, u16 mesh_size, v3s16 cam_pos_nodes);
Expand Down
2 changes: 1 addition & 1 deletion src/collision.cpp
Expand Up @@ -89,7 +89,7 @@ static inline v3f truncate(const v3f& vec, const f32 factor)
// The time after which the collision occurs is stored in dtime.
CollisionAxis axisAlignedCollision(
const aabb3f &staticbox, const aabb3f &movingbox,
const v3f &speed, f32 *dtime)
const v3f speed, f32 *dtime)
{
//TimeTaker tt("axisAlignedCollision");

Expand Down
2 changes: 1 addition & 1 deletion src/collision.h
Expand Up @@ -78,7 +78,7 @@ collisionMoveResult collisionMoveSimple(Environment *env,IGameDef *gamedef,
// dtime receives time until first collision, invalid if -1 is returned
CollisionAxis axisAlignedCollision(
const aabb3f &staticbox, const aabb3f &movingbox,
const v3f &speed, f32 *dtime);
v3f speed, f32 *dtime);

// Helper function:
// Checks if moving the movingbox up by the given distance would hit a ceiling.
Expand Down
1 change: 1 addition & 0 deletions src/database/database-files.cpp
Expand Up @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "filesys.h"
#include "server/player_sao.h"
#include "util/string.h"
#include <json/json.h>
#include <cassert>

// !!! WARNING !!!
Expand Down
1 change: 0 additions & 1 deletion src/database/database-files.h
Expand Up @@ -94,7 +94,6 @@ class ModStorageDatabaseFiles : public ModStorageDatabase

private:
Json::Value *getOrCreateJson(const std::string &modname);
bool writeJson(const std::string &modname, const Json::Value &json);

std::string m_storage_dir;
std::unordered_map<std::string, Json::Value> m_mod_storage;
Expand Down
2 changes: 1 addition & 1 deletion src/emerge.cpp
Expand Up @@ -646,7 +646,7 @@ void *EmergeThread::run()
std::map<v3s16, MapBlock *> modified_blocks;

m_map = &m_server->m_env->getServerMap();
m_emerge = m_server->m_emerge;
m_emerge = m_server->getEmergeManager();
m_mapgen = m_emerge->m_mapgens[id];
enable_mapgen_debug_info = m_emerge->enable_mapgen_debug_info;

Expand Down
18 changes: 6 additions & 12 deletions src/httpfetch.cpp
Expand Up @@ -19,8 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "httpfetch.h"
#include "porting.h" // for sleep_ms(), get_sysinfo(), secure_rand_fill_buf()
#include <iostream>
#include <sstream>
#include <list>
#include <unordered_map>
#include <cerrno>
Expand Down Expand Up @@ -152,9 +150,9 @@ bool httpfetch_async_get(u64 caller, HTTPFetchResult &fetch_result)
static size_t httpfetch_writefunction(
char *ptr, size_t size, size_t nmemb, void *userdata)
{
std::ostringstream *stream = (std::ostringstream*)userdata;
auto *dest = reinterpret_cast<std::string*>(userdata);
size_t count = size * nmemb;
stream->write(ptr, count);
dest->append(ptr, count);
return count;
}

Expand Down Expand Up @@ -215,7 +213,6 @@ class HTTPFetchOngoing
CURLM *multi = nullptr;
HTTPFetchRequest request;
HTTPFetchResult result;
std::ostringstream oss;
struct curl_slist *http_header = nullptr;
curl_mime *multipart_mime = nullptr;
};
Expand All @@ -225,8 +222,7 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
CurlHandlePool *pool_):
pool(pool_),
request(request_),
result(request_),
oss(std::ios::binary)
result(request_)
{
curl = pool->alloc();
if (!curl)
Expand Down Expand Up @@ -277,16 +273,15 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
curl_easy_setopt(curl, CURLOPT_USERAGENT, request.useragent.c_str());

// Set up a write callback that writes to the
// ostringstream ongoing->oss, unless the data
// is to be discarded
// result struct, unless the data is to be discarded
if (request.caller == HTTPFETCH_DISCARD) {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
httpfetch_discardfunction);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, nullptr);
} else {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
httpfetch_writefunction);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &oss);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result.data);
}

// Set data from fields or raw_data
Expand Down Expand Up @@ -372,7 +367,6 @@ const HTTPFetchResult * HTTPFetchOngoing::complete(CURLcode res)
{
result.succeeded = (res == CURLE_OK);
result.timeout = (res == CURLE_OPERATION_TIMEDOUT);
result.data = oss.str();

// Get HTTP/FTP response code
result.response_code = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/map.cpp
Expand Up @@ -600,7 +600,7 @@ void Map::removeNodeTimer(v3s16 p)
block->removeNodeTimer(p_rel);
}

bool Map::determineAdditionalOcclusionCheck(const v3s16 &pos_camera,
bool Map::determineAdditionalOcclusionCheck(const v3s16 pos_camera,
const core::aabbox3d<s16> &block_bounds, v3s16 &check)
{
/*
Expand Down Expand Up @@ -664,7 +664,7 @@ bool Map::determineAdditionalOcclusionCheck(const v3s16 &pos_camera,
return false;
}

bool Map::isOccluded(const v3s16 &pos_camera, const v3s16 &pos_target,
bool Map::isOccluded(const v3s16 pos_camera, const v3s16 pos_target,
float step, float stepfac, float offset, float end_offset, u32 needed_count)
{
v3f direction = intToFloat(pos_target - pos_camera, BS);
Expand Down
14 changes: 3 additions & 11 deletions src/map.h
Expand Up @@ -120,14 +120,6 @@ class Map /*: public NodeContainer*/
virtual ~Map();
DISABLE_CLASS_COPY(Map);

/*
Drop (client) or delete (server) the map.
*/
virtual void drop()
{
delete this;
}

void addEventReceiver(MapEventReceiver *event_receiver);
void removeEventReceiver(MapEventReceiver *event_receiver);
// event shall be deleted by caller after the call.
Expand Down Expand Up @@ -314,9 +306,9 @@ class Map /*: public NodeContainer*/
// Can be implemented by child class
virtual void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) {}

bool determineAdditionalOcclusionCheck(const v3s16 &pos_camera,
const core::aabbox3d<s16> &block_bounds, v3s16 &check);
bool isOccluded(const v3s16 &pos_camera, const v3s16 &pos_target,
bool determineAdditionalOcclusionCheck(v3s16 pos_camera,
const core::aabbox3d<s16> &block_bounds, v3s16 &to_check);
bool isOccluded(v3s16 pos_camera, v3s16 pos_target,
float step, float stepfac, float start_offset, float end_offset,
u32 needed_count);
};
Expand Down
2 changes: 1 addition & 1 deletion src/mapgen/mg_decoration.cpp
Expand Up @@ -492,5 +492,5 @@ size_t DecoLSystem::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling)

// Make sure that tree_def can't be modified, since it is shared.
const auto &ref = *tree_def;
return treegen::make_ltree(*vm, p, m_ndef, ref);
return treegen::make_ltree(*vm, p, ref);
}

0 comments on commit bc4ab8b

Please sign in to comment.