move Chunks from Level to Player
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
#include "data/dv_util.hpp"
|
||||
#include "items/Inventories.hpp"
|
||||
#include "items/Inventory.hpp"
|
||||
#include "lighting/Lighting.hpp"
|
||||
#include "objects/Entities.hpp"
|
||||
#include "objects/Player.hpp"
|
||||
#include "objects/Players.hpp"
|
||||
@@ -12,7 +11,6 @@
|
||||
#include "physics/PhysicsSolver.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "voxels/Chunk.hpp"
|
||||
#include "voxels/Chunks.hpp"
|
||||
#include "voxels/GlobalChunks.hpp"
|
||||
#include "window/Camera.hpp"
|
||||
#include "LevelEvents.hpp"
|
||||
@@ -60,31 +58,11 @@ Level::Level(
|
||||
events->listen(LevelEventType::EVT_CHUNK_HIDDEN, [this](LevelEventType, Chunk* chunk) {
|
||||
chunksStorage->decref(chunk);
|
||||
});
|
||||
|
||||
uint matrixSize =
|
||||
(settings.chunks.loadDistance.get() + settings.chunks.padding.get()) *
|
||||
2;
|
||||
chunks = std::make_unique<Chunks>(
|
||||
matrixSize, matrixSize, 0, 0, events.get(), content->getIndices()
|
||||
);
|
||||
|
||||
inventories = std::make_unique<Inventories>(*this);
|
||||
}
|
||||
|
||||
Level::~Level() = default;
|
||||
|
||||
void Level::loadMatrix(int32_t x, int32_t z, uint32_t radius) {
|
||||
chunks->setCenter(x, z);
|
||||
uint32_t diameter = std::min(
|
||||
radius * 2LL,
|
||||
(settings.chunks.loadDistance.get() + settings.chunks.padding.get()) *
|
||||
2LL
|
||||
);
|
||||
if (chunks->getWidth() != diameter) {
|
||||
chunks->resize(diameter, diameter);
|
||||
}
|
||||
}
|
||||
|
||||
World* Level::getWorld() {
|
||||
return world.get();
|
||||
}
|
||||
|
||||
@@ -9,11 +9,9 @@
|
||||
|
||||
class Content;
|
||||
class World;
|
||||
class Chunks;
|
||||
class Entities;
|
||||
class Inventories;
|
||||
class LevelEvents;
|
||||
class Lighting;
|
||||
class PhysicsSolver;
|
||||
class GlobalChunks;
|
||||
class Camera;
|
||||
@@ -27,7 +25,6 @@ class Level {
|
||||
public:
|
||||
const Content* const content;
|
||||
|
||||
std::unique_ptr<Chunks> chunks;
|
||||
std::unique_ptr<GlobalChunks> chunksStorage;
|
||||
std::unique_ptr<Inventories> inventories;
|
||||
|
||||
@@ -44,8 +41,6 @@ public:
|
||||
);
|
||||
~Level();
|
||||
|
||||
void loadMatrix(int32_t x, int32_t z, uint32_t radius);
|
||||
|
||||
World* getWorld();
|
||||
|
||||
const World* getWorld() const;
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
#include "voxels/Block.hpp"
|
||||
#include "voxels/GlobalChunks.hpp"
|
||||
#include "voxels/VoxelsVolume.hpp"
|
||||
#include "voxels/blocks_agent.hpp"
|
||||
#include "world/Level.hpp"
|
||||
#include "core_defs.hpp"
|
||||
|
||||
std::unique_ptr<VoxelFragment> VoxelFragment::create(
|
||||
Level* level,
|
||||
const Level& level,
|
||||
const glm::ivec3& a,
|
||||
const glm::ivec3& b,
|
||||
bool crop,
|
||||
@@ -26,7 +27,7 @@ std::unique_ptr<VoxelFragment> VoxelFragment::create(
|
||||
if (crop) {
|
||||
VoxelsVolume volume(size.x, size.y, size.z);
|
||||
volume.setPosition(start.x, start.y, start.z);
|
||||
level->chunks->getVoxels(&volume);
|
||||
blocks_agent::get_voxels(*level.chunksStorage, &volume);
|
||||
|
||||
auto end = start + size;
|
||||
|
||||
@@ -51,14 +52,14 @@ std::unique_ptr<VoxelFragment> VoxelFragment::create(
|
||||
|
||||
VoxelsVolume volume(size.x, size.y, size.z);
|
||||
volume.setPosition(start.x, start.y, start.z);
|
||||
level->chunks->getVoxels(&volume);
|
||||
blocks_agent::get_voxels(*level.chunksStorage, &volume);
|
||||
|
||||
auto volVoxels = volume.getVoxels();
|
||||
std::vector<voxel> voxels(size.x * size.y * size.z);
|
||||
|
||||
std::vector<std::string> blockNames {CORE_AIR};
|
||||
std::unordered_map<blockid_t, blockid_t> blocksRegistered {{0, 0}};
|
||||
auto contentIndices = level->content->getIndices();
|
||||
auto contentIndices = level.content->getIndices();
|
||||
for (size_t i = 0 ; i < voxels.size(); i++) {
|
||||
blockid_t id = volVoxels[i].id;
|
||||
blockid_t index;
|
||||
@@ -170,7 +171,7 @@ void VoxelFragment::prepare(const Content& content) {
|
||||
}
|
||||
|
||||
void VoxelFragment::place(
|
||||
Chunks& chunks, const glm::ivec3& offset, ubyte rotation
|
||||
GlobalChunks& chunks, const glm::ivec3& offset, ubyte rotation
|
||||
) {
|
||||
auto& structVoxels = getRuntimeVoxels();
|
||||
for (int y = 0; y < size.y; y++) {
|
||||
@@ -185,7 +186,9 @@ void VoxelFragment::place(
|
||||
const auto& structVoxel =
|
||||
structVoxels[vox_index(x, y, z, size.x, size.z)];
|
||||
if (structVoxel.id) {
|
||||
chunks.set(sx, sy, sz, structVoxel.id, structVoxel.state);
|
||||
blocks_agent::set(
|
||||
chunks, sx, sy, sz, structVoxel.id, structVoxel.state
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ inline constexpr int STRUCTURE_FORMAT_VERSION = 1;
|
||||
|
||||
class Level;
|
||||
class Content;
|
||||
class Chunks;
|
||||
class GlobalChunks;
|
||||
|
||||
class VoxelFragment : public Serializable {
|
||||
glm::ivec3 size;
|
||||
@@ -45,13 +45,13 @@ public:
|
||||
/// @brief Place fragment to the world
|
||||
/// @param offset target location
|
||||
/// @param rotation rotation index
|
||||
void place(Chunks& chunks, const glm::ivec3& offset, ubyte rotation);
|
||||
void place(GlobalChunks& chunks, const glm::ivec3& offset, ubyte rotation);
|
||||
|
||||
/// @brief Create structure copy rotated 90 deg. clockwise
|
||||
std::unique_ptr<VoxelFragment> rotated(const Content& content) const;
|
||||
|
||||
static std::unique_ptr<VoxelFragment> create(
|
||||
Level* level,
|
||||
const Level& level,
|
||||
const glm::ivec3& a,
|
||||
const glm::ivec3& b,
|
||||
bool crop,
|
||||
|
||||
Reference in New Issue
Block a user