Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah committed May 20, 2023
1 parent 812b3e6 commit 68ca488
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 83 deletions.
83 changes: 39 additions & 44 deletions src/client/mapview.cpp
Expand Up @@ -80,12 +80,12 @@ MapView::MapView() : m_pool(g_drawPool.get(DrawPoolType::MAP)), m_lightView(std:
}

g_painter->setOpacity(fadeOpacity);
});
});

m_pool->onAfterDraw([] {
g_painter->resetShaderProgram();
g_painter->resetOpacity();
});
});

setVisibleDimension(Size(15, 11));
}
Expand Down Expand Up @@ -200,8 +200,7 @@ void MapView::drawFloor()
const auto& crosshairRect = Rect(point, m_tileSize, m_tileSize);
g_drawPool.addTexturedRect(crosshairRect, m_crosshairTexture);
}
}
else if (m_lastHighlightTile) {
} else if (m_lastHighlightTile) {
m_mousePosition = {}; // Invalidate mousePosition
m_lastHighlightTile->unselect();
m_lastHighlightTile = nullptr;
Expand Down Expand Up @@ -282,15 +281,13 @@ void MapView::updateVisibleTiles()
for (int iz = m_cachedLastVisibleFloor; iz >= cachedFirstVisibleFloor; --iz) {
m_floors[iz].fadingTimers.restart(m_floorFading * 1000);
}
}
else if (prevFirstVisibleFloor < m_cachedFirstVisibleFloor) { // hiding new floor
} else if (prevFirstVisibleFloor < m_cachedFirstVisibleFloor) { // hiding new floor
m_fadeType = FadeType::OUT$;
for (int iz = prevFirstVisibleFloor; iz < m_cachedFirstVisibleFloor; ++iz) {
const int shift = std::max<int>(0, m_floorFading - m_floors[iz].fadingTimers.elapsed_millis());
m_floors[iz].fadingTimers.restart(shift * 1000);
}
}
else if (prevFirstVisibleFloor > m_cachedFirstVisibleFloor) { // showing floor
} else if (prevFirstVisibleFloor > m_cachedFirstVisibleFloor) { // showing floor
m_fadeType = FadeType::IN$;
m_fadeFinish = false;
for (int iz = m_cachedFirstVisibleFloor; iz < prevFirstVisibleFloor; ++iz) {
Expand Down Expand Up @@ -411,7 +408,7 @@ void MapView::updateGeometry(const Size& visibleDimension)
}
g_mainDispatcher.addEvent([=, this]() {
m_pool->getFrameBuffer()->resize(bufferSize);
});
});

const uint8_t left = std::min<uint8_t>(g_map.getAwareRange().left, (m_drawDimension.width() / 2) - 1);
const uint8_t top = std::min<uint8_t>(g_map.getAwareRange().top, (m_drawDimension.height() / 2) - 1);
Expand Down Expand Up @@ -553,7 +550,7 @@ void MapView::setAntiAliasingMode(const AntialiasingMode mode)
g_mainDispatcher.addEvent([=, this]() {
g_drawPool.get(DrawPoolType::MAP)->getFrameBuffer()
->setSmooth(mode != ANTIALIASING_DISABLED);
});
});

updateGeometry(m_visibleDimension);
}
Expand Down Expand Up @@ -662,8 +659,7 @@ uint8_t MapView::calcFirstVisibleFloor(bool checkLimitsFloorsView) const
// return forced first visible floor
if (m_lockedFirstVisibleFloor != -1) {
z = m_lockedFirstVisibleFloor;
}
else {
} else {
// this could happens if the player is not known yet
if (m_posInfo.camera.isValid()) {
// if nothing is limiting the view, the first visible floor is 0
Expand Down Expand Up @@ -764,8 +760,7 @@ void MapView::setShader(const std::string_view name, float fadein, float fadeout
if (fadeout > 0.0f && m_shader) {
m_nextShader = shader;
m_shaderSwitchDone = false;
}
else {
} else {
m_shader = shader;
m_nextShader = nullptr;
m_shaderSwitchDone = true;
Expand All @@ -776,7 +771,7 @@ void MapView::setShader(const std::string_view name, float fadein, float fadeout
m_fadeOutTime = fadeout;

if (shader) m_shaderPosition = getCameraPosition();
});
});
}

void MapView::setDrawLights(bool enable)
Expand All @@ -801,35 +796,35 @@ void MapView::updateViewportDirectionCache()
vp.left = vp.right;

switch (dir) {
case Otc::North:
case Otc::South:
vp.top += 1;
vp.bottom += 1;
break;

case Otc::West:
case Otc::East:
vp.right += 1;
vp.left += 1;
break;

case Otc::NorthEast:
case Otc::SouthEast:
case Otc::NorthWest:
case Otc::SouthWest:
vp.left += 1;
vp.bottom += 1;
vp.top += 1;
vp.right += 1;
break;

case Otc::InvalidDirection:
vp.left -= 1;
vp.right -= 1;
break;

default:
break;
case Otc::North:
case Otc::South:
vp.top += 1;
vp.bottom += 1;
break;

case Otc::West:
case Otc::East:
vp.right += 1;
vp.left += 1;
break;

case Otc::NorthEast:
case Otc::SouthEast:
case Otc::NorthWest:
case Otc::SouthWest:
vp.left += 1;
vp.bottom += 1;
vp.top += 1;
vp.right += 1;
break;

case Otc::InvalidDirection:
vp.left -= 1;
vp.right -= 1;
break;

default:
break;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/client/mapview.h
Expand Up @@ -207,7 +207,8 @@ class MapView : public LuaObject
void clear() { shades.clear(); tiles.clear(); }
};

struct FloorData {
struct FloorData
{
MapObject cachedVisibleTiles;
stdext::timer fadingTimers;
};
Expand Down
26 changes: 11 additions & 15 deletions src/client/minimap.cpp
Expand Up @@ -198,8 +198,7 @@ void Minimap::updateTile(const Position& pos, const TilePtr& tile)
if (!tile->isPathable())
minimapTile.flags |= MinimapTileNotPathable;
minimapTile.speed = std::min<int>(static_cast<int>(std::ceil(tile->getGroundSpeed() / 10.f)), UINT8_MAX);
}
else {
} else {
minimapTile.flags |= MinimapTileNotWalkable | MinimapTileNotPathable;
}

Expand Down Expand Up @@ -305,8 +304,7 @@ bool Minimap::loadImage(const std::string& fileName, const Position& topLeft, fl
}
}
return true;
}
catch (const stdext::exception& e) {
} catch (const stdext::exception& e) {
g_logger.error(stdext::format("failed to load OTMM minimap: %s", e.what()));
return false;
}
Expand Down Expand Up @@ -335,13 +333,13 @@ bool Minimap::loadOtmm(const std::string& fileName)
fin->getU32(); // flags

switch (version) {
case 1:
{
fin->getString(); // description
break;
}
default:
throw Exception("OTMM version not supported");
case 1:
{
fin->getString(); // description
break;
}
default:
throw Exception("OTMM version not supported");
}

fin->seek(start);
Expand Down Expand Up @@ -377,8 +375,7 @@ bool Minimap::loadOtmm(const std::string& fileName)

fin->close();
return true;
}
catch (const stdext::exception& e) {
} catch (const stdext::exception& e) {
g_logger.error(stdext::format("failed to load OTMM minimap: %s", e.what()));
return false;
}
Expand Down Expand Up @@ -438,8 +435,7 @@ void Minimap::saveOtmm(const std::string& fileName)
fin->flush();

fin->close();
}
catch (const stdext::exception& e) {
} catch (const stdext::exception& e) {
g_logger.error(stdext::format("failed to save OTMM minimap: %s", e.what()));
}
}
24 changes: 8 additions & 16 deletions src/client/missile.cpp
Expand Up @@ -58,36 +58,28 @@ void Missile::setPath(const Position& fromPosition, const Position& toPosition)
if (m_direction == Otc::NorthWest) {
m_numPatternX = 0;
m_numPatternY = 0;
}
else if (m_direction == Otc::North) {
} else if (m_direction == Otc::North) {
m_numPatternX = 1;
m_numPatternY = 0;
}
else if (m_direction == Otc::NorthEast) {
} else if (m_direction == Otc::NorthEast) {
m_numPatternX = 2;
m_numPatternY = 0;
}
else if (m_direction == Otc::East) {
} else if (m_direction == Otc::East) {
m_numPatternX = 2;
m_numPatternY = 1;
}
else if (m_direction == Otc::SouthEast) {
} else if (m_direction == Otc::SouthEast) {
m_numPatternX = 2;
m_numPatternY = 2;
}
else if (m_direction == Otc::South) {
} else if (m_direction == Otc::South) {
m_numPatternX = 1;
m_numPatternY = 2;
}
else if (m_direction == Otc::SouthWest) {
} else if (m_direction == Otc::SouthWest) {
m_numPatternX = 0;
m_numPatternY = 2;
}
else if (m_direction == Otc::West) {
} else if (m_direction == Otc::West) {
m_numPatternX = 0;
m_numPatternY = 1;
}
else {
} else {
m_numPatternX = 1;
m_numPatternY = 1;
}
Expand Down
9 changes: 3 additions & 6 deletions src/client/spritemanager.cpp
Expand Up @@ -70,8 +70,7 @@ bool SpriteManager::loadSpr(std::string file)
m_loaded = true;
g_lua.callGlobalField("g_sprites", "onLoadSpr", file);
return true;
}
catch (const stdext::exception& e) {
} catch (const stdext::exception& e) {
g_logger.error(stdext::format("Failed to load sprites from '%s': %s", file, e.what()));
return false;
}
Expand Down Expand Up @@ -127,8 +126,7 @@ void SpriteManager::saveSpr(const std::string& fileName)

fin->flush();
fin->close();
}
catch (const std::exception& e) {
} catch (const std::exception& e) {
g_logger.error(stdext::format("Failed to save '%s': %s", fileName, e.what()));
}
}
Expand Down Expand Up @@ -240,8 +238,7 @@ ImagePtr SpriteManager::getSpriteImage(int id, const FileStreamPtr& file) {
}

return image;
}
catch (const stdext::exception& e) {
} catch (const stdext::exception& e) {
g_logger.error(stdext::format("Failed to get sprite id %d: %s", id, e.what()));
return nullptr;
}
Expand Down
1 change: 0 additions & 1 deletion src/framework/graphics/fontmanager.h
Expand Up @@ -38,7 +38,6 @@ class FontManager

BitmapFontPtr getDefaultFont() const { return m_defaultFont; }


private:
std::vector<BitmapFontPtr> m_fonts;
BitmapFontPtr m_defaultFont;
Expand Down

0 comments on commit 68ca488

Please sign in to comment.