1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-25 20:02:40 +01:00
openrw/rwgame/states/BenchmarkState.cpp

105 lines
3.0 KiB
C++
Raw Normal View History

#include "BenchmarkState.hpp"
#include <engine/GameState.hpp>
2016-09-09 22:13:20 +02:00
#include "RWGame.hpp"
#include <fstream>
#include <iostream>
BenchmarkState::BenchmarkState(RWGame* game, const std::string& benchfile)
: State(game), benchfile(benchfile), benchmarkTime(0.f), duration(0.f), frameCounter(0) {
}
2016-09-09 22:13:20 +02:00
void BenchmarkState::enter() {
getWindow().hideCursor();
2016-09-09 22:13:20 +02:00
std::ifstream benchstream(benchfile);
2016-09-09 22:13:20 +02:00
unsigned int clockHour;
unsigned int clockMinute;
benchstream >> clockHour;
benchstream.seekg(1, std::ios_base::cur);
benchstream >> clockMinute;
2016-09-09 22:13:20 +02:00
game->getWorld()->state->basic.gameHour = clockHour;
game->getWorld()->state->basic.gameMinute = clockMinute;
2016-09-09 22:13:20 +02:00
float time = 0.f;
glm::vec3 tmpPos{};
2016-09-09 22:13:20 +02:00
while (benchstream) {
TrackPoint point;
benchstream >> point.time;
if (!benchstream) break;
benchstream >> point.position.x;
if (!benchstream) break;
benchstream >> point.position.y;
if (!benchstream) break;
benchstream >> point.position.z;
if (!benchstream) break;
benchstream >> point.angle.x;
if (!benchstream) break;
benchstream >> point.angle.y;
if (!benchstream) break;
benchstream >> point.angle.z;
if (!benchstream) break;
benchstream >> point.angle.w;
if (!benchstream) break;
if (track.empty()) {
2016-09-09 22:13:20 +02:00
tmpPos = point.position;
}
float pointDist = glm::distance(tmpPos, point.position);
tmpPos = point.position;
point.time = time + pointDist / 50.f;
time = point.time;
duration = std::max(duration, point.time);
track.push_back(point);
}
2016-09-09 22:13:20 +02:00
std::cout << "Loaded " << track.size() << " points" << std::endl;
}
2016-09-09 22:13:20 +02:00
void BenchmarkState::exit() {
std::cout << "Results =============\n"
<< "Benchmark: " << benchfile << "\n"
<< "Frames: " << frameCounter << "\n"
<< "Duration: " << duration << " seconds\n"
<< "Avg frametime: " << std::setprecision(3)
<< (duration / frameCounter) << " (" << (frameCounter / duration)
<< " fps)" << std::endl;
}
2016-09-09 22:13:20 +02:00
void BenchmarkState::tick(float dt) {
if (!track.empty()) {
2016-09-09 22:13:20 +02:00
TrackPoint& a = track.front();
TrackPoint& b = track.back();
for (TrackPoint& p : track) {
if (benchmarkTime < p.time) {
b = p;
break;
}
a = p;
}
if (benchmarkTime > duration) {
done();
2016-09-09 22:13:20 +02:00
}
if (b.time != a.time) {
float alpha = (benchmarkTime - a.time) / (b.time - a.time);
trackCam.position = glm::mix(a.position, b.position, alpha);
trackCam.rotation = glm::slerp(a.angle, b.angle, alpha);
}
benchmarkTime += dt;
}
}
2016-09-09 22:13:20 +02:00
void BenchmarkState::draw(GameRenderer* r) {
frameCounter++;
State::draw(r);
}
2016-09-09 22:13:20 +02:00
void BenchmarkState::handleEvent(const SDL_Event& e) {
State::handleEvent(e);
}
Fix some warnings openrw/rwengine/src/engine/GameData.cpp:358:26: warning: moving a temporary object prevents copy elision [-Wpessimizing-move] textureslots[slot] = std::move(loadTextureArchive(name)); ^ openrw/rwengine/src/engine/GameData.cpp:358:26: note: remove std::move call here textureslots[slot] = std::move(loadTextureArchive(name)); ^~~~~~~~~~ ~ openrw/rwengine/src/objects/CharacterObject.cpp:16:18: warning: unused variable 'enter_offset' [-Wunused-variable] static glm::vec3 enter_offset(0.81756252f, 0.34800607f, -0.486281008f); ^ In file included from openrw/rwgame/RWGame.cpp:5: openrw/rwgame/states/BenchmarkState.hpp:33:23: warning: 'BenchmarkState::getCamera' hides overloaded virtual function [-Woverloaded-virtual] const ViewCamera& getCamera(); ^ openrw/rwgame/State.hpp:51:31: note: hidden overloaded virtual function 'State::getCamera' declared here: different number of parameters (1 vs 0) virtual const ViewCamera& getCamera(float alpha); ^ In file included from openrw/rwgame/RWGame.cpp:6: openrw/rwgame/states/IngameState.hpp:53:18: warning: 'draw' overrides a member function but is not marked 'override' [-Winconsistent-missing-override] virtual void draw(GameRenderer* r); ^ openrw/rwgame/State.hpp:28:18: note: overridden virtual function is here virtual void draw(GameRenderer* r) { ^ In file included from openrw/rwgame/RWGame.cpp:6: openrw/rwgame/states/IngameState.hpp:60:23: warning: 'getCamera' overrides a member function but is not marked 'override' [-Winconsistent-missing-override] const ViewCamera& getCamera(float alpha); ^ openrw/rwgame/State.hpp:51:31: note: overridden virtual function is here virtual const ViewCamera& getCamera(float alpha); ^ openrw/rwgame/RWGame.cpp:242:22: warning: unused variable 'vehicleModel' [-Wunused-variable] uint16_t vehicleModel = 110; // @todo Which cars are spawned?! ^ In file included from openrw/rwengine/src/script/modules/GTA3Module.cpp:1: In file included from openrw/rwengine/src/engine/GameState.hpp:7: openrw/rwengine/src/engine/ScreenText.hpp:140:63: warning: suggest braces around initialization of subobject [-Wmissing-braces] const std::array<GameString, sizeof...(args)> vals = {args...}; ^~~~ { } openrw/rwengine/src/script/modules/GTA3ModuleImpl.inl:5669:16: note: in instantiation of function template specialization 'ScreenText::format<std::__1::basic_string<unsigned short, std::__1::char_traits<unsigned short>, std::__1::allocator<unsigned short> > >' requested here ScreenText::format( ^ In file included from openrw/rwengine/src/script/modules/GTA3Module.cpp:1: In file included from openrw/rwengine/src/engine/GameState.hpp:7: openrw/rwengine/src/engine/ScreenText.hpp:140:63: warning: suggest braces around initialization of subobject [-Wmissing-braces] const std::array<GameString, sizeof...(args)> vals = {args...}; ^~~~ { } openrw/rwengine/src/script/modules/GTA3ModuleImpl.inl:10214:18: note: in instantiation of function template specialization 'ScreenText::format<std::__1::basic_string<unsigned short, std::__1::char_traits<unsigned short>, std::__1::allocator<unsigned short> >, std::__1::basic_string<unsigned short, std::__1::char_traits<unsigned short>, std::__1::allocator<unsigned short> > >' requested here ScreenText::format(script::gxt(args, gxtEntry), ^ openrw/rwgame/State.cpp:40:42: warning: unused parameter 'alpha' [-Wunused-parameter] const ViewCamera& State::getCamera(float alpha) { ^ openrw/rwengine/src/render/ObjectRenderer.cpp:20:17: warning: unused variable 'kWorldDrawDistanceFactor' [-Wunused-const-variable] constexpr float kWorldDrawDistanceFactor = kDrawDistanceFactor; ^
2017-09-21 16:45:44 +02:00
const ViewCamera& BenchmarkState::getCamera(float) {
2016-09-09 22:13:20 +02:00
return trackCam;
}