From 44a67465b96e1612ebab142aaff981afc7562c77 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 15 Jan 2011 10:33:07 +0000 Subject: [PATCH] Add profiling script --- .gitignore | 1 + include/IWindow.hpp | 2 +- src/Main.cpp | 4 +++- src/SDLWindow.cpp | 10 +++++++--- tools/profile.sh | 2 ++ 5 files changed, 14 insertions(+), 5 deletions(-) create mode 100755 tools/profile.sh diff --git a/.gitignore b/.gitignore index e520554..9e8d6ca 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ install_manifest.txt GG/ config.h core +callgrind.out.* diff --git a/include/IWindow.hpp b/include/IWindow.hpp index a939b34..b180bea 100644 --- a/include/IWindow.hpp +++ b/include/IWindow.hpp @@ -26,7 +26,7 @@ class IWindow { public: virtual ~IWindow() {} - virtual void run(IScreenPtr a_screen) = 0; + virtual void run(IScreenPtr a_screen, int frames = 0) = 0; virtual void switch_screen(IScreenPtr a_screen) = 0; virtual void quit() = 0; virtual void take_screen_shot() = 0; diff --git a/src/Main.cpp b/src/Main.cpp index 9eaa49f..46030d7 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -36,6 +36,7 @@ namespace { // Options set from command line int new_map_width = 32; int new_map_height = 32; + int run_cycles = 0; string map_file; string action; } @@ -51,6 +52,7 @@ static void parse_options(int argc, char** argv) ("height", value(&new_map_height), "Set new map height") ("action", value(&action), "Either `play' or `edit'") ("map", value(&map_file), "Name of map to load or create") + ("cycles", value(&run_cycles), "Run for N frames") ; positional_options_description p; @@ -122,7 +124,7 @@ int main(int argc, char** argv) else throw runtime_error("Unrecognised command: " + ::action); - ::window->run(screen); + ::window->run(screen, run_cycles); cfg->flush(); } diff --git a/src/SDLWindow.cpp b/src/SDLWindow.cpp index 9cd9dd1..aa4ed93 100644 --- a/src/SDLWindow.cpp +++ b/src/SDLWindow.cpp @@ -43,7 +43,7 @@ public: ~SDLWindow(); // IWindow interface - void run(IScreenPtr a_screen); + void run(IScreenPtr a_screen, int frames); void switch_screen(IScreenPtr a_screen); void quit(); void take_screen_shot(); @@ -181,8 +181,8 @@ void SDLWindow::switch_screen(IScreenPtr a_screen) will_skip_next_frame = true; } -// Run the game until the user quits -void SDLWindow::run(IScreenPtr a_screen) +// Run the game until the user quits or the frame limit runs out +void SDLWindow::run(IScreenPtr a_screen, int frames) { assert(!am_running); @@ -221,6 +221,10 @@ void SDLWindow::run(IScreenPtr a_screen) will_take_screen_shot = false; } + if (frames > 0) { + am_running = (--frames > 0); + } + frame_complete(); //fps_timer.update_title(); last_tick = tick_start; diff --git a/tools/profile.sh b/tools/profile.sh new file mode 100755 index 0000000..f7c2d9a --- /dev/null +++ b/tools/profile.sh @@ -0,0 +1,2 @@ +#!/bin/sh +valgrind --tool=callgrind ./bin/TrainGame --cycles 100 play figure8 -- 2.39.2