1 #include "WorldState.hpp"
3 #include "Environment.hpp"
10 WorldState::WorldState(
12 const Interface::Config &ic,
13 const World::Config &wc,
17 , world(env.assets, wc, save)
19 , interface(ic, env, world)
20 , preload(env, world.Loader())
21 , unload(env, world.Loader()) {
26 void WorldState::OnEnter() {
27 env.state.Push(&preload);
31 void WorldState::Handle(const SDL_Event &event) {
34 interface.HandlePress(event.key);
37 interface.HandleRelease(event.key);
39 case SDL_MOUSEBUTTONDOWN:
40 interface.HandlePress(event.button);
42 case SDL_MOUSEBUTTONUP:
43 interface.HandleRelease(event.button);
46 interface.Handle(event.motion);
49 interface.Handle(event.wheel);
52 env.state.Switch(&unload);
59 void WorldState::Update(int dt) {
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);
73 void WorldState::Render(Viewport &viewport) {
74 world.Render(viewport);
75 interface.Render(viewport);