summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--src/game.cpp16
-rw-r--r--src/graphics.cpp9
-rw-r--r--src/main.cpp20
-rw-r--r--src/main.h1
-rw-r--r--src/resources/resourcemanager.cpp2
6 files changed, 43 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index f0060129..24d92fb8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@
- Added item descriptions to inventory and buy/sell dialogs
- Added confirmation dialog before quitting
- Added button to show/hide equipment window
+- Added framerate limiter to config options
- Fixed a crash in OpenGL mode
- Fixed rendering of minimap, progress bars and player sprite in OpenGL mode
diff --git a/src/game.cpp b/src/game.cpp
index 7481ea9a..8c90f329 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -68,8 +68,10 @@ class DeatchNoticeListener : public gcn::ActionListener {
}
} deathNoticeListener;
-
-Uint32 refresh_time(Uint32 interval, void *param)
+/**
+ * Advances game logic counter.
+ */
+Uint32 nextTick(Uint32 interval, void *param)
{
tick_time++;
if (tick_time == MAX_TIME) tick_time = 0;
@@ -80,7 +82,7 @@ Uint32 refresh_time(Uint32 interval, void *param)
* Lets u only trigger an action every other second
* tmp. counts fps
*/
-Uint32 second(Uint32 interval, void *param)
+Uint32 nextSecond(Uint32 interval, void *param)
{
action_time = true;
fps = frame;
@@ -107,6 +109,7 @@ void game()
while (state != EXIT)
{
+ // Handle all necessary game logic
while (get_elapsed_time(gameTime) > 0)
{
do_input();
@@ -115,9 +118,12 @@ void game()
}
gameTime = tick_time;
+ // Draw next frame
gui->logic();
engine->draw();
graphics->updateScreen();
+
+ // Handle network stuff and flush it
do_parse();
flush();
}
@@ -153,8 +159,8 @@ void do_init()
// Initialize timers
tick_time = 0;
- SDL_AddTimer(10, refresh_time, NULL);
- SDL_AddTimer(1000, second, NULL);
+ SDL_AddTimer(10, nextTick, NULL); // Logic counter
+ SDL_AddTimer(1000, nextSecond, NULL); // Seconds counter
// Initialize beings
player_node = new Being();
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 7da5520c..94c23704 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -148,4 +148,13 @@ void Graphics::updateScreen()
else {
SDL_Flip(screen);
}
+
+ // Decrement frame counter when using framerate limiting
+ if (framesToDraw > 1) framesToDraw--;
+
+ // Wait while we're not allowed to draw next frame yet
+ while (framesToDraw == 1)
+ {
+ SDL_Delay(10);
+ }
}
diff --git a/src/main.cpp b/src/main.cpp
index 8c871b6a..505cc647 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -68,6 +68,7 @@ unsigned char screen_mode;
char *homeDir = NULL;
int displayFlags, screenW, screenH, bitDepth;
bool useOpenGL = false;
+volatile int framesToDraw = 0;
Sound sound;
Music *bgm;
@@ -77,6 +78,15 @@ Logger *logger; /**< Log object */
ItemManager *itemDb; /**< Item database object */
/**
+ * Allows the next frame to be drawn (part of framerate limiting)
+ */
+Uint32 nextFrame(Uint32 interval, void *param)
+{
+ framesToDraw++;
+ return interval;
+}
+
+/**
* Listener used for responding to map start error dialog.
*/
class MapStartErrorListener : public gcn::ActionListener {
@@ -159,6 +169,7 @@ void init_engine()
config.setValue("remember", 1);
config.setValue("sfxVolume", 100);
config.setValue("musicVolume", 60);
+ config.setValue("fpslimit", 0);
// Checking if the configuration file exists... otherwise creates it with
// default options !
@@ -296,6 +307,15 @@ void init_engine()
new OkDialog("Sound Engine", err, &initWarningListener);
logger->log("Warning: %s", err);
}
+
+ // Set frame counter when using fps limit
+ int fpsLimit = (int)config.getValue("fpslimit", 0);
+ if (fpsLimit)
+ {
+ if (fpsLimit < 20) fpsLimit = 20;
+ if (fpsLimit > 200) fpsLimit = 200;
+ SDL_AddTimer(1000 / fpsLimit, nextFrame, NULL);
+ }
}
/** Clear the engine */
diff --git a/src/main.h b/src/main.h
index 944e755b..59dd1792 100644
--- a/src/main.h
+++ b/src/main.h
@@ -111,5 +111,6 @@ extern int screenW, screenH, bitDepth, displayFlags;
extern bool useOpenGL;
extern ItemManager *itemDb;
extern char *homeDir;
+extern volatile int framesToDraw;
#endif
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index d4a3a037..051f047c 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -213,10 +213,10 @@ void ResourceManager::searchAndAddZipFiles()
PHYSFS_addToSearchPath(TMW_DATADIR "data", 1);
PHYSFS_addToSearchPath("data", 1);
+#ifdef _WIN32
// Define the path in which to search
std::string searchString = std::string("data/*.zip");
-#ifdef _WIN32
// Create our find file data structure
struct _finddata_t findFileInfo;