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
: 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()
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) {
#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"
const WorldSave &,
const Config &
);
+ ~ServerState();
void Handle(const SDL_Event &) override;
void Update(int dt) override;
HeadlessEnvironment &env;
BlockTypeRegistry block_types;
World world;
+ ChunkIndex &spawn_index;
Generator generator;
ChunkLoader chunk_loader;
Skeletons skeletons;
PlayerEntity().Ref();
if (server.GetWorldSave().Exists(player)) {
server.GetWorldSave().Read(player);
+ } else {
+ // TODO: spawn
}
old_base = PlayerChunks().Base();
, 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())
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);
#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"
const World::Config &,
const WorldSave &
);
+ ~MasterState();
void OnEnter() override;
BlockTypeRegistry block_types;
const WorldSave &save;
World world;
+ ChunkIndex &spawn_index;
Player &player;
HUD hud;
InteractiveManipulator manip;
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,
const BlockTypeRegistry &block_type;
ChunkStore chunks;
- ChunkIndex &spawn_index;
std::list<Player> players;
std::list<Entity> entities;
: 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)
}
World::~World() {
- chunks.UnregisterIndex(spawn_index);
+
}
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();
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();