2014-12-18 07:02:48 +01:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
|
|
|
* Filename: World.cpp
|
|
|
|
*
|
2018-06-05 01:24:54 +02:00
|
|
|
* Description:
|
2014-12-18 07:02:48 +01:00
|
|
|
*
|
|
|
|
* Created: 16/12/2014 15:28:19
|
|
|
|
*
|
2018-06-12 09:24:43 +02:00
|
|
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
2014-12-18 07:02:48 +01:00
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
2018-12-29 02:23:23 +01:00
|
|
|
#include <gk/resource/ResourceHandler.hpp>
|
|
|
|
|
2018-06-13 03:47:20 +02:00
|
|
|
#include "Config.hpp"
|
2014-12-18 07:02:48 +01:00
|
|
|
#include "World.hpp"
|
|
|
|
|
2018-07-06 11:58:34 +02:00
|
|
|
bool World::isReloadRequested = false;
|
2018-06-30 05:07:57 +02:00
|
|
|
|
2020-01-16 11:59:14 +09:00
|
|
|
Chunk *World::getChunkAtBlockPos(int x, int y, int z) const {
|
|
|
|
return getChunk(
|
2020-01-16 11:04:52 +09:00
|
|
|
std::floor((float)x / CHUNK_WIDTH),
|
|
|
|
std::floor((float)y / CHUNK_HEIGHT),
|
|
|
|
std::floor((float)z / CHUNK_DEPTH)
|
|
|
|
);
|
2020-01-16 11:59:14 +09:00
|
|
|
}
|
2020-01-16 11:04:52 +09:00
|
|
|
|
2020-01-16 11:59:14 +09:00
|
|
|
BlockData *World::getBlockData(int x, int y, int z) const {
|
|
|
|
Chunk *chunk = getChunkAtBlockPos(x, y, z);
|
2020-01-16 10:07:01 +09:00
|
|
|
if (chunk)
|
|
|
|
return chunk->getBlockData(x & (CHUNK_WIDTH - 1), y & (CHUNK_HEIGHT - 1), z & (CHUNK_DEPTH - 1));
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 World::getBlock(int x, int y, int z) const {
|
2020-01-16 11:59:14 +09:00
|
|
|
Chunk *chunk = getChunkAtBlockPos(x, y, z);
|
2020-01-16 10:07:01 +09:00
|
|
|
if (chunk)
|
|
|
|
return chunk->getBlock(x & (CHUNK_WIDTH - 1), y & (CHUNK_HEIGHT - 1), z & (CHUNK_DEPTH - 1));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void World::setBlock(int x, int y, int z, u16 id) const {
|
2020-01-16 11:59:14 +09:00
|
|
|
Chunk *chunk = getChunkAtBlockPos(x, y, z);
|
2020-01-16 10:07:01 +09:00
|
|
|
if (chunk)
|
|
|
|
chunk->setBlock(x & (CHUNK_WIDTH - 1), y & (CHUNK_HEIGHT - 1), z & (CHUNK_DEPTH - 1), id);
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 World::getData(int x, int y, int z) const {
|
2020-01-16 11:59:14 +09:00
|
|
|
Chunk *chunk = getChunkAtBlockPos(x, y, z);
|
2020-01-16 10:07:01 +09:00
|
|
|
if (chunk)
|
|
|
|
return chunk->getData(x & (CHUNK_WIDTH - 1), y & (CHUNK_HEIGHT - 1), z & (CHUNK_DEPTH - 1));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void World::setData(int x, int y, int z, u16 id) const {
|
2020-01-16 11:59:14 +09:00
|
|
|
Chunk *chunk = getChunkAtBlockPos(x, y, z);
|
2020-01-16 10:07:01 +09:00
|
|
|
if (chunk)
|
|
|
|
chunk->setBlock(x & (CHUNK_WIDTH - 1), y & (CHUNK_HEIGHT - 1), z & (CHUNK_DEPTH - 1), id);
|
|
|
|
}
|