66 lines
1.8 KiB
C++
Raw Normal View History

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
*
* 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>
#include "Config.hpp"
2014-12-18 07:02:48 +01:00
#include "World.hpp"
bool World::isReloadRequested = false;
Chunk *World::getChunkAtBlockPos(int x, int y, int z) const {
return getChunk(
std::floor((float)x / CHUNK_WIDTH),
std::floor((float)y / CHUNK_HEIGHT),
std::floor((float)z / CHUNK_DEPTH)
);
}
BlockData *World::getBlockData(int x, int y, int z) const {
Chunk *chunk = getChunkAtBlockPos(x, y, z);
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 {
Chunk *chunk = getChunkAtBlockPos(x, y, z);
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 {
Chunk *chunk = getChunkAtBlockPos(x, y, z);
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 {
Chunk *chunk = getChunkAtBlockPos(x, y, z);
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 {
Chunk *chunk = getChunkAtBlockPos(x, y, z);
if (chunk)
chunk->setBlock(x & (CHUNK_WIDTH - 1), y & (CHUNK_HEIGHT - 1), z & (CHUNK_DEPTH - 1), id);
}