mirror of
https://github.com/bdnugget/freeminer.git
synced 2026-11-07 06:57:27 +00:00
farlights
This commit is contained in:
1 parent
d57a872581
commit
ec0f04656f
6 files changed
+120
-4
No files matched your search
@@ -32,7 +32,8 @@
|
||||
|
||||
MeshMakeData::MeshMakeData(const NodeDefManager *ndef,
|
||||
u16 side_length, MeshGrid mesh_grid
|
||||
, int lod_step, int far_step,
|
||||
, int lod_step
|
||||
, int far_step,
|
||||
NodeContainer *nodecontainer) :
|
||||
m_side_length(side_length >> lod_step),
|
||||
m_mesh_grid(mesh_grid),
|
||||
@@ -42,7 +43,7 @@ MeshMakeData::MeshMakeData(const NodeDefManager *ndef,
|
||||
side_length_data{side_length},
|
||||
lod_step{lod_step},
|
||||
far_step{far_step},
|
||||
fscale(1<<(far_step + lod_step))
|
||||
fscale(1 << (far_step + lod_step))
|
||||
{
|
||||
assert(m_side_length > 0);
|
||||
}
|
||||
@@ -742,6 +743,53 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data):
|
||||
buf->drop();
|
||||
}
|
||||
|
||||
if (static const auto farlights = g_settings->getBool("farlights"); farlights && far_step) {
|
||||
scene::SMeshBuffer *buffer = new scene::SMeshBuffer();
|
||||
buffer->Material.PointCloud = true;
|
||||
buffer->Material.BackfaceCulling = false;
|
||||
buffer->Material.FogEnable = true;
|
||||
v3bpos_t ofs;
|
||||
const auto &storage =
|
||||
client->getEnv().getClientMap().far_blocks_storage[far_step];
|
||||
int index_i = 0;
|
||||
for (ofs.Z = 0; ofs.Z < mesh_grid.cell_size; ofs.Z++) {
|
||||
for (ofs.Y = 0; ofs.Y < mesh_grid.cell_size; ofs.Y++) {
|
||||
for (ofs.X = 0; ofs.X < mesh_grid.cell_size; ofs.X++) {
|
||||
v3bpos_t p = (bp + ofs); // * MAP_BLOCKSIZE;
|
||||
const auto block = storage.get(p).block;
|
||||
|
||||
if (!block)
|
||||
continue;
|
||||
if (block->m_light_points.empty())
|
||||
continue;
|
||||
const auto bpos_rel = block->getPosRelative();
|
||||
for (const auto &lp : block->m_light_points) {
|
||||
if (++index_i > 16000)
|
||||
break;
|
||||
float r{200};
|
||||
float g{230};
|
||||
float b{static_cast<float>(16 * lp.second)};
|
||||
const auto color_far_scale = far_step / 3.0f;
|
||||
if (!color_far_scale) {
|
||||
continue;
|
||||
}
|
||||
r /= color_far_scale;
|
||||
g /= color_far_scale;
|
||||
b /= color_far_scale;
|
||||
const video::SColor c(255 / fscale, r, g, b);
|
||||
const auto lpos_rel = lp.first - bpos_rel;
|
||||
const auto coord = posToFloat(lpos_rel, BS);
|
||||
video::S3DVertex v(coord.X, coord.Y, coord.Z, 0.0f, 0.0f,
|
||||
1.0f, c, 0.0f, 0.0f);
|
||||
buffer->Vertices->Data.emplace_back(v);
|
||||
buffer->Indices->Data.emplace_back(index_i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mesh->addMeshBuffer(buffer);
|
||||
}
|
||||
|
||||
if (mesh) {
|
||||
// Use VBO for mesh (this just would set this for every buffer)
|
||||
mesh->setHardwareMappingHint(scene::EHM_STATIC);
|
||||
|
||||
@@ -765,6 +765,7 @@ void *WorldMergeThread::run()
|
||||
merger.world_merge_max_clients = m_server->isSingleplayer() ? 1 : 0;
|
||||
g_settings->getU32NoEx("world_merge_max_clients", merger.world_merge_max_clients);
|
||||
g_settings->getU32NoEx("world_merge_lazy_up", merger.lazy_up);
|
||||
g_settings->getBoolNoEx("farlights", merger.farlights);
|
||||
|
||||
{
|
||||
merger.world_merge_load_all = -1;
|
||||
|
||||
+30
-2
@@ -184,11 +184,17 @@ void WorldMerger::merge_one_block(MapDatabase *dbase, MapDatabase *dbase_up,
|
||||
top_c[c] += 4;
|
||||
}
|
||||
|
||||
if (const auto light_night = n.getLightRaw(
|
||||
LIGHTBANK_NIGHT, ndef->getLightingFlags(n));
|
||||
const auto &lf = ndef->getLightingFlags(c);
|
||||
if (const auto light_night = n.getLightRaw(LIGHTBANK_NIGHT, lf);
|
||||
light_night) {
|
||||
top_light_night.emplace_back(light_night);
|
||||
}
|
||||
if (farlights && !step && (lf.light_source)) {
|
||||
const auto plpos =
|
||||
block->getPosRelative() + p; //pos_in_block;
|
||||
const auto &[i, r] = block->m_light_points.try_emplace(
|
||||
plpos, lf.light_source);
|
||||
}
|
||||
|
||||
nodes[c] = n;
|
||||
}
|
||||
@@ -221,6 +227,28 @@ void WorldMerger::merge_one_block(MapDatabase *dbase, MapDatabase *dbase_up,
|
||||
}
|
||||
// TODO: skip full air;
|
||||
|
||||
if (farlights) {
|
||||
int lights_count = 0, lights_used = 0;
|
||||
constexpr auto some_magick_thinner_const = 3; // more -> less far ligts
|
||||
for (const auto &[bpos, block] : blocks) {
|
||||
if (!block) {
|
||||
continue;
|
||||
}
|
||||
// TODO: apply some smart? filtering here
|
||||
block_up->m_light_points.insert(
|
||||
block->m_light_points.begin(), block->m_light_points.end());
|
||||
for (const auto &lp : block->m_light_points) {
|
||||
++lights_count;
|
||||
if (lights_count % (some_magick_thinner_const * (16 - lp.second))) {
|
||||
continue;
|
||||
}
|
||||
++lights_used;
|
||||
block_up->m_light_points.emplace(lp);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!not_empty_nodes) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public:
|
||||
uint32_t world_merge_throttle{};
|
||||
uint32_t world_merge_max_clients{};
|
||||
int16_t world_merge_load_all{}; // -1 : auto; 0 : disable; 1 : force
|
||||
bool farlights {true};
|
||||
bool partial{};
|
||||
uint32_t lazy_up{};
|
||||
const NodeDefManager *const ndef{};
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "content_mapnode.h" // For legacy name-id mapping
|
||||
#include "content_nodemeta.h" // For legacy deserialization
|
||||
#include "serialization.h"
|
||||
#include "util/msgpack_serialize.h"
|
||||
#if CHECK_CLIENT_BUILD()
|
||||
#include "client/mapblock_mesh.h"
|
||||
#endif
|
||||
@@ -243,6 +244,12 @@ MapNode MapBlock::getNodeTry(const v3pos_t &p)
|
||||
return getNodeNoLock(p);
|
||||
}
|
||||
|
||||
constexpr auto MAPBLOCK_DATA{0};
|
||||
enum
|
||||
{
|
||||
MAPBLOCK_LIGHT_POINTS
|
||||
};
|
||||
|
||||
// ==
|
||||
|
||||
/*
|
||||
@@ -539,7 +546,12 @@ void MapBlock::serialize(std::ostream &os_compressed, u8 version, bool disk, int
|
||||
infostream<<" serialize not generated block"<<std::endl;
|
||||
}
|
||||
|
||||
// freeminer
|
||||
if(!m_light_points.empty()) {
|
||||
flags |= (1 << 7);
|
||||
}
|
||||
const auto lock = lock_shared_rec();
|
||||
// =========
|
||||
|
||||
writeU8(os, flags);
|
||||
if (version >= 27) {
|
||||
@@ -627,6 +639,14 @@ void MapBlock::serialize(std::ostream &os_compressed, u8 version, bool disk, int
|
||||
}
|
||||
}
|
||||
|
||||
// freeminer
|
||||
if (flags & (1 << 7)) {
|
||||
MSGPACK_PACKET_INIT((int)MAPBLOCK_DATA, 1);
|
||||
PACK(MAPBLOCK_LIGHT_POINTS, m_light_points);
|
||||
os_raw << serializeString32(std::string_view{buffer.data(), buffer.size()});
|
||||
}
|
||||
// =========
|
||||
|
||||
if (version >= 29) {
|
||||
// now compress the whole thing
|
||||
compress(os_raw.str(), os_compressed, version, compression_level);
|
||||
@@ -805,6 +825,20 @@ bool MapBlock::deSerialize(std::istream &in_compressed, u8 version, bool disk)
|
||||
analyzeContent();
|
||||
}
|
||||
|
||||
if (flags & (1 << 7)) {
|
||||
std::string data = deSerializeString32(is);
|
||||
if (!data.empty()) {
|
||||
msgpack::unpacked msg;
|
||||
msgpack::unpack(msg, data.data(), data.size());
|
||||
auto &obj = msg.get();
|
||||
auto packet = obj.as<MsgpackPacket>();
|
||||
const auto it = packet.find(MAPBLOCK_LIGHT_POINTS);
|
||||
if (it != packet.end()) {
|
||||
it->second.convert(m_light_points);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TRACESTREAM(<<"MapBlock::deSerialize "<<getPos()
|
||||
<<": Done."<<std::endl);
|
||||
return true;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "fm_nodecontainer.h"
|
||||
#include "irr_v3d.h"
|
||||
@@ -536,6 +538,8 @@ public:
|
||||
std::mutex abm_triggers_mutex;
|
||||
size_t abmTriggersRun(ServerEnvironment *m_env, u32 time, uint8_t activate = 0);
|
||||
uint32_t m_abm_timestamp{};
|
||||
using light_t = uint8_t;
|
||||
std::unordered_map<v3pos_t, light_t> m_light_points;
|
||||
|
||||
u32 getActualTimestamp()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user