From: Daniel Karbach Date: Fri, 2 Oct 2015 14:54:52 +0000 (+0200) Subject: move spawn index out of world X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=5178dd1e226d45db7ae61e3d7d6866dc4254d9ae;p=blank.git move spawn index out of world client doesn't need those --- diff --git a/doc/todo b/doc/todo index d5a961c..1cf7ed0 100644 --- a/doc/todo +++ b/doc/todo @@ -99,5 +99,19 @@ entity/world collision first draft of entity/world collision is implemented it jitters and has some surprising behaviour - finding a spawn point which doesn't put entities in solids is - now a little more crucial. press N if you're in trouble + +spawning + + need a way to find a suitable location to spawn new players in + I imagine a "random block" function of ChunkIndex could be nice + (also for use with the AI spawner) + also, finding a spawn position for a player must no fail. after a + certain number of tries, the world must change to safely accomodate + the player. + chunk generation could be adjusted to make a little more room near the + origin (since that's where the usual spawn point will be), but that's + not strictly necessary and might overcomplicate the generation + if all fails, the spawner has to modify the world + how much space has to be cleared and how to make sure the spawning + space connects to "open space" I don't know yet, it's all a little + fuzzy anyway diff --git a/src/server/ServerState.cpp b/src/server/ServerState.cpp index cedae4e..9020aa0 100644 --- a/src/server/ServerState.cpp +++ b/src/server/ServerState.cpp @@ -20,6 +20,7 @@ ServerState::ServerState( : env(env) , block_types() , world(block_types, wc) +, spawn_index(world.Chunks().MakeIndex(wc.spawn, 3)) , generator(gc) , chunk_loader(world.Chunks(), generator, ws) , skeletons() @@ -37,6 +38,10 @@ ServerState::ServerState( std::cout << "listening on UDP port " << config.net.port << std::endl; } +ServerState::~ServerState() { + world.Chunks().UnregisterIndex(spawn_index); +} + void ServerState::Handle(const SDL_Event &event) { if (event.type == SDL_QUIT) { diff --git a/src/server/ServerState.hpp b/src/server/ServerState.hpp index 31ad521..e22f9b1 100644 --- a/src/server/ServerState.hpp +++ b/src/server/ServerState.hpp @@ -7,6 +7,7 @@ #include "../app/State.hpp" #include "../model/Skeletons.hpp" #include "../world/BlockTypeRegistry.hpp" +#include "../world/ChunkIndex.hpp" #include "../world/ChunkLoader.hpp" #include "../world/Generator.hpp" #include "../world/World.hpp" @@ -31,6 +32,7 @@ public: const WorldSave &, const Config & ); + ~ServerState(); void Handle(const SDL_Event &) override; void Update(int dt) override; @@ -40,6 +42,7 @@ private: HeadlessEnvironment &env; BlockTypeRegistry block_types; World world; + ChunkIndex &spawn_index; Generator generator; ChunkLoader chunk_loader; Skeletons skeletons; diff --git a/src/server/net.cpp b/src/server/net.cpp index 7cb07cd..16aa1cb 100644 --- a/src/server/net.cpp +++ b/src/server/net.cpp @@ -397,6 +397,8 @@ void ClientConnection::AttachPlayer(Player &player) { PlayerEntity().Ref(); if (server.GetWorldSave().Exists(player)) { server.GetWorldSave().Read(player); + } else { + // TODO: spawn } old_base = PlayerChunks().Base(); diff --git a/src/standalone/MasterState.cpp b/src/standalone/MasterState.cpp index 98d3c83..dccc0f9 100644 --- a/src/standalone/MasterState.cpp +++ b/src/standalone/MasterState.cpp @@ -24,6 +24,7 @@ MasterState::MasterState( , block_types() , save(save) , world(block_types, wc) +, spawn_index(world.Chunks().MakeIndex(wc.spawn, 3)) , player(*world.AddPlayer(config.player.name)) , hud(env, config, player) , manip(env, player.GetEntity()) @@ -46,9 +47,15 @@ MasterState::MasterState( spawner.LimitSkeletons(0, skeletons.Size()); if (save.Exists(player)) { save.Read(player); + } else { + // TODO: spawn } } +MasterState::~MasterState() { + world.Chunks().UnregisterIndex(spawn_index); +} + void MasterState::OnEnter() { env.state.Push(&preload); diff --git a/src/standalone/MasterState.hpp b/src/standalone/MasterState.hpp index 823e7f3..84c3315 100644 --- a/src/standalone/MasterState.hpp +++ b/src/standalone/MasterState.hpp @@ -14,6 +14,7 @@ #include "../ui/InteractiveManipulator.hpp" #include "../ui/Interface.hpp" #include "../world/BlockTypeRegistry.hpp" +#include "../world/ChunkIndex.hpp" #include "../world/ChunkLoader.hpp" #include "../world/ChunkRenderer.hpp" #include "../world/Generator.hpp" @@ -40,6 +41,7 @@ public: const World::Config &, const WorldSave & ); + ~MasterState(); void OnEnter() override; @@ -62,6 +64,7 @@ private: BlockTypeRegistry block_types; const WorldSave &save; World world; + ChunkIndex &spawn_index; Player &player; HUD hud; InteractiveManipulator manip; diff --git a/src/world/World.hpp b/src/world/World.hpp index d58ad6f..848f801 100644 --- a/src/world/World.hpp +++ b/src/world/World.hpp @@ -25,8 +25,8 @@ class World { public: struct Config { std::string name = "default"; - // initial player position - glm::vec3 spawn = { 0.0f, 0.0f, 0.0f }; + // chunk base where new players are spawned + glm::ivec3 spawn = { 0, 0, 0 }; // direction facing towards(!) the light glm::vec3 light_direction = { -1.0f, -3.0f, -2.0f }; // fade out reaches 1/e (0.3679) at 1/fog_density, @@ -100,7 +100,6 @@ private: const BlockTypeRegistry &block_type; ChunkStore chunks; - ChunkIndex &spawn_index; std::list players; std::list entities; diff --git a/src/world/world.cpp b/src/world/world.cpp index f648baa..8ea99fe 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -145,8 +145,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 +153,7 @@ World::World(const BlockTypeRegistry &types, const Config &config) } World::~World() { - chunks.UnregisterIndex(spawn_index); + } @@ -169,7 +167,6 @@ Player *World::AddPlayer(const std::string &name) { entity.Name(name); 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(); @@ -188,7 +185,6 @@ Player *World::AddPlayer(const std::string &name, std::uint32_t id) { entity->Name(name); 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();