53 lines
1.7 KiB
C++
53 lines
1.7 KiB
C++
#include "LocalUniverse.hpp"
|
|
|
|
#include "../../core/data/math.hpp"
|
|
#include "../contouring/Abstract.hpp"
|
|
#include "../Window.hpp"
|
|
#include "../../core/utils/logger.hpp"
|
|
#include "../../core/world/Area.hpp"
|
|
|
|
using namespace world::client;
|
|
|
|
LocalUniverse::LocalUniverse(server_handle *const handle, const std::string& contour): Universe(contour), handle(handle) {
|
|
assert(handle != nullptr);
|
|
for (auto i = 0; i < 500 && !handle->running; i++) {
|
|
LOG_D("Waiting local server startup");
|
|
Window::wait();
|
|
}
|
|
handle->onUpdate = std::function([&](const area_<chunk_pos> &pos, const chunk_pos &offset, const world::ChunkContainer &data, geometry::Faces neighbors) {
|
|
contouring->onUpdate(pos, offset, data, neighbors);
|
|
});
|
|
}
|
|
LocalUniverse::~LocalUniverse() {
|
|
handle->running = false;
|
|
}
|
|
|
|
void LocalUniverse::update(voxel_pos pos, float) {
|
|
if (handle->teleport.has_value() && onTeleport) {
|
|
pos = handle->teleport.value();
|
|
onTeleport(pos);
|
|
handle->teleport = std::nullopt;
|
|
}
|
|
|
|
const auto cur_chunk = glm::divide(pos);
|
|
const auto chunkChange = cur_chunk != last_chunk;
|
|
last_chunk = cur_chunk;
|
|
|
|
if(chunkChange) {
|
|
for(const auto& area: *handle->areas) {
|
|
const chunk_pos diff = glm::divide(pos - area.second->getOffset().as_voxel());
|
|
for(const auto& chunk: area.second->getChunks()) {
|
|
contouring->onNotify(std::make_pair(area.first, chunk.first), diff, area.second->getChunks());
|
|
}
|
|
}
|
|
}
|
|
|
|
contouring->update(pos, *handle->areas);
|
|
}
|
|
|
|
void LocalUniverse::emit(const action::packet &packet) {
|
|
handle->emit(packet);
|
|
}
|
|
Universe::ray_result LocalUniverse::raycast(const geometry::Ray& ray) const {
|
|
return handle->raycast(ray);
|
|
} |