FeatherMC/src/world/World.h

55 lines
1.2 KiB
C
Raw Normal View History

2020-08-07 05:48:54 +01:00
#pragma once
#include "Common.h"
2020-08-13 04:15:51 +01:00
#include "nbt/NBT.h"
#include "Chunk.h"
2020-08-13 04:10:44 +01:00
#include "Palette.h"
#include "../Lockable.h"
2020-08-13 04:10:44 +01:00
2020-08-07 05:48:54 +01:00
#include <cstdint>
#include <string>
#include <map>
2020-08-07 05:48:54 +01:00
namespace Feather
{
struct LevelData
{
int32_t spawnX, spawnY, spawnZ;
};
2020-08-07 05:48:54 +01:00
class World
{
2020-11-05 00:32:44 +00:00
public:
// Min and max build height, inclusive
static constexpr int MIN_BUILD_HEIGHT = 0, MAX_BUILD_HEIGHT = 255;
2020-08-07 05:48:54 +01:00
public:
World(std::string name);
2020-08-14 02:41:05 +01:00
void PrepareSpawn();
2020-08-13 04:10:44 +01:00
// global palette of all block states
2020-11-07 01:51:08 +00:00
// TODO: move this to ChunkSection
2020-08-13 04:10:44 +01:00
static const GlobalPalette<BlockState> GLOBAL_PALETTE;
2020-08-13 04:15:51 +01:00
Chunk* GetChunk(ChunkPos pos);
2020-08-13 04:15:51 +01:00
2020-11-05 00:32:44 +00:00
bool SetBlock(const BlockPos& pos, const BlockState& state);
LevelData GetLevelData() const { return m_levelData; }
2020-08-07 05:48:54 +01:00
2020-11-05 00:32:44 +00:00
inline bool IsOutsideBuildHeight(BlockPos pos) { return IsOutsideBuildHeight(pos.y); }
inline bool IsOutsideBuildHeight(int y) { return y < MIN_BUILD_HEIGHT || y > MAX_BUILD_HEIGHT; }
private:
std::unique_ptr<Chunk> LoadChunk(ChunkPos pos);
2020-11-05 00:32:44 +00:00
LockableMap<ChunkPos, std::unique_ptr<Chunk>> m_chunks;
LevelData m_levelData;
// TODO nuke this shit
std::string m_name;
2020-08-07 05:48:54 +01:00
};
2020-11-05 00:32:44 +00:00
}