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