- }
-}
-
-void Interface::FaceBlock() {
- selection.SetFace(Block::Face((selection.GetFace() + 1) % Block::FACE_COUNT));
- hud.Display(selection);
-}
-
-void Interface::TurnBlock() {
- selection.SetTurn(Block::Turn((selection.GetTurn() + 1) % Block::TURN_COUNT));
- hud.Display(selection);
-}
-
-void Interface::ToggleCollision() {
- ctrl.Controlled().WorldCollidable(!ctrl.Controlled().WorldCollidable());
- if (ctrl.Controlled().WorldCollidable()) {
- PostMessage("collision on");
- } else {
- PostMessage("collision off");
- }
-}
-
-void Interface::PrintBlockInfo() {
- std::cout << std::endl;
- if (!aim_world) {
- PostMessage("not looking at any block");
- Ray aim = ctrl.Aim();
- std::stringstream s;
- s << "aim ray: " << aim.orig << ", " << aim.dir;
- PostMessage(s.str());
- return;
- }
- std::stringstream s;
- s << "looking at block " << aim_world.block
- << " " << aim_world.BlockCoords()
- << " of chunk " << aim_world.GetChunk().Position()
- ;
- PostMessage(s.str());
- Print(aim_world.GetBlock());
-}
-
-void Interface::PrintChunkInfo() {
- std::cout << std::endl;
- if (!aim_world) {
- PostMessage("not looking at any block");
- return;
- }
- std::stringstream s;
- s << "looking at chunk " << aim_world.GetChunk().Position();
- PostMessage(s.str());
-
- PostMessage(" neighbors:");
- if (aim_world.GetChunk().HasNeighbor(Block::FACE_LEFT)) {
- s.str("");
- s << " left " << aim_world.GetChunk().GetNeighbor(Block::FACE_LEFT).Position();
- PostMessage(s.str());
- }
- if (aim_world.GetChunk().HasNeighbor(Block::FACE_RIGHT)) {
- s.str("");
- s << " right " << aim_world.GetChunk().GetNeighbor(Block::FACE_RIGHT).Position();
- PostMessage(s.str());
- }
- if (aim_world.GetChunk().HasNeighbor(Block::FACE_UP)) {
- s.str("");
- s << " up " << aim_world.GetChunk().GetNeighbor(Block::FACE_UP).Position();
- PostMessage(s.str());
- }
- if (aim_world.GetChunk().HasNeighbor(Block::FACE_DOWN)) {
- s.str("");
- s << " down " << aim_world.GetChunk().GetNeighbor(Block::FACE_DOWN).Position();
- PostMessage(s.str());
- }
- if (aim_world.GetChunk().HasNeighbor(Block::FACE_FRONT)) {
- s.str("");
- s << " front " << aim_world.GetChunk().GetNeighbor(Block::FACE_FRONT).Position();
- PostMessage(s.str());
- }
- if (aim_world.GetChunk().HasNeighbor(Block::FACE_BACK)) {
- s.str("");
- s << " back " << aim_world.GetChunk().GetNeighbor(Block::FACE_BACK).Position();
- PostMessage(s.str());
- }
- std::cout << std::endl;
-}
-
-void Interface::PrintLightInfo() {
- std::stringstream s;
- s
- << "light level " << world.PlayerChunk().GetLight(world.Player().Position())
- << " at position " << world.Player().Position()
- ;
- PostMessage(s.str());
-}
-
-void Interface::PrintSelectionInfo() {
- std::cout << std::endl;
- Print(selection);
-}
-
-void Interface::Print(const Block &block) {
- std::stringstream s;
- s << "type: " << block.type
- << ", face: " << block.GetFace()
- << ", turn: " << block.GetTurn()
- ;
- 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::ToggleDebug() {
- debug = !debug;
- if (debug) {
- UpdateCounter();
- UpdatePosition();
- UpdateOrientation();
- UpdateBlockInfo();
- }
-}
-
-void Interface::UpdateCounter() {
- std::stringstream s;
- s << std::setprecision(3) <<
- "avg: " << env.counter.Average().running << "ms, "
- "peak: " << env.counter.Peak().running << "ms";
- std::string text = s.str();
- counter_text.Set(env.assets.small_ui_font, text);
-}
-
-void Interface::UpdatePosition() {
- std::stringstream s;
- s << std::setprecision(3) << "pos: " << ctrl.Controlled().AbsolutePosition();
- position_text.Set(env.assets.small_ui_font, s.str());
-}