]> git.localhorst.tv Git - blank.git/blob - src/app/WorldState.cpp
fix some inline TODOs
[blank.git] / src / app / WorldState.cpp
1 #include "WorldState.hpp"
2
3 #include "Environment.hpp"
4
5 #include <SDL.h>
6
7
8 namespace blank {
9
10 WorldState::WorldState(
11         Environment &env,
12         const Interface::Config &ic,
13         const World::Config &wc,
14         const WorldSave &save
15 )
16 : env(env)
17 , world(env.assets, wc, save)
18 , spawner(world)
19 , interface(ic, env, world)
20 , preload(env, world.Loader())
21 , unload(env, world.Loader()) {
22
23 }
24
25
26 void WorldState::OnEnter() {
27         env.state.Push(&preload);
28 }
29
30
31 void WorldState::Handle(const SDL_Event &event) {
32         switch (event.type) {
33                 case SDL_KEYDOWN:
34                         interface.HandlePress(event.key);
35                         break;
36                 case SDL_KEYUP:
37                         interface.HandleRelease(event.key);
38                         break;
39                 case SDL_MOUSEBUTTONDOWN:
40                         interface.HandlePress(event.button);
41                         break;
42                 case SDL_MOUSEBUTTONUP:
43                         interface.HandleRelease(event.button);
44                         break;
45                 case SDL_MOUSEMOTION:
46                         interface.Handle(event.motion);
47                         break;
48                 case SDL_MOUSEWHEEL:
49                         interface.Handle(event.wheel);
50                         break;
51                 case SDL_QUIT:
52                         env.state.Switch(&unload);
53                         break;
54                 default:
55                         break;
56         }
57 }
58
59 void WorldState::Update(int dt) {
60         interface.Update(dt);
61         spawner.Update(dt);
62         world.Update(dt);
63
64         glm::mat4 trans = world.Player().Transform(Chunk::Pos(0, 0, 0));
65         glm::vec3 dir(trans * glm::vec4(0.0f, 0.0f, -1.0f, 0.0f));
66         glm::vec3 up(trans * glm::vec4(0.0f, 1.0f, 0.0f, 0.0f));
67         env.audio.Position(world.Player().Position());
68         env.audio.Velocity(world.Player().Velocity());
69         env.audio.Orientation(dir, up);
70
71 }
72
73 void WorldState::Render(Viewport &viewport) {
74         world.Render(viewport);
75         interface.Render(viewport);
76 }
77
78 }