#include "../app/Assets.hpp"
#include "../app/FrameCounter.hpp"
#include "../app/init.hpp"
+#include "../audio/Audio.hpp"
#include "../graphics/Font.hpp"
#include "../graphics/Viewport.hpp"
#include "../model/shapes.hpp"
block_transform = glm::rotate(block_transform, 3.5f, glm::vec3(1.0f, 0.0f, 0.0f));
block_transform = glm::rotate(block_transform, 0.35f, glm::vec3(0.0f, 1.0f, 0.0f));
- crosshair.vertices = std::vector<glm::vec3>({
+ OutlineModel::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 },
});
- crosshair.indices = std::vector<OutlineModel::Index>({
+ buf.indices = std::vector<OutlineModel::Index>({
0, 1, 2, 3
});
- crosshair.colors.resize(4, { 10.0f, 10.0f, 10.0f });
- crosshair.Invalidate();
+ buf.colors.resize(4, { 10.0f, 10.0f, 10.0f });
+ crosshair.Update(buf);
block_label.Position(
glm::vec3(50.0f, 85.0f, 0.0f),
const BlockType &type = types.Get(b.type);
block_buf.Clear();
- type.FillModel(block_buf, b.Transform());
+ type.FillEntityModel(block_buf, b.Transform());
block.Update(block_buf);
block_label.Set(font, type.label);
Interface::Interface(
const Config &config,
const Assets &assets,
+ Audio &audio,
const FrameCounter &counter,
World &world)
-: counter(counter)
+: audio(audio)
+, counter(counter)
, world(world)
, ctrl(world.Player())
, font(assets.LoadFont("DejaVuSans", 16))
, remove_timer(256)
, remove(0)
, selection(1)
+, place_sound(assets.LoadSound("thump"))
+, remove_sound(assets.LoadSound("plop"))
, fwd(0)
, rev(0) {
counter_text.Hide();
PrintSelectionInfo();
break;
+ case SDLK_F1:
+ ToggleVisual();
+ break;
case SDLK_F3:
ToggleCounter();
break;
+ case SDLK_F4:
+ ToggleAudio();
+ break;
}
}
PostMessage(s.str());
}
+void Interface::ToggleAudio() {
+ config.audio_disabled = !config.audio_disabled;
+ if (config.audio_disabled) {
+ PostMessage("audio off");
+ } else {
+ PostMessage("audio on");
+ }
+}
+
+void Interface::ToggleVisual() {
+ config.visual_disabled = !config.visual_disabled;
+ if (config.visual_disabled) {
+ PostMessage("visual off");
+ } else {
+ PostMessage("visual on");
+ }
+}
+
void Interface::ToggleCounter() {
counter_text.Toggle();
if (counter_text.Visible()) {
void Interface::UpdateCounter() {
std::stringstream s;
- s << std::setprecision(3) << counter.AvgRunning() << "ms";
+ s << std::setprecision(3) <<
+ "avg: " << counter.Average().running << "ms, "
+ "peak: " << counter.Peak().running << "ms";
std::string text = s.str();
counter_text.Set(font, text);
}
}
mod_chunk->SetBlock(next_pos, selection);
mod_chunk->Invalidate();
+
+ if (config.audio_disabled) return;
+ const Entity &player = ctrl.Controlled();
+ audio.Play(
+ place_sound,
+ mod_chunk->ToSceneCoords(player.ChunkCoords(), next_pos)
+ );
}
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(
+ remove_sound,
+ aim_chunk->ToSceneCoords(player.ChunkCoords(), Chunk::ToCoords(aim_block))
+ );
}
}
}
+namespace {
+
+OutlineModel::Buffer outl_buf;
+
+}
+
void Interface::CheckAim() {
float dist;
if (world.Intersection(aim, glm::mat4(1.0f), aim_chunk, aim_block, dist, aim_normal)) {
- outline.Clear();
- aim_chunk->Type(aim_chunk->BlockAt(aim_block)).FillOutlineModel(outline);
+ outl_buf.Clear();
+ aim_chunk->Type(aim_chunk->BlockAt(aim_block)).FillOutlineModel(outl_buf);
+ outline.Update(outl_buf);
outline_transform = glm::scale(glm::vec3(1.0002f));
outline_transform *= aim_chunk->Transform(world.Player().ChunkCoords());
outline_transform *= aim_chunk->ToTransform(Chunk::ToPos(aim_block), aim_block);