]> git.localhorst.tv Git - blank.git/blob - src/app/ServerState.cpp
fix loop removing players from world
[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 Generator::Config &gc,
15         const World::Config &wc,
16         const WorldSave &ws,
17         const Server::Config &sc
18 )
19 : env(env)
20 , block_types()
21 , world(block_types, wc)
22 , generator(gc)
23 , chunk_loader(world.Chunks(), generator, ws)
24 , skeletons()
25 , spawner(world, skeletons, gc.seed)
26 , server(sc, world)
27 , push_timer(16) {
28         TextureIndex tex_index;
29         env.loader.LoadBlockTypes("default", block_types, tex_index);
30         skeletons.LoadHeadless();
31
32         push_timer.Start();
33
34         std::cout << "listening on UDP port " << sc.port << std::endl;
35 }
36
37
38 void ServerState::Handle(const SDL_Event &event) {
39         if (event.type == SDL_QUIT) {
40                 env.state.PopAll();
41         }
42 }
43
44
45 void ServerState::Update(int dt) {
46         push_timer.Update(dt);
47         server.Handle();
48         spawner.Update(dt);
49         world.Update(dt);
50         chunk_loader.Update(dt);
51         if (push_timer.Hit()) {
52                 server.Update(dt);
53         }
54 }
55
56
57 void ServerState::Render(Viewport &viewport) {
58
59 }
60
61 }