Skip to content

Commit

Permalink
fix: clang warning/errors
Browse files Browse the repository at this point in the history
now it is possible to compile using LLVM(clang) in visual studio
  • Loading branch information
mehah authored Feb 27, 2023
1 parent e21a547 commit 01d8f9e
Show file tree
Hide file tree
Showing 26 changed files with 93 additions and 163 deletions.
3 changes: 2 additions & 1 deletion src/client/animatedtext.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@

#pragma once

#include "declarations.h"
#include <framework/core/timer.h>
#include <framework/graphics/cachedtext.h>
#include <framework/graphics/fontmanager.h>
#include "thing.h"
#include <framework/luaengine/luaobject.h>

// @bindclass
class AnimatedText : public LuaObject
Expand Down
2 changes: 1 addition & 1 deletion src/client/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ uint16_t Creature::getStepDuration(bool ignoreDiagonal, Otc::Direction dir)
stepDuration = ((stepDuration + serverBeat - 1) / serverBeat) * serverBeat;
}

if (m_stepCache.mustStabilizeCam = (isLocalPlayer() && stepDuration <= 100)) {
if ((m_stepCache.mustStabilizeCam = (isLocalPlayer() && stepDuration <= 100))) {
stepDuration += 10;
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Effect : public Thing
void setId(uint32_t id) override;
void setPosition(const Position& position, uint8_t stackPos = 0, bool hasElevation = false) override;

bool isEffect() { return true; }
bool isEffect() override { return true; }
bool waitFor(const EffectPtr&);

EffectPtr asEffect() { return static_self_cast<Effect>(); }
Expand Down
2 changes: 1 addition & 1 deletion src/client/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void Item::setPosition(const Position& position, uint8_t stackPos, bool hasEleva
{
Thing::setPosition(position, stackPos);

if (hasElevation || m_drawConductor.agroup && stackPos > 0)
if (hasElevation || (m_drawConductor.agroup && stackPos > 0))
m_drawConductor.agroup = false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/localplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool LocalPlayer::retryAutoWalk()
m_autoWalkContinueEvent->cancel();

m_autoWalkContinueEvent = g_dispatcher.scheduleEvent(
[capture0 = asLocalPlayer(), this, autoWalkDest = m_autoWalkDestination] { capture0->autoWalk(autoWalkDest, true); }, 200
[capture0 = asLocalPlayer(), autoWalkDest = m_autoWalkDestination] { capture0->autoWalk(autoWalkDest, true); }, 200
);

m_autoWalkRetries += 1;
Expand Down
7 changes: 5 additions & 2 deletions src/client/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ void Map::cleanDynamicThings()

void Map::addThing(const ThingPtr& thing, const Position& pos, int16_t stackPos)
{
if (!thing || thing->isItem() && thing->getId() == 0)
if (!thing)
return;

if (thing->isItem() && thing->getId() == 0)
return;

if (thing->isMissile()) {
Expand Down Expand Up @@ -438,7 +441,7 @@ void Map::setShowAnimations(bool show)
m_animationFlags |= Animation_Show;
} else
m_animationFlags &= ~Animation_Show;
}
}
#endif

void Map::beginGhostMode(float opacity) { g_painter->setOpacity(opacity); }
Expand Down
4 changes: 2 additions & 2 deletions src/client/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ MapView::MapView() : m_pool(g_drawPool.get<DrawPoolFramed>(DrawPoolType::MAP))
g_painter->setOpacity(fadeOpacity);
});

m_pool->onAfterDraw([this] {
m_pool->onAfterDraw([] {
g_painter->resetShaderProgram();
g_painter->resetOpacity();
});
Expand Down Expand Up @@ -140,7 +140,7 @@ void MapView::drawFloor()
g_drawPool.setOpacity(fadeLevel);

Position _camera = cameraPosition;
const bool alwaysTransparent = m_floorViewMode == ALWAYS_WITH_TRANSPARENCY && z < m_cachedFirstVisibleFloor&& _camera.coveredUp(cameraPosition.z - z);
const bool alwaysTransparent = m_floorViewMode == ALWAYS_WITH_TRANSPARENCY && z < m_cachedFirstVisibleFloor && _camera.coveredUp(cameraPosition.z - z);

const auto& map = m_cachedVisibleTiles[z];

Expand Down
3 changes: 1 addition & 2 deletions src/client/minimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,7 @@ void Minimap::saveOtmm(const std::string& fileName)
fin->addU8(pos.z);

unsigned long len = blockSize;
const int ret = compress2(compressBuffer.data(), &len, (uint8_t*)&(*block).getTiles(), blockSize, COMPRESS_LEVEL);
assert(ret == Z_OK);
compress2(compressBuffer.data(), &len, (uint8_t*)&(*block).getTiles(), blockSize, COMPRESS_LEVEL);
fin->addU16(len);
fin->write(compressBuffer.data(), len);
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/missile.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Missile : public Thing
void setId(uint32_t id) override;
void setPath(const Position& fromPosition, const Position& toPosition);

bool isMissile() { return true; }
bool isMissile() override { return true; }

MissilePtr asMissile() { return static_self_cast<Missile>(); }

Expand Down
1 change: 1 addition & 0 deletions src/client/thingtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ ThingFlagAttr ThingType::thingAttrToThingFlagAttr(ThingAttr attr) {
case ThingAttrPodium: return ThingFlagAttrPodium;
case ThingAttrTopEffect: return ThingFlagAttrTopEffect;
case ThingAttrMarket: return ThingFlagAttrMarket;
default: break;
}

return ThingFlagAttrNone;
Expand Down
1 change: 1 addition & 0 deletions src/client/uimapanchorlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ int UIPositionAnchor::getHookedPoint(const UIWidgetPtr& hookedWidget, const UIWi
case Fw::AnchorBottom: return hookedRect.bottom();
case Fw::AnchorVerticalCenter: return hookedRect.verticalCenter();
case Fw::AnchorHorizontalCenter: return hookedRect.horizontalCenter();
case Fw::AnchorNone: break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/framework/core/eventdispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void EventDispatcher::poll()
break;
}

for (int_fast32_t i = -1; ++i < m_pollEventsSize;) {
for (int_fast32_t i = -1; ++i < static_cast<int_fast32_t>(m_pollEventsSize);) {
const auto event = m_eventList.front();
m_eventList.pop_front();
if (isMainDispatcher) ul.unlock();
Expand Down
2 changes: 1 addition & 1 deletion src/framework/core/graphicalapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void GraphicalApplication::resize(const Size& size)
g_ui.resize(size);
m_onInputEvent = false;

g_mainDispatcher.addEvent([this, size] {
g_mainDispatcher.addEvent([size] {
g_graphics.resize(size);
g_drawPool.get<DrawPoolFramed>(DrawPoolType::FOREGROUND)->resize(size);
});
Expand Down
2 changes: 1 addition & 1 deletion src/framework/core/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <framework/luaengine/luainterface.h>
#include <framework/otml/otml.h>

Module::Module(const std::string_view name) : m_name(name.data()), m_sandboxEnv(g_lua.newSandboxEnv()) {}
Module::Module(const std::string_view name) : m_sandboxEnv(g_lua.newSandboxEnv()), m_name(name.data()) {}

bool Module::load()
{
Expand Down
2 changes: 1 addition & 1 deletion src/framework/graphics/drawpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ bool DrawPool::canRepaint(const bool autoUpdateStatus)
if (m_shaderRefreshDelay > 0 && (m_refreshDelay == 0 || m_shaderRefreshDelay < m_refreshDelay))
refreshDelay = m_shaderRefreshDelay;

const bool canRepaint = m_status.first != m_status.second || refreshDelay > 0 && m_refreshTimer.ticksElapsed() >= refreshDelay;
const bool canRepaint = (m_status.first != m_status.second) || (refreshDelay > 0 && m_refreshTimer.ticksElapsed() >= refreshDelay);

if (canRepaint) {
if (static_cast<bool>(m_refreshDelay) != autoUpdateStatus)
Expand Down
3 changes: 0 additions & 3 deletions src/framework/graphics/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ void Image::blit(const Point& dest, const ImagePtr& other)
if (!other)
return;

int coloredPixelSize = 0;

const uint8_t* otherPixels = other->getPixelData();
for (int p = 0; p < other->getPixelCount(); ++p) {
const int x = p % other->getWidth();
Expand All @@ -141,7 +139,6 @@ void Image::blit(const Point& dest, const ImagePtr& other)
m_pixels[pos + 1] = otherPixels[p * 4 + 1];
m_pixels[pos + 2] = otherPixels[p * 4 + 2];
m_pixels[pos + 3] = otherPixels[p * 4 + 3];
++coloredPixelSize;
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/framework/graphics/particleaffector.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@

#pragma once

#include <framework/otml/otml.h>
#include "declarations.h"
#include <framework/otml/otml.h>

class ParticleAffector
{
public:
virtual ~ParticleAffector() {} // fix clang warning

void update(float elapsedTime);
virtual void load(const OTMLNodePtr& node);
virtual void updateParticle(const ParticlePtr&, float) const {}
virtual void updateParticle(const ParticlePtr&, float) const = 0;

bool hasFinished() const { return m_finished; }

Expand Down
3 changes: 1 addition & 2 deletions src/framework/graphics/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#include <framework/core/application.h>
#include <framework/core/resourcemanager.h>

Shader::Shader(ShaderType shaderType) : m_shaderType(shaderType),
m_shaderId(glCreateShader(static_cast<GLenum>(shaderType)))
Shader::Shader(ShaderType shaderType) : m_shaderId(glCreateShader(static_cast<GLenum>(shaderType))), m_shaderType(shaderType)
{
;
if (!m_shaderId)
Expand Down
2 changes: 2 additions & 0 deletions src/framework/otml/otmlnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
class OTMLNode : public std::enable_shared_from_this<OTMLNode>
{
public:
virtual ~OTMLNode() {} // fix clang warning

static OTMLNodePtr create(const std::string_view tag = "", bool unique = false);
static OTMLNodePtr create(const std::string_view tag, const std::string_view value);

Expand Down
14 changes: 5 additions & 9 deletions src/framework/platform/win32window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ bool WIN32Window::isExtensionSupported(const char* ext)
//TODO
return false;
#else
using wglGetExtensionsStringProc = const char* (WINAPI*)();
const auto wglGetExtensionsString = static_cast<wglGetExtensionsStringProc>(getExtensionProcAddress("wglGetExtensionsStringEXT"));
const auto wglGetExtensionsString = (const char* (WINAPI*)())(getExtensionProcAddress("wglGetExtensionsStringEXT"));
if (!wglGetExtensionsString)
return false;

Expand All @@ -443,7 +442,7 @@ void* WIN32Window::getExtensionProcAddress(const char* ext)
//TODO
return NULL;
#else
return static_cast<void*>(wglGetProcAddress(ext));
return (void*)wglGetProcAddress(ext);
#endif
}

Expand Down Expand Up @@ -940,8 +939,7 @@ void WIN32Window::setVerticalSync(bool enable)
if (!isExtensionSupported("WGL_EXT_swap_control"))
return;

using wglSwapIntervalProc = BOOL(WINAPI*)(int);
const auto wglSwapInterval = static_cast<wglSwapIntervalProc>(getExtensionProcAddress("wglSwapIntervalEXT"));
const auto wglSwapInterval = (BOOL(WINAPI*)(int))getExtensionProcAddress("wglSwapIntervalEXT");
if (!wglSwapInterval)
return;

Expand Down Expand Up @@ -1054,8 +1052,7 @@ Rect WIN32Window::getClientRect() const
{
if (m_window) {
RECT clientRect = { 0,0,0,0 };
const int ret = GetClientRect(m_window, &clientRect);
assert(ret != 0);
GetClientRect(m_window, &clientRect);
return Rect(Point(clientRect.left, clientRect.top), Point(clientRect.right, clientRect.bottom));
}
return Rect(m_position, m_size);
Expand All @@ -1065,8 +1062,7 @@ Rect WIN32Window::getWindowRect()
{
if (m_window) {
RECT windowRect = { 0,0,0,0 };
const int ret = GetWindowRect(m_window, &windowRect);
assert(ret != 0);
GetWindowRect(m_window, &windowRect);
return Rect(Point(windowRect.left, windowRect.top), Point(windowRect.right, windowRect.bottom));
}
return adjustWindowRect(getClientRect());
Expand Down
2 changes: 2 additions & 0 deletions src/framework/sound/soundfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
class SoundFile : public std::enable_shared_from_this<SoundFile>
{
public:
virtual ~SoundFile() {} // fix clang warning

SoundFile(const FileStreamPtr& fileStream) : m_file(fileStream) {}
static SoundFilePtr loadSoundFile(const std::string& filename);

Expand Down
79 changes: 15 additions & 64 deletions src/framework/stdext/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,71 +75,22 @@ namespace stdext

bool is_valid_utf8(const std::string_view src)
{
const auto* bytes = src.data();
while (*bytes) {
if ((// ASCII
// use bytes[0] <= 0x7F to allow ASCII control characters
bytes[0] == 0x09 ||
bytes[0] == 0x0A ||
bytes[0] == 0x0D ||
(0x20 <= bytes[0] && bytes[0] <= 0x7E)
)
) {
bytes += 1;
continue;
int c, i, ix, n, j;
for (i = 0, ix = src.length(); i < ix; i++) {
c = (unsigned char)src[i];
//if (c==0x09 || c==0x0a || c==0x0d || (0x20 <= c && c <= 0x7e) ) n = 0; // is_printable_ascii
if (0x00 <= c && c <= 0x7f) n = 0; // 0bbbbbbb
else if ((c & 0xE0) == 0xC0) n = 1; // 110bbbbb
else if (c == 0xed && i < (ix - 1) && ((unsigned char)src[i + 1] & 0xa0) == 0xa0) return false; //U+d800 to U+dfff
else if ((c & 0xF0) == 0xE0) n = 2; // 1110bbbb
else if ((c & 0xF8) == 0xF0) n = 3; // 11110bbb
//else if (($c & 0xFC) == 0xF8) n=4; // 111110bb //byte 5, unnecessary in 4 byte UTF-8
//else if (($c & 0xFE) == 0xFC) n=5; // 1111110b //byte 6, unnecessary in 4 byte UTF-8
else return false;
for (j = 0; j < n && i < ix; j++) { // n bytes matching 10bbbbbb follow ?
if ((++i == ix) || (((unsigned char)src[i] & 0xC0) != 0x80))
return false;
}
if ((// non-overlong 2-byte
(0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
(0x80 <= bytes[1] && bytes[1] <= 0xBF)
)
) {
bytes += 2;
continue;
}
if ((// excluding overlongs
bytes[0] == 0xE0 &&
(0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
(0x80 <= bytes[2] && bytes[2] <= 0xBF)
) ||
(// straight 3-byte
((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
bytes[0] == 0xEE ||
bytes[0] == 0xEF) &&
(0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
(0x80 <= bytes[2] && bytes[2] <= 0xBF)
) ||
(// excluding surrogates
bytes[0] == 0xED &&
(0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
(0x80 <= bytes[2] && bytes[2] <= 0xBF)
)
) {
bytes += 3;
continue;
}
if ((// planes 1-3
bytes[0] == 0xF0 &&
(0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
(0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
(0x80 <= bytes[3] && bytes[3] <= 0xBF)
) ||
(// planes 4-15
(0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
(0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
(0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
(0x80 <= bytes[3] && bytes[3] <= 0xBF)
) ||
(// plane 16
bytes[0] == 0xF4 &&
(0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
(0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
(0x80 <= bytes[3] && bytes[3] <= 0xBF)
)
) {
bytes += 4;
continue;
}
return false;
}
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/uianchorlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
class UIAnchor :public std::enable_shared_from_this<UIAnchor>
{
public:
virtual ~UIAnchor() {} // fix clang warning

UIAnchor(Fw::AnchorEdge anchoredEdge, std::string_view hookedWidgetId, Fw::AnchorEdge hookedEdge) :
m_anchoredEdge(anchoredEdge), m_hookedEdge(hookedEdge), m_hookedWidgetId(std::string{ hookedWidgetId })
{}
Expand Down
2 changes: 1 addition & 1 deletion src/framework/ui/uiwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void UIWidget::drawSelf(DrawPoolType drawPane)
void UIWidget::drawChildren(const Rect& visibleRect, DrawPoolType drawPane)
{
// draw children
for (const auto child : m_children) { // don't use auto&
for (const auto& child : m_children) {
// render only visible children with a valid rect inside parent rect
if (!child || !child->isExplicitlyVisible() || !child->getRect().isValid() || child->getOpacity() <= Fw::MIN_ALPHA)
continue;
Expand Down
Loading

0 comments on commit 01d8f9e

Please sign in to comment.