summaryrefslogtreecommitdiffstats
path: root/src/game/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/server')
-rw-r--r--src/game/server/game.cc32
-rw-r--r--src/game/server/globals.cc6
-rw-r--r--src/game/server/globals.hh12
-rw-r--r--src/game/server/main.cc2
-rw-r--r--src/game/server/receive.cc22
-rw-r--r--src/game/server/sessions.cc34
-rw-r--r--src/game/server/sessions.hh9
-rw-r--r--src/game/server/whitelist.cc2
-rw-r--r--src/game/server/world/inhabited.hh3
-rw-r--r--src/game/server/world/overworld.cc25
-rw-r--r--src/game/server/world/overworld.hh12
-rw-r--r--src/game/server/world/random_tick.cc4
-rw-r--r--src/game/server/world/random_tick.hh7
-rw-r--r--src/game/server/world/universe.cc35
-rw-r--r--src/game/server/world/universe.hh11
-rw-r--r--src/game/server/world/unloader.cc22
-rw-r--r--src/game/server/world/unloader.hh7
-rw-r--r--src/game/server/world/worldgen.cc20
-rw-r--r--src/game/server/world/worldgen.hh11
19 files changed, 122 insertions, 154 deletions
diff --git a/src/game/server/game.cc b/src/game/server/game.cc
index 3a13690..deb7d68 100644
--- a/src/game/server/game.cc
+++ b/src/game/server/game.cc
@@ -66,12 +66,12 @@ void server_game::init(void)
server_chat::init();
server_recieve::init();
- world::worldgen::init();
+ worldgen::init();
- world::unloader::init();
- world::universe::init();
+ unloader::init();
+ universe::init();
- world::random_tick::init();
+ random_tick::init();
}
void server_game::init_late(void)
@@ -99,8 +99,8 @@ void server_game::init_late(void)
game_voxels::populate();
game_items::populate();
- world::unloader::init_late();
- world::universe::init_late();
+ unloader::init_late();
+ universe::init_late();
sessions::init_post_universe();
}
@@ -119,21 +119,21 @@ void server_game::shutdown(void)
enet_host_service(globals::server_host, nullptr, 500);
enet_host_destroy(globals::server_host);
- world::universe::shutdown();
+ universe::shutdown();
}
void server_game::fixed_update(void)
{
// FIXME: threading
for(auto dimension : globals::dimensions) {
- entity::Collision::fixed_update(dimension.second);
- entity::Velocity::fixed_update(dimension.second);
- entity::Transform::fixed_update(dimension.second);
- entity::Gravity::fixed_update(dimension.second);
- entity::Stasis::fixed_update(dimension.second);
-
- for(auto [entity, component] : dimension.second->chunks.view<world::ChunkComponent>().each()) {
- world::random_tick::tick(component.cpos, component.chunk);
+ Collision::fixed_update(dimension.second);
+ Velocity::fixed_update(dimension.second);
+ Transform::fixed_update(dimension.second);
+ Gravity::fixed_update(dimension.second);
+ Stasis::fixed_update(dimension.second);
+
+ for(auto [entity, component] : dimension.second->chunks.view<ChunkComponent>().each()) {
+ random_tick::tick(component.cpos, component.chunk);
}
}
}
@@ -158,6 +158,6 @@ void server_game::fixed_update_late(void)
// FIXME: threading
for(auto dimension : globals::dimensions) {
- world::unloader::fixed_update_late(dimension.second);
+ unloader::fixed_update_late(dimension.second);
}
}
diff --git a/src/game/server/globals.cc b/src/game/server/globals.cc
index 7d79e4d..12fce4a 100644
--- a/src/game/server/globals.cc
+++ b/src/game/server/globals.cc
@@ -6,7 +6,7 @@
#include "shared/protocol.hh"
-io::ConfigMap globals::server_config;
+ConfigMap globals::server_config;
ENetHost* globals::server_host;
@@ -14,5 +14,5 @@ bool globals::is_running;
unsigned int globals::tickrate;
std::uint64_t globals::tickrate_dt;
-world::Dimension* globals::spawn_dimension;
-std::unordered_map<std::string, world::Dimension*> globals::dimensions;
+Dimension* globals::spawn_dimension;
+std::unordered_map<std::string, Dimension*> globals::dimensions;
diff --git a/src/game/server/globals.hh b/src/game/server/globals.hh
index b684d3b..80e84bb 100644
--- a/src/game/server/globals.hh
+++ b/src/game/server/globals.hh
@@ -2,19 +2,13 @@
#include "shared/globals.hh"
-namespace io
-{
class ConfigMap;
-} // namespace io
-namespace world
-{
class Dimension;
-} // namespace world
namespace globals
{
-extern io::ConfigMap server_config;
+extern ConfigMap server_config;
extern ENetHost* server_host;
@@ -22,6 +16,6 @@ extern bool is_running;
extern unsigned int tickrate;
extern std::uint64_t tickrate_dt;
-extern world::Dimension* spawn_dimension;
-extern std::unordered_map<std::string, world::Dimension*> dimensions;
+extern Dimension* spawn_dimension;
+extern std::unordered_map<std::string, Dimension*> dimensions;
} // namespace globals
diff --git a/src/game/server/main.cc b/src/game/server/main.cc
index cf265a4..181145f 100644
--- a/src/game/server/main.cc
+++ b/src/game/server/main.cc
@@ -31,7 +31,7 @@ static void on_termination_signal(int)
int main(int argc, char** argv)
{
- io::cmdline::create(argc, argv);
+ cmdline::create(argc, argv);
shared_game::init(argc, argv, "voxelius-server.log");
diff --git a/src/game/server/receive.cc b/src/game/server/receive.cc
index b804450..a3ce14b 100644
--- a/src/game/server/receive.cc
+++ b/src/game/server/receive.cc
@@ -27,7 +27,7 @@ static void on_entity_transform_packet(const protocol::EntityTransform& packet)
{
if(auto session = sessions::find(packet.peer)) {
if(session->dimension && session->dimension->entities.valid(session->player_entity)) {
- auto& component = session->dimension->entities.emplace_or_replace<entity::Transform>(session->player_entity);
+ auto& component = session->dimension->entities.emplace_or_replace<Transform>(session->player_entity);
component.angles = packet.angles;
component.chunk = packet.chunk;
component.local = packet.local;
@@ -49,7 +49,7 @@ static void on_entity_velocity_packet(const protocol::EntityVelocity& packet)
{
if(auto session = sessions::find(packet.peer)) {
if(session->dimension && session->dimension->entities.valid(session->player_entity)) {
- auto& component = session->dimension->entities.emplace_or_replace<entity::Velocity>(session->player_entity);
+ auto& component = session->dimension->entities.emplace_or_replace<Velocity>(session->player_entity);
component.value = packet.value;
protocol::EntityVelocity response;
@@ -67,7 +67,7 @@ static void on_entity_head_packet(const protocol::EntityHead& packet)
{
if(auto session = sessions::find(packet.peer)) {
if(session->dimension && session->dimension->entities.valid(session->player_entity)) {
- auto& component = session->dimension->entities.emplace_or_replace<entity::Head>(session->player_entity);
+ auto& component = session->dimension->entities.emplace_or_replace<Head>(session->player_entity);
component.angles = packet.angles;
protocol::EntityHead response;
@@ -84,12 +84,12 @@ static void on_entity_head_packet(const protocol::EntityHead& packet)
static void on_set_voxel_packet(const protocol::SetVoxel& packet)
{
if(auto session = sessions::find(packet.peer)) {
- if(session->dimension && !session->dimension->set_voxel(world::voxel_registry::find(packet.voxel), packet.vpos)) {
+ if(session->dimension && !session->dimension->set_voxel(voxel_registry::find(packet.voxel), packet.vpos)) {
auto cpos = coord::to_chunk(packet.vpos);
auto lpos = coord::to_local(packet.vpos);
auto index = coord::to_index(lpos);
- if(world::worldgen::is_generating(session->dimension, cpos)) {
+ if(worldgen::is_generating(session->dimension, cpos)) {
// The chunk is currently being generated;
// ignore all requests from players to build there
return;
@@ -103,9 +103,9 @@ static void on_set_voxel_packet(const protocol::SetVoxel& packet)
return;
}
- chunk->set_voxel(world::voxel_registry::find(packet.voxel), index);
+ chunk->set_voxel(voxel_registry::find(packet.voxel), index);
- session->dimension->chunks.emplace_or_replace<world::Inhabited>(chunk->get_entity());
+ session->dimension->chunks.emplace_or_replace<Inhabited>(chunk->get_entity());
protocol::SetVoxel response;
response.vpos = packet.vpos;
@@ -126,20 +126,20 @@ static void on_request_chunk_packet(const protocol::RequestChunk& packet)
return;
}
- if(auto transform = session->dimension->entities.try_get<entity::Transform>(session->player_entity)) {
- world::ChunkAABB view_box;
+ if(auto transform = session->dimension->entities.try_get<Transform>(session->player_entity)) {
+ ChunkAABB view_box;
view_box.min = transform->chunk - static_cast<chunk_pos::value_type>(server_game::view_distance.get_value());
view_box.max = transform->chunk + static_cast<chunk_pos::value_type>(server_game::view_distance.get_value());
if(view_box.contains(packet.cpos)) {
- if(auto chunk = world::universe::load_chunk(session->dimension, packet.cpos)) {
+ if(auto chunk = universe::load_chunk(session->dimension, packet.cpos)) {
protocol::ChunkVoxels response;
response.chunk = packet.cpos;
response.voxels = chunk->get_voxels();
protocol::send(packet.peer, protocol::encode(response));
}
else {
- world::worldgen::request_chunk(session, packet.cpos);
+ worldgen::request_chunk(session, packet.cpos);
}
}
}
diff --git a/src/game/server/sessions.cc b/src/game/server/sessions.cc
index 3a63ae8..b161d55 100644
--- a/src/game/server/sessions.cc
+++ b/src/game/server/sessions.cc
@@ -34,11 +34,11 @@
class DimensionListener final {
public:
- explicit DimensionListener(world::Dimension* dimension);
+ explicit DimensionListener(Dimension* dimension);
void on_destroy_entity(const entt::registry& registry, entt::entity entity);
private:
- world::Dimension* dimension;
+ Dimension* dimension;
};
config::Unsigned sessions::max_players(8U, 1U, 128U);
@@ -85,14 +85,14 @@ static void on_login_request_packet(const protocol::LoginRequest& packet)
// FIXME: calculate voxel registry checksum ahead of time
// instead of figuring it out every time a new player connects
- if(packet.voxel_registry_checksum != world::voxel_registry::get_checksum()) {
+ if(packet.voxel_registry_checksum != voxel_registry::get_checksum()) {
protocol::Disconnect response;
response.reason = "protocol.voxel_registry_checksum";
protocol::send(packet.peer, protocol::encode(response));
return;
}
- if(packet.item_registry_checksum != world::item_registry::get_checksum()) {
+ if(packet.item_registry_checksum != item_registry::get_checksum()) {
protocol::Disconnect response;
response.reason = "protocol.item_registry_checksum";
protocol::send(packet.peer, protocol::encode(response));
@@ -151,14 +151,14 @@ static void on_login_request_packet(const protocol::LoginRequest& packet)
// anything here and just straight up spawing the player and await them
// to receive all the chunks and entites they feel like requesting
for(auto entity : globals::spawn_dimension->entities.view<entt::entity>()) {
- if(const auto head = globals::spawn_dimension->entities.try_get<entity::Head>(entity)) {
+ if(const auto head = globals::spawn_dimension->entities.try_get<Head>(entity)) {
protocol::EntityHead head_packet;
head_packet.entity = entity;
head_packet.angles = head->angles;
protocol::send(session->peer, protocol::encode(head_packet));
}
- if(const auto transform = globals::spawn_dimension->entities.try_get<entity::Transform>(entity)) {
+ if(const auto transform = globals::spawn_dimension->entities.try_get<Transform>(entity)) {
protocol::EntityTransform transform_packet;
transform_packet.entity = entity;
transform_packet.angles = transform->angles;
@@ -167,14 +167,14 @@ static void on_login_request_packet(const protocol::LoginRequest& packet)
protocol::send(session->peer, protocol::encode(transform_packet));
}
- if(const auto velocity = globals::spawn_dimension->entities.try_get<entity::Velocity>(entity)) {
+ if(const auto velocity = globals::spawn_dimension->entities.try_get<Velocity>(entity)) {
protocol::EntityVelocity velocity_packet;
velocity_packet.entity = entity;
velocity_packet.value = velocity->value;
protocol::send(session->peer, protocol::encode(velocity_packet));
}
- if(globals::spawn_dimension->entities.all_of<entity::Player>(entity)) {
+ if(globals::spawn_dimension->entities.all_of<Player>(entity)) {
protocol::EntityPlayer player_packet;
player_packet.entity = entity;
protocol::send(session->peer, protocol::encode(player_packet));
@@ -183,11 +183,11 @@ static void on_login_request_packet(const protocol::LoginRequest& packet)
session->dimension = globals::spawn_dimension;
session->player_entity = globals::spawn_dimension->entities.create();
- entity::shared::create_player(globals::spawn_dimension, session->player_entity);
+ shared::create_player(globals::spawn_dimension, session->player_entity);
- const auto& head = globals::spawn_dimension->entities.get<entity::Head>(session->player_entity);
- const auto& transform = globals::spawn_dimension->entities.get<entity::Transform>(session->player_entity);
- const auto& velocity = globals::spawn_dimension->entities.get<entity::Velocity>(session->player_entity);
+ const auto& head = globals::spawn_dimension->entities.get<Head>(session->player_entity);
+ const auto& transform = globals::spawn_dimension->entities.get<Transform>(session->player_entity);
+ const auto& velocity = globals::spawn_dimension->entities.get<Velocity>(session->player_entity);
protocol::EntityHead head_packet;
head_packet.entity = session->player_entity;
@@ -257,7 +257,7 @@ static void on_disconnect_packet(const protocol::Disconnect& packet)
// NOTE: [sessions] is a good place for this since [receive]
// handles entity data sent by players and [sessions] handles
// everything else network related that is not player movement
-static void on_voxel_set(const world::VoxelSetEvent& event)
+static void on_voxel_set(const VoxelSetEvent& event)
{
protocol::SetVoxel packet;
packet.vpos = coord::to_voxel(event.cpos, event.lpos);
@@ -266,7 +266,7 @@ static void on_voxel_set(const world::VoxelSetEvent& event)
protocol::broadcast(globals::server_host, protocol::encode(packet));
}
-DimensionListener::DimensionListener(world::Dimension* dimension)
+DimensionListener::DimensionListener(Dimension* dimension)
{
this->dimension = dimension;
}
@@ -286,7 +286,7 @@ void sessions::init(void)
globals::dispatcher.sink<protocol::LoginRequest>().connect<&on_login_request_packet>();
globals::dispatcher.sink<protocol::Disconnect>().connect<&on_disconnect_packet>();
- globals::dispatcher.sink<world::VoxelSetEvent>().connect<&on_voxel_set>();
+ globals::dispatcher.sink<VoxelSetEvent>().connect<&on_voxel_set>();
}
void sessions::init_late(void)
@@ -420,7 +420,7 @@ void sessions::destroy(Session* session)
}
}
-void sessions::broadcast(const world::Dimension* dimension, ENetPacket* packet)
+void sessions::broadcast(const Dimension* dimension, ENetPacket* packet)
{
for(const auto& session : sessions_vector) {
if(session.peer && (session.dimension == dimension)) {
@@ -429,7 +429,7 @@ void sessions::broadcast(const world::Dimension* dimension, ENetPacket* packet)
}
}
-void sessions::broadcast(const world::Dimension* dimension, ENetPacket* packet, ENetPeer* except)
+void sessions::broadcast(const Dimension* dimension, ENetPacket* packet, ENetPeer* except)
{
for(const auto& session : sessions_vector) {
if(session.peer && (session.peer != except)) {
diff --git a/src/game/server/sessions.hh b/src/game/server/sessions.hh
index 656b76d..4c64f80 100644
--- a/src/game/server/sessions.hh
+++ b/src/game/server/sessions.hh
@@ -1,9 +1,6 @@
#pragma once
-namespace world
-{
class Dimension;
-} // namespace world
namespace config
{
@@ -15,7 +12,7 @@ struct Session final {
std::uint64_t client_identity;
std::string client_username;
entt::entity player_entity;
- world::Dimension* dimension;
+ Dimension* dimension;
ENetPeer* peer;
};
@@ -45,8 +42,8 @@ void destroy(Session* session);
namespace sessions
{
-void broadcast(const world::Dimension* dimension, ENetPacket* packet);
-void broadcast(const world::Dimension* dimension, ENetPacket* packet, ENetPeer* except);
+void broadcast(const Dimension* dimension, ENetPacket* packet);
+void broadcast(const Dimension* dimension, ENetPacket* packet, ENetPeer* except);
} // namespace sessions
namespace sessions
diff --git a/src/game/server/whitelist.cc b/src/game/server/whitelist.cc
index 3f1c413..555e5f3 100644
--- a/src/game/server/whitelist.cc
+++ b/src/game/server/whitelist.cc
@@ -48,7 +48,7 @@ void whitelist::init_late(void)
PHYSFS_File* file = PHYSFS_openRead(whitelist::filename.c_str());
if(file == nullptr) {
- spdlog::warn("whitelist: {}: {}", whitelist::filename.get(), io::physfs_error());
+ spdlog::warn("whitelist: {}: {}", whitelist::filename.get(), physfs_error());
whitelist::enabled.set_value(false);
return;
}
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