pushGLStates & popGLStates optimizations

master
Vectozavr 2021-11-06 01:55:34 +07:00
parent a68a28313c
commit cc0f0022aa
3 changed files with 12 additions and 10 deletions

View File

@ -10,7 +10,7 @@ using namespace std;
int main() {
Shooter game;
game.create(1280, 720, ShooterConsts::PROJECT_NAME, false);
game.create(1280, 720, ShooterConsts::PROJECT_NAME, true);
//game.create(1920, 1080, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen);
//game.create(2048, 1152, ShooterConsts::PROJECT_NAME, false);

View File

@ -69,6 +69,7 @@ void Engine::create(int screenWidth, int screenHeight, const std::string &name,
}
delete[] view;
} else {
screen->pushGLStates();
// clear triangles from previous frame
camera->clear();
// project triangles to the camera plane
@ -81,6 +82,7 @@ void Engine::create(int screenWidth, int screenHeight, const std::string &name,
}
_triPerSec = camera->buffSize() * Time::fps();
screen->popGLStates();
}
Time::stopTimer("d projections");
@ -147,11 +149,11 @@ void Engine::printDebugInfo() const {
float yPos = 300;
int height = 50;
double totalTime = Time::elapsedTimerMilliseconds("d all");
double totalTime = Time::elapsedTimerSeconds("d all");
double timeSum = 0;
int i = 0;
for (auto &[timerName, timer] : Time::timers()) {
int width = timerWidth * timer.elapsedMilliseconds() / totalTime;
int width = timerWidth * timer.elapsedSeconds() / totalTime;
if (timerName == "d all" || timerName[0] != 'd') {
continue;
@ -168,13 +170,13 @@ void Engine::printDebugInfo() const {
screen->drawText(
timerName.substr(2, timerName.size()) + ":\t" +
std::to_string((int) (1.0 / timer.elapsedMilliseconds())) + " / s \t (" +
std::to_string((int) (100 * timer.elapsedMilliseconds() / totalTime)) + "%)",
std::to_string((int) (1.0 / timer.elapsedSeconds())) + " / s \t (" +
std::to_string((int) (100 * timer.elapsedSeconds() / totalTime)) + "%)",
Vec2D{xPos + 10, yPos + height * i + 5}, 30,
sf::Color(0, 0, 0, 150));
i++;
timeSum += timer.elapsedMilliseconds();
timeSum += timer.elapsedSeconds();
}
int width = timerWidth * (totalTime - timeSum) / totalTime;

View File

@ -17,6 +17,10 @@ void Timer::stop() {
}
double Timer::elapsedMilliseconds() const {
return elapsedSeconds()*1000;
}
double Timer::elapsedSeconds() const {
high_resolution_clock::time_point endTime;
if(_isRunning) {
@ -27,7 +31,3 @@ double Timer::elapsedMilliseconds() const {
return duration<double>(endTime - _startTime).count();
}
double Timer::elapsedSeconds() const {
return elapsedMilliseconds() / 1000.0;
}