Skip to content

Commit

Permalink
Merge pull request EasyRPG#622 from carstene1ns/fps
Browse files Browse the repository at this point in the history
Implement new FPS display behaviour
  • Loading branch information
fdelapena committed Oct 7, 2015
2 parents 305ac28 + b00c1ce commit dcd2cc2
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern "C" {
JNIEXPORT void JNICALL Java_org_easyrpg_player_player_EasyRpgPlayerActivity_toggleFps
(JNIEnv *, jclass)
{
Graphics::fps_on_screen = !Graphics::fps_on_screen;
Player::fps_flag = !Player::fps_flag;
}

JNIEXPORT void JNICALL Java_org_easyrpg_player_player_EasyRpgPlayerActivity_endGame
Expand Down
3 changes: 3 additions & 0 deletions builds/easyrpg-player.6.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ for some additional binary patches.
*--fullscreen*::
Start in fullscreen mode.

*--show-fps*::
Enable frames per second counter.

*--hide-title*::
Hide the title background image and center the command menu.

Expand Down
7 changes: 2 additions & 5 deletions src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#include "player.h"

namespace Graphics {
bool fps_on_screen;

void UpdateTitle();
void DrawFrame();
void DrawOverlay();
Expand Down Expand Up @@ -75,7 +73,6 @@ unsigned SecondToFrame(float const second) {
}

void Graphics::Init() {
fps_on_screen = false;
fps = 0;
frozen_screen = BitmapRef();
screen_erased = false;
Expand Down Expand Up @@ -150,7 +147,7 @@ void Graphics::UpdateTitle() {
std::stringstream title;
title << Player::game_title;

if (!fps_on_screen) {
if (Player::fps_flag) {
title << " - FPS " << real_fps;
}

Expand Down Expand Up @@ -204,7 +201,7 @@ void Graphics::DrawFrame() {
}

void Graphics::DrawOverlay() {
if (Graphics::fps_on_screen) {
if (DisplayUi->IsFullscreen() && Player::fps_flag) {
std::stringstream text;
text << "FPS: " << real_fps;
DisplayUi->GetDisplaySurface()->TextDraw(2, 2, Color(255, 255, 255, 255), text.str());
Expand Down
2 changes: 0 additions & 2 deletions src/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ namespace Graphics {

void UpdateZCallback();

extern bool fps_on_screen;

void Push();
void Pop();

Expand Down
9 changes: 8 additions & 1 deletion src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace Player {
bool debug_flag;
bool hide_title_flag;
bool window_flag;
bool fps_flag;
bool battle_test_flag;
int battle_test_troop_id;
bool new_game_flag;
Expand Down Expand Up @@ -227,7 +228,7 @@ void Player::Update(bool update_scene) {

// Normal logic update
if (Input::IsTriggered(Input::TOGGLE_FPS)) {
Graphics::fps_on_screen = !Graphics::fps_on_screen;
fps_flag = !fps_flag;
}
if (Input::IsTriggered(Input::TAKE_SCREENSHOT)) {
Output::TakeScreenshot();
Expand Down Expand Up @@ -303,6 +304,7 @@ void Player::ParseCommandLine(int argc, char *argv[]) {
#else
window_flag = false;
#endif
fps_flag = false;
debug_flag = false;
hide_title_flag = false;
exit_flag = false;
Expand Down Expand Up @@ -336,6 +338,9 @@ void Player::ParseCommandLine(int argc, char *argv[]) {
if (*it == "window" || *it == "--window") {
window_flag = true;
}
else if (*it == "--show-fps") {
fps_flag = true;
}
else if (*it == "testplay" || *it == "--test-play") {
debug_flag = true;
}
Expand Down Expand Up @@ -698,6 +703,8 @@ void Player::PrintUsage() {

std::cout << " " << "--fullscreen " << "Start in fullscreen mode." << std::endl;

std::cout << " " << "--show-fps " << "Enable frames per second counter." << std::endl;

std::cout << " " << "--hide-title " << "Hide the title background image and center the" << std::endl;
std::cout << " " << " " << "command menu." << std::endl;

Expand Down
3 changes: 3 additions & 0 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ namespace Player {
/** Window flag, if true will run in window mode instead of full screen. */
extern bool window_flag;

/** FPS flag, if true will display frames per second counter. */
extern bool fps_flag;

/** Battle Test flag, if true will run battle test. */
extern bool battle_test_flag;

Expand Down
3 changes: 0 additions & 3 deletions src/sdl_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,7 @@ bool SdlUi::RefreshDisplayMode() {
uint32_t flags = current_display_mode.flags;
int display_width = current_display_mode.width;
int display_height = current_display_mode.height;

// Display on screen fps while fullscreen or no window available
bool is_fullscreen = (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP;
Graphics::fps_on_screen = is_fullscreen || !toggle_fs_available;

if (zoom_available && current_display_mode.zoom) {
display_width *= 2;
Expand Down

0 comments on commit dcd2cc2

Please sign in to comment.