mirror of
https://github.com/edubart/otclient.git
synced 2025-11-30 23:26:51 +01:00
Platform fixes and rework ping
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
bool shouldProcessNextFrame();
|
||||
void processNextFrame();
|
||||
void update();
|
||||
bool update();
|
||||
void setMaxFps(int maxFps);
|
||||
bool isFpsLimitActive() { return m_maxFps != 0; }
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#define CONNECTION_H
|
||||
|
||||
#include "declarations.h"
|
||||
#include <boost/asio.hpp>
|
||||
#include <framework/luaengine/luaobject.h>
|
||||
#include <framework/core/timer.h>
|
||||
#include <framework/core/declarations.h>
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <framework/global.h>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
namespace asio = boost::asio;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#define UITEXTEDIT_H
|
||||
|
||||
#include "uiwidget.h"
|
||||
#include <boost/concept_check.hpp>
|
||||
|
||||
// @bindclass
|
||||
class UITextEdit : public UIWidget
|
||||
|
||||
Reference in New Issue
Block a user