X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fui%2Fui.cpp;h=43cdb53613ec2660603204128f9fffc91cf24839;hb=57d3e33b47c92d56de4007e23800d9bcdb353463;hp=c7d8b2498c97a39e31b1ef75fa32002a96bc227f;hpb=b61d462707dd3d40a32a6104d88eb24f6a52df63;p=blank.git diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index c7d8b24..43cdb53 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -12,6 +12,7 @@ #include "../app/FrameCounter.hpp" #include "../app/init.hpp" #include "../audio/Audio.hpp" +#include "../audio/SoundBank.hpp" #include "../graphics/Font.hpp" #include "../graphics/Viewport.hpp" #include "../io/TokenStreamReader.hpp" @@ -82,10 +83,11 @@ void PlayerController::Invalidate() noexcept { } void PlayerController::UpdatePlayer() noexcept { - constexpr float max_vel = 0.005f; + constexpr float max_vel = 5.0f; // in m/s if (dirty) { - player.GetEntity().Orientation(glm::quat(glm::vec3(pitch, yaw, 0.0f))); - player.GetEntity().Velocity(glm::rotateY(move_dir * max_vel, yaw)); + player.GetEntity().Orientation(glm::quat(glm::vec3(0.0f, yaw, 0.0f))); + player.GetEntity().GetModel().EyesState().orientation = glm::quat(glm::vec3(pitch, 0.0f, 0.0f)); + player.GetEntity().TargetVelocity(glm::rotateY(move_dir * max_vel, yaw)); Ray aim = player.Aim(); if (!world.Intersection(aim, glm::mat4(1.0f), player.GetEntity().ChunkCoords(), aim_world)) { @@ -424,22 +426,26 @@ void HUD::Render(Viewport &viewport) noexcept { } -InteractiveManipulator::InteractiveManipulator(Environment &env, Entity &player) +InteractiveManipulator::InteractiveManipulator(Audio &audio, const SoundBank &sounds, Entity &player) : player(player) -, audio(env.audio) -, place_sound(env.loader.LoadSound("thump")) -, remove_sound(env.loader.LoadSound("plop")) { +, audio(audio) +, sounds(sounds) { } void InteractiveManipulator::SetBlock(Chunk &chunk, int index, const Block &block) { + const BlockType &old_type = chunk.Type(index); chunk.SetBlock(index, block); + const BlockType &new_type = chunk.Type(index); glm::vec3 coords = chunk.ToSceneCoords(player.ChunkCoords(), Chunk::ToCoords(index)); - // TODO: get sound effect from block type - if (block.type == 0) { - audio.Play(remove_sound, coords); + if (new_type.id == 0) { + if (old_type.remove_sound >= 0) { + audio.Play(sounds[old_type.remove_sound], coords); + } } else { - audio.Play(place_sound, coords); + if (new_type.place_sound >= 0) { + audio.Play(sounds[new_type.place_sound], coords); + } } }