1
0
Fork 0
Univerxel/src/core/world/EdittableChunk.hpp

54 lines
1.5 KiB
C++

#pragma once
#include "Chunk.hpp"
#include "../geometry/Faces.hpp"
using namespace geometry;
namespace world::client {
class EdittableChunk: public virtual world::Chunk {
public:
EdittableChunk(std::istream &is);
/// Create from average
EdittableChunk(Voxel val);
virtual ~EdittableChunk();
/// Update voxels
/// @return if modified neighbors to update
virtual std::optional<Faces> update(float deltaTime, bool animate);
/// Notify for render
inline void invalidate(Faces faces) {
upToDate = false;
toUpdate = toUpdate | faces;
}
void invalidate(chunk_voxel_idx idx);
void apply(const Chunk::Edit &edit);
/// Get pending changes
const std::vector<Chunk::Edit> &getEdits() const { return edits; }
static std::optional<chunk_voxel_idx> getNeighborIdx(chunk_voxel_idx idx, Face dir);
constexpr bool isTrusted(bool allowMajorant) const { return !isAverage || (allowMajorant && isMajorant); }
void unsetMajorant() {
assert(isMajorant);
isMajorant = false;
}
protected:
EdittableChunk();
/// Is temporary average
const bool isAverage = false;
/// Is temporary full valued
bool isMajorant = false;
/// Temporary changes
std::vector<Chunk::Edit> edits;
/// Require update
bool upToDate = true;
/// Neighbors to update
Faces toUpdate = Faces::None;
};
}