diff --git a/data/styles/10-labels.otui b/data/styles/10-labels.otui index f422b8c1..f257494e 100644 --- a/data/styles/10-labels.otui +++ b/data/styles/10-labels.otui @@ -21,45 +21,3 @@ MenuLabel < Label GameLabel < UILabel font: verdana-11px-antialised color: #bbbbbb - -FrameCounterLabel < Label - font: verdana-11px-rounded - @onSetup: | - self.updateEvent = cycleEvent(function() - local text = 'FPS: ' .. g_app.getBackgroundPaneFps() - self:setText(text) - end, 1000) - @onDestroy: self.updateEvent:cancel() - -PingLabel < Label - font: verdana-11px-rounded - @onSetup: | - self.updateEvent = cycleEvent(function() - if g_game.isOnline() and modules.client_options.getOption('showPing') then - local ping = -1 - if g_game.getFeature(GameClientPing) or g_game.getFeature(GameExtendedClientPing) then - ping = g_game.getPing() - else - ping = g_game.getLocalPlayer():getWalkPing() - end - local text = 'Ping: ' - if ping < 0 then - text = text .. "??" - self:setColor('yellow') - else - text = text .. ping .. ' ms' - if ping >= 500 then - self:setColor('red') - elseif ping >= 250 then - self:setColor('yellow') - else - self:setColor('green') - end - end - self:setText(text) - self:show() - else - self:hide() - end - end, 1000) - @onDestroy: self.updateEvent:cancel() diff --git a/data/styles/20-topmenu.otui b/data/styles/20-topmenu.otui index 5c6e24c7..ecf47262 100644 --- a/data/styles/20-topmenu.otui +++ b/data/styles/20-topmenu.otui @@ -46,7 +46,11 @@ TopMenuPanel < Panel image-repeated: true focusable: false -TopMenuFrameCounterLabel < FrameCounterLabel +TopMenuFrameCounterLabel < Label + font: verdana-11px-rounded color: white margin-top: 4 margin-left: 5 + +TopMenuPingLabel < Label + font: verdana-11px-rounded diff --git a/modules/client_entergame/entergame.lua b/modules/client_entergame/entergame.lua index e8cac33f..fced9c85 100644 --- a/modules/client_entergame/entergame.lua +++ b/modules/client_entergame/entergame.lua @@ -145,10 +145,10 @@ function EnterGame.firstShow() local host = g_settings.get('host') local autologin = g_settings.getBoolean('autologin') if #host > 0 and #password > 0 and #account > 0 and autologin then - connect(g_app, { onRun = function() + addEvent(function() if not g_settings.getBoolean('autologin') then return end EnterGame.doLogin() - end}) + end) end end diff --git a/modules/client_entergame/waitinglist.otui b/modules/client_entergame/waitinglist.otui index 185a7584..c7b86a61 100644 --- a/modules/client_entergame/waitinglist.otui +++ b/modules/client_entergame/waitinglist.otui @@ -1,7 +1,7 @@ MainWindow id: waitingWindow !text: tr('Waiting List') - size: 260 160 + size: 260 180 @onEscape: CharacterList.cancelWait() Label diff --git a/modules/client_options/options.lua b/modules/client_options/options.lua index ab3a0545..4e7c7770 100644 --- a/modules/client_options/options.lua +++ b/modules/client_options/options.lua @@ -179,15 +179,9 @@ function setOption(key, value) if key == 'vsync' then g_window.setVerticalSync(value) elseif key == 'showFps' then - addEvent(function() - local frameCounter = rootWidget:recursiveGetChildById('frameCounter') - if frameCounter then frameCounter:setVisible(value) end - end) + modules.client_topmenu.setFpsVisible(value) elseif key == 'showPing' then - addEvent(function() - local ping = rootWidget:recursiveGetChildById('pingLabel') - if ping then ping:setVisible(value) end - end) + modules.client_topmenu.setPingVisible(value) elseif key == 'fullscreen' then g_window.setFullscreen(value) panel = graphicsPanel diff --git a/modules/client_terminal/commands.lua b/modules/client_terminal/commands.lua index 678e9782..5bd5b4cc 100644 --- a/modules/client_terminal/commands.lua +++ b/modules/client_terminal/commands.lua @@ -92,3 +92,8 @@ function createDebugUIItem(id) uiitem:setItemId(id) uiitem:show() end + +function debugPings() + g_game.setPingDelay(0) + connect(g_game, { onPingBack = function(ping) print(g_game.getWorldName() .. ' => ' .. ping .. ' ms') end }) +end diff --git a/modules/client_topmenu/topmenu.lua b/modules/client_topmenu/topmenu.lua index aeb75ba3..4f198cff 100644 --- a/modules/client_topmenu/topmenu.lua +++ b/modules/client_topmenu/topmenu.lua @@ -37,8 +37,10 @@ end -- public functions function init() - connect(g_game, { onGameStart = showGameButtons, - onGameEnd = hideGameButtons }) + connect(g_game, { onGameStart = online, + onGameEnd = offline, + onPingBack = updatePing }) + connect(g_app, { onFps = updateFps }) topMenu = g_ui.displayUI('topmenu') @@ -46,20 +48,75 @@ function init() rightButtonsPanel = topMenu:getChildById('rightButtonsPanel') leftGameButtonsPanel = topMenu:getChildById('leftGameButtonsPanel') rightGameButtonsPanel = topMenu:getChildById('rightGameButtonsPanel') + pingLabel = topMenu:getChildById('pingLabel') + fpsLabel = topMenu:getChildById('fpsLabel') if g_game.isOnline() then - leftGameButtonsPanel:show() - rightGameButtonsPanel:show() + online() end end function terminate() - disconnect(g_game, { onGameStart = showGameButtons, - onGameEnd = hideGameButtons }) + disconnect(g_game, { onGameStart = online, + onGameEnd = offline, + onPingBack = updatePing }) + disconnect(g_app, { onFps = updateFps }) topMenu:destroy() end +function online() + showGameButtons() + + if modules.client_options.getOption('showFps') then + pingLabel:show() + end +end + +function offline() + hideGameButtons() + pingLabel:hide() +end + +function updateFps(fps) + text = 'FPS: ' .. fps + fpsLabel:setText(text) +end + +function updatePing(ping) + local ping = -1 + if g_game.getFeature(GameClientPing) or g_game.getFeature(GameExtendedClientPing) then + ping = g_game.getPing() + else + ping = g_game.getLocalPlayer():getWalkPing() + end + local text = 'Ping: ' + local color + if ping < 0 then + text = text .. "??" + color = 'yellow' + else + text = text .. ping .. ' ms' + if ping >= 500 then + color = 'red' + elseif ping >= 250 then + color = 'yellow' + else + color = 'green' + end + end + pingLabel:setColor(color) + pingLabel:setText(text) +end + +function setPingVisible(enable) + pingLabel:setVisible(enable) +end + +function setFpsVisible(enable) + fpsLabel:setVisible(enable) +end + function addLeftButton(id, description, icon, callback, front) return addButton(id, description, icon, callback, leftButtonsPanel, false, front) end @@ -92,16 +149,16 @@ function addRightGameToggleButton(id, description, icon, callback, front) return addButton(id, description, icon, callback, rightGameButtonsPanel, true, front) end -function hideGameButtons() - leftGameButtonsPanel:hide() - rightGameButtonsPanel:hide() -end - function showGameButtons() leftGameButtonsPanel:show() rightGameButtonsPanel:show() end +function hideGameButtons() + leftGameButtonsPanel:hide() + rightGameButtonsPanel:hide() +end + function getButton(id) return topMenu:recursiveGetChildById(id) end diff --git a/modules/client_topmenu/topmenu.otui b/modules/client_topmenu/topmenu.otui index 9a12b89e..0a7d2276 100644 --- a/modules/client_topmenu/topmenu.otui +++ b/modules/client_topmenu/topmenu.otui @@ -18,17 +18,17 @@ TopMenuPanel visible: false TopMenuFrameCounterLabel - id: frameCounter + id: fpsLabel text-auto-resize: true anchors.top: parent.top anchors.left: leftGameButtonsPanel.right - PingLabel + TopMenuPingLabel color: white id: pingLabel text-auto-resize: true - anchors.top: frameCounter.bottom - anchors.left: frameCounter.left + anchors.top: fpsLabel.bottom + anchors.left: fpsLabel.left TopMenuButtonsPanel id: rightButtonsPanel diff --git a/modules/gamelib/ui/uiminimap.lua b/modules/gamelib/ui/uiminimap.lua index b57e7146..5f99797d 100644 --- a/modules/gamelib/ui/uiminimap.lua +++ b/modules/gamelib/ui/uiminimap.lua @@ -113,6 +113,7 @@ function UIMinimap:addFlag(pos, icon, description) flag:setIcon('/images/game/minimap/flag' .. icon) flag:setTooltip(description) flag.onMouseRelease = onFlagMouseRelease + flag.onDestroy = function() table.removevalue(self.flags, flag) end table.insert(self.flags, flag) self:centerInPosition(flag, pos) end @@ -162,7 +163,6 @@ function UIMinimap:removeFlag(pos, icon, description) local flag = self:getFlag(pos) if flag then flag:destroy() - table.removevalue(self.flags, flag) end end diff --git a/src/client/game.cpp b/src/client/game.cpp index 997e66cb..3e5b8486 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -47,6 +47,7 @@ Game::Game() m_serverBeat = 50; m_seq = 0; m_ping = -1; + m_pingDelay = 1000; m_canReportBugs = false; m_fightMode = Otc::FightBalanced; m_chaseMode = Otc::DontChase; @@ -79,6 +80,8 @@ void Game::resetGameStates() m_followingCreature = nullptr; m_attackingCreature = nullptr; m_localPlayer = nullptr; + m_pingSent = 0; + m_pingReceived = 0; for(auto& it : m_containers) { const ContainerPtr& container = it.second; @@ -176,14 +179,9 @@ void Game::processGameStart() disableBotCall(); if(g_game.getFeature(Otc::GameClientPing) || g_game.getFeature(Otc::GameExtendedClientPing)) { - m_protocolGame->sendPing(); - m_pingEvent = g_dispatcher.cycleEvent([this] { - if(m_protocolGame && m_protocolGame->isConnected()) { - enableBotCall(); - m_protocolGame->sendPing(); - disableBotCall(); - } - }, 2000); + m_pingEvent = g_dispatcher.scheduleEvent([this] { + g_game.ping(); + }, m_pingDelay); } } @@ -224,10 +222,20 @@ void Game::processPing() disableBotCall(); } -void Game::processPingBack(int elapsed) +void Game::processPingBack() { - m_ping = elapsed; - g_lua.callGlobalField("g_game", "onPingBack", elapsed); + m_pingReceived++; + + if(m_pingReceived == m_pingSent) + m_ping = m_pingTimer.elapsed_millis(); + else + g_logger.error("got an invalid ping from server"); + + g_lua.callGlobalField("g_game", "onPingBack", m_ping); + + m_pingEvent = g_dispatcher.scheduleEvent([this] { + g_game.ping(); + }, m_pingDelay); } void Game::processTextMessage(Otc::MessageMode mode, const std::string& text) @@ -1252,9 +1260,14 @@ void Game::ping() if(!m_protocolGame || !m_protocolGame->isConnected()) return; + if(m_pingReceived != m_pingSent) + return; + m_denyBotCall = false; m_protocolGame->sendPing(); m_denyBotCall = true; + m_pingSent++; + m_pingTimer.restart(); } void Game::changeMapAwareRange(int xrange, int yrange) diff --git a/src/client/game.h b/src/client/game.h index 453f6f71..9590a8db 100644 --- a/src/client/game.h +++ b/src/client/game.h @@ -54,7 +54,7 @@ protected: void processConnectionError(const boost::system::error_code& error); void processDisconnect(); void processPing(); - void processPingBack(int elapsed); + void processPingBack(); void processUpdateNeeded(const std::string& signature); void processLoginError(const std::string& error); @@ -252,6 +252,7 @@ public: //void reportRuleViolation2(); void ping(); + void setPingDelay(int delay) { m_pingDelay = delay; } // otclient only void changeMapAwareRange(int xrange, int yrange); @@ -280,7 +281,7 @@ public: bool isAttacking() { return !!m_attackingCreature; } bool isFollowing() { return !!m_followingCreature; } - int getPing() { return m_ping; } + int getPing() { return m_ping >= 0 ? std::max(m_ping, m_pingTimer.elapsed_millis()) : -1; } ContainerPtr getContainer(int index) { return m_containers[index]; } std::map getContainers() { return m_containers; } std::map getVips() { return m_vips; } @@ -320,8 +321,12 @@ private: bool m_denyBotCall; bool m_dead; int m_serverBeat; - int m_ping; + ticks_t m_ping; + uint m_pingSent; + uint m_pingReceived; + stdext::timer m_pingTimer; uint m_seq; + int m_pingDelay; Otc::FightModes m_fightMode; Otc::ChaseModes m_chaseMode; Otc::Direction m_lastWalkDir; diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 5c9a7ee2..07bbf520 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -77,7 +77,7 @@ bool LocalPlayer::canWalk(Otc::Direction direction) return false; // prewalk has a timeout, because for some reason that I don't know yet the server sometimes doesn't answer the prewalk - bool prewalkTimeouted = m_walking && m_preWalking && m_walkTimer.ticksElapsed() >= getStepDuration() + PREWALK_TIMEOUT; + bool prewalkTimeouted = m_walking && m_preWalking && m_walkTimer.ticksElapsed() >= getStepDuration() + 5*PREWALK_TIMEOUT; // avoid doing more walks than wanted when receiving a lot of walks from server if(!m_lastPrewalkDone && m_preWalking && !prewalkTimeouted) @@ -127,8 +127,9 @@ void LocalPlayer::preWalk(Otc::Direction direction) Position newPos = m_position.translatedToDirection(direction); // avoid reanimating prewalks - if(m_preWalking && m_lastPrewalkDestination == newPos) + if(m_preWalking && m_lastPrewalkDestination == newPos) { return; + } m_waitingWalkPong = false; if(m_walkPingTimer.ticksElapsed() > getStepDuration() && m_idleTimer.ticksElapsed() > getStepDuration()*2) { @@ -157,6 +158,7 @@ void LocalPlayer::cancelWalk(Otc::Direction direction) m_waitingWalkPong = false; m_walkPingTimer.restart(); m_idleTimer.restart(); + lockWalk(); if(m_autoWalkDestination.isValid()) { g_game.stop(); diff --git a/src/client/luafunctions.cpp b/src/client/luafunctions.cpp index 9e38f002..1e8b0c49 100644 --- a/src/client/luafunctions.cpp +++ b/src/client/luafunctions.cpp @@ -219,6 +219,7 @@ void Client::registerLuaFunctions() g_lua.bindSingletonFunction("g_game", "mount", &Game::mount, &g_game); g_lua.bindSingletonFunction("g_game", "requestItemInfo", &Game::requestItemInfo, &g_game); g_lua.bindSingletonFunction("g_game", "ping", &Game::ping, &g_game); + g_lua.bindSingletonFunction("g_game", "setPingDelay", &Game::setPingDelay, &g_game); g_lua.bindSingletonFunction("g_game", "changeMapAwareRange", &Game::changeMapAwareRange, &g_game); g_lua.bindSingletonFunction("g_game", "canPerformGameAction", &Game::canPerformGameAction, &g_game); g_lua.bindSingletonFunction("g_game", "canReportBugs", &Game::canReportBugs, &g_game); diff --git a/src/client/mapview.cpp b/src/client/mapview.cpp index 7c80e2eb..10d5d1b2 100644 --- a/src/client/mapview.cpp +++ b/src/client/mapview.cpp @@ -37,7 +37,6 @@ #include #include #include -#include enum { diff --git a/src/client/protocolgame.h b/src/client/protocolgame.h index 850f12aa..99c5973a 100644 --- a/src/client/protocolgame.h +++ b/src/client/protocolgame.h @@ -235,7 +235,6 @@ private: std::string m_accountName; std::string m_accountPassword; std::string m_characterName; - stdext::timer m_pingTimer; LocalPlayerPtr m_localPlayer; }; diff --git a/src/client/protocolgameparse.cpp b/src/client/protocolgameparse.cpp index b6950cdd..f2b4ca5a 100644 --- a/src/client/protocolgameparse.cpp +++ b/src/client/protocolgameparse.cpp @@ -430,7 +430,7 @@ void ProtocolGame::parsePing(const InputMessagePtr& msg) void ProtocolGame::parsePingBack(const InputMessagePtr& msg) { - g_game.processPingBack(m_pingTimer.elapsed_millis()); + g_game.processPingBack(); } void ProtocolGame::parseChallenge(const InputMessagePtr& msg) diff --git a/src/client/protocolgamesend.cpp b/src/client/protocolgamesend.cpp index 388b2143..5ae33942 100644 --- a/src/client/protocolgamesend.cpp +++ b/src/client/protocolgamesend.cpp @@ -129,7 +129,6 @@ void ProtocolGame::sendPing() msg->addU8(Proto::ClientPing); Protocol::send(msg); } - m_pingTimer.restart(); } void ProtocolGame::sendPingBack() diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 4d44e646..1e395871 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -137,6 +137,7 @@ if(NOT APPLE) option(CRASH_HANDLER "Generate crash reports" ON) option(USE_STATIC_LIBS "Don't use shared libraries (dlls)" ON) option(USE_LIBCPP "Use the new libc++ library instead of stdc++" OFF) + option(USE_LTO "Use link time optimizations" OFF) else() set(CRASH_HANDLER OFF) set(USE_STATIC_LIBS OFF) @@ -162,10 +163,18 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNS_FLAGS} ${ARCH_ set(CMAKE_CXX_FLAGS_COMPILESPEED "-O0") set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -fno-omit-frame-pointer") -set(CMAKE_CXX_FLAGS_RELEASE "-O2") -set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os") +set(CMAKE_CXX_FLAGS_RELEASE "-Os") set(CMAKE_CXX_FLAGS_PERFORMANCE "-Ofast -mmmx -msse -msse2") +if(USE_LTO) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fwhole-program -flto") + if(WIN32) + set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,-O1,--gc-sections,--sort-common,--relax") + else() + set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,-O1,--gc-sections,--sort-common,--relax,-z,relro") + endif() +endif() + # process options if(USE_STATIC_LIBS) if(NOT APPLE) @@ -231,8 +240,8 @@ else() if(NOT CMAKE_BUILD_TYPE STREQUAL "CompileSpeed") set(framework_DEFINITIONS ${framework_DEFINITIONS} -DNDEBUG) # NDEBUG disable asserts endif() - set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,-s") # strip all debug information if(NOT APPLE) + set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,-s") # strip all debug information set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,--as-needed") # only link needed libraries endif() endif() diff --git a/src/framework/core/adaptativeframecounter.cpp b/src/framework/core/adaptativeframecounter.cpp index 005bae48..aa227250 100644 --- a/src/framework/core/adaptativeframecounter.cpp +++ b/src/framework/core/adaptativeframecounter.cpp @@ -60,7 +60,7 @@ void AdaptativeFrameCounter::processNextFrame() m_lastFrame = now ; } -void AdaptativeFrameCounter::update() +bool AdaptativeFrameCounter::update() { ticks_t now = g_clock.micros(); ticks_t delta = now - m_lastPartialFpsUpdate; @@ -82,7 +82,9 @@ void AdaptativeFrameCounter::update() m_frameDelaySum = 0; //dump << stdext::format("FPS => %d Partial FPS => %d Frame Delay Hit => %.2f%%", m_lastFps, (int)m_partialFps, getFrameDelayHit()); + return true; } + return false; } void AdaptativeFrameCounter::setMaxFps(int maxFps) diff --git a/src/framework/core/adaptativeframecounter.h b/src/framework/core/adaptativeframecounter.h index eab231a2..43a0dbab 100644 --- a/src/framework/core/adaptativeframecounter.h +++ b/src/framework/core/adaptativeframecounter.h @@ -43,7 +43,7 @@ public: bool shouldProcessNextFrame(); void processNextFrame(); - void update(); + bool update(); void setMaxFps(int maxFps); bool isFpsLimitActive() { return m_maxFps != 0; } diff --git a/src/framework/core/graphicalapplication.cpp b/src/framework/core/graphicalapplication.cpp index 5367a80c..c4bd1bc9 100644 --- a/src/framework/core/graphicalapplication.cpp +++ b/src/framework/core/graphicalapplication.cpp @@ -184,7 +184,8 @@ void GraphicalApplication::run() // only update the current time once per frame to gain performance g_clock.update(); - m_backgroundFrameCounter.update(); + if(m_backgroundFrameCounter.update()) + g_lua.callGlobalField("g_app", "onFps", m_backgroundFrameCounter.getLastFps()); m_foregroundFrameCounter.update(); int sleepMicros = m_backgroundFrameCounter.getMaximumSleepMicros(); diff --git a/src/framework/core/resourcemanager.cpp b/src/framework/core/resourcemanager.cpp index e0f1f56c..89a0cb5f 100644 --- a/src/framework/core/resourcemanager.cpp +++ b/src/framework/core/resourcemanager.cpp @@ -45,10 +45,11 @@ void ResourceManager::terminate() bool ResourceManager::discoverWorkDir(const std::string& existentFile) { // search for modules directory - std::string possiblePaths[] = { g_resources.getCurrentDir(), + std::string possiblePaths[] = { g_platform.getCurrentDir(), g_resources.getBaseDir(), g_resources.getBaseDir() + "../", g_resources.getBaseDir() + "../share/" + g_app.getCompactName() + "/" }; + bool found = false; for(const std::string& dir : possiblePaths) { if(!PHYSFS_addToSearchPath(dir.c_str(), 0)) @@ -296,11 +297,6 @@ std::string ResourceManager::getRealDir(const std::string& path) return dir; } -std::string ResourceManager::getCurrentDir() -{ - return g_platform.getCurrentDir(); -} - std::string ResourceManager::getBaseDir() { return PHYSFS_getBaseDir(); diff --git a/src/framework/core/resourcemanager.h b/src/framework/core/resourcemanager.h index 77a61a20..e698767e 100644 --- a/src/framework/core/resourcemanager.h +++ b/src/framework/core/resourcemanager.h @@ -64,7 +64,6 @@ public: std::string resolvePath(const std::string& path); std::string getRealDir(const std::string& path); - std::string getCurrentDir(); std::string getBaseDir(); std::string getUserDir(); std::string getWriteDir() { return m_writeDir; } diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index eebcfab7..ed14348c 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -84,6 +84,7 @@ void Application::registerLuaFunctions() g_lua.bindSingletonFunction("g_platform", "isProcessRunning", &Platform::isProcessRunning, &g_platform); g_lua.bindSingletonFunction("g_platform", "copyFile", &Platform::copyFile, &g_platform); g_lua.bindSingletonFunction("g_platform", "fileExists", &Platform::fileExists, &g_platform); + g_lua.bindSingletonFunction("g_platform", "removeFile", &Platform::removeFile, &g_platform); g_lua.bindSingletonFunction("g_platform", "killProcess", &Platform::killProcess, &g_platform); g_lua.bindSingletonFunction("g_platform", "getTempPath", &Platform::getTempPath, &g_platform); g_lua.bindSingletonFunction("g_platform", "openUrl", &Platform::openUrl, &g_platform); diff --git a/src/framework/net/connection.h b/src/framework/net/connection.h index 78075178..ebfddc63 100644 --- a/src/framework/net/connection.h +++ b/src/framework/net/connection.h @@ -24,7 +24,6 @@ #define CONNECTION_H #include "declarations.h" -#include #include #include #include diff --git a/src/framework/net/declarations.h b/src/framework/net/declarations.h index ab4a7d5e..cd2536d6 100644 --- a/src/framework/net/declarations.h +++ b/src/framework/net/declarations.h @@ -25,6 +25,7 @@ #include #include +#include namespace asio = boost::asio; diff --git a/src/framework/platform/platform.h b/src/framework/platform/platform.h index 992f6fd4..9332bf08 100644 --- a/src/framework/platform/platform.h +++ b/src/framework/platform/platform.h @@ -37,7 +37,8 @@ public: std::string getTempPath(); std::string getCurrentDir(); bool copyFile(std::string from, std::string to); - bool fileExists(const std::string& file); + bool fileExists(std::string file); + bool removeFile(std::string file); void openUrl(std::string url); std::string getCPUName(); double getTotalSystemMemory(); diff --git a/src/framework/platform/unixplatform.cpp b/src/framework/platform/unixplatform.cpp index 2d7dd513..8e190184 100644 --- a/src/framework/platform/unixplatform.cpp +++ b/src/framework/platform/unixplatform.cpp @@ -83,8 +83,10 @@ std::string Platform::getCurrentDir() { std::string res; char cwd[2048]; - if(getcwd(cwd, sizeof(cwd)) != NULL) + if(getcwd(cwd, sizeof(cwd)) != NULL) { res = cwd; + res += "/"; + } return res; } @@ -93,12 +95,19 @@ bool Platform::copyFile(std::string from, std::string to) return system(stdext::format("/bin/cp '%s' '%s'", from, to).c_str()) == 0; } -bool Platform::fileExists(const std::string& file) +bool Platform::fileExists(std::string file) { struct stat buffer; return (stat(file.c_str(), &buffer) == 0); } +bool Platform::removeFile(std::string file) +{ + if(unlink(file.c_str()) == 0) + return true; + return false; +} + void Platform::openUrl(std::string url) { if(url.find("http://") == std::string::npos) diff --git a/src/framework/platform/win32platform.cpp b/src/framework/platform/win32platform.cpp index f58daaf2..5c6a7a18 100644 --- a/src/framework/platform/win32platform.cpp +++ b/src/framework/platform/win32platform.cpp @@ -95,11 +95,13 @@ std::string Platform::getCurrentDir() GetCurrentDirectoryW(MAX_PATH, path); ret = stdext::utf16_to_utf8(path); boost::replace_all(ret, "\\", "/"); + ret += "/"; return ret; } -bool Platform::fileExists(const std::string& file) +bool Platform::fileExists(std::string file) { + boost::replace_all(file, "/", "\\"); std::wstring wfile = stdext::utf8_to_utf16(file); DWORD dwAttrib = GetFileAttributesW(wfile.c_str()); return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); @@ -114,6 +116,14 @@ bool Platform::copyFile(std::string from, std::string to) return true; } +bool Platform::removeFile(std::string file) +{ + boost::replace_all(file, "/", "\\"); + if(DeleteFileW(stdext::utf8_to_utf16(file).c_str()) == 0) + return false; + return true; +} + void Platform::openUrl(std::string url) { if(url.find("http://") == std::string::npos) diff --git a/src/framework/platform/win32window.cpp b/src/framework/platform/win32window.cpp index 5bf5519a..f712e058 100644 --- a/src/framework/platform/win32window.cpp +++ b/src/framework/platform/win32window.cpp @@ -590,8 +590,12 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar } case WM_ACTIVATE: { m_focused = !(wParam == WA_INACTIVE); - if(!m_focused) - releaseAllKeys(); + releaseAllKeys(); + break; + } + case WM_SETFOCUS: + case WM_KILLFOCUS: { + releaseAllKeys(); break; } case WM_CHAR: { diff --git a/src/framework/ui/uitextedit.h b/src/framework/ui/uitextedit.h index f9fdbd24..de253d78 100644 --- a/src/framework/ui/uitextedit.h +++ b/src/framework/ui/uitextedit.h @@ -24,7 +24,6 @@ #define UITEXTEDIT_H #include "uiwidget.h" -#include // @bindclass class UITextEdit : public UIWidget