Optimize debug info & Dimension updates.

master
Auri 2021-08-15 18:30:38 -07:00
parent a077065aec
commit 46a6a148de
12 changed files with 78 additions and 73 deletions

View File

@ -6,6 +6,10 @@
<file path="$PROJECT_DIR$/src" />
<file path="$PROJECT_DIR$/test" />
</sourceRoots>
<libraryRoots>
<file path="$PROJECT_DIR$/cmake-build-debug" />
<file path="$PROJECT_DIR$/cmake-build-release" />
</libraryRoots>
<excludeRoots>
<file path="$PROJECT_DIR$/.github" />
<file path="$PROJECT_DIR$/.idea" />

View File

@ -61,7 +61,7 @@ DebugGui::DebugGui(u16vec2 buffer, SubgamePtr game, LocalWorld& world, vec<strin
add(perfGraph);
auto chunkStates = make_shared<GuiCellGraph>("chunkStates");
chunkStates->create(6, vec4(4), CHUNK_RANGE, "Chunk Compression", f);
chunkStates->create(12, vec4(4), MAPBLOCK_RANGE, "Mapblocks", f);
chunkStates->refresh();
add(chunkStates);
@ -82,7 +82,7 @@ void DebugGui::positionElements(u16vec2 buffer) {
get<GuiLabelledGraph>("gpuGraph")->setPos({ buffer.x - 254, 90 + 80 });
get<GuiLabelledGraph>("perfGraph")->setPos({ buffer.x - 354 - 254, 10 });
get<GuiLabelledGraph>("chunkStates")->setPos({ buffer.x - 264 - 300, buffer.y - 334 });
get<GuiLabelledGraph>("chunkStates")->setPos({ buffer.x - 264 - 144, buffer.y - 178 });
}
void DebugGui::update(sptr<LocalPlayer> player, f64 delta, u32 interpolatedChunks, u32 generatedChunks,
@ -176,51 +176,40 @@ void DebugGui::update(sptr<LocalPlayer> player, f64 delta, u32 interpolatedChunk
str << "No Target" << std::endl << std::endl;
}
// for (usize i = 0; i < perfTimings.size(); i++) {
// str << perfSections[i] << ": " << perfTimings[i] << " ns." << std::endl;
// }
get<GuiText>("dataText")->setText(str.str());
// Chunk States
if (chunkTimer == 0) {
auto chunkStates = get<GuiCellGraph>("chunkStates");
ivec3 off = { 0, 0, 0 };
for (off.x = 0; off.x < CHUNK_RANGE; off.x++) {
for (off.z = 0; off.z < CHUNK_RANGE; off.z++) {
f32 existAmount = 0;
f32 compressedAmount = 0;
ivec3 check = ivec3(chunkPos) + off -
glm::ivec3(floor(CHUNK_RANGE / 2), 0, floor(CHUNK_RANGE / 2));
auto chunkStates = get<GuiCellGraph>("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 < CHUNK_VERT; off.y++) {
check.y = static_cast<i32>(chunkPos.y) + off.y - CHUNK_VERT / 2;
const auto chunk = world.getActiveDimension()->getChunk(check);
if (chunk) {
existAmount++;
if (chunk->isCompressed()) compressedAmount++;
}
}
const auto color = glm::mix(CHUNK_UNLOADED,
glm::mix(CHUNK_UNCOMPRESSED, CHUNK_COMPRESSED,
compressedAmount / CHUNK_VERT),existAmount / CHUNK_VERT);
chunkStates->setCellColor(u16vec2(off.x, off.z), color);
for (off.y = 0; off.y < MAPBLOCK_VERT; off.y++) {
check.y = static_cast<i32>(chunkPos.y) + off.y - MAPBLOCK_VERT / 2;
const auto mapBlock = world.getActiveDimension()->getMapBlock(check);
if (mapBlock) existAmount++;
}
}
chunkStates->refresh();
}
chunkTimer = (chunkTimer + 1) % CHUNK_INTERVAL;
// Crosshair information
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<GuiText>("crosshairText")->setText(
"`b" + def.name + " (`r` `c7" + def.identifier + "`cr - " + std::to_string(def.index) + "` `b)");
get<GuiText>("crosshairText")->setText("`b" + def.name + " (`r` `c7" +
def.identifier + "`cr - " + std::to_string(def.index) + "` `b)");
}
else {
get<GuiText>("crosshairText")->setText("");

View File

@ -37,18 +37,18 @@ public:
private:
constexpr static vec4 CHUNK_UNLOADED = { 1, 1, 1, 0.15 };
constexpr static vec4 CHUNK_COMPRESSED = { 1, 1, 1, 0.75 };
constexpr static vec4 CHUNK_UNCOMPRESSED = { 1, 0, 0, 0.75 };
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 CHUNK_VERT = 3;
constexpr static i32 CHUNK_RANGE = 48;
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;
u16 chunkTimer = 0;
constexpr static u16 CHUNK_INTERVAL = 5;
Visibility state = Visibility::ON;
};

View File

@ -84,14 +84,15 @@ void GuiMeter::updateMesh() {
}
const vec<vec3> GuiMeter::COLORS = {
{ 63 / 255.f, 224 / 255.f, 208 / 255.f },
{ 51 / 255.f, 187 / 255.f, 232 / 255.f },
{ 94 / 255.f, 105 / 255.f, 219 / 255.f },
{ 159 / 255.f, 94 / 255.f, 255 / 255.f },
{ 255 / 255.f, 138 / 255.f, 243 / 255.f },
{ 255 / 255.f, 102 / 255.f, 102 / 255.f },
{ 255 / 255.f, 157 / 255.f, 77 / 255.f },
{ 169 / 255.f, 212 / 255.f, 89 / 255.f },
{ 42 / 255.f, 212 / 255.f, 119 / 255.f },
{ 0.3, 0.3, 0.3 }
vec3 { 63, 224, 208 } / 255.f,
vec3 { 51, 187, 232 } / 255.f,
vec3 { 94, 105, 219 } / 255.f,
vec3 { 159, 94, 255 } / 255.f,
vec3 { 255, 138, 243 } / 255.f,
vec3 { 255, 102, 102 } / 255.f,
// vec3 { 255, 157, 77 } / 255.f,
// vec3 { 169, 212, 89 } / 255.f,
// vec3 { 42, 212, 119 } / 255.f,
vec3 { 200, 200, 200 } / 255.f,
vec3 { 120, 120, 120 } / 255.f
};

View File

@ -24,7 +24,7 @@ void GuiPerfGraph::create(f32 scale, vec4 padding, const vec<string>& sections,
background->setPos({ 0, 0 });
auto meter = make_shared<GuiMeter>("meter");
meter->create({ scale - GRAPH_PAD_X * 2, 24 }, {}, 0.85);
meter->create({ scale - GRAPH_PAD_X * 2, 24 }, {}, 0.95);
add(meter);
meter->setBudget(1 / 60.f * 1000000000);
meter->setPos({ GRAPH_PAD_X, GRAPH_PAD_Y });

View File

@ -25,7 +25,7 @@ void GameScene::update() {
Window& window = client.renderer.window;
auto perfTimings = perf.end();
perf.start("update:mods");
perf.start("other");
client.game->update(client.getDelta());
world.l()->update(client.getDelta(), perfTimings, perf);

View File

@ -18,8 +18,8 @@ public:
void draw() override;
private:
vec<string> perfSections = { "update:mods", "update:world", "update:player", "update:net", "update:chunks",
"draw:world", "draw:entities", "draw:interface", "update:debug", "idle" };
vec<string> perfSections = { "update:world", "update:player", "update:debug",
"draw:world", "draw:entities", "draw:interface", "other", "idle" };
PerfTimer perf { perfSections };
WorldPtr world;

View File

@ -8,6 +8,15 @@ void PerfTimer::start(const string& section) {
stopCurrent();
const usize ind = find(sections.begin(), sections.end(), section) - sections.begin();
if (ind == sections.size()) throw std::invalid_argument("Tried to start invalid section '" + section + "'");
timings[ind] = 0;
timer = Timer();
currentSection = section;
}
void PerfTimer::resume(const string& section) {
stopCurrent();
const usize ind = find(sections.begin(), sections.end(), section) - sections.begin();
if (ind == sections.size()) throw std::invalid_argument("Tried to resume invalid section '" + section + "'");
timer = Timer();
currentSection = section;
}
@ -22,7 +31,7 @@ vec<usize> PerfTimer::end() {
void PerfTimer::stopCurrent() {
if (currentSection != "") {
const usize ind = find(sections.begin(), sections.end(), currentSection) - sections.begin();
timings[ind] = timer.elapsedNs();
timings[ind] += timer.elapsedNs();
currentSection = "";
}
}

View File

@ -7,6 +7,8 @@ public:
PerfTimer(const vec<string>& sections);
void start(const string& section);
void resume(const string& section);
vec<usize> end();
private:
void stopCurrent();

View File

@ -16,7 +16,7 @@ LocalWorld::LocalWorld(SubgamePtr game, ServerConnection& conn, Renderer& render
// worldGenStream(make_shared<WorldInterpolationStream>(*game.l(), *this, 55)),
player(make_shared<LocalPlayer>(game, *this, DimensionPtr(nullptr), renderer)) {
renderer.window.onResize(Util::bind_this(&debugGui, &DebugGui::bufferResized));
lock = renderer.window.onResize(Util::bind_this(&debugGui, &DebugGui::bufferResized));
}
void LocalWorld::init() {
@ -43,15 +43,9 @@ void LocalWorld::update(f64 delta, vec<usize>& perfTimings, PerfTimer& perf) {
refs->update(delta, net);
// Update the network
perf.start("update:net");
perf.resume("other");
net.update();
// Commit interpolated mapblocks
perf.start("update:chunks");
// auto finishedChunks = worldGenStream->update();
// lastInterpolations = finishedChunks->size() / 64;
// for (const auto& chunk : *finishedChunks) commitChunk(chunk);
// Update debug interface
perf.start("update:debug");
debugGui.update(
@ -60,20 +54,21 @@ void LocalWorld::update(f64 delta, vec<usize>& perfTimings, PerfTimer& perf) {
perfTimings,
activeDimension->getMeshChunksDrawn(),
activeDimension->getMeshChunksCommitted());
perf.resume("other");
// Toggle regular interface
if (renderer.window.input.keyPressed(GLFW_KEY_F1)) {
hudVisible = !hudVisible;
debugGui.changeVisibility(hudVisible ? debugVisible ? DebugGui::Visibility::OFF :
DebugGui::Visibility::FPS_ONLY : DebugGui::Visibility::ON);
player.l()->setHudVisible(hudVisible);
debugGui.changeVisibility(hudVisible ? debugVisible ? DebugGui::Visibility::ON :
DebugGui::Visibility::FPS_ONLY : DebugGui::Visibility::OFF);
}
// Toggle debug interface
if (renderer.window.input.keyPressed(GLFW_KEY_F3)) {
debugVisible = !debugVisible;
debugGui.changeVisibility(hudVisible ? debugVisible ? DebugGui::Visibility::OFF :
DebugGui::Visibility::FPS_ONLY : DebugGui::Visibility::ON);
debugGui.changeVisibility(hudVisible ? debugVisible ? DebugGui::Visibility::ON :
DebugGui::Visibility::FPS_ONLY : DebugGui::Visibility::OFF);
}
}

View File

@ -52,7 +52,7 @@ void LocalDimension::update(f64 delta) {
for (let it = regions.cbegin(); it != regions.cend();) {
for (u16 m = 0; m < 64; m++) {
let mapBlock = it->second->get(m);
if (!mapBlock) continue;
if (!mapBlock || (mapBlock->pos.y - mapBlockScanY) % MAPBLOCK_SCAN_Y_INTERVAL != 0) continue;
if (abs(clientMapBlock.x - mapBlock->pos.x) > retainMapBlockRange.x ||
abs(clientMapBlock.y - mapBlock->pos.y) > retainMapBlockRange.y ||
@ -80,6 +80,8 @@ void LocalDimension::update(f64 delta) {
erase_region_and_continue:
it = regions.erase(it);
}
mapBlockScanY = (mapBlockScanY + 1) % MAPBLOCK_SCAN_Y_INTERVAL;
}
void LocalDimension::setChunk(sptr<Chunk> chunk) {

View File

@ -98,6 +98,9 @@ private:
std::unordered_map<vec3, chunk_ref, Vec::vec3> renderRefs{};
std::list<sptr<ChunkRenderElem>> renderElems{};
u32 mapBlockScanY = 0;
const static u32 MAPBLOCK_SCAN_Y_INTERVAL = 8;
const ivec2 retainMapBlockRange = { 4, 4 };
i64 entityInd = -1;
};