]> git.localhorst.tv Git - blank.git/blob - src/app/ServerState.cpp
sync entities with clients
[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 , server(sc, world)
22 , push_timer(16) {
23         TextureIndex tex_index;
24         env.loader.LoadBlockTypes("default", block_types, tex_index);
25
26         push_timer.Start();
27
28         std::cout << "listening on UDP port " << sc.port << std::endl;
29 }
30
31
32 void ServerState::Handle(const SDL_Event &event) {
33         if (event.type == SDL_QUIT) {
34                 env.state.PopAll();
35         }
36 }
37
38
39 void ServerState::Update(int dt) {
40         push_timer.Update(dt);
41
42         server.Handle();
43         if (push_timer.Hit()) {
44                 server.Update(dt);
45         }
46 }
47
48
49 void ServerState::Render(Viewport &viewport) {
50
51 }
52
53 }