]> git.localhorst.tv Git - blank.git/blobdiff - src/ui/ui.cpp
use "forces" for entity control and RK4 integrator
[blank.git] / src / ui / ui.cpp
index 4dd9711edac447276bc721235749a6d573b27e67..96386195e57803c4aa8fcd498072caa229df768f 100644 (file)
 #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"
-#include "../model/shapes.hpp"
+#include "../model/bounds.hpp"
 #include "../world/BlockLookup.hpp"
 #include "../world/World.hpp"
 #include "../world/WorldManipulator.hpp"
@@ -85,7 +86,7 @@ void PlayerController::UpdatePlayer() noexcept {
        constexpr float max_vel = 0.005f;
        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().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)) {
@@ -250,12 +251,12 @@ HUD::HUD(Environment &env, Config &config, const Player &player)
        messages.Background(glm::vec4(0.5f));
 
        // crosshair
-       OutlineModel::Buffer buf;
+       OutlineMesh::Buffer buf;
        buf.vertices = std::vector<glm::vec3>({
                { -10.0f,   0.0f, 0.0f }, { 10.0f,  0.0f, 0.0f },
                {   0.0f, -10.0f, 0.0f }, {  0.0f, 10.0f, 0.0f },
        });
-       buf.indices = std::vector<OutlineModel::Index>({
+       buf.indices = std::vector<OutlineMesh::Index>({
                0, 1, 2, 3
        });
        buf.colors.resize(4, { 10.0f, 10.0f, 10.0f });
@@ -264,7 +265,7 @@ HUD::HUD(Environment &env, Config &config, const Player &player)
 
 namespace {
 
-OutlineModel::Buffer outl_buf;
+OutlineMesh::Buffer outl_buf;
 
 }
 
@@ -272,7 +273,7 @@ void HUD::FocusBlock(const Chunk &chunk, int index) {
        const Block &block = chunk.BlockAt(index);
        const BlockType &type = chunk.Type(index);
        outl_buf.Clear();
-       type.FillOutlineModel(outl_buf);
+       type.FillOutlineMesh(outl_buf);
        outline.Update(outl_buf);
        outline_transform = chunk.Transform(player.GetEntity().ChunkCoords());
        outline_transform *= chunk.ToTransform(Chunk::ToPos(index), index);
@@ -312,7 +313,7 @@ void HUD::DisplayNone() {
 
 void HUD::Display(const BlockType &type) {
        block_buf.Clear();
-       type.FillEntityModel(block_buf);
+       type.FillEntityMesh(block_buf);
        block.Update(block_buf);
 
        block_label.Set(env.assets.small_ui_font, type.label);
@@ -424,22 +425,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);
+               }
        }
 }