summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorReid <reidyaro@gmail.com>2011-08-08 16:51:11 +0200
committerReid <reidyaro@gmail.com>2011-08-08 16:51:11 +0200
commit7f8498bf14338f67089881afb14b0b398a152c8c (patch)
treee0ba5648c775776be6177dae3c0c8b50922517b1 /src/game.cpp
parent391a4c3a1e4d5c3815ba7c822fb9bd03969dea6e (diff)
parentbcd0bdb1f087c3153d070baa274e7ecf8c8268e1 (diff)
downloadmanaverse-7f8498bf14338f67089881afb14b0b398a152c8c.tar.gz
manaverse-7f8498bf14338f67089881afb14b0b398a152c8c.tar.bz2
manaverse-7f8498bf14338f67089881afb14b0b398a152c8c.tar.xz
manaverse-7f8498bf14338f67089881afb14b0b398a152c8c.zip
Merge branch 'master' of gitorious.org:manaplus/manaplus
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp131
1 files changed, 129 insertions, 2 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 494d35692..9a5128f37 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -162,6 +162,8 @@ ChatTab *debugChatTab = NULL;
TradeTab *tradeChatTab = NULL;
BattleTab *battleChatTab = NULL;
+const unsigned adjustDelay = 10;
+
/**
* Initialize every game sub-engines in the right order
*/
@@ -331,8 +333,12 @@ Game *Game::mInstance = 0;
Game::Game():
mLastTarget(ActorSprite::UNKNOWN),
- mCurrentMap(0), mMapName(""),
- mValidSpeed(true), mLastAction(0)
+ mCurrentMap(0),
+ mMapName(""),
+ mValidSpeed(true),
+ mLastAction(0),
+ mNextAdjustTime(cur_time + adjustDelay),
+ mAdjustLevel(0)
{
spellManager = new SpellManager;
spellShortcut = new SpellShortcut;
@@ -342,6 +348,8 @@ Game::Game():
disconnectedDialog = NULL;
+ mAdjustPerfomance = config.getBoolValue("adjustPerfomance");
+
// Create the viewport
viewport = new Viewport;
viewport->setDimension(gcn::Rectangle(0, 0, graphics->mWidth,
@@ -391,6 +399,9 @@ Game::~Game()
{
config.write();
serverConfig.write();
+
+ resetAdjustLevel();
+
// delete mWindowMenu;
// mWindowMenu = 0;
@@ -504,6 +515,7 @@ void Game::logic()
// Handle network stuff
if (!Net::getGameHandler()->isConnected())
{
+
if (Client::getState() == STATE_CHANGE_MAP)
return; // Not a problem here
@@ -530,6 +542,8 @@ void Game::logic()
}
else
{
+ if (mAdjustPerfomance)
+ adjustPerfomance();
if (disconnectedDialog)
{
disconnectedDialog->scheduleDelete();
@@ -538,6 +552,117 @@ void Game::logic()
}
}
+void Game::adjustPerfomance()
+{
+ if (mNextAdjustTime <= adjustDelay)
+ {
+ mNextAdjustTime = cur_time + adjustDelay;
+ }
+ else if (mNextAdjustTime < cur_time)
+ {
+ mNextAdjustTime = cur_time + adjustDelay;
+
+ if (mAdjustLevel > 3 || !player_node || player_node->getHalfAway()
+ || player_node->getAway())
+ {
+ return;
+ }
+
+ int maxFps = config.getIntValue("fpslimit");
+ if (!maxFps)
+ maxFps = 30;
+ else if (maxFps < 10)
+ return;
+
+ if (fps < maxFps - 10)
+ {
+ mAdjustLevel ++;
+ switch (mAdjustLevel)
+ {
+ case 1:
+ {
+ if (config.getBoolValue("beingopacity"))
+ {
+ config.setValue("beingopacity", false);
+ config.setSilent("beingopacity", true);
+ if (localChatTab)
+ {
+ localChatTab->chatLog("Auto disable Show "
+ "beings transparency", BY_SERVER);
+ }
+ }
+ else
+ {
+ mNextAdjustTime = cur_time + 1;
+ }
+ break;
+ }
+ case 2:
+ if (Particle::emitterSkip < 4)
+ {
+ Particle::emitterSkip = 4;
+// config.setValue("particleEmitterSkip", 3);
+ if (localChatTab)
+ {
+ localChatTab->chatLog("Auto lower Particle "
+ "effects", BY_SERVER);
+ }
+ }
+ else
+ {
+ mNextAdjustTime = cur_time + 1;
+ }
+ break;
+ case 3:
+ if (!config.getBoolValue("alphaCache"))
+ {
+ config.setValue("alphaCache", true);
+ config.setSilent("alphaCache", false);
+ if (localChatTab)
+ {
+ localChatTab->chatLog("Auto enable opacity cache",
+ BY_SERVER);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+}
+
+void Game::resetAdjustLevel()
+{
+ if (!mAdjustPerfomance)
+ return;
+
+ mNextAdjustTime = cur_time + adjustDelay;
+ switch (mAdjustLevel)
+ {
+ case 1:
+ config.setValue("beingopacity",
+ config.getBoolValue("beingopacity"));
+ break;
+ case 2:
+ config.setValue("beingopacity",
+ config.getBoolValue("beingopacity"));
+ Particle::emitterSkip = config.getIntValue(
+ "particleEmitterSkip") + 1;
+ break;
+ default:
+ case 3:
+ config.setValue("beingopacity",
+ config.getBoolValue("beingopacity"));
+ Particle::emitterSkip = config.getIntValue(
+ "particleEmitterSkip") + 1;
+ config.setValue("alphaCache",
+ config.getBoolValue("alphaCache"));
+ break;
+ }
+ mAdjustLevel = 0;
+}
+
/**
* The huge input handling method.
*/
@@ -1414,6 +1539,8 @@ void Game::handleInput()
*/
void Game::changeMap(const std::string &mapPath)
{
+ resetAdjustLevel();
+
// Clean up floor items, beings and particles
actorSpriteManager->clear();