Files
LuaVox/Src/Server/World.cpp

94 lines
2.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "World.hpp"
#include "TOSLib.hpp"
#include <memory>
namespace LV::Server {
World::World(DefWorldId_t defId)
: DefId(defId)
{
}
World::~World() {
}
std::vector<Pos::GlobalRegion> World::onCEC_RegionsEnter(ContentEventController *cec, const std::vector<Pos::GlobalRegion>& enter, WorldId_t wId) {
std::vector<Pos::GlobalRegion> out;
TOS::Logger("Test").debug() << "Start";
for(const Pos::GlobalRegion &pos : enter) {
auto iterRegion = Regions.find(pos);
if(iterRegion == Regions.end()) {
out.push_back(pos);
continue;
}
auto &region = *iterRegion->second;
region.CECs.push_back(cec);
// Отправить клиенту информацию о чанках и сущностях
std::unordered_map<Pos::bvec4u, const std::vector<VoxelCube>*> voxels;
std::unordered_map<Pos::bvec4u, const Node*> nodes;
for(auto& [key, value] : region.Voxels) {
voxels[key] = &value;
}
for(int z = 0; z < 4; z++)
for(int y = 0; y < 4; y++)
for(int x = 0; x < 4; x++) {
nodes[Pos::bvec4u(x, y, z)] = (const Node*) &region.Nodes[0][0][0][x][y][z];
}
cec->onChunksUpdate_Voxels(wId, pos, voxels);
cec->onChunksUpdate_Nodes(wId, pos, nodes);
}
TOS::Logger("Test").debug() << "End";
return out;
}
void World::onCEC_RegionsLost(ContentEventController *cec, const std::vector<Pos::GlobalRegion> &lost) {
for(const Pos::GlobalRegion &pos : lost) {
auto region = Regions.find(pos);
if(region == Regions.end())
continue;
std::vector<ContentEventController*> &CECs = region->second->CECs;
for(size_t iter = 0; iter < CECs.size(); iter++) {
if(CECs[iter] == cec) {
CECs.erase(CECs.begin()+iter);
break;
}
}
}
}
World::SaveUnloadInfo World::onStepDatabaseSync() {
return {};
}
void World::pushRegions(std::vector<std::pair<Pos::GlobalRegion, RegionIn>> regions) {
for(auto& [key, value] : regions) {
Region &region = *(Regions[key] = std::make_unique<Region>());
region.Voxels = std::move(value.Voxels);
Node *ptr = (Node*) region.Nodes;
for(std::array<Node, 16*16*16>& nodes : value.Nodes) {
std::copy(nodes.data(), nodes.data()+16*16*16, ptr);
ptr += 16*16*16;
}
}
}
void World::onUpdate(GameServer *server, float dtime) {
}
}