X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fui%2Fui.cpp;h=0c89a2f3a554ab6c0347ed669bdd71d801dea22a;hb=551573ecb04969696f916aeb5485658e298a7f6b;hp=6fa7356c790b25894a09a4bf22e5dc4076e7980b;hpb=a1f911f8257f614f874c201fede5d5206f5b7e80;p=blank.git diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index 6fa7356..0c89a2f 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -2,6 +2,7 @@ #include "Interface.hpp" #include "../app/Assets.hpp" +#include "../app/Environment.hpp" #include "../app/FrameCounter.hpp" #include "../app/init.hpp" #include "../audio/Audio.hpp" @@ -92,15 +93,12 @@ void HUD::Render(Viewport &viewport) noexcept { Interface::Interface( const Config &config, - const Assets &assets, - Audio &audio, - const FrameCounter &counter, + Environment &env, World &world) -: audio(audio) -, counter(counter) +: env(env) , world(world) , ctrl(world.Player()) -, font(assets.LoadFont("DejaVuSans", 16)) +, font(env.assets.LoadFont("DejaVuSans", 16)) , hud(world.BlockTypes(), font) , aim{{ 0, 0, 0 }, { 0, 0, -1 }} , aim_chunk(nullptr) @@ -116,8 +114,8 @@ Interface::Interface( , remove_timer(256) , remove(0) , selection(1) -, place_sound(assets.LoadSound("thump")) -, remove_sound(assets.LoadSound("plop")) +, place_sound(env.assets.LoadSound("thump")) +, remove_sound(env.assets.LoadSound("plop")) , fwd(0) , rev(0) { counter_text.Hide(); @@ -354,8 +352,8 @@ void Interface::ToggleDebug() { void Interface::UpdateCounter() { std::stringstream s; s << std::setprecision(3) << - "avg: " << counter.Average().running << "ms, " - "peak: " << counter.Peak().running << "ms"; + "avg: " << env.counter.Average().running << "ms, " + "peak: " << env.counter.Peak().running << "ms"; std::string text = s.str(); counter_text.Set(font, text); } @@ -412,11 +410,10 @@ void Interface::PlaceBlock() { next_pos -= aim_normal * glm::vec3(Chunk::Extent()); } mod_chunk->SetBlock(next_pos, selection); - mod_chunk->Invalidate(); if (config.audio_disabled) return; const Entity &player = ctrl.Controlled(); - audio.Play( + env.audio.Play( place_sound, mod_chunk->ToSceneCoords(player.ChunkCoords(), next_pos) ); @@ -425,11 +422,10 @@ void Interface::PlaceBlock() { void Interface::RemoveBlock() noexcept { if (!aim_chunk) return; aim_chunk->SetBlock(aim_block, remove); - aim_chunk->Invalidate(); if (config.audio_disabled) return; const Entity &player = ctrl.Controlled(); - audio.Play( + env.audio.Play( remove_sound, aim_chunk->ToSceneCoords(player.ChunkCoords(), Chunk::ToCoords(aim_block)) ); @@ -496,7 +492,7 @@ void Interface::Update(int dt) { CheckAim(); } - if (counter_text.Visible() && counter.Changed()) { + if (counter_text.Visible() && env.counter.Changed()) { UpdateCounter(); } if (position_text.Visible()) {