X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2Fworld.cpp;h=e4fb968ddfbb8014004a2b7a6a7647be53b2c2a5;hb=04531ab5fc3d82ba5b5d456bcc277fe6499e1150;hp=e659322aa333c753fd953a718fc0c18b7eace276;hpb=ccd6e7001572808400b9cb9bc91f9bedcf28a1ad;p=blank.git diff --git a/src/world/world.cpp b/src/world/world.cpp index e659322..e4fb968 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -136,6 +136,19 @@ Player::~Player() { } +bool Player::SuitableSpawn(BlockLookup &spawn_block) const noexcept { + if (!spawn_block || spawn_block.GetType().collide_block) { + return false; + } + + BlockLookup head_block(spawn_block.Next(Block::FACE_UP)); + if (!head_block || head_block.GetType().collide_block) { + return false; + } + + return true; +} + void Player::Update(int dt) { chunks.Rebase(entity.ChunkCoords()); } @@ -145,8 +158,6 @@ World::World(const BlockTypeRegistry &types, const Config &config) : config(config) , block_type(types) , chunks(types) -// TODO: set spawn base and extent from config -, spawn_index(chunks.MakeIndex(Chunk::Pos(0, 0, 0), 3)) , players() , entities() , light_direction(config.light_direction) @@ -155,7 +166,7 @@ World::World(const BlockTypeRegistry &types, const Config &config) } World::~World() { - chunks.UnregisterIndex(spawn_index); + } @@ -167,10 +178,8 @@ Player *World::AddPlayer(const std::string &name) { } Entity &entity = AddEntity(); entity.Name(name); - // TODO: load from save file here entity.Bounds({ { -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f } }); entity.WorldCollidable(true); - entity.Position(config.spawn); ChunkIndex &index = chunks.MakeIndex(entity.ChunkCoords(), 6); players.emplace_back(entity, index); return &players.back(); @@ -187,10 +196,8 @@ Player *World::AddPlayer(const std::string &name, std::uint32_t id) { return nullptr; } entity->Name(name); - // TODO: load from save file here entity->Bounds({ { -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f } }); entity->WorldCollidable(true); - entity->Position(config.spawn); ChunkIndex &index = chunks.MakeIndex(entity->ChunkCoords(), 6); players.emplace_back(*entity, index); return &players.back();