1 #include "ServerState.hpp"
3 #include "../app/Environment.hpp"
4 #include "../app/TextureIndex.hpp"
5 #include "../io/WorldSave.hpp"
6 #include "../net/io.hpp"
14 ServerState::ServerState(
15 HeadlessEnvironment &env,
16 const Generator::Config &gc,
17 const World::Config &wc,
24 , world(block_types, wc)
26 , chunk_loader(world.Chunks(), generator, ws)
28 , spawner(world, skeletons, env.rng)
29 , server(config.net, world, wc, ws)
31 TextureIndex tex_index;
32 env.loader.LoadShapes("default", shapes);
33 env.loader.LoadBlockTypes("default", block_types, tex_index, shapes);
34 generator.LoadTypes(block_types);
35 skeletons.LoadHeadless();
36 spawner.LimitSkeletons(1, skeletons.size());
37 server.SetPlayerModel(skeletons[0]);
41 std::cout << "listening on UDP port " << config.net.port << std::endl;
44 ServerState::~ServerState() {
49 void ServerState::Handle(const SDL_Event &event) {
50 if (event.type == SDL_QUIT) {
51 std::cout << "saving remaining chunks" << std::endl;
52 for (Chunk &chunk : world.Chunks()) {
53 if (chunk.ShouldUpdateSave()) {
54 chunk_loader.SaveFile().Write(chunk);
62 void ServerState::Update(int dt) {
63 loop_timer.Update(dt);
66 while (loop_timer.HitOnce()) {
67 spawner.Update(loop_timer.Interval());
68 world.Update(loop_timer.Interval());
69 world_dt += loop_timer.Interval();
70 loop_timer.PopIteration();
72 chunk_loader.Update(dt);
74 server.Update(world_dt);
79 void ServerState::Render(Viewport &viewport) {