]> git.localhorst.tv Git - blank.git/blob - src/app/ServerState.cpp
some experiements with state sync
[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 , loop_timer(16)
28 , push_timer(16) {
29         TextureIndex tex_index;
30         env.loader.LoadBlockTypes("default", block_types, tex_index);
31         skeletons.LoadHeadless();
32
33         loop_timer.Start();
34         push_timer.Start();
35
36         std::cout << "listening on UDP port " << sc.port << std::endl;
37 }
38
39
40 void ServerState::Handle(const SDL_Event &event) {
41         if (event.type == SDL_QUIT) {
42                 env.state.PopAll();
43         }
44 }
45
46
47 void ServerState::Update(int dt) {
48         loop_timer.Update(dt);
49         push_timer.Update(dt);
50         server.Handle();
51         while (loop_timer.HitOnce()) {
52                 spawner.Update(loop_timer.Interval());
53                 world.Update(loop_timer.Interval());
54                 loop_timer.PopIteration();
55         }
56         chunk_loader.Update(dt);
57         if (push_timer.Hit()) {
58                 server.Update(dt);
59         }
60 }
61
62
63 void ServerState::Render(Viewport &viewport) {
64
65 }
66
67 }