Optimize debug info & Dimension updates.
parent
a077065aec
commit
46a6a148de
|
@ -6,6 +6,10 @@
|
||||||
<file path="$PROJECT_DIR$/src" />
|
<file path="$PROJECT_DIR$/src" />
|
||||||
<file path="$PROJECT_DIR$/test" />
|
<file path="$PROJECT_DIR$/test" />
|
||||||
</sourceRoots>
|
</sourceRoots>
|
||||||
|
<libraryRoots>
|
||||||
|
<file path="$PROJECT_DIR$/cmake-build-debug" />
|
||||||
|
<file path="$PROJECT_DIR$/cmake-build-release" />
|
||||||
|
</libraryRoots>
|
||||||
<excludeRoots>
|
<excludeRoots>
|
||||||
<file path="$PROJECT_DIR$/.github" />
|
<file path="$PROJECT_DIR$/.github" />
|
||||||
<file path="$PROJECT_DIR$/.idea" />
|
<file path="$PROJECT_DIR$/.idea" />
|
||||||
|
|
|
@ -61,7 +61,7 @@ DebugGui::DebugGui(u16vec2 buffer, SubgamePtr game, LocalWorld& world, vec<strin
|
||||||
add(perfGraph);
|
add(perfGraph);
|
||||||
|
|
||||||
auto chunkStates = make_shared<GuiCellGraph>("chunkStates");
|
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();
|
chunkStates->refresh();
|
||||||
add(chunkStates);
|
add(chunkStates);
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ void DebugGui::positionElements(u16vec2 buffer) {
|
||||||
get<GuiLabelledGraph>("gpuGraph")->setPos({ buffer.x - 254, 90 + 80 });
|
get<GuiLabelledGraph>("gpuGraph")->setPos({ buffer.x - 254, 90 + 80 });
|
||||||
get<GuiLabelledGraph>("perfGraph")->setPos({ buffer.x - 354 - 254, 10 });
|
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,
|
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;
|
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());
|
get<GuiText>("dataText")->setText(str.str());
|
||||||
|
|
||||||
// Chunk States
|
// Chunk States
|
||||||
|
|
||||||
if (chunkTimer == 0) {
|
auto chunkStates = get<GuiCellGraph>("chunkStates");
|
||||||
auto chunkStates = get<GuiCellGraph>("chunkStates");
|
ivec3 off = { 0, 0, 0 };
|
||||||
ivec3 off = { 0, 0, 0 };
|
for (off.x = 0; off.x < MAPBLOCK_RANGE; off.x++) {
|
||||||
for (off.x = 0; off.x < CHUNK_RANGE; off.x++) {
|
if ((off.x - mapBlockScanX) % MAPBLOCK_SCAN_X_INTERVAL != 0) continue;
|
||||||
for (off.z = 0; off.z < CHUNK_RANGE; off.z++) {
|
|
||||||
f32 existAmount = 0;
|
for (off.z = 0; off.z < MAPBLOCK_RANGE; off.z++) {
|
||||||
f32 compressedAmount = 0;
|
f32 existAmount = 0;
|
||||||
ivec3 check = ivec3(chunkPos) + off -
|
ivec3 check = ivec3(mapBlockPos) + off -
|
||||||
glm::ivec3(floor(CHUNK_RANGE / 2), 0, floor(CHUNK_RANGE / 2));
|
ivec3(MAPBLOCK_RANGE / 2, 0, MAPBLOCK_RANGE / 2);
|
||||||
|
|
||||||
for (off.y = 0; off.y < CHUNK_VERT; off.y++) {
|
for (off.y = 0; off.y < MAPBLOCK_VERT; off.y++) {
|
||||||
check.y = static_cast<i32>(chunkPos.y) + off.y - CHUNK_VERT / 2;
|
check.y = static_cast<i32>(chunkPos.y) + off.y - MAPBLOCK_VERT / 2;
|
||||||
const auto chunk = world.getActiveDimension()->getChunk(check);
|
const auto mapBlock = world.getActiveDimension()->getMapBlock(check);
|
||||||
if (chunk) {
|
if (mapBlock) existAmount++;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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) {
|
if (target.type == Target::Type::BLOCK) {
|
||||||
const auto& def = game->getDefs().blockFromId(world.getActiveDimension()->getBlock(target.data.block.pos));
|
const auto& def = game->getDefs().blockFromId(world.getActiveDimension()->getBlock(target.data.block.pos));
|
||||||
get<GuiText>("crosshairText")->setText(
|
get<GuiText>("crosshairText")->setText("`b" + def.name + " (`r` `c7" +
|
||||||
"`b" + def.name + " (`r` `c7" + def.identifier + "`cr - " + std::to_string(def.index) + "` `b)");
|
def.identifier + "`cr - " + std::to_string(def.index) + "` `b)");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
get<GuiText>("crosshairText")->setText("");
|
get<GuiText>("crosshairText")->setText("");
|
||||||
|
|
|
@ -37,18 +37,18 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
constexpr static vec4 CHUNK_UNLOADED = { 1, 1, 1, 0.15 };
|
constexpr static vec4 MAPBLOCK_UNLOADED = { 1, 1, 1, 0.15 };
|
||||||
constexpr static vec4 CHUNK_COMPRESSED = { 1, 1, 1, 0.75 };
|
constexpr static vec4 MAPBLOCK_LOADED = { 1, 1, 1, 0.75 };
|
||||||
constexpr static vec4 CHUNK_UNCOMPRESSED = { 1, 0, 0, 0.75 };
|
constexpr static vec4 MAPBLOCK_CURRENT = { 1, 0.93, 0.35, 1 };
|
||||||
|
|
||||||
constexpr static i32 CHUNK_VERT = 3;
|
constexpr static i32 MAPBLOCK_VERT = 3;
|
||||||
constexpr static i32 CHUNK_RANGE = 48;
|
constexpr static i32 MAPBLOCK_RANGE = 11;
|
||||||
|
|
||||||
|
u32 mapBlockScanX = 0;
|
||||||
|
constexpr static u32 MAPBLOCK_SCAN_X_INTERVAL = 9;
|
||||||
|
|
||||||
SubgamePtr game;
|
SubgamePtr game;
|
||||||
LocalWorld& world;
|
LocalWorld& world;
|
||||||
|
|
||||||
u16 chunkTimer = 0;
|
|
||||||
constexpr static u16 CHUNK_INTERVAL = 5;
|
|
||||||
|
|
||||||
Visibility state = Visibility::ON;
|
Visibility state = Visibility::ON;
|
||||||
};
|
};
|
||||||
|
|
|
@ -84,14 +84,15 @@ void GuiMeter::updateMesh() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const vec<vec3> GuiMeter::COLORS = {
|
const vec<vec3> GuiMeter::COLORS = {
|
||||||
{ 63 / 255.f, 224 / 255.f, 208 / 255.f },
|
vec3 { 63, 224, 208 } / 255.f,
|
||||||
{ 51 / 255.f, 187 / 255.f, 232 / 255.f },
|
vec3 { 51, 187, 232 } / 255.f,
|
||||||
{ 94 / 255.f, 105 / 255.f, 219 / 255.f },
|
vec3 { 94, 105, 219 } / 255.f,
|
||||||
{ 159 / 255.f, 94 / 255.f, 255 / 255.f },
|
vec3 { 159, 94, 255 } / 255.f,
|
||||||
{ 255 / 255.f, 138 / 255.f, 243 / 255.f },
|
vec3 { 255, 138, 243 } / 255.f,
|
||||||
{ 255 / 255.f, 102 / 255.f, 102 / 255.f },
|
vec3 { 255, 102, 102 } / 255.f,
|
||||||
{ 255 / 255.f, 157 / 255.f, 77 / 255.f },
|
// vec3 { 255, 157, 77 } / 255.f,
|
||||||
{ 169 / 255.f, 212 / 255.f, 89 / 255.f },
|
// vec3 { 169, 212, 89 } / 255.f,
|
||||||
{ 42 / 255.f, 212 / 255.f, 119 / 255.f },
|
// vec3 { 42, 212, 119 } / 255.f,
|
||||||
{ 0.3, 0.3, 0.3 }
|
vec3 { 200, 200, 200 } / 255.f,
|
||||||
|
vec3 { 120, 120, 120 } / 255.f
|
||||||
};
|
};
|
|
@ -24,7 +24,7 @@ void GuiPerfGraph::create(f32 scale, vec4 padding, const vec<string>& sections,
|
||||||
background->setPos({ 0, 0 });
|
background->setPos({ 0, 0 });
|
||||||
|
|
||||||
auto meter = make_shared<GuiMeter>("meter");
|
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);
|
add(meter);
|
||||||
meter->setBudget(1 / 60.f * 1000000000);
|
meter->setBudget(1 / 60.f * 1000000000);
|
||||||
meter->setPos({ GRAPH_PAD_X, GRAPH_PAD_Y });
|
meter->setPos({ GRAPH_PAD_X, GRAPH_PAD_Y });
|
||||||
|
|
|
@ -25,7 +25,7 @@ void GameScene::update() {
|
||||||
Window& window = client.renderer.window;
|
Window& window = client.renderer.window;
|
||||||
auto perfTimings = perf.end();
|
auto perfTimings = perf.end();
|
||||||
|
|
||||||
perf.start("update:mods");
|
perf.start("other");
|
||||||
client.game->update(client.getDelta());
|
client.game->update(client.getDelta());
|
||||||
|
|
||||||
world.l()->update(client.getDelta(), perfTimings, perf);
|
world.l()->update(client.getDelta(), perfTimings, perf);
|
||||||
|
|
|
@ -18,8 +18,8 @@ public:
|
||||||
void draw() override;
|
void draw() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vec<string> perfSections = { "update:mods", "update:world", "update:player", "update:net", "update:chunks",
|
vec<string> perfSections = { "update:world", "update:player", "update:debug",
|
||||||
"draw:world", "draw:entities", "draw:interface", "update:debug", "idle" };
|
"draw:world", "draw:entities", "draw:interface", "other", "idle" };
|
||||||
PerfTimer perf { perfSections };
|
PerfTimer perf { perfSections };
|
||||||
|
|
||||||
WorldPtr world;
|
WorldPtr world;
|
||||||
|
|
|
@ -8,6 +8,15 @@ void PerfTimer::start(const string& section) {
|
||||||
stopCurrent();
|
stopCurrent();
|
||||||
const usize ind = find(sections.begin(), sections.end(), section) - sections.begin();
|
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 + "'");
|
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();
|
timer = Timer();
|
||||||
currentSection = section;
|
currentSection = section;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +31,7 @@ vec<usize> PerfTimer::end() {
|
||||||
void PerfTimer::stopCurrent() {
|
void PerfTimer::stopCurrent() {
|
||||||
if (currentSection != "") {
|
if (currentSection != "") {
|
||||||
const usize ind = find(sections.begin(), sections.end(), currentSection) - sections.begin();
|
const usize ind = find(sections.begin(), sections.end(), currentSection) - sections.begin();
|
||||||
timings[ind] = timer.elapsedNs();
|
timings[ind] += timer.elapsedNs();
|
||||||
currentSection = "";
|
currentSection = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ public:
|
||||||
PerfTimer(const vec<string>& sections);
|
PerfTimer(const vec<string>& sections);
|
||||||
|
|
||||||
void start(const string& section);
|
void start(const string& section);
|
||||||
|
void resume(const string& section);
|
||||||
|
|
||||||
vec<usize> end();
|
vec<usize> end();
|
||||||
private:
|
private:
|
||||||
void stopCurrent();
|
void stopCurrent();
|
||||||
|
|
|
@ -16,7 +16,7 @@ LocalWorld::LocalWorld(SubgamePtr game, ServerConnection& conn, Renderer& render
|
||||||
// worldGenStream(make_shared<WorldInterpolationStream>(*game.l(), *this, 55)),
|
// worldGenStream(make_shared<WorldInterpolationStream>(*game.l(), *this, 55)),
|
||||||
player(make_shared<LocalPlayer>(game, *this, DimensionPtr(nullptr), renderer)) {
|
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() {
|
void LocalWorld::init() {
|
||||||
|
@ -43,15 +43,9 @@ void LocalWorld::update(f64 delta, vec<usize>& perfTimings, PerfTimer& perf) {
|
||||||
refs->update(delta, net);
|
refs->update(delta, net);
|
||||||
|
|
||||||
// Update the network
|
// Update the network
|
||||||
perf.start("update:net");
|
perf.resume("other");
|
||||||
net.update();
|
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
|
// Update debug interface
|
||||||
perf.start("update:debug");
|
perf.start("update:debug");
|
||||||
debugGui.update(
|
debugGui.update(
|
||||||
|
@ -60,20 +54,21 @@ void LocalWorld::update(f64 delta, vec<usize>& perfTimings, PerfTimer& perf) {
|
||||||
perfTimings,
|
perfTimings,
|
||||||
activeDimension->getMeshChunksDrawn(),
|
activeDimension->getMeshChunksDrawn(),
|
||||||
activeDimension->getMeshChunksCommitted());
|
activeDimension->getMeshChunksCommitted());
|
||||||
|
perf.resume("other");
|
||||||
|
|
||||||
// Toggle regular interface
|
// Toggle regular interface
|
||||||
if (renderer.window.input.keyPressed(GLFW_KEY_F1)) {
|
if (renderer.window.input.keyPressed(GLFW_KEY_F1)) {
|
||||||
hudVisible = !hudVisible;
|
hudVisible = !hudVisible;
|
||||||
debugGui.changeVisibility(hudVisible ? debugVisible ? DebugGui::Visibility::OFF :
|
|
||||||
DebugGui::Visibility::FPS_ONLY : DebugGui::Visibility::ON);
|
|
||||||
player.l()->setHudVisible(hudVisible);
|
player.l()->setHudVisible(hudVisible);
|
||||||
|
debugGui.changeVisibility(hudVisible ? debugVisible ? DebugGui::Visibility::ON :
|
||||||
|
DebugGui::Visibility::FPS_ONLY : DebugGui::Visibility::OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle debug interface
|
// Toggle debug interface
|
||||||
if (renderer.window.input.keyPressed(GLFW_KEY_F3)) {
|
if (renderer.window.input.keyPressed(GLFW_KEY_F3)) {
|
||||||
debugVisible = !debugVisible;
|
debugVisible = !debugVisible;
|
||||||
debugGui.changeVisibility(hudVisible ? debugVisible ? DebugGui::Visibility::OFF :
|
debugGui.changeVisibility(hudVisible ? debugVisible ? DebugGui::Visibility::ON :
|
||||||
DebugGui::Visibility::FPS_ONLY : DebugGui::Visibility::ON);
|
DebugGui::Visibility::FPS_ONLY : DebugGui::Visibility::OFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ void LocalDimension::update(f64 delta) {
|
||||||
for (let it = regions.cbegin(); it != regions.cend();) {
|
for (let it = regions.cbegin(); it != regions.cend();) {
|
||||||
for (u16 m = 0; m < 64; m++) {
|
for (u16 m = 0; m < 64; m++) {
|
||||||
let mapBlock = it->second->get(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 ||
|
if (abs(clientMapBlock.x - mapBlock->pos.x) > retainMapBlockRange.x ||
|
||||||
abs(clientMapBlock.y - mapBlock->pos.y) > retainMapBlockRange.y ||
|
abs(clientMapBlock.y - mapBlock->pos.y) > retainMapBlockRange.y ||
|
||||||
|
@ -80,6 +80,8 @@ void LocalDimension::update(f64 delta) {
|
||||||
erase_region_and_continue:
|
erase_region_and_continue:
|
||||||
it = regions.erase(it);
|
it = regions.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mapBlockScanY = (mapBlockScanY + 1) % MAPBLOCK_SCAN_Y_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalDimension::setChunk(sptr<Chunk> chunk) {
|
void LocalDimension::setChunk(sptr<Chunk> chunk) {
|
||||||
|
|
|
@ -98,6 +98,9 @@ private:
|
||||||
std::unordered_map<vec3, chunk_ref, Vec::vec3> renderRefs{};
|
std::unordered_map<vec3, chunk_ref, Vec::vec3> renderRefs{};
|
||||||
std::list<sptr<ChunkRenderElem>> renderElems{};
|
std::list<sptr<ChunkRenderElem>> renderElems{};
|
||||||
|
|
||||||
|
u32 mapBlockScanY = 0;
|
||||||
|
const static u32 MAPBLOCK_SCAN_Y_INTERVAL = 8;
|
||||||
|
|
||||||
const ivec2 retainMapBlockRange = { 4, 4 };
|
const ivec2 retainMapBlockRange = { 4, 4 };
|
||||||
i64 entityInd = -1;
|
i64 entityInd = -1;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue