]> git.localhorst.tv Git - blank.git/blob - src/app/ServerState.cpp
c2163ad161976124f08b5bbcfc3cf1dba450d826
[blank.git] / src / app / ServerState.cpp
1 #include "ServerState.hpp"
2
3 #include "Environment.hpp"
4 #include "TextureIndex.hpp"
5 #include "../net/io.hpp"
6
7 #include <iostream>
8
9
10 namespace blank {
11
12 ServerState::ServerState(
13         HeadlessEnvironment &env,
14         const World::Config &wc,
15         const WorldSave &ws,
16         const Server::Config &sc
17 )
18 : env(env)
19 , block_types()
20 , world(block_types, wc, ws)
21 , skeletons()
22 , spawner(world, skeletons, wc.gen.seed)
23 , server(sc, world)
24 , push_timer(16) {
25         TextureIndex tex_index;
26         env.loader.LoadBlockTypes("default", block_types, tex_index);
27         skeletons.LoadHeadless();
28
29         push_timer.Start();
30
31         std::cout << "listening on UDP port " << sc.port << std::endl;
32 }
33
34
35 void ServerState::Handle(const SDL_Event &event) {
36         if (event.type == SDL_QUIT) {
37                 env.state.PopAll();
38         }
39 }
40
41
42 void ServerState::Update(int dt) {
43         push_timer.Update(dt);
44         server.Handle();
45         spawner.Update(dt);
46         if (!world.Players().empty()) {
47                 world.Update(dt);
48         }
49         if (push_timer.Hit()) {
50                 server.Update(dt);
51         }
52 }
53
54
55 void ServerState::Render(Viewport &viewport) {
56
57 }
58
59 }