- player = &AddEntity();
- player->Name("player");
- player->Bounds({ { -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f } });
- player->WorldCollidable(true);
- player->Position(config.spawn);
+Player World::AddPlayer(const std::string &name) {
+ for (Player &p : players) {
+ if (p.entity->Name() == name) {
+ return { nullptr, nullptr };
+ }
+ }
+ 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();
+}
+
+Player World::AddPlayer(const std::string &name, std::uint32_t id) {
+ for (Player &p : players) {
+ if (p.entity->Name() == name) {
+ return { nullptr, nullptr };
+ }
+ }
+ Entity *entity = AddEntity(id);
+ if (!entity) {
+ return { nullptr, 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();
+}