Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,13 @@ endif()
add_subdirectory(src/protobuf)
# Src
add_subdirectory(src)

option(OTCLIENT_BUILD_TESTS "Build unit tests" ON)

if(OTCLIENT_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
log_option_enabled("Build tests")
else()
log_option_disabled("Build tests")
endif()
201 changes: 109 additions & 92 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,71 +75,12 @@ if (ANDROID OR WASM)
set(FRAMEWORK_DEFINITIONS ${FRAMEWORK_DEFINITIONS} -DOPENGL_ES=2)
endif()

# Set for use precompiled header
if(TOGGLE_PRE_COMPILED_HEADER)
# === PRECOMPILED HEADER ===
target_precompile_headers(${PROJECT_NAME} PRIVATE framework/pch.h)
message(STATUS "Use precompiled header: ON")
else()
message(STATUS "Use precompiled header: OFF")
endif(TOGGLE_PRE_COMPILED_HEADER)

# === UNITY BUILD (compile time reducer) ===
if(SPEED_UP_BUILD_UNITY)
set_target_properties(${PROJECT_NAME} PROPERTIES UNITY_BUILD ON)
log_option_enabled("Build unity for speed up compilation")
endif(SPEED_UP_BUILD_UNITY)

set(VERSION "1.0.0")

# *****************************************************************************
# Build flags
# *****************************************************************************
if (NOT MSVC)
if (CMAKE_COMPILER_IS_GNUCXX)
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-deprecated-declarations)
endif()
endif()

if(THREADS_HAVE_PTHREAD_ARG)
target_compile_options(${PROJECT_NAME} PUBLIC "-pthread")
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions(-DNDEBUG)
endif()

# *****************************************************************************
# Definitions code
# *****************************************************************************


# === ASAN ===
if(ASAN_ENABLED)
log_option_enabled("asan")

if(MSVC)
string(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
target_compile_options(${PROJECT_NAME} PUBLIC /fsanitize=address)
target_link_options(${PROJECT_NAME} PUBLIC /fsanitize=address)
else()
target_compile_options(${PROJECT_NAME} PUBLIC -fsanitize=address)
target_link_options(${PROJECT_NAME} PUBLIC -fsanitize=address)
endif()
else()
log_option_disabled("asan")
endif()


# === DEBUG LOG ===
# cmake -DDEBUG_LOG=ON ..
if(CMAKE_BUILD_TYPE MATCHES Debug)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DDEBUG_LOG=ON )
log_option_enabled("DEBUG LOG")
else()
log_option_disabled("DEBUG LOG")
endif(CMAKE_BUILD_TYPE MATCHES Debug)

# *****************************************************************************
# Sanity Check
# *****************************************************************************
Expand Down Expand Up @@ -210,12 +151,12 @@ if(NOT OPENSSL_FOUND)
find_package(GMP REQUIRED)
endif()
if(ENABLE_DISCORD_RPC AND NOT ANDROID)
find_package(DiscordRPC REQUIRED)
target_compile_definitions(${PROJECT_NAME} PRIVATE ENABLE_DISCORD_RPC=1)
log_option_enabled("Discord Rich Presence")
find_package(DiscordRPC REQUIRED)
set(OTCLIENT_ENABLE_DISCORD_RPC 1)
log_option_enabled("Discord Rich Presence")
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE ENABLE_DISCORD_RPC=0)
log_option_disabled("Discord Rich Presence")
set(OTCLIENT_ENABLE_DISCORD_RPC 0)
log_option_disabled("Discord Rich Presence")
endif()
if(TOGGLE_DIRECTX)
find_package(DirectX REQUIRED)
Expand Down Expand Up @@ -366,9 +307,6 @@ set(SOURCE_FILES
client/uiminimap.cpp
client/uiprogressrect.cpp
client/uisprite.cpp

main.cpp
androidmain.cpp
)

if (TOGGLE_FRAMEWORK_GRAPHICS)
Expand Down Expand Up @@ -446,23 +384,93 @@ if (WASM)
)
endif()

add_library(otclient_core STATIC ${SOURCE_FILES})
if(NOT MSVC)
target_link_options(otclient_core PUBLIC -flto=auto)
endif()

if(TOGGLE_PRE_COMPILED_HEADER)
# === PRECOMPILED HEADER ===
target_precompile_headers(otclient_core PRIVATE framework/pch.h)
message(STATUS "Use precompiled header: ON")
else()
message(STATUS "Use precompiled header: OFF")
endif(TOGGLE_PRE_COMPILED_HEADER)

if(SPEED_UP_BUILD_UNITY)
set_target_properties(otclient_core PROPERTIES UNITY_BUILD ON)
log_option_enabled("Build unity for speed up compilation")
endif(SPEED_UP_BUILD_UNITY)

if(ANDROID)
target_sources(${PROJECT_NAME} PRIVATE androidmain.cpp)
else()
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
endif()

target_link_libraries(${PROJECT_NAME} PRIVATE otclient_core)

# *****************************************************************************
# Build flags
# *****************************************************************************
if (NOT MSVC)
if (CMAKE_COMPILER_IS_GNUCXX)
target_compile_options(otclient_core PRIVATE -Wno-deprecated-declarations)
endif()
endif()

if(THREADS_HAVE_PTHREAD_ARG)
target_compile_options(otclient_core PUBLIC "-pthread")
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions(-DNDEBUG)
endif()

# *****************************************************************************
# Definitions code
# *****************************************************************************

# === ASAN ===
if(ASAN_ENABLED)
log_option_enabled("asan")

if(MSVC)
string(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
target_compile_options(otclient_core PUBLIC /fsanitize=address)
target_link_options(${PROJECT_NAME} PUBLIC /fsanitize=address)
else()
target_compile_options(otclient_core PUBLIC -fsanitize=address)
target_link_options(${PROJECT_NAME} PUBLIC -fsanitize=address)
endif()
else()
log_option_disabled("asan")
endif()

# === DEBUG LOG ===
# cmake -DDEBUG_LOG=ON ..
if(CMAKE_BUILD_TYPE MATCHES Debug)
target_compile_definitions(otclient_core PRIVATE -DDEBUG_LOG=ON )
log_option_enabled("DEBUG LOG")
else()
log_option_disabled("DEBUG LOG")
endif(CMAKE_BUILD_TYPE MATCHES Debug)

target_sources(${PROJECT_NAME} PRIVATE ${SOURCE_FILES})
target_link_options(${PROJECT_NAME} PUBLIC -flto=auto)
target_compile_definitions(otclient_core PRIVATE ENABLE_DISCORD_RPC=${OTCLIENT_ENABLE_DISCORD_RPC})

# *****************************************************************************
# Includes and librarys
# *****************************************************************************
if(MSVC)

# Set variables to have Windows Vista Value so httplib will build 'inet_pton'
target_compile_definitions(${PROJECT_NAME}
PRIVATE
target_compile_definitions(otclient_core
PUBLIC
NTDDI_VERSION=0x06000000
_WIN32_WINNT=0x0600
)

target_compile_options(${PROJECT_NAME} PUBLIC /MP /FS /Zf /EHsc /bigobj)
target_compile_options(otclient_core PUBLIC /MP /FS /Zf /EHsc /bigobj)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
Expand All @@ -482,15 +490,24 @@ if(MSVC)
if(ANDROID)
find_package(Vorbis CONFIG REQUIRED)
endif()
set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
foreach(msvc_target IN ITEMS otclient_core ${PROJECT_NAME})
if(TARGET ${msvc_target})
set_property(TARGET ${msvc_target} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endforeach()
set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "")
else()
log_option_disabled("STATIC_LIBRARY")
set(VCPKG_TARGET_TRIPLET "x64-windows" CACHE STRING "")
foreach(msvc_target IN ITEMS otclient_core ${PROJECT_NAME})
if(TARGET ${msvc_target})
set_property(TARGET ${msvc_target} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
endforeach()
endif()

target_include_directories(${PROJECT_NAME}
PRIVATE
target_include_directories(otclient_core
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
${LUAJIT_INCLUDE_DIR}
Expand All @@ -503,8 +520,8 @@ if(MSVC)
${NLOHMANN_JSON_INCLUDE_DIR}
${CPPCODEC_INCLUDE_DIRS}
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
target_link_libraries(otclient_core
PUBLIC
${LUAJIT_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
${PHYSFS_LIBRARY}
Expand Down Expand Up @@ -533,8 +550,8 @@ if(MSVC)
fmt::fmt-header-only
)
elseif(ANDROID)
target_include_directories(${PROJECT_NAME}
PRIVATE
target_include_directories(otclient_core
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
${LUAJIT_INCLUDE_DIR}
Expand All @@ -549,8 +566,8 @@ elseif(ANDROID)
${MINIZIP_INCLUDE_DIR}
${CPPCODEC_INCLUDE_DIRS}
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
target_link_libraries(otclient_core
PUBLIC
${LUA_LIBRARY}
${LUAJIT_LIBRARY}
${PHYSFS_LIBRARY}
Expand Down Expand Up @@ -583,8 +600,8 @@ elseif(ANDROID)
)

elseif(WASM)
target_include_directories(${PROJECT_NAME}
PRIVATE
target_include_directories(otclient_core
PUBLIC
${CMAKE_SOURCE_DIR}/src
${CMAKE_THREAD_LIBS_INIT}
${Protobuf_INCLUDE_DIRS}
Expand All @@ -597,8 +614,8 @@ elseif(WASM)
${BROWSER_INCLUDE_DIR}
${CPPCODEC_INCLUDE_DIRS}
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
target_link_libraries(otclient_core
PUBLIC
${LUA_LIBRARY}
${PHYSFS_LIBRARY}
${ZLIB_LIBRARY}
Expand Down Expand Up @@ -641,7 +658,7 @@ elseif(WASM)
get_property(linkflags TARGET ${PROJECT_NAME} PROPERTY LINK_FLAGS)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${PROJECT_NAME}
target_compile_options(otclient_core
PRIVATE
-Wall -Wextra -Wpedantic
)
Expand All @@ -667,8 +684,8 @@ elseif(WASM)
set(VCPKG_TARGET_TRIPLET "wasm32-emscripten" CACHE STRING "")

else() # Linux
target_include_directories(${PROJECT_NAME}
PRIVATE
target_include_directories(otclient_core
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
${LUAJIT_INCLUDE_DIR}
Expand All @@ -682,8 +699,8 @@ else() # Linux
${OPENSSL_INCLUDE_DIR}
${CPPCODEC_INCLUDE_DIRS}
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
target_link_libraries(otclient_core
PUBLIC
${LUAJIT_LIBRARY}
${PHYSFS_LIBRARY}
${ZLIB_LIBRARY}
Expand Down Expand Up @@ -722,15 +739,15 @@ else() # Linux
)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${PROJECT_NAME}
target_compile_options(otclient_core
PRIVATE
-Wall -Wextra -Wpedantic
)
endif()

endif()
if(ENABLE_DISCORD_RPC AND NOT ANDROID)
target_link_libraries(${PROJECT_NAME} PRIVATE ${DISCORDRPC_LIBRARY})
target_link_libraries(otclient_core PUBLIC ${DISCORDRPC_LIBRARY})
endif()

# *****************************************************************************
Expand Down
11 changes: 8 additions & 3 deletions src/client/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@
bool isWalking() { return m_walking; }

bool isRemoved() { return m_removed; }
bool isRemoved() const { return m_removed; }
const Position& getOldPosition() const { return m_oldPosition; }
bool isInvisible() { return m_outfit.isEffect() && m_outfit.getAuxId() == 13; }
bool isDead() { return m_healthPercent <= 0; }
bool isFullHealth() { return m_healthPercent == 100; }
bool canBeSeen() { return !isInvisible() || isPlayer(); }
bool isCreature() override { return true; }
bool isCreature() const override { return true; }
bool isCovered() { return m_isCovered; }

void setCovered(bool covered);
Expand Down Expand Up @@ -203,7 +205,7 @@
}

void setVocation(uint8_t vocation) { m_vocation = vocation; }
const uint8_t getVocation() { return m_vocation; }

Check warning on line 208 in src/client/creature.h

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

type qualifiers ignored on function return type [-Wignored-qualifiers]

protected:
virtual void terminateWalk();
Expand All @@ -211,6 +213,9 @@
void updateWalkOffset(uint8_t totalPixelsWalked);
void updateWalk();

void setOldPositionSilently(const Position& pos) { m_oldPosition = pos; }
void setRemovedSilently(const bool removed) { m_removed = removed; }

ThingType* getThingType() const override;
ThingType* getMountThingType() const;

Expand Down Expand Up @@ -362,12 +367,12 @@
class Npc final : public Creature
{
public:
bool isNpc() override { return true; }
bool isNpc() const override { return true; }
};

// @bindclass
class Monster final : public Creature
{
public:
bool isMonster() override { return true; }
bool isMonster() const override { return true; }
};
2 changes: 1 addition & 1 deletion src/client/effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Effect final : public Thing
void setId(uint32_t id) override;
void setPosition(const Position& position, uint8_t stackPos = 0) override;

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

EffectPtr asEffect() { return static_self_cast<Effect>(); }
Expand Down
Loading
Loading