diff --git a/.gitignore b/.gitignore index 4c3db973..6f51ee8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ cmake-build-debug cmake-build-install cmake-build-release +cmake-build-minsizerel +cmake-build-relwithdebinfo .hidden .vscode diff --git a/.hidden b/.hidden deleted file mode 100644 index f0e54612..00000000 --- a/.hidden +++ /dev/null @@ -1,3 +0,0 @@ -cmake-build-debug -cmake-build-install -cmake-build-release diff --git a/.idea/misc.xml b/.idea/misc.xml index 2ce47f5b..7d33cc65 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,17 +7,18 @@ - - + - - - - + + - + + + + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7f..57bf306a 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md index ba9f6a01..5d06c070 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -(c) 2018-2019 Nicole Collings, All rights reserved. +(c) 2018-2021 Auri Collings, All rights reserved. You do not have permission to redistribute, copy, or share this work without my explicit written permission. You may download the repository and compile it for personal use or potential contributions. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aac15769..841339d6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -70,8 +70,8 @@ add_library(Zepha_Core client/gui/compound/GuiInventoryList.h client/gui/compound/GuiLabelledGraph.cpp client/gui/compound/GuiLabelledGraph.cpp - client/gui/DebugGui.cpp - client/gui/DebugGui.h + client/gui/DebugDisplay.cpp + client/gui/DebugDisplay.h client/gui/GameGui.cpp client/gui/GameGui.h client/gui/Element.cpp @@ -146,8 +146,6 @@ add_library(Zepha_Core lua/ErrorFormatter.h lua/LocalLuaParser.cpp lua/LocalLuaParser.h - lua/LocalModHandler.cpp - lua/LocalModHandler.h lua/LuaKeybindHandler.cpp lua/LuaKeybindHandler.h lua/LuaMod.cpp diff --git a/src/client/graph/Renderer.cpp b/src/client/graph/Renderer.cpp index 3bd0b68f..3224ae4f 100644 --- a/src/client/graph/Renderer.cpp +++ b/src/client/graph/Renderer.cpp @@ -51,7 +51,7 @@ Renderer::Renderer(glm::ivec2 win) : })); //VSync 1 = On, 0 = Off - glfwSwapInterval(1); +// glfwSwapInterval(1); } void Renderer::update(double delta) { diff --git a/src/client/gui/BoxElement.cpp b/src/client/gui/BoxElement.cpp index 9d3dbf7f..c0fdd8db 100644 --- a/src/client/gui/BoxElement.cpp +++ b/src/client/gui/BoxElement.cpp @@ -48,10 +48,10 @@ void Gui::BoxElement::updateElement() { entity.setModel(model); } - let margin = getStyle(Prop::MARGIN, {}); + let margin = getStyle(Prop::MARGIN, {}); - entity.setScale(vec3(getComputedSize(), 0)); - entity.setPos(vec3(getComputedScreenPos() + ivec2 { margin.x, margin.y }, 0)); + entity.setScale(ivec3(getComputedSize(), 0)); + entity.setPos(ivec3(getComputedScreenPos() + vec2 { margin.x, margin.y }, 0)); Element::updateElement(); } \ No newline at end of file diff --git a/src/client/gui/DebugDisplay.cpp b/src/client/gui/DebugDisplay.cpp new file mode 100644 index 00000000..c37fb030 --- /dev/null +++ b/src/client/gui/DebugDisplay.cpp @@ -0,0 +1,221 @@ +#include "DebugDisplay.h" + +#include "world/LocalWorld.h" +#include "game/def/BiomeDef.h" +#include "game/def/BlockDef.h" +#include "world/dim/chunk/Chunk.h" +#include "client/gui/BoxElement.h" +#include "client/gui/TextElement.h" +#include "world/player/LocalPlayer.h" +//#include "client/gui/compound/GuiPerfGraph.h" +//#include "client/gui/compound/GuiCellGraph.h" +//#include "client/gui/compound/GuiLabelledGraph.h" + +DebugDisplay::DebugDisplay(sptr root, SubgamePtr game, LocalWorld& world, vec& perfSections) : + root(root), game(game), world(world) { + + using Expr = Gui::Expression; + + crosshair = root->append({{ + { Gui::Prop::TEXT_SIZE, Expr("2px") }, + { Gui::Prop::POS, array { Expr("50cw + 8dp"), Expr("50ch - 3.333dp") } }, + { Gui::Prop::BACKGROUND, vec4 { 0.2, 0.2, 0.2, 0.3 } } + }}); + + data = root->append({{ + { Gui::Prop::TEXT_SIZE, Expr("2px") }, + { Gui::Prop::POS, array { Expr("4dp"), Expr("4dp") } }, + { Gui::Prop::BACKGROUND, vec4 { 0.2, 0.2, 0.2, 0.3 } } + }}); + +// auto interpGraph = make_shared(window, "interpGraph"); +// interpGraph->create({ 244, 64 }, {}, "Interp", 120, 256, genericHistogramRef, f); +// add(interpGraph); +// +// auto meshGraph = make_shared(window, "meshGraph"); +// meshGraph->create({ 244, 64 }, {}, "Mesh", 120, 32, genericHistogramRef, f); +// add(meshGraph); +// +// auto genGraph = make_shared(window, "genGraph"); +// genGraph->create({ 244, 64 }, {}, "Gen", 120, 16, genericHistogramRef, f); +// add(genGraph); +// +// auto packetGraph = make_shared(window, "packetGraph"); +// packetGraph->create({ 244, 64 }, {}, "Packets", 120, 32, genericHistogramRef, f); +// add(packetGraph); +// +// auto fpsGraph = make_shared(window, "fpsGraph"); +// fpsGraph->create({ 244, 64 }, {}, "FPS", 120, 60, fpsHistogramRef, f); +// add(fpsGraph); +// +// auto drawsGraph = make_shared(window, "drawsGraph"); +// drawsGraph->create({ 244, 64 }, {}, "Draw Calls", 120, 0, genericHistogramRef, f); +// add(drawsGraph); +// +// auto gpuGraph = make_shared(window, "gpuGraph"); +// gpuGraph->create({ 244, 64 }, {}, "GPU", 120, 1, genericHistogramRef, f); +// add(gpuGraph); +// +// auto perfGraph = make_shared(window, "perfGraph"); +// perfGraph->create(344, {}, perfSections, "Performance", f); +// add(perfGraph); +// +// auto chunkStates = make_shared(window, "chunkStates"); +// chunkStates->create(12, vec4(4), MAPBLOCK_RANGE, "Mapblocks", f); +// chunkStates->refresh(); +// add(chunkStates); +} + +//void DebugGui::positionElements(u16vec2 buffer) { +// get("crosshairText")->setPos({ buffer.x / 2 + 22, buffer.y / 2 - 7 }); +// get("dataText")->setPos({ 10, 10 }); +// +// get("genGraph")->setPos({ buffer.x - 254, buffer.y - 70 - 160 }); +// get("packetGraph")->setPos({ buffer.x - 254, buffer.y - 70 - 240 }); +// get("meshGraph")->setPos({ buffer.x - 254, buffer.y - 70 - 80 }); +// get("interpGraph")->setPos({ buffer.x - 254, buffer.y - 70 }); +// +// get("fpsGraph")->setPos({ buffer.x - 254, 10 }); +// get("drawsGraph")->setPos({ buffer.x - 254, 90 }); +// get("gpuGraph")->setPos({ buffer.x - 254, 90 + 80 }); +// get("perfGraph")->setPos({ buffer.x - 354 - 254, 10 }); +// +// get("chunkStates")->setPos({ buffer.x - 264 - 144, buffer.y - 178 }); +//} + +void DebugDisplay::update(sptr player, f64 delta, u32 interpolatedChunks, u32 generatedChunks, + u32 recievedPackets, vec& perfTimings, u32 drawnMeshChunks, u32 generatedMeshChunks) { + + Target target = player->getTarget(); + + auto& onBiomeDef = game->getBiomes().biomeFromId( + world.getActiveDimension()->getBiome(glm::floor(player->getPos()))); + +// // FPS and Draw calls graphs +// +// get("perfGraph")->updateTimings(perfTimings); +// get("fpsGraph")->pushValue(1 / delta); +// get("drawsGraph")->pushValue(drawnMeshChunks); +// +// int videoMemAvail, videoMemTotal; +// +// glGetIntegerv(0x9048, &videoMemTotal); +// glGetIntegerv(0x9049, &videoMemAvail); +// +// get("gpuGraph")->pushValue(std::round( +// (videoMemTotal - videoMemAvail) / static_cast(videoMemTotal) * 100.0) / 100.0f); +// +// +// // Thread information graphs +// +// get("meshGraph")->pushValue(generatedMeshChunks); +// get("interpGraph")->pushValue(interpolatedChunks); +// get("genGraph")->pushValue(generatedChunks); +// get("packetGraph")->pushValue(recievedPackets); + + // Textual information + + vec3 playerPos = glm::floor(player->getPos()); + vec3 chunkPos = Space::Chunk::world::fromBlock(playerPos); + vec3 mapBlockPos = Space::MapBlock::world::fromChunk(chunkPos); + vec3 regionPos = Space::Region::world::fromChunk(chunkPos); + + vec3 posOffsetFromChunk = Space::Block::relative::toChunk(playerPos); + vec3 posOffsetFromBlock = Space::Block::relative::toMapBlock(playerPos); + vec3 posOffsetFromRegion = Space::Block::relative::toRegion(playerPos); + + std::ostringstream str; + + str << "Dimension: " << world.getActiveDimension()->getIdentifier() + << " [" << world.getActiveDimension()->getInd() << "]" << std::endl << std::endl + + << "Pos: " << playerPos << " (" << player->getPos() << ")" << std::endl + << "Vel: " << player->getVel() << std::endl + + << "Yaw: " << player->getYaw() << ", " + << "Pitch: " << player->getPitch() << std::endl << std::endl + + << "C: " << posOffsetFromChunk << " [" << chunkPos << "]" << std::endl + << "M: " << posOffsetFromBlock << " [" << mapBlockPos << "]" << std::endl + << "R: " << posOffsetFromRegion << " [" << regionPos << "]" << std::endl + << std::endl + + << "Texture Slots: " << game.l()->textures.textureSlotsUsed << " / " << game.l()->textures.maxTextureSlots + << " (" + << round(game.l()->textures.textureSlotsUsed / static_cast(game.l()->textures.maxTextureSlots) * 100) + << "%)" << std::endl << std::endl + + << "Biome: " << onBiomeDef.identifier << " [" << onBiomeDef.index << "]" << std::endl << std::endl; + + if (target.type == Target::Type::BLOCK) { + string face = + target.data.block.face == EVec::TOP ? "Top" : + target.data.block.face == EVec::BOTTOM ? "Bottom" : + target.data.block.face == EVec::LEFT ? "Left" : + target.data.block.face == EVec::RIGHT ? "Right" : + target.data.block.face == EVec::FRONT ? "Front" : + target.data.block.face == EVec::BACK ? "Back" : + "None (!)"; + + const auto& def = game->getDefs().blockFromId(world.getActiveDimension()->getBlock(target.data.block.pos)); + + str << "Pointing At: " << def.identifier << " [" << def.index << "]" << std::endl + << "Pointed Position: " << target.data.block.pos << std::endl + << "Pointed Face: " << face << std::endl; + } + else if (target.type == Target::Type::ENTITY) { + const auto& entity = **world.getActiveDimension().l()->getEntityById(target.data.entity.id).entity; + + str << "Pointing At: " << (target.data.entity.id < 0 ? "Local" : "Server") + << " Entity #" << std::fabs(target.data.entity.id) << std::endl + << "Pointed Position: " << entity.getPos() << std::endl << std::endl; + } + else { + str << "No Target" << std::endl << std::endl; + } + + data->setProp(Gui::Prop::CONTENT, str.str()); +// // Chunk States +// +// auto chunkStates = get("chunkStates"); +// ivec3 off = { 0, 0, 0 }; +// for (off.x = 0; off.x < MAPBLOCK_RANGE; off.x++) { +// if ((off.x - mapBlockScanX) % MAPBLOCK_SCAN_X_INTERVAL != 0) continue; +// +// for (off.z = 0; off.z < MAPBLOCK_RANGE; off.z++) { +// f32 existAmount = 0; +// ivec3 check = ivec3(mapBlockPos) + off - +// ivec3(MAPBLOCK_RANGE / 2, 0, MAPBLOCK_RANGE / 2); +// +// for (off.y = 0; off.y < MAPBLOCK_VERT; off.y++) { +// check.y = static_cast(mapBlockPos.y) + off.y - MAPBLOCK_VERT / 2; +// const auto mapBlock = world.getActiveDimension()->getMapBlock(check); +// if (mapBlock) existAmount++; +// } +// +// const auto color = +// (off.x == MAPBLOCK_RANGE / 2 && off.z == MAPBLOCK_RANGE / 2) ? MAPBLOCK_CURRENT +// : glm::mix(MAPBLOCK_UNLOADED, MAPBLOCK_LOADED, existAmount / MAPBLOCK_VERT); +// chunkStates->setCellColor(u16vec2(off.x, off.z), color); +// } +// } +// chunkStates->refresh(); +// +// mapBlockScanX = (mapBlockScanX + 1) % MAPBLOCK_SCAN_X_INTERVAL; + + if (target.type == Target::Type::BLOCK) { + const auto& def = game->getDefs().blockFromId(world.getActiveDimension()->getBlock(target.data.block.pos)); + crosshair->setProp(Gui::Prop::CONTENT, "`b" + def.name + " (`r` `c1" + + def.identifier + "`cr - " + std::to_string(def.index) + "` `b)"); + } + else { + crosshair->setProp(Gui::Prop::CONTENT, string("")); + } + + root->updateElement(); +} + +//void DebugDisplay::changeVisibility(Visibility state) { +//// setVisible(state == Visibility::ON); +//// get("fpsGraph")->setVisible(state != Visibility::OFF); +//} diff --git a/src/client/gui/DebugDisplay.h b/src/client/gui/DebugDisplay.h new file mode 100644 index 00000000..ebd373a2 --- /dev/null +++ b/src/client/gui/DebugDisplay.h @@ -0,0 +1,52 @@ +#pragma once + +#include "util/Types.h" +//#include "client/Window.h" +#include "util/CovariantPtr.h" + +class Window; +class LocalWorld; +class LocalPlayer; +class LocalSubgame; +namespace Gui { + class Element; + class BoxElement; + class TextElement; +}; + +/** + * Renders debug information, in the form of graphs and text. + * Can be enabled, disabled, or displayed with FPS only. + */ + +class DebugDisplay { +public: + + enum class Visibility { OFF, FPS_ONLY, ON }; + + DebugDisplay(sptr root, SubgamePtr game, LocalWorld& world, vec& perfSections); + + /** Updates the debug screen with the latest data. */ + void update(sptr player, f64 delta, u32 interpolatedChunks, u32 generatedChunks, + u32 recievedPackets, vec& perfTimings, u32 drawnMeshChunks, u32 generatedMeshChunks); + +private: + + constexpr static vec4 MAPBLOCK_UNLOADED = { 1, 1, 1, 0.15 }; + constexpr static vec4 MAPBLOCK_LOADED = { 1, 1, 1, 0.75 }; + constexpr static vec4 MAPBLOCK_CURRENT = { 1, 0.93, 0.35, 1 }; + + constexpr static i32 MAPBLOCK_VERT = 3; + constexpr static i32 MAPBLOCK_RANGE = 11; + + u32 mapBlockScanX = 0; + constexpr static u32 MAPBLOCK_SCAN_X_INTERVAL = 9; + + SubgamePtr game; + LocalWorld& world; + + sptr root; + sptr crosshair, data; + + Visibility state = Visibility::ON; +}; diff --git a/src/client/gui/DebugGui.cpp b/src/client/gui/DebugGui.cpp deleted file mode 100644 index 93bcc099..00000000 --- a/src/client/gui/DebugGui.cpp +++ /dev/null @@ -1,226 +0,0 @@ -//#include -//#include -//#include "DebugGui.h" -// -//#include "world/LocalWorld.h" -//#include "game/def/BiomeDef.h" -//#include "game/def/BlockDef.h" -//#include "client/graph/Font.h" -//#include "world/dim/chunk/Chunk.h" -//#include "client/gui/basic/GuiText.h" -//#include "world/player/LocalPlayer.h" -//#include "client/gui/compound/GuiLabelledGraph.h" -// -//DebugGui::DebugGui(Window& window, SubgamePtr game, LocalWorld& world, vec& perfSections) : -// game(game), world(world) { -// -// auto fontRef = game.l()->textures["font"]; -// auto fpsHistogramRef = game.l()->textures["histogram"]; -// auto genericHistogramRef = game.l()->textures["histogram_white"]; -// -// Font f(game.l()->textures, fontRef); -// -// auto crosshairText = make_shared(window, "crosshairText"); -// crosshairText->create({ 2, 2 }, {}, { 1, 1, 1, 1 }, { 0.2, 0.2, 0.2, 0.5 }, f); -// add(crosshairText); -// -// auto dataText = make_shared(window, "dataText"); -// dataText->create({ 2, 2 }, {}, { 1, 1, 1, 1 }, { 0.2, 0.2, 0.2, 0.5 }, f); -// add(dataText); -// -// auto interpGraph = make_shared(window, "interpGraph"); -// interpGraph->create({ 244, 64 }, {}, "Interp", 120, 256, genericHistogramRef, f); -// add(interpGraph); -// -// auto meshGraph = make_shared(window, "meshGraph"); -// meshGraph->create({ 244, 64 }, {}, "Mesh", 120, 32, genericHistogramRef, f); -// add(meshGraph); -// -// auto genGraph = make_shared(window, "genGraph"); -// genGraph->create({ 244, 64 }, {}, "Gen", 120, 16, genericHistogramRef, f); -// add(genGraph); -// -// auto packetGraph = make_shared(window, "packetGraph"); -// packetGraph->create({ 244, 64 }, {}, "Packets", 120, 32, genericHistogramRef, f); -// add(packetGraph); -// -// auto fpsGraph = make_shared(window, "fpsGraph"); -// fpsGraph->create({ 244, 64 }, {}, "FPS", 120, 60, fpsHistogramRef, f); -// add(fpsGraph); -// -// auto drawsGraph = make_shared(window, "drawsGraph"); -// drawsGraph->create({ 244, 64 }, {}, "Draw Calls", 120, 0, genericHistogramRef, f); -// add(drawsGraph); -// -// auto gpuGraph = make_shared(window, "gpuGraph"); -// gpuGraph->create({ 244, 64 }, {}, "GPU", 120, 1, genericHistogramRef, f); -// add(gpuGraph); -// -// auto perfGraph = make_shared(window, "perfGraph"); -// perfGraph->create(344, {}, perfSections, "Performance", f); -// add(perfGraph); -// -// auto chunkStates = make_shared(window, "chunkStates"); -// chunkStates->create(12, vec4(4), MAPBLOCK_RANGE, "Mapblocks", f); -// chunkStates->refresh(); -// add(chunkStates); -// -// positionElements(window.getSize()); -//} -// -//void DebugGui::positionElements(u16vec2 buffer) { -// get("crosshairText")->setPos({ buffer.x / 2 + 22, buffer.y / 2 - 7 }); -// get("dataText")->setPos({ 10, 10 }); -// -// get("genGraph")->setPos({ buffer.x - 254, buffer.y - 70 - 160 }); -// get("packetGraph")->setPos({ buffer.x - 254, buffer.y - 70 - 240 }); -// get("meshGraph")->setPos({ buffer.x - 254, buffer.y - 70 - 80 }); -// get("interpGraph")->setPos({ buffer.x - 254, buffer.y - 70 }); -// -// get("fpsGraph")->setPos({ buffer.x - 254, 10 }); -// get("drawsGraph")->setPos({ buffer.x - 254, 90 }); -// get("gpuGraph")->setPos({ buffer.x - 254, 90 + 80 }); -// get("perfGraph")->setPos({ buffer.x - 354 - 254, 10 }); -// -// get("chunkStates")->setPos({ buffer.x - 264 - 144, buffer.y - 178 }); -//} -// -//void DebugGui::update(sptr player, f64 delta, u32 interpolatedChunks, u32 generatedChunks, -// u32 recievedPackets, vec& perfTimings, u32 drawnMeshChunks, u32 generatedMeshChunks) { -// -// Target target = player->getTarget(); -// -// auto& onBiomeDef = game->getBiomes().biomeFromId( -// world.getActiveDimension()->getBiome(glm::floor(player->getPos()))); -// -// // FPS and Draw calls graphs -// -// get("perfGraph")->updateTimings(perfTimings); -// get("fpsGraph")->pushValue(1 / delta); -// get("drawsGraph")->pushValue(drawnMeshChunks); -// -// int videoMemAvail, videoMemTotal; -// -// glGetIntegerv(0x9048, &videoMemTotal); -// glGetIntegerv(0x9049, &videoMemAvail); -// -// get("gpuGraph")->pushValue(std::round( -// (videoMemTotal - videoMemAvail) / static_cast(videoMemTotal) * 100.0) / 100.0f); -// -// -// // Thread information graphs -// -// get("meshGraph")->pushValue(generatedMeshChunks); -// get("interpGraph")->pushValue(interpolatedChunks); -// get("genGraph")->pushValue(generatedChunks); -// get("packetGraph")->pushValue(recievedPackets); -// -// // Textual information -// -// vec3 playerPos = glm::floor(player->getPos()); -// vec3 chunkPos = Space::Chunk::world::fromBlock(playerPos); -// vec3 mapBlockPos = Space::MapBlock::world::fromChunk(chunkPos); -// vec3 regionPos = Space::Region::world::fromChunk(chunkPos); -// -// vec3 posOffsetFromChunk = Space::Block::relative::toChunk(playerPos); -// vec3 posOffsetFromBlock = Space::Block::relative::toMapBlock(playerPos); -// vec3 posOffsetFromRegion = Space::Block::relative::toRegion(playerPos); -// -// std::ostringstream str; -// -// str << "Dimension: " << world.getActiveDimension()->getIdentifier() -// << " [" << world.getActiveDimension()->getInd() << "]" << std::endl << std::endl -// -// << "Pos: " << playerPos << " (" << player->getPos() << ")" << std::endl -// << "Vel: " << player->getVel() << std::endl -// -// << "Yaw: " << player->getYaw() << ", " -// << "Pitch: " << player->getPitch() << std::endl << std::endl -// -// << "C: " << posOffsetFromChunk << " [" << chunkPos << "]" << std::endl -// << "M: " << posOffsetFromBlock << " [" << mapBlockPos << "]" << std::endl -// << "R: " << posOffsetFromRegion << " [" << regionPos << "]" << std::endl -// << std::endl -// -// << "Texture Slots: " << game.l()->textures.textureSlotsUsed << " / " << game.l()->textures.maxTextureSlots -// << " (" -// << round(game.l()->textures.textureSlotsUsed / static_cast(game.l()->textures.maxTextureSlots) * 100) -// << "%)" << std::endl << std::endl -// -// << "Biome: " << onBiomeDef.identifier << " [" << onBiomeDef.index << "]" << std::endl << std::endl; -// -// if (target.type == Target::Type::BLOCK) { -// string face = -// target.data.block.face == EVec::TOP ? "Top" : -// target.data.block.face == EVec::BOTTOM ? "Bottom" : -// target.data.block.face == EVec::LEFT ? "Left" : -// target.data.block.face == EVec::RIGHT ? "Right" : -// target.data.block.face == EVec::FRONT ? "Front" : -// target.data.block.face == EVec::BACK ? "Back" : -// "None (!)"; -// -// const auto& def = game->getDefs().blockFromId(world.getActiveDimension()->getBlock(target.data.block.pos)); -// -// str << "Pointing At: " << def.identifier << " [" << def.index << "]" << std::endl -// << "Pointed Position: " << target.data.block.pos << std::endl -// << "Pointed Face: " << face << std::endl; -// } -// else if (target.type == Target::Type::ENTITY) { -// const auto& entity = **world.getActiveDimension().l()->getEntityById(target.data.entity.id).entity; -// -// str << "Pointing At: " << (target.data.entity.id < 0 ? "Local" : "Server") -// << " Entity #" << std::fabs(target.data.entity.id) << std::endl -// << "Pointed Position: " << entity.getPos() << std::endl << std::endl; -// } -// else { -// str << "No Target" << std::endl << std::endl; -// } -// -// get("dataText")->setText(str.str()); -// -// // Chunk States -// -// auto chunkStates = get("chunkStates"); -// ivec3 off = { 0, 0, 0 }; -// for (off.x = 0; off.x < MAPBLOCK_RANGE; off.x++) { -// if ((off.x - mapBlockScanX) % MAPBLOCK_SCAN_X_INTERVAL != 0) continue; -// -// for (off.z = 0; off.z < MAPBLOCK_RANGE; off.z++) { -// f32 existAmount = 0; -// ivec3 check = ivec3(mapBlockPos) + off - -// ivec3(MAPBLOCK_RANGE / 2, 0, MAPBLOCK_RANGE / 2); -// -// for (off.y = 0; off.y < MAPBLOCK_VERT; off.y++) { -// check.y = static_cast(mapBlockPos.y) + off.y - MAPBLOCK_VERT / 2; -// const auto mapBlock = world.getActiveDimension()->getMapBlock(check); -// if (mapBlock) existAmount++; -// } -// -// const auto color = -// (off.x == MAPBLOCK_RANGE / 2 && off.z == MAPBLOCK_RANGE / 2) ? MAPBLOCK_CURRENT -// : glm::mix(MAPBLOCK_UNLOADED, MAPBLOCK_LOADED, existAmount / MAPBLOCK_VERT); -// chunkStates->setCellColor(u16vec2(off.x, off.z), color); -// } -// } -// chunkStates->refresh(); -// -// mapBlockScanX = (mapBlockScanX + 1) % MAPBLOCK_SCAN_X_INTERVAL; -// -// if (target.type == Target::Type::BLOCK) { -// const auto& def = game->getDefs().blockFromId(world.getActiveDimension()->getBlock(target.data.block.pos)); -// get("crosshairText")->setText("`b" + def.name + " (`r` `c7" + -// def.identifier + "`cr - " + std::to_string(def.index) + "` `b)"); -// } -// else { -// get("crosshairText")->setText(""); -// } -//} -// -//void DebugGui::bufferResized(u16vec2 buffer) { -// positionElements(buffer); -//} -// -//void DebugGui::changeVisibility(Visibility state) { -// setVisible(state == Visibility::ON); -// get("fpsGraph")->setVisible(state != Visibility::OFF); -//} diff --git a/src/client/gui/DebugGui.h b/src/client/gui/DebugGui.h deleted file mode 100644 index 1379d239..00000000 --- a/src/client/gui/DebugGui.h +++ /dev/null @@ -1,55 +0,0 @@ -//#pragma once -// -//#include "client/gui/basic/GuiContainer.h" -// -//#include "util/Types.h" -//#include "util/CovariantPtr.h" -// -//class GuiRect; -//class LocalWorld; -//class LocalPlayer; -//class LocalSubgame; -// -///** -// * Renders debug information, in the form of graphs and text. -// * Can be enabled, disabled, or displayed with FPS only. -// */ -// -//class DebugGui : public GuiContainer { -//public: -// -// enum class Visibility { OFF, FPS_ONLY, ON }; -// -// DebugGui(Window& window, SubgamePtr game, LocalWorld& world, vec& perfSections); -// -// /** Resizes elements when the screen buffer is resized. */ -// void bufferResized(u16vec2 bufferSize); -// -// /** Sets which elements are visible based on the state provided. */ -// void changeVisibility(Visibility state); -// -// /** Positions all elements based on the buffer size. */ -// void positionElements(u16vec2 buffer); -// -// /** Updates the debug screen with the latest data. */ -// void update(sptr player, f64 delta, u32 interpolatedChunks, u32 generatedChunks, -// u32 recievedPackets, vec& perfTimings, u32 drawnMeshChunks, u32 generatedMeshChunks); -// -//private: -// -// constexpr static vec4 MAPBLOCK_UNLOADED = { 1, 1, 1, 0.15 }; -// constexpr static vec4 MAPBLOCK_LOADED = { 1, 1, 1, 0.75 }; -// constexpr static vec4 MAPBLOCK_CURRENT = { 1, 0.93, 0.35, 1 }; -// -// constexpr static i32 MAPBLOCK_VERT = 3; -// constexpr static i32 MAPBLOCK_RANGE = 11; -// -// u32 mapBlockScanX = 0; -// constexpr static u32 MAPBLOCK_SCAN_X_INTERVAL = 9; -// -// Window& window; -// SubgamePtr game; -// LocalWorld& world; -// -// Visibility state = Visibility::ON; -//}; diff --git a/src/client/gui/Element.cpp b/src/client/gui/Element.cpp index 551516bd..dabc082f 100644 --- a/src/client/gui/Element.cpp +++ b/src/client/gui/Element.cpp @@ -59,44 +59,48 @@ void Gui::Element::onClick(const std::function& cb) { Gui::ExpressionInfo Gui::Element::getExpr() const { return { - parent ? parent->getComputedSize() : ivec2 {}, + parent ? parent->getComputedSize() : vec2 {}, getComputedSize() }; } -ivec2 Gui::Element::getComputedSize() const { +vec2 Gui::Element::getComputedSize() const { let size = getStyleWithExpr(Prop::SIZE, vec2(nanf("")), - { parent ? parent->computedSize : ivec2 {}, {} }); - if (std::isnan(size.x)) size.x = std::max(layoutSize.x, 0); - if (std::isnan(size.y)) size.y = std::max(layoutSize.y, 0); - computedSize = ivec2(size); + { parent ? parent->computedSize : vec2 {}, {} }); + if (std::isnan(size.x)) size.x = std::max(layoutSize.x, 0.f); + if (std::isnan(size.y)) size.y = std::max(layoutSize.y, 0.f); + computedSize = size; return size; } -ivec2 Gui::Element::getComputedContentSize() const { +vec2 Gui::Element::getComputedContentSize() const { let size = getComputedSize(); - let padding = getStyle(Prop::PADDING, {}); - return glm::max(ivec2 { size.x - padding.x - padding.z, size.y - padding.y - padding.w }, 0); + let padding = getStyle(Prop::PADDING, {}); + return glm::max(vec2 { size.x - padding.x - padding.z, size.y - padding.y - padding.w }, vec2(0)); } -ivec2 Gui::Element::getExplicitSize() const { - return getStyle(Prop::SIZE, ivec2(-1)); +vec2 Gui::Element::getExplicitSize() const { + return getStyle(Prop::SIZE, vec2(-1)); } -ivec2 Gui::Element::getComputedPos() const { - return getStyle(Prop::POS, layoutPosition); +vec2 Gui::Element::getComputedPos() const { + return getStyle(Prop::POS, layoutPosition); } -ivec2 Gui::Element::getComputedScreenPos() const { +vec2 Gui::Element::getComputedScreenPos() const { return getComputedPos() + parentOffset; } +vec2 Gui::Element::getExplicitPos() const { + return getStyle(Prop::POS, vec2(nanf(""))); +} + bool Gui::Element::handleMouseHover(ivec2 mousePos, bool& pointer) { bool childIntersects = false; for (let& child : children) if (child->handleMouseHover(mousePos, pointer)) childIntersects = true; - ivec2 size = getComputedSize(); - ivec2 pos = getComputedScreenPos(); + vec2 size = getComputedSize(); + vec2 pos = getComputedScreenPos(); bool intersects = mousePos.x >= pos.x && mousePos.x <= pos.x + size.x && mousePos.y >= pos.y && mousePos.y <= pos.y + size.y; @@ -115,8 +119,8 @@ bool Gui::Element::handleMouseClick(ivec2 mousePos, u32 button, bool down) { for (i32 i = children.size() - 1; i >= 0; i--) if (children[i]->handleMouseClick(mousePos, button, down)) return true; - ivec2 size = getComputedSize(); - ivec2 pos = getComputedScreenPos(); + vec2 size = getComputedSize(); + vec2 pos = getComputedScreenPos(); bool intersects = mousePos.x >= pos.x && mousePos.x <= pos.x + size.x && mousePos.y >= pos.y && mousePos.y <= pos.y + size.y; if (!intersects) return false; @@ -166,8 +170,8 @@ void Gui::Element::layoutChildren() { * The element gap across the primary axis. */ - const i32 gap = getStyle(Prop::GAP, ivec2(0))[primary]; - const ivec4& padding = getStyle(Prop::PADDING, ivec4 {}); + const f32 gap = getStyle(Prop::GAP, vec2(0))[primary]; + const vec4& padding = getStyle(Prop::PADDING, {}); /* * Calculates the explicit spaced used up by children across the primary axis, @@ -176,14 +180,15 @@ void Gui::Element::layoutChildren() { */ let selfSize = getComputedContentSize(); - i32 explicitSize = gap * (children.size() - 1); - i32 implicitCount = 0; + f32 explicitSize = gap * (children.size() - 1); + u32 implicitCount = 0; for (const let& child : children) { + if (!std::isnan(child->getExplicitPos()[primary])) continue; let childExplicitSize = child->getExplicitSize(); if (childExplicitSize[primary] != -1) explicitSize += childExplicitSize[primary]; else implicitCount++; - let childMargin = child->getStyle(Prop::MARGIN, {}); + let childMargin = child->getStyle(Prop::MARGIN, {}); explicitSize += childMargin[primary] + childMargin[primary + 2]; } @@ -191,7 +196,7 @@ void Gui::Element::layoutChildren() { * The cumulative layout offset of the children across the x and y axis. */ - ivec2 offset = { padding.x, padding.y }; + vec2 offset = { padding.x, padding.y }; if (align[primary] == 1) offset[primary] += selfSize[primary] - explicitSize - (gap * (children.size() - 1)); else if (align[primary] == 0) offset[primary] += selfSize[primary] / 2 - explicitSize / 2 - (gap * (children.size() - 1)) / 2; @@ -200,17 +205,17 @@ void Gui::Element::layoutChildren() { * The amount of size each implicitly sized element should occupy. */ - i32 implicitElemSize = floor((selfSize[primary] - explicitSize) / (std::max)(implicitCount, 1)); + f32 implicitElemSize = floor((selfSize[primary] - explicitSize) / (std::max)(implicitCount, u32(1))); - ivec2 selfOffset = getComputedPos() + parentOffset; + vec2 selfOffset = getComputedPos() + parentOffset; /** * Position each child according to `offset`, size implicitly sized elements using `implicitElemSize`. */ for (const let& child : children) { - let childExplicitSize = child->getExplicitSize(); - let childMargin = child->getStyle(Prop::MARGIN, {}); + vec2 childExplicitSize = child->getExplicitSize(); + vec4 childMargin = child->getStyle(Prop::MARGIN, {}); child->layoutSize[primary] = (childExplicitSize[primary] == -1 && align[primary] == 2) ? implicitElemSize : 0; @@ -224,13 +229,13 @@ void Gui::Element::layoutChildren() { else if (align[!primary] == 1) child->layoutPosition[!primary] = selfSize[!primary] - childExplicitSize[!primary]; child->layoutPosition[primary] = offset[primary]; - - offset[primary] += ((childExplicitSize[primary] == -1 && align[primary] == 2) - ? implicitElemSize : childExplicitSize[primary]) - + gap + childMargin[primary] + childMargin[primary + 2]; + + if (std::isnan(child->getExplicitPos()[primary])) + offset[primary] += ((childExplicitSize[primary] == -1 && align[primary] == 2) + ? implicitElemSize : childExplicitSize[primary]) + + gap + childMargin[primary] + childMargin[primary + 2]; child->parentOffset = selfOffset; - child->updateElement(); } break; diff --git a/src/client/gui/Element.h b/src/client/gui/Element.h index ef6c7c57..ab6b7a6f 100644 --- a/src/client/gui/Element.h +++ b/src/client/gui/Element.h @@ -94,19 +94,22 @@ namespace Gui { void onClick(const std::function& cb); /** Returns the element's computed size. */ - virtual ivec2 getComputedSize() const; + virtual vec2 getComputedSize() const; /** Returns the element's computed content size, which is its size - padding. */ - virtual ivec2 getComputedContentSize() const; + virtual vec2 getComputedContentSize() const; /** Returns the element's explicit size. Unspecified dimensions are -1. */ - virtual ivec2 getExplicitSize() const; + virtual vec2 getExplicitSize() const; /** Returns the element's computed position relative to its parent. */ - virtual ivec2 getComputedPos() const; + virtual vec2 getComputedPos() const; /** Returns the element's computed position relative to the screen. */ - virtual ivec2 getComputedScreenPos() const; + virtual vec2 getComputedScreenPos() const; + + /** Returns the element's explicit position. Unspecified dimensions are nan. */ + virtual vec2 getExplicitPos() const; /** Gets a style value from the element's styles or the root's stylesheets. */ const optional getStyle(Prop rule) const { @@ -232,16 +235,16 @@ namespace Gui { std::function clickCb = nullptr; /** The screen offset of the parent. */ - ivec2 parentOffset {}; + vec2 parentOffset {}; /** The last computed size of the element. */ - mutable ivec2 computedSize {}; + mutable vec2 computedSize {}; /** The element's implicit size, as defined by the parent layout. */ - ivec2 layoutSize { -1, -1 }; + vec2 layoutSize { -1, -1 }; /** The element's implicit position, as defined by the parent layout. */ - ivec2 layoutPosition {}; + vec2 layoutPosition {}; /** Updates child sizes and offsets based on layout styles. */ virtual void layoutChildren(); diff --git a/src/client/gui/Expression.cpp b/src/client/gui/Expression.cpp index 9355e373..7dfb4ffb 100644 --- a/src/client/gui/Expression.cpp +++ b/src/client/gui/Expression.cpp @@ -105,9 +105,7 @@ void Gui::Expression::setExpression(string exp) { } f32 Gui::Expression::eval(const ExpressionInfo& info) { - if (!expression.size()) { - return nanf(""); - } + if (!expression.size()) return nanf(""); std::stack eval {}; diff --git a/src/client/gui/TextElement.cpp b/src/client/gui/TextElement.cpp index 6a32aa32..8ce1cd00 100644 --- a/src/client/gui/TextElement.cpp +++ b/src/client/gui/TextElement.cpp @@ -191,10 +191,10 @@ void Gui::TextElement::updateElement() { } let scale = getStyle(Prop::TEXT_SIZE, 3.f); - let margin = getStyle(Prop::MARGIN, {}); + let margin = getStyle(Prop::MARGIN, {}); - entity.setScale(vec3(scale, scale, 0)); - entity.setPos(vec3(getComputedScreenPos() + ivec2 { margin.x, margin.y }, 0)); + entity.setScale(ivec3(scale, scale, 0)); + entity.setPos(ivec3(getComputedScreenPos() + vec2 { margin.x, margin.y }, 0)); Element::updateElement(); } diff --git a/src/lua/LocalLuaParser.cpp b/src/lua/LocalLuaParser.cpp index 217b0e83..d2692e0b 100644 --- a/src/lua/LocalLuaParser.cpp +++ b/src/lua/LocalLuaParser.cpp @@ -33,7 +33,7 @@ // Util #include "lua/register/CreateRegister.h" -LocalLuaParser::LocalLuaParser(LocalSubgame& game) : LuaParser(game), keybinds(this) {} +LocalLuaParser::LocalLuaParser(LocalSubgame& game) : LuaParser(game) {} void LocalLuaParser::init(WorldPtr world, PlayerPtr player, Client& client) { this->client = &client; @@ -139,13 +139,13 @@ void LocalLuaParser::loadApi(WorldPtr world, PlayerPtr player) { Api::Util::createRegister(lua, core, "mesh"); Api::Util::createRegister(lua, core, "item", - [&](const auto& iden) { RegisterItem::client(core, game, iden); }); + [&](const string& iden) { RegisterItem::client(core, game, iden); }); Api::Util::createRegister(lua, core, "block", - [&](const auto& iden) { RegisterBlock::client(core, game, iden); }); + [&](const string& iden) { RegisterBlock::client(core, game, iden); }); Api::Util::createRegister(lua, core, "biome", - [&](const auto& iden) { RegisterBiome::client(core, game, iden); }); + [&](const string& iden) { RegisterBiome::client(core, game, iden); }); Api::Util::createRegister(lua, core, "keybind", - [&](const auto& iden) { RegisterKeybind::client(core, keybinds, iden); }); + [&](const string& iden) { RegisterKeybind::client(core, client->renderer.window.input, refs, iden); }); Api::Util::createRegister(lua, core, "blockmodel"); Api::Util::createRegister(lua, core, "entity", nullptr, "entities"); diff --git a/src/lua/LocalLuaParser.h b/src/lua/LocalLuaParser.h index dac4c07c..8dbd2e56 100644 --- a/src/lua/LocalLuaParser.h +++ b/src/lua/LocalLuaParser.h @@ -9,6 +9,7 @@ #include "lua/LuaParser.h" #include "LuaMod.h" +#include "client/Callback.h" #include "util/CovariantPtr.h" #include "lua/LuaKeybindHandler.h" @@ -35,9 +36,9 @@ private: sol::protected_function_result runFileSandboxed(const std::string& file); Client* client; - LuaKeybindHandler keybinds; double accumulatedDelta = 0; - std::unordered_map mods {}; + vec refs; vec modLoadOrder {}; + std::unordered_map mods {}; }; diff --git a/src/lua/LocalModHandler.cpp b/src/lua/LocalModHandler.cpp deleted file mode 100644 index ca315c73..00000000 --- a/src/lua/LocalModHandler.cpp +++ /dev/null @@ -1,37 +0,0 @@ -//// -//// Created by aurailus on 2020-02-19. -//// -// -//#include "lua/Lua.h" -// -//#include "LocalModHandler.h" -// -//void LocalModHandler::addLuaMod(const LuaMod& mod) { -// mods.emplace_back(mod); -//} -// -//void LocalModHandler::setModsOrder(const std::vector& order) { -// modsOrder = order; -//} -// -//void LocalModHandler::executeMods(std::function run) { -// try { -// for (std::string& modName : modsOrder) { -// if (modName == "base") { -// run(modName + "/init"); -// break; -// } -// } -// -// for (std::string& modName : modsOrder) { -// if (modName != "base") run(modName + "/init"); -// } -// } -// catch (sol::error e) { -// std::cout << "CAUGHT B " << e.what() << std::endl; -// } -//} -// -//const std::vector& LocalModHandler::cGetMods() const { -// return mods; -//} \ No newline at end of file diff --git a/src/lua/LocalModHandler.h b/src/lua/LocalModHandler.h deleted file mode 100644 index 8a36b4c9..00000000 --- a/src/lua/LocalModHandler.h +++ /dev/null @@ -1,24 +0,0 @@ -//// -//// Created by aurailus on 2020-02-19. -//// -// -//#pragma once -// -//#include -// -//#include "LuaMod.h" -// -//class LocalModHandler { -// public: -// void addLuaMod(const LuaMod& mod); -// -// void setModsOrder(const std::vector& order); -// -// void executeMods(std::function run); -// -// const std::vector& cGetMods() const; -// -// private: -// std::vector mods; -// std::vector modsOrder; -//}; diff --git a/src/lua/register/RegisterKeybind.h b/src/lua/register/RegisterKeybind.h index 9610bf78..a1b25dbb 100644 --- a/src/lua/register/RegisterKeybind.h +++ b/src/lua/register/RegisterKeybind.h @@ -16,15 +16,17 @@ namespace RegisterKeybind { * @param handler - The keybind handler to add the keybind to. */ - static void registerKeybind(sol::table keybinds, const std::string& identifier, LuaKeybindHandler& handler) { + static void registerKeybind(Input& input, vec& refs, sol::table keybinds, const string& identifier) { sol::table keybindTbl = keybinds[identifier]; - unsigned short def = keybindTbl.get("default"); + u32 def = keybindTbl.get("default"); auto onPress = keybindTbl.get>("on_press"); auto onRelease = keybindTbl.get>("on_release"); - if (onPress) handler.bindOnDown(def, *onPress); - if (onRelease) handler.bindOnUp(def, *onRelease); + if (onPress) refs.emplace_back(input.events.bind(Input::CBType::KEY_PRESS, [=](u32 key, i32) { + if (key == def) (*onPress)(); })); + if (onRelease) refs.emplace_back(input.events.bind(Input::CBType::KEY_RELEASE, [=](u32 key, i32) { + if (key == def) (*onRelease)(); })); } } @@ -35,11 +37,11 @@ namespace RegisterKeybind { * Registers a keybind to the keybind handler. * * @param core - The core table to index for 'registered_keybinds', i.e. `_G['zepha']`. - * @param game - The keybind handler to add the keybind to. + * @param game - The input manager to add the keybind to. * @param identifier - The identifier of the keybind to add. */ - static void client(sol::table& core, LuaKeybindHandler& handler, const std::string& identifier) { - registerKeybind(core.get("registered_keybinds"), identifier, handler); + static void client(sol::table& core, Input& input, vec& refs, const string& identifier) { + registerKeybind(input, refs, core.get("registered_keybinds"), identifier); } }; \ No newline at end of file diff --git a/src/lua/usertype/GuiElement.cpp b/src/lua/usertype/GuiElement.cpp index 8a810a6f..bdef0ed1 100644 --- a/src/lua/usertype/GuiElement.cpp +++ b/src/lua/usertype/GuiElement.cpp @@ -164,8 +164,8 @@ void Api::Usertype::GuiElement::bind(sol::state& lua, sol::table& core, Gui::Roo }), "prepend", [&](sol::this_state s, Gui::Element& self, sol::object child) { if (child.is>()) self.prepend(child.as>()); - else if (child.is()) { - sol::protected_function fn = child.as(); + else if (child.is()) { + sol::protected_function fn = child.as(); sol::table tbl = sol::state_view(s)["zepha"]["__builtin"]["gui_env"]; sol::environment env(s, sol::create, tbl); sol::set_environment(env, fn); @@ -176,8 +176,8 @@ void Api::Usertype::GuiElement::bind(sol::state& lua, sol::table& core, Gui::Roo }, "append", [&](sol::this_state s, Gui::Element& self, sol::object child) { if (child.is>()) self.append(child.as>()); - else if (child.is()) { - let fn = child.as(); + else if (child.is()) { + let fn = child.as(); sol::table tbl = sol::state_view(s)["zepha"]["__builtin"]["gui_env"]; sol::environment env(s, sol::create, tbl); sol::set_environment(env, fn); diff --git a/src/world/LocalWorld.cpp b/src/world/LocalWorld.cpp index 7f62925c..a017f7ea 100644 --- a/src/world/LocalWorld.cpp +++ b/src/world/LocalWorld.cpp @@ -13,7 +13,7 @@ LocalWorld::LocalWorld(SubgamePtr game, ServerConnection& conn, Renderer& render renderer(renderer), net(conn, *this), refs(make_shared(game, net)), -// debugGui(renderer.window.getSize(), game, *this, perfSections), + debug(player.l()->getDebug(), game, *this, perfSections), // worldGenStream(make_shared(*game.l(), *this, 55)), player(make_shared(game, *this, DimensionPtr(nullptr), renderer)) { @@ -49,12 +49,12 @@ void LocalWorld::update(f64 delta, vec& perfTimings, PerfTimer& perf) { // Update debug interface perf.start("update:debug"); -// debugGui.update( -// player.l(), delta, -// lastInterpolations, net.serverSideChunkGens, net.recvPackets, -// perfTimings, -// activeDimension->getMeshChunksDrawn(), -// activeDimension->getMeshChunksCommitted()); + debug.update( + player.l(), delta, + lastInterpolations, net.serverSideChunkGens, net.recvPackets, + perfTimings, + activeDimension->getMeshChunksDrawn(), + activeDimension->getMeshChunksCommitted()); perf.resume("other"); // Toggle regular interface diff --git a/src/world/LocalWorld.h b/src/world/LocalWorld.h index 12dc9c13..64976d01 100644 --- a/src/world/LocalWorld.h +++ b/src/world/LocalWorld.h @@ -3,7 +3,7 @@ #include "World.h" #include "client/Window.h" -#include "client/gui/DebugGui.h" +#include "client/gui/DebugDisplay.h" #include "world/dim/LocalDimension.h" #include "client/conn/ClientNetworkInterpreter.h" @@ -90,7 +90,7 @@ private: PlayerPtr player; /** The debug interface. */ -// DebugGui debugGui; + DebugDisplay debug; /** The number of chunks that were interpolated last frome. */ u32 lastInterpolations = 0; diff --git a/src/world/player/LocalPlayer.cpp b/src/world/player/LocalPlayer.cpp index fcd069d5..f91943a5 100644 --- a/src/world/player/LocalPlayer.cpp +++ b/src/world/player/LocalPlayer.cpp @@ -17,19 +17,19 @@ LocalPlayer::LocalPlayer(SubgamePtr game, LocalWorld& world, DimensionPtr dim, Renderer& renderer) : Player(game, world, dim), DrawableEntity(game, dim), Entity(game, dim), root(renderer.window, game.l()->textures), + hud(root.body->append({{ { Gui::Prop::CLASS, vec { "_GUI_ROOT" } } }})), + menu(root.body->append({{ { Gui::Prop::CLASS, vec { "_GUI_ROOT" } } }})), + debug(root.body->append({{ { Gui::Prop::CLASS, vec { "_GUI_ROOT" } } }})), wireframe(game, dim, { 1, 1, 1 }), renderer(renderer) { handItemModel.parent = &handModel; - hud = root.body->append({{ - { Gui::Prop::POS, array { Gui::Expression("0"), Gui::Expression("0") }}, - { Gui::Prop::SIZE, array { Gui::Expression("100cw"), Gui::Expression("100ch") }} - }}); - - menu = root.body->append({{ - { Gui::Prop::POS, array { Gui::Expression("0"), Gui::Expression("0") }}, - { Gui::Prop::SIZE, array { Gui::Expression("100cw"), Gui::Expression("100ch") }} - }}); + root.addStylesheet({ + { "_GUI_ROOT", {{ + { Gui::Prop::POS, array { Gui::Expression("0"), Gui::Expression("0") }}, + { Gui::Prop::SIZE, array { Gui::Expression("100cw"), Gui::Expression("100ch") }} + }}} + }); } void LocalPlayer::update(f64 delta, vec2 mouseDelta) { @@ -100,7 +100,7 @@ InventoryPtr LocalPlayer::getInventory() { } bool LocalPlayer::isInMenu() { -// return gameGui.isInMenu(); + return menu->get(0) != nullptr; } void LocalPlayer::showMenu(sptr newMenu) { @@ -118,6 +118,10 @@ Gui::Root& LocalPlayer::getRoot() { return root; } +sptr LocalPlayer::getDebug() { + return debug; +} + sptr LocalPlayer::getHud() { return hud->get(0); } @@ -138,6 +142,7 @@ void LocalPlayer::draw(Renderer&) { void LocalPlayer::drawHud(Renderer&) { hud->draw(renderer); + debug->draw(renderer); } void LocalPlayer::drawMenu(Renderer&) { diff --git a/src/world/player/LocalPlayer.h b/src/world/player/LocalPlayer.h index 7884e2c8..6f34b9ce 100644 --- a/src/world/player/LocalPlayer.h +++ b/src/world/player/LocalPlayer.h @@ -65,6 +65,9 @@ public: /** Returns the Gui root. */ Gui::Root& getRoot(); + /** Gets the debug element. */ + sptr getDebug(); + /** Gets the hud element. */ sptr getHud(); @@ -116,7 +119,7 @@ private: Gui::Root root; /** Element roots for the hud and menu, respectively. */ - sptr hud, menu; + sptr hud, menu, debug; /** A reference to the renderer. */ Renderer& renderer; diff --git a/subgames/zeus/mods/auri_health/script/init.lua b/subgames/zeus/mods/auri_health/script/init.lua index 5ccca303..70c46b00 100644 --- a/subgames/zeus/mods/auri_health/script/init.lua +++ b/subgames/zeus/mods/auri_health/script/init.lua @@ -1,6 +1,6 @@ --- _G['health'] = {} --- health.internal = {} --- --- require(_PATH .. 'api') --- require(_PATH .. 'interface') --- require(_PATH .. 'hooks') \ No newline at end of file +_G['health'] = {} +health.internal = {} + +require(_PATH .. 'api') +require(_PATH .. 'interface') +require(_PATH .. 'hooks') \ No newline at end of file diff --git a/subgames/zeus/mods/auri_health/script/interface.lua b/subgames/zeus/mods/auri_health/script/interface.lua index 6a33089a..e1d9a100 100644 --- a/subgames/zeus/mods/auri_health/script/interface.lua +++ b/subgames/zeus/mods/auri_health/script/interface.lua @@ -2,11 +2,7 @@ if not zepha.client then return end local hud = zepha.player:get_hud() -health.internal._wrapper = zepha.gui(function() - return Gui.Box { - id = 'health_wrapper' - } -end) +health.internal._wrapper = zepha.Gui.Box { id = 'health_wrapper' } function health.internal.update() local hp = health.my_health @@ -16,14 +12,14 @@ function health.internal.update() health.internal._wrapper:append(function() local elem = Gui.Box { id = '@health:component', - size = { health.internal._width, 9 }, + size = { health.internal._width .. 'dp', '9dp' } } -- Background for i = 1, hp.max do elem:append(Gui.Box { - size = { 9, 9 }, - position = { 8 * (i - 1), 0 }, + size = '9dp', + pos = { 8 * (i - 1) .. 'dp', 0 }, background = 'crop(0, 0, 9, 9, @auri:health:hearts)' }) end @@ -36,15 +32,15 @@ function health.internal.update() if i > red_start and i <= red_end then local segment = start ~= 0 and 9 or 18 elem:append(Gui.Box { - size = { 9, 9 }, - position = { 8 * math.floor((i - 1) / 2), 0 }, + size = '9dp', + pos = { 8 * math.floor((i - 1) / 2) .. 'dp', 0 }, background = 'crop(9, ' .. segment .. ', 9, 9, @auri:health:hearts)' }) elseif i > blue_start and i <= blue_end then local segment = start ~= 0 and 9 or 18 elem:append(Gui.Box { - size = { 9, 9 }, - position = { 8 * math.floor((i - 1) / 2), 0 }, + size = '9dp', + pos = { 8 * math.floor((i - 1) / 2) .. 'dp', 0 }, background = 'crop(18, ' .. segment .. ', 9, 9, @auri:health:hearts)' }) end @@ -57,16 +53,14 @@ end function health.render_default(render) hud:remove('@health:default') if render then - hud:append(function() - return Gui.Rect { - id = '@health:default', + hud:append(zepha.Gui.Box { + id = '@health:default', - size = { health.internal._width, 9 }, - position = { '50cw - 50sw', '100cw - 30px' }, + pos = { '50cw - 50sw', '100ch - 18dp' }, + size = { health.internal._width .. "dp", 9 }, - health.internal._wrapper - } - end) + health.internal._wrapper + }) end end diff --git a/subgames/zeus/mods/auri_hot_wheel/script/init.lua b/subgames/zeus/mods/auri_hot_wheel/script/init.lua index 45e37110..5303a58d 100644 --- a/subgames/zeus/mods/auri_hot_wheel/script/init.lua +++ b/subgames/zeus/mods/auri_hot_wheel/script/init.lua @@ -1,10 +1,10 @@ --- _G["hot_wheel"] = {} --- --- if zepha.server then --- require(_PATH .. "register") --- end --- --- if zepha.client then --- require(_PATH .. "interface") --- require(_PATH .. "keys") --- end +_G["hot_wheel"] = {} + +if zepha.server then + require(_PATH .. "register") +end + +if zepha.client then + require(_PATH .. "interface") + require(_PATH .. "keys") +end diff --git a/subgames/zeus/mods/auri_hot_wheel/script/interface.lua b/subgames/zeus/mods/auri_hot_wheel/script/interface.lua index 636a9219..2b724e5c 100644 --- a/subgames/zeus/mods/auri_hot_wheel/script/interface.lua +++ b/subgames/zeus/mods/auri_hot_wheel/script/interface.lua @@ -8,134 +8,136 @@ if health then end hud:append(function() - local root = Gui.Rect { - key = "hot_wheel_root", + local root = Gui.Box { + id = 'hot_wheel_root', - size = { 140, 80 }, - position = { "0%", "100%" }, - position_anchor = { "-10%", "110%" }, + size = { '140dp', '80dp' }, + pos = { '0', '100ch - 100sh' }, - Gui.Rect { - size = { 94, 18 }, - position = { 52, 19 }, - background = "@auri:hot_wheel:hot_wheel_line", + Gui.Box { + pos = { '52dp', '19dp' }, + size = { '94dp', '18dp' }, + background = '@auri:hot_wheel:hot_wheel_line', - Gui.Rect { - key = "expanded_indicator", - size = { 18, 18 }, - position = { 2, 0 }, - background = "@auri:hot_wheel:hot_wheel_selection" + Gui.Box { + id = 'expanded_indicator', + + size = '18dp', + pos = { '2dp', 0 }, + background = '@auri:hot_wheel:hot_wheel_selection' }, - Gui.InventoryList { - key = "list_expanded", - position = { 3, 1 }, - slot_spacing = { 2, 2 }, - length = 6, - source = "current_player", - list = "hot_wheel_1", +-- Gui.InventoryList { +-- key = 'list_expanded', +-- pos = { 3, 1 }, +-- gap = { 2, 2 }, +-- +-- length = 6, +-- list = 'hot_wheel_1', +-- source = 'current_player', +-- } + }, + + Gui.Box { + size = '80dp', + background = '@auri:hot_wheel:hot_wheel_circle', + +-- Gui.InventoryList { +-- key = 'list_1', +-- slot_spacing = { 2, 2 }, +-- length = 1, +-- source = 'current_player', +-- list = 'hot_wheel_1', +-- }, +-- Gui.InventoryList { +-- key = 'list_2', +-- slot_spacing = { 2, 2 }, +-- length = 1, +-- source = 'current_player', +-- list = 'hot_wheel_2', +-- }, +-- Gui.InventoryList { +-- key = 'list_3', +-- slot_spacing = { 2, 2 }, +-- length = 1, +-- source = 'current_player', +-- list = 'hot_wheel_3', +-- }, +-- Gui.InventoryList { +-- key = 'list_4', +-- slot_spacing = { 2, 2 }, +-- length = 1, +-- source = 'current_player', +-- list = 'hot_wheel_4', +-- }, +-- Gui.InventoryList { +-- key = 'list_5', +-- slot_spacing = { 2, 2 }, +-- length = 1, +-- source = 'current_player', +-- list = 'hot_wheel_5', +-- }, +-- Gui.InventoryList { +-- key = 'list_6', +-- slot_spacing = { 2, 2 }, +-- length = 1, +-- source = 'current_player', +-- list = 'hot_wheel_6', +-- }, + + Gui.Text { + id = 'label_1', + content = '1' + }, + Gui.Text { + id = 'label_2', + content = '2' + }, + Gui.Text { + id = 'label_3', + content = '3' + }, + Gui.Text { + id = 'label_4', + content = '4' + }, + Gui.Text { + id = 'label_5', + content = '5' + }, + Gui.Text { + id = 'label_6', + content = '6' } }, - Gui.Rect { - size = { 80, 80 }, - background = "@auri:hot_wheel:hot_wheel_circle", + Gui.Box { + pos = { '75dp', '40dp' }, - Gui.InventoryList { - key = "list_1", - slot_spacing = { 2, 2 }, - length = 1, - source = "current_player", - list = "hot_wheel_1", - }, - Gui.InventoryList { - key = "list_2", - slot_spacing = { 2, 2 }, - length = 1, - source = "current_player", - list = "hot_wheel_2", - }, - Gui.InventoryList { - key = "list_3", - slot_spacing = { 2, 2 }, - length = 1, - source = "current_player", - list = "hot_wheel_3", - }, - Gui.InventoryList { - key = "list_4", - slot_spacing = { 2, 2 }, - length = 1, - source = "current_player", - list = "hot_wheel_4", - }, - Gui.InventoryList { - key = "list_5", - slot_spacing = { 2, 2 }, - length = 1, - source = "current_player", - list = "hot_wheel_5", - }, - Gui.InventoryList { - key = "list_6", - slot_spacing = { 2, 2 }, - length = 1, - source = "current_player", - list = "hot_wheel_6", - }, - - Gui.Text { - key = "label_1", - content = "1" - }, - Gui.Text { - key = "label_2", - content = "2" - }, - Gui.Text { - key = "label_3", - content = "3" - }, - Gui.Text { - key = "label_4", - content = "4" - }, - Gui.Text { - key = "label_5", - content = "5" - }, - Gui.Text { - key = "label_6", - content = "6" - } - }, - - Gui.Rect { - position = { 75, 40 }, health_elem } } api.labels = { - root:get("label_1"), - root:get("label_2"), - root:get("label_3"), - root:get("label_4"), - root:get("label_5"), - root:get("label_6") + root:get('label_1'), + root:get('label_2'), + root:get('label_3'), + root:get('label_4'), + root:get('label_5'), + root:get('label_6') } api.lists = { - root:get("list_1"), - root:get("list_2"), - root:get("list_3"), - root:get("list_4"), - root:get("list_5"), - root:get("list_6") + root:get('list_1'), + root:get('list_2'), + root:get('list_3'), + root:get('list_4'), + root:get('list_5'), + root:get('list_6') } - api.list_expanded = root:get("list_expanded") - api.list_expanded_indicator = root:get("expanded_indicator") + api.list_expanded = root:get('list_expanded') + api.list_expanded_indicator = root:get('expanded_indicator') return root end) \ No newline at end of file diff --git a/subgames/zeus/mods/auri_hot_wheel/script/keys.lua b/subgames/zeus/mods/auri_hot_wheel/script/keys.lua index dcb2deec..ccfc44dd 100644 --- a/subgames/zeus/mods/auri_hot_wheel/script/keys.lua +++ b/subgames/zeus/mods/auri_hot_wheel/script/keys.lua @@ -16,9 +16,17 @@ local function position() currentRotation = currentRotation + (desiredRotation - currentRotation) / 2 for i, list in ipairs(api.lists) do - list.position = { 32.5 + 22 * math.sin(currentRotation - (r * (i + 3))), 32.5 + 22 * math.cos(currentRotation - (r * (i + 3))) } end + list.pos = { + 32.5 + 22 * math.sin(currentRotation - (r * (i + 3))) .. 'dp', + 32.5 + 22 * math.cos(currentRotation - (r * (i + 3))) .. 'dp' + } + end for i, label in ipairs(api.labels) do - label.position = { 37 + 35 * math.sin(currentRotation - (r * (i + 3))), 36 + 35 * math.cos(currentRotation - (r * (i + 3))) } end + label.pos = { + 37 + 35 * math.sin(currentRotation - (r * (i + 3))) .. 'dp', + 36 + 35 * math.cos(currentRotation - (r * (i + 3))) .. 'dp' + } + end if currentRotation == desiredRotation then rotating = false @@ -35,19 +43,19 @@ local function select_slot(n) local offset = n - 1 desiredRotation = offset * r - api.list_expanded.list = "hot_wheel_" .. n +-- api.list_expanded.list = 'hot_wheel_' .. n - for i, list in ipairs(api.lists) do list.visible = i ~= n end - for i, label in ipairs(api.labels) do label.visible = i ~= n end +-- for i, list in ipairs(api.lists) do list.visible = i ~= n end +-- for i, label in ipairs(api.labels) do label.visible = i ~= n end - zepha.player:set_wield_list("hot_wheel_" .. slot); + zepha.player:set_wield_list('hot_wheel_' .. slot); if not rotating then position() end end local function select_item(n) item = ((item + n) - 1) % 5 + 1 local offset = slot - 1 - api.list_expanded_indicator.position = { 2 + 18 * (item - 1), 0 } + api.list_expanded_indicator.pos = { 2 + 18 * (item - 1) .. 'dp', 0 } zepha.player:set_wield_index(item) end diff --git a/subgames/zeus/mods/zeus_inventory/script/menu.lua b/subgames/zeus/mods/zeus_inventory/script/menu.lua index f45bdfe5..a7ad918f 100644 --- a/subgames/zeus/mods/zeus_inventory/script/menu.lua +++ b/subgames/zeus/mods/zeus_inventory/script/menu.lua @@ -5,15 +5,15 @@ local menu = zepha.gui(function() Gui.Box { id = "inventory", - size = { 342, 187 }, + size = { "342dp", "187dp" }, pos = { "50cw - 50sw", "50ch - 50sh" }, Gui.Box { id = "backpack", pos = { 1, 0 }, - size = { 106, 187 }, - padding = { 19, 9, 8, 9 }, + size = { "106dp", "187dp" }, + padding = { "19dp", "9dp", "8dp", "9dp" }, background = "zeus:inventory:backpack" @@ -70,8 +70,8 @@ local menu = zepha.gui(function() Gui.Box { id = "player_frame", - pos = { 105, 0 }, - size = { 106, 187 }, + pos = { "105dp", 0 }, + size = { "106dp", "187dp" }, background = "zeus:inventory:player_frame", @@ -88,25 +88,26 @@ local menu = zepha.gui(function() Gui.Box { id = "equipment", - pos = { 209, 1 }, - size = { 132, 80 }, - padding = { 18, 8, 8, 8 }, + pos = { "209dp", "1dp" }, + size = { "132dp", "80dp" }, + padding = { "18dp", "8dp", "8dp", "8dp" }, background = "zeus:inventory:equipment", Gui.Box { id = "player_clamp", - pos = { 41, 1 }, - size = { 34, 52 }, + pos = { "41dp", "1dp" }, + size = { "34dp", "52dp" }, overflow = "hidden" } }, Gui.Box { id = "dynamic", - pos = { 209, 80 }, - size = { 132, 107 }, - padding = { 8, 8, 8, 8 }, + pos = { "209dp", "80dp" }, + size = { "132dp", "107dp" }, + padding = "8dp", + background = "zeus:inventory:dynamic" -- Gui.InventoryList {