diff --git a/.gitignore b/.gitignore index 26ec652..ed5879a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,12 +4,43 @@ *.dll *.def *.exe -/lib/slang* -/mapslang/pkg/* +*.so +*.a +*.pc +*.log +lib/slang* +mapslang/pkg/* +mapslang/mapslang +mapslang/map +map .vs/ .git /.cproject /.project /.settings/ -/tmp/ -/build/ +tmp/ +build/ +Makefile +CMakeFiles/ +CMakeCache.txt +cmake_install.cmake +install_manifest.txt +libadikted/CMakeFiles/ +libadikted/CMakeCache.txt +libadikted/Makefile* +libadikted/cmake_install.cmake +libadikted/install_manifest.txt +mapslang/CMakeFiles/ +mapslang/CMakeCache.txt +mapslang/cmake_install.cmake +mapslang/Makefile* +mapslang/install_manifest.txt +mapslang/map +putemple +puttrain +putgems +viewmap* +./putemple +./puttrain +./putgems +./viewmap* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..11c49ea --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,48 @@ +cmake_minimum_required( VERSION 3.5 ) + +project( ADiKtED LANGUAGES C ) +set(PROJECT_DESCRIPTION "Dungeon Keeper 1 map editor") + +include(GNUInstallDirs) +include(FindPkgConfig) + +if( NOT CMAKE_BUILD_TYPE ) + set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE ) +endif() + +set( CMAKE_C_STANDARD 99 ) +set( CMAKE_C_STANDARD_REQUIRED ON ) + +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-switch" ) +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic" ) +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra" ) +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror-implicit-function-declaration -Wno-conversion -Wno-traditional-conversion -Wno-sign-compare" ) + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + +include(LibFindMacros) +include(FindMath) +include(FindBsd) + +# Add examples +include(cmake/examples.cmake) +option( ADIKTED_BUILD_EXAMPLES "Build ADiKtEd examples" ON ) +if( ADIKTED_BUILD_EXAMPLES ) + set( + ADIKTED_EXAMPLES + putgems + puttrain + viewmap + putemple + ) + +foreach( EXAMPLE ${ADIKTED_EXAMPLES} ) + add_example( ${EXAMPLE} ) + endforeach() +endif() + +add_subdirectory(libadikted) +add_subdirectory(mapslang) + +install( TARGETS ${ADIKTED_EXAMPLES} RUNTIME + DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT binaries) diff --git a/README.md b/README.md new file mode 100644 index 0000000..8bad11e --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# Adikted Dungeon Keeper Map Editor + +Note - there is now a manual available for ADiKtEd. +It even includes a basic tutorial to quickly learn the program. +A version of it is included within this distribution, +called `dk_adikted_manual.htm`. You may wish to print this out. +## Build + +### Unix-like systems + +#### CMake + +Run +`cmake --install-prefix=/usr . && make install` +and copy the examples to the keeperfx directory + +### Windows + +#### make + +Run `cd libadikted/ && make -f Makefile.win && cd mapslang && make -f Makefile.win` + +Here's the Win32 version executable. Just put all the +files in the same directory, edit map.ini as appropriate (you should +change paths to your DK files; you can also change other parameters +if you want), and run it. + +## Usage + +Run `map [mapfile] [-m ] [-v] [-r] [-n] [-s [mapfile]] [-q]` + +When ADiKtEd saves a map, it will ask you what you wish to call it +(unless you're not using quick save). I suggest you don't save +directly over the Dungeon Keeper original levels, but keep it +in the current directory until you're finished. +Then, at end, save it on `map00001` to access it easily in the game. + +You'll need a level script for your newly created level. You may be +able to get by with the script which comes with the original level 1 +- ie just copy it and paste into TXT file of your new map - but +if not, study the level scripts reference from `dk_scripting_ref.htm`. +You can also try looking at the original DK and DD levels for examples. + +Press F1 for help. + +## TODO before final + Fixations in room things parameters (height,other) + Fixations in room corner graphics + +## Author + Jon Skeet, skeet@pobox.com + +Dev-C++ IDE version, +rewritten most of the code: + Tomasz Lis diff --git a/cmake/FindBsd.cmake b/cmake/FindBsd.cmake new file mode 100644 index 0000000..4e61437 --- /dev/null +++ b/cmake/FindBsd.cmake @@ -0,0 +1,31 @@ +# Find Bsd compat lib +# +# Once done, this will define: +# +# Bsd_FOUND - system has Bsd compat +# Bsd_INCLUDE_DIRS - the Bsd compat include directories +# Bsd_LIBRARIES - link these to use Bsd compat +# + +include(LibFindMacros) + +if (BSD_INCLUDE_DIR AND BSD_LIBRARY) + # Already in cache, be silent + set(BSD_FIND_QUIETLY TRUE) +endif () + +libfind_pkg_check_modules(BSD_PKGCONF libbsd) + +find_path(BSD_INCLUDE_DIR bsd.h + PATH_SUFFIX bsd + PATHS ${BSD_PKGCONF_INCLUDE_DIRS} +) + +find_library(BSD_LIBRARY + NAMES bsd + PATHS ${BSD_PKGCONF_LIBRARY_DIRS} +) + +set(BSD_PROCESS_INCLUDES ${BSD_INCLUDE_DIR}) +set(BSD_PROCESS_LIBS ${BSD_LIBRARY}) +libfind_process(BSD) diff --git a/cmake/FindMath.cmake b/cmake/FindMath.cmake new file mode 100644 index 0000000..ca854c9 --- /dev/null +++ b/cmake/FindMath.cmake @@ -0,0 +1,76 @@ +include (CheckLibraryExists) +set(Math_FOUND FALSE) +set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET}) +set(CMAKE_REQUIRED_QUIET ${Math_FIND_QUIETLY}) + +if(CMAKE_C_COMPILER_LOADED) + include (CheckIncludeFile) + include (CheckCSourceCompiles) +elseif(CMAKE_CXX_COMPILER_LOADED) + include (CheckIncludeFileCXX) + include (CheckCXXSourceCompiles) +else() + message(FATAL_ERROR "FindMath only works if either C or CXX language is enabled") +endif() + +set(MATH_C_CXX_TEST_SOURCE [====[ +#include + +int main() +{ + const double x = 7.3; + ceil(x); + acos(x); + sin(x); + sqrt(x); + + return 0; +} +]====]) + + +if(CMAKE_C_COMPILER_LOADED) + CHECK_INCLUDE_FILE("math.h" CMAKE_HAVE_MATH_H) +else() + CHECK_INCLUDE_FILE_CXX("math.h" CMAKE_HAVE_MATH_H) +endif() + +if(CMAKE_HAVE_MATH_H) + set(CMAKE_HAVE_MATH_LIBRARY) + + set(CMAKE_REQUIRED_LIBRARIES -lm) + if(CMAKE_C_COMPILER_LOADED) + CHECK_C_SOURCE_COMPILES("${MATH_C_CXX_TEST_SOURCE}" CMAKE_HAVE_LIBC_LIBM) + elseif(CMAKE_CXX_COMPILER_LOADED) + CHECK_CXX_SOURCE_COMPILES("${MATH_C_CXX_TEST_SOURCE}" CMAKE_HAVE_LIBC_LIBM) + endif() + + if(CMAKE_HAVE_LIBC_LIBM) + set(CMAKE_MATH_LIBS_INIT ${CMAKE_REQUIRED_LIBRARIES}) + set(CMAKE_HAVE_MATH_LIBRARY 1) + set(Math_FOUND TRUE) + else() + set(Math_FOUND FALSE) + endif() + + unset(CMAKE_REQUIRED_LIBRARIES) + set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE}) + + include(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(Math DEFAULT_MSG Math_FOUND) + + if(MATH_FOUND AND NOT TARGET Math::Math) + add_library(Math::Math INTERFACE IMPORTED) + + if(CMAKE_MATH_LIBS_INIT) + set_property(TARGET Math::Math PROPERTY INTERFACE_LINK_LIBRARIES "${CMAKE_MATH_LIBS_INIT}") + endif() + elseif(NOT MATH_FOUND) + file(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if compiler accepts -lm failed with the following output:\n${_cmake_find_math_output}\n\n") + message(SEND_ERROR "Required Math library not found!") + endif() +endif() + +unset(_cmake_find_math_output) diff --git a/cmake/LibFindMacros.cmake b/cmake/LibFindMacros.cmake new file mode 100644 index 0000000..98f818e --- /dev/null +++ b/cmake/LibFindMacros.cmake @@ -0,0 +1,99 @@ +# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments +# used for the current package. For this to work, the first parameter must be the +# prefix of the current package, then the prefix of the new package etc, which are +# passed to find_package. +macro (libfind_package PREFIX) + set (LIBFIND_PACKAGE_ARGS ${ARGN}) + if (${PREFIX}_FIND_QUIETLY) + set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) + endif (${PREFIX}_FIND_QUIETLY) + if (${PREFIX}_FIND_REQUIRED) + set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) + endif (${PREFIX}_FIND_REQUIRED) + find_package(${LIBFIND_PACKAGE_ARGS}) +endmacro (libfind_package) + +# CMake developers made the UsePkgConfig system deprecated in the same release (2.6) +# where they added pkg_check_modules. Consequently I need to support both in my scripts +# to avoid those deprecated warnings. Here's a helper that does just that. +# Works identically to pkg_check_modules, except that no checks are needed prior to use. +macro (libfind_pkg_check_modules PREFIX PKGNAME) + if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + include(UsePkgConfig) + pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS) + else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + find_package(PkgConfig) + if (PKG_CONFIG_FOUND) + pkg_check_modules(${PREFIX} ${PKGNAME}) + endif (PKG_CONFIG_FOUND) + endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) +endmacro (libfind_pkg_check_modules) + +# Do the final processing once the paths have been detected. +# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain +# all the variables, each of which contain one include directory. +# Ditto for ${PREFIX}_PROCESS_LIBS and library files. +# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. +# Also handles errors in case library detection was required, etc. +macro (libfind_process PREFIX) + # Skip processing if already processed during this run + if (NOT ${PREFIX}_FOUND) + # Start with the assumption that the library was found + set (${PREFIX}_FOUND TRUE) + + # Process all includes and set _FOUND to false if any are missing + foreach (i ${${PREFIX}_PROCESS_INCLUDES}) + if (${i}) + set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) + mark_as_advanced(${i}) + else (${i}) + set (${PREFIX}_FOUND FALSE) + endif (${i}) + endforeach (i) + + # Process all libraries and set _FOUND to false if any are missing + foreach (i ${${PREFIX}_PROCESS_LIBS}) + if (${i}) + set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) + mark_as_advanced(${i}) + else (${i}) + set (${PREFIX}_FOUND FALSE) + endif (${i}) + endforeach (i) + + # Print message and/or exit on fatal error + if (${PREFIX}_FOUND) + if (NOT ${PREFIX}_FIND_QUIETLY) + message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}") + endif (NOT ${PREFIX}_FIND_QUIETLY) + else (${PREFIX}_FOUND) + if (${PREFIX}_FIND_REQUIRED) + foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) + message("${i}=${${i}}") + endforeach (i) + message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.") + endif (${PREFIX}_FIND_REQUIRED) + endif (${PREFIX}_FOUND) + endif (NOT ${PREFIX}_FOUND) +endmacro (libfind_process) + +macro(libfind_library PREFIX basename) + set(TMP "") + if(MSVC80) + set(TMP -vc80) + endif(MSVC80) + if(MSVC90) + set(TMP -vc90) + endif(MSVC90) + set(${PREFIX}_LIBNAMES ${basename}${TMP}) + if(${ARGC} GREATER 2) + set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2}) + string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES}) + set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP}) + endif(${ARGC} GREATER 2) + find_library(${PREFIX}_LIBRARY + NAMES ${${PREFIX}_LIBNAMES} + PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS} + ) +endmacro(libfind_library) + diff --git a/cmake/examples.cmake b/cmake/examples.cmake new file mode 100644 index 0000000..76eab47 --- /dev/null +++ b/cmake/examples.cmake @@ -0,0 +1,28 @@ +function( add_example ARG_NAME ) + list( APPEND ARG_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/examples/${ARG_NAME}" ) + set( SOURCES "" ) + set( RESOURCES "" ) + foreach( DIR ${ARG_DIRECTORIES} ) + file( GLOB GLOB_SOURCES ${DIR}/*.c ${DIR}/*.h ) + list( APPEND SOURCES ${GLOB_SOURCES} ) + file( GLOB GLOB_RESOURCES ${DIR}/*.rc ) + list( APPEND RESOURCES ${GLOB_RESOURCES} ) + endforeach() + add_executable( ${ARG_NAME} ${SOURCES} ) + target_link_libraries( ${ARG_NAME} PUBLIC adikted ) + find_package( SDL REQUIRED ) + target_link_libraries( ${ARG_NAME} PUBLIC ${SDL_LIBRARY} ) + target_compile_definitions( ${ARG_NAME} PUBLIC ENTRY_CONFIG_USE_SDL ) + target_link_libraries( ${ARG_NAME} PUBLIC X11 Math::Math ) + target_include_directories(${ARG_NAME} PUBLIC Math::Math + $ + $ + ${SDL_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/.) + + # Directory name + set_target_properties( ${ARG_NAME} PROPERTIES FOLDER + "${CMAKE_CURRENT_SOURCE_DIR}/examples" ) + add_test(${ARG_NAME} ${ARG_NAME}) +endfunction() + diff --git a/example4/Makefile.win b/examples/putemple/Makefile.win similarity index 100% rename from example4/Makefile.win rename to examples/putemple/Makefile.win diff --git a/example4/putemple.c b/examples/putemple/putemple.c similarity index 98% rename from example4/putemple.c rename to examples/putemple/putemple.c index 8af279e..24903e9 100644 --- a/example4/putemple.c +++ b/examples/putemple/putemple.c @@ -1,6 +1,6 @@ /******************************************************************************/ /** @file putemple.c - * ADiKtEd library example 4. + * ADiKtEd library putemple example. * @par Purpose: * Demonstrates fast drawing routines and putting slabs with mouse. * Also, shows how to draw ADiKtEd messages using DK font. @@ -23,7 +23,7 @@ #include #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #define ONE_LOOP_DELAY 20 /** @@ -404,7 +404,7 @@ static void process_events() // contains error message. // Release the error message. message_release(); - message_info("example4 finished with map load error"); + message_info("putemple finished with map load error"); reload_data=0; level_redraw=0; clip_view=0; @@ -425,7 +425,7 @@ static void process_events() { // Release the error message. message_release(); - message_info("example4 finished with data files load error"); + message_info("putemple finished with data files load error"); level_redraw=0; clip_view=0; done = 1; @@ -493,7 +493,7 @@ int main (int argc, char *argv[]) free_messages(); return 2; } - SDL_WM_SetCaption ("ADiKtEd Libray example 4", NULL); + SDL_WM_SetCaption ("ADiKtEd Libray putemple example", NULL); message_log("Preparing data structures"); // create object for storing map diff --git a/example4/putemple.dev b/examples/putemple/putemple.dev similarity index 100% rename from example4/putemple.dev rename to examples/putemple/putemple.dev diff --git a/example4/putemple_private.h b/examples/putemple/putemple_private.h similarity index 100% rename from example4/putemple_private.h rename to examples/putemple/putemple_private.h diff --git a/example4/putemple_private.rc b/examples/putemple/putemple_private.rc similarity index 100% rename from example4/putemple_private.rc rename to examples/putemple/putemple_private.rc diff --git a/example1/Makefile.win b/examples/putgems/Makefile.win similarity index 100% rename from example1/Makefile.win rename to examples/putgems/Makefile.win diff --git a/example1/putgems.c b/examples/putgems/putgems.c similarity index 90% rename from example1/putgems.c rename to examples/putgems/putgems.c index 6c33380..c6f9eff 100644 --- a/example1/putgems.c +++ b/examples/putgems/putgems.c @@ -1,6 +1,6 @@ /******************************************************************************/ /** @file putgems.c - * ADiKtEd library example 1. + * ADiKtEd library putgems example. * @par Purpose: * This example puts gems on center of gold vein in map 1. * Demonstrates how to load/save map, and how to change slabs. @@ -19,7 +19,7 @@ #include #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" int main(int argc, char *argv[]) { @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) // but still they have to be initialized) init_messages(); - printf("\nexample1: how to put gems on map\n\n"); + printf("\nputgems: how to put gems on map\n\n"); // Setting file name of the map to load format_lvl_fname(lvl,"Levels/MAP00001"); @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) if (result!=ERR_NONE) { printf("cannot load map\n"); - printf("example1 finished with error\n"); + printf("putgems finished with error\n"); system("pause"); // The following two commands should be used to free memory @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) if (result!=ERR_NONE) { printf("cannot save map\n"); - printf("example1 finished with error\n"); + printf("putgems finished with error\n"); system("pause"); // The following two commands should be used to free memory @@ -85,7 +85,7 @@ int main(int argc, char *argv[]) return 1; } printf("map \"%s\" saved\n", get_lvl_savfname(lvl)); - printf("example1 finished successfully\n"); + printf("putgems finished successfully\n"); system("pause"); // The following two commands should be used to free memory diff --git a/example1/putgems.dev b/examples/putgems/putgems.dev similarity index 100% rename from example1/putgems.dev rename to examples/putgems/putgems.dev diff --git a/example2/Makefile.win b/examples/puttrain/Makefile.win similarity index 100% rename from example2/Makefile.win rename to examples/puttrain/Makefile.win diff --git a/example2/puttrain.c b/examples/puttrain/puttrain.c similarity index 94% rename from example2/puttrain.c rename to examples/puttrain/puttrain.c index f4ef6c9..899d0d8 100644 --- a/example2/puttrain.c +++ b/examples/puttrain/puttrain.c @@ -1,6 +1,6 @@ /******************************************************************************/ /** @file puttrain.c - * ADiKtEd library example 2. + * ADiKtEd library puttrain example. * @par Purpose: * This example puts 3x5 training room in bottom right part of map 1. * Demonstrates how to change many slabs at once, @@ -20,7 +20,7 @@ #include #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" int main(int argc, char *argv[]) { @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) // Instead of printing the message directly, we will send it // to the internal messages system. - message_info("example2: how to put a larger room on map"); + message_info("puttrain: how to put a larger room on map"); // Now we can easily get the message back, even multiple times. printf("%s\n",message_get()); @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) // Now, as the buffer is released, the message_info() function // can be used to store next message. - message_info("example2 finished with load error"); + message_info("puttrain finished with load error"); printf("%s\n",message_get()); system("pause"); @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) // Now, as the buffer is released, the message_info() function // can be used to store next message. - message_info("example2 finished with save error"); + message_info("puttrain finished with save error"); printf("%s\n",message_get()); system("pause"); @@ -138,7 +138,7 @@ int main(int argc, char *argv[]) printf("%s\n",message_get()); message_release(); - message_info("example2 finished successfully"); + message_info("puttrain finished successfully"); printf("%s\n",message_get()); system("pause"); diff --git a/example2/puttrain.dev b/examples/puttrain/puttrain.dev similarity index 100% rename from example2/puttrain.dev rename to examples/puttrain/puttrain.dev diff --git a/example3/Makefile.win b/examples/viewmap/Makefile.win similarity index 100% rename from example3/Makefile.win rename to examples/viewmap/Makefile.win diff --git a/example3/viewmap.c b/examples/viewmap/viewmap.c similarity index 97% rename from example3/viewmap.c rename to examples/viewmap/viewmap.c index 09e6f9a..28f3fe4 100644 --- a/example3/viewmap.c +++ b/examples/viewmap/viewmap.c @@ -1,6 +1,6 @@ /******************************************************************************/ /** @file viewmap.c - * ADiKtEd library example 3. + * ADiKtEd library viewmap example. * @par Purpose: * This example shows how to view maps graphically using libAdikted. * Move with mouse, zoom with numpad +/-. @@ -22,7 +22,7 @@ #include #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #define ONE_LOOP_DELAY 32 /** @@ -279,7 +279,7 @@ static void process_events() // Release the error message. message_release(); - message_info("example3 finished with data files load error"); + message_info("viewmap finished with data files load error"); clip_view=0; done = 1; @@ -339,7 +339,7 @@ int main (int argc, char *argv[]) free_messages(); return 2; } - SDL_WM_SetCaption ("ADiKtEd Libray example 3", NULL); + SDL_WM_SetCaption ("ADiKtEd Libray viewmap example", NULL); // create object for storing map level_init(&lvl,MFV_DKGOLD,NULL); @@ -365,7 +365,7 @@ int main (int argc, char *argv[]) // Release the error message. message_release(); - message_info("example3 finished with map load error"); + message_info("viewmap finished with map load error"); level_free(lvl); level_deinit(&lvl); diff --git a/example3/viewmap.dev b/examples/viewmap/viewmap.dev similarity index 100% rename from example3/viewmap.dev rename to examples/viewmap/viewmap.dev diff --git a/example3/viewmap_private.h b/examples/viewmap/viewmap_private.h similarity index 100% rename from example3/viewmap_private.h rename to examples/viewmap/viewmap_private.h diff --git a/example3/viewmap_private.rc b/examples/viewmap/viewmap_private.rc similarity index 100% rename from example3/viewmap_private.rc rename to examples/viewmap/viewmap_private.rc diff --git a/libadikted/CMakeLists.txt b/libadikted/CMakeLists.txt index 652e56e..b069376 100644 --- a/libadikted/CMakeLists.txt +++ b/libadikted/CMakeLists.txt @@ -1,80 +1,81 @@ -## -## -## +cmake_minimum_required( VERSION 3.5 ) +set( TARGET_NAME adikted ) +project( lib${TARGET_NAME} LANGUAGES C ) +set( PROJECT_DESCRIPTION "Dungeon Keeper 1 ADiKtEd map editor C library" ) -## 3.1 -- CMAKE_C_STANDARD -cmake_minimum_required( VERSION 3.1 ) - - -if( "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}" ) - message( FATAL_ERROR "Building in source is forbidden. Change output directory.") -endif() - - -project( libadikted LANGUAGES C ) - +include(GNUInstallDirs) +include(FindPkgConfig) if( NOT CMAKE_BUILD_TYPE ) - set( CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE ) + set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE ) endif() -if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - ## do not install accidentally to system directory - set( CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Install path prefix" FORCE ) -endif() - - set(CMAKE_DEBUG_POSTFIX _d) - -## -## set default compilation standard -## set( CMAKE_C_STANDARD 99 ) set( CMAKE_C_STANDARD_REQUIRED ON ) - -## -## compiler flags, gcc does not handle "appended" values -## -set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" ) +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-switch" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror-implicit-function-declaration -Wno-conversion -Wno-traditional-conversion -Wno-sign-compare" ) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +include(LibFindMacros) +include(FindMath) +include(FindBsd) ## ================= build ================= -option( USE_RNG_MT "Use Mersenne Twister RNG" OFF ) +option( USE_RNG_MT "Use Mersenne Twister RNG" ON ) if( USE_RNG_MT ) add_definitions( -DRNG_MT ) endif() - -set( TARGET_NAME adikted ) +find_package(Bsd) if( NOT ${TARGET_NAME}_TYPE ) ## build library as shared by default set( ${TARGET_NAME}_TYPE SHARED ) endif() +file( GLOB c_files ${CMAKE_CURRENT_SOURCE_DIR}/*.c) +file( GLOB h_files ${CMAKE_CURRENT_SOURCE_DIR}/*.h) -file( GLOB_RECURSE c_files *.c ) -file( GLOB_RECURSE h_files *.h ) - -if( NOT USE_RNG_MT ) - list(REMOVE_ITEM h_files "${CMAKE_CURRENT_SOURCE_DIR}/mtwist/mtwist.h" ) - list(REMOVE_ITEM c_files "${CMAKE_CURRENT_SOURCE_DIR}/mtwist/mtwist.c" ) +if( USE_RNG_MT ) + list(APPEND h_files "${CMAKE_CURRENT_SOURCE_DIR}/mtwist/mtwist.h" ) + list(APPEND c_files "${CMAKE_CURRENT_SOURCE_DIR}/mtwist/mtwist.c" ) endif() add_library( ${TARGET_NAME} ${${TARGET_NAME}_TYPE} ${c_files} ) -target_include_directories( ${TARGET_NAME} PUBLIC ".." PRIVATE "." ) set_target_properties( ${TARGET_NAME} PROPERTIES PUBLIC_HEADER "${h_files}" ) - -install( TARGETS ${TARGET_NAME} - PUBLIC_HEADER DESTINATION include/lib${TARGET_NAME} COMPONENT headers - LIBRARY DESTINATION lib COMPONENT binaries +target_include_directories(${TARGET_NAME} PUBLIC Math::Math ${BSD_PROCESS_INCLUDES} + $ + $ + PRIVATE "." + ) + target_link_libraries(${TARGET_NAME} Math::Math ${BSD_PROCESS_LIBS}) + +# pkg-config variables +set(target_name "${TARGET_NAME}") +set(stdclibs "${CMAKE_C_STANDARD_LIBRARIES}" Math::Math ${BSD_PROCESS_LIBS}) +set(install_prefix "${CMAKE_INSTALL_PREFIX}") +set(install_libdir "${CMAKE_INSTALL_LIBDIR}") +set(install_includedir "${CMAKE_INSTALL_INCLUDEDIR}") +configure_file(lib${TARGET_NAME}.pc.in ${PROJECT_BINARY_DIR}/lib${TARGET_NAME}.pc @ONLY) + +set(ENV{PKG_CONFIG_PATH} "${PROJECT_BINARY_DIR}:$ENV{PKG_CONFIG_PATH}") + +install( TARGETS ${TARGET_NAME} EXPORT lib${TARGET_NAME}Config + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT binaries + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lib${TARGET_NAME} COMPONENT headers ) + +install(FILES ${PROJECT_BINARY_DIR}/lib${TARGET_NAME}.pc DESTINATION + ${CMAKE_INSTALL_LIBDIR}/pkgconfig/) + diff --git a/libadikted/Makefile b/libadikted/Makefile.win similarity index 100% rename from libadikted/Makefile rename to libadikted/Makefile.win diff --git a/libadikted/cmake/FindBsd.cmake b/libadikted/cmake/FindBsd.cmake new file mode 100644 index 0000000..4e61437 --- /dev/null +++ b/libadikted/cmake/FindBsd.cmake @@ -0,0 +1,31 @@ +# Find Bsd compat lib +# +# Once done, this will define: +# +# Bsd_FOUND - system has Bsd compat +# Bsd_INCLUDE_DIRS - the Bsd compat include directories +# Bsd_LIBRARIES - link these to use Bsd compat +# + +include(LibFindMacros) + +if (BSD_INCLUDE_DIR AND BSD_LIBRARY) + # Already in cache, be silent + set(BSD_FIND_QUIETLY TRUE) +endif () + +libfind_pkg_check_modules(BSD_PKGCONF libbsd) + +find_path(BSD_INCLUDE_DIR bsd.h + PATH_SUFFIX bsd + PATHS ${BSD_PKGCONF_INCLUDE_DIRS} +) + +find_library(BSD_LIBRARY + NAMES bsd + PATHS ${BSD_PKGCONF_LIBRARY_DIRS} +) + +set(BSD_PROCESS_INCLUDES ${BSD_INCLUDE_DIR}) +set(BSD_PROCESS_LIBS ${BSD_LIBRARY}) +libfind_process(BSD) diff --git a/libadikted/cmake/FindMath.cmake b/libadikted/cmake/FindMath.cmake new file mode 100644 index 0000000..ca854c9 --- /dev/null +++ b/libadikted/cmake/FindMath.cmake @@ -0,0 +1,76 @@ +include (CheckLibraryExists) +set(Math_FOUND FALSE) +set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET}) +set(CMAKE_REQUIRED_QUIET ${Math_FIND_QUIETLY}) + +if(CMAKE_C_COMPILER_LOADED) + include (CheckIncludeFile) + include (CheckCSourceCompiles) +elseif(CMAKE_CXX_COMPILER_LOADED) + include (CheckIncludeFileCXX) + include (CheckCXXSourceCompiles) +else() + message(FATAL_ERROR "FindMath only works if either C or CXX language is enabled") +endif() + +set(MATH_C_CXX_TEST_SOURCE [====[ +#include + +int main() +{ + const double x = 7.3; + ceil(x); + acos(x); + sin(x); + sqrt(x); + + return 0; +} +]====]) + + +if(CMAKE_C_COMPILER_LOADED) + CHECK_INCLUDE_FILE("math.h" CMAKE_HAVE_MATH_H) +else() + CHECK_INCLUDE_FILE_CXX("math.h" CMAKE_HAVE_MATH_H) +endif() + +if(CMAKE_HAVE_MATH_H) + set(CMAKE_HAVE_MATH_LIBRARY) + + set(CMAKE_REQUIRED_LIBRARIES -lm) + if(CMAKE_C_COMPILER_LOADED) + CHECK_C_SOURCE_COMPILES("${MATH_C_CXX_TEST_SOURCE}" CMAKE_HAVE_LIBC_LIBM) + elseif(CMAKE_CXX_COMPILER_LOADED) + CHECK_CXX_SOURCE_COMPILES("${MATH_C_CXX_TEST_SOURCE}" CMAKE_HAVE_LIBC_LIBM) + endif() + + if(CMAKE_HAVE_LIBC_LIBM) + set(CMAKE_MATH_LIBS_INIT ${CMAKE_REQUIRED_LIBRARIES}) + set(CMAKE_HAVE_MATH_LIBRARY 1) + set(Math_FOUND TRUE) + else() + set(Math_FOUND FALSE) + endif() + + unset(CMAKE_REQUIRED_LIBRARIES) + set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE}) + + include(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(Math DEFAULT_MSG Math_FOUND) + + if(MATH_FOUND AND NOT TARGET Math::Math) + add_library(Math::Math INTERFACE IMPORTED) + + if(CMAKE_MATH_LIBS_INIT) + set_property(TARGET Math::Math PROPERTY INTERFACE_LINK_LIBRARIES "${CMAKE_MATH_LIBS_INIT}") + endif() + elseif(NOT MATH_FOUND) + file(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if compiler accepts -lm failed with the following output:\n${_cmake_find_math_output}\n\n") + message(SEND_ERROR "Required Math library not found!") + endif() +endif() + +unset(_cmake_find_math_output) diff --git a/libadikted/cmake/LibFindMacros.cmake b/libadikted/cmake/LibFindMacros.cmake new file mode 100644 index 0000000..98f818e --- /dev/null +++ b/libadikted/cmake/LibFindMacros.cmake @@ -0,0 +1,99 @@ +# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments +# used for the current package. For this to work, the first parameter must be the +# prefix of the current package, then the prefix of the new package etc, which are +# passed to find_package. +macro (libfind_package PREFIX) + set (LIBFIND_PACKAGE_ARGS ${ARGN}) + if (${PREFIX}_FIND_QUIETLY) + set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) + endif (${PREFIX}_FIND_QUIETLY) + if (${PREFIX}_FIND_REQUIRED) + set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) + endif (${PREFIX}_FIND_REQUIRED) + find_package(${LIBFIND_PACKAGE_ARGS}) +endmacro (libfind_package) + +# CMake developers made the UsePkgConfig system deprecated in the same release (2.6) +# where they added pkg_check_modules. Consequently I need to support both in my scripts +# to avoid those deprecated warnings. Here's a helper that does just that. +# Works identically to pkg_check_modules, except that no checks are needed prior to use. +macro (libfind_pkg_check_modules PREFIX PKGNAME) + if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + include(UsePkgConfig) + pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS) + else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + find_package(PkgConfig) + if (PKG_CONFIG_FOUND) + pkg_check_modules(${PREFIX} ${PKGNAME}) + endif (PKG_CONFIG_FOUND) + endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) +endmacro (libfind_pkg_check_modules) + +# Do the final processing once the paths have been detected. +# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain +# all the variables, each of which contain one include directory. +# Ditto for ${PREFIX}_PROCESS_LIBS and library files. +# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. +# Also handles errors in case library detection was required, etc. +macro (libfind_process PREFIX) + # Skip processing if already processed during this run + if (NOT ${PREFIX}_FOUND) + # Start with the assumption that the library was found + set (${PREFIX}_FOUND TRUE) + + # Process all includes and set _FOUND to false if any are missing + foreach (i ${${PREFIX}_PROCESS_INCLUDES}) + if (${i}) + set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) + mark_as_advanced(${i}) + else (${i}) + set (${PREFIX}_FOUND FALSE) + endif (${i}) + endforeach (i) + + # Process all libraries and set _FOUND to false if any are missing + foreach (i ${${PREFIX}_PROCESS_LIBS}) + if (${i}) + set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) + mark_as_advanced(${i}) + else (${i}) + set (${PREFIX}_FOUND FALSE) + endif (${i}) + endforeach (i) + + # Print message and/or exit on fatal error + if (${PREFIX}_FOUND) + if (NOT ${PREFIX}_FIND_QUIETLY) + message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}") + endif (NOT ${PREFIX}_FIND_QUIETLY) + else (${PREFIX}_FOUND) + if (${PREFIX}_FIND_REQUIRED) + foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) + message("${i}=${${i}}") + endforeach (i) + message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.") + endif (${PREFIX}_FIND_REQUIRED) + endif (${PREFIX}_FOUND) + endif (NOT ${PREFIX}_FOUND) +endmacro (libfind_process) + +macro(libfind_library PREFIX basename) + set(TMP "") + if(MSVC80) + set(TMP -vc80) + endif(MSVC80) + if(MSVC90) + set(TMP -vc90) + endif(MSVC90) + set(${PREFIX}_LIBNAMES ${basename}${TMP}) + if(${ARGC} GREATER 2) + set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2}) + string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES}) + set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP}) + endif(${ARGC} GREATER 2) + find_library(${PREFIX}_LIBRARY + NAMES ${${PREFIX}_LIBNAMES} + PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS} + ) +endmacro(libfind_library) + diff --git a/libadikted/draw_map.c b/libadikted/draw_map.c index 8582e8b..dcc66df 100644 --- a/libadikted/draw_map.c +++ b/libadikted/draw_map.c @@ -714,7 +714,7 @@ short draw_rect_sum_on_buffer(unsigned char *dest,const struct IPOINT_2D dest_po * @param scale Destination buffer scale. * @return Returns ERR_NONE on success, error code on failure. */ -short draw_texture_on_buffer_avg4(unsigned char *dest,const struct IPOINT_2D dest_pos, +short draw_texture_on_buffer_avg4(char *dest,const struct IPOINT_2D dest_pos, const struct IPOINT_2D dest_size, const unsigned int dest_scanln, const unsigned char *src,const struct IPOINT_2D src_pos,const struct IPOINT_2D src_size, const struct IPOINT_2D rect_size,struct PALETTE_ENTRY *pal,const struct IPOINT_2D scale) @@ -818,7 +818,7 @@ short draw_texture_on_buffer_avg4(unsigned char *dest,const struct IPOINT_2D des * @param scale Destination buffer scale. * @return Returns ERR_NONE on success, error code on failure. */ -short draw_texture_on_buffer_avg4_unsafe(unsigned char *dest,const struct IPOINT_2D dest_pos, +short draw_texture_on_buffer_avg4_unsafe(char *dest,const struct IPOINT_2D dest_pos, __attribute__((unused)) const struct IPOINT_2D dest_size, const unsigned int dest_scanln, const unsigned char *src,const struct IPOINT_2D src_pos,const struct IPOINT_2D src_size, const struct IPOINT_2D rect_size,struct PALETTE_ENTRY *pal,const struct IPOINT_2D scale) @@ -884,7 +884,7 @@ short draw_texture_on_buffer_avg4_unsafe(unsigned char *dest,const struct IPOINT * @param scale Destination buffer scale. * @return Returns ERR_NONE on success, error code on failure. */ -short draw_texture_on_buffer_avg2(unsigned char *dest,const struct IPOINT_2D dest_pos, +short draw_texture_on_buffer_avg2(char *dest,const struct IPOINT_2D dest_pos, const struct IPOINT_2D dest_size, const unsigned int dest_scanln, const unsigned char *src,const struct IPOINT_2D src_pos,const struct IPOINT_2D src_size, const struct IPOINT_2D rect_size,struct PALETTE_ENTRY *pal,const struct IPOINT_2D scale) @@ -974,7 +974,7 @@ short draw_texture_on_buffer_avg2(unsigned char *dest,const struct IPOINT_2D des * @param scale Destination buffer scale. * @return Returns ERR_NONE on success, error code on failure. */ -FASTCALL short draw_texture_on_buffer_avg2_fast(unsigned char *dest,const struct IPOINT_2D dest_pos, +FASTCALL short draw_texture_on_buffer_avg2_fast(char *dest,const struct IPOINT_2D dest_pos, const struct IPOINT_2D dest_size, const unsigned int dest_scanln, const unsigned char *src,const struct IPOINT_2D src_pos,const struct IPOINT_2D src_size, const struct IPOINT_2D rect_size,struct PALETTE_ENTRY *pal,const struct IPOINT_2D scale) @@ -1053,7 +1053,7 @@ FASTCALL short draw_texture_on_buffer_avg2_fast(unsigned char *dest,const struct * @param scale Destination buffer scale. * @return Returns ERR_NONE on success, error code on failure. */ -FASTCALL short draw_texture_on_buffer_avg2_fast_unsafe(unsigned char *dest,const struct IPOINT_2D dest_pos, +FASTCALL short draw_texture_on_buffer_avg2_fast_unsafe(char *dest,const struct IPOINT_2D dest_pos, __attribute__((unused)) const struct IPOINT_2D dest_size, const unsigned int dest_scanln, const unsigned char *src,const struct IPOINT_2D src_pos,const struct IPOINT_2D src_size, const struct IPOINT_2D rect_size,struct PALETTE_ENTRY *pal,const struct IPOINT_2D scale) @@ -1104,7 +1104,7 @@ FASTCALL short draw_texture_on_buffer_avg2_fast_unsafe(unsigned char *dest,const * @param scale Destination buffer scale. * @return Returns ERR_NONE on success, error code on failure. */ -short draw_texture_on_buffer_noavg(unsigned char *dest,const struct IPOINT_2D dest_pos, +short draw_texture_on_buffer_noavg(char *dest,const struct IPOINT_2D dest_pos, const struct IPOINT_2D dest_size, const unsigned int dest_scanln, const unsigned char *src,const struct IPOINT_2D src_pos,const struct IPOINT_2D src_size, const struct IPOINT_2D rect_size,struct PALETTE_ENTRY *pal,const struct IPOINT_2D scale) @@ -1198,7 +1198,7 @@ short draw_texture_on_buffer_noavg(unsigned char *dest,const struct IPOINT_2D de * @param scale Destination buffer scale. * @return Returns ERR_NONE on success, error code on failure. */ -short draw_texture_on_buffer_noavg_unsafe(unsigned char *dest,const struct IPOINT_2D dest_pos, +short draw_texture_on_buffer_noavg_unsafe(char *dest,const struct IPOINT_2D dest_pos, __attribute__((unused)) const struct IPOINT_2D dest_size, const unsigned int dest_scanln, const unsigned char *src,const struct IPOINT_2D src_pos,const struct IPOINT_2D src_size, const struct IPOINT_2D rect_size,struct PALETTE_ENTRY *pal,const struct IPOINT_2D scale) @@ -1251,7 +1251,7 @@ short draw_texture_on_buffer_noavg_unsafe(unsigned char *dest,const struct IPOIN * @param pal Texture palette. * @return Returns ERR_NONE on success, error code on failure. */ -short draw_texture_on_buffer_noscale(unsigned char *dest,const struct IPOINT_2D dest_pos, +short draw_texture_on_buffer_noscale(char *dest,const struct IPOINT_2D dest_pos, const struct IPOINT_2D dest_size, const unsigned int dest_scanln, const unsigned char *src,const struct IPOINT_2D src_pos,const struct IPOINT_2D src_size, const struct IPOINT_2D rect_size,struct PALETTE_ENTRY *pal) @@ -1305,7 +1305,7 @@ short draw_texture_on_buffer_noscale(unsigned char *dest,const struct IPOINT_2D * @param scale Destination buffer scale. * @return Returns ERR_NONE on success, error code on failure. */ -short draw_texture_on_buffer(unsigned char *dest,const struct IPOINT_2D dest_pos, +short draw_texture_on_buffer(char *dest,const struct IPOINT_2D dest_pos, const struct IPOINT_2D dest_size, const unsigned int dest_scanln, const unsigned char *src,const struct IPOINT_2D src_pos,const struct IPOINT_2D src_size, const struct IPOINT_2D rect_size,struct PALETTE_ENTRY *pal,const struct IPOINT_2D scale) @@ -1343,7 +1343,7 @@ short draw_texture_on_buffer(unsigned char *dest,const struct IPOINT_2D dest_pos * @param scale Destination buffer scale. * @return Returns ERR_NONE on success, error code on failure. */ -short draw_texture_on_buffer_unsafe(unsigned char *dest,const struct IPOINT_2D dest_pos, +short draw_texture_on_buffer_unsafe(char *dest,const struct IPOINT_2D dest_pos, const struct IPOINT_2D dest_size, const unsigned int dest_scanln, const unsigned char *src,const struct IPOINT_2D src_pos,const struct IPOINT_2D src_size, const struct IPOINT_2D rect_size,struct PALETTE_ENTRY *pal,const struct IPOINT_2D scale) @@ -1379,7 +1379,7 @@ short draw_texture_on_buffer_unsafe(unsigned char *dest,const struct IPOINT_2D d * @param scale Destination buffer scale. * @return Returns ERR_NONE on success, error code on failure. */ -short draw_texture_on_buffer_fast(unsigned char *dest,const struct IPOINT_2D dest_pos, +short draw_texture_on_buffer_fast(char *dest,const struct IPOINT_2D dest_pos, const struct IPOINT_2D dest_size, const unsigned int dest_scanln, const unsigned char *src,const struct IPOINT_2D src_pos,const struct IPOINT_2D src_size, const struct IPOINT_2D rect_size,struct PALETTE_ENTRY *pal,const struct IPOINT_2D scale) @@ -1413,7 +1413,7 @@ short draw_texture_on_buffer_fast(unsigned char *dest,const struct IPOINT_2D des * @param scale Destination buffer scale. * @return Returns ERR_NONE on success, error code on failure. */ -short draw_texture_on_buffer_fast_unsafe(unsigned char *dest,const struct IPOINT_2D dest_pos, +short draw_texture_on_buffer_fast_unsafe(char *dest,const struct IPOINT_2D dest_pos, const struct IPOINT_2D dest_size, const unsigned int dest_scanln, const unsigned char *src,const struct IPOINT_2D src_pos,const struct IPOINT_2D src_size, const struct IPOINT_2D rect_size,struct PALETTE_ENTRY *pal,const struct IPOINT_2D scale) diff --git a/libadikted/globals.h b/libadikted/globals.h index bca8705..9d05214 100644 --- a/libadikted/globals.h +++ b/libadikted/globals.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/libadikted/lev_files.c b/libadikted/lev_files.c index 7fcb9a3..f312dad 100644 --- a/libadikted/lev_files.c +++ b/libadikted/lev_files.c @@ -691,7 +691,6 @@ short load_wlb(struct LEVEL *lvl,char *fname) short load_slx(struct LEVEL *lvl,char *fname) { message_log(" load_slx: started"); - short result; FILE *F = fopen(fname, "rb"); if (F == NULL) return ERR_FILE_BADDATA; diff --git a/libadikted/lev_script.c b/libadikted/lev_script.c index 9a34db8..e60961e 100644 --- a/libadikted/lev_script.c +++ b/libadikted/lev_script.c @@ -16,6 +16,7 @@ /******************************************************************************/ #include +#include #include "lev_script.h" @@ -518,32 +519,40 @@ const char *cmd_font_fullnames[]={ const char *object_available_shortnames[]={ "None", "Rsch", "Got",}; -short script_param_to_int(int *val,const char *param) +int script_param_to_s32(const char *param, int* e) { - if ((param==NULL)||(val==NULL)) return false; - int n_read; - if (strncmp(param,"0x",2)==0) - { - n_read=sscanf(param+2,"%x",val); - } else - { - n_read=sscanf(param,"%d",val); - } - return (n_read==1); + if (param==NULL) { *e = -1; return -1; } + return strtoi(param, NULL, 0, 0, INT_MAX, e); } -short script_param_to_ulong(unsigned long *val,const char *param) +unsigned int script_param_to_u32(const char *param, int* e) { - if ((param==NULL)||(val==NULL)) return false; - int n_read; - if (strncmp(param,"0x",2)==0) - { - n_read=sscanf(param+2,"%lx",val); - } else - { - n_read=sscanf(param,"%lu",val); - } - return (n_read==1); + if (param==NULL) { *e = -1; return UINT_MAX; } + return strtou(param, NULL, 0, 0, UINT_MAX, e); +} + +bool script_param_read_s32(int* dst, size_t count, unsigned char** params) +{ + int result[count]; + for(size_t i = 0; i < count; i++) + { + dst[i] = script_param_to_s32((const char*)params[i], &result[i]); + if (result[i] != 0) + return false; + } + return true; +} + +bool script_param_read_u32(unsigned int* dst, size_t count, unsigned char** params) +{ + int result[count]; + for(size_t i = 0; i < count; i++) + { + dst[i] = script_param_to_u32((const char*)params[i], &result[i]); + if (result[i] != 0) + return false; + } + return true; } /* @@ -560,33 +569,21 @@ short execute_adikted_command(struct LEVEL *lvl,struct DK_SCRIPT_COMMAND *cmd,ch sprintf(err_msg,"%s requires more parameters",adikted_cmd_text(cmd->index)); return false; } - int sx=-1,sy=-1; - short result=true; - result&=script_param_to_int(&sx,cmd->params[0]); - result&=script_param_to_int(&sy,cmd->params[1]); - if (!result) + int s[2] = { -1 }; + if(!script_param_read_s32(s, 2, &cmd->params[0])) { sprintf(err_msg,"Cannot read map subtile coordinates"); return false; } - int wib_val; - int lintel; - int orient; - int base; - result&=script_param_to_int(&wib_val,cmd->params[2]); - result&=script_param_to_int(&lintel,cmd->params[3]); - result&=script_param_to_int(&orient,cmd->params[4]); - result&=script_param_to_int(&base,cmd->params[5]); - if (!result) + int p[4]; + if(script_param_read_s32(p, 4, &cmd->params[2])) { sprintf(err_msg,"Cannot read basic column parameters"); return false; } int c[8]; int i; - for (i=0;i<8;i++) - result&=script_param_to_int(&c[i],cmd->params[6+i]); - if (!result) + if(!script_param_read_s32(c, 8, &cmd->params[6+i])) { sprintf(err_msg,"Cannot read column cubes"); return false; @@ -595,13 +592,13 @@ short execute_adikted_command(struct LEVEL *lvl,struct DK_SCRIPT_COMMAND *cmd,ch struct DK_CUSTOM_CLM *ccol; ccol=create_cust_col(); struct COLUMN_REC *clm_rec=ccol->rec; - ccol->wib_val=wib_val; - fill_column_rec_sim(clm_rec, 0, base, + ccol->wib_val=p[0]; + fill_column_rec_sim(clm_rec, 0, p[3], c[0],c[1],c[2],c[3],c[4],c[5],c[6],c[7]); - clm_rec->lintel=lintel; - clm_rec->orientation=orient; + clm_rec->lintel=p[1]; + clm_rec->orientation=p[2]; /*Adding custom column to level */ - cust_col_add_or_update(lvl,sx,sy,ccol); + cust_col_add_or_update(lvl,s[0],s[0],ccol); return true; case DEFINE_GRAFFITI: { @@ -610,18 +607,10 @@ short execute_adikted_command(struct LEVEL *lvl,struct DK_SCRIPT_COMMAND *cmd,ch sprintf(err_msg,"%s requires more parameters",adikted_cmd_text(cmd->index)); return false; } - int tx=-1,ty=-1,height=0; - short result=true; - result&=script_param_to_int(&tx,cmd->params[0]); - result&=script_param_to_int(&ty,cmd->params[1]); - if (!result) + int t[3] = { -1 }; + if(!script_param_read_s32(t, 3, &cmd->params[0])) { - sprintf(err_msg,"Cannot read map tile coordinates"); - return false; - } - if (sscanf(cmd->params[2],"%d",&height)<1) - { - sprintf(err_msg,"Cannot read height in tile"); + sprintf(err_msg,"Cannot read map tile coordinates/height"); return false; } int orient; @@ -633,7 +622,7 @@ short execute_adikted_command(struct LEVEL *lvl,struct DK_SCRIPT_COMMAND *cmd,ch int i,textlen; unsigned int cube=0x0184; /*Note: +2 is to skip 0x; must change this later... */ - if (sscanf(cmd->params[5]+2,"%x",&cube)<1) + if(!script_param_read_u32(&cube, 1, &cmd->params[5])) { sprintf(err_msg,"Cannot read filler cube index"); return false; @@ -650,7 +639,7 @@ short execute_adikted_command(struct LEVEL *lvl,struct DK_SCRIPT_COMMAND *cmd,ch text[i]=c; } text[textlen]='\0'; - int graf_idx=graffiti_add(lvl,tx,ty,height,text,font,orient,cube); + int graf_idx=graffiti_add(lvl,t[0],t[1],t[2],text,font,orient,cube); if (graf_idx<0) { sprintf(err_msg,"Cannot add graffiti"); @@ -664,18 +653,14 @@ short execute_adikted_command(struct LEVEL *lvl,struct DK_SCRIPT_COMMAND *cmd,ch sprintf(err_msg,"%s requires more parameters",adikted_cmd_text(cmd->index)); return false; } - short result=true; - unsigned long creat_date; - unsigned long lastsav_date; - result&=script_param_to_ulong(&creat_date,cmd->params[0]); - result&=script_param_to_ulong(&lastsav_date,cmd->params[1]); - if (!result) + unsigned int date[2]; + if(!script_param_read_u32(date, 2, cmd->params)) { sprintf(err_msg,"Cannot read level date parameters"); return false; } - lvl->info.creat_date=creat_date; - lvl->info.lastsav_date=lastsav_date; + lvl->info.creat_date=date[0]; + lvl->info.lastsav_date=date[1]; };return true; case USER_CMNDS_COUNT: { @@ -684,30 +669,24 @@ short execute_adikted_command(struct LEVEL *lvl,struct DK_SCRIPT_COMMAND *cmd,ch sprintf(err_msg,"%s requires more parameters",adikted_cmd_text(cmd->index)); return false; } - short result=true; - unsigned long ucmdcnt; - unsigned long umdswcnt,umslbcnt,ucrobcnt; - result&=script_param_to_ulong(&ucmdcnt,cmd->params[0]); - if (!result) + unsigned int count[4]; + if(!script_param_read_u32(count, 1, cmd->params)) { sprintf(err_msg,"Cannot read first user commands count parameter"); return false; } - lvl->info.usr_cmds_count=ucmdcnt; + lvl->info.usr_cmds_count=count[0]; /* The rest of parameters don't have to be present */ if (cmd->param_count>3) { - result&=script_param_to_ulong(&umdswcnt,cmd->params[1]); - result&=script_param_to_ulong(&umslbcnt,cmd->params[2]); - result&=script_param_to_ulong(&ucrobcnt,cmd->params[3]); - if (!result) - { - sprintf(err_msg,"Cannot read user commands count parameters"); - return false; - } - lvl->info.usr_mdswtch_count=umdswcnt; - lvl->info.usr_slbchng_count=umslbcnt; - lvl->info.usr_creatobj_count=ucrobcnt; + if(!script_param_read_u32(count, 3, &cmd->params[1])) + { + sprintf(err_msg,"Cannot read user commands count parameters"); + return false; + } + lvl->info.usr_mdswtch_count = count[1]; + lvl->info.usr_slbchng_count = count[2]; + lvl->info.usr_creatobj_count = count[3]; } };return true; case LEVEL_VERSION: @@ -717,19 +696,15 @@ short execute_adikted_command(struct LEVEL *lvl,struct DK_SCRIPT_COMMAND *cmd,ch sprintf(err_msg,"%s requires more parameters",adikted_cmd_text(cmd->index)); return false; } - short result=true; - int vma,vmi,vre; - result&=script_param_to_int(&vma,cmd->params[0]); - result&=script_param_to_int(&vmi,cmd->params[1]); - result&=script_param_to_int(&vre,cmd->params[2]); - if (!result) + int v[3]; + if(!script_param_read_s32(v, 3, cmd->params)) { - sprintf(err_msg,"Cannot read version parameters"); - return false; + sprintf(err_msg,"Cannot read version parameters"); + return false; } - lvl->info.ver_major=vma; - lvl->info.ver_minor=vmi; - lvl->info.ver_rel=vre; + lvl->info.ver_major=v[0]; + lvl->info.ver_minor=v[1]; + lvl->info.ver_rel=v[2]; };return true; case LEVEL_NAME: { @@ -860,7 +835,7 @@ short script_cmd_verify_arg_actnpt(__attribute__((unused)) struct SCRIPT_VERIFY_ return false; } int val; - if (!script_param_to_int(&val,param)) + if (!script_param_read_s32(&val, 1, (unsigned char**)¶m)) { if (strlen(param) <= 16) sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param); @@ -921,7 +896,7 @@ short script_cmd_verify_arg_gameturn(__attribute__((unused)) struct SCRIPT_VERIF return false; } int val; - if (!script_param_to_int(&val,param)) + if (!script_param_read_s32(&val, 1, (unsigned char**)¶m)) { if (strlen(param) <= 16) sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param); @@ -965,7 +940,7 @@ short script_cmd_verify_arg_goldamnt(__attribute__((unused)) struct SCRIPT_VERIF return false; } int val; - if (!script_param_to_int(&val,param)) + if (!script_param_read_s32(&val, 1, (unsigned char**)¶m)) { if (strlen(param) <= 16) sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param); @@ -1009,7 +984,7 @@ short script_cmd_verify_arg_experience(__attribute__((unused)) struct SCRIPT_VER return false; } int val; - if (!script_param_to_int(&val,param)) + if (!script_param_read_s32(&val, 1, (unsigned char**)¶m)) { if (strlen(param) <= 16) sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param); @@ -1050,7 +1025,7 @@ short script_cmd_verify_arg_ncrtrs(__attribute__((unused)) struct SCRIPT_VERIFY_ return false; } int val; - if (!script_param_to_int(&val,param)) + if (!script_param_read_s32(&val, 1, (unsigned char**)¶m)) { if (strlen(param) <= 16) sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param); @@ -1204,7 +1179,7 @@ short script_cmd_verify_arg_btnparam(__attribute__((unused)) struct SCRIPT_VERIF return false; } int val; - if (!script_param_to_int(&val,param)) + if (!script_param_read_s32(&val, 1, (unsigned char**)¶m)) { if (strlen(param) <= 16) sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param); @@ -1375,7 +1350,7 @@ short script_cmd_verify_arg_limparam(__attribute__((unused)) struct SCRIPT_VERIF return false; } int val; - if (!script_param_to_int(&val,param)) + if (!script_param_read_s32(&val, 1, (unsigned char**)¶m)) { sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param); return false; @@ -1417,7 +1392,7 @@ short script_cmd_verify_arg_unsg_int(__attribute__((unused)) struct SCRIPT_VERIF return false; } int val; - if (!script_param_to_int(&val,param)) + if (!script_param_read_s32(&val, 1, (unsigned char**)¶m)) { sprintf(err_msg,"Internal - no numeric value for \"%s\" in script",param); return false; @@ -3159,7 +3134,7 @@ short script_decomposed_to_params_cmd_condit(struct DK_SCRIPT_PARAMETERS *par, par->end_level++; if (cmd->param_count<2) return false; - if (!script_param_to_int(&actnpt_num,cmd->params[0])) + if (!script_param_read_s32(&actnpt_num, 1, &cmd->params[0])) return false; plyr_idx=players_cmd_index(cmd->params[1]); if (plyr_idx<0) @@ -3222,9 +3197,9 @@ short script_decomposed_to_params_cmd_avail(struct DK_SCRIPT_PARAMETERS *par, object_idx=room_cmd_index(cmd->params[1]); if ((plyr_idx<0)||(object_idx<0)) return false; - if (!script_param_to_int(&logic_val,cmd->params[2])) + if (!script_param_read_s32(&logic_val, 1, &cmd->params[2])) return false; - if (!script_param_to_int(&amount,cmd->params[3])) + if (!script_param_read_s32(&amount, 1, &cmd->params[3])) return false; if (amount) available=AVAIL_INSTANT; @@ -3253,9 +3228,9 @@ short script_decomposed_to_params_cmd_avail(struct DK_SCRIPT_PARAMETERS *par, object_idx=creatures_cmd_index(cmd->params[1]); if ((plyr_idx<0)||(object_idx<0)) return false; - if (!script_param_to_int(&logic_val,cmd->params[2])) + if (!script_param_read_s32(&logic_val, 1, &cmd->params[2])) return false; - if (!script_param_to_int(&amount,cmd->params[3])) + if (!script_param_read_s32(&amount, 1, &cmd->params[3])) return false; if (amount) available=AVAIL_INSTANT; @@ -3284,9 +3259,9 @@ short script_decomposed_to_params_cmd_avail(struct DK_SCRIPT_PARAMETERS *par, object_idx=spell_cmd_index(cmd->params[1]); if ((plyr_idx<0)||(object_idx<0)) return false; - if (!script_param_to_int(&logic_val,cmd->params[2])) + if (!script_param_read_s32(&logic_val, 1, &cmd->params[2])) return false; - if (!script_param_to_int(&amount,cmd->params[3])) + if (!script_param_read_s32(&amount, 1, &cmd->params[3])) return false; if (amount) available=AVAIL_INSTANT; @@ -3315,9 +3290,9 @@ short script_decomposed_to_params_cmd_avail(struct DK_SCRIPT_PARAMETERS *par, object_idx=trap_cmd_index(cmd->params[1]); if ((plyr_idx<0)||(object_idx<0)) return false; - if (!script_param_to_int(&logic_val,cmd->params[2])) + if (!script_param_read_s32(&logic_val, 1, &cmd->params[2])) return false; - if (!script_param_to_int(&amount,cmd->params[3])) + if (!script_param_read_s32(&amount, 1, &cmd->params[3])) return false; if (plyr_idxparams[1]); if ((plyr_idx<0)||(object_idx<0)) return false; - if (!script_param_to_int(&logic_val,cmd->params[2])) + if (!script_param_read_s32(&logic_val, 1, &cmd->params[2])) return false; - if (!script_param_to_int(&amount,cmd->params[3])) + if (!script_param_read_s32(&amount, 1, &cmd->params[3])) return false; if (plyr_idxparam_count<1) return false; - if (!script_param_to_int(&amount,cmd->params[0])) + if (!script_param_read_s32(&amount, 1, &cmd->params[0])) return false; par->portal_gen_speed=amount; break; @@ -3405,7 +3380,7 @@ short script_decomposed_to_params_cmd_setup(struct DK_SCRIPT_PARAMETERS *par, plyr_idx=players_cmd_index(cmd->params[0]); if (plyr_idx<0) return false; - if (!script_param_to_int(&amount,cmd->params[1])) + if (!script_param_read_s32(&amount, 1, &cmd->params[1])) return false; if (plyr_idxparams[0]); if (plyr_idx<0) return false; - if (!script_param_to_int(&amount,cmd->params[1])) + if (!script_param_read_s32(&amount, 1, &cmd->params[1])) return false; if (plyr_idxparams[0]); if ((plyr_idx<0)) return false; - if (!script_param_to_int(&amount,cmd->params[1])) + if (!script_param_read_s32(&amount, 1, &cmd->params[1])) return false; if (plyr_idxparam_count<1) return false; - if (!script_param_to_int(&logic_val,cmd->params[0])) + if (!script_param_read_s32(&logic_val, 1, &cmd->params[0])) return false; par->dead_return_to_pool=(logic_val!=0); break; @@ -3580,7 +3555,7 @@ short script_decomposed_to_params_cmd_crtradj(struct DK_SCRIPT_PARAMETERS *par, crtr_idx=creatures_cmd_index(cmd->params[0]); if (crtr_idx<0) return false; - if (!script_param_to_int(&amount,cmd->params[1])) + if (!script_param_read_s32(&amount, 1, &cmd->params[1])) return false; par->creature_pool[crtr_idx]=amount; break; @@ -3591,7 +3566,7 @@ short script_decomposed_to_params_cmd_crtradj(struct DK_SCRIPT_PARAMETERS *par, crtr_idx=creatures_cmd_index(cmd->params[1]); if ((plyr_idx<0)||(crtr_idx<0)) return false; - if (!script_param_to_int(&amount,cmd->params[2])) + if (!script_param_read_s32(&amount, 1, &cmd->params[2])) return false; if (plyr_idxparams[0]); if (crtr_idx<0) return false; - if (!script_param_to_int(&amount,cmd->params[1])) + if (!script_param_read_s32(&amount, 1, &cmd->params[1])) return false; /*TODO */ break; @@ -3622,7 +3597,7 @@ short script_decomposed_to_params_cmd_crtradj(struct DK_SCRIPT_PARAMETERS *par, crtr_idx=creatures_cmd_index(cmd->params[0]); if (crtr_idx<0) return false; - if (!script_param_to_int(&amount,cmd->params[1])) + if (!script_param_read_s32(&amount, 1, &cmd->params[1])) return false; /*TODO */ break; @@ -3632,7 +3607,7 @@ short script_decomposed_to_params_cmd_crtradj(struct DK_SCRIPT_PARAMETERS *par, crtr_idx=creatures_cmd_index(cmd->params[0]); if (crtr_idx<0) return false; - if (!script_param_to_int(&amount,cmd->params[1])) + if (!script_param_read_s32(&amount, 1, &cmd->params[1])) return false; /*TODO */ break; @@ -3642,7 +3617,7 @@ short script_decomposed_to_params_cmd_crtradj(struct DK_SCRIPT_PARAMETERS *par, crtr_idx=creatures_cmd_index(cmd->params[0]); if (crtr_idx<0) return false; - if (!script_param_to_int(&amount,cmd->params[1])) + if (!script_param_read_s32(&amount, 1, &cmd->params[1])) return false; /*TODO */ break; @@ -4595,7 +4570,7 @@ int special_cmd_index(const char *cmdtext) if (stricmp(random_cmdtext,cmdtext)==0) return SPEC_RANDOM; int val; - if (script_param_to_int(&val,cmdtext)) + if (script_param_read_s32(&val, 1, (unsigned char**)&cmdtext)) return SPEC_NUMBER; return -1; } diff --git a/libadikted/lev_script.h b/libadikted/lev_script.h index 6bd9173..05f668e 100644 --- a/libadikted/lev_script.h +++ b/libadikted/lev_script.h @@ -477,8 +477,10 @@ DLLIMPORT void script_command_renew(struct DK_SCRIPT_COMMAND **cmd); DLLIMPORT void script_command_free(struct DK_SCRIPT_COMMAND *cmd); DLLIMPORT char *get_orientation_shortname(unsigned short orient); DLLIMPORT char *get_font_longname(unsigned short font); -DLLIMPORT short script_param_to_int(int *val,const char *param); -DLLIMPORT short script_param_to_ulong(unsigned long *val,const char *param); +DLLIMPORT int script_param_to_s32(const char *param, int* e); +DLLIMPORT unsigned int script_param_to_u32(const char *param, int* e); +DLLIMPORT bool script_param_read_s32(int* dst, size_t count, unsigned char** params); +DLLIMPORT bool script_param_read_u32(unsigned int* dst, size_t count, unsigned char** params); DLLIMPORT const char *script_cmd_text(const int group,const int cmdidx,const char *prev_val); DLLIMPORT short is_no_bracket_command(int group,int cmdidx); DLLIMPORT char *script_strword( const char *str, const short whole_rest ); diff --git a/libadikted/libadikted.pc.in b/libadikted/libadikted.pc.in new file mode 100644 index 0000000..44b2849 --- /dev/null +++ b/libadikted/libadikted.pc.in @@ -0,0 +1,12 @@ +prefix=@install_prefix@ +exe_prefix=${prefix} +libdir=${prefix}/@install_libdir@ +includedir=${prefix}/@install_includedir@ + +Name: lib@target_name@ +Description: @PROJECT_DESCRIPTION@ +Version: @PROJECT_VERSION@ + +Requires: +Libs: -L${libdir} -l@target_name@ @stdclib@ +Cflags: -I${includedir} -I${includedir}/@target_name@ diff --git a/mapslang/CMakeLists.txt b/mapslang/CMakeLists.txt new file mode 100644 index 0000000..a82d9d2 --- /dev/null +++ b/mapslang/CMakeLists.txt @@ -0,0 +1,80 @@ +cmake_minimum_required( VERSION 3.5 ) +project(mapslang LANGUAGES C) +set(TARGET_NAME map) + +include(FindPkgConfig) +include(CMakePackageConfigHelpers) + +set_property( GLOBAL PROPERTY USE_FOLDERS ON ) +set( CMAKE_C_STANDARD 99 ) +set( CMAKE_C_STANDARD_REQUIRED ON ) +set( CMAKE_C_EXTENSIONS ON ) +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-discarded-qualifiers -Wno-unused-result -Wno-unused-parameter" ) +add_definitions( -DINSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${TARGET_NAME}" ) + +set( MAPSLANG_LIBRARY_TYPE "STATIC" CACHE STRING "Linking type for library" ) + +set_property( CACHE MAPSLANG_LIBRARY_TYPE PROPERTY STRINGS STATIC SHARED ) + +if( MAPSLANG_LIBRARY_TYPE MATCHES "SHARED" ) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() + +if(POLICY CMP0072) + cmake_policy(SET CMP0072 NEW) +endif() + +# Add Math::Math +include(cmake/FindMath.cmake) + +# check for installed slang +pkg_search_module(SLANG REQUIRED slang) +# check for installed libadikted +pkg_search_module(ADIKTED REQUIRED libadikted) + +# Grab the keeperfx source files +file( GLOB MAPSLANG_SOURCES input_kb.c main.c output_scr.c scr_actn.c scr_clm.c scr_cube.c scr_help.c scr_list.c scr_rwrk.c scr_slab.c scr_thing.c scr_tileset.c scr_txted.c scr_txtgen.c textmenu.c var_utils.c ) + +add_executable( ${TARGET_NAME} ${MAPSLANG_SOURCES} ) +target_include_directories( ${TARGET_NAME} + PUBLIC Math::Math + $ + $ + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..) + +target_compile_options( ${TARGET_NAME} PUBLIC ${ADIKTED_CFLAGS} ${SLANG_CFLAGS}) +target_link_directories( ${TARGET_NAME} PUBLIC + $ + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../libadikted ) +target_link_libraries( ${TARGET_NAME} PUBLIC ${ADIKTED_LIBRARIES} + ${SLANG_LIBRARIES} Math::Math) + +# Put in a "mapslang" folder in Visual Studio +set_target_properties( ${TARGET_NAME} PROPERTIES FOLDER "mapslang" ) + +# Special Visual Studio Flags +if( MSVC ) + target_compile_definitions( ${TARGET_NAME} PRIVATE "_CRT_SECURE_NO_WARNINGS" ) +endif() + +if ("${CMAKE_BUILD_TYPE}" STREQUAL "") + set(CMAKE_BUILD_TYPE "None") +endif () + +set(uppercase_CMAKE_BUILD_TYPE TOUPPER "${CMAKE_BUILD_TYPE}" "NONE") +# Add debug config required in keeperfx headers since bx is private +if ( uppercase_CMAKE_BUILD_TYPE} STREQUAL "DEBUG" ) + target_compile_definitions( ${TARGET_NAME} PUBLIC "MAP_DEBUG=0" ) +endif() + +install( TARGETS map + EXPORT "${TARGETS_EXPORT_NAME}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + RESOURCE DESTINATION "${CMAKE_INSTALL_DATADIR}/${TARGET_NAME}" + INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + ) + +install(FILES map.hlp map.ini map.ico DESTINATION "${CMAKE_INSTALL_DATADIR}/${TARGET_NAME}" + COMPONENT Resources ) diff --git a/mapslang/Makefile b/mapslang/Makefile.win similarity index 95% rename from mapslang/Makefile rename to mapslang/Makefile.win index 8a1b97f..41dfe09 100644 --- a/mapslang/Makefile +++ b/mapslang/Makefile.win @@ -82,15 +82,15 @@ WARNFLAGS = -Wall -Wextra -Werror-implicit-function-declaration -Wno-co PLATFORM_FLAGS = -march=i486 CSTANDARD = -std=gnu99 CC = $(CROSS_COMPILE)gcc$(CROSS_EXEEXT) $(CSTANDARD) $(WARNFLAGS) -CFLAGS = -c -O -I. -I../lib/$(SLANG_NAME)/src $(DLL_FLAG) $(PLATFORM_FLAGS) -CFLAGS_DEBUG = -c -g -I. -I../lib/$(SLANG_NAME)/src $(DLL_FLAG) $(PLATFORM_FLAGS) -DDEBUG +CFLAGS = -c -O -I.. -I. -I../lib/$(SLANG_NAME)/src $(DLL_FLAG) $(PLATFORM_FLAGS) +CFLAGS_DEBUG = -c -g -I.. -I. -I../lib/$(SLANG_NAME)/src $(DLL_FLAG) $(PLATFORM_FLAGS) -DDEBUG LINK = $(CROSS_COMPILE)gcc$(CROSS_EXEEXT) WINDRES = $(CROSS_COMPILE)windres$(CROSS_EXEEXT) RES = obj/map_private.res RC = map_private.rc LFLAGS = -static-libgcc $(PLATFORM_FLAGS) LFLAGS_DEBUG = -static-libgcc $(PLATFORM_FLAGS) -DDEBUG -LIBS = -L. -L../libadikted/bin -L..$(SLANG_BIN_FOLDER) -lslang -ladikted +LIBS = -L.. -L. -Llibadikted/bin -L..$(SLANG_BIN_FOLDER) -lslang -ladikted SRC = \ input_kb.c \ main.c \ diff --git a/mapslang/cmake/FindMath.cmake b/mapslang/cmake/FindMath.cmake new file mode 100644 index 0000000..ca854c9 --- /dev/null +++ b/mapslang/cmake/FindMath.cmake @@ -0,0 +1,76 @@ +include (CheckLibraryExists) +set(Math_FOUND FALSE) +set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET}) +set(CMAKE_REQUIRED_QUIET ${Math_FIND_QUIETLY}) + +if(CMAKE_C_COMPILER_LOADED) + include (CheckIncludeFile) + include (CheckCSourceCompiles) +elseif(CMAKE_CXX_COMPILER_LOADED) + include (CheckIncludeFileCXX) + include (CheckCXXSourceCompiles) +else() + message(FATAL_ERROR "FindMath only works if either C or CXX language is enabled") +endif() + +set(MATH_C_CXX_TEST_SOURCE [====[ +#include + +int main() +{ + const double x = 7.3; + ceil(x); + acos(x); + sin(x); + sqrt(x); + + return 0; +} +]====]) + + +if(CMAKE_C_COMPILER_LOADED) + CHECK_INCLUDE_FILE("math.h" CMAKE_HAVE_MATH_H) +else() + CHECK_INCLUDE_FILE_CXX("math.h" CMAKE_HAVE_MATH_H) +endif() + +if(CMAKE_HAVE_MATH_H) + set(CMAKE_HAVE_MATH_LIBRARY) + + set(CMAKE_REQUIRED_LIBRARIES -lm) + if(CMAKE_C_COMPILER_LOADED) + CHECK_C_SOURCE_COMPILES("${MATH_C_CXX_TEST_SOURCE}" CMAKE_HAVE_LIBC_LIBM) + elseif(CMAKE_CXX_COMPILER_LOADED) + CHECK_CXX_SOURCE_COMPILES("${MATH_C_CXX_TEST_SOURCE}" CMAKE_HAVE_LIBC_LIBM) + endif() + + if(CMAKE_HAVE_LIBC_LIBM) + set(CMAKE_MATH_LIBS_INIT ${CMAKE_REQUIRED_LIBRARIES}) + set(CMAKE_HAVE_MATH_LIBRARY 1) + set(Math_FOUND TRUE) + else() + set(Math_FOUND FALSE) + endif() + + unset(CMAKE_REQUIRED_LIBRARIES) + set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE}) + + include(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(Math DEFAULT_MSG Math_FOUND) + + if(MATH_FOUND AND NOT TARGET Math::Math) + add_library(Math::Math INTERFACE IMPORTED) + + if(CMAKE_MATH_LIBS_INIT) + set_property(TARGET Math::Math PROPERTY INTERFACE_LINK_LIBRARIES "${CMAKE_MATH_LIBS_INIT}") + endif() + elseif(NOT MATH_FOUND) + file(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if compiler accepts -lm failed with the following output:\n${_cmake_find_math_output}\n\n") + message(SEND_ERROR "Required Math library not found!") + endif() +endif() + +unset(_cmake_find_math_output) diff --git a/mapslang/input_kb.c b/mapslang/input_kb.c index db2cd6b..5fa6ce1 100644 --- a/mapslang/input_kb.c +++ b/mapslang/input_kb.c @@ -23,7 +23,7 @@ #include #include "output_scr.h" #include "var_utils.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" short input_initied=false; short disable_sounds=false; diff --git a/mapslang/main.c b/mapslang/main.c index 683cea1..882ffe6 100644 --- a/mapslang/main.c +++ b/mapslang/main.c @@ -4,14 +4,14 @@ #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "scr_actn.h" #include "scr_help.h" #include "scr_txted.h" #include "input_kb.h" #include "var_utils.h" -const char config_filename[]="map.ini"; +char *config_filename = NULL; void read_init(struct SCRMODE_DATA *scrmode,struct WORKMODE_DATA *workdata) { @@ -21,7 +21,13 @@ void read_init(struct SCRMODE_DATA *scrmode,struct WORKMODE_DATA *workdata) char buffer[READ_BUFSIZE]; char *p; int l; - + + if(format_data_fname(&config_filename, INSTALL_DATADIR, "%s", "map.ini") == false) + { + message_info_force("Couldn't concatenate data_dir and config_filename string, defaults loaded."); + return; + } + FILE *fp; fp = fopen (config_filename, "rb"); // If we can't get anything, warn but don't die diff --git a/mapslang/output_scr.c b/mapslang/output_scr.c index 86bdd60..41b1451 100644 --- a/mapslang/output_scr.c +++ b/mapslang/output_scr.c @@ -20,7 +20,7 @@ #include "output_scr.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include #include "scr_actn.h" diff --git a/mapslang/scr_actn.c b/mapslang/scr_actn.c index 0086296..224ec0d 100644 --- a/mapslang/scr_actn.c +++ b/mapslang/scr_actn.c @@ -23,7 +23,7 @@ #include #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "var_utils.h" #include "output_scr.h" #include "input_kb.h" diff --git a/mapslang/scr_actn.h b/mapslang/scr_actn.h index 61d9417..cca0eef 100644 --- a/mapslang/scr_actn.h +++ b/mapslang/scr_actn.h @@ -21,7 +21,7 @@ #ifndef ADIKT_SCRACTN_H #define ADIKT_SCRACTN_H -#include "../libadikted/globals.h" +#include "libadikted/globals.h" struct LEVEL; diff --git a/mapslang/scr_clm.c b/mapslang/scr_clm.c index 64baebd..d0498b7 100644 --- a/mapslang/scr_clm.c +++ b/mapslang/scr_clm.c @@ -21,7 +21,7 @@ #include "scr_clm.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "output_scr.h" #include "input_kb.h" #include "scr_actn.h" diff --git a/mapslang/scr_cube.c b/mapslang/scr_cube.c index 90c023f..19a9db1 100644 --- a/mapslang/scr_cube.c +++ b/mapslang/scr_cube.c @@ -20,7 +20,7 @@ #include "scr_cube.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "output_scr.h" #include "input_kb.h" #include "scr_actn.h" diff --git a/mapslang/scr_help.c b/mapslang/scr_help.c index e6b5741..c915f68 100644 --- a/mapslang/scr_help.c +++ b/mapslang/scr_help.c @@ -21,7 +21,7 @@ #include "scr_help.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "scr_actn.h" #include "output_scr.h" #include "input_kb.h" @@ -29,7 +29,7 @@ // Help variables -const char *help_filename="map.hlp"; +char *help_filename = NULL; const int itm_desc_rows=8; short init_help(struct SCRMODE_DATA *scrmode,struct WORKMODE_DATA *workdata) @@ -47,6 +47,13 @@ short init_help(struct SCRMODE_DATA *scrmode,struct WORKMODE_DATA *workdata) char ***what; FILE *fp; strcpy (title, ""); + + if(format_data_fname(&help_filename, INSTALL_DATADIR, "%s", "map.hlp") == false) + { + message_info("Error concatenating data_dir and help_filename."); + return false; + } + fp = fopen (help_filename, "rb"); // Non-fatal error if (!fp) diff --git a/mapslang/scr_help.h b/mapslang/scr_help.h index aff5dc4..38d5e1b 100644 --- a/mapslang/scr_help.h +++ b/mapslang/scr_help.h @@ -28,6 +28,11 @@ struct WORKMODE_DATA; #define DHFLAG_USE_COLORS 1 +#ifndef INSTALL_DATADIR +#define INSTALL_DATADIR "." +#endif + + struct HelpInfo { int numrows; diff --git a/mapslang/scr_list.c b/mapslang/scr_list.c index 5f723c6..a7a743f 100644 --- a/mapslang/scr_list.c +++ b/mapslang/scr_list.c @@ -21,7 +21,7 @@ #include "scr_list.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "output_scr.h" #include "input_kb.h" #include "scr_actn.h" diff --git a/mapslang/scr_rwrk.c b/mapslang/scr_rwrk.c index 567b568..b9b71fe 100644 --- a/mapslang/scr_rwrk.c +++ b/mapslang/scr_rwrk.c @@ -20,7 +20,7 @@ #include "scr_rwrk.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "output_scr.h" #include "input_kb.h" #include "scr_actn.h" diff --git a/mapslang/scr_slab.c b/mapslang/scr_slab.c index 515b056..7e437f7 100644 --- a/mapslang/scr_slab.c +++ b/mapslang/scr_slab.c @@ -22,7 +22,7 @@ #include "scr_slab.h" #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "output_scr.h" #include "input_kb.h" #include "scr_actn.h" diff --git a/mapslang/scr_thing.c b/mapslang/scr_thing.c index 232c7f5..b838ef3 100644 --- a/mapslang/scr_thing.c +++ b/mapslang/scr_thing.c @@ -22,7 +22,7 @@ #include "scr_thing.h" #include -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "scr_help.h" #include "output_scr.h" #include "input_kb.h" diff --git a/mapslang/scr_tileset.c b/mapslang/scr_tileset.c index e81f61a..7fe633b 100644 --- a/mapslang/scr_tileset.c +++ b/mapslang/scr_tileset.c @@ -19,9 +19,9 @@ /******************************************************************************/ -#include "../libadikted/globals.h" -#include "../libadikted/lev_data.h" -#include "../libadikted/msg_log.h" +#include "libadikted/globals.h" +#include "libadikted/lev_data.h" +#include "libadikted/msg_log.h" #include "input_kb.h" #include "output_scr.h" #include "scr_actn.h" diff --git a/mapslang/scr_txted.c b/mapslang/scr_txted.c index bc9f902..205bc31 100644 --- a/mapslang/scr_txted.c +++ b/mapslang/scr_txted.c @@ -20,7 +20,7 @@ #include "scr_txted.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "output_scr.h" #include "input_kb.h" #include "scr_actn.h" diff --git a/mapslang/scr_txtgen.c b/mapslang/scr_txtgen.c index 1d349d8..2b26576 100644 --- a/mapslang/scr_txtgen.c +++ b/mapslang/scr_txtgen.c @@ -24,7 +24,7 @@ #include "scr_txtgen.h" -#include "../libadikted/adikted.h" +#include "libadikted/adikted.h" #include "var_utils.h" #include "input_kb.h" #include "output_scr.h" diff --git a/mapslang/textmenu.c b/mapslang/textmenu.c index c38485c..5dbc485 100644 --- a/mapslang/textmenu.c +++ b/mapslang/textmenu.c @@ -25,11 +25,12 @@ #include "textmenu.h" -#include "../libadikted/globals.h" +#include "libadikted/globals.h" #include "input_kb.h" #include "output_scr.h" #include "var_utils.h" + inline union _value menu_value_num(long num) { union _value ret; ret.num=num; return ret; } diff --git a/mapslang/textmenu.h b/mapslang/textmenu.h index a71ec51..7b5e2eb 100644 --- a/mapslang/textmenu.h +++ b/mapslang/textmenu.h @@ -20,7 +20,7 @@ #ifndef BULL_TEXTMENU_H #define BULL_TEXTMENU_H -#include "../libadikted/globals.h" +#include "libadikted/globals.h" #define MIT_NUMERIC 0 #define MIT_BOOLEAN 1 diff --git a/mapslang/var_utils.c b/mapslang/var_utils.c index 0b99b05..f0f630c 100644 --- a/mapslang/var_utils.c +++ b/mapslang/var_utils.c @@ -19,11 +19,11 @@ #include "var_utils.h" -#include "../libadikted/globals.h" +#include "libadikted/globals.h" #include #include "input_kb.h" -#include "../libadikted/msg_log.h" -#include "../libadikted/lev_data.h" +#include "libadikted/msg_log.h" +#include "libadikted/lev_data.h" #include "output_scr.h" #include "scr_actn.h"