diff options
Diffstat (limited to 'src/game/server/world')
| -rw-r--r-- | src/game/server/world/inhabited.hh | 3 | ||||
| -rw-r--r-- | src/game/server/world/overworld.cc | 25 | ||||
| -rw-r--r-- | src/game/server/world/overworld.hh | 12 | ||||
| -rw-r--r-- | src/game/server/world/random_tick.cc | 4 | ||||
| -rw-r--r-- | src/game/server/world/random_tick.hh | 7 | ||||
| -rw-r--r-- | src/game/server/world/universe.cc | 35 | ||||
| -rw-r--r-- | src/game/server/world/universe.hh | 11 | ||||
| -rw-r--r-- | src/game/server/world/unloader.cc | 22 | ||||
| -rw-r--r-- | src/game/server/world/unloader.hh | 7 | ||||
| -rw-r--r-- | src/game/server/world/worldgen.cc | 20 | ||||
| -rw-r--r-- | src/game/server/world/worldgen.hh | 11 |
11 files changed, 67 insertions, 90 deletions
diff --git a/src/game/server/world/inhabited.hh b/src/game/server/world/inhabited.hh index 57008e9..e4b2344 100644 --- a/src/game/server/world/inhabited.hh +++ b/src/game/server/world/inhabited.hh @@ -1,6 +1,3 @@ #pragma once -namespace world -{ struct Inhabited final {}; -} // namespace world diff --git a/src/game/server/world/overworld.cc b/src/game/server/world/overworld.cc index 1a558c1..b03311d 100644 --- a/src/game/server/world/overworld.cc +++ b/src/game/server/world/overworld.cc @@ -11,8 +11,7 @@ #include "shared/game_voxels.hh" // FIXME: load these from a file -static void compute_tree_feature(unsigned int height, world::Feature& feature, const world::Voxel* log_voxel, - const world::Voxel* leaves_voxel) +static void compute_tree_feature(unsigned int height, Feature& feature, const Voxel* log_voxel, const Voxel* leaves_voxel) { // Ensure the tree height is too small height = glm::max<unsigned int>(height, 4U); @@ -72,7 +71,7 @@ static void compute_tree_feature(unsigned int height, world::Feature& feature, c } } -world::Overworld::Overworld(std::string_view name) : Dimension(name, -30.0f) +Overworld::Overworld(std::string_view name) : Dimension(name, -30.0f) { m_bottommost_chunk.set_limits(-64, -4); m_terrain_variation.set_limits(16, 256); @@ -83,7 +82,7 @@ world::Overworld::Overworld(std::string_view name) : Dimension(name, -30.0f) compute_tree_feature(8U, m_feat_tree[3], game_voxels::oak_log, game_voxels::oak_leaves); } -void world::Overworld::init(io::ConfigMap& config) +void Overworld::init(ConfigMap& config) { m_terrain_variation.set_value(64); m_bottommost_chunk.set_value(-4); @@ -92,7 +91,7 @@ void world::Overworld::init(io::ConfigMap& config) config.add_value("overworld.bottommost_chunk", m_bottommost_chunk); } -void world::Overworld::init_late(std::uint64_t global_seed) +void Overworld::init_late(std::uint64_t global_seed) { std::mt19937_64 twister(global_seed); @@ -130,7 +129,7 @@ void world::Overworld::init_late(std::uint64_t global_seed) m_metamap.clear(); } -bool world::Overworld::generate(const chunk_pos& cpos, VoxelStorage& voxels) +bool Overworld::generate(const chunk_pos& cpos, VoxelStorage& voxels) { if(cpos.y <= m_bottommost_chunk.get_value()) { // If the player asks the generator @@ -161,7 +160,7 @@ bool world::Overworld::generate(const chunk_pos& cpos, VoxelStorage& voxels) return true; } -bool world::Overworld::is_inside_cave(const voxel_pos& vpos) +bool Overworld::is_inside_cave(const voxel_pos& vpos) { auto vpos_x = static_cast<float>(vpos.x); auto vpos_y = static_cast<float>(vpos.y) * 2.0f; @@ -172,7 +171,7 @@ bool world::Overworld::is_inside_cave(const voxel_pos& vpos) return (noise_a > 0.95f) && (noise_b > 0.85f); } -bool world::Overworld::is_inside_terrain(const voxel_pos& vpos) +bool Overworld::is_inside_terrain(const voxel_pos& vpos) { auto vpos_x = static_cast<float>(vpos.x); auto vpos_y = static_cast<float>(vpos.y); @@ -184,7 +183,7 @@ bool world::Overworld::is_inside_terrain(const voxel_pos& vpos) return noise > 0.0f; } -const world::Overworld_Metadata& world::Overworld::get_or_create_metadata(const chunk_pos_xz& cpos) +const Overworld_Metadata& Overworld::get_or_create_metadata(const chunk_pos_xz& cpos) { auto it = m_metamap.find(cpos); @@ -249,7 +248,7 @@ const world::Overworld_Metadata& world::Overworld::get_or_create_metadata(const return metadata; } -void world::Overworld::generate_terrain(const chunk_pos& cpos, VoxelStorage& voxels) +void Overworld::generate_terrain(const chunk_pos& cpos, VoxelStorage& voxels) { auto& metadata = get_or_create_metadata(chunk_pos_xz(cpos.x, cpos.z)); auto variation = m_terrain_variation.get_value(); @@ -275,7 +274,7 @@ void world::Overworld::generate_terrain(const chunk_pos& cpos, VoxelStorage& vox } } -void world::Overworld::generate_surface(const chunk_pos& cpos, VoxelStorage& voxels) +void Overworld::generate_surface(const chunk_pos& cpos, VoxelStorage& voxels) { auto& metadata = get_or_create_metadata(chunk_pos_xz(cpos.x, cpos.z)); auto variation = m_terrain_variation.get_value(); @@ -330,7 +329,7 @@ void world::Overworld::generate_surface(const chunk_pos& cpos, VoxelStorage& vox } } -void world::Overworld::generate_caves(const chunk_pos& cpos, VoxelStorage& voxels) +void Overworld::generate_caves(const chunk_pos& cpos, VoxelStorage& voxels) { auto& metadata = get_or_create_metadata(chunk_pos_xz(cpos.x, cpos.z)); auto variation = m_terrain_variation.get_value(); @@ -352,7 +351,7 @@ void world::Overworld::generate_caves(const chunk_pos& cpos, VoxelStorage& voxel } } -void world::Overworld::generate_features(const chunk_pos& cpos, VoxelStorage& voxels) +void Overworld::generate_features(const chunk_pos& cpos, VoxelStorage& voxels) { const chunk_pos_xz tree_chunks[] = { chunk_pos_xz(cpos.x - 0, cpos.z - 1), diff --git a/src/game/server/world/overworld.hh b/src/game/server/world/overworld.hh index f3fc8cf..ef4bb54 100644 --- a/src/game/server/world/overworld.hh +++ b/src/game/server/world/overworld.hh @@ -11,24 +11,19 @@ constexpr static unsigned int OW_NUM_TREES = 4U; -namespace world -{ struct Overworld_Metadata final { - world::dimension_entropy_map entropy; - world::dimension_height_map heightmap; + dimension_entropy_map entropy; + dimension_height_map heightmap; std::vector<local_pos> trees; }; -} // namespace world -namespace world -{ class Overworld final : public Dimension { public: explicit Overworld(std::string_view name); virtual ~Overworld(void) = default; public: - virtual void init(io::ConfigMap& config) override; + virtual void init(ConfigMap& config) override; virtual void init_late(std::uint64_t global_seed) override; virtual bool generate(const chunk_pos& cpos, VoxelStorage& voxels) override; @@ -65,4 +60,3 @@ private: private: std::mutex m_mutex; }; -} // namespace world diff --git a/src/game/server/world/random_tick.cc b/src/game/server/world/random_tick.cc index c5fa47c..8fdcfeb 100644 --- a/src/game/server/world/random_tick.cc +++ b/src/game/server/world/random_tick.cc @@ -17,14 +17,14 @@ static config::Int random_tick_speed(2, 1, 1000); static std::mt19937_64 random_source; -void world::random_tick::init(void) +void random_tick::init(void) { globals::server_config.add_value("world.random_tick_speed", random_tick_speed); random_source.seed(std::random_device {}()); } -void world::random_tick::tick(const chunk_pos& cpos, Chunk* chunk) +void random_tick::tick(const chunk_pos& cpos, Chunk* chunk) { assert(chunk); diff --git a/src/game/server/world/random_tick.hh b/src/game/server/world/random_tick.hh index 4ef1691..9c67dc4 100644 --- a/src/game/server/world/random_tick.hh +++ b/src/game/server/world/random_tick.hh @@ -2,13 +2,10 @@ #include "shared/types.hh" -namespace world -{ class Chunk; -} // namespace world -namespace world::random_tick +namespace random_tick { void init(void); void tick(const chunk_pos& cpos, Chunk* chunk); -} // namespace world::random_tick +} // namespace random_tick diff --git a/src/game/server/world/universe.cc b/src/game/server/world/universe.cc index 6d52951..defefc6 100644 --- a/src/game/server/world/universe.cc +++ b/src/game/server/world/universe.cc @@ -22,17 +22,17 @@ struct DimensionMetadata final { std::string config_path; std::string zvox_dir; - io::ConfigMap config; + ConfigMap config; }; static config::String universe_name("save"); -static io::ConfigMap universe_config; +static ConfigMap universe_config; static config::Unsigned64 universe_config_seed; static config::String universe_spawn_dimension("world"); static std::string universe_config_path; -static std::unordered_map<world::Dimension*, DimensionMetadata*> metadata_map; +static std::unordered_map<Dimension*, DimensionMetadata*> metadata_map; static std::string make_chunk_filename(const DimensionMetadata* metadata, const chunk_pos& cpos) { @@ -42,7 +42,7 @@ static std::string make_chunk_filename(const DimensionMetadata* metadata, const return std::format("{}/{:08X}-{:08X}-{:08X}.zvox", metadata->zvox_dir, unsigned_x, unsigned_y, unsigned_z); } -static void add_new_dimension(world::Dimension* dimension) +static void add_new_dimension(Dimension* dimension) { if(globals::dimensions.count(std::string(dimension->get_name()))) { spdlog::critical("universe: dimension named {} already exists", dimension->get_name()); @@ -52,7 +52,7 @@ static void add_new_dimension(world::Dimension* dimension) auto dimension_dir = std::format("{}/{}", universe_name.get(), dimension->get_name()); if(!PHYSFS_mkdir(dimension_dir.c_str())) { - spdlog::critical("universe: {}: {}", dimension_dir, io::physfs_error()); + spdlog::critical("universe: {}: {}", dimension_dir, physfs_error()); std::terminate(); } @@ -61,7 +61,7 @@ static void add_new_dimension(world::Dimension* dimension) metadata->zvox_dir = std::format("{}/chunk", dimension_dir); if(!PHYSFS_mkdir(metadata->zvox_dir.c_str())) { - spdlog::critical("universe: {}: {}", metadata->zvox_dir, io::physfs_error()); + spdlog::critical("universe: {}: {}", metadata->zvox_dir, physfs_error()); std::terminate(); } @@ -76,12 +76,11 @@ static void add_new_dimension(world::Dimension* dimension) dimension->init_late(universe_config_seed.get_value()); } -static void internal_save_chunk(const DimensionMetadata* metadata, const world::Dimension* dimension, const chunk_pos& cpos, - const world::Chunk* chunk) +static void internal_save_chunk(const DimensionMetadata* metadata, const Dimension* dimension, const chunk_pos& cpos, const Chunk* chunk) { auto path = make_chunk_filename(metadata, cpos); - io::WriteBuffer buffer; + WriteBuffer buffer; chunk->get_voxels().serialize(buffer); if(auto file = buffer.to_file(path.c_str())) { @@ -90,7 +89,7 @@ static void internal_save_chunk(const DimensionMetadata* metadata, const world:: } } -void world::universe::init(void) +void universe::init(void) { // If the world is newly created, the seed will // be chosed based on the current system's view on UNIX time @@ -105,12 +104,12 @@ void world::universe::init(void) universe_config.add_value("spawn_dimension", universe_spawn_dimension); } -void world::universe::init_late(void) +void universe::init_late(void) { const auto universe_dir = std::string(universe_name.get()); if(!PHYSFS_mkdir(universe_dir.c_str())) { - spdlog::critical("universe: {}: {}", universe_dir, io::physfs_error()); + spdlog::critical("universe: {}: {}", universe_dir, physfs_error()); std::terminate(); } @@ -135,7 +134,7 @@ void world::universe::init_late(void) globals::spawn_dimension = spawn_dimension->second; } -void world::universe::shutdown(void) +void universe::shutdown(void) { for(const auto metadata : metadata_map) { metadata.second->config.save_file(metadata.second->config_path.c_str()); @@ -145,7 +144,7 @@ void world::universe::shutdown(void) metadata_map.clear(); for(const auto dimension : globals::dimensions) { - world::universe::save_all_chunks(dimension.second); + universe::save_all_chunks(dimension.second); delete dimension.second; } @@ -155,7 +154,7 @@ void world::universe::shutdown(void) universe_config.save_file(universe_config_path.c_str()); } -world::Chunk* world::universe::load_chunk(Dimension* dimension, const chunk_pos& cpos) +Chunk* universe::load_chunk(Dimension* dimension, const chunk_pos& cpos) { if(auto chunk = dimension->find_chunk(cpos)) { // Just return the existing chunk which is @@ -173,7 +172,7 @@ world::Chunk* world::universe::load_chunk(Dimension* dimension, const chunk_pos& if(auto file = PHYSFS_openRead(make_chunk_filename(metadata->second, cpos).c_str())) { VoxelStorage voxels; - io::ReadBuffer buffer(file); + ReadBuffer buffer(file); voxels.deserialize(buffer); PHYSFS_close(file); @@ -190,7 +189,7 @@ world::Chunk* world::universe::load_chunk(Dimension* dimension, const chunk_pos& return nullptr; } -void world::universe::save_chunk(Dimension* dimension, const chunk_pos& cpos) +void universe::save_chunk(Dimension* dimension, const chunk_pos& cpos) { auto metadata = metadata_map.find(dimension); @@ -205,7 +204,7 @@ void world::universe::save_chunk(Dimension* dimension, const chunk_pos& cpos) } } -void world::universe::save_all_chunks(Dimension* dimension) +void universe::save_all_chunks(Dimension* dimension) { auto group = dimension->chunks.group(entt::get<ChunkComponent, Inhabited>); auto metadata = metadata_map.find(dimension); diff --git a/src/game/server/world/universe.hh b/src/game/server/world/universe.hh index e542eca..31d3721 100644 --- a/src/game/server/world/universe.hh +++ b/src/game/server/world/universe.hh @@ -2,24 +2,21 @@ #include "shared/types.hh" -namespace world -{ class Chunk; class Dimension; -} // namespace world struct Session; -namespace world::universe +namespace universe { void init(void); void init_late(void); void shutdown(void); -} // namespace world::universe +} // namespace universe -namespace world::universe +namespace universe { Chunk* load_chunk(Dimension* dimension, const chunk_pos& cpos); void save_chunk(Dimension* dimension, const chunk_pos& cpos); void save_all_chunks(Dimension* dimension); -} // namespace world::universe +} // namespace universe diff --git a/src/game/server/world/unloader.cc b/src/game/server/world/unloader.cc index 4a3f4e1..5842b14 100644 --- a/src/game/server/world/unloader.cc +++ b/src/game/server/world/unloader.cc @@ -17,29 +17,29 @@ #include "server/game.hh" #include "server/globals.hh" -static void on_chunk_update(const world::ChunkUpdateEvent& event) +static void on_chunk_update(const ChunkUpdateEvent& event) { - event.dimension->chunks.emplace_or_replace<world::Inhabited>(event.chunk->get_entity()); + event.dimension->chunks.emplace_or_replace<Inhabited>(event.chunk->get_entity()); } -static void on_voxel_set(const world::VoxelSetEvent& event) +static void on_voxel_set(const VoxelSetEvent& event) { - event.dimension->chunks.emplace_or_replace<world::Inhabited>(event.chunk->get_entity()); + event.dimension->chunks.emplace_or_replace<Inhabited>(event.chunk->get_entity()); } -void world::unloader::init(void) +void unloader::init(void) { - globals::dispatcher.sink<world::ChunkUpdateEvent>().connect<&on_chunk_update>(); - globals::dispatcher.sink<world::VoxelSetEvent>().connect<&on_voxel_set>(); + globals::dispatcher.sink<ChunkUpdateEvent>().connect<&on_chunk_update>(); + globals::dispatcher.sink<VoxelSetEvent>().connect<&on_voxel_set>(); } -void world::unloader::init_late(void) +void unloader::init_late(void) { } -void world::unloader::fixed_update_late(Dimension* dimension) +void unloader::fixed_update_late(Dimension* dimension) { - auto group = dimension->entities.group(entt::get<entity::Player, entity::Transform>); + auto group = dimension->entities.group(entt::get<Player, Transform>); auto boxes = std::vector<ChunkAABB>(); for(const auto [entity, transform] : group.each()) { @@ -70,7 +70,7 @@ void world::unloader::fixed_update_late(Dimension* dimension) if(dimension->chunks.any_of<Inhabited>(entity)) { // Only store inhabited chunks on disk - world::universe::save_chunk(dimension, chunk.cpos); + universe::save_chunk(dimension, chunk.cpos); } dimension->remove_chunk(entity); diff --git a/src/game/server/world/unloader.hh b/src/game/server/world/unloader.hh index 9682de6..bf816bd 100644 --- a/src/game/server/world/unloader.hh +++ b/src/game/server/world/unloader.hh @@ -1,13 +1,10 @@ #pragma once -namespace world -{ class Dimension; -} // namespace world -namespace world::unloader +namespace unloader { void init(void); void init_late(void); void fixed_update_late(Dimension* dimension); -} // namespace world::unloader +} // namespace unloader diff --git a/src/game/server/world/worldgen.cc b/src/game/server/world/worldgen.cc index 8b02b52..c8c7ade 100644 --- a/src/game/server/world/worldgen.cc +++ b/src/game/server/world/worldgen.cc @@ -18,22 +18,22 @@ static bool aggressive_caching; -static emhash8::HashMap<world::Dimension*, emhash8::HashMap<chunk_pos, std::unordered_set<Session*>>> active_tasks; +static emhash8::HashMap<Dimension*, emhash8::HashMap<chunk_pos, std::unordered_set<Session*>>> active_tasks; class WorldgenTask final : public Task { public: - explicit WorldgenTask(world::Dimension* dimension, const chunk_pos& cpos); + explicit WorldgenTask(Dimension* dimension, const chunk_pos& cpos); virtual ~WorldgenTask(void) = default; virtual void process(void) override; virtual void finalize(void) override; private: - world::Dimension* m_dimension; - world::VoxelStorage m_voxels; + Dimension* m_dimension; + VoxelStorage m_voxels; chunk_pos m_cpos; }; -WorldgenTask::WorldgenTask(world::Dimension* dimension, const chunk_pos& cpos) +WorldgenTask::WorldgenTask(Dimension* dimension, const chunk_pos& cpos) { m_dimension = dimension; m_voxels.fill(rand()); // trolling @@ -75,7 +75,7 @@ void WorldgenTask::finalize(void) // it so that it is saved regardles of whether it was // modified by players or not. This isn't particularly // good for server-side disk usage but it might improve performance - m_dimension->chunks.emplace<world::Inhabited>(chunk->get_entity()); + m_dimension->chunks.emplace<Inhabited>(chunk->get_entity()); } protocol::ChunkVoxels response; @@ -102,12 +102,12 @@ void WorldgenTask::finalize(void) } } -void world::worldgen::init(void) +void worldgen::init(void) { - aggressive_caching = io::cmdline::contains("aggressive-caching"); + aggressive_caching = cmdline::contains("aggressive-caching"); } -bool world::worldgen::is_generating(Dimension* dimension, const chunk_pos& cpos) +bool worldgen::is_generating(Dimension* dimension, const chunk_pos& cpos) { auto dim_tasks = active_tasks.find(dimension); @@ -126,7 +126,7 @@ bool world::worldgen::is_generating(Dimension* dimension, const chunk_pos& cpos) return true; } -void world::worldgen::request_chunk(Session* session, const chunk_pos& cpos) +void worldgen::request_chunk(Session* session, const chunk_pos& cpos) { if(session->dimension) { auto dim_tasks = active_tasks.find(session->dimension); diff --git a/src/game/server/world/worldgen.hh b/src/game/server/world/worldgen.hh index 30d7070..f991744 100644 --- a/src/game/server/world/worldgen.hh +++ b/src/game/server/world/worldgen.hh @@ -2,20 +2,17 @@ #include "shared/types.hh" -namespace world -{ class Dimension; -} // namespace world struct Session; -namespace world::worldgen +namespace worldgen { void init(void); -} // namespace world::worldgen +} // namespace worldgen -namespace world::worldgen +namespace worldgen { bool is_generating(Dimension* dimension, const chunk_pos& cpos); void request_chunk(Session* session, const chunk_pos& cpos); -} // namespace world::worldgen +} // namespace worldgen |
