1 #include "ServerState.hpp"
3 #include "../app/Environment.hpp"
4 #include "../app/TextureIndex.hpp"
5 #include "../net/io.hpp"
13 ServerState::ServerState(
14 HeadlessEnvironment &env,
15 const Generator::Config &gc,
16 const World::Config &wc,
22 , world(block_types, wc)
23 , spawn_index(world.Chunks().MakeIndex(wc.spawn, 3))
25 , chunk_loader(world.Chunks(), generator, ws)
27 , spawner(world, skeletons, env.rng)
28 , server(config.net, world, ws)
30 TextureIndex tex_index;
31 env.loader.LoadBlockTypes("default", block_types, tex_index);
32 generator.LoadTypes(block_types);
33 skeletons.LoadHeadless();
34 spawner.LimitSkeletons(1, skeletons.size());
35 server.SetPlayerModel(skeletons[0]);
39 std::cout << "listening on UDP port " << config.net.port << std::endl;
42 ServerState::~ServerState() {
43 world.Chunks().UnregisterIndex(spawn_index);
47 void ServerState::Handle(const SDL_Event &event) {
48 if (event.type == SDL_QUIT) {
54 void ServerState::Update(int dt) {
55 loop_timer.Update(dt);
58 while (loop_timer.HitOnce()) {
59 spawner.Update(loop_timer.Interval());
60 world.Update(loop_timer.Interval());
61 world_dt += loop_timer.Interval();
62 loop_timer.PopIteration();
64 chunk_loader.Update(dt);
66 server.Update(world_dt);
71 void ServerState::Render(Viewport &viewport) {