World: Load spawn chunks at start
This commit is contained in:
parent
c71e330026
commit
eec887a052
|
@ -55,6 +55,22 @@ namespace Feather
|
|||
m_levelData.spawnZ = levelDat.Get<int32_t>("SpawnZ");
|
||||
}
|
||||
|
||||
void World::PrepareSpawn()
|
||||
{
|
||||
Log::Info("Loading spawn area...");
|
||||
|
||||
BlockPos spawnPos(m_levelData.spawnX, m_levelData.spawnY, m_levelData.spawnZ);
|
||||
ChunkPos spawnChunk(spawnPos);
|
||||
|
||||
for (int x = -10; x <= 10; x++) {
|
||||
for (int z = -10; z <= 10; z++) {
|
||||
GetChunk(ChunkPos(spawnChunk.x + x, spawnChunk.z + z));
|
||||
}
|
||||
}
|
||||
|
||||
Log::Info("Finished loading spawn area.");
|
||||
}
|
||||
|
||||
Chunk* World::GetChunk(ChunkPos pos)
|
||||
{
|
||||
auto [chunks, lock] = m_chunks.borrow();
|
||||
|
@ -94,7 +110,10 @@ namespace Feather
|
|||
|
||||
std::ifstream* chunkStream = region.GetChunkStream(regionChunkPos);
|
||||
|
||||
Log::Trace("{}", chunkStream->good());
|
||||
if (!chunkStream->good()) {
|
||||
Log::Error("Failed to find chunk ({}, {}) on disk.", pos.x, pos.z);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char lengthBytes[5];
|
||||
chunkStream->read(lengthBytes, 5);
|
||||
|
|
|
@ -22,6 +22,8 @@ namespace Feather
|
|||
public:
|
||||
World(std::string name);
|
||||
|
||||
void PrepareSpawn();
|
||||
|
||||
// global palette of all block states
|
||||
static const GlobalPalette<BlockState> GLOBAL_PALETTE;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace Feather
|
|||
{
|
||||
void WorldManager::LoadWorld(string name)
|
||||
{
|
||||
world = new World(name);
|
||||
world = new World(name);
|
||||
world->PrepareSpawn();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue