Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
MillhioreBT committed Apr 4, 2024
1 parent 9ee5529 commit 15ea75c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 75 deletions.
51 changes: 37 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
cmake_minimum_required(VERSION 3.16)

set(CMAKE_CXX_COMPILER g++-10)

set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_BUILD_TYPE Release)

# Ensure to pick up the default triplet from the environment if any. This helps
# driving the vcpkg triplet in the same way either when starting vcpkg directly,
# or when letting CMake start vcpkg at configure/generate time.
# Note: this logic must happen before PROJECT command.
if (DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "The vcpkg triplet")
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "The vcpkg triplet")
endif()

project(tfs CXX)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

if (NOT WIN32)
add_compile_options(-Wall -Wextra -Wnon-virtual-dtor -pedantic -Werror -pipe -fvisibility=hidden)
add_compile_options(-Wall -Wextra -Wnon-virtual-dtor -Wold-style-cast -pedantic -Werror -pipe -fvisibility=hidden)
endif ()

if (CMAKE_COMPILER_IS_GNUCXX)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-fno-strict-aliasing)
endif ()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options(-Wimplicit-fallthrough -Wmove)
endif ()

# Find packages.
find_package(cryptopp CONFIG)
if (CryptoPP_FOUND) # vcpkg-provided cmake package called CryptoPP
Expand All @@ -50,7 +51,23 @@ endif ()

find_package(Threads REQUIRED)
find_package(PugiXML CONFIG REQUIRED)
find_package(Lua54 REQUIRED)

# Selects LuaJIT if user defines or auto-detected
if (DEFINED USE_LUAJIT AND NOT USE_LUAJIT)
set(FORCE_LUAJIT ${USE_LUAJIT})
else ()
find_package(LuaJIT)
set(FORCE_LUAJIT ${LuaJIT_FOUND})
endif ()
option(USE_LUAJIT "Use LuaJIT" ${FORCE_LUAJIT})

if (NOT FORCE_LUAJIT)
find_package(Lua REQUIRED)
endif ()

if (APPLE)
find_package(Iconv REQUIRED)
endif()

find_package(Boost 1.66.0 REQUIRED COMPONENTS system iostreams)

Expand Down Expand Up @@ -88,14 +105,20 @@ endif ()
# the source code for watching a git repository.
option(SKIP_GIT "Skip checking for git updates" OFF)
if(NOT SKIP_GIT)
set(PRE_CONFIGURE_FILE "cmake/gitmetadata.h.in")
set(POST_CONFIGURE_FILE "${CMAKE_CURRENT_BINARY_DIR}/gitmetadata.h")
include(git_watcher)
if(Git_FOUND)
add_dependencies(tfs check_git)
target_include_directories(tfs PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
endif()
set(PRE_CONFIGURE_FILE "cmake/gitmetadata.h.in")
set(POST_CONFIGURE_FILE "${CMAKE_CURRENT_BINARY_DIR}/gitmetadata.h")
include(git_watcher)
if(Git_FOUND)
add_dependencies(tfs check_git)
target_include_directories(tfs PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
endif()
endif()
### END Git Version ###

# Option to disable unity builds
option(ENABLE_UNITY_BUILD "Enable unity build" ON)
if(ENABLE_UNITY_BUILD)
set_target_properties(tfslib PROPERTIES UNITY_BUILD ON)
endif()

target_precompile_headers(tfs PUBLIC src/otpch.h)
30 changes: 14 additions & 16 deletions cmake/FindLua54.cmake → cmake/FindLuaJIT.cmake
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
# Locate Lua library
# Locate LuaJIT library
# This module defines
# LUA_FOUND, if false, do not try to link to Lua
# LUAJIT_FOUND, if false, do not try to link to Lua
# LUA_LIBRARIES
# LUA_INCLUDE_DIR, where to find lua.h
# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
# LUAJIT_VERSION_STRING, the version of Lua found (since CMake 2.8.8)

## Copied from default CMake FindLua54.cmake
## Copied from default CMake FindLua51.cmake

find_path(LUA_INCLUDE_DIR lua.h
find_path(LUA_INCLUDE_DIR luajit.h
HINTS
ENV LUA_DIR
PATH_SUFFIXES usr/include/lua5.4 include/lua5.4 include lua5.4
PATH_SUFFIXES include/luajit-2.0 include/luajit-2.1 include luajit
PATHS
~/Library/Frameworks
/Library/Frameworks
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
/usr
/usr/include
/usr/include/lua5.4
)

find_library(LUA_LIBRARY
NAMES lua5.4
NAMES luajit-5.1 lua51
HINTS
ENV LUA_DIR
PATH_SUFFIXES lib
Expand All @@ -48,18 +45,19 @@ if(LUA_LIBRARY)
endif()
endif()

if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_VERSION[ \t]+\"Lua .+\"")
if(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/luajit.h")
file(STRINGS "${LUA_INCLUDE_DIR}/luajit.h" luajit_version_str REGEX "^#define[ \t]+LUAJIT_VERSION[ \t]+\"LuaJIT .+\"")

string(REGEX REPLACE "^#define[ \t]+LUA_VERSION[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
unset(lua_version_str)
string(REGEX REPLACE "^#define[ \t]+LUAJIT_VERSION[ \t]+\"LuaJIT ([^\"]+)\".*" "\\1" LUAJIT_VERSION_STRING "${luajit_version_str}")
unset(luajit_version_str)
endif()

include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
# all listed variables are TRUE
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua54
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaJIT
REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
VERSION_VAR LUA_VERSION_STRING)
VERSION_VAR LUAJIT_VERSION_STRING)

mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)

88 changes: 43 additions & 45 deletions src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2127,51 +2127,6 @@ void LuaScriptInterface::registerFunctions()
#undef registerEnum
#undef registerEnumIn

namespace {
const std::unordered_map<std::string_view, LuaDataType> LuaDataTypeByClassName = {
{"Item", LuaData_Item},
{"Container", LuaData_Container},
{"Teleport", LuaData_Teleport},
{"Creature", LuaData_Creature},
{"Player", LuaData_Player},
{"Monster", LuaData_Monster},
{"Npc", LuaData_Npc},
{"Tile", LuaData_Tile},
{"Condition", LuaData_Condition},

{"Combat", LuaData_Combat},
{"Group", LuaData_Group},
{"Guild", LuaData_Guild},
{"House", LuaData_House},
{"ItemType", LuaData_ItemType},
{"ModalWindow", LuaData_ModalWindow},
{"MonsterType", LuaData_MonsterType},
{"NetworkMessage", LuaData_NetworkMessage},
{"Party", LuaData_Party},
{"Vocation", LuaData_Vocation},
{"Town", LuaData_Town},
{"LuaVariant", LuaData_LuaVariant},
{"Position", LuaData_Position},

{"Outfit", LuaData_Outfit},
{"Loot", LuaData_Loot},
{"MonsterSpell", LuaData_MonsterSpell},
{"Spell", LuaData_Spell},
{"InstantSpell", LuaData_Spell},
{"Action", LuaData_Action},
{"TalkAction", LuaData_TalkAction},
{"CreatureEvent", LuaData_CreatureEvent},
{"MoveEvent", LuaData_MoveEvent},
{"GlobalEvent", LuaData_GlobalEvent},
{"Weapon", LuaData_Weapon},
{"WeaponDistance", LuaData_Weapon},
{"WeaponWand", LuaData_Weapon},
{"WeaponMelee", LuaData_Weapon},
{"XMLDocument", LuaData_XMLDocument},
{"XMLNode", LuaData_XMLNode},
};
}

void LuaScriptInterface::registerClass(const std::string& className, const std::string& baseClass,
lua_CFunction newFunction /* = nullptr*/)
{
Expand Down Expand Up @@ -2223,6 +2178,49 @@ void LuaScriptInterface::registerClass(const std::string& className, const std::
lua_pushinteger(luaState, parents);
lua_rawseti(luaState, metatable, 'p');

static std::unordered_map<std::string_view, LuaDataType> LuaDataTypeByClassName = {
{"Item", LuaData_Item},
{"Container", LuaData_Container},
{"Teleport", LuaData_Teleport},
{"Creature", LuaData_Creature},
{"Player", LuaData_Player},
{"Monster", LuaData_Monster},
{"Npc", LuaData_Npc},
{"Tile", LuaData_Tile},
{"Condition", LuaData_Condition},

{"Combat", LuaData_Combat},
{"Group", LuaData_Group},
{"Guild", LuaData_Guild},
{"House", LuaData_House},
{"ItemType", LuaData_ItemType},
{"ModalWindow", LuaData_ModalWindow},
{"MonsterType", LuaData_MonsterType},
{"NetworkMessage", LuaData_NetworkMessage},
{"Party", LuaData_Party},
{"Vocation", LuaData_Vocation},
{"Town", LuaData_Town},
{"LuaVariant", LuaData_LuaVariant},
{"Position", LuaData_Position},

{"Outfit", LuaData_Outfit},
{"Loot", LuaData_Loot},
{"MonsterSpell", LuaData_MonsterSpell},
{"Spell", LuaData_Spell},
{"InstantSpell", LuaData_Spell},
{"Action", LuaData_Action},
{"TalkAction", LuaData_TalkAction},
{"CreatureEvent", LuaData_CreatureEvent},
{"MoveEvent", LuaData_MoveEvent},
{"GlobalEvent", LuaData_GlobalEvent},
{"Weapon", LuaData_Weapon},
{"WeaponDistance", LuaData_Weapon},
{"WeaponWand", LuaData_Weapon},
{"WeaponMelee", LuaData_Weapon},
{"XMLDocument", LuaData_XMLDocument},
{"XMLNode", LuaData_XMLNode},
};

// className.metatable['t'] = type
auto luaDataType = LuaDataTypeByClassName.find(className);
if (luaDataType == LuaDataTypeByClassName.end()) {
Expand Down

0 comments on commit 15ea75c

Please sign in to comment.