From e26423653606556d049768773cd8a9f89c0b87cd Mon Sep 17 00:00:00 2001 From: bakasuradbl <47023887+bakasuradbl@users.noreply.github.com> Date: Sun, 5 Jul 2020 19:25:50 +0200 Subject: [PATCH 01/11] Changes in range in map.cpp Better manage of view range --- src/client/map.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/client/map.cpp b/src/client/map.cpp index 461cefbf0..7b3b87c08 100644 --- a/src/client/map.cpp +++ b/src/client/map.cpp @@ -29,6 +29,7 @@ #include "statictext.h" #include "mapview.h" #include "minimap.h" +#include "mapviewcontrol.h" #include #include @@ -689,10 +690,10 @@ void Map::setAwareRange(const AwareRange& range) void Map::resetAwareRange() { AwareRange range; - range.left = 8; - range.top = 6; - range.bottom = 7; - range.right = 9; + range.left = MapViewControl::maxMapviewX; + range.top = MapViewControl::maxMapviewY; + range.bottom = range.top + 1; + range.right = range.left + 1; setAwareRange(range); } From 4a77340933c4bf9dbf10a2101102d50ff98adce9 Mon Sep 17 00:00:00 2001 From: bakasuradbl <47023887+bakasuradbl@users.noreply.github.com> Date: Sun, 5 Jul 2020 19:26:54 +0200 Subject: [PATCH 02/11] Added mapviewcontrol to CMakeLists.txt --- src/client/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index d6fb4f6bc..b87db783c 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -76,6 +76,8 @@ set(client_SOURCES ${client_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/towns.h ${CMAKE_CURRENT_LIST_DIR}/creatures.cpp ${CMAKE_CURRENT_LIST_DIR}/creatures.h + ${CMAKE_CURRENT_LIST_DIR}/mapviewcontrol.cpp + ${CMAKE_CURRENT_LIST_DIR}/mapviewcontrol.h # lua ${CMAKE_CURRENT_LIST_DIR}/luavaluecasts.cpp From f35c8ef7ea23567c7d1511194dae3c40b5b373fd Mon Sep 17 00:00:00 2001 From: bakasuradbl <47023887+bakasuradbl@users.noreply.github.com> Date: Sun, 5 Jul 2020 19:30:22 +0200 Subject: [PATCH 03/11] Added mapviewcontrol to mapview.cpp Current OTClient drawFlags solution is left intact --- src/client/mapview.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/client/mapview.cpp b/src/client/mapview.cpp index eb12a5870..eab35fe81 100644 --- a/src/client/mapview.cpp +++ b/src/client/mapview.cpp @@ -66,6 +66,11 @@ MapView::MapView() setVisibleDimension(Size(15, 11)); m_shader = g_shaders.getDefaultMapShader(); + + for(int dir = Otc::North; dir < Otc::InvalidDirection; ++dir) { + MapViewControl mapview = MapViewControl((Otc::Direction)dir); + m_mapViewControl[dir] = mapview; + } } MapView::~MapView() @@ -127,6 +132,10 @@ void MapView::draw(const Rect& rect) } g_painter->setColor(Color::white); + const LocalPlayerPtr player = g_game.getLocalPlayer(); + const bool isWalking = player->isWalking() || player->isPreWalking() || player->isServerWalking(); + const auto& mapview = isWalking ? m_mapViewControl[player->getDirection()] : m_mapViewControl[Otc::InvalidDirection]; + auto it = m_cachedVisibleTiles.begin(); auto end = m_cachedVisibleTiles.end(); for(int z=m_cachedLastVisibleFloor;z>=m_cachedFirstVisibleFloor;--z) { @@ -139,6 +148,9 @@ void MapView::draw(const Rect& rect) else ++it; + if(!mapview.isValid(tile, cameraPosition)) + continue; + if (g_map.isCovered(tilePos, m_cachedFirstVisibleFloor)) tile->draw(transformPositionTo2D(tilePos, cameraPosition), scaleFactor, drawFlags); else From 6a8ce184c30aeedbb4f55365c46147fbbc855cd1 Mon Sep 17 00:00:00 2001 From: bakasuradbl <47023887+bakasuradbl@users.noreply.github.com> Date: Sun, 5 Jul 2020 19:33:34 +0200 Subject: [PATCH 04/11] Added mapviewcontrol to mapview.h --- src/client/mapview.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client/mapview.h b/src/client/mapview.h index 4f5721c53..84a7c6d06 100644 --- a/src/client/mapview.h +++ b/src/client/mapview.h @@ -29,6 +29,7 @@ #include #include #include "lightview.h" +#include "mapviewcontrol.h" // @bindclass class MapView : public LuaObject @@ -162,6 +163,7 @@ class MapView : public LuaObject stdext::boolean m_follow; std::vector m_cachedVisibleTiles; std::vector m_cachedFloorVisibleCreatures; + std::array m_mapViewControl; CreaturePtr m_followingCreature; FrameBufferPtr m_framebuffer; PainterShaderProgramPtr m_shader; From 1f8be6a0ef199bbf027f22ac663e923ad1d7a369 Mon Sep 17 00:00:00 2001 From: bakasuradbl <47023887+bakasuradbl@users.noreply.github.com> Date: Sun, 5 Jul 2020 19:36:23 +0200 Subject: [PATCH 05/11] Include mapviewcontrol to otclient.vcxproj --- vc14/otclient.vcxproj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vc14/otclient.vcxproj b/vc14/otclient.vcxproj index 095b26bfe..b7a89c2d0 100644 --- a/vc14/otclient.vcxproj +++ b/vc14/otclient.vcxproj @@ -161,6 +161,7 @@ + @@ -312,6 +313,7 @@ + @@ -474,4 +476,4 @@ - \ No newline at end of file + From 5e0bee78f1c6ed8fa4f65bb98027bf43f3982cea Mon Sep 17 00:00:00 2001 From: bakasuradbl <47023887+bakasuradbl@users.noreply.github.com> Date: Sun, 5 Jul 2020 19:37:44 +0200 Subject: [PATCH 06/11] Include mapviewcontrol to otclient.vcxproj.filters --- vc14/otclient.vcxproj.filters | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vc14/otclient.vcxproj.filters b/vc14/otclient.vcxproj.filters index 560887f35..4b0983936 100644 --- a/vc14/otclient.vcxproj.filters +++ b/vc14/otclient.vcxproj.filters @@ -453,6 +453,9 @@ Source Files\client + + Source Files\client + Source Files\client From a89b0de327423eb2ff61177e6ab78ad915e3b9f8 Mon Sep 17 00:00:00 2001 From: bakasuradbl <47023887+bakasuradbl@users.noreply.github.com> Date: Sun, 5 Jul 2020 19:39:55 +0200 Subject: [PATCH 07/11] Upload of mapviewcontrol.cpp Mehah solution --- src/client/mapviewcontrol.cpp | 95 +++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/client/mapviewcontrol.cpp diff --git a/src/client/mapviewcontrol.cpp b/src/client/mapviewcontrol.cpp new file mode 100644 index 000000000..b9de0a730 --- /dev/null +++ b/src/client/mapviewcontrol.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2010-2020 OTClient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "mapviewcontrol.h" +#include "map.h" + +MapViewControl::MapViewControl(const Otc::Direction directionWalking) +{ + m_top = maxMapviewY; + m_right = maxMapviewX; + m_bottom = m_top; + m_left = m_right; + + switch(directionWalking) { + case Otc::North: + m_top += 1; + m_bottom += 1; + break; + case Otc::East: + m_right += 1; + m_left += 1; + break; + case Otc::South: + m_top += 1; + m_bottom += 1; + break; + case Otc::West: + m_left += 1; + m_right += 1; + break; + case Otc::NorthEast: + m_left += 1; + m_bottom += 1; + + m_top += 1; + m_right += 1; + break; + case Otc::SouthEast: + m_right += 1; + m_bottom += 1; + + m_top += 1; + m_left += 1; + break; + case Otc::SouthWest: + m_top += 1; + m_right += 1; + + m_left += 1; + m_bottom += 1; + break; + case Otc::NorthWest: + m_right += 1; + m_bottom += 1; + + m_top += 1; + m_left += 1; + break; + case Otc::InvalidDirection: + break; + } +} + +bool MapViewControl::isValid(const TilePtr& tile, const Position cameraPosition) const +{ + const Position tilePos = tile->getPosition(); + const int dz = tilePos.z - cameraPosition.z; + Position checkPos = tilePos.translated(dz, dz); + + if(cameraPosition.x - checkPos.x >= m_left || cameraPosition.y - checkPos.y >= m_top) + return false; + else if((checkPos.x - cameraPosition.x >= m_right || checkPos.y - cameraPosition.y >= m_bottom) && tile->isSingleDimension()) + return false; + + return true; +} From be473ed0aa3734582241664fb21cb2c18ee693ba Mon Sep 17 00:00:00 2001 From: bakasuradbl <47023887+bakasuradbl@users.noreply.github.com> Date: Sun, 5 Jul 2020 19:42:26 +0200 Subject: [PATCH 08/11] Upload of mapviewcontrol.h Mehah solution --- src/client/mapviewcontrol.h | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/client/mapviewcontrol.h diff --git a/src/client/mapviewcontrol.h b/src/client/mapviewcontrol.h new file mode 100644 index 000000000..562e62039 --- /dev/null +++ b/src/client/mapviewcontrol.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2010-2020 OTClient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MAPVIEW_OPTIMIZED_H +#define MAPVIEW_OPTIMIZED_H + +#include "declarations.h" +#include "const.h" + +class MapViewControl { +public: + static const int32_t maxMapviewX = 8; + static const int32_t maxMapviewY = 6; + + MapViewControl(const Otc::Direction directionWalking = Otc::InvalidDirection); + + bool isValid(const TilePtr& tile, const Position cameraPosition) const; + + int top() const { return m_top; } + int right() const { return m_right; } + int bottom() const { return m_bottom; } + int left() const { return m_left; } + +private: + int m_top; + int m_right; + int m_bottom; + int m_left; +}; + +#endif From 80c50244bdc50615bac49a948383e6cfc1d14b92 Mon Sep 17 00:00:00 2001 From: Kamil Chojnowski Date: Sun, 5 Jul 2020 21:33:36 +0200 Subject: [PATCH 09/11] Minor fixes --- src/client/CMakeLists.txt | 4 ++-- src/client/mapview.cpp | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index b87db783c..1a4e0d30d 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -46,6 +46,8 @@ set(client_SOURCES ${client_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/mapio.cpp ${CMAKE_CURRENT_LIST_DIR}/mapview.cpp ${CMAKE_CURRENT_LIST_DIR}/mapview.h + ${CMAKE_CURRENT_LIST_DIR}/mapviewcontrol.cpp + ${CMAKE_CURRENT_LIST_DIR}/mapviewcontrol.h ${CMAKE_CURRENT_LIST_DIR}/minimap.cpp ${CMAKE_CURRENT_LIST_DIR}/minimap.h ${CMAKE_CURRENT_LIST_DIR}/lightview.cpp @@ -76,8 +78,6 @@ set(client_SOURCES ${client_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/towns.h ${CMAKE_CURRENT_LIST_DIR}/creatures.cpp ${CMAKE_CURRENT_LIST_DIR}/creatures.h - ${CMAKE_CURRENT_LIST_DIR}/mapviewcontrol.cpp - ${CMAKE_CURRENT_LIST_DIR}/mapviewcontrol.h # lua ${CMAKE_CURRENT_LIST_DIR}/luavaluecasts.cpp diff --git a/src/client/mapview.cpp b/src/client/mapview.cpp index eab35fe81..24186244b 100644 --- a/src/client/mapview.cpp +++ b/src/client/mapview.cpp @@ -23,6 +23,7 @@ #include "mapview.h" #include "creature.h" +#include "game.h" #include "map.h" #include "tile.h" #include "statictext.h" @@ -68,8 +69,8 @@ MapView::MapView() m_shader = g_shaders.getDefaultMapShader(); for(int dir = Otc::North; dir < Otc::InvalidDirection; ++dir) { - MapViewControl mapview = MapViewControl((Otc::Direction)dir); - m_mapViewControl[dir] = mapview; + MapViewControl mapViewControl = MapViewControl((Otc::Direction) dir); + m_mapViewControl[dir] = mapViewControl; } } @@ -134,12 +135,11 @@ void MapView::draw(const Rect& rect) const LocalPlayerPtr player = g_game.getLocalPlayer(); const bool isWalking = player->isWalking() || player->isPreWalking() || player->isServerWalking(); - const auto& mapview = isWalking ? m_mapViewControl[player->getDirection()] : m_mapViewControl[Otc::InvalidDirection]; + const auto& mapViewControl = isWalking ? m_mapViewControl[player->getDirection()] : m_mapViewControl[Otc::InvalidDirection]; auto it = m_cachedVisibleTiles.begin(); auto end = m_cachedVisibleTiles.end(); for(int z=m_cachedLastVisibleFloor;z>=m_cachedFirstVisibleFloor;--z) { - while(it != end) { const TilePtr& tile = *it; Position tilePos = tile->getPosition(); @@ -148,7 +148,7 @@ void MapView::draw(const Rect& rect) else ++it; - if(!mapview.isValid(tile, cameraPosition)) + if(!mapViewControl.isValid(tile, cameraPosition)) continue; if (g_map.isCovered(tilePos, m_cachedFirstVisibleFloor)) @@ -172,7 +172,6 @@ void MapView::draw(const Rect& rect) m_mustDrawVisibleTilesCache = false; } - float fadeOpacity = 1.0f; if(!m_shaderSwitchDone && m_fadeOutTime > 0) { fadeOpacity = 1.0f - (m_fadeTimer.timeElapsed() / m_fadeOutTime); From 9c0f60f01a93acd7c59fef055acbb1bdc5102d9d Mon Sep 17 00:00:00 2001 From: Kamil Chojnowski Date: Sun, 5 Jul 2020 22:07:53 +0200 Subject: [PATCH 10/11] Update visible tile cache invalidation --- src/client/game.cpp | 2 ++ src/client/localplayer.cpp | 3 +++ src/client/map.h | 1 + src/client/mapview.cpp | 15 +++++++-------- src/client/mapview.h | 3 ++- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/client/game.cpp b/src/client/game.cpp index 833ac34fd..d2d9b7fd7 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -653,6 +653,8 @@ bool Game::walk(Otc::Direction direction, bool dash) } m_localPlayer->stopAutoWalk(); + for(const auto& mapView: g_map.getMapViews()) + mapView->requestVisibleTilesCacheUpdate(); if(getClientVersion() <= 740) { const TilePtr& fromTile = g_map.getTile(m_localPlayer->getPosition()); diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 2d2e53b12..ad9c61b0d 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -243,6 +243,9 @@ void LocalPlayer::stopWalk() m_lastPrewalkDone = true; m_lastPrewalkDestination = Position(); + + for(const auto& mapView: g_map.getMapViews()) + mapView->requestVisibleTilesCacheUpdate(); } void LocalPlayer::updateWalkOffset(int totalPixelsWalked) diff --git a/src/client/map.h b/src/client/map.h index a7ce119b4..3fe70a62a 100644 --- a/src/client/map.h +++ b/src/client/map.h @@ -144,6 +144,7 @@ class Map void addMapView(const MapViewPtr& mapView); void removeMapView(const MapViewPtr& mapView); + const std::vector &getMapViews() const { return m_mapViews; } void notificateTileUpdate(const Position& pos); bool loadOtcm(const std::string& fileName); diff --git a/src/client/mapview.cpp b/src/client/mapview.cpp index 24186244b..83425b36e 100644 --- a/src/client/mapview.cpp +++ b/src/client/mapview.cpp @@ -133,10 +133,6 @@ void MapView::draw(const Rect& rect) } g_painter->setColor(Color::white); - const LocalPlayerPtr player = g_game.getLocalPlayer(); - const bool isWalking = player->isWalking() || player->isPreWalking() || player->isServerWalking(); - const auto& mapViewControl = isWalking ? m_mapViewControl[player->getDirection()] : m_mapViewControl[Otc::InvalidDirection]; - auto it = m_cachedVisibleTiles.begin(); auto end = m_cachedVisibleTiles.end(); for(int z=m_cachedLastVisibleFloor;z>=m_cachedFirstVisibleFloor;--z) { @@ -148,9 +144,6 @@ void MapView::draw(const Rect& rect) else ++it; - if(!mapViewControl.isValid(tile, cameraPosition)) - continue; - if (g_map.isCovered(tilePos, m_cachedFirstVisibleFloor)) tile->draw(transformPositionTo2D(tilePos, cameraPosition), scaleFactor, drawFlags); else @@ -322,6 +315,10 @@ void MapView::updateVisibleTilesCache(int start) if(!cameraPosition.isValid()) return; + const LocalPlayerPtr player = g_game.getLocalPlayer(); + const bool isWalking = player->isWalking() || player->isPreWalking() || player->isServerWalking(); + const auto& mapViewControl = isWalking ? m_mapViewControl[player->getDirection()] : m_mapViewControl[Otc::InvalidDirection]; + bool stop = false; // clear current visible tiles cache @@ -363,6 +360,8 @@ void MapView::updateVisibleTilesCache(int start) // skip tiles that are completely behind another tile if(g_map.isCompletelyCovered(tilePos, m_cachedFirstVisibleFloor)) continue; + if(!mapViewControl.isValid(tile, cameraPosition)) + continue; m_cachedVisibleTiles.push_back(tile); } m_updateTilesPos++; @@ -412,7 +411,7 @@ void MapView::updateVisibleTilesCache(int start) Position tilePos = cameraPosition.translated(p.x - m_virtualCenterOffset.x, p.y - m_virtualCenterOffset.y); tilePos.coveredUp(cameraPosition.z - iz); if(const TilePtr& tile = g_map.getTile(tilePos)) { - if(tile->isDrawable()) + if(tile->isDrawable() && mapViewControl.isValid(tile, cameraPosition)) m_cachedVisibleTiles.push_back(tile); } } diff --git a/src/client/mapview.h b/src/client/mapview.h index 84a7c6d06..7130a53f1 100644 --- a/src/client/mapview.h +++ b/src/client/mapview.h @@ -49,7 +49,6 @@ class MapView : public LuaObject private: void updateGeometry(const Size& visibleDimension, const Size& optimizedSize); void updateVisibleTilesCache(int start = 0); - void requestVisibleTilesCacheUpdate() { m_mustUpdateVisibleTilesCache = true; } protected: void onTileUpdate(const Position& pos); @@ -58,6 +57,8 @@ class MapView : public LuaObject friend class Map; public: + void requestVisibleTilesCacheUpdate() { m_mustUpdateVisibleTilesCache = true; } + // floor visibility related void lockFirstVisibleFloor(int firstVisibleFloor); void unlockFirstVisibleFloor(); From 8ed0ec8fa06da460be10b04fd9653a254a53be31 Mon Sep 17 00:00:00 2001 From: Kamil Chojnowski Date: Sun, 5 Jul 2020 22:15:03 +0200 Subject: [PATCH 11/11] Style --- src/client/map.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/map.h b/src/client/map.h index 3fe70a62a..966a4991a 100644 --- a/src/client/map.h +++ b/src/client/map.h @@ -144,7 +144,7 @@ class Map void addMapView(const MapViewPtr& mapView); void removeMapView(const MapViewPtr& mapView); - const std::vector &getMapViews() const { return m_mapViews; } + const std::vector& getMapViews() const { return m_mapViews; } void notificateTileUpdate(const Position& pos); bool loadOtcm(const std::string& fileName);