1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

Moved framerate keeper from CPlayerInterface to CGuiHandler, thing should be running smoother.

This commit is contained in:
Michał W. Urbańczyk 2011-04-03 10:45:39 +00:00
parent 6d52bb5842
commit b5a546349b
4 changed files with 13 additions and 14 deletions

View File

@ -10,8 +10,6 @@
#include "CPlayerInterface.h" #include "CPlayerInterface.h"
//#include "SDL_Extensions.h" //#include "SDL_Extensions.h"
#include "SDL_Extensions.h" #include "SDL_Extensions.h"
//#include "SDL_framerate.h"
#include "SDL_framerate.h" #include "SDL_framerate.h"
#include "CConfigHandler.h" #include "CConfigHandler.h"
#include "CCreatureAnimation.h" #include "CCreatureAnimation.h"
@ -108,9 +106,6 @@ CPlayerInterface::CPlayerInterface(int Player)
showingDialog = new CondSh<bool>(false); showingDialog = new CondSh<bool>(false);
sysOpts = GDefaultOptions; sysOpts = GDefaultOptions;
//initializing framerate keeper //initializing framerate keeper
mainFPSmng = new FPSmanager;
SDL_initFramerate(mainFPSmng);
SDL_setFramerate(mainFPSmng, 48);
//framerate keeper initialized //framerate keeper initialized
cingconsole = new CInGameConsole; cingconsole = new CInGameConsole;
terminate_cond.set(false); terminate_cond.set(false);
@ -123,7 +118,6 @@ CPlayerInterface::~CPlayerInterface()
//delete pim; //delete pim;
//delNull(pim); //delNull(pim);
delete showingDialog; delete showingDialog;
delete mainFPSmng;
if(adventureInt) if(adventureInt)
{ {
if(adventureInt->active & CIntObject::KEYBOARD) if(adventureInt->active & CIntObject::KEYBOARD)
@ -289,7 +283,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details)
initMovement(details, ho, hp); initMovement(details, ho, hp);
//first initializing done //first initializing done
SDL_framerateDelay(mainFPSmng); // after first move SDL_framerateDelay(GH.mainFPSmng); // after first move
//main moving //main moving
for(int i=1; i<32; i+=2*sysOpts.heroMoveSpeed) for(int i=1; i<32; i+=2*sysOpts.heroMoveSpeed)
@ -298,7 +292,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details)
adventureInt->updateScreen = true; adventureInt->updateScreen = true;
adventureInt->show(screen); adventureInt->show(screen);
CSDL_Ext::update(screen); CSDL_Ext::update(screen);
SDL_framerateDelay(mainFPSmng); //for animation purposes SDL_framerateDelay(GH.mainFPSmng); //for animation purposes
} //for(int i=1; i<32; i+=4) } //for(int i=1; i<32; i+=4)
//main moving done //main moving done
@ -1349,8 +1343,6 @@ void CPlayerInterface::update()
CCS->curh->draw2(); CCS->curh->draw2();
pim->unlock(); pim->unlock();
SDL_framerateDelay(mainFPSmng);
} }
int CPlayerInterface::getLastIndex( std::string namePrefix) int CPlayerInterface::getLastIndex( std::string namePrefix)

View File

@ -3,7 +3,6 @@
#include "../global.h" #include "../global.h"
#include "../CGameInterface.h" #include "../CGameInterface.h"
#include "../lib/CondSh.h" #include "../lib/CondSh.h"
#include "SDL_framerate.h"
#include <map> #include <map>
#include <list> #include <list>
#include <algorithm> #include <algorithm>
@ -130,7 +129,6 @@ public:
CCastleInterface * castleInt; //NULL if castle window isn't opened CCastleInterface * castleInt; //NULL if castle window isn't opened
static CBattleInterface * battleInt; //NULL if no battle static CBattleInterface * battleInt; //NULL if no battle
FPSmanager * mainFPSmng; //to keep const framerate
CInGameConsole * cingconsole; CInGameConsole * cingconsole;
CCallback * cb; //to communicate with engine CCallback * cb; //to communicate with engine

View File

@ -9,6 +9,7 @@
#include "CBitmapHandler.h" #include "CBitmapHandler.h"
#include "Graphics.h" #include "Graphics.h"
#include "../CThreadHelper.h" #include "../CThreadHelper.h"
/* /*
* GUIBase.cpp, part of VCMI engine * GUIBase.cpp, part of VCMI engine
* *
@ -342,11 +343,14 @@ void CGuiHandler::run()
setThreadName(-1, "CGuiHandler::run"); setThreadName(-1, "CGuiHandler::run");
try try
{ {
SDL_initFramerate(mainFPSmng);
while(!terminate) while(!terminate)
{ {
if(curInt) if(curInt)
curInt->update(); curInt->update();
SDL_Delay(20); //give time for other apps
SDL_framerateDelay(mainFPSmng);
//SDL_Delay(20); //give time for other apps
} }
} HANDLE_EXCEPTION } HANDLE_EXCEPTION
} }
@ -358,11 +362,14 @@ CGuiHandler::CGuiHandler()
current = NULL; current = NULL;
terminate = false; terminate = false;
statusbar = NULL; statusbar = NULL;
mainFPSmng = new FPSmanager;
SDL_setFramerate(mainFPSmng, 48);
} }
CGuiHandler::~CGuiHandler() CGuiHandler::~CGuiHandler()
{ {
delete mainFPSmng;
} }
void CGuiHandler::breakEventHandling() void CGuiHandler::breakEventHandling()

View File

@ -7,6 +7,7 @@
#include <list> #include <list>
#include "../timeHandler.h" #include "../timeHandler.h"
#include "FontBase.h" #include "FontBase.h"
#include "SDL_framerate.h"
#ifdef max #ifdef max
#undef max #undef max
@ -511,6 +512,7 @@ public:
class CGuiHandler class CGuiHandler
{ {
public: public:
FPSmanager * mainFPSmng; //to keep const framerate
timeHandler th; timeHandler th;
std::list<IShowActivable *> listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on) std::list<IShowActivable *> listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on)
IStatusBar * statusbar; IStatusBar * statusbar;