parent
54bfd5f5b4
commit
49da2ad701
|
@ -72,8 +72,8 @@ endif()
|
|||
target_compile_definitions(${MAIN_EXEC_NAME} PUBLIC SOL_ALL_SAFETIES_ON)
|
||||
|
||||
# Test Build
|
||||
#add_subdirectory(test)
|
||||
#add_executable(${TEST_EXEC_NAME} test/Main.cpp)
|
||||
#
|
||||
#target_link_libraries(${TEST_EXEC_NAME} Zepha_Core)
|
||||
#target_link_libraries(${TEST_EXEC_NAME} zeusTest)
|
||||
add_subdirectory(test)
|
||||
add_executable(${TEST_EXEC_NAME} test/Main.cpp)
|
||||
|
||||
target_link_libraries(${TEST_EXEC_NAME} Zepha_Core)
|
||||
target_link_libraries(${TEST_EXEC_NAME} Zepha_Test)
|
||||
|
|
|
@ -91,7 +91,7 @@ set(ZEPHA_SRC
|
|||
server/world/WorldGenStream.h
|
||||
game/scene/world/WorldInterpolationStream.cpp
|
||||
game/scene/world/WorldInterpolationStream.h
|
||||
util/TransPos.h
|
||||
util/Space.h
|
||||
game/scene/world/MeshGenStream.cpp
|
||||
game/scene/world/MeshGenStream.h
|
||||
util/Vec.h
|
||||
|
|
|
@ -173,7 +173,7 @@ void MapGen::buildDensityMap(MapGenJob &job, const glm::vec3& worldPos) {
|
|||
|
||||
glm::vec3 lp;
|
||||
for (int m = 0; m < 4096; m++) {
|
||||
VecUtils::indAssignVec(m, lp);
|
||||
Vec::indAssignVec(m, lp);
|
||||
job.density[m] = sTerrainFinal.get(lp) - (lp.y + worldPos.y * 16);
|
||||
}
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ void MapGen::buildElevationMap(std::array<std::pair<MapGenJob, BlockChunk *>, 64
|
|||
|
||||
short depth = 16;
|
||||
|
||||
if (chunk.first.density[VecUtils::vecToInd(x, 15, z)] > 0) {
|
||||
if (chunk.first.density[Space::Block::index({x, 15, z})] > 0) {
|
||||
if (localPos.y < 3) {
|
||||
unsigned short index = localPos.x + 4 * (localPos.y + 1 + 4 * localPos.z);
|
||||
upperChunk = &chunks[index].first;
|
||||
|
@ -200,7 +200,7 @@ void MapGen::buildElevationMap(std::array<std::pair<MapGenJob, BlockChunk *>, 64
|
|||
}
|
||||
|
||||
for (int j = 0; j < 16; j++) {
|
||||
int ind = VecUtils::vecToInd(x, j, z);
|
||||
int ind = Space::Block::index({x, j, z});
|
||||
|
||||
if (upperChunk->density[ind] <= 0) {
|
||||
depth = j;
|
||||
|
@ -211,7 +211,7 @@ void MapGen::buildElevationMap(std::array<std::pair<MapGenJob, BlockChunk *>, 64
|
|||
else depth = 0;
|
||||
|
||||
for (int y = 15; y >= 0; y--) {
|
||||
int ind = VecUtils::vecToInd(x, y, z);
|
||||
int ind = Space::Block::index({x, y, z});
|
||||
|
||||
if (chunk.first.density[ind] > 0) {
|
||||
depth = std::min(depth + 1, 16);
|
||||
|
@ -233,7 +233,7 @@ void MapGen::populateChunk(std::pair<MapGenJob, BlockChunk*>& chunk, const glm::
|
|||
glm::vec3 lp;
|
||||
|
||||
for (int m = 0; m < 4096; m++) {
|
||||
VecUtils::indAssignVec(m, lp);
|
||||
Vec::indAssignVec(m, lp);
|
||||
|
||||
auto biome = biomes.getBiomeAt(sTemperature.get(lp), sHumidity.get(lp), sRoughness.get(lp));
|
||||
chunk.second->biomes[m] = biome.index;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <array>
|
||||
#include <vector>
|
||||
#include <glm/vec3.hpp>
|
||||
#include "../../util/TransPos.h"
|
||||
#include "../../util/Space.h"
|
||||
|
||||
struct MapGenJob {
|
||||
std::array<float, 4096> density {};
|
||||
|
|
|
@ -97,25 +97,26 @@ void DebugGui::update(Player& player, LocalWorld& world, LocalDefs& defs, double
|
|||
}
|
||||
|
||||
{ //Top-left Data
|
||||
glm::vec3 footPos = TransPos::roundPos(player.getPos()) - glm::vec3(0, 0.02, 0);
|
||||
glm::vec3 footPos = glm::floor(player.getPos()) - glm::vec3(0, 0.02, 0);
|
||||
|
||||
unsigned int blockID = world.getBlock(footPos);
|
||||
std::string on = defs.defs().fromId(blockID).identifier;
|
||||
|
||||
unsigned int biomeID = world.getBiome(TransPos::roundPos(player.getPos()));
|
||||
unsigned int biomeID = world.getBiome(glm::floor(player.getPos()));
|
||||
std::string biome = defs.gen().biomeFromId(biomeID).identifier;
|
||||
|
||||
glm::vec3 playerPos = TransPos::roundPos(player.getPos());
|
||||
glm::vec3 chunkPos = TransPos::chunkFromVec(playerPos);
|
||||
glm::vec3 playerPos = glm::floor(player.getPos());
|
||||
glm::vec3 chunkPos = Space::Chunk::world::fromBlock(playerPos);
|
||||
|
||||
//Block Coordinates offset from respective container
|
||||
glm::vec3 posOffsetFromChunk = TransPos::chunkLocalFromVec(playerPos);
|
||||
glm::vec3 posOffsetFromBlock = TransPos::mapBlockLocalFromVec(playerPos);
|
||||
glm::vec3 posOffsetFromRegion = TransPos::regionLocalFromVec(playerPos);
|
||||
//TODO: Reimplement these functions
|
||||
glm::vec3 posOffsetFromChunk = Space::Block::relative::toChunk(playerPos);
|
||||
glm::vec3 posOffsetFromBlock = Space::Block::relative::toMapBlock(playerPos);
|
||||
glm::vec3 posOffsetFromRegion = Space::Block::relative::toRegion(playerPos);
|
||||
|
||||
glm::vec3 chunkCoordinate = TransPos::Dimension::chunkOffsetFromMapBlock(chunkPos);
|
||||
glm::vec3 mapBlockCoordinate = TransPos::Dimension::mapBlockOffsetFromRegion(chunkPos);
|
||||
glm::vec3 regionCoordinate = TransPos::Dimension::regionFromVec(chunkPos);
|
||||
glm::vec3 chunkCoordinate = chunkPos;
|
||||
glm::vec3 mapBlockCoordinate = Space::MapBlock::world::fromChunk(chunkPos);
|
||||
glm::vec3 regionCoordinate = Space::Region::world::fromChunk(chunkPos);
|
||||
|
||||
std::ostringstream str;
|
||||
|
||||
|
@ -141,18 +142,15 @@ void DebugGui::update(Player& player, LocalWorld& world, LocalDefs& defs, double
|
|||
|
||||
PointedThing thing = player.getPointedThing();
|
||||
if (thing.thing == PointedThing::Thing::BLOCK) {
|
||||
std::string face = "NONE";
|
||||
if (thing.thing == PointedThing::Thing::BLOCK) {
|
||||
Dir faceDir = thing.target.block.face;
|
||||
std::string face =
|
||||
(faceDir == Dir::TOP) ? "TOP" :
|
||||
(faceDir == Dir::BOTTOM) ? "BOTTOM" :
|
||||
(faceDir == Dir::LEFT) ? "LEFT" :
|
||||
(faceDir == Dir::RIGHT) ? "RIGHT" :
|
||||
(faceDir == Dir::FRONT) ? "FRONT" :
|
||||
(faceDir == Dir::BACK) ? "BACK" :
|
||||
"NONE";
|
||||
}
|
||||
Dir faceDir = thing.target.block.face;
|
||||
std::string face =
|
||||
(faceDir == Dir::TOP) ? "TOP" :
|
||||
(faceDir == Dir::BOTTOM) ? "BOTTOM" :
|
||||
(faceDir == Dir::LEFT) ? "LEFT" :
|
||||
(faceDir == Dir::RIGHT) ? "RIGHT" :
|
||||
(faceDir == Dir::FRONT) ? "FRONT" :
|
||||
(faceDir == Dir::BACK) ? "BACK" :
|
||||
"NONE";
|
||||
str << "Pointing At: " << defs.defs().blockFromId(thing.target.block.blockId).identifier << std::endl;
|
||||
str << "Pointed Position: " << vecToString(thing.target.block.pos) << std::endl;
|
||||
str << "Pointed Face: " << face << std::endl;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <sstream>
|
||||
#include "../graph/window/Window.h"
|
||||
#include "../graph/drawable/DrawableGroup.h"
|
||||
#include "../../util/TransPos.h"
|
||||
#include "../../util/Space.h"
|
||||
#include "../../util/Util.h"
|
||||
#include "../../util/Ray.h"
|
||||
#include "components/compound/GUILabelledGraph.h"
|
||||
|
|
|
@ -133,8 +133,8 @@ int LocalWorld::getMeshChunkCount() {
|
|||
}
|
||||
|
||||
unsigned int LocalWorld::getBlock(glm::vec3 pos) {
|
||||
auto chunkPos = TransPos::chunkFromVec(TransPos::roundPos(pos));
|
||||
auto local = TransPos::chunkLocalFromVec(TransPos::roundPos(pos));
|
||||
auto chunkPos = Space::Chunk::world::fromBlock(pos);
|
||||
auto local = Space::Block::relative::toChunk(pos);
|
||||
|
||||
auto chunk = getChunk(chunkPos);
|
||||
if (chunk != nullptr) return chunk->getBlock(local);
|
||||
|
@ -142,8 +142,8 @@ unsigned int LocalWorld::getBlock(glm::vec3 pos) {
|
|||
}
|
||||
|
||||
unsigned short LocalWorld::getBiome(glm::vec3 pos) {
|
||||
auto chunkPos = TransPos::chunkFromVec(TransPos::roundPos(pos));
|
||||
auto local = TransPos::chunkLocalFromVec(TransPos::roundPos(pos));
|
||||
auto chunkPos = Space::Chunk::world::fromBlock(pos);
|
||||
auto local = Space::Block::relative::toChunk(pos);
|
||||
|
||||
auto chunk = getChunk(chunkPos);
|
||||
if (chunk != nullptr) return chunk->getBiome(local);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "../../../def/LocalDefinitionAtlas.h"
|
||||
#include "../../../world/chunk/BlockChunk.h"
|
||||
#include "../../../def/gen/MapGen.h"
|
||||
#include "../../../util/TransPos.h"
|
||||
#include "../../../util/Space.h"
|
||||
#include "../../../util/Vec.h"
|
||||
#include "../../../world/LocalDimension.h"
|
||||
#include "../../../def/LocalDefs.h"
|
||||
|
|
|
@ -64,7 +64,7 @@ std::vector<MeshDetails*> MeshGenStream::update() {
|
|||
u.thisChunk = shared_ptr<BlockChunk>(chunk);
|
||||
|
||||
int ind = 0;
|
||||
for (glm::vec3 dir : VecUtils::getCardinalVectors()) {
|
||||
for (glm::vec3 dir : Vec::cardinalVectors) {
|
||||
std::shared_ptr<BlockChunk> adjacent = dimension.getChunk(pos + dir);
|
||||
u.adjacentChunks[ind++] = shared_ptr<BlockChunk>(adjacent);
|
||||
if (adjacent == nullptr) goto breakAddTask;
|
||||
|
|
|
@ -66,6 +66,6 @@ private:
|
|||
|
||||
std::array<NoiseSample, 3> noiseSampler;
|
||||
std::vector<glm::vec3> queuedTasks;
|
||||
std::unordered_set<glm::vec3, VecUtils::compareFunc> queuedMap;
|
||||
std::unordered_set<glm::vec3, Vec::compareFunc> queuedMap;
|
||||
};
|
||||
|
||||
|
|
|
@ -115,9 +115,9 @@ void Player::findPointedThing(InputManager &input) {
|
|||
|
||||
for (Ray ray(this); ray.getLength() < LOOK_DISTANCE; ray.step(LOOK_PRECISION)) {
|
||||
glm::vec3 rayEnd = ray.getEnd();
|
||||
glm::vec3 roundedPos = TransPos::roundPos(rayEnd);
|
||||
glm::vec3 roundedPos = glm::floor(rayEnd);
|
||||
|
||||
auto currChunkPos = TransPos::chunkFromVec(roundedPos);
|
||||
auto currChunkPos = Space::Chunk::world::fromBlock(roundedPos);
|
||||
if (currChunkPos != chunkPos || blockChunk == nullptr) {
|
||||
chunkPos = currChunkPos;
|
||||
blockChunk = world.getChunk(chunkPos);
|
||||
|
@ -125,7 +125,7 @@ void Player::findPointedThing(InputManager &input) {
|
|||
|
||||
unsigned int blockID = 0;
|
||||
if (blockChunk != nullptr) {
|
||||
blockID = blockChunk->getBlock(TransPos::chunkLocalFromVec(roundedPos));
|
||||
blockID = blockChunk->getBlock(Space::Block::relative::toChunk(roundedPos));
|
||||
}
|
||||
|
||||
auto& boxes = defs.defs().blockFromId(blockID).sBoxes;
|
||||
|
|
|
@ -11,7 +11,7 @@ void MeshChunk::create(std::vector<ChunkVertex> &vertices, std::vector<unsigned
|
|||
|
||||
void MeshChunk::draw(Renderer& renderer) {
|
||||
glm::mat4 model = glm::mat4(1.0);
|
||||
model = glm::translate(model, pos * static_cast<float>(TransPos::CHUNK_SIZE));
|
||||
model = glm::translate(model, pos * static_cast<float>(16));
|
||||
renderer.setModelMatrix(model);
|
||||
mesh->draw();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <list>
|
||||
#include "ChunkRenderElem.h"
|
||||
#include "../../../entity/Entity.h"
|
||||
#include "../../../../util/TransPos.h"
|
||||
#include "../../../../util/Space.h"
|
||||
|
||||
class MeshChunk : public ChunkRenderElem, Drawable {
|
||||
public:
|
||||
|
|
|
@ -28,7 +28,7 @@ MeshGenerator::MeshGenerator(MeshDetails* meshDetails, LocalDefs& defs, std::sha
|
|||
glm::vec3 biomeTint = defs.gen().biomeFromId(chunk->getBiome(i)).biomeTint;
|
||||
|
||||
if (model.visible) {
|
||||
VecUtils::indAssignVec(i, off);
|
||||
Vec::indAssignVec(i, off);
|
||||
|
||||
vis = off;
|
||||
|
||||
|
@ -75,16 +75,16 @@ MeshGenerator::MeshGenerator(MeshDetails* meshDetails, LocalDefs& defs, std::sha
|
|||
}
|
||||
|
||||
BlockDef& MeshGenerator::getBlockAt(const glm::vec3 &pos) {
|
||||
if (pos.x < 0 || pos.x >= TransPos::CHUNK_SIZE || pos.y < 0 || pos.y >= TransPos::CHUNK_SIZE || pos.z < 0 || pos.z >= TransPos::CHUNK_SIZE) {
|
||||
if (pos.x < 0 || pos.x >= 16 || pos.y < 0 || pos.y >= 16 || pos.z < 0 || pos.z >= 16) {
|
||||
|
||||
if (pos.x == TransPos::CHUNK_SIZE) return atlas.blockFromId(adjacent[0]->getBlock(pos - glm::vec3(TransPos::CHUNK_SIZE, 0, 0)));
|
||||
if (pos.x == -1) return atlas.blockFromId(adjacent[1]->getBlock(pos + glm::vec3(TransPos::CHUNK_SIZE, 0, 0)));
|
||||
if (pos.x == 16) return atlas.blockFromId(adjacent[0]->getBlock(pos - glm::vec3(16, 0, 0)));
|
||||
if (pos.x == -1) return atlas.blockFromId(adjacent[1]->getBlock(pos + glm::vec3(16, 0, 0)));
|
||||
|
||||
if (pos.y == TransPos::CHUNK_SIZE) return atlas.blockFromId(adjacent[2]->getBlock(pos - glm::vec3(0, TransPos::CHUNK_SIZE, 0)));
|
||||
if (pos.y == -1) return atlas.blockFromId(adjacent[3]->getBlock(pos + glm::vec3(0, TransPos::CHUNK_SIZE, 0)));
|
||||
if (pos.y == 16) return atlas.blockFromId(adjacent[2]->getBlock(pos - glm::vec3(0, 16, 0)));
|
||||
if (pos.y == -1) return atlas.blockFromId(adjacent[3]->getBlock(pos + glm::vec3(0, 16, 0)));
|
||||
|
||||
if (pos.z == TransPos::CHUNK_SIZE) return atlas.blockFromId(adjacent[4]->getBlock(pos - glm::vec3(0, 0, TransPos::CHUNK_SIZE)));
|
||||
if (pos.z == -1) return atlas.blockFromId(adjacent[5]->getBlock(pos + glm::vec3(0, 0, TransPos::CHUNK_SIZE)));
|
||||
if (pos.z == 16) return atlas.blockFromId(adjacent[4]->getBlock(pos - glm::vec3(0, 0, 16)));
|
||||
if (pos.z == -1) return atlas.blockFromId(adjacent[5]->getBlock(pos + glm::vec3(0, 0, 16)));
|
||||
}
|
||||
|
||||
return atlas.blockFromId(chunk->getBlock(pos));
|
||||
|
|
|
@ -14,7 +14,7 @@ sol::table LuaLocalPlayer::get_pos(sol::this_state s) {
|
|||
}
|
||||
|
||||
sol::table LuaLocalPlayer::get_block_pos(sol::this_state s) {
|
||||
glm::vec3 pos = TransPos::roundPos(player.getPos());
|
||||
glm::vec3 pos = glm::floor(player.getPos());
|
||||
return sol::state_view(s).create_table_with("x", pos.x, "y", pos.y, "z", pos.z);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,14 +10,14 @@ ServerPlayer::ServerPlayer(glm::vec3 pos, unsigned int connectID, const std::str
|
|||
connectID(connectID),
|
||||
username(username) {
|
||||
|
||||
mapBlock = TransPos::mapBlockFromVec(pos);
|
||||
mapBlock = Space::MapBlock::world::fromBlock(pos);
|
||||
lastMapBlock = mapBlock - glm::vec3(200); //Force resending of all chunks around getPlayer.
|
||||
changedMapBlocks = true;
|
||||
}
|
||||
|
||||
void ServerPlayer::setPos(glm::vec3 pos) {
|
||||
this->pos = pos;
|
||||
glm::vec3 newMapBlock = TransPos::mapBlockFromVec(pos);
|
||||
glm::vec3 newMapBlock = Space::MapBlock::world::fromBlock(pos);
|
||||
|
||||
if (newMapBlock != mapBlock) {
|
||||
if (!changedMapBlocks) {
|
||||
|
@ -41,5 +41,5 @@ float ServerPlayer::getAngle() {
|
|||
}
|
||||
|
||||
glm::vec3 ServerPlayer::getChunkPos() {
|
||||
return TransPos::chunkFromVec(pos);
|
||||
return Space::Chunk::world::fromBlock(pos);
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
#include "../../util/TransPos.h"
|
||||
#include "../../util/Space.h"
|
||||
|
||||
class ServerPlayer {
|
||||
public:
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
#include "../../util/Timer.h"
|
||||
#include "../../util/Util.h"
|
||||
|
||||
const static int MB_GEN_H = 2;
|
||||
const static int MB_GEN_V = 2;
|
||||
const static int MB_GEN_H = 3;
|
||||
const static int MB_GEN_V = 3;
|
||||
|
||||
ServerWorld::ServerWorld(unsigned int seed, ServerDefs& defs, ServerClients& clients) :
|
||||
seed(seed),
|
||||
|
@ -97,7 +97,7 @@ void ServerWorld::update() {
|
|||
{mapBlock.x - MB_GEN_H, mapBlock.y - MB_GEN_V, mapBlock.z - MB_GEN_H},
|
||||
{mapBlock.x + MB_GEN_H, mapBlock.y + MB_GEN_V, mapBlock.z + MB_GEN_H}};
|
||||
|
||||
if (isInBounds(TransPos::mapBlockFromVec(chunk->pos * 16), bounds)) {
|
||||
if (isInBounds(Space::MapBlock::world::fromChunk(chunk->pos), bounds)) {
|
||||
sendChunk(chunk->pos, *client);
|
||||
}
|
||||
}
|
||||
|
@ -118,6 +118,7 @@ void ServerWorld::update() {
|
|||
|
||||
void ServerWorld::sendChunk(glm::vec3 pos, ServerClient &peer) {
|
||||
auto chunk = dimension.getChunk(pos);
|
||||
assert(chunk != nullptr);
|
||||
auto serialized = chunk->serialize();
|
||||
|
||||
Packet r(PacketType::CHUNK);
|
||||
|
@ -150,7 +151,7 @@ void ServerWorld::setBlock(glm::vec3 pos, unsigned int block) {
|
|||
Serializer::encodeIntVec3(b.data, pos);
|
||||
Serializer::encodeInt(b.data, block);
|
||||
|
||||
auto chunkPos = TransPos::chunkFromVec(TransPos::roundPos(pos));
|
||||
auto chunkPos = Space::Chunk::world::fromBlock(pos);
|
||||
|
||||
for (auto &client : clientList.clients) {
|
||||
if (client->hasPlayer()) {
|
||||
|
@ -160,7 +161,7 @@ void ServerWorld::setBlock(glm::vec3 pos, unsigned int block) {
|
|||
{mapBlock.x - MB_GEN_H, mapBlock.y - MB_GEN_V, mapBlock.z - MB_GEN_H},
|
||||
{mapBlock.x + MB_GEN_H, mapBlock.y + MB_GEN_V, mapBlock.z + MB_GEN_H}};
|
||||
|
||||
if (isInBounds(TransPos::mapBlockFromVec(chunkPos * 16), bounds)) {
|
||||
if (isInBounds(Space::MapBlock::world::fromChunk(chunkPos), bounds)) {
|
||||
b.sendTo(client->getPeer(), PacketChannel::BLOCK);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ private:
|
|||
WorldGenStream* genStream = nullptr;
|
||||
ServerDimension dimension;
|
||||
|
||||
std::unordered_set<glm::vec3, VecUtils::compareFunc> generateQueueMap;
|
||||
std::unordered_set<glm::vec3, Vec::compareFunc> generateQueueMap;
|
||||
std::vector<glm::vec3> generateQueueList;
|
||||
|
||||
unsigned int seed;
|
||||
|
|
|
@ -56,7 +56,7 @@ private:
|
|||
|
||||
MapGen gen;
|
||||
std::vector<glm::vec3> queuedTasks;
|
||||
std::unordered_set<glm::vec3, VecUtils::compareFunc> queuedMap;
|
||||
std::unordered_set<glm::vec3, Vec::compareFunc> queuedMap;
|
||||
};
|
||||
|
||||
#pragma clang diagnostic pop
|
|
@ -8,4 +8,3 @@
|
|||
|
||||
#define sptr std::shared_ptr
|
||||
#define uptr std::unique_ptr
|
||||
#define wptr std::weak_ptr
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
//
|
||||
// Created by aurailus on 24/03/19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <tgmath.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/common.hpp>
|
||||
|
||||
namespace Space {
|
||||
const static int CHUNK_SIZE = 16;
|
||||
const static int MAPBLOCK_SIZE = 4;
|
||||
const static int REGION_SIZE = 4;
|
||||
|
||||
const static int CHUNK_BLOCK_LENGTH = CHUNK_SIZE;
|
||||
const static int MAPBLOCK_BLOCK_LENGTH = CHUNK_BLOCK_LENGTH * MAPBLOCK_SIZE;
|
||||
const static int REGION_BLOCK_LENGTH = MAPBLOCK_BLOCK_LENGTH * REGION_SIZE;
|
||||
|
||||
const static int MAPBLOCK_CHUNK_LENGTH = MAPBLOCK_SIZE;
|
||||
const static int REGION_CHUNK_LENGTH = MAPBLOCK_CHUNK_LENGTH * REGION_SIZE;
|
||||
|
||||
// Private helper methods
|
||||
namespace {
|
||||
inline glm::vec3 localFromGlobal(const glm::vec3 &pos, int size) {
|
||||
auto round = glm::floor(pos);
|
||||
return glm::vec3 {
|
||||
(round.x < 0) ? size - 1 + static_cast<int>(round.x + 1) % size : static_cast<int>(round.x) % size,
|
||||
(round.y < 0) ? size - 1 + static_cast<int>(round.y + 1) % size : static_cast<int>(round.y) % size,
|
||||
(round.z < 0) ? size - 1 + static_cast<int>(round.z + 1) % size : static_cast<int>(round.z) % size
|
||||
};
|
||||
}
|
||||
|
||||
inline glm::vec3 sectionFromGlobal(glm::vec3 pos, int size) {
|
||||
auto round = glm::floor(pos);
|
||||
return {std::floor(round.x / size), std::floor(round.y / size), std::floor(round.z / size)};
|
||||
}
|
||||
}
|
||||
|
||||
namespace Region {
|
||||
namespace world {
|
||||
// Get a Region world position from a MapBlock's world position.
|
||||
static inline glm::vec3 fromMapBlock(const glm::vec3& mapBlock) {
|
||||
return sectionFromGlobal(mapBlock, REGION_SIZE);
|
||||
}
|
||||
|
||||
// Get a Region world position from a Chunk's world position.
|
||||
static inline glm::vec3 fromChunk(const glm::vec3 &chunk) {
|
||||
return sectionFromGlobal(chunk, REGION_CHUNK_LENGTH);
|
||||
}
|
||||
|
||||
// Get a Region world position from a Block's world position.
|
||||
static inline glm::vec3 fromBlock(const glm::vec3 &chunk) {
|
||||
return sectionFromGlobal(chunk, REGION_BLOCK_LENGTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace MapBlock {
|
||||
namespace relative {
|
||||
// Get a MapBlock's relative position in its Region from its world position.
|
||||
static inline glm::vec3 toRegion(const glm::vec3& pos) {
|
||||
return localFromGlobal(pos, MAPBLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
namespace world {
|
||||
// Get a MapBlock world position from a Chunk's world position.
|
||||
static inline glm::vec3 fromChunk(const glm::vec3 &chunk) {
|
||||
return sectionFromGlobal(chunk, MAPBLOCK_SIZE);
|
||||
}
|
||||
|
||||
// Get a MapBlock world position from a Block's world position.
|
||||
static inline glm::vec3 fromBlock(const glm::vec3 &vec) {
|
||||
return sectionFromGlobal(vec, MAPBLOCK_BLOCK_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the index of a MapBlock within its Region from its local or world position.
|
||||
static inline unsigned int index(const glm::vec3& vec) {
|
||||
glm::vec3 local = MapBlock::relative::toRegion(vec);
|
||||
unsigned int ind = static_cast<unsigned int>(local.x + REGION_SIZE * (local.y + REGION_SIZE * local.z));
|
||||
return ind;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Chunk {
|
||||
namespace relative {
|
||||
// Get a Chunk's relative position in its MapBlock from its world position.
|
||||
static inline glm::vec3 toMapBlock(const glm::vec3& pos) {
|
||||
return localFromGlobal(pos, MAPBLOCK_CHUNK_LENGTH);
|
||||
}
|
||||
|
||||
// Get a Chunk's relative position in its Region from its world position.
|
||||
static inline glm::vec3 toRegion(const glm::vec3& pos) {
|
||||
return localFromGlobal(pos, REGION_CHUNK_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
namespace world {
|
||||
// Get a Chunk world position from a Block's world position.
|
||||
static inline glm::vec3 fromBlock(const glm::vec3& pos) {
|
||||
return sectionFromGlobal(pos, CHUNK_BLOCK_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the index of a Chunk within its MapBlock from its local or world position.
|
||||
static inline unsigned int index(const glm::vec3& vec) {
|
||||
glm::vec3 local = Chunk::relative::toMapBlock(vec);
|
||||
return static_cast<unsigned int>(local.x + MAPBLOCK_SIZE * (local.y + MAPBLOCK_SIZE * local.z));
|
||||
}
|
||||
}
|
||||
|
||||
namespace Block {
|
||||
namespace relative {
|
||||
// Get a Block's relative position to its Chunk from its world position.
|
||||
static inline glm::vec3 toChunk(const glm::vec3& pos) {
|
||||
return localFromGlobal(pos, CHUNK_BLOCK_LENGTH);
|
||||
}
|
||||
|
||||
// Get a Block's relative position to its MapBlock from its world position.
|
||||
static inline glm::vec3 toMapBlock(const glm::vec3& pos) {
|
||||
return localFromGlobal(pos, MAPBLOCK_BLOCK_LENGTH);
|
||||
}
|
||||
|
||||
// Get a Block's relative position in its Region from its world position.
|
||||
static inline glm::vec3 toRegion(const glm::vec3& pos) {
|
||||
return localFromGlobal(pos, REGION_BLOCK_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the index of a Block within its Chunk from its local or world position.
|
||||
static inline unsigned int index(const glm::vec3& vec) {
|
||||
glm::vec3 local = Block::relative::toChunk(vec);
|
||||
return static_cast<unsigned int>(local.x + CHUNK_SIZE * (local.y + CHUNK_SIZE * local.z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 24/03/19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <tgmath.h>
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
namespace TransPos {
|
||||
const static int CHUNK_SIZE = 16; //Must be a multiple of 16
|
||||
const static int MAPBLOCK_SIZE = 4;
|
||||
const static int REGION_SIZE = 4;
|
||||
|
||||
const static int CHUNK_BLOCK_LENGTH = CHUNK_SIZE;
|
||||
const static int MAPBLOCK_BLOCK_LENGTH = CHUNK_BLOCK_LENGTH * MAPBLOCK_SIZE;
|
||||
const static int REGION_BLOCK_LENGTH = MAPBLOCK_BLOCK_LENGTH * REGION_SIZE;
|
||||
|
||||
const static int MAPBLOCK_CHUNK_LENGTH = MAPBLOCK_SIZE;
|
||||
const static int REGION_CHUNK_LENGTH = MAPBLOCK_CHUNK_LENGTH * REGION_SIZE;
|
||||
|
||||
static inline glm::vec3 roundPos(glm::vec3 vec) {
|
||||
return { floor(vec.x), floor(vec.y), floor(vec.z) };
|
||||
}
|
||||
|
||||
namespace {
|
||||
inline glm::vec3 localFromGlobal(glm::vec3 &pos, int size) {
|
||||
auto round = roundPos(pos);
|
||||
glm::vec3 out;
|
||||
out.x = (round.x < 0) ? ((size - 1) + (((int) round.x + 1) % size)) : (((int) round.x) % size);
|
||||
out.y = (round.y < 0) ? ((size - 1) + (((int) round.y + 1) % size)) : (((int) round.y) % size);
|
||||
out.z = (round.z < 0) ? ((size - 1) + (((int) round.z + 1) % size)) : (((int) round.z) % size);
|
||||
return out;
|
||||
}
|
||||
|
||||
inline glm::vec3 sectionFromGlobal(glm::vec3 pos, int size) {
|
||||
auto round = roundPos(pos);
|
||||
return {std::floor(round.x / size), std::floor(round.y / size), std::floor(round.z / size)};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Return a local position vector relative to the respective structure
|
||||
|
||||
static inline glm::vec3 regionLocalFromVec(glm::vec3 vec) {
|
||||
return localFromGlobal(vec, REGION_BLOCK_LENGTH);
|
||||
}
|
||||
|
||||
static inline glm::vec3 mapBlockLocalFromVec(glm::vec3 vec) {
|
||||
return localFromGlobal(vec, MAPBLOCK_BLOCK_LENGTH);
|
||||
}
|
||||
|
||||
static inline glm::vec3 chunkLocalFromVec(glm::vec3 vec) {
|
||||
return localFromGlobal(vec, CHUNK_BLOCK_LENGTH);
|
||||
}
|
||||
|
||||
//Returns the Chunk Position from a pos vector
|
||||
|
||||
static inline glm::vec3 chunkFromVec(glm::vec3 vec) {
|
||||
return sectionFromGlobal(vec, CHUNK_BLOCK_LENGTH);
|
||||
}
|
||||
|
||||
static inline glm::vec3 mapBlockFromVec(glm::vec3 vec) {
|
||||
return sectionFromGlobal(vec, MAPBLOCK_BLOCK_LENGTH);
|
||||
}
|
||||
|
||||
namespace Dimension {
|
||||
//Used to get the chunk position from a global coordinate in LocalDimension
|
||||
|
||||
//Retrieve the region pos from a block pos
|
||||
static inline glm::vec3 regionFromVec(glm::vec3 vec) {
|
||||
return sectionFromGlobal(vec, REGION_CHUNK_LENGTH);
|
||||
}
|
||||
|
||||
//Retrieve the raw (chunk pos of bottom left corner) pos of a region
|
||||
static inline glm::vec3 regionRawFromRegionVec(glm::vec3 vec) {
|
||||
return vec * glm::vec3(REGION_CHUNK_LENGTH);
|
||||
}
|
||||
|
||||
//Retrieve the offset of a mapblock from it's region using a chunk position
|
||||
static inline glm::vec3 mapBlockOffsetFromRegion(glm::vec3 vec) {
|
||||
return sectionFromGlobal(localFromGlobal(vec, REGION_CHUNK_LENGTH), MAPBLOCK_CHUNK_LENGTH);
|
||||
}
|
||||
|
||||
//Retrieve the offset of a chunk from it's mapblock using a chunk position
|
||||
static inline glm::vec3 chunkOffsetFromMapBlock(glm::vec3 vec) {
|
||||
return localFromGlobal(vec, MAPBLOCK_CHUNK_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Used to get indices from various vectors
|
||||
|
||||
static inline unsigned int mapBlockIndFromVec(glm::vec3 vec) {
|
||||
return (unsigned int)(vec.x + REGION_SIZE * (vec.y + REGION_SIZE * vec.z));
|
||||
}
|
||||
|
||||
static inline unsigned int chunkIndFromVec(glm::vec3 vec) {
|
||||
return (unsigned int)(vec.x + MAPBLOCK_SIZE * (vec.y + MAPBLOCK_SIZE * vec.z));
|
||||
}
|
||||
};
|
||||
|
|
@ -64,7 +64,6 @@ namespace Util {
|
|||
return x;
|
||||
}
|
||||
|
||||
|
||||
static glm::vec4 hexToColorVec(std::string hex) {
|
||||
glm::vec4 color {};
|
||||
|
||||
|
|
|
@ -8,44 +8,34 @@
|
|||
#include <glm/vec3.hpp>
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include "TransPos.h"
|
||||
#include "Space.h"
|
||||
|
||||
namespace VecUtils {
|
||||
namespace Vec {
|
||||
struct compareFunc {
|
||||
size_t operator()(const glm::vec3& k)const {
|
||||
return std::hash<float>()(k.x) ^ std::hash<float>()(k.y) ^ std::hash<float>()(k.z);
|
||||
}
|
||||
};
|
||||
|
||||
static inline std::array<glm::vec3, 6> getCardinalVectors() {
|
||||
return {
|
||||
glm::vec3(1, 0, 0), glm::vec3(-1, 0, 0),
|
||||
glm::vec3(0, 1, 0), glm::vec3(0, -1, 0),
|
||||
glm::vec3(0, 0, 1), glm::vec3(0, 0, -1),
|
||||
};
|
||||
const static std::array<glm::vec3, 6> cardinalVectors = {
|
||||
glm::vec3 {1, 0, 0}, glm::vec3 {-1, 0, 0},
|
||||
glm::vec3 {0, 1, 0}, glm::vec3 {0, -1, 0},
|
||||
glm::vec3 {0, 0, 1}, glm::vec3 {0, 0, -1}
|
||||
};
|
||||
|
||||
static inline void indAssignVec(int ind, glm::vec3& vec) {
|
||||
vec.z = ind / (TransPos::CHUNK_SIZE * TransPos::CHUNK_SIZE);
|
||||
ind -= ((int)vec.z * TransPos::CHUNK_SIZE * TransPos::CHUNK_SIZE);
|
||||
vec.y = ind / TransPos::CHUNK_SIZE;
|
||||
vec.x = ind % TransPos::CHUNK_SIZE;
|
||||
vec.z = ind / (16 * 16);
|
||||
ind -= ((int)vec.z * 16 * 16);
|
||||
vec.y = ind / 16;
|
||||
vec.x = ind % 16;
|
||||
}
|
||||
|
||||
static inline glm::vec3* indToVec(int ind) {
|
||||
int z = ind / (TransPos::CHUNK_SIZE * TransPos::CHUNK_SIZE);
|
||||
ind -= (z * TransPos::CHUNK_SIZE * TransPos::CHUNK_SIZE);
|
||||
int y = ind / TransPos::CHUNK_SIZE;
|
||||
int x = ind % TransPos::CHUNK_SIZE;
|
||||
int z = ind / (16 * 16);
|
||||
ind -= (z * 16 * 16);
|
||||
int y = ind / 16;
|
||||
int x = ind % 16;
|
||||
return new glm::vec3(x, y, z);
|
||||
}
|
||||
|
||||
static inline unsigned int vecToInd(int x, int y, int z) {
|
||||
return (unsigned int)(x + TransPos::CHUNK_SIZE * (y + TransPos::CHUNK_SIZE * z));
|
||||
}
|
||||
|
||||
static inline unsigned int vecToInd(const glm::vec3& vec) {
|
||||
return (unsigned int)(vec.x + TransPos::CHUNK_SIZE * (vec.y + TransPos::CHUNK_SIZE * vec.z));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue