From 42e632d220d2a8e102f1c5f94c4741a714c8f065 Mon Sep 17 00:00:00 2001 From: Ara Date: Fri, 8 Dec 2023 09:53:51 +0600 Subject: [PATCH] ScopeTimer + small fixes --- .gitignore | 1 + src/frontend/gui/panels.h | 3 ++- src/util/timeutil.cpp | 8 ++++++++ src/util/timeutil.h | 13 +++++++++++++ src/voxels/Chunks.cpp | 11 +++++------ 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 1dfd2a2a..55057c5a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ Debug/src/**/*.o Debug/voxel_engine /build +/screenshots /world /worlds/**/* diff --git a/src/frontend/gui/panels.h b/src/frontend/gui/panels.h index 3524576f..1911abfc 100644 --- a/src/frontend/gui/panels.h +++ b/src/frontend/gui/panels.h @@ -93,7 +93,8 @@ namespace gui { void back(); void clearHistory(); void reset(); - +//comment or erase pragma if you hate notes.. +#pragma message("gui::PagesControl::current() returns Page by-value! (can initiate unexpected behaviour)") Page current(); }; } diff --git a/src/util/timeutil.cpp b/src/util/timeutil.cpp index 7cee8e9f..04be381f 100644 --- a/src/util/timeutil.cpp +++ b/src/util/timeutil.cpp @@ -1,5 +1,7 @@ #include "timeutil.h" +#include + using std::chrono::high_resolution_clock; using std::chrono::duration_cast; using std::chrono::microseconds; @@ -11,6 +13,12 @@ int64_t timeutil::Timer::stop() { return duration_cast(high_resolution_clock::now()-start).count(); } +timeutil::ScopeLogTimer::ScopeLogTimer(long long id) : scopeid_(id) {} + +timeutil::ScopeLogTimer::~ScopeLogTimer() { + std::cout << "Scope "<< scopeid_ <<" finished in "<< ScopeLogTimer::stop() << " micros."<setModified(true); } - +#include "../util/timeutil.h" voxel* Chunks::rayCast(vec3 start, vec3 dir, float maxDist, @@ -218,6 +218,7 @@ voxel* Chunks::rayCast(vec3 start, voxel* voxel = get(ix, iy, iz); const Block* def = nullptr; if (voxel == nullptr || (def = contentIds->getBlockDef(voxel->id))->selectable){ + timeutil::ScopeLogTimer lg((long long)def); end.x = px + t * dx; end.y = py + t * dy; end.z = pz + t * dz; @@ -336,7 +337,7 @@ void Chunks::translate(int dx, int dz){ } for (int z = 0; z < d; z++){ for (int x = 0; x < w; x++){ - shared_ptr chunk = chunks[z * d + x]; + shared_ptr chunk = chunks[z * w + x]; int nx = x - dx; int nz = z - dz; if (chunk == nullptr) @@ -351,9 +352,7 @@ void Chunks::translate(int dx, int dz){ chunksSecond[nz * w + nx] = chunk; } } - shared_ptr* ctemp = chunks; - chunks = chunksSecond; - chunksSecond = ctemp; + std::swap(chunks, chunksSecond); ox += dx; oz += dz;