git repos / saland

commit d04df111

sago007 · 2018-10-28 12:35
d04df111d48be4b308b0507e1cc4bf5cb74dc55f patch · browse files
parent 148e781ea16aa7f11fbdb4fc18f43f6d2517beac

Add fps counter in game

Changed files

M src/sago/SagoTextField.cpp before
M src/saland/Game.cpp before
diff --git a/src/sago/SagoTextField.cpp b/src/sago/SagoTextField.cpp index 2bb40f9..666de12 100644 --- a/src/sago/SagoTextField.cpp +++ b/src/sago/SagoTextField.cpp
@@ -209,7 +209,7 @@ void SagoTextField::Draw(SDL_Renderer* target, int x, int y, Alignment alignment
x -= texW/2;
}
if (alignment == Alignment::right) {
- y -= texW;
+ x -= texW;
}
if (verticalAlignment == VerticalAlignment::center) {
y -= texH/2;
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 35d70a9..bac51d7 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp
@@ -214,6 +214,24 @@ void Game::Draw(SDL_Renderer* target) {
);
data->bottomField.SetText(buffer);
data->bottomField.Draw(target, 2, screen_height, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::bottom);
+//#if DEBUG
+ static unsigned long int Frames;
+ static unsigned long int Ticks;
+ static char FPS[10];
+ static sago::SagoTextField fpsField;
+ fpsField.SetHolder(globalData.dataHolder);
+ Frames++;
+ if (SDL_GetTicks() >= Ticks + 1000) {
+ if (Frames > 999) {
+ Frames=999;
+ }
+ snprintf(FPS, sizeof(FPS), "%lu fps", Frames);
+ Frames = 0;
+ Ticks = SDL_GetTicks();
+ }
+ fpsField.SetText(FPS);
+ fpsField.Draw(globalData.screen, globalData.xsize-4, 4, sago::SagoTextField::Alignment::right);
+//#endif
}
void Game::ProcessInput(const SDL_Event& event, bool& processed) {