mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-10 21:41:50 +00:00
move Chunks from Level to Player
This commit is contained in:
parent
b7664b4188
commit
1c18c02092
40 changed files with 450 additions and 220 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue