Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Jul 20, 2023
1 parent b423624 commit f8b7f47
Show file tree
Hide file tree
Showing 25 changed files with 149 additions and 130 deletions.
41 changes: 21 additions & 20 deletions src/client/clientmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "clientmap.h"
#include "client.h"
#include "irr_v2d.h"
#include "irr_v3d.h"
#include "mapblock_mesh.h"
#include <IMaterialRenderer.h>
Expand Down Expand Up @@ -169,7 +170,7 @@ void ClientMap::OnRegisterSceneNode()
}

void ClientMap::getBlocksInViewRange(v3pos_t cam_pos_nodes,
v3pos_t *p_blocks_min, v3pos_t *p_blocks_max, float range)
v3bpos_t *p_blocks_min, v3bpos_t *p_blocks_max, float range)
{
if (range <= 0.0f)
range = m_control.wanted_range;
Expand All @@ -188,11 +189,11 @@ void ClientMap::getBlocksInViewRange(v3pos_t cam_pos_nodes,
cam_pos_nodes.Z + box_nodes_d.Z);
// Take a fair amount as we will be dropping more out later
// Umm... these additions are a bit strange but they are needed.
*p_blocks_min = v3pos_t(
*p_blocks_min = v3bpos_t(
p_nodes_min.X / MAP_BLOCKSIZE - 3,
p_nodes_min.Y / MAP_BLOCKSIZE - 3,
p_nodes_min.Z / MAP_BLOCKSIZE - 3);
*p_blocks_max = v3pos_t(
*p_blocks_max = v3bpos_t(
p_nodes_max.X / MAP_BLOCKSIZE + 1,
p_nodes_max.Y / MAP_BLOCKSIZE + 1,
p_nodes_max.Z / MAP_BLOCKSIZE + 1);
Expand All @@ -205,7 +206,7 @@ class MapBlockFlags
static constexpr u16 CHUNK_MASK = CHUNK_EDGE - 1;
static constexpr std::size_t CHUNK_VOLUME = CHUNK_EDGE * CHUNK_EDGE * CHUNK_EDGE; // volume of a chunk

MapBlockFlags(v3s16 min_pos, v3s16 max_pos)
MapBlockFlags(v3bpos_t min_pos, v3bpos_t max_pos)
: min_pos(min_pos), volume((max_pos - min_pos) / CHUNK_EDGE + 1)
{
chunks.resize(volume.X * volume.Y * volume.Z);
Expand All @@ -214,24 +215,24 @@ class MapBlockFlags
class Chunk
{
public:
inline u8 &getBits(v3s16 pos)
inline u8 &getBits(v3bpos_t pos)
{
std::size_t address = getAddress(pos);
return bits[address];
}

private:
inline std::size_t getAddress(v3s16 pos) {
inline std::size_t getAddress(v3bpos_t pos) {
std::size_t address = (pos.X & CHUNK_MASK) + (pos.Y & CHUNK_MASK) * CHUNK_EDGE + (pos.Z & CHUNK_MASK) * (CHUNK_EDGE * CHUNK_EDGE);
return address;
}

std::array<u8, CHUNK_VOLUME> bits;
};

Chunk &getChunk(v3s16 pos)
Chunk &getChunk(v3bpos_t pos)
{
v3s16 delta = (pos - min_pos) / CHUNK_EDGE;
v3bpos_t delta = (pos - min_pos) / CHUNK_EDGE;
std::size_t address = delta.X + delta.Y * volume.X + delta.Z * volume.X * volume.Y;
Chunk *chunk = chunks[address].get();
if (!chunk) {
Expand All @@ -242,8 +243,8 @@ class MapBlockFlags
}
private:
std::vector<std::unique_ptr<Chunk>> chunks;
v3s16 min_pos;
v3s16 volume;
v3bpos_t min_pos;
v3bpos_t volume;
};

void ClientMap::updateDrawList()
Expand Down Expand Up @@ -289,7 +290,7 @@ void ClientMap::updateDrawList()
// if (occlusion_culling_enabled && m_control.show_wireframe)
// occlusion_culling_enabled = porting::getTimeS() & 1;

std::queue<v3s16> blocks_to_consider;
std::queue<v3bpos_t> blocks_to_consider;

// Bits per block:
// [ visited | 0 | 0 | 0 | 0 | Z visible | Y visible | X visible ]
Expand All @@ -302,7 +303,7 @@ void ClientMap::updateDrawList()
// Recursively walk the space and pick mapblocks for drawing
while (blocks_to_consider.size() > 0) {

v3s16 block_coord = blocks_to_consider.front();
v3bpos_t block_coord = blocks_to_consider.front();
blocks_to_consider.pop();

auto &flags = blocks_seen.getChunk(block_coord).getBits(block_coord);
Expand All @@ -315,7 +316,7 @@ void ClientMap::updateDrawList()
blocks_visited++;

// Get the sector, block and mesh
MapSector *sector = this->getSectorNoGenerate(v2s16(block_coord.X, block_coord.Z));
MapSector *sector = this->getSectorNoGenerate(v2bpos_t(block_coord.X, block_coord.Z));

if (!sector)
continue;
Expand All @@ -329,7 +330,7 @@ void ClientMap::updateDrawList()
v3f mesh_sphere_center;
f32 mesh_sphere_radius;

v3s16 block_pos_nodes = block_coord * MAP_BLOCKSIZE;
v3pos_t block_pos_nodes = block_coord * MAP_BLOCKSIZE;

if (mesh) {
mesh_sphere_center = intToFloat(block_pos_nodes, BS)
Expand Down Expand Up @@ -357,7 +358,7 @@ void ClientMap::updateDrawList()

// Calculate the vector from the camera block to the current block
// We use it to determine through which sides of the current block we can continue the search
v3s16 look = block_coord - camera_block;
v3bpos_t look = block_coord - camera_block;

// Occluded near sides will further occlude the far sides
u8 visible_outer_sides = flags & 0x07;
Expand Down Expand Up @@ -422,7 +423,7 @@ void ClientMap::updateDrawList()

// Calculate vector from camera to mapblock center. Because we only need relation between
// coordinates we scale by 2 to avoid precision loss.
v3s16 precise_look = 2 * (block_pos_nodes - cam_pos_nodes) + MAP_BLOCKSIZE - 1;
v3bpos_t precise_look = 2 * (block_pos_nodes - cam_pos_nodes) + MAP_BLOCKSIZE - 1;

// dominant axis flag
u8 dominant_axis = (abs(precise_look.X) > abs(precise_look.Y) && abs(precise_look.X) > abs(precise_look.Z)) |
Expand All @@ -448,7 +449,7 @@ void ClientMap::updateDrawList()
bool side_visible = ((near_transparency & adjacent_sides) | (near_transparency & my_side & dominant_axis)) != 0;
side_visible = side_visible && ((far_side_mask & transparent_sides) != 0);

v3s16 next_pos = block_coord;
v3bpos_t next_pos = block_coord;
next_pos[axis] += next_pos_offset;

// If a side is a see-through, mark the next block's side as visible, and queue
Expand Down Expand Up @@ -483,10 +484,10 @@ void ClientMap::updateDrawList()

void ClientMap::touchMapBlocks()
{
v3s16 cam_pos_nodes = floatToInt(m_camera_position, BS);
v3pos_t cam_pos_nodes = floatToInt(m_camera_position, BS);

v3s16 p_blocks_min;
v3s16 p_blocks_max;
v3bpos_t p_blocks_min;
v3bpos_t p_blocks_max;
getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max);

// Number of blocks currently loaded by the client
Expand Down
16 changes: 8 additions & 8 deletions src/client/mapblock_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1586,20 +1586,20 @@ video::SColor encode_light(u16 light, u8 emissive_light)

u8 get_solid_sides(MeshMakeData *data)
{
v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
v3pos_t blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
const NodeDefManager *ndef = data->m_client->ndef();

u8 result = 0x3F; // all sides solid;

for (s16 i = 0; i < MAP_BLOCKSIZE && result != 0; i++)
for (s16 j = 0; j < MAP_BLOCKSIZE && result != 0; j++) {
v3s16 positions[6] = {
v3s16(0, i, j),
v3s16(MAP_BLOCKSIZE - 1, i, j),
v3s16(i, 0, j),
v3s16(i, MAP_BLOCKSIZE - 1, j),
v3s16(i, j, 0),
v3s16(i, j, MAP_BLOCKSIZE - 1)
v3pos_t positions[6] = {
v3pos_t(0, i, j),
v3pos_t(MAP_BLOCKSIZE - 1, i, j),
v3pos_t(i, 0, j),
v3pos_t(i, MAP_BLOCKSIZE - 1, j),
v3pos_t(i, j, 0),
v3pos_t(i, j, MAP_BLOCKSIZE - 1)
};

for (u8 k = 0; k < 6; k++) {
Expand Down
5 changes: 3 additions & 2 deletions src/client/mesh_generator_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/

#include "mesh_generator_thread.h"
#include "irr_v3d.h"
#include "settings.h"
#include "profiler.h"
#include "client.h"
Expand Down Expand Up @@ -106,7 +107,7 @@ bool MeshUpdateQueue::addBlock(Map *map, v3bpos_t p, bool ack_block_to_server, b
cached_blocks.reserve(3*3*3);
cached_blocks.push_back(main_block);
main_block->refGrab();
for (v3s16 dp : g_26dirs) {
for (v3pos_t dp : g_26dirs) {
MapBlock *block = map->getBlockNoCreateNoEx(p + dp);
cached_blocks.push_back(block);
if (block)
Expand Down Expand Up @@ -185,7 +186,7 @@ void MeshUpdateQueue::fillDataFromMapBlocks(QueuedMeshUpdate *q)
MeshUpdateWorkerThread
*/

MeshUpdateWorkerThread::MeshUpdateWorkerThread(MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset) :
MeshUpdateWorkerThread::MeshUpdateWorkerThread(MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3pos_t *camera_offset) :
UpdateThread("Mesh"), m_queue_in(queue_in), m_manager(manager), m_camera_offset(camera_offset)
{
m_generation_interval = g_settings->getU16("mesh_generation_interval");
Expand Down
7 changes: 4 additions & 3 deletions src/client/mesh_generator_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <mutex>
#include <unordered_map>
#include <unordered_set>
#include "irr_v3d.h"
#include "mapblock_mesh.h"
#include "threading/mutex_auto_lock.h"
#include "util/thread.h"
Expand Down Expand Up @@ -68,7 +69,7 @@ class MeshUpdateQueue
QueuedMeshUpdate *pop();

// Marks a position as finished, unblocking the next update
void done(v3s16 pos);
void done(v3pos_t pos);

u32 size()
{
Expand Down Expand Up @@ -109,15 +110,15 @@ class MeshUpdateManager;
class MeshUpdateWorkerThread : public UpdateThread
{
public:
MeshUpdateWorkerThread(MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset);
MeshUpdateWorkerThread(MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3pos_t *camera_offset);

protected:
virtual void doUpdate();

private:
MeshUpdateQueue *m_queue_in;
MeshUpdateManager *m_manager;
v3s16 *m_camera_offset;
v3pos_t *m_camera_offset;

// TODO: Add callback to update these when g_settings changes
int m_generation_interval;
Expand Down
11 changes: 7 additions & 4 deletions src/dummymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#pragma once

#include "irr_v2d.h"
#include "irr_v3d.h"
#include "irrlichttypes.h"
#include "map.h"
#include "mapsector.h"

class DummyMap : public Map
{
public:
DummyMap(IGameDef *gamedef, v3s16 bpmin, v3s16 bpmax): Map(gamedef)
DummyMap(IGameDef *gamedef, v3bpos_t bpmin, v3bpos_t bpmax): Map(gamedef)
{
for (s16 z = bpmin.Z; z <= bpmax.Z; z++)
for (s16 x = bpmin.X; x <= bpmax.X; x++) {
v2s16 p2d(x, z);
for (bpos_t z = bpmin.Z; z <= bpmax.Z; z++)
for (bpos_t x = bpmin.X; x <= bpmax.X; x++) {
v2bpos_t p2d(x, z);
MapSector *sector = new MapSector(this, p2d, gamedef);
m_sectors[p2d] = sector;
for (s16 y = bpmin.Y; y <= bpmax.Y; y++)
Expand Down
4 changes: 2 additions & 2 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ void ServerMap::transformLiquids(std::map<v3bpos_t, MapBlock*> &modified_blocks,

std::vector<std::pair<v3pos_t, MapNode> > changed_nodes;

std::vector<v3s16> check_for_falling;
std::vector<v3pos_t> check_for_falling;

u32 liquid_loop_max = g_settings->getS32("liquid_loop_max");
u32 loop_max = liquid_loop_max;
Expand Down Expand Up @@ -843,7 +843,7 @@ void ServerMap::transformLiquids(std::map<v3bpos_t, MapBlock*> &modified_blocks,

voxalgo::update_lighting_nodes(this, changed_nodes, modified_blocks);

for (const v3s16 &p : check_for_falling) {
for (const v3pos_t &p : check_for_falling) {
env->getScriptIface()->check_for_falling(p);
}

Expand Down
6 changes: 3 additions & 3 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ struct MapEditEvent
MapEditEvent() = default;

// Sets the event's position and marks the block as modified.
void setPositionModified(v3s16 pos)
void setPositionModified(v3pos_t pos)
{
assert(modified_blocks.empty()); // only meant for initialization (once)
p = pos;
modified_blocks.push_back(getNodeBlockPos(pos));
}

void setModifiedBlocks(const std::map<v3s16, MapBlock *> blocks)
void setModifiedBlocks(const std::map<v3bpos_t, MapBlock *> blocks)
{
assert(modified_blocks.empty()); // only meant for initialization (once)
modified_blocks.reserve(blocks.size());
Expand Down Expand Up @@ -309,7 +309,7 @@ class Map /*: public NodeContainer*/
}
}

bool isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes);
bool isBlockOccluded(MapBlock *block, v3pos_t cam_pos_nodes);
protected:
IGameDef *m_gamedef;

Expand Down
7 changes: 4 additions & 3 deletions src/mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapblock.h"

#include <sstream>
#include "irr_v3d.h"
#include "map.h"
#include "light.h"
#include "nodedef.h"
Expand Down Expand Up @@ -125,13 +126,13 @@ bool MapBlock::saveStaticObject(u16 id, const StaticObject &obj, u32 reason)
}

// This method is only for Server, don't call it on client
void MapBlock::step(float dtime, const std::function<bool(v3s16, MapNode, f32)> &on_timer_cb)
void MapBlock::step(float dtime, const std::function<bool(v3pos_t, MapNode, f32)> &on_timer_cb)
{
// Run script callbacks for elapsed node_timers
std::vector<NodeTimer> elapsed_timers = m_node_timers.step(dtime);
if (!elapsed_timers.empty()) {
MapNode n;
v3s16 p;
v3pos_t p;
for (const NodeTimer &elapsed_timer : elapsed_timers) {
n = getNodeNoEx(elapsed_timer.position);
p = elapsed_timer.position + getPosRelative();
Expand Down Expand Up @@ -910,7 +911,7 @@ std::string analyze_block(MapBlock *block)
for(s16 y0=0; y0<MAP_BLOCKSIZE; y0++)
for(s16 x0=0; x0<MAP_BLOCKSIZE; x0++)
{
v3s16 p(x0,y0,z0);
v3pos_t p(x0,y0,z0);
MapNode n = block->getNodeNoEx(p);
content_t c = n.getContent();
if(c == CONTENT_IGNORE)
Expand Down
2 changes: 1 addition & 1 deletion src/mapblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class MapBlock
bool onObjectsActivation();
bool saveStaticObject(u16 id, const StaticObject &obj, u32 reason);

void step(float dtime, const std::function<bool(v3s16, MapNode, f32)> &on_timer_cb);
void step(float dtime, const std::function<bool(v3pos_t, MapNode, f32)> &on_timer_cb);

////
//// Timestamp (see m_timestamp)
Expand Down
7 changes: 4 additions & 3 deletions src/mapgen/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/

#include <cmath>
#include "irrlichttypes.h"
#include "mapgen.h"
#include "voxel.h"
#include "noise.h"
Expand Down Expand Up @@ -1066,7 +1067,7 @@ void MapgenParams::writeParams(Settings *settings) const
s32 MapgenParams::getSpawnRangeMax()
{
if (!m_mapgen_edges_calculated) {
std::pair<s16, s16> edges = get_mapgen_edges(mapgen_limit, chunksize);
std::pair<pos_t, pos_t> edges = get_mapgen_edges(mapgen_limit, chunksize);
mapgen_edge_min = edges.first;
mapgen_edge_max = edges.second;
m_mapgen_edges_calculated = true;
Expand All @@ -1076,7 +1077,7 @@ s32 MapgenParams::getSpawnRangeMax()
}


std::pair<s16, s16> get_mapgen_edges(s16 mapgen_limit, s16 chunksize)
std::pair<pos_t, pos_t> get_mapgen_edges(pos_t mapgen_limit, s16 chunksize)
{
// Central chunk offset, in blocks
s16 ccoff_b = -chunksize / 2;
Expand All @@ -1100,5 +1101,5 @@ std::pair<s16, s16> get_mapgen_edges(s16 mapgen_limit, s16 chunksize)
pos_t numcmin = MYMAX((ccfmin - mapgen_limit_min) / csize_n, 0);
pos_t numcmax = MYMAX((mapgen_limit_max - ccfmax) / csize_n, 0);
// Mapgen edges, in nodes
return std::pair<s16, s16>(ccmin - numcmin * csize_n, ccmax + numcmax * csize_n);
return std::pair<pos_t, pos_t>(ccmin - numcmin * csize_n, ccmax + numcmax * csize_n);
}
Loading

0 comments on commit f8b7f47

Please sign in to comment.