This commit is contained in:
MihailRis
2024-12-24 11:31:54 +03:00
parent e153e1fbd7
commit b4abecc764
8 changed files with 29 additions and 12 deletions
+9 -5
View File
@@ -324,7 +324,7 @@ void Hud::update(bool visible) {
const auto& chunks = *player.chunks; const auto& chunks = *player.chunks;
const auto& menu = gui.getMenu(); const auto& menu = gui.getMenu();
debugPanel->setVisible(player.debug && visible); debugPanel->setVisible(debug && visible);
if (!visible && inventoryOpen) { if (!visible && inventoryOpen) {
closeInventory(); closeInventory();
@@ -359,7 +359,7 @@ void Hud::update(bool visible) {
if (visible) { if (visible) {
for (auto& element : elements) { for (auto& element : elements) {
element.update(pause, inventoryOpen, player.debug); element.update(pause, inventoryOpen, debug);
if (element.isRemoved()) { if (element.isRemoved()) {
onRemove(element); onRemove(element);
} }
@@ -367,8 +367,8 @@ void Hud::update(bool visible) {
} }
cleanup(); cleanup();
debugMinimap->setVisible(player.debug && showGeneratorMinimap); debugMinimap->setVisible(debug && showGeneratorMinimap);
if (player.debug && showGeneratorMinimap) { if (debug && showGeneratorMinimap) {
updateWorldGenDebugVisualization(); updateWorldGenDebugVisualization();
} }
} }
@@ -585,6 +585,10 @@ void Hud::remove(const std::shared_ptr<UINode>& node) {
cleanup(); cleanup();
} }
void Hud::setDebug(bool flag) {
debug = flag;
}
void Hud::draw(const DrawContext& ctx){ void Hud::draw(const DrawContext& ctx){
const Viewport& viewport = ctx.getViewport(); const Viewport& viewport = ctx.getViewport();
const uint width = viewport.getWidth(); const uint width = viewport.getWidth();
@@ -602,7 +606,7 @@ void Hud::draw(const DrawContext& ctx){
uishader.uniformMatrix("u_projview", uicamera->getProjView()); uishader.uniformMatrix("u_projview", uicamera->getProjView());
// Crosshair // Crosshair
if (!pause && !inventoryOpen && !player.debug) { if (!pause && !inventoryOpen && !debug) {
DrawContext chctx = ctx.sub(batch); DrawContext chctx = ctx.sub(batch);
chctx.setBlendMode(BlendMode::inversion); chctx.setBlendMode(BlendMode::inversion);
auto texture = assets.get<Texture>("gui/crosshair"); auto texture = assets.get<Texture>("gui/crosshair");
+3
View File
@@ -113,6 +113,7 @@ class Hud : public util::ObjectsKeeper {
bool showContentPanel = true; bool showContentPanel = true;
/// @brief Provide cheat controllers to the debug panel /// @brief Provide cheat controllers to the debug panel
bool allowDebugCheats = true; bool allowDebugCheats = true;
bool debug = false;
/// @brief UI element will be dynamicly positioned near to inventory or in screen center /// @brief UI element will be dynamicly positioned near to inventory or in screen center
std::shared_ptr<gui::UINode> secondUI; std::shared_ptr<gui::UINode> secondUI;
@@ -193,6 +194,8 @@ public:
void onRemove(const HudElement& element); void onRemove(const HudElement& element);
void remove(const std::shared_ptr<gui::UINode>& node); void remove(const std::shared_ptr<gui::UINode>& node);
void setDebug(bool flag);
Player* getPlayer() const; Player* getPlayer() const;
std::shared_ptr<Inventory> getBlockInventory(); std::shared_ptr<Inventory> getBlockInventory();
+3 -1
View File
@@ -157,7 +157,9 @@ void LevelScreen::updateHotkeys() {
hudVisible = !hudVisible; hudVisible = !hudVisible;
} }
if (Events::jpressed(keycode::F3)) { if (Events::jpressed(keycode::F3)) {
player->debug = !player->debug; debug = !debug;
hud->setDebug(debug);
worldRenderer->setDebug(debug);
} }
} }
+1
View File
@@ -29,6 +29,7 @@ class LevelScreen : public Screen {
void saveWorldPreview(); void saveWorldPreview();
bool hudVisible = true; bool hudVisible = true;
bool debug = false;
void updateHotkeys(); void updateHotkeys();
void initializeContent(); void initializeContent();
void initializePack(ContentPackRuntime* pack); void initializePack(ContentPackRuntime* pack);
+7 -3
View File
@@ -211,7 +211,7 @@ void WorldRenderer::renderBlockSelection() {
lineBatch->box( lineBatch->box(
center, size + glm::vec3(0.01), glm::vec4(0.f, 0.f, 0.f, 0.5f) center, size + glm::vec3(0.01), glm::vec4(0.f, 0.f, 0.f, 0.5f)
); );
if (player.debug) { if (debug) {
lineBatch->line( lineBatch->line(
point, point + norm * 0.5f, glm::vec4(1.0f, 0.0f, 1.0f, 1.0f) point, point + norm * 0.5f, glm::vec4(1.0f, 0.0f, 1.0f, 1.0f)
); );
@@ -228,7 +228,7 @@ void WorldRenderer::renderLines(
if (player.selection.vox.id != BLOCK_VOID) { if (player.selection.vox.id != BLOCK_VOID) {
renderBlockSelection(); renderBlockSelection();
} }
if (player.debug && showEntitiesDebug) { if (debug && showEntitiesDebug) {
auto ctx = pctx.sub(lineBatch.get()); auto ctx = pctx.sub(lineBatch.get());
bool culling = engine.getSettings().graphics.frustumCulling.get(); bool culling = engine.getSettings().graphics.frustumCulling.get();
level.entities->renderDebug( level.entities->renderDebug(
@@ -337,7 +337,7 @@ void WorldRenderer::draw(
renderLevel(ctx, camera, settings, delta, pause, hudVisible); renderLevel(ctx, camera, settings, delta, pause, hudVisible);
// Debug lines // Debug lines
if (hudVisible) { if (hudVisible) {
if (player.debug) { if (debug) {
guides->renderDebugLines( guides->renderDebugLines(
ctx, camera, *lineBatch, linesShader, showChunkBorders ctx, camera, *lineBatch, linesShader, showChunkBorders
); );
@@ -410,3 +410,7 @@ void WorldRenderer::renderBlockOverlay(const DrawContext& wctx) {
void WorldRenderer::clear() { void WorldRenderer::clear() {
chunks->clear(); chunks->clear();
} }
void WorldRenderer::setDebug(bool flag) {
debug = flag;
}
+3
View File
@@ -45,6 +45,7 @@ class WorldRenderer {
std::unique_ptr<ModelBatch> modelBatch; std::unique_ptr<ModelBatch> modelBatch;
float timer = 0.0f; float timer = 0.0f;
bool debug = false;
/// @brief Render block selection lines /// @brief Render block selection lines
void renderBlockSelection(); void renderBlockSelection();
@@ -100,4 +101,6 @@ public:
); );
void clear(); void clear();
void setDebug(bool flag);
}; };
+1
View File
@@ -39,6 +39,7 @@ void ChunksController::update(
int centerY = floordiv<CHUNK_D>(position.z); int centerY = floordiv<CHUNK_D>(position.z);
if (player.isLoadingChunks()) { if (player.isLoadingChunks()) {
/// FIXME: one generator for multiple players
generator->update(centerX, centerY, loadDistance); generator->update(centerX, centerY, loadDistance);
} }
+2 -3
View File
@@ -55,10 +55,9 @@ class Player : public Serializable {
entityid_t eid; entityid_t eid;
entityid_t selectedEid = 0; entityid_t selectedEid = 0;
public: public:
std::unique_ptr<Chunks> chunks; // not in use yet std::unique_ptr<Chunks> chunks;
std::shared_ptr<Camera> fpCamera, spCamera, tpCamera; std::shared_ptr<Camera> fpCamera, spCamera, tpCamera;
std::shared_ptr<Camera> currentCamera; std::shared_ptr<Camera> currentCamera;;
bool debug = false;
glm::vec3 cam {}; glm::vec3 cam {};
CursorSelection selection {}; CursorSelection selection {};