Skip to content

Commit f8fd432

Browse files
lhofhanslest31
authored andcommittedNov 4, 2016
Add debug priv, and allow player to display the scene as wire-frame. (#4709)
1 parent bf315c0 commit f8fd432

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed
 

Diff for: ‎builtin/game/privileges.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,7 @@ core.register_privilege("zoom", {
5858
description = "Can zoom the camera",
5959
give_to_singleplayer = false,
6060
})
61-
61+
core.register_privilege("debug", {
62+
description = "Allows enabling various debug options that may affect gameplay",
63+
give_to_singleplayer = false,
64+
})

Diff for: ‎src/clientmap.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
521521
buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, m_cache_trilinear_filter);
522522
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, m_cache_bilinear_filter);
523523
buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, m_cache_anistropic_filter);
524+
buf->getMaterial().setFlag(video::EMF_WIREFRAME, m_control.show_wireframe);
524525

525526
const video::SMaterial& material = buf->getMaterial();
526527
video::IMaterialRenderer* rnd =

Diff for: ‎src/clientmap.h

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct MapDrawControl
3232
range_all(false),
3333
wanted_range(0),
3434
wanted_max_blocks(0),
35+
show_wireframe(false),
3536
blocks_drawn(0),
3637
blocks_would_have_drawn(0),
3738
farthest_drawn(0)
@@ -43,6 +44,8 @@ struct MapDrawControl
4344
float wanted_range;
4445
// Maximum number of blocks to draw
4546
u32 wanted_max_blocks;
47+
// show a wire frame for debugging
48+
bool show_wireframe;
4649
// Number of blocks rendered is written here by the renderer
4750
u32 blocks_drawn;
4851
// Number of blocks that would have been drawn in wanted_range

Diff for: ‎src/game.cpp

+21-9
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ class Game {
15731573
bool shift_pressed);
15741574
void toggleFog(float *statustext_time, bool *flag);
15751575
void toggleDebug(float *statustext_time, bool *show_debug,
1576-
bool *show_profiler_graph);
1576+
bool *show_profiler_graph, bool *show_wireframe);
15771577
void toggleUpdateCamera(float *statustext_time, bool *flag);
15781578
void toggleProfiler(float *statustext_time, u32 *profiler_current_page,
15791579
u32 profiler_max_page);
@@ -2812,7 +2812,8 @@ void Game::processKeyInput(VolatileRunFlags *flags,
28122812
} else if (wasKeyDown(KeyType::TOGGLE_UPDATE_CAMERA)) {
28132813
toggleUpdateCamera(statustext_time, &flags->disable_camera_update);
28142814
} else if (wasKeyDown(KeyType::TOGGLE_DEBUG)) {
2815-
toggleDebug(statustext_time, &flags->show_debug, &flags->show_profiler_graph);
2815+
toggleDebug(statustext_time, &flags->show_debug, &flags->show_profiler_graph,
2816+
&draw_control->show_wireframe);
28162817
} else if (wasKeyDown(KeyType::TOGGLE_PROFILER)) {
28172818
toggleProfiler(statustext_time, profiler_current_page, profiler_max_page);
28182819
} else if (wasKeyDown(KeyType::INCREASE_VIEWING_RANGE)) {
@@ -3119,22 +3120,33 @@ void Game::toggleFog(float *statustext_time, bool *flag)
31193120

31203121

31213122
void Game::toggleDebug(float *statustext_time, bool *show_debug,
3122-
bool *show_profiler_graph)
3123+
bool *show_profiler_graph, bool *show_wireframe)
31233124
{
3124-
// Initial / 3x toggle: Chat only
3125+
// Initial / 4x toggle: Chat only
31253126
// 1x toggle: Debug text with chat
31263127
// 2x toggle: Debug text with profiler graph
3128+
// 3x toggle: Debug text and wireframe
31273129
if (!*show_debug) {
31283130
*show_debug = true;
31293131
*show_profiler_graph = false;
3132+
*show_wireframe = false;
31303133
statustext = L"Debug info shown";
3131-
} else if (*show_profiler_graph) {
3132-
*show_debug = false;
3133-
*show_profiler_graph = false;
3134-
statustext = L"Debug info and profiler graph hidden";
3135-
} else {
3134+
} else if (!*show_profiler_graph) {
31363135
*show_profiler_graph = true;
31373136
statustext = L"Profiler graph shown";
3137+
} else if (!*show_wireframe && client->checkPrivilege("debug")) {
3138+
*show_profiler_graph = false;
3139+
*show_wireframe = true;
3140+
statustext = L"Wireframe shown";
3141+
} else {
3142+
*show_debug = false;
3143+
*show_profiler_graph = false;
3144+
*show_wireframe = false;
3145+
if (client->checkPrivilege("debug")) {
3146+
statustext = L"Debug info, profiler graph, and wireframe hidden";
3147+
} else {
3148+
statustext = L"Debug info and profiler graph hidden";
3149+
}
31383150
}
31393151
*statustext_time = 0;
31403152
}

0 commit comments

Comments
 (0)