From a2a915d948e83e16f50a88fbea7dba2c265789c9 Mon Sep 17 00:00:00 2001 From: 4drik <4drik@users.noreply.github.com> Date: Sun, 5 Jul 2020 17:32:37 +0200 Subject: [PATCH 1/8] 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..49bf9e5d3 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 "viewportcontrol.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 = ViewportControl::maxViewportX; + range.top = ViewportControl::maxViewportY; + range.bottom = range.top + 1; + range.right = range.left + 1; setAwareRange(range); } From c65518bc9db95de5e7d2e656f6ac4b5b6b0b860e Mon Sep 17 00:00:00 2001 From: 4drik <4drik@users.noreply.github.com> Date: Sun, 5 Jul 2020 17:35:47 +0200 Subject: [PATCH 2/8] Added viewportcontrol 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..92c7e7bb7 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}/viewportcontrol.cpp + ${CMAKE_CURRENT_LIST_DIR}/viewportcontrol.h # lua ${CMAKE_CURRENT_LIST_DIR}/luavaluecasts.cpp From 5ca52170c37b86ddf5e9a9ef19db24ad407e9931 Mon Sep 17 00:00:00 2001 From: 4drik <4drik@users.noreply.github.com> Date: Sun, 5 Jul 2020 17:40:52 +0200 Subject: [PATCH 3/8] Added viewportcontrol 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..5c266775f 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) { + ViewportControl viewport = ViewportControl((Otc::Direction)dir); + m_viewportControl[dir] = viewport; + } } 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& viewport = isWalking ? m_viewportControl[player->getDirection()] : m_viewportControl[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(!viewport.isValid(tile, cameraPosition)) + continue; + if (g_map.isCovered(tilePos, m_cachedFirstVisibleFloor)) tile->draw(transformPositionTo2D(tilePos, cameraPosition), scaleFactor, drawFlags); else From 61191dc2581eb0ee53b6852c016757a1a2201681 Mon Sep 17 00:00:00 2001 From: 4drik <4drik@users.noreply.github.com> Date: Sun, 5 Jul 2020 17:42:08 +0200 Subject: [PATCH 4/8] Added viewportcontrol 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..3794583f6 100644 --- a/src/client/mapview.h +++ b/src/client/mapview.h @@ -29,6 +29,7 @@ #include #include #include "lightview.h" +#include "viewportcontrol.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_viewportControl; CreaturePtr m_followingCreature; FrameBufferPtr m_framebuffer; PainterShaderProgramPtr m_shader; From baa50ecc464e6a8e40cfb1c8414b31f67c3ac367 Mon Sep 17 00:00:00 2001 From: 4drik <4drik@users.noreply.github.com> Date: Sun, 5 Jul 2020 17:49:51 +0200 Subject: [PATCH 5/8] Include viewportcontrol 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..3b4997a56 100644 --- a/vc14/otclient.vcxproj +++ b/vc14/otclient.vcxproj @@ -184,6 +184,7 @@ + @@ -335,6 +336,7 @@ + @@ -474,4 +476,4 @@ - \ No newline at end of file + From cdb62518e54dcbaa9372bc4ef745d9a07b2053c6 Mon Sep 17 00:00:00 2001 From: 4drik <4drik@users.noreply.github.com> Date: Sun, 5 Jul 2020 17:51:02 +0200 Subject: [PATCH 6/8] Include viewportcontrol 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..cad984d95 100644 --- a/vc14/otclient.vcxproj.filters +++ b/vc14/otclient.vcxproj.filters @@ -522,6 +522,9 @@ Source Files\client + + Source Files\client + Source Files From 55ec544ad6a0cd899f4f262714785815fd9ff845 Mon Sep 17 00:00:00 2001 From: 4drik <4drik@users.noreply.github.com> Date: Sun, 5 Jul 2020 17:52:26 +0200 Subject: [PATCH 7/8] Upload of viewportcontrol.cpp Mehah solution --- src/client/viewportcontrol.cpp | 95 ++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/client/viewportcontrol.cpp diff --git a/src/client/viewportcontrol.cpp b/src/client/viewportcontrol.cpp new file mode 100644 index 000000000..e06117899 --- /dev/null +++ b/src/client/viewportcontrol.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 "viewportcontrol.h" +#include "map.h" + +ViewportControl::ViewportControl(const Otc::Direction directionWalking) +{ + m_top = maxViewportY; + m_right = maxViewportX; + 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 ViewportControl::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 8dd8c289640afe0ac982e349fe46601a76f5bf00 Mon Sep 17 00:00:00 2001 From: 4drik <4drik@users.noreply.github.com> Date: Sun, 5 Jul 2020 17:53:10 +0200 Subject: [PATCH 8/8] Uploaf og viewportcontrol.h Mehah solution --- src/client/viewportcontrol.h | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/client/viewportcontrol.h diff --git a/src/client/viewportcontrol.h b/src/client/viewportcontrol.h new file mode 100644 index 000000000..86f4196cc --- /dev/null +++ b/src/client/viewportcontrol.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 VIEWPORT_OPTIMIZED_H +#define VIEWPORT_OPTIMIZED_H + +#include "declarations.h" +#include "const.h" + +class ViewportControl { +public: + static const int32_t maxViewportX = 8; + static const int32_t maxViewportY = 6; + + ViewportControl(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