From eb4fb4ff41cd0c9bc6e9331a4ffe1059d9c8082f Mon Sep 17 00:00:00 2001 From: Ahmed Samy Date: Sat, 14 Dec 2013 18:48:18 +0200 Subject: [PATCH] Animations are now optional The default behaviour is still there though. --- src/client/luafunctions.cpp | 4 ++++ src/client/map.cpp | 29 +++++++++++++++++++++++++++++ src/client/map.h | 11 +++++++++++ src/client/mapview.cpp | 17 ++++++++++++++--- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/client/luafunctions.cpp b/src/client/luafunctions.cpp index adb97749..e3161d4e 100644 --- a/src/client/luafunctions.cpp +++ b/src/client/luafunctions.cpp @@ -141,6 +141,10 @@ void Client::registerLuaFunctions() g_lua.bindSingletonFunction("g_map", "getZoneColor", &Map::getZoneColor, &g_map); g_lua.bindSingletonFunction("g_map", "showZones", &Map::showZones, &g_map); g_lua.bindSingletonFunction("g_map", "showZone", &Map::showZone, &g_map); + g_lua.bindSingletonFunction("g_map", "setForceShowAnimations", &Map::setForceShowAnimations, &g_map); + g_lua.bindSingletonFunction("g_map", "isForcingAnimations", &Map::isForcingAnimations, &g_map); + g_lua.bindSingletonFunction("g_map", "isShowingAnimations", &Map::isShowingAnimations, &g_map); + g_lua.bindSingletonFunction("g_map", "setShowAnimations", &Map::setShowAnimations, &g_map); g_lua.bindSingletonFunction("g_map", "beginGhostMode", &Map::beginGhostMode, &g_map); g_lua.bindSingletonFunction("g_map", "endGhostMode", &Map::endGhostMode, &g_map); g_lua.bindSingletonFunction("g_map", "findItemsById", &Map::findItemsById, &g_map); diff --git a/src/client/map.cpp b/src/client/map.cpp index d6bcba4f..5501e481 100644 --- a/src/client/map.cpp +++ b/src/client/map.cpp @@ -39,6 +39,7 @@ TilePtr Map::m_nulltile; void Map::init() { resetAwareRange(); + m_animationFlags |= Animation_Show; } void Map::terminate() @@ -363,6 +364,34 @@ void Map::setZoneColor(tileflags_t zone, const Color& color) m_zoneColors[zone] = color; } +void Map::setForceShowAnimations(bool force) +{ + if(force) { + if(!(m_animationFlags & Animation_Force)) + m_animationFlags |= Animation_Force; + } else + m_animationFlags &= ~Animation_Force; +} + +bool Map::isForcingAnimations() +{ + return (m_animationFlags & Animation_Force) == Animation_Force; +} + +bool Map::isShowingAnimations() +{ + return (m_animationFlags & Animation_Show) == Animation_Show; +} + +void Map::setShowAnimations(bool show) +{ + if(show) { + if(!(m_animationFlags & Animation_Show)) + m_animationFlags |= Animation_Show; + } else + m_animationFlags &= ~Animation_Show; +} + void Map::beginGhostMode(float opacity) { g_painter->setOpacity(opacity); diff --git a/src/client/map.h b/src/client/map.h index 6c975374..4c0dc95f 100644 --- a/src/client/map.h +++ b/src/client/map.h @@ -93,6 +93,11 @@ enum { BLOCK_SIZE = 32 }; +enum : uint8 { + Animation_Force, + Animation_Show +}; + class TileBlock { public: TileBlock() { m_tiles.fill(nullptr); } @@ -195,6 +200,11 @@ public: bool showZones() { return m_zoneFlags != 0; } bool showZone(tileflags_t zone) { return (m_zoneFlags & zone) == zone; } + void setForceShowAnimations(bool force); + bool isForcingAnimations(); + bool isShowingAnimations(); + void setShowAnimations(bool show); + void beginGhostMode(float opacity); void endGhostMode(); @@ -244,6 +254,7 @@ private: std::vector m_mapViews; std::unordered_map m_waypoints; + uint8 m_animationFlags; uint32 m_zoneFlags; std::array m_zoneColors; float m_zoneOpacity; diff --git a/src/client/mapview.cpp b/src/client/mapview.cpp index 192732da..85c60676 100644 --- a/src/client/mapview.cpp +++ b/src/client/mapview.cpp @@ -85,11 +85,22 @@ void MapView::draw(const Rect& rect) Position cameraPosition = getCameraPosition(); int drawFlags = 0; + // First branch: + // This is unlikely to be false because a lot of us + // don't wanna hear their GPU fan while playing a + // 2D game. + // + // Second & Third branch: + // This is likely to be true since not many people have + // low-end graphics cards. + if(unlikely(g_map.isForcingAnimations()) || (likely(g_map.isShowingAnimations()) && m_viewMode == NEAR_VIEW)) + drawFlags = Otc::DrawAnimations; + if(m_viewMode == NEAR_VIEW) - drawFlags = Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawWalls | - Otc::DrawItems | Otc::DrawCreatures | Otc::DrawEffects | Otc::DrawMissiles | Otc::DrawAnimations; + drawFlags |= Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawWalls | + Otc::DrawItems | Otc::DrawCreatures | Otc::DrawEffects | Otc::DrawMissiles; else - drawFlags = Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawWalls | Otc::DrawItems; + drawFlags |= Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawWalls | Otc::DrawItems; if(m_mustDrawVisibleTilesCache || (drawFlags & Otc::DrawAnimations)) { m_framebuffer->bind();