ScopeTimer + small fixes
This commit is contained in:
parent
eea920d98f
commit
42e632d220
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@ Debug/src/**/*.o
|
|||||||
Debug/voxel_engine
|
Debug/voxel_engine
|
||||||
|
|
||||||
/build
|
/build
|
||||||
|
/screenshots
|
||||||
|
|
||||||
/world
|
/world
|
||||||
/worlds/**/*
|
/worlds/**/*
|
||||||
|
|||||||
@ -93,7 +93,8 @@ namespace gui {
|
|||||||
void back();
|
void back();
|
||||||
void clearHistory();
|
void clearHistory();
|
||||||
void reset();
|
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();
|
Page current();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
#include "timeutil.h"
|
#include "timeutil.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using std::chrono::high_resolution_clock;
|
using std::chrono::high_resolution_clock;
|
||||||
using std::chrono::duration_cast;
|
using std::chrono::duration_cast;
|
||||||
using std::chrono::microseconds;
|
using std::chrono::microseconds;
|
||||||
@ -11,6 +13,12 @@ int64_t timeutil::Timer::stop() {
|
|||||||
return duration_cast<microseconds>(high_resolution_clock::now()-start).count();
|
return duration_cast<microseconds>(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."<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
float timeutil::time_value(float hour, float minute, float second) {
|
float timeutil::time_value(float hour, float minute, float second) {
|
||||||
return (hour + (minute + second / 60.0f) / 60.0f) / 24.0f;
|
return (hour + (minute + second / 60.0f) / 60.0f) / 24.0f;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,19 @@ namespace timeutil {
|
|||||||
int64_t stop();
|
int64_t stop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Timer that stops and prints time when destructor called
|
||||||
|
* @example:
|
||||||
|
* { // some scope (custom, function, if/else, cycle etc.)
|
||||||
|
* timeutil::ScopeLogTimer scopeclock();
|
||||||
|
* ...
|
||||||
|
* } */
|
||||||
|
class ScopeLogTimer : public Timer{
|
||||||
|
long long scopeid_;
|
||||||
|
public:
|
||||||
|
ScopeLogTimer(long long id);
|
||||||
|
~ScopeLogTimer();
|
||||||
|
};
|
||||||
|
|
||||||
float time_value(float hour, float minute, float second);
|
float time_value(float hour, float minute, float second);
|
||||||
void from_value(float value, int& hour, int& minute, int& second);
|
void from_value(float value, int& hour, int& minute, int& second);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,7 @@ Chunks::~Chunks(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
voxel* Chunks::get(int x, int y, int z){
|
voxel* Chunks::get(int x, int y, int z){
|
||||||
x -= ox * CHUNK_W;
|
x -= ox * CHUNK_W;
|
||||||
z -= oz * CHUNK_D;
|
z -= oz * CHUNK_D;
|
||||||
int cx = x / CHUNK_W;
|
int cx = x / CHUNK_W;
|
||||||
int cy = y / CHUNK_H;
|
int cy = y / CHUNK_H;
|
||||||
@ -174,7 +174,7 @@ void Chunks::set(int x, int y, int z, int id, uint8_t states){
|
|||||||
if (lz == CHUNK_D-1 && (chunk = getChunk(cx+ox, cz+oz+1)))
|
if (lz == CHUNK_D-1 && (chunk = getChunk(cx+ox, cz+oz+1)))
|
||||||
chunk->setModified(true);
|
chunk->setModified(true);
|
||||||
}
|
}
|
||||||
|
#include "../util/timeutil.h"
|
||||||
voxel* Chunks::rayCast(vec3 start,
|
voxel* Chunks::rayCast(vec3 start,
|
||||||
vec3 dir,
|
vec3 dir,
|
||||||
float maxDist,
|
float maxDist,
|
||||||
@ -218,6 +218,7 @@ voxel* Chunks::rayCast(vec3 start,
|
|||||||
voxel* voxel = get(ix, iy, iz);
|
voxel* voxel = get(ix, iy, iz);
|
||||||
const Block* def = nullptr;
|
const Block* def = nullptr;
|
||||||
if (voxel == nullptr || (def = contentIds->getBlockDef(voxel->id))->selectable){
|
if (voxel == nullptr || (def = contentIds->getBlockDef(voxel->id))->selectable){
|
||||||
|
timeutil::ScopeLogTimer lg((long long)def);
|
||||||
end.x = px + t * dx;
|
end.x = px + t * dx;
|
||||||
end.y = py + t * dy;
|
end.y = py + t * dy;
|
||||||
end.z = pz + t * dz;
|
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 z = 0; z < d; z++){
|
||||||
for (int x = 0; x < w; x++){
|
for (int x = 0; x < w; x++){
|
||||||
shared_ptr<Chunk> chunk = chunks[z * d + x];
|
shared_ptr<Chunk> chunk = chunks[z * w + x];
|
||||||
int nx = x - dx;
|
int nx = x - dx;
|
||||||
int nz = z - dz;
|
int nz = z - dz;
|
||||||
if (chunk == nullptr)
|
if (chunk == nullptr)
|
||||||
@ -351,9 +352,7 @@ void Chunks::translate(int dx, int dz){
|
|||||||
chunksSecond[nz * w + nx] = chunk;
|
chunksSecond[nz * w + nx] = chunk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shared_ptr<Chunk>* ctemp = chunks;
|
std::swap(chunks, chunksSecond);
|
||||||
chunks = chunksSecond;
|
|
||||||
chunksSecond = ctemp;
|
|
||||||
|
|
||||||
ox += dx;
|
ox += dx;
|
||||||
oz += dz;
|
oz += dz;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user