From 5de3cd7e83ce041360403d8d28ea2616283bc6f9 Mon Sep 17 00:00:00 2001 From: abma Date: Mon, 20 Feb 2012 17:26:22 +0100 Subject: [PATCH 01/38] initialze more vars + free memory --- Image.cpp | 5 +++-- SMFMap.cpp | 4 ++-- TileStorage.cpp | 2 +- decompiler.cpp | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Image.cpp b/Image.cpp index 9bb0446..a35bef0 100644 --- a/Image.cpp +++ b/Image.cpp @@ -27,8 +27,9 @@ CannotLoadImageException::CannotLoadImageException(std::string path) : runtime_e Image::Image() { ilGenImages(1,&image); - - + w = 0; + h = 0; + d = 0; } void Image::GetRect(int x, int y, int w, int h,ILenum format, void * dest) diff --git a/SMFMap.cpp b/SMFMap.cpp index 6960b2b..11bdc2c 100644 --- a/SMFMap.cpp +++ b/SMFMap.cpp @@ -65,6 +65,7 @@ SMFMap::SMFMap(std::string smfname) typemap = NULL; minimap = NULL; vegetationmap = NULL; + m_tiles = NULL; FILE * smffile = fopen(smfname.c_str(),"rb"); if ( !smffile ) { @@ -238,8 +239,7 @@ SMFMap::SMFMap(std::string smfname) } fclose(smffile); delete [] dxt1data; - - + delete [] tilematrix; } void SMFMap::SetClamping(bool b) diff --git a/TileStorage.cpp b/TileStorage.cpp index 2be0454..7c32693 100644 --- a/TileStorage.cpp +++ b/TileStorage.cpp @@ -230,7 +230,7 @@ uint64_t TileStorage::AddTileOrGetSimiliar(uint8_t* data, float th, int compress }else if ( compresslevel == COMPRESS_REASONABLE_BESTQUALITY ) { float mindiff = 9999999.0f; - uint64_t besttile; + uint64_t besttile = 0; for ( std::list::iterator it = m_lasttiles.begin(); it != m_lasttiles.end(); it++ ) { float diff = tilediff(data,m_tiles[(*it)]); diff --git a/decompiler.cpp b/decompiler.cpp index 107d52c..6ff486a 100644 --- a/decompiler.cpp +++ b/decompiler.cpp @@ -85,6 +85,7 @@ int main(int argc, char** argv) } SMFMap * m = new SMFMap(mapfile); m->SaveSourceFiles(); + delete m; } } From 8b7c9150a2c91b8321ec675c67b133a8f92378ee Mon Sep 17 00:00:00 2001 From: abma Date: Mon, 20 Feb 2012 17:27:17 +0100 Subject: [PATCH 02/38] workaround weird win32 crash --- main.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main.cpp b/main.cpp index 39aa554..b4fcbea 100644 --- a/main.cpp +++ b/main.cpp @@ -16,8 +16,22 @@ void help(char ** argv) std::cout << "If you specify less than -490000 as ypos , it will calculate ypos depending on terrain height" << std::endl; } +#ifdef WIN32 +static void* ILAPIENTRY AllocFunc(const ILsizei Size) +{ + return malloc(Size); +} +static void ILAPIENTRY FreeFunc(const void * CONST_RESTRICT ptr) +{ + free((void*)ptr); +} +#endif + int main(int argc, char** argv) { +#ifdef WIN32 //FIXME: workaround weird win32 crash + ilSetMemory(AllocFunc, FreeFunc); +#endif ilInit(); if ( argc == 1 ) { From a17a7858c7a8e1e37a1e9fd331191e6a5fe42a8a Mon Sep 17 00:00:00 2001 From: abma Date: Mon, 20 Feb 2012 18:00:40 +0100 Subject: [PATCH 03/38] fix delete calls + free memory --- TileStorage.cpp | 4 ++-- main.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/TileStorage.cpp b/TileStorage.cpp index 7c32693..9d0f3ec 100644 --- a/TileStorage.cpp +++ b/TileStorage.cpp @@ -58,10 +58,10 @@ void TileStorage::Reset() { if ( m_tiles_compressed.find((*it).first) != m_tiles_compressed.end() ) { - delete m_tiles_compressed[(*it).first]; + delete [] m_tiles_compressed[(*it).first]; } - delete (*it).second; + delete [] (*it).second; } m_tiles.clear(); m_lasttiles.clear(); diff --git a/main.cpp b/main.cpp index b4fcbea..35ee53e 100644 --- a/main.cpp +++ b/main.cpp @@ -253,6 +253,7 @@ int main(int argc, char** argv) } m->Compile(); + delete m; } } From 047b11d6920946a0dc90d55c00a48b820dcac4b4 Mon Sep 17 00:00:00 2001 From: abma Date: Mon, 20 Feb 2012 18:10:14 +0100 Subject: [PATCH 04/38] remove ifdefs --- main.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 35ee53e..cbfa533 100644 --- a/main.cpp +++ b/main.cpp @@ -16,7 +16,7 @@ void help(char ** argv) std::cout << "If you specify less than -490000 as ypos , it will calculate ypos depending on terrain height" << std::endl; } -#ifdef WIN32 + static void* ILAPIENTRY AllocFunc(const ILsizei Size) { return malloc(Size); @@ -25,13 +25,10 @@ static void ILAPIENTRY FreeFunc(const void * CONST_RESTRICT ptr) { free((void*)ptr); } -#endif int main(int argc, char** argv) { -#ifdef WIN32 //FIXME: workaround weird win32 crash - ilSetMemory(AllocFunc, FreeFunc); -#endif + ilSetMemory(AllocFunc, FreeFunc); //FIXME: remove this, workaround weird win32 crash ilInit(); if ( argc == 1 ) { From a25be415e592ed24810efe2b4aef9632519cf3c7 Mon Sep 17 00:00:00 2001 From: abma Date: Thu, 25 Sep 2014 21:15:10 +0200 Subject: [PATCH 05/38] merge conflict --- CMakeLists.txt | 27 +++++--- Image.h | 5 ++ cmake/FindDevIL.cmake | 143 ++++++++++++++++++++++++++++++++++++++++++ decompiler.cpp | 6 +- main.cpp | 7 ++- 5 files changed, 175 insertions(+), 13 deletions(-) create mode 100644 cmake/FindDevIL.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e757cf..5d1b7fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,32 +1,41 @@ project(SpringMapConvNG) cmake_minimum_required(VERSION 2.6) -#find_package(Qt4 REQUIRED) + +LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + + if (NOT MINGW ) - include_directories(${CMAKE_CURRENT_BINARY_DIR}) + include_directories(${CMAKE_CURRENT_BINARY_DIR} ${IL_INCLUDE_DIR}) else ( NOT MINGW ) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/winlibs/Devil_${ARCH}/include ) link_directories( ${PROJECT_SOURCE_DIR}/winlibs/Devil_${ARCH}/lib ${PROJECT_SOURCE_DIR}/winlibs/Devil_${ARCH} ) - endif ( NOT MINGW ) #qt4_automoc(${springMapConvNG_SRCS}) +find_package(ImageMagick COMPONENTS Magick++) find_package(DevIL REQUIRED) +include_directories(${ImageMagick_INCLUDE_DIRS}) + add_library(mapconv SHARED CRC.cpp Image.cpp SMFMap.cpp TileStorage.cpp ) add_library(mapconv_static STATIC CRC.cpp Image.cpp SMFMap.cpp TileStorage.cpp ) add_executable(springMapConvNG main.cpp) add_executable(smfdecompiler decompiler.cpp) + +set(MAPCONV_LIBS ${IL_LIBRARIES} ${ImageMagick_LIBRARIES}) + if (NOT MINGW ) -target_link_libraries(springMapConvNG IL ILU mapconv_static ) -target_link_libraries(mapconv IL ILU ) -target_link_libraries(smfdecompiler IL ILU mapconv_static ) + target_link_libraries(springMapConvNG mapconv_static ${MAPCONV_LIBS}) + target_link_libraries(mapconv ${IL_LIBRARIES}) + target_link_libraries(smfdecompiler mapconv_static ${MAPCONV_LIBS}) else ( NOT MINGW ) -target_link_libraries(springMapConvNG DevIL ILU mapconv ) -target_link_libraries(mapconv DevIL ILU ) -target_link_libraries(smfdecompiler DevIL ILU mapconv ) + target_link_libraries(springMapConvNG mapconv ${MAPCONV_LIBS}) + target_link_libraries(mapconv ${IL_LIBRARIES}) + target_link_libraries(smfdecompiler mapconv ${MAPCONV_LIBS}) endif ( NOT MINGW ) install(TARGETS springMapConvNG smfdecompiler RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin ) install(TARGETS mapconv_static ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ) install(TARGETS mapconv LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ) + diff --git a/Image.h b/Image.h index 00dc9c1..8000333 100644 --- a/Image.h +++ b/Image.h @@ -23,6 +23,11 @@ #include #include #include + +#ifdef SetPixelRGBA +#undef SetPixelRGBA +#endif + class CannotLoadImageException : public std::runtime_error { public: diff --git a/cmake/FindDevIL.cmake b/cmake/FindDevIL.cmake new file mode 100644 index 0000000..1f4e286 --- /dev/null +++ b/cmake/FindDevIL.cmake @@ -0,0 +1,143 @@ +# Downloaded from: http://www-id.imag.fr/FLOWVR/manual/flowvr-suite-src/flowvr-render/cmake/ +# License: GPL v2, http://www-id.imag.fr/FLOWVR/manual/flowvr-suite-src/flowvr-render/COPYING +# +# Modifications: +# 2008.01.16 Tobi Vollebregt -- changed Devil->DEVIL for consistency +# -- added devil, ilu, ilut alternative names for MinGW +# -- removed "looking for devil" status message + +# - Find DevIL +# Find the native DevIL includes and libraries. +# +# IL_INCLUDE_DIR - Where to find "IL/il.h", "IL/ilu.h" and "IL/ilut.h" +# IL_IL_LIBRARY - Path to the IL shared library +# IL_ILU_LIBRARY - Path to the ILU shared library +# IL_ILUT_LIBRARY - Path to the ILUT shared library +# IL_LIBRARIES - List of libraries when using IL +# IL_FOUND - True if IL is found. + +INCLUDE(FindPackageHandleStandardArgs) + +IF (IL_INCLUDE_DIR AND IL_IL_LIBRARY) + # Already in cache, be silent + SET(DevIL_FIND_QUIETLY TRUE) +ENDIF (IL_INCLUDE_DIR AND IL_IL_LIBRARY) + + + +set(IL_FIND_LIB_STD_ARGS + PATH_SUFFIXES + lib64 + lib + libs64 + libs + libs/Win32 + libs/Win64 + PATHS + ${PROJECT_BINARY_DIR} + ${PROJECT_SOURCE_DIR} + $ENV{LD_LIBRARY_PATH} + $ENV{LIBRARY_PATH} + /usr + /usr/local + /usr/bin + ) + +FIND_LIBRARY(IL_IL_LIBRARY + NAMES + IL + devil + DevIL + ${IL_FIND_LIB_STD_ARGS} +) + +FIND_LIBRARY(IL_ILU_LIBRARY + NAMES + ilu + ILU + ${IL_FIND_LIB_STD_ARGS} +) + +FIND_LIBRARY(IL_ILUT_LIBRARY + NAMES + ilut + ILUT + ${IL_FIND_LIB_STD_ARGS} +) + +SET(IL_LIBRARIES "") +IF (IL_IL_LIBRARY) + LIST(APPEND IL_LIBRARIES ${IL_IL_LIBRARY}) +ENDIF (IL_IL_LIBRARY) +IF (IL_ILU_LIBRARY) + LIST(APPEND IL_LIBRARIES ${IL_ILU_LIBRARY}) +ENDIF (IL_ILU_LIBRARY) +IF (IL_ILUT_LIBRARY) + LIST(APPEND IL_LIBRARIES ${IL_ILUT_LIBRARY}) +ENDIF (IL_ILUT_LIBRARY) + +GET_FILENAME_COMPONENT(IL_LIBRARY_DIR "${IL_IL_LIBRARY}" PATH) +GET_FILENAME_COMPONENT(IL_LIBRARY_SUPER_DIR "${IL_LIBRARY_DIR}" PATH) + + + +set(IL_FIND_HEADER_STD_ARGS + PATHS + ${PROJECT_BINARY_DIR}/include + ${PROJECT_SOURCE_DIR}/include + ${IL_LIBRARY_SUPER_DIR}/include + $ENV{CPATH} + /usr/local/include + /usr/include + NO_DEFAULT_PATH + ) + +FIND_FILE(IL_IL_HEADER IL/il.h + ${IL_FIND_INCLUDE_STD_ARGS} +) + +FIND_FILE(IL_ILU_HEADER IL/ilu.h + ${IL_FIND_INCLUDE_STD_ARGS} +) + +FIND_FILE(IL_ILUT_HEADER IL/ilut.h + ${IL_FIND_INCLUDE_STD_ARGS} +) + +FIND_PATH(IL_INCLUDE_DIR IL/il.h + ${IL_FIND_INCLUDE_STD_ARGS} +) + + + +# handle the QUIETLY and REQUIRED arguments and set IL_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(DevIL DEFAULT_MSG IL_IL_HEADER IL_INCLUDE_DIR IL_IL_LIBRARY IL_LIBRARIES) + +IF (IL_ILU_HEADER AND IL_ILU_LIBRARY) + SET(IL_ILU_FOUND TRUE) + IF (NOT DevIL_FIND_QUIETLY) + MESSAGE(STATUS "Found DevIL-ILU: ${IL_ILU_LIBRARY} - ${IL_ILU_HEADER}") + ENDIF (NOT DevIL_FIND_QUIETLY) +ELSE (IL_ILU_HEADER AND IL_ILU_LIBRARY) + SET(IL_ILU_FOUND FALSE) +ENDIF (IL_ILU_HEADER AND IL_ILU_LIBRARY) + +IF (IL_ILUT_HEADER AND IL_ILUT_LIBRARY) + SET(IL_ILUT_FOUND TRUE) + IF (NOT DevIL_FIND_QUIETLY) + MESSAGE(STATUS "Found DevIL-ILUT: ${IL_ILUT_LIBRARY} - ${IL_ILUT_HEADER}") + ENDIF (NOT DevIL_FIND_QUIETLY) +ELSE (IL_ILUT_HEADER AND IL_ILUT_LIBRARY) + SET(IL_ILUT_FOUND FALSE) +ENDIF (IL_ILUT_HEADER AND IL_ILUT_LIBRARY) + + + +MARK_AS_ADVANCED( + IL_INCLUDE_DIR + IL_IL_LIBRARY + IL_ILU_LIBRARY + IL_ILUT_LIBRARY + IL_LIBRARIES + ) diff --git a/decompiler.cpp b/decompiler.cpp index 6ff486a..ab9883e 100644 --- a/decompiler.cpp +++ b/decompiler.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include "SMFMap.h" @@ -8,6 +8,8 @@ #include #include #include +#else +#include #endif void help(char ** argv) { @@ -16,7 +18,7 @@ void help(char ** argv) } int main(int argc, char** argv) { - ilInit(); + Magick::InitializeMagick(*argv); if ( argc == 1 ) { diff --git a/main.cpp b/main.cpp index cbfa533..4180de1 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,7 @@ #include +#include #include #include #include "SMFMap.h" @@ -16,7 +17,7 @@ void help(char ** argv) std::cout << "If you specify less than -490000 as ypos , it will calculate ypos depending on terrain height" << std::endl; } - +/* static void* ILAPIENTRY AllocFunc(const ILsizei Size) { return malloc(Size); @@ -26,10 +27,12 @@ static void ILAPIENTRY FreeFunc(const void * CONST_RESTRICT ptr) free((void*)ptr); } +*/ int main(int argc, char** argv) { - ilSetMemory(AllocFunc, FreeFunc); //FIXME: remove this, workaround weird win32 crash +// ilSetMemory(AllocFunc, FreeFunc); //FIXME: remove this, workaround weird win32 crash ilInit(); + Magick::InitializeMagick(*argv); if ( argc == 1 ) { From a052d94e35712d8dce3e4e46764cc04ccc0d076d Mon Sep 17 00:00:00 2001 From: abma Date: Thu, 25 Sep 2014 21:10:16 +0200 Subject: [PATCH 06/38] add travis file --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4daf65e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: cpp +compiler: + - gcc + - clang +before_script: + - sudo apt-get install libdevil-dev libmagick++-dev + - cmake . +script: + - make + From dd4d16040483a63edc40834e62575b2ac4ca29bb Mon Sep 17 00:00:00 2001 From: abma Date: Thu, 25 Sep 2014 21:28:19 +0200 Subject: [PATCH 07/38] fix error: integer constant is too large for its type --- TileStorage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TileStorage.h b/TileStorage.h index 113dee6..23375e1 100644 --- a/TileStorage.h +++ b/TileStorage.h @@ -32,7 +32,7 @@ inline uint64_t tilechecksum( uint8_t * data ) r += data[x]*63018038201L*x*x; r ^= 13091204281L; r *= 13091204281L*x; - r *= 226673591177742970257407LL*data[x]; + r *= 108086391056891903ULL*data[x]; } Crc32 c; c.AddData(data,32*32*4); From 57dc3653b37696c4fe66feaa92316285b7b58385 Mon Sep 17 00:00:00 2001 From: abma Date: Thu, 25 Sep 2014 21:48:45 +0200 Subject: [PATCH 08/38] oops --- decompiler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/decompiler.cpp b/decompiler.cpp index ab9883e..619032e 100644 --- a/decompiler.cpp +++ b/decompiler.cpp @@ -18,6 +18,7 @@ void help(char ** argv) } int main(int argc, char** argv) { + ilInit(); Magick::InitializeMagick(*argv); if ( argc == 1 ) { From ea88b850f8d9fad16f44ddce0f240040bb2cbb48 Mon Sep 17 00:00:00 2001 From: abma Date: Thu, 25 Sep 2014 21:50:02 +0200 Subject: [PATCH 09/38] add .gitignore --- .gitignore | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aaeba20 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +/CMakeFiles +/CMakeCache.txt +/Makefile +/cmake_install.cmake + +*.swp +*.so +*.a +/smfdecompiler +/springMapConvNG From 6177c44cea7c254829ea08ee3517325f12fedae4 Mon Sep 17 00:00:00 2001 From: abma Date: Thu, 25 Sep 2014 22:22:56 +0200 Subject: [PATCH 10/38] force ImageMagick --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d1b7fe..68c2328 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ endif ( NOT MINGW ) #qt4_automoc(${springMapConvNG_SRCS}) -find_package(ImageMagick COMPONENTS Magick++) +find_package(ImageMagick REQUIRED COMPONENTS Magick++) find_package(DevIL REQUIRED) include_directories(${ImageMagick_INCLUDE_DIRS}) From 2886f1bb4fa79e1235579753d9d522e2313e9e85 Mon Sep 17 00:00:00 2001 From: abma Date: Thu, 25 Sep 2014 22:24:10 +0200 Subject: [PATCH 11/38] unused file --- SpringMapConvNG.kdev4 | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 SpringMapConvNG.kdev4 diff --git a/SpringMapConvNG.kdev4 b/SpringMapConvNG.kdev4 deleted file mode 100644 index 1966f2e..0000000 --- a/SpringMapConvNG.kdev4 +++ /dev/null @@ -1,4 +0,0 @@ -[Project] -Name=SpringMapConvNG -Manager=KDevCMakeManager -VersionControl= From 2025ee14e8737c17bdd54ff4b234ce6c6811e99d Mon Sep 17 00:00:00 2001 From: abma Date: Thu, 25 Sep 2014 22:26:02 +0200 Subject: [PATCH 12/38] add readme --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..d82fd4d --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# SpringMapConvNG + +SpringMapConvNG is a map compiler for the spring rts engine. + +it also contains a decompiler, smfdecompiler. + +for details see http://springrts.com/wiki/MapConvNG + +# compile + +to compile install g++/clang, cmake, ImageMagick-devel and DevIL-dev. then run + + cmake . + make From deac70366ff6682afc3b28d99a7dd5940498ce1b Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 21:42:18 +0200 Subject: [PATCH 13/38] remove unused imagemagick dependency --- CMakeLists.txt | 7 +------ README.md | 2 +- decompiler.cpp | 2 -- main.cpp | 13 ------------- 4 files changed, 2 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 68c2328..a67aa39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,19 +11,14 @@ else ( NOT MINGW ) link_directories( ${PROJECT_SOURCE_DIR}/winlibs/Devil_${ARCH}/lib ${PROJECT_SOURCE_DIR}/winlibs/Devil_${ARCH} ) endif ( NOT MINGW ) -#qt4_automoc(${springMapConvNG_SRCS}) - -find_package(ImageMagick REQUIRED COMPONENTS Magick++) find_package(DevIL REQUIRED) -include_directories(${ImageMagick_INCLUDE_DIRS}) - add_library(mapconv SHARED CRC.cpp Image.cpp SMFMap.cpp TileStorage.cpp ) add_library(mapconv_static STATIC CRC.cpp Image.cpp SMFMap.cpp TileStorage.cpp ) add_executable(springMapConvNG main.cpp) add_executable(smfdecompiler decompiler.cpp) -set(MAPCONV_LIBS ${IL_LIBRARIES} ${ImageMagick_LIBRARIES}) +set(MAPCONV_LIBS ${IL_LIBRARIES}) if (NOT MINGW ) target_link_libraries(springMapConvNG mapconv_static ${MAPCONV_LIBS}) diff --git a/README.md b/README.md index d82fd4d..0bfcc16 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ for details see http://springrts.com/wiki/MapConvNG # compile -to compile install g++/clang, cmake, ImageMagick-devel and DevIL-dev. then run +to compile install g++/clang, cmake, DevIL-dev. then run cmake . make diff --git a/decompiler.cpp b/decompiler.cpp index 619032e..dbe38e4 100644 --- a/decompiler.cpp +++ b/decompiler.cpp @@ -1,4 +1,3 @@ -#include #include #include #include "SMFMap.h" @@ -19,7 +18,6 @@ void help(char ** argv) int main(int argc, char** argv) { ilInit(); - Magick::InitializeMagick(*argv); if ( argc == 1 ) { diff --git a/main.cpp b/main.cpp index 4180de1..228bb12 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,6 @@ #include -#include #include #include #include "SMFMap.h" @@ -17,22 +16,10 @@ void help(char ** argv) std::cout << "If you specify less than -490000 as ypos , it will calculate ypos depending on terrain height" << std::endl; } -/* -static void* ILAPIENTRY AllocFunc(const ILsizei Size) -{ - return malloc(Size); -} -static void ILAPIENTRY FreeFunc(const void * CONST_RESTRICT ptr) -{ - free((void*)ptr); -} -*/ int main(int argc, char** argv) { -// ilSetMemory(AllocFunc, FreeFunc); //FIXME: remove this, workaround weird win32 crash ilInit(); - Magick::InitializeMagick(*argv); if ( argc == 1 ) { From f9180378b1b812a52092cf1cc6f69c37975a55ee Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 22:18:41 +0200 Subject: [PATCH 14/38] KISS: drop mapconv lib --- CMakeLists.txt | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a67aa39..0d7f4c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,34 +3,18 @@ cmake_minimum_required(VERSION 2.6) LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +find_package(DevIL REQUIRED) -if (NOT MINGW ) - include_directories(${CMAKE_CURRENT_BINARY_DIR} ${IL_INCLUDE_DIR}) -else ( NOT MINGW ) - include_directories(${CMAKE_CURRENT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/winlibs/Devil_${ARCH}/include ) - link_directories( ${PROJECT_SOURCE_DIR}/winlibs/Devil_${ARCH}/lib ${PROJECT_SOURCE_DIR}/winlibs/Devil_${ARCH} ) -endif ( NOT MINGW ) -find_package(DevIL REQUIRED) +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${IL_INCLUDE_DIR}) -add_library(mapconv SHARED CRC.cpp Image.cpp SMFMap.cpp TileStorage.cpp ) -add_library(mapconv_static STATIC CRC.cpp Image.cpp SMFMap.cpp TileStorage.cpp ) -add_executable(springMapConvNG main.cpp) -add_executable(smfdecompiler decompiler.cpp) +set(MAPCONV_FILES CRC.cpp Image.cpp SMFMap.cpp TileStorage.cpp) -set(MAPCONV_LIBS ${IL_LIBRARIES}) +add_executable(springMapConvNG main.cpp ${MAPCONV_FILES}) +add_executable(smfdecompiler decompiler.cpp ${MAPCONV_FILES}) -if (NOT MINGW ) - target_link_libraries(springMapConvNG mapconv_static ${MAPCONV_LIBS}) - target_link_libraries(mapconv ${IL_LIBRARIES}) - target_link_libraries(smfdecompiler mapconv_static ${MAPCONV_LIBS}) -else ( NOT MINGW ) - target_link_libraries(springMapConvNG mapconv ${MAPCONV_LIBS}) - target_link_libraries(mapconv ${IL_LIBRARIES}) - target_link_libraries(smfdecompiler mapconv ${MAPCONV_LIBS}) -endif ( NOT MINGW ) +target_link_libraries(springMapConvNG ${IL_LIBRARIES}) +target_link_libraries(smfdecompiler ${IL_LIBRARIES}) install(TARGETS springMapConvNG smfdecompiler RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin ) -install(TARGETS mapconv_static ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ) -install(TARGETS mapconv LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ) From 62415d1276330ec40c817791a139950e80728d7f Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 22:29:42 +0200 Subject: [PATCH 15/38] - --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d7f4c9..4fc7bd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") find_package(DevIL REQUIRED) -include_directories(${CMAKE_CURRENT_BINARY_DIR} ${IL_INCLUDE_DIR}) +include_directories(${IL_INCLUDE_DIR}) set(MAPCONV_FILES CRC.cpp Image.cpp SMFMap.cpp TileStorage.cpp) From c47295d671205887621258935efcf20fc0981fb5 Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 22:31:23 +0200 Subject: [PATCH 16/38] move source files into src/ --- CMakeLists.txt | 13 +++++++++---- CRC.cpp => src/CRC.cpp | 0 CRC.h => src/CRC.h | 0 Image.cpp => src/Image.cpp | 0 Image.h => src/Image.h | 0 SMFMap.cpp => src/SMFMap.cpp | 0 SMFMap.h => src/SMFMap.h | 0 TileStorage.cpp => src/TileStorage.cpp | 0 TileStorage.h => src/TileStorage.h | 0 decompiler.cpp => src/decompiler.cpp | 0 main.cpp => src/main.cpp | 0 11 files changed, 9 insertions(+), 4 deletions(-) rename CRC.cpp => src/CRC.cpp (100%) rename CRC.h => src/CRC.h (100%) rename Image.cpp => src/Image.cpp (100%) rename Image.h => src/Image.h (100%) rename SMFMap.cpp => src/SMFMap.cpp (100%) rename SMFMap.h => src/SMFMap.h (100%) rename TileStorage.cpp => src/TileStorage.cpp (100%) rename TileStorage.h => src/TileStorage.h (100%) rename decompiler.cpp => src/decompiler.cpp (100%) rename main.cpp => src/main.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fc7bd9..919a89f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,10 +8,15 @@ find_package(DevIL REQUIRED) include_directories(${IL_INCLUDE_DIR}) -set(MAPCONV_FILES CRC.cpp Image.cpp SMFMap.cpp TileStorage.cpp) - -add_executable(springMapConvNG main.cpp ${MAPCONV_FILES}) -add_executable(smfdecompiler decompiler.cpp ${MAPCONV_FILES}) +set(MAPCONV_FILES + src/CRC.cpp + src/Image.cpp + src/SMFMap.cpp + src/TileStorage.cpp +) + +add_executable(springMapConvNG src/main.cpp ${MAPCONV_FILES}) +add_executable(smfdecompiler src/decompiler.cpp ${MAPCONV_FILES}) target_link_libraries(springMapConvNG ${IL_LIBRARIES}) target_link_libraries(smfdecompiler ${IL_LIBRARIES}) diff --git a/CRC.cpp b/src/CRC.cpp similarity index 100% rename from CRC.cpp rename to src/CRC.cpp diff --git a/CRC.h b/src/CRC.h similarity index 100% rename from CRC.h rename to src/CRC.h diff --git a/Image.cpp b/src/Image.cpp similarity index 100% rename from Image.cpp rename to src/Image.cpp diff --git a/Image.h b/src/Image.h similarity index 100% rename from Image.h rename to src/Image.h diff --git a/SMFMap.cpp b/src/SMFMap.cpp similarity index 100% rename from SMFMap.cpp rename to src/SMFMap.cpp diff --git a/SMFMap.h b/src/SMFMap.h similarity index 100% rename from SMFMap.h rename to src/SMFMap.h diff --git a/TileStorage.cpp b/src/TileStorage.cpp similarity index 100% rename from TileStorage.cpp rename to src/TileStorage.cpp diff --git a/TileStorage.h b/src/TileStorage.h similarity index 100% rename from TileStorage.h rename to src/TileStorage.h diff --git a/decompiler.cpp b/src/decompiler.cpp similarity index 100% rename from decompiler.cpp rename to src/decompiler.cpp diff --git a/main.cpp b/src/main.cpp similarity index 100% rename from main.cpp rename to src/main.cpp From 9ec610750733295536ce0d89721a443bcfde7b39 Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 22:33:41 +0200 Subject: [PATCH 17/38] update .gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index aaeba20..add6e85 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,8 @@ *.a /smfdecompiler /springMapConvNG +/.ninja_deps +/.ninja_log +/build.ninja +/rules.ninja + From 10dd0697feb718016fadc308db581a8e0aec3c58 Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 22:36:44 +0200 Subject: [PATCH 18/38] - --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4daf65e..765bf46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ compiler: - gcc - clang before_script: - - sudo apt-get install libdevil-dev libmagick++-dev + - sudo apt-get install libdevil-dev - cmake . script: - make From 643f7a4f4005f5e4091028145d60ad389baa6dbf Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 22:40:17 +0200 Subject: [PATCH 19/38] add clang-format file + format files! (nlc) --- .clang-format | 27 + src/CRC.cpp | 18 +- src/CRC.h | 14 +- src/Image.cpp | 178 +++---- src/Image.h | 80 +-- src/SMFMap.cpp | 1159 ++++++++++++++++++++----------------------- src/SMFMap.h | 143 +++--- src/TileStorage.cpp | 335 ++++++------- src/TileStorage.h | 82 ++- src/decompiler.cpp | 127 ++--- src/main.cpp | 432 ++++++++-------- 11 files changed, 1206 insertions(+), 1389 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..ee01f0d --- /dev/null +++ b/.clang-format @@ -0,0 +1,27 @@ +BasedOnStyle: LLVM +AccessModifierOffset: -8 +AlignEscapedNewlinesLeft: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AlwaysBreakTemplateDeclarations: false +BinPackParameters: true +ColumnLimit: 0 +ConstructorInitializerAllOnOneLineOrOnePerLine: false +DerivePointerBinding: false +IndentCaseLabels: true +MaxEmptyLinesToKeep: 2 +ObjCSpaceBeforeProtocolList: true +PenaltyBreakComment: 45 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 75 +PointerBindsToType: true +PointerAlignment: Left +SpacesBeforeTrailingComments: 1 +Standard: Auto +IndentWidth: 8 +UseTab: Always +BreakBeforeBraces: Linux +BreakConstructorInitializersBeforeComma: true diff --git a/src/CRC.cpp b/src/CRC.cpp index 65a6707..48cb29b 100644 --- a/src/CRC.cpp +++ b/src/CRC.cpp @@ -68,27 +68,23 @@ static const uint32_t kCrc32Table[256] = { }; // kCrc32Table void Crc32::AddData(const uint8_t* pData, const uint32_t length) { - uint8_t* pCur = (uint8_t*)pData; - uint32_t remaining = length; - for (; remaining--; ++pCur) - _crc = ( _crc >> 8 ) ^ kCrc32Table[(_crc ^ *pCur) & 0xff]; + uint8_t* pCur = (uint8_t*)pData; + uint32_t remaining = length; + for (; remaining--; ++pCur) + _crc = (_crc >> 8) ^ kCrc32Table[(_crc ^ *pCur) & 0xff]; } void Crc32::Reset() { - _crc = (uint32_t)~0; + _crc = (uint32_t)~0; } const uint32_t Crc32::GetCrc32() { - return ~_crc; + return ~_crc; } Crc32::Crc32() { - Reset(); + Reset(); } Crc32::~Crc32() { - } - - - diff --git a/src/CRC.h b/src/CRC.h index e5af8cd..6f7692b 100644 --- a/src/CRC.h +++ b/src/CRC.h @@ -6,15 +6,15 @@ class Crc32 { public: - Crc32() ; - ~Crc32(); - void Reset(); - void AddData(const uint8_t* pData, const uint32_t length); - - const uint32_t GetCrc32(); + Crc32(); + ~Crc32(); + void Reset(); + void AddData(const uint8_t* pData, const uint32_t length); + + const uint32_t GetCrc32(); private: - uint32_t _crc; + uint32_t _crc; }; #endif // CRC_H diff --git a/src/Image.cpp b/src/Image.cpp index a35bef0..cae92a0 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -19,161 +19,147 @@ #include "Image.h" -CannotLoadImageException::CannotLoadImageException(std::string path) : runtime_error(path) +CannotLoadImageException::CannotLoadImageException(std::string path) + : runtime_error(path) { - } Image::Image() { - ilGenImages(1,&image); - w = 0; - h = 0; - d = 0; - + ilGenImages(1, &image); + w = 0; + h = 0; + d = 0; } -void Image::GetRect(int x, int y, int w, int h,ILenum format, void * dest) +void Image::GetRect(int x, int y, int w, int h, ILenum format, void* dest) { - ilBindImage(image); - ilCopyPixels(x,y,0,w,h,1,format,IL_UNSIGNED_BYTE,dest); + ilBindImage(image); + ilCopyPixels(x, y, 0, w, h, 1, format, IL_UNSIGNED_BYTE, dest); } void Image::GetRect(int x, int y, int w, int h, ILenum format, ILenum type, void* dest) { - ilBindImage(image); - ilCopyPixels(x,y,0,w,h,1,format,type,dest); + ilBindImage(image); + ilCopyPixels(x, y, 0, w, h, 1, format, type, dest); } void Image::FlipVertical() { - ilBindImage(image); - iluFlipImage(); + ilBindImage(image); + iluFlipImage(); } -Image::Image(const char* filename, bool hdrlum ) +Image::Image(const char* filename, bool hdrlum) { - ilGenImages(1,&image); - ilBindImage(image); - if ( ! ilLoadImage(filename) ) - { - throw CannotLoadImageException(std::string(filename)); - - } - if (!hdrlum) - { - ConvertToRGBA(); - }else if ( ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL ) != 2 || ilGetInteger(IL_IMAGE_FORMAT) != IL_LUMINANCE ) { - ConvertToLUMHDR(); - } - w = ilGetInteger(IL_IMAGE_WIDTH); - h = ilGetInteger(IL_IMAGE_HEIGHT); - d = ilGetInteger(IL_IMAGE_DEPTH); - datapointer = ilGetData(); - + ilGenImages(1, &image); + ilBindImage(image); + if (!ilLoadImage(filename)) { + throw CannotLoadImageException(std::string(filename)); + } + if (!hdrlum) { + ConvertToRGBA(); + } else if (ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL) != 2 || ilGetInteger(IL_IMAGE_FORMAT) != IL_LUMINANCE) { + ConvertToLUMHDR(); + } + w = ilGetInteger(IL_IMAGE_WIDTH); + h = ilGetInteger(IL_IMAGE_HEIGHT); + d = ilGetInteger(IL_IMAGE_DEPTH); + datapointer = ilGetData(); } void Image::Save(const char* filename) { - ilBindImage(image); - ilSaveImage(filename); + ilBindImage(image); + ilSaveImage(filename); } void Image::AllocateLUM(int x, int y, char* data) { - ilBindImage(image); - ilTexImage(x,y,1,1,IL_LUMINANCE,IL_UNSIGNED_BYTE,data); - datapointer = ilGetData(); - w = ilGetInteger(IL_IMAGE_WIDTH); - h = ilGetInteger(IL_IMAGE_HEIGHT); - d = ilGetInteger(IL_IMAGE_DEPTH); + ilBindImage(image); + ilTexImage(x, y, 1, 1, IL_LUMINANCE, IL_UNSIGNED_BYTE, data); + datapointer = ilGetData(); + w = ilGetInteger(IL_IMAGE_WIDTH); + h = ilGetInteger(IL_IMAGE_HEIGHT); + d = ilGetInteger(IL_IMAGE_DEPTH); } void Image::AllocateRGBA(int x, int y, char* data) { - ilBindImage(image); - ilTexImage(x,y,1,4,IL_RGBA,IL_UNSIGNED_BYTE,data); - datapointer = ilGetData(); - w = ilGetInteger(IL_IMAGE_WIDTH); - h = ilGetInteger(IL_IMAGE_HEIGHT); - d = ilGetInteger(IL_IMAGE_DEPTH); + ilBindImage(image); + ilTexImage(x, y, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, data); + datapointer = ilGetData(); + w = ilGetInteger(IL_IMAGE_WIDTH); + h = ilGetInteger(IL_IMAGE_HEIGHT); + d = ilGetInteger(IL_IMAGE_DEPTH); } void Image::Rescale(int x, int y) { - ilBindImage(image); - iluScale(x,y,1); - datapointer = ilGetData(); - w = ilGetInteger(IL_IMAGE_WIDTH); - h = ilGetInteger(IL_IMAGE_HEIGHT); - d = ilGetInteger(IL_IMAGE_DEPTH); + ilBindImage(image); + iluScale(x, y, 1); + datapointer = ilGetData(); + w = ilGetInteger(IL_IMAGE_WIDTH); + h = ilGetInteger(IL_IMAGE_HEIGHT); + d = ilGetInteger(IL_IMAGE_DEPTH); } void Image::GetPixelRGBA(int x_, int y_, unsigned char* pix) { - int x = x_ % w; - int y = h -(y_ % h); + int x = x_ % w; + int y = h - (y_ % h); - if ( datapointer ) - { - pix[0] = datapointer[w*y*4+x*4]; - pix[1] = datapointer[w*y*4+x*4+1]; - pix[2] = datapointer[w*y*4+x*4+2]; - pix[3] = datapointer[w*y*4+x*4+3]; - } else { - printf("GetPixelRGBA(%i,%i): datapointer is NULL\n",x_,y_); - } - //printf("%i %i %i\n",(int)pix[0],(int)pix[1],int(pix[2])); + if (datapointer) { + pix[0] = datapointer[w * y * 4 + x * 4]; + pix[1] = datapointer[w * y * 4 + x * 4 + 1]; + pix[2] = datapointer[w * y * 4 + x * 4 + 2]; + pix[3] = datapointer[w * y * 4 + x * 4 + 3]; + } else { + printf("GetPixelRGBA(%i,%i): datapointer is NULL\n", x_, y_); + } + //printf("%i %i %i\n",(int)pix[0],(int)pix[1],int(pix[2])); } - void Image::SetPixelRGBA(int x_, int y_, char r, char g, char b, char a) { - int x = (x_ % w); - int y = h - (y_ % h) - 1; - datapointer[w*y*3+x*3] = r; - datapointer[w*y*3+x*3+1] = g; - datapointer[w*y*3+x*3+2] = b; - datapointer[w*y*4+x*4+3] = a; - + int x = (x_ % w); + int y = h - (y_ % h) - 1; + datapointer[w * y * 3 + x * 3] = r; + datapointer[w * y * 3 + x * 3 + 1] = g; + datapointer[w * y * 3 + x * 3 + 2] = b; + datapointer[w * y * 4 + x * 4 + 3] = a; } void Image::SetPixelLUM(int x_, int y_, char val) { - int x = x_ % w; - int y = y_ % h; - datapointer[y*w+x] = val; - - + int x = x_ % w; + int y = y_ % h; + datapointer[y * w + x] = val; } void Image::GetPixelLUM(int x_, int y_, unsigned char* p) { - //printf("GetPixelLUM(%i,%i)\n",x_,y_); - int x = x_ % w; - int y = y_ % h; - p[0] = datapointer[y*w+x]; - + //printf("GetPixelLUM(%i,%i)\n",x_,y_); + int x = x_ % w; + int y = y_ % h; + p[0] = datapointer[y * w + x]; } void Image::ConvertToLUM() { - ilBindImage(image); - ilConvertImage(IL_LUMINANCE,IL_UNSIGNED_BYTE); - datapointer = ilGetData(); - + ilBindImage(image); + ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE); + datapointer = ilGetData(); } void Image::ConvertToLUMHDR() { - ilBindImage(image); - ilConvertImage(IL_LUMINANCE,IL_UNSIGNED_SHORT); - datapointer = ilGetData(); + ilBindImage(image); + ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_SHORT); + datapointer = ilGetData(); } void Image::ConvertToRGBA() { - ilBindImage(image); - ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE); - datapointer = ilGetData(); + ilBindImage(image); + ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); + datapointer = ilGetData(); } Image::~Image() { - ilDeleteImages(1,&image); + ilDeleteImages(1, &image); } - - diff --git a/src/Image.h b/src/Image.h index 8000333..656454c 100644 --- a/src/Image.h +++ b/src/Image.h @@ -21,8 +21,8 @@ #define IMAGE_H #include #include -#include #include +#include #ifdef SetPixelRGBA #undef SetPixelRGBA @@ -31,46 +31,46 @@ class CannotLoadImageException : public std::runtime_error { public: - CannotLoadImageException(std::string path); + CannotLoadImageException(std::string path); }; -class Image{ - public: - ILuint image; - int w; - int h; - int d; - unsigned char * datapointer; - Image(); - - Image(const char* filename, bool hdrlum = false); - - void Save(const char * filename); - - void AllocateLUM(int x, int y,char * data=NULL); - - void AllocateRGBA(int x, int y,char * data=NULL); - - void Rescale(int x , int y); - - void GetPixelRGBA(int x_,int y_,unsigned char * pix); - - void SetPixelRGBA(int x_, int y_,char r, char g, char b, char a); - - void SetPixelLUM(int x_, int y_, char val); - - void GetPixelLUM(int x_, int y_,unsigned char * p); - - void ConvertToLUM(); - - void ConvertToLUMHDR(); - - void ConvertToRGBA(); - - void FlipVertical(); - void GetRect(int x, int y, int w, int h, ILenum format, void* dest); - void GetRect(int x, int y, int w, int h, ILenum format , ILenum type, void* dest); - ~Image(); - +class Image +{ +public: + ILuint image; + int w; + int h; + int d; + unsigned char* datapointer; + Image(); + + Image(const char* filename, bool hdrlum = false); + + void Save(const char* filename); + + void AllocateLUM(int x, int y, char* data = NULL); + + void AllocateRGBA(int x, int y, char* data = NULL); + + void Rescale(int x, int y); + + void GetPixelRGBA(int x_, int y_, unsigned char* pix); + + void SetPixelRGBA(int x_, int y_, char r, char g, char b, char a); + + void SetPixelLUM(int x_, int y_, char val); + + void GetPixelLUM(int x_, int y_, unsigned char* p); + + void ConvertToLUM(); + + void ConvertToLUMHDR(); + + void ConvertToRGBA(); + + void FlipVertical(); + void GetRect(int x, int y, int w, int h, ILenum format, void* dest); + void GetRect(int x, int y, int w, int h, ILenum format, ILenum type, void* dest); + ~Image(); }; #endif // IMAGE_H diff --git a/src/SMFMap.cpp b/src/SMFMap.cpp index 11bdc2c..5421282 100644 --- a/src/SMFMap.cpp +++ b/src/SMFMap.cpp @@ -20,365 +20,325 @@ #include "SMFMap.h" #include #include -#include -#include #include +#include +#include #ifndef bzero -#define bzero(ptr,len) memset(ptr,0,len) +#define bzero(ptr, len) memset(ptr, 0, len) #endif -SMFMap::SMFMap(std::string name,std::string texturepath) +SMFMap::SMFMap(std::string name, std::string texturepath) { - - m_tiles = new TileStorage(); - metalmap = NULL; - heightmap = NULL; - typemap = NULL; - minimap = NULL; - vegetationmap = NULL; - texture = new Image(texturepath.c_str()); - - if ( texture->w < 1 ) - throw CannotLoadTextureException(); - if ( texture->w % 1024 != 0 || texture->h % 1024 != 0) - { - throw InvalidMapSizeException(); - - } - mapx = ( texture->w / 1024 ) * 128; - mapy = ( texture->h / 1024 ) * 128; - m_minh = 0.0; - m_maxh = 1.0; - m_name = name; - m_doclamp = true; - m_th = 0; - m_comptype = COMPRESS_REASONABLE; - m_smooth = false; - texpath = texturepath; + + m_tiles = new TileStorage(); + metalmap = NULL; + heightmap = NULL; + typemap = NULL; + minimap = NULL; + vegetationmap = NULL; + texture = new Image(texturepath.c_str()); + + if (texture->w < 1) + throw CannotLoadTextureException(); + if (texture->w % 1024 != 0 || texture->h % 1024 != 0) { + throw InvalidMapSizeException(); + } + mapx = (texture->w / 1024) * 128; + mapy = (texture->h / 1024) * 128; + m_minh = 0.0; + m_maxh = 1.0; + m_name = name; + m_doclamp = true; + m_th = 0; + m_comptype = COMPRESS_REASONABLE; + m_smooth = false; + texpath = texturepath; } SMFMap::SMFMap(std::string smfname) { - std::vector tiles_images; - std::vector tile_files; - metalmap = NULL; - heightmap = NULL; - typemap = NULL; - minimap = NULL; - vegetationmap = NULL; - m_tiles = NULL; - FILE * smffile = fopen(smfname.c_str(),"rb"); - if ( !smffile ) - { - throw CannotLoadSmfFileException(); - - } - SMFHeader hdr; - fread(&hdr,sizeof(hdr),1,smffile); - if ( strncmp(hdr.magic,"spring map file",15) > 0 ) - { - fclose(smffile); - throw InvalidSmfFileException(); - } - mapx = hdr.mapx; - mapy = hdr.mapy; - m_minh = hdr.minHeight; - m_maxh = hdr.maxHeight; - m_smfname = smfname; - m_doclamp = true; - m_th = 0; - m_comptype = COMPRESS_REASONABLE; - m_smooth = false; - texture = new Image(); - texture->AllocateRGBA((mapx/128)*1024,(mapy/128)*1024); - std::cout << "Loading metal map..." << std::endl; - metalmap = new Image(); - metalmap->AllocateLUM(mapx/2,mapy/2); - fseek(smffile,hdr.metalmapPtr,SEEK_SET); - fread(metalmap->datapointer,mapx/2*mapy/2,1,smffile); - - - std::cout << "Loading heightmap..." << std::endl; - heightmap = new Image(); - heightmap->AllocateLUM(mapx+1,mapy+1); - heightmap->ConvertToLUMHDR();//TODO: Allocate directly HDR - fseek(smffile,hdr.heightmapPtr,SEEK_SET); - fread(heightmap->datapointer,(mapx+1)*(mapy+1)*2,1,smffile); - heightmap->FlipVertical(); - - std::cout << "Loading type map..." << std::endl; - typemap = new Image(); - typemap->AllocateLUM(mapx/2,mapy/2); - fseek(smffile,hdr.typeMapPtr,SEEK_SET); - fread(typemap->datapointer,mapx/2*mapy/2,1,smffile); - typemap->FlipVertical(); - - std::cout << "Loading minimap..." << std::endl; - minimap = new Image(); - uint8_t * dxt1data = new uint8_t[699064]; - fseek(smffile,hdr.minimapPtr,SEEK_SET); - fread(dxt1data,699064,1,smffile); - ilBindImage(minimap->image); - ilTexImageDxtc(1024,1024,1,IL_DXT1,dxt1data); - ilDxtcDataToImage(); - std::cout << "Extracting main texture..." << std::endl; - int *tilematrix = new int[mapx/4 * mapy/4]; - - fseek(smffile,hdr.tilesPtr,SEEK_SET); - MapTileHeader thdr; - fread(&thdr,sizeof(thdr),1,smffile); - while ( tile_files.size() < thdr.numTileFiles ) - { - tile_files.push_back(""); - char byte; - int numtiles; - fread(&numtiles,4,1,smffile); - fread(&byte,1,1,smffile); - while ( byte != 0 ) - { - tile_files[tile_files.size()-1].append(1,byte); - fread(&byte,1,1,smffile); - } - } - for ( std::vector::iterator it = tile_files.begin(); it != tile_files.end(); it++ ) - { - std::cout << "Opening " << *it << std::endl; - FILE* smtfile = fopen((*it).c_str(),"rb"); - if ( !smtfile ) - { - fclose(smffile); - delete [] tilematrix; - throw CannotOpenSmtFileException(); - } - TileFileHeader smthdr; - fread(&smthdr,sizeof(smthdr),1,smtfile); - if ( strncmp(smthdr.magic,"spring tilefile",14) ) - { - fclose(smffile); - fclose(smtfile); - delete [] tilematrix; - throw InvalidSmtFileException(); - } - for ( int i = 0; i < smthdr.numTiles; i++ ) - { - ILuint tile = ilGenImage(); - fread(dxt1data,680,1,smtfile); - ilBindImage(tile); - ilTexImageDxtc(32,32,1,IL_DXT1,dxt1data); - ilDxtcDataToImage(); - tiles_images.push_back(tile); - } - fclose(smtfile); - - - } - std::cout << "Tiles @ " << ftell(smffile) << std::endl; - fread(tilematrix,mapx/4 * mapy/4 * 4,1,smffile); - ilBindImage(texture->image); - unsigned int * texdata = (unsigned int *)ilGetData(); - std::cout << "Blitting tiles..." << std::endl; - for ( int y = 0; y < mapy/4; y++ ) - { - std::cout << "Row " << y << " of " << mapy/4 << std::endl; - for ( int x = 0; x < mapx/4; x++ ) - { - if ( tilematrix[y*(mapx/4)+x] >= tiles_images.size() ) - { - std::cerr << "Warning: tile " << tilematrix[y*(mapx/4)+x] << " out of range" << std::endl; - continue; - } - //ilBlit(tiles_images[tilematrix[y*(mapx/4)+x]],x*32,y*32,0,0,0,0,32,32,1); - ilBindImage(tiles_images[tilematrix[y*(mapx/4)+x]]); - unsigned int * data = (unsigned int *)ilGetData(); - int r2 = 0; - for ( int y2 = y*32; y2 < y*32+32; y2++ )//FAST blitting - { - /*for ( int x2 = y*32; x2 < y*32+32; x2++ ) + std::vector tiles_images; + std::vector tile_files; + metalmap = NULL; + heightmap = NULL; + typemap = NULL; + minimap = NULL; + vegetationmap = NULL; + m_tiles = NULL; + FILE* smffile = fopen(smfname.c_str(), "rb"); + if (!smffile) { + throw CannotLoadSmfFileException(); + } + SMFHeader hdr; + fread(&hdr, sizeof(hdr), 1, smffile); + if (strncmp(hdr.magic, "spring map file", 15) > 0) { + fclose(smffile); + throw InvalidSmfFileException(); + } + mapx = hdr.mapx; + mapy = hdr.mapy; + m_minh = hdr.minHeight; + m_maxh = hdr.maxHeight; + m_smfname = smfname; + m_doclamp = true; + m_th = 0; + m_comptype = COMPRESS_REASONABLE; + m_smooth = false; + texture = new Image(); + texture->AllocateRGBA((mapx / 128) * 1024, (mapy / 128) * 1024); + std::cout << "Loading metal map..." << std::endl; + metalmap = new Image(); + metalmap->AllocateLUM(mapx / 2, mapy / 2); + fseek(smffile, hdr.metalmapPtr, SEEK_SET); + fread(metalmap->datapointer, mapx / 2 * mapy / 2, 1, smffile); + + + std::cout << "Loading heightmap..." << std::endl; + heightmap = new Image(); + heightmap->AllocateLUM(mapx + 1, mapy + 1); + heightmap->ConvertToLUMHDR(); //TODO: Allocate directly HDR + fseek(smffile, hdr.heightmapPtr, SEEK_SET); + fread(heightmap->datapointer, (mapx + 1) * (mapy + 1) * 2, 1, smffile); + heightmap->FlipVertical(); + + std::cout << "Loading type map..." << std::endl; + typemap = new Image(); + typemap->AllocateLUM(mapx / 2, mapy / 2); + fseek(smffile, hdr.typeMapPtr, SEEK_SET); + fread(typemap->datapointer, mapx / 2 * mapy / 2, 1, smffile); + typemap->FlipVertical(); + + std::cout << "Loading minimap..." << std::endl; + minimap = new Image(); + uint8_t* dxt1data = new uint8_t[699064]; + fseek(smffile, hdr.minimapPtr, SEEK_SET); + fread(dxt1data, 699064, 1, smffile); + ilBindImage(minimap->image); + ilTexImageDxtc(1024, 1024, 1, IL_DXT1, dxt1data); + ilDxtcDataToImage(); + std::cout << "Extracting main texture..." << std::endl; + int* tilematrix = new int[mapx / 4 * mapy / 4]; + + fseek(smffile, hdr.tilesPtr, SEEK_SET); + MapTileHeader thdr; + fread(&thdr, sizeof(thdr), 1, smffile); + while (tile_files.size() < thdr.numTileFiles) { + tile_files.push_back(""); + char byte; + int numtiles; + fread(&numtiles, 4, 1, smffile); + fread(&byte, 1, 1, smffile); + while (byte != 0) { + tile_files[tile_files.size() - 1].append(1, byte); + fread(&byte, 1, 1, smffile); + } + } + for (std::vector::iterator it = tile_files.begin(); it != tile_files.end(); it++) { + std::cout << "Opening " << *it << std::endl; + FILE* smtfile = fopen((*it).c_str(), "rb"); + if (!smtfile) { + fclose(smffile); + delete[] tilematrix; + throw CannotOpenSmtFileException(); + } + TileFileHeader smthdr; + fread(&smthdr, sizeof(smthdr), 1, smtfile); + if (strncmp(smthdr.magic, "spring tilefile", 14)) { + fclose(smffile); + fclose(smtfile); + delete[] tilematrix; + throw InvalidSmtFileException(); + } + for (int i = 0; i < smthdr.numTiles; i++) { + ILuint tile = ilGenImage(); + fread(dxt1data, 680, 1, smtfile); + ilBindImage(tile); + ilTexImageDxtc(32, 32, 1, IL_DXT1, dxt1data); + ilDxtcDataToImage(); + tiles_images.push_back(tile); + } + fclose(smtfile); + } + std::cout << "Tiles @ " << ftell(smffile) << std::endl; + fread(tilematrix, mapx / 4 * mapy / 4 * 4, 1, smffile); + ilBindImage(texture->image); + unsigned int* texdata = (unsigned int*)ilGetData(); + std::cout << "Blitting tiles..." << std::endl; + for (int y = 0; y < mapy / 4; y++) { + std::cout << "Row " << y << " of " << mapy / 4 << std::endl; + for (int x = 0; x < mapx / 4; x++) { + if (tilematrix[y * (mapx / 4) + x] >= tiles_images.size()) { + std::cerr << "Warning: tile " << tilematrix[y * (mapx / 4) + x] << " out of range" << std::endl; + continue; + } + //ilBlit(tiles_images[tilematrix[y*(mapx/4)+x]],x*32,y*32,0,0,0,0,32,32,1); + ilBindImage(tiles_images[tilematrix[y * (mapx / 4) + x]]); + unsigned int* data = (unsigned int*)ilGetData(); + int r2 = 0; + for (int y2 = y * 32; y2 < y * 32 + 32; y2++) //FAST blitting + { + /*for ( int x2 = y*32; x2 < y*32+32; x2++ ) { }*/ - memcpy(&texdata[y2*texture->w+x*32],&data[r2*32],32*4); - r2++; - } - } - - } - texture->FlipVertical(); - - - std::cout << "Loading features..." << std::endl; - - fseek(smffile,hdr.featurePtr,SEEK_SET); - MapFeatureHeader mfhdr; - fread(&mfhdr,sizeof(mfhdr),1,smffile); - //-32767.0f+f->rotation/65535.0f*360 - - std::vector feature_types; - while ( feature_types.size() < mfhdr.numFeatureType ) - { - feature_types.push_back(""); - char byte; - fread(&byte,1,1,smffile); - while ( byte != 0 ) - { - feature_types[feature_types.size()-1].append(1,byte); - fread(&byte,1,1,smffile); - } - } - for ( int i = 0; i < mfhdr.numFeatures; i++ ) - { - MapFeatureStruct f; - fread(&f,sizeof(f),1,smffile); - if ( f.featureType >= feature_types.size() ) - { - std::cerr << "Warning: invalid feature type " << f.featureType << std::endl; - continue; - } - AddFeature(feature_types[f.featureType],f.xpos,f.ypos,f.zpos,-32767.0f+f.rotation/65535.0f*360); - - } - fclose(smffile); - delete [] dxt1data; - delete [] tilematrix; + memcpy(&texdata[y2 * texture->w + x * 32], &data[r2 * 32], 32 * 4); + r2++; + } + } + } + texture->FlipVertical(); + + + std::cout << "Loading features..." << std::endl; + + fseek(smffile, hdr.featurePtr, SEEK_SET); + MapFeatureHeader mfhdr; + fread(&mfhdr, sizeof(mfhdr), 1, smffile); + //-32767.0f+f->rotation/65535.0f*360 + + std::vector feature_types; + while (feature_types.size() < mfhdr.numFeatureType) { + feature_types.push_back(""); + char byte; + fread(&byte, 1, 1, smffile); + while (byte != 0) { + feature_types[feature_types.size() - 1].append(1, byte); + fread(&byte, 1, 1, smffile); + } + } + for (int i = 0; i < mfhdr.numFeatures; i++) { + MapFeatureStruct f; + fread(&f, sizeof(f), 1, smffile); + if (f.featureType >= feature_types.size()) { + std::cerr << "Warning: invalid feature type " << f.featureType << std::endl; + continue; + } + AddFeature(feature_types[f.featureType], f.xpos, f.ypos, f.zpos, -32767.0f + f.rotation / 65535.0f * 360); + } + fclose(smffile); + delete[] dxt1data; + delete[] tilematrix; } void SMFMap::SetClamping(bool b) { - m_doclamp = b; + m_doclamp = b; } void SMFMap::SaveSourceFiles() { - if ( metalmap ) - { - metalmap->Save("metalmap.png"); - } - if ( typemap ) - { - typemap->Save("typemap.png"); - } - if ( heightmap ) - { - heightmap->Save("heightmap.png"); - //heightmap->Save("heightmap.exr"); Not needed , png already supports 16 bit and DevIL too - - } - if ( texture ) - { - texture->Save("texture.png"); - } - if ( minimap ) - { - minimap->Save("minimap.png"); - } - FILE * featurefile = fopen("features.txt","w"); - for ( std::map * >::iterator it = features.begin(); it != features.end(); it++ ) - { - for ( std::list::iterator it2 = (*it).second->begin(); it2 != (*it).second->end(); it2++ ) - { - MapFeatureStruct* f = (*it2); - float degrot = -32767.0f+f->rotation/65535.0f*360; // 32767.0f-((orientation/360.0)*65535.0f); - - fprintf(featurefile,"%s %f %f %f %f\n",(*it).first.c_str(),f->xpos,f->ypos,f->zpos,degrot); - - - } - - - } - fclose(featurefile); - - const char* compileCmd = "springMapConvNG -t texture.png -h heightmap.png -z typemap.png -m metalmap.png -maxh %f -minh %f -th 0.8 -ct 4 -features features.txt -minimap minimap.png -o \"%s\""; - FILE * makefile = fopen("Makefile","w"); - fprintf(makefile,"%s: texture.png heightmap.png typemap.png metalmap.png minimap.png features.txt\n",m_smfname.c_str()); - std::string smfbasename = m_smfname.substr(0,m_smfname.find(".")); - fprintf(makefile, "\t"); - fprintf(makefile, compileCmd, m_maxh, m_minh, smfbasename.c_str()); - fprintf(makefile, "\n"); - fclose(makefile); - - FILE * batchfile = fopen("make.bat","w"); - fprintf(batchfile, compileCmd, m_maxh, m_minh, smfbasename.c_str()); - fprintf(batchfile,"\r\npause\r\n"); - fclose(batchfile); + if (metalmap) { + metalmap->Save("metalmap.png"); + } + if (typemap) { + typemap->Save("typemap.png"); + } + if (heightmap) { + heightmap->Save("heightmap.png"); + //heightmap->Save("heightmap.exr"); Not needed , png already supports 16 bit and DevIL too + } + if (texture) { + texture->Save("texture.png"); + } + if (minimap) { + minimap->Save("minimap.png"); + } + FILE* featurefile = fopen("features.txt", "w"); + for (std::map*>::iterator it = features.begin(); it != features.end(); it++) { + for (std::list::iterator it2 = (*it).second->begin(); it2 != (*it).second->end(); it2++) { + MapFeatureStruct* f = (*it2); + float degrot = -32767.0f + f->rotation / 65535.0f * 360; // 32767.0f-((orientation/360.0)*65535.0f); + + fprintf(featurefile, "%s %f %f %f %f\n", (*it).first.c_str(), f->xpos, f->ypos, f->zpos, degrot); + } + } + fclose(featurefile); + + const char* compileCmd = "springMapConvNG -t texture.png -h heightmap.png -z typemap.png -m metalmap.png -maxh %f -minh %f -th 0.8 -ct 4 -features features.txt -minimap minimap.png -o \"%s\""; + FILE* makefile = fopen("Makefile", "w"); + fprintf(makefile, "%s: texture.png heightmap.png typemap.png metalmap.png minimap.png features.txt\n", m_smfname.c_str()); + std::string smfbasename = m_smfname.substr(0, m_smfname.find(".")); + fprintf(makefile, "\t"); + fprintf(makefile, compileCmd, m_maxh, m_minh, smfbasename.c_str()); + fprintf(makefile, "\n"); + fclose(makefile); + + FILE* batchfile = fopen("make.bat", "w"); + fprintf(batchfile, compileCmd, m_maxh, m_minh, smfbasename.c_str()); + fprintf(batchfile, "\r\npause\r\n"); + fclose(batchfile); } void SMFMap::SetVegetationMap(std::string path) { - Image * img = new Image(path.c_str()); - if ( img->w > 0 ) - { - if ( vegetationmap ) - delete vegetationmap; - vegetationmap = img; - vegetationmap->ConvertToLUM(); - if ( img->w != mapx/4 || img->h != mapy/4 ) - { - std::cerr << "Warning: Vegetation map has wrong size , rescaling!" << std::endl; - vegetationmap->Rescale(mapx/4,mapy/4); - - } - } + Image* img = new Image(path.c_str()); + if (img->w > 0) { + if (vegetationmap) + delete vegetationmap; + vegetationmap = img; + vegetationmap->ConvertToLUM(); + if (img->w != mapx / 4 || img->h != mapy / 4) { + std::cerr << "Warning: Vegetation map has wrong size , rescaling!" << std::endl; + vegetationmap->Rescale(mapx / 4, mapy / 4); + } + } } void SMFMap::AddFeature(std::string name, float x, float y, float z, float orientation) { - if ( features.find(name) == features.end() )//Allocate new vector - { - features[name] = new std::list(); - } - MapFeatureStruct * feat = (MapFeatureStruct*)malloc(sizeof(MapFeatureStruct)); - feat->xpos = x; - feat->ypos = y; - feat->zpos = z; - feat->rotation = 32767.0f-((orientation/360.0)*65535.0f); - feat->relativeSize = 1; - features[name]->push_back(feat); + if (features.find(name) == features.end()) //Allocate new vector + { + features[name] = new std::list(); + } + MapFeatureStruct* feat = (MapFeatureStruct*)malloc(sizeof(MapFeatureStruct)); + feat->xpos = x; + feat->ypos = y; + feat->zpos = z; + feat->rotation = 32767.0f - ((orientation / 360.0) * 65535.0f); + feat->relativeSize = 1; + features[name]->push_back(feat); } void SMFMap::SetHeightRange(float minh, float maxh) { - m_minh = minh; - m_maxh = maxh; + m_minh = minh; + m_maxh = maxh; } SMFMap::~SMFMap() { - delete m_tiles; - if ( metalmap ) - delete metalmap; - if ( heightmap ) - delete heightmap; - if ( typemap ) - delete typemap; - if ( minimap ) - delete minimap; - if ( texture ) - delete texture; - if ( vegetationmap ) - delete vegetationmap; + delete m_tiles; + if (metalmap) + delete metalmap; + if (heightmap) + delete heightmap; + if (typemap) + delete typemap; + if (minimap) + delete minimap; + if (texture) + delete texture; + if (vegetationmap) + delete vegetationmap; } void SMFMap::SetMiniMap(std::string path) { - delete texture; - std::cout << "Loading minimap " << path << std::endl; - Image * img = new Image(path.c_str()); - if ( img->w > 0 ) - { - if ( minimap ) - delete minimap; - minimap = img; - minimap->ConvertToRGBA(); - minimap->FlipVertical(); - if ( img->w != 1024 || img->h != 1024 ) - { - std::cerr << "Warning: Minimap has wrong size , rescaling!" << std::endl; - minimap->Rescale(1024,1024); - - } - texture = new Image(texpath.c_str()); - return; - } - std::cout << "Failed " << path << std::endl; - texture = new Image(texpath.c_str()); + delete texture; + std::cout << "Loading minimap " << path << std::endl; + Image* img = new Image(path.c_str()); + if (img->w > 0) { + if (minimap) + delete minimap; + minimap = img; + minimap->ConvertToRGBA(); + minimap->FlipVertical(); + if (img->w != 1024 || img->h != 1024) { + std::cerr << "Warning: Minimap has wrong size , rescaling!" << std::endl; + minimap->Rescale(1024, 1024); + } + texture = new Image(texpath.c_str()); + return; + } + std::cout << "Failed " << path << std::endl; + texture = new Image(texpath.c_str()); } /*void SMFMap::SetFeatureMap(std::string path) @@ -400,215 +360,186 @@ void SMFMap::SetMiniMap(std::string path) }*/ void SMFMap::SetHeightMap(std::string path) { - Image * img = new Image(path.c_str(),true); - if ( img->w > 0 ) - { - if ( heightmap ) - delete heightmap; - heightmap = img; - // heightmap->ConvertToLUMHDR(); - if ( img->w != mapx+1 || img->h != mapy+1 ) - { - std::cerr << "Warning: Height map has wrong size , rescaling! (" << img->w << "," << img->h << ") instead of (" << mapx+1 << "," << mapy+1 << ")" << std::endl; - heightmap->Rescale(mapx+1,mapy+1); - - } - //Clamp heightmap before blurring - if ( m_doclamp ) - { - float _min = 65537.0f; - float _max = -65337.0f; - unsigned short * pixels = (unsigned short*)heightmap->datapointer; - for ( int i = 0; i < heightmap->w*heightmap->h; i++ ) - { - if ( _min > pixels[i] ) - _min = pixels[i]; - if ( _max < pixels[i] ) - _max = pixels[i]; - - } - std::cout << "Range : " << _min << " -> " << _max << std::endl; - float range = _max-_min; - for ( int i = 0; i < heightmap->w*heightmap->h; i++ ) - { - pixels[i] = (unsigned short)((((pixels[i]-_min)/range)*65535.0f)); - - } - } - if ( m_smooth ) - { - std::cout << "Blurring heightmap..." << std::endl; - /*ilBindImage(heightmap->image); // Seems broken with 16 bit image + Image* img = new Image(path.c_str(), true); + if (img->w > 0) { + if (heightmap) + delete heightmap; + heightmap = img; + // heightmap->ConvertToLUMHDR(); + if (img->w != mapx + 1 || img->h != mapy + 1) { + std::cerr << "Warning: Height map has wrong size , rescaling! (" << img->w << "," << img->h << ") instead of (" << mapx + 1 << "," << mapy + 1 << ")" << std::endl; + heightmap->Rescale(mapx + 1, mapy + 1); + } + //Clamp heightmap before blurring + if (m_doclamp) { + float _min = 65537.0f; + float _max = -65337.0f; + unsigned short* pixels = (unsigned short*)heightmap->datapointer; + for (int i = 0; i < heightmap->w * heightmap->h; i++) { + if (_min > pixels[i]) + _min = pixels[i]; + if (_max < pixels[i]) + _max = pixels[i]; + } + std::cout << "Range : " << _min << " -> " << _max << std::endl; + float range = _max - _min; + for (int i = 0; i < heightmap->w * heightmap->h; i++) { + pixels[i] = (unsigned short)((((pixels[i] - _min) / range) * 65535.0f)); + } + } + if (m_smooth) { + std::cout << "Blurring heightmap..." << std::endl; + /*ilBindImage(heightmap->image); // Seems broken with 16 bit image iluBlurAvg(5); heightmap->datapointer = ilGetData();*/ - unsigned short * tempdata = new unsigned short[img->h*img->w]; - for ( int pass = 0; pass < 3; pass++ ) - { - std::cout << "Blurring heightmap pass " << pass+1 << "..." << std::endl; - memcpy(tempdata,img->datapointer,img->h*img->w*2); - for ( int y = 1; y < img->h-1; y++ ) - { - for ( int x = 1; x < img->w-1; x++ ) - { - float sum = 0.0f; - sum += ((unsigned short*)img->datapointer)[y*img->w+x]; - sum += ((unsigned short*)img->datapointer)[(y-1)*img->w+(x-1)]; - sum += ((unsigned short*)img->datapointer)[(y-1)*img->w+(x-0)]; - sum += ((unsigned short*)img->datapointer)[(y-1)*img->w+(x+1)]; - sum += ((unsigned short*)img->datapointer)[(y-0)*img->w+(x-1)]; - sum += ((unsigned short*)img->datapointer)[(y-0)*img->w+(x+1)]; - sum += ((unsigned short*)img->datapointer)[(y+1)*img->w+(x-1)]; - sum += ((unsigned short*)img->datapointer)[(y+1)*img->w+(x-0)]; - sum += ((unsigned short*)img->datapointer)[(y+1)*img->w+(x+1)]; - sum /= 9.0f; - tempdata[y*img->w+x] = (unsigned short)(sum); - } - - } - memcpy(img->datapointer,tempdata,img->h*img->w*2); - } - delete [] tempdata; + unsigned short* tempdata = new unsigned short[img->h * img->w]; + for (int pass = 0; pass < 3; pass++) { + std::cout << "Blurring heightmap pass " << pass + 1 << "..." << std::endl; + memcpy(tempdata, img->datapointer, img->h * img->w * 2); + for (int y = 1; y < img->h - 1; y++) { + for (int x = 1; x < img->w - 1; x++) { + float sum = 0.0f; + sum += ((unsigned short*)img->datapointer)[y * img->w + x]; + sum += ((unsigned short*)img->datapointer)[(y - 1) * img->w + (x - 1)]; + sum += ((unsigned short*)img->datapointer)[(y - 1) * img->w + (x - 0)]; + sum += ((unsigned short*)img->datapointer)[(y - 1) * img->w + (x + 1)]; + sum += ((unsigned short*)img->datapointer)[(y - 0) * img->w + (x - 1)]; + sum += ((unsigned short*)img->datapointer)[(y - 0) * img->w + (x + 1)]; + sum += ((unsigned short*)img->datapointer)[(y + 1) * img->w + (x - 1)]; + sum += ((unsigned short*)img->datapointer)[(y + 1) * img->w + (x - 0)]; + sum += ((unsigned short*)img->datapointer)[(y + 1) * img->w + (x + 1)]; + sum /= 9.0f; + tempdata[y * img->w + x] = (unsigned short)(sum); + } + } + memcpy(img->datapointer, tempdata, img->h * img->w * 2); + } + delete[] tempdata; + } } - } - } void SMFMap::SetBlur(bool b) { - m_smooth = b; + m_smooth = b; } void SMFMap::SetCompareTileCount(uint32_t count) { - m_tiles->SetDictSize(count); + m_tiles->SetDictSize(count); } void SMFMap::SetMetalMap(std::string path) { - Image * img = new Image(path.c_str()); - if ( img->w > 0 ) - { - if ( metalmap ) - delete metalmap; - metalmap = img; - metalmap->ConvertToLUM(); - - if ( img->w != mapx/2 || img->h != mapy/2 ) - { - std::cerr << "Warning: Metal map has wrong size , rescaling! (" << img->w << "," << img->h << ") instead of (" << mapx/2 << "," << mapy/2 << ")" << std::endl; - metalmap->Rescale( mapx/2,mapy/2); - - } - } + Image* img = new Image(path.c_str()); + if (img->w > 0) { + if (metalmap) + delete metalmap; + metalmap = img; + metalmap->ConvertToLUM(); + + if (img->w != mapx / 2 || img->h != mapy / 2) { + std::cerr << "Warning: Metal map has wrong size , rescaling! (" << img->w << "," << img->h << ") instead of (" << mapx / 2 << "," << mapy / 2 << ")" << std::endl; + metalmap->Rescale(mapx / 2, mapy / 2); + } + } } void SMFMap::SetTypeMap(std::string path) { - Image * img = new Image(path.c_str()); - if ( img->w > 0 ) - { - if ( typemap ) - delete typemap; - typemap = img; - typemap->ConvertToLUM(); - if ( img->w != mapx/2 || img->h != mapy/2 ) - { - std::cerr << "Warning: Type map has wrong size , rescaling! (" << img->w << "," << img->h << ") instead of (" << mapx/2 << "," << mapy/2 << ")" << std::endl; - typemap->Rescale(mapx/2,mapy/2); - - } - - } - + Image* img = new Image(path.c_str()); + if (img->w > 0) { + if (typemap) + delete typemap; + typemap = img; + typemap->ConvertToLUM(); + if (img->w != mapx / 2 || img->h != mapy / 2) { + std::cerr << "Warning: Type map has wrong size , rescaling! (" << img->w << "," << img->h << ") instead of (" << mapx / 2 << "," << mapy / 2 << ")" << std::endl; + typemap->Rescale(mapx / 2, mapy / 2); + } + } } void SMFMap::Compile() { - SMFHeader hdr; - strcpy(hdr.magic,"spring map file"); - hdr.version = 1; - hdr.mapid = rand(); - hdr.mapx = (texture->w / 1024)*128; - hdr.mapy = (texture->h / 1024)*128; - hdr.squareSize = 8; - hdr.texelPerSquare = 8; - hdr.tilesize = 32; - hdr.minHeight = m_minh; - hdr.maxHeight = m_maxh; - - - short int * hmap = new short int[(mapy+1)*(mapx+1)];bzero(hmap,((mapy+1)*(mapx+1))*2); - if ( heightmap ) - { - //heightmap->GetRect(0,0,heightmap->w,heightmap->h,IL_LUMINANCE,IL_SHORT,hmap); : IL seems to fail to convert from unsigned short to signed - /*for ( int k = 0; k < (mapy+1)*(mapx+1); k++ ) + SMFHeader hdr; + strcpy(hdr.magic, "spring map file"); + hdr.version = 1; + hdr.mapid = rand(); + hdr.mapx = (texture->w / 1024) * 128; + hdr.mapy = (texture->h / 1024) * 128; + hdr.squareSize = 8; + hdr.texelPerSquare = 8; + hdr.tilesize = 32; + hdr.minHeight = m_minh; + hdr.maxHeight = m_maxh; + + + short int* hmap = new short int[(mapy + 1) * (mapx + 1)]; + bzero(hmap, ((mapy + 1) * (mapx + 1)) * 2); + if (heightmap) { + //heightmap->GetRect(0,0,heightmap->w,heightmap->h,IL_LUMINANCE,IL_SHORT,hmap); : IL seems to fail to convert from unsigned short to signed + /*for ( int k = 0; k < (mapy+1)*(mapx+1); k++ ) { int pix = ((unsigned short*)heightmap->datapointer)[k]; hmap[k] = short(int(pix)-int(32767)); */ - memcpy(hmap,heightmap->datapointer,((mapy+1)*(mapx+1))*2); - } - unsigned char * typedata = new unsigned char[mapy/2 * mapx/2];bzero(typedata,(mapy/2 * mapx/2)); - if ( typemap ) - { - typemap->GetRect(0,0,typemap->w,typemap->h,IL_LUMINANCE,IL_UNSIGNED_BYTE,typedata); - - } - uint8_t * minimap_data = new uint8_t[699064]; - bzero(minimap_data,699064); - if ( minimap ) - { - int p = 0; - int s = 1024; - - Image * im2 = new Image(); - im2->AllocateRGBA(1024,1024,(char*)minimap->datapointer); - for ( int i = 0; i < 9; i++ ) - { - //std::cout << ">Mipmap " << i << std::endl; - im2->Rescale(s,s); - //std::cout << "datapointer,s,s,1,IL_DXT1,&ss); - //std::cout << ss << " " << s; - memcpy(&minimap_data[p],dxtdata,ss); - free(dxtdata); - p += ss; - - s = s >> 1; - - } - delete im2; - - } - unsigned char * metalmap_data = new unsigned char[mapx/2 * mapy/2];bzero(metalmap_data,(mapy/2 * mapx/2)); - if ( metalmap ) - { - metalmap->GetRect(0,0,metalmap->w,metalmap->h,IL_LUMINANCE,IL_UNSIGNED_BYTE,metalmap_data); - - } - /*hdr.heightmapPtr = sizeof(hdr); + memcpy(hmap, heightmap->datapointer, ((mapy + 1) * (mapx + 1)) * 2); + } + unsigned char* typedata = new unsigned char[mapy / 2 * mapx / 2]; + bzero(typedata, (mapy / 2 * mapx / 2)); + if (typemap) { + typemap->GetRect(0, 0, typemap->w, typemap->h, IL_LUMINANCE, IL_UNSIGNED_BYTE, typedata); + } + uint8_t* minimap_data = new uint8_t[699064]; + bzero(minimap_data, 699064); + if (minimap) { + int p = 0; + int s = 1024; + + Image* im2 = new Image(); + im2->AllocateRGBA(1024, 1024, (char*)minimap->datapointer); + for (int i = 0; i < 9; i++) { + //std::cout << ">Mipmap " << i << std::endl; + im2->Rescale(s, s); + //std::cout << "datapointer, s, s, 1, IL_DXT1, &ss); + //std::cout << ss << " " << s; + memcpy(&minimap_data[p], dxtdata, ss); + free(dxtdata); + p += ss; + + s = s >> 1; + } + delete im2; + } + unsigned char* metalmap_data = new unsigned char[mapx / 2 * mapy / 2]; + bzero(metalmap_data, (mapy / 2 * mapx / 2)); + if (metalmap) { + metalmap->GetRect(0, 0, metalmap->w, metalmap->h, IL_LUMINANCE, IL_UNSIGNED_BYTE, metalmap_data); + } + /*hdr.heightmapPtr = sizeof(hdr); hdr.typeMapPtr = hdr.heightmapPtr + ((mapy+1)*(mapx+1))*2; hdr.minimapPtr = hdr.typeMapPtr + (mapy/2 * mapx/2); hdr.metalmapPtr = hdr.minimapPtr + 699048; hdr.featurePtr = hdr.metalmapPtr + (mapy/2 * mapx/2);*/ - MapFeatureHeader mfhdr; - - hdr.tilesPtr = hdr.featurePtr + sizeof(mfhdr); - hdr.numExtraHeaders = 1; - ExtraHeader grassHeader; - grassHeader.size = 4; - grassHeader.type = 1; - MapTileHeader mthdr; - mthdr.numTileFiles = 1; - unsigned char * grass_data = new unsigned char[mapx/4 * mapy/4];bzero(grass_data,mapx/4 * mapy/4); - if ( vegetationmap ) - { - vegetationmap->GetRect(0,0,vegetationmap->w,vegetationmap->h,IL_LUMINANCE,IL_UNSIGNED_BYTE,grass_data); - - } - int * tiles = new int[mapx/4 * mapy/4]; - std::vector order; - DoCompress(tiles,order); - /* for ( int y = 0; y < mapy/4; y++ ) + MapFeatureHeader mfhdr; + + hdr.tilesPtr = hdr.featurePtr + sizeof(mfhdr); + hdr.numExtraHeaders = 1; + ExtraHeader grassHeader; + grassHeader.size = 4; + grassHeader.type = 1; + MapTileHeader mthdr; + mthdr.numTileFiles = 1; + unsigned char* grass_data = new unsigned char[mapx / 4 * mapy / 4]; + bzero(grass_data, mapx / 4 * mapy / 4); + if (vegetationmap) { + vegetationmap->GetRect(0, 0, vegetationmap->w, vegetationmap->h, IL_LUMINANCE, IL_UNSIGNED_BYTE, grass_data); + } + int* tiles = new int[mapx / 4 * mapy / 4]; + std::vector order; + DoCompress(tiles, order); + /* for ( int y = 0; y < mapy/4; y++ ) { for ( int x = 0; x < mapx/4; x++ ) { @@ -616,135 +547,119 @@ void SMFMap::Compile() } printf("\n"); }*/ - - FILE * tilefile = fopen((m_name+std::string(".smt")).c_str(),"wb"); - delete texture; //Temporarily delete texture from memory to reduce mem usage - m_tiles->WriteToFile(tilefile,order); - texture = new Image(texpath.c_str()); - - fclose(tilefile); - FILE * smffile = fopen((m_name+std::string(".smf")).c_str(),"wb"); - fwrite(&hdr,sizeof(hdr),1,smffile); - fwrite(&grassHeader,sizeof(grassHeader),1,smffile); - int _ofs = ftell(smffile)+4; - fwrite(&_ofs,4,1,smffile); - fwrite(grass_data,mapx/4 * mapy/4,1,smffile); - - hdr.minimapPtr = ftell(smffile); - fwrite(minimap_data,699064,1,smffile); - hdr.heightmapPtr = ftell(smffile); - fwrite(hmap,((mapy+1)*(mapx+1))*2,1,smffile); - hdr.typeMapPtr = ftell(smffile); - fwrite(typedata,mapy/2 * mapx/2,1,smffile); - - hdr.metalmapPtr = ftell(smffile); - fwrite(metalmap_data,mapy/2 * mapx/2,1,smffile); - hdr.featurePtr = ftell(smffile); - - - mfhdr.numFeatures = 0; - for ( std::map * >::iterator it = features.begin(); it != features.end(); it++ )//Enumerate features - mfhdr.numFeatures += (*it).second->size(); - mfhdr.numFeatureType = features.size(); - fwrite(&mfhdr,sizeof(mfhdr),1,smffile); - { - std::map featureTypes; - unsigned int z = 0; - for ( std::map * >::iterator it = features.begin(); it != features.end(); it++ )//Write feature types - { - fwrite((*it).first.c_str(),(*it).first.size()+1,1,smffile); - featureTypes[(*it).first] = z++; - } - for ( std::map * >::iterator it = features.begin(); it != features.end(); it++ )//Write feature types - { - for ( std::list::iterator it2 = (*it).second->begin(); it2 != (*it).second->end(); it2++ ) + + FILE* tilefile = fopen((m_name + std::string(".smt")).c_str(), "wb"); + delete texture; //Temporarily delete texture from memory to reduce mem usage + m_tiles->WriteToFile(tilefile, order); + texture = new Image(texpath.c_str()); + + fclose(tilefile); + FILE* smffile = fopen((m_name + std::string(".smf")).c_str(), "wb"); + fwrite(&hdr, sizeof(hdr), 1, smffile); + fwrite(&grassHeader, sizeof(grassHeader), 1, smffile); + int _ofs = ftell(smffile) + 4; + fwrite(&_ofs, 4, 1, smffile); + fwrite(grass_data, mapx / 4 * mapy / 4, 1, smffile); + + hdr.minimapPtr = ftell(smffile); + fwrite(minimap_data, 699064, 1, smffile); + hdr.heightmapPtr = ftell(smffile); + fwrite(hmap, ((mapy + 1) * (mapx + 1)) * 2, 1, smffile); + hdr.typeMapPtr = ftell(smffile); + fwrite(typedata, mapy / 2 * mapx / 2, 1, smffile); + + hdr.metalmapPtr = ftell(smffile); + fwrite(metalmap_data, mapy / 2 * mapx / 2, 1, smffile); + hdr.featurePtr = ftell(smffile); + + + mfhdr.numFeatures = 0; + for (std::map*>::iterator it = features.begin(); it != features.end(); it++) //Enumerate features + mfhdr.numFeatures += (*it).second->size(); + mfhdr.numFeatureType = features.size(); + fwrite(&mfhdr, sizeof(mfhdr), 1, smffile); { - (*it2)->featureType = featureTypes[(*it).first]; - if ( (*it2)->ypos < 490000.0f ) // Align on terrain - { - unsigned int hmapx = ((*it2)->xpos/float((mapx/128)*1024))*heightmap->w; - unsigned int hmapy = ((*it2)->zpos/float((mapy/128)*1024))*heightmap->h; - (*it2)->ypos = hdr.minHeight+(float(hmap[hmapy*(mapx+1)+hmapx])/32767.0)*(hdr.maxHeight-hdr.minHeight); - std::cout << "Feature " << (*it).first << " Instance " << (*it2) << " Terrain height: " << (*it2)->ypos << std::endl; - } - - fwrite((*it2),sizeof(MapFeatureStruct),1,smffile); + std::map featureTypes; + unsigned int z = 0; + for (std::map*>::iterator it = features.begin(); it != features.end(); it++) //Write feature types + { + fwrite((*it).first.c_str(), (*it).first.size() + 1, 1, smffile); + featureTypes[(*it).first] = z++; + } + for (std::map*>::iterator it = features.begin(); it != features.end(); it++) //Write feature types + { + for (std::list::iterator it2 = (*it).second->begin(); it2 != (*it).second->end(); it2++) { + (*it2)->featureType = featureTypes[(*it).first]; + if ((*it2)->ypos < 490000.0f) // Align on terrain + { + unsigned int hmapx = ((*it2)->xpos / float((mapx / 128) * 1024)) * heightmap->w; + unsigned int hmapy = ((*it2)->zpos / float((mapy / 128) * 1024)) * heightmap->h; + (*it2)->ypos = hdr.minHeight + (float(hmap[hmapy * (mapx + 1) + hmapx]) / 32767.0) * (hdr.maxHeight - hdr.minHeight); + std::cout << "Feature " << (*it).first << " Instance " << (*it2) << " Terrain height: " << (*it2)->ypos << std::endl; + } + + fwrite((*it2), sizeof(MapFeatureStruct), 1, smffile); + } + } } - - } - - - - } - - hdr.tilesPtr = ftell(smffile); - uint32_t tc = m_tiles->GetTileCount(); - mthdr.numTiles = tc; - fwrite(&mthdr,sizeof(mthdr),1,smffile); - fwrite(&tc,4,1,smffile); - fwrite((m_name+std::string(".smt")).c_str(),(m_name+std::string(".smt")).length()+1,1,smffile); - fwrite(tiles,(mapx/4 * mapy/4)*4,1,smffile); - fseek(smffile,0,SEEK_SET); - fwrite(&hdr,sizeof(hdr),1,smffile); - fclose(smffile); - delete [] metalmap_data; - delete [] hmap; - delete [] typedata; - delete [] tiles; - delete [] minimap_data; - delete [] grass_data; + + hdr.tilesPtr = ftell(smffile); + uint32_t tc = m_tiles->GetTileCount(); + mthdr.numTiles = tc; + fwrite(&mthdr, sizeof(mthdr), 1, smffile); + fwrite(&tc, 4, 1, smffile); + fwrite((m_name + std::string(".smt")).c_str(), (m_name + std::string(".smt")).length() + 1, 1, smffile); + fwrite(tiles, (mapx / 4 * mapy / 4) * 4, 1, smffile); + fseek(smffile, 0, SEEK_SET); + fwrite(&hdr, sizeof(hdr), 1, smffile); + fclose(smffile); + delete[] metalmap_data; + delete[] hmap; + delete[] typedata; + delete[] tiles; + delete[] minimap_data; + delete[] grass_data; } -void SMFMap::DoCompress(int* indices, std::vector< uint64_t >& order) +void SMFMap::DoCompress(int* indices, std::vector& order) { - order.clear(); - - uint8_t tiledata[32*32*4]; - std::map existingtiles; - int c = 0; - for ( int y = 0; y < mapy/4; y++ ) - { - for ( int x = 0; x < mapx/4; x++ ) - { - if ( c % 50 == 0 ) - printf("\rCompressing %8d/%8d - %6d tiles ",c,mapy/4*mapx/4,m_tiles->GetTileCount()); - c++; - texture->GetRect(x*32,y*32,32,32,IL_RGBA,IL_UNSIGNED_BYTE,tiledata); - for ( int yy = 0; yy < 16; yy++ )//Flip vertically - { - char tmprow[32*4]; - memcpy(tmprow,&tiledata[(31-yy)*32*4],32*4); - memcpy(&tiledata[(31-yy)*32*4],&tiledata[yy*32*4],32*4); - memcpy(&tiledata[yy*32*4],tmprow,32*4); - } - // std::cout << "Compressing (" << x << "," << y << ")" << std::endl; - uint64_t uid = m_tiles->AddTileOrGetSimiliar(tiledata,m_th,m_comptype); - if ( existingtiles.find(uid) == existingtiles.end() ) - { - indices[(mapx/4)*y+x] = order.size(); - existingtiles[uid] = order.size(); - order.push_back(uid); - }else{ - indices[(mapx/4)*y+x] = existingtiles[uid]; - - } - - - } - - - - } - printf("\n"); - std::cout << "Compress done , ratio: " << float(existingtiles.size())/float(mapy/4 * mapx/4)*100.0 << std::endl; - + order.clear(); + + uint8_t tiledata[32 * 32 * 4]; + std::map existingtiles; + int c = 0; + for (int y = 0; y < mapy / 4; y++) { + for (int x = 0; x < mapx / 4; x++) { + if (c % 50 == 0) + printf("\rCompressing %8d/%8d - %6d tiles ", c, mapy / 4 * mapx / 4, m_tiles->GetTileCount()); + c++; + texture->GetRect(x * 32, y * 32, 32, 32, IL_RGBA, IL_UNSIGNED_BYTE, tiledata); + for (int yy = 0; yy < 16; yy++) //Flip vertically + { + char tmprow[32 * 4]; + memcpy(tmprow, &tiledata[(31 - yy) * 32 * 4], 32 * 4); + memcpy(&tiledata[(31 - yy) * 32 * 4], &tiledata[yy * 32 * 4], 32 * 4); + memcpy(&tiledata[yy * 32 * 4], tmprow, 32 * 4); + } + // std::cout << "Compressing (" << x << "," << y << ")" << std::endl; + uint64_t uid = m_tiles->AddTileOrGetSimiliar(tiledata, m_th, m_comptype); + if (existingtiles.find(uid) == existingtiles.end()) { + indices[(mapx / 4) * y + x] = order.size(); + existingtiles[uid] = order.size(); + order.push_back(uid); + } else { + indices[(mapx / 4) * y + x] = existingtiles[uid]; + } + } + } + printf("\n"); + std::cout << "Compress done , ratio: " << float(existingtiles.size()) / float(mapy / 4 * mapx / 4) * 100.0 << std::endl; } void SMFMap::SetCompressionTol(float th) { - m_th = th; + m_th = th; } void SMFMap::SetCompressionType(int c) { - m_comptype = c; + m_comptype = c; } - diff --git a/src/SMFMap.h b/src/SMFMap.h index e386777..09ce902 100644 --- a/src/SMFMap.h +++ b/src/SMFMap.h @@ -19,134 +19,127 @@ #ifndef SMFMAP_H #define SMFMAP_H -#include "TileStorage.h" #include "Image.h" +#include "TileStorage.h" #include typedef struct { - char magic[16]; ///< "spring map file\0" - int version; ///< Must be 1 for now - int mapid; ///< Sort of a GUID of the file, just set to a random value when writing a map + char magic[16]; ///< "spring map file\0" + int version; ///< Must be 1 for now + int mapid; ///< Sort of a GUID of the file, just set to a random value when writing a map - int mapx; ///< Must be divisible by 128 - int mapy; ///< Must be divisible by 128 - int squareSize; ///< Distance between vertices. Must be 8 - int texelPerSquare; ///< Number of texels per square, must be 8 for now - int tilesize; ///< Number of texels in a tile, must be 32 for now - float minHeight; ///< Height value that 0 in the heightmap corresponds to - float maxHeight; ///< Height value that 0xffff in the heightmap corresponds to + int mapx; ///< Must be divisible by 128 + int mapy; ///< Must be divisible by 128 + int squareSize; ///< Distance between vertices. Must be 8 + int texelPerSquare; ///< Number of texels per square, must be 8 for now + int tilesize; ///< Number of texels in a tile, must be 32 for now + float minHeight; ///< Height value that 0 in the heightmap corresponds to + float maxHeight; ///< Height value that 0xffff in the heightmap corresponds to - int heightmapPtr; ///< File offset to elevation data (short int[(mapy+1)*(mapx+1)]) - int typeMapPtr; ///< File offset to typedata (unsigned char[mapy/2 * mapx/2]) - int tilesPtr; ///< File offset to tile data (see MapTileHeader) - int minimapPtr; ///< File offset to minimap (always 1024*1024 dxt1 compresed data plus 8 mipmap sublevels) - int metalmapPtr; ///< File offset to metalmap (unsigned char[mapx/2 * mapy/2]) - int featurePtr; ///< File offset to feature data (see MapFeatureHeader) + int heightmapPtr; ///< File offset to elevation data (short int[(mapy+1)*(mapx+1)]) + int typeMapPtr; ///< File offset to typedata (unsigned char[mapy/2 * mapx/2]) + int tilesPtr; ///< File offset to tile data (see MapTileHeader) + int minimapPtr; ///< File offset to minimap (always 1024*1024 dxt1 compresed data plus 8 mipmap sublevels) + int metalmapPtr; ///< File offset to metalmap (unsigned char[mapx/2 * mapy/2]) + int featurePtr; ///< File offset to feature data (see MapFeatureHeader) int numExtraHeaders; ///< Numbers of extra headers following main header -} SMFHeader ; -typedef struct +} SMFHeader; +typedef struct { int numFeatureType; int numFeatures; -}MapFeatureHeader ; +} MapFeatureHeader; typedef struct { int numTileFiles; ///< Number of tile files to read in (usually 1) int numTiles; ///< Total number of tiles } MapTileHeader; -typedef struct{ +typedef struct { int size; ///< Size of extra header int type; ///< Type of extra header } ExtraHeader; typedef struct { - int featureType; ///< Index to one of the strings above - float xpos; ///< X coordinate of the feature - float ypos; ///< Y coordinate of the feature (height) - float zpos; ///< Z coordinate of the feature + int featureType; ///< Index to one of the strings above + float xpos; ///< X coordinate of the feature + float ypos; ///< Y coordinate of the feature (height) + float zpos; ///< Z coordinate of the feature float rotation; ///< Orientation of this feature (-32768..32767 for full circle) float relativeSize; ///< Not used at the moment keep 1 } MapFeatureStruct; typedef struct { - char magic[16]; ///< "spring tilefile\0" - int version; ///< Must be 1 for now + char magic[16]; ///< "spring tilefile\0" + int version; ///< Must be 1 for now - int numTiles; ///< Total number of tiles in this file - int tileSize; ///< Must be 32 for now + int numTiles; ///< Total number of tiles in this file + int tileSize; ///< Must be 32 for now int compressionType; ///< Must be 1 (= dxt1) for now } TileFileHeader; class InvalidMapSizeException { - }; class CannotLoadTextureException { - }; class CannotLoadSmfFileException { - - }; class InvalidSmfFileException { - }; class CannotOpenSmtFileException { - }; class InvalidSmtFileException { - }; class SMFMap { public: - SMFMap(std::string name,std::string texturepath); - SMFMap(std::string smfname); //Decompile - virtual ~SMFMap(); - void SetMetalMap(std::string path); - void SetTypeMap(std::string path); - //void SetFeatureMap(std::string path); - void SetHeightMap(std::string path); - void SetVegetationMap(std::string path); - void SetMiniMap(std::string path); - void Compile(); - void SetHeightRange(float minh,float maxh); - void SetCompressionTol(float th); - void SetCompressionType(int c); - void SetCompareTileCount(uint32_t count); - void SetClamping(bool b); - void SetBlur(bool b); - void SaveSourceFiles(); - void AddFeature(std::string name,float x, float y , float z,float orientation); - + SMFMap(std::string name, std::string texturepath); + SMFMap(std::string smfname); //Decompile + virtual ~SMFMap(); + void SetMetalMap(std::string path); + void SetTypeMap(std::string path); + //void SetFeatureMap(std::string path); + void SetHeightMap(std::string path); + void SetVegetationMap(std::string path); + void SetMiniMap(std::string path); + void Compile(); + void SetHeightRange(float minh, float maxh); + void SetCompressionTol(float th); + void SetCompressionType(int c); + void SetCompareTileCount(uint32_t count); + void SetClamping(bool b); + void SetBlur(bool b); + void SaveSourceFiles(); + void AddFeature(std::string name, float x, float y, float z, float orientation); + private: - void DoCompress(int * indices , std::vector& order); - TileStorage * m_tiles; - Image * metalmap; - //Image * featuremap; - Image * heightmap; - Image * typemap; - Image * texture; - Image * minimap; - Image * vegetationmap; - int mapx,mapy; - std::string m_name; - float m_minh; - float m_maxh; - float m_th; - bool m_doclamp; - bool m_smooth; - int m_comptype; - std::string texpath; - std::string m_smfname; - std::map * > features; + void DoCompress(int* indices, std::vector& order); + TileStorage* m_tiles; + Image* metalmap; + //Image * featuremap; + Image* heightmap; + Image* typemap; + Image* texture; + Image* minimap; + Image* vegetationmap; + int mapx, mapy; + std::string m_name; + float m_minh; + float m_maxh; + float m_th; + bool m_doclamp; + bool m_smooth; + int m_comptype; + std::string texpath; + std::string m_smfname; + std::map*> features; }; #endif // SMFMAP_H diff --git a/src/TileStorage.cpp b/src/TileStorage.cpp index 9d0f3ec..e8ded53 100644 --- a/src/TileStorage.cpp +++ b/src/TileStorage.cpp @@ -18,237 +18,194 @@ #include "TileStorage.h" -#include -#include -#include #include #include +#include +#include +#include #include #include -inline float tilediff(uint8_t * t1,uint8_t * t2) +inline float tilediff(uint8_t* t1, uint8_t* t2) { - float diff = 0.0; - for ( int i = 0; i < 32*32*4; i++ ) - { - float d1 = fabs(float(t1[i])-float(t2[i])); - if ( d1 < 30 ) - diff += d1; - else - diff += 255.0f;//If it has a point that is VERY different , it must not be reused - - - } - diff /= 32.0*32.0*4.0f*10.0f; - return diff; + float diff = 0.0; + for (int i = 0; i < 32 * 32 * 4; i++) { + float d1 = fabs(float(t1[i]) - float(t2[i])); + if (d1 < 30) + diff += d1; + else + diff += 255.0f; //If it has a point that is VERY different , it must not be reused + } + diff /= 32.0 * 32.0 * 4.0f * 10.0f; + return diff; } TileStorage::TileStorage() { - Reset(); - m_dictcount = 64; + Reset(); + m_dictcount = 64; } TileStorage::~TileStorage() { - Reset(); + Reset(); } void TileStorage::Reset() { - for ( std::map::iterator it = m_tiles.begin(); it != m_tiles.end(); it++ ) - { - if ( m_tiles_compressed.find((*it).first) != m_tiles_compressed.end() ) - { - delete [] m_tiles_compressed[(*it).first]; - - } - delete [] (*it).second; - } - m_tiles.clear(); - m_lasttiles.clear(); - m_tiles_compressed.clear(); + for (std::map::iterator it = m_tiles.begin(); it != m_tiles.end(); it++) { + if (m_tiles_compressed.find((*it).first) != m_tiles_compressed.end()) { + delete[] m_tiles_compressed[(*it).first]; + } + delete[](*it).second; + } + m_tiles.clear(); + m_lasttiles.clear(); + m_tiles_compressed.clear(); } uint64_t TileStorage::AddTile(uint8_t* data) { - uint64_t checksum = tilechecksum(data); - if ( m_tiles.find(checksum) != m_tiles.end() ) - { - std::cerr << "Duplicate tile detected, dropping!" << std::endl; - return checksum; - } - uint8_t* data_copy = new uint8_t[32*32*4]; - memcpy(data_copy,data,32*32*4); - m_tiles.insert(std::pair(checksum,data_copy)); - m_lasttiles.push_back(checksum); - if ( m_lasttiles.size() > m_dictcount ) - m_lasttiles.pop_front(); - return checksum; + uint64_t checksum = tilechecksum(data); + if (m_tiles.find(checksum) != m_tiles.end()) { + std::cerr << "Duplicate tile detected, dropping!" << std::endl; + return checksum; + } + uint8_t* data_copy = new uint8_t[32 * 32 * 4]; + memcpy(data_copy, data, 32 * 32 * 4); + m_tiles.insert(std::pair(checksum, data_copy)); + m_lasttiles.push_back(checksum); + if (m_lasttiles.size() > m_dictcount) + m_lasttiles.pop_front(); + return checksum; } void TileStorage::CompressAll() { - for ( std::map::iterator it = m_tiles.begin(); it != m_tiles.end(); it++ ) - { - if ( m_tiles_compressed.find((*it).first) == m_tiles_compressed.end() ) - { - CompressTile((*it).first); - - - } - - - } - + for (std::map::iterator it = m_tiles.begin(); it != m_tiles.end(); it++) { + if (m_tiles_compressed.find((*it).first) == m_tiles_compressed.end()) { + CompressTile((*it).first); + } + } } void TileStorage::SetDictSize(uint32_t s) { - m_dictcount = s; + m_dictcount = s; } void TileStorage::CompressTile(uint64_t uid) { - uint8_t * m0; - uint8_t * m1; - uint8_t * m2; - uint8_t * m3; - uint8_t * dataptr = m_tiles[uid]; - uint8_t * compressedmipmaps = new uint8_t[680]; - if ( !dataptr ) - { - delete [] compressedmipmaps; - throw InvalidTileDataPointerException(); - - } - uint32_t s; - uint32_t s2 = 0; - ILuint mip1 = ilGenImage(); - ilBindImage(mip1); - ilTexImage(32,32,1,4,IL_RGBA,IL_UNSIGNED_BYTE,dataptr); - /*std::stringstream ss; + uint8_t* m0; + uint8_t* m1; + uint8_t* m2; + uint8_t* m3; + uint8_t* dataptr = m_tiles[uid]; + uint8_t* compressedmipmaps = new uint8_t[680]; + if (!dataptr) { + delete[] compressedmipmaps; + throw InvalidTileDataPointerException(); + } + uint32_t s; + uint32_t s2 = 0; + ILuint mip1 = ilGenImage(); + ilBindImage(mip1); + ilTexImage(32, 32, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, dataptr); + /*std::stringstream ss; ss << "Tile" << uid << ".png"; ilSaveImage(ss.str().c_str());*/ - m0 = ilCompressDXT(ilGetData(),32,32,1,IL_DXT1,&s); - memcpy(&compressedmipmaps[s2],m0,s); - s2 += s; - iluScale(16,16,1); - m1 = ilCompressDXT(ilGetData(),16,16,1,IL_DXT1,&s); - memcpy(&compressedmipmaps[s2],m1,s); - s2 += s; - iluScale(8,8,1); - m2 = ilCompressDXT(ilGetData(),8,8,1,IL_DXT1,&s); - memcpy(&compressedmipmaps[s2],m2,s); - s2 += s; - iluScale(4,4,1); - m3 = ilCompressDXT(ilGetData(),4,4,1,IL_DXT1,&s); - memcpy(&compressedmipmaps[s2],m3,s); - s2 += s; - ilDeleteImage(mip1); - - /*squish::CompressImage(dataptr,32,32,m0,squish::kDxt1); + m0 = ilCompressDXT(ilGetData(), 32, 32, 1, IL_DXT1, &s); + memcpy(&compressedmipmaps[s2], m0, s); + s2 += s; + iluScale(16, 16, 1); + m1 = ilCompressDXT(ilGetData(), 16, 16, 1, IL_DXT1, &s); + memcpy(&compressedmipmaps[s2], m1, s); + s2 += s; + iluScale(8, 8, 1); + m2 = ilCompressDXT(ilGetData(), 8, 8, 1, IL_DXT1, &s); + memcpy(&compressedmipmaps[s2], m2, s); + s2 += s; + iluScale(4, 4, 1); + m3 = ilCompressDXT(ilGetData(), 4, 4, 1, IL_DXT1, &s); + memcpy(&compressedmipmaps[s2], m3, s); + s2 += s; + ilDeleteImage(mip1); + + /*squish::CompressImage(dataptr,32,32,m0,squish::kDxt1); squish::CompressImage(dataptr,16,16,m1,squish::kDxt1); squish::CompressImage(dataptr,8,8,m2,squish::kDxt1); squish::CompressImage(dataptr,4,4,m3,squish::kDxt1);*/ - - - - - free(m0); - free(m1); - free(m2); - free(m3); - - m_tiles_compressed[uid] = compressedmipmaps; - //std::cout << "Tile " << uid << " compressed!" << std::endl; - + + + free(m0); + free(m1); + free(m2); + free(m3); + + m_tiles_compressed[uid] = compressedmipmaps; + //std::cout << "Tile " << uid << " compressed!" << std::endl; } -void TileStorage::WriteToFile(FILE* f, std::vector< uint64_t >& tile_order) +void TileStorage::WriteToFile(FILE* f, std::vector& tile_order) { - char magic[16]; - strcpy(magic,"spring tilefile"); - int version = 1; - int numtiles = m_tiles_compressed.size(); - int tileSize = 32; - int compressionType = 1; - fwrite(magic,16,1,f); - fwrite(&version,4,1,f); - fwrite(&numtiles,4,1,f); - fwrite(&tileSize,4,1,f); - fwrite(&compressionType,4,1,f); - for ( std::vector< uint64_t >::const_iterator it = tile_order.begin(); it != tile_order.end(); it++ ) - { - if ( m_tiles_compressed.find(*it) == m_tiles_compressed.end() ) - { - CompressAll(); - - - } - if ( m_tiles_compressed.find(*it) == m_tiles_compressed.end() ) - { - throw InvalidTileIndexException(); - } - fwrite(m_tiles_compressed[*it],680,1,f); - } - fflush(f); + char magic[16]; + strcpy(magic, "spring tilefile"); + int version = 1; + int numtiles = m_tiles_compressed.size(); + int tileSize = 32; + int compressionType = 1; + fwrite(magic, 16, 1, f); + fwrite(&version, 4, 1, f); + fwrite(&numtiles, 4, 1, f); + fwrite(&tileSize, 4, 1, f); + fwrite(&compressionType, 4, 1, f); + for (std::vector::const_iterator it = tile_order.begin(); it != tile_order.end(); it++) { + if (m_tiles_compressed.find(*it) == m_tiles_compressed.end()) { + CompressAll(); + } + if (m_tiles_compressed.find(*it) == m_tiles_compressed.end()) { + throw InvalidTileIndexException(); + } + fwrite(m_tiles_compressed[*it], 680, 1, f); + } + fflush(f); } uint64_t TileStorage::AddTileOrGetSimiliar(uint8_t* data, float th, int compresslevel) { - uint64_t checksum = tilechecksum(data); - if ( m_tiles.find(checksum) != m_tiles.end() ) - { - //std::cout << "Debug(AddTileOrGetSimiliar): " << checksum << " already exists" << std::endl; - return checksum; - - } - if ( compresslevel == COMPRESS_INSANE ) - { - for ( std::map::iterator it = m_tiles.begin(); it != m_tiles.end(); it++ ) - { - if ( tilediff(data,(*it).second) < th ) - { - return (*it).first; - - } - - - } - }else if ( compresslevel == COMPRESS_REASONABLE ) - { - for ( std::list::iterator it = m_lasttiles.begin(); it != m_lasttiles.end(); it++ ) - { - if ( tilediff(data,m_tiles[(*it)]) < th ) - { - return (*it); - - } - } - - - }else if ( compresslevel == COMPRESS_SHITTY ) - { - //do nothing... - - }else if ( compresslevel == COMPRESS_REASONABLE_BESTQUALITY ) - { - float mindiff = 9999999.0f; - uint64_t besttile = 0; - for ( std::list::iterator it = m_lasttiles.begin(); it != m_lasttiles.end(); it++ ) - { - float diff = tilediff(data,m_tiles[(*it)]); - if ( diff < mindiff ) - { - besttile = (*it); - mindiff = diff; - - } - } - if ( mindiff <= th ) - return besttile; - - - } - return AddTile(data); + uint64_t checksum = tilechecksum(data); + if (m_tiles.find(checksum) != m_tiles.end()) { + //std::cout << "Debug(AddTileOrGetSimiliar): " << checksum << " already exists" << std::endl; + return checksum; + } + if (compresslevel == COMPRESS_INSANE) { + for (std::map::iterator it = m_tiles.begin(); it != m_tiles.end(); it++) { + if (tilediff(data, (*it).second) < th) { + return (*it).first; + } + } + } else if (compresslevel == COMPRESS_REASONABLE) { + for (std::list::iterator it = m_lasttiles.begin(); it != m_lasttiles.end(); it++) { + if (tilediff(data, m_tiles[(*it)]) < th) { + return (*it); + } + } + + + } else if (compresslevel == COMPRESS_SHITTY) { + //do nothing... + + } else if (compresslevel == COMPRESS_REASONABLE_BESTQUALITY) { + float mindiff = 9999999.0f; + uint64_t besttile = 0; + for (std::list::iterator it = m_lasttiles.begin(); it != m_lasttiles.end(); it++) { + float diff = tilediff(data, m_tiles[(*it)]); + if (diff < mindiff) { + besttile = (*it); + mindiff = diff; + } + } + if (mindiff <= th) + return besttile; + } + return AddTile(data); } uint32_t TileStorage::GetTileCount() { - return std::max(m_tiles_compressed.size(),m_tiles.size()); + return std::max(m_tiles_compressed.size(), m_tiles.size()); } diff --git a/src/TileStorage.h b/src/TileStorage.h index 23375e1..e988930 100644 --- a/src/TileStorage.h +++ b/src/TileStorage.h @@ -18,66 +18,60 @@ #ifndef TILESTORAGE_H #define TILESTORAGE_H -#include +#include "CRC.h" +#include #include -#include +#include #include -#include -#include "CRC.h" -inline uint64_t tilechecksum( uint8_t * data ) +#include +inline uint64_t tilechecksum(uint8_t* data) { - uint64_t r = 0; - for ( int x = 0; x < 32*32*4; x++ ) - { - r += data[x]*63018038201L*x*x; - r ^= 13091204281L; - r *= 13091204281L*x; - r *= 108086391056891903ULL*data[x]; - } - Crc32 c; - c.AddData(data,32*32*4); - r *= c.GetCrc32(); - return r; - + uint64_t r = 0; + for (int x = 0; x < 32 * 32 * 4; x++) { + r += data[x] * 63018038201L * x * x; + r ^= 13091204281L; + r *= 13091204281L * x; + r *= 108086391056891903ULL * data[x]; + } + Crc32 c; + c.AddData(data, 32 * 32 * 4); + r *= c.GetCrc32(); + return r; } class InvalidTileIndexException { - - }; class InvalidTileDataPointerException { - - }; -enum CompressLevels -{ - COMPRESS_SHITTY = 1, - COMPRESS_REASONABLE = 2, - COMPRESS_INSANE = 3, - COMPRESS_REASONABLE_BESTQUALITY = 4 - - +enum CompressLevels { + COMPRESS_SHITTY = 1, + COMPRESS_REASONABLE = 2, + COMPRESS_INSANE = 3, + COMPRESS_REASONABLE_BESTQUALITY = 4 + + }; class TileStorage { public: - TileStorage(); - virtual ~TileStorage(); - uint64_t AddTile( uint8_t * data ); // 32x32 RGBA - void WriteToFile( FILE * f , std::vector& tile_order); - uint64_t AddTileOrGetSimiliar( uint8_t* data, float th, int compresslevel ); - uint32_t GetTileCount(); - void SetDictSize(uint32_t s); - void Reset(); + TileStorage(); + virtual ~TileStorage(); + uint64_t AddTile(uint8_t* data); // 32x32 RGBA + void WriteToFile(FILE* f, std::vector& tile_order); + uint64_t AddTileOrGetSimiliar(uint8_t* data, float th, int compresslevel); + uint32_t GetTileCount(); + void SetDictSize(uint32_t s); + void Reset(); + private: - void CompressAll(); - void CompressTile(uint64_t uid); - std::map m_tiles; - std::map m_tiles_compressed; - std::list m_lasttiles; - unsigned int m_dictcount; + void CompressAll(); + void CompressTile(uint64_t uid); + std::map m_tiles; + std::map m_tiles_compressed; + std::list m_lasttiles; + unsigned int m_dictcount; }; #endif // TILESTORAGE_H diff --git a/src/decompiler.cpp b/src/decompiler.cpp index dbe38e4..bdf5154 100644 --- a/src/decompiler.cpp +++ b/src/decompiler.cpp @@ -1,92 +1,73 @@ +#include "SMFMap.h" #include #include -#include "SMFMap.h" #include #ifdef WIN32 -#include #include #include +#include #else #include #endif -void help(char ** argv) +void help(char** argv) { - std::cout << "Usage: " << argv[0] << " -directory [directory where .smt files are] -mapfile [name of the smf file , NOT path ]" << std::endl; - + std::cout << "Usage: " << argv[0] << " -directory [directory where .smt files are] -mapfile [name of the smf file , NOT path ]" << std::endl; } int main(int argc, char** argv) { - ilInit(); - if ( argc == 1 ) - { - - help(argv); - return 1; - }else{ - std::string mapdirectory; - std::string mapfile; - bool valid1=false,valid2=false; - for ( int i = 1; i < argc; i++ ) - { - if ( strlen(argv[i]) > 1 ) - { - if ( argv[i][0] == '-' ) - { - if ( strcmp(&argv[i][1],"directory") == 0 ) - { - valid1 = true; - if ( i+1 < argc ) - { - mapdirectory = argv[++i]; - }else{ - goto error; - } - }else if ( strcmp(&argv[i][1],"mapfile") == 0 ) - { - if ( i+1 < argc ) - { - mapfile = argv[++i]; - }else{ - goto error; - } - valid2 = true; - - } - else if ( strncmp(&argv[i][1],"h",1) == 0 )//Help - { - goto error; - } - - - - - - - } - - } - - } - - if ( valid1 && valid2 ) - goto success; - error: - help(argv); - return 1; - success: + ilInit(); + if (argc == 1) { + + help(argv); + return 1; + } else { + std::string mapdirectory; + std::string mapfile; + bool valid1 = false, valid2 = false; + for (int i = 1; i < argc; i++) { + if (strlen(argv[i]) > 1) { + if (argv[i][0] == '-') { + if (strcmp(&argv[i][1], "directory") == 0) { + valid1 = true; + if (i + 1 < argc) { + mapdirectory = argv[++i]; + } else { + goto error; + } + } else if (strcmp(&argv[i][1], "mapfile") == 0) { + if (i + 1 < argc) { + mapfile = argv[++i]; + } else { + goto error; + } + valid2 = true; + + } else if (strncmp(&argv[i][1], "h", 1) == 0) //Help + { + goto error; + } + } + } + } + + if (valid1 && valid2) + goto success; + error: + help(argv); + return 1; + success: #ifndef WIN32 - if ( chdir(mapdirectory.c_str()) ) + if (chdir(mapdirectory.c_str())) #else - if ( _chdir(mapdirectory.c_str()) ) + if (_chdir(mapdirectory.c_str())) #endif - { - std::cerr << "Cannot change working directory to " << mapdirectory << std::endl; - return 1; + { + std::cerr << "Cannot change working directory to " << mapdirectory << std::endl; + return 1; + } + SMFMap* m = new SMFMap(mapfile); + m->SaveSourceFiles(); + delete m; } - SMFMap * m = new SMFMap(mapfile); - m->SaveSourceFiles(); - delete m; - } } - diff --git a/src/main.cpp b/src/main.cpp index 228bb12..6bbd66e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,246 +1,214 @@ +#include "SMFMap.h" #include #include #include -#include "SMFMap.h" #include -void help(char ** argv) +void help(char** argv) { - std::cout << "Usage: " << argv[0] << " -t [maintexture] -m [metalmap] -z [typemap] -h [heightmap] -maxh [white height value] -minh [black height value] -o [outputsuffix] -minimap [minimap_image]" << std::endl; - std::cout << " -ct [compression_type] -ccount [compare_tilecount] -th [compression_level] -features [featurefile]" << std::endl; - std::cout << " -noclamp disables heightmap clamping to max - min values , you should avoid using that , cause you lose precision, if you want less high landscape use maxh and minh" << std::endl; - std::cout << "Compression types:\n\t1: No compression \n\t2: Fast compression , compare tile with last -ccount tiles , take first which difference is below -th\n\t3: Insane Compression: compare each tile with whole map , it is very SLOW, not recomended\n\t4: High quality Fast compression: Slightly slower than 2 , it searchs for less different tile in last -ccount tiles" << std::endl; - std::cout << "Feature file: Each line is a feature instance and has the fields in the following order [tdfname] [xpos] [ypos] [zpos] [rotation yaxis] , please do not leave whitespaces at the end or it\n will give errors." << std::endl; - std::cout << "If you specify less than -490000 as ypos , it will calculate ypos depending on terrain height" << std::endl; - + std::cout << "Usage: " << argv[0] << " -t [maintexture] -m [metalmap] -z [typemap] -h [heightmap] -maxh [white height value] -minh [black height value] -o [outputsuffix] -minimap [minimap_image]" << std::endl; + std::cout << " -ct [compression_type] -ccount [compare_tilecount] -th [compression_level] -features [featurefile]" << std::endl; + std::cout << " -noclamp disables heightmap clamping to max - min values , you should avoid using that , cause you lose precision, if you want less high landscape use maxh and minh" << std::endl; + std::cout << "Compression types:\n\t1: No compression \n\t2: Fast compression , compare tile with last -ccount tiles , take first which difference is below -th\n\t3: Insane Compression: compare each tile with whole map , it is very SLOW, not recomended\n\t4: High quality Fast compression: Slightly slower than 2 , it searchs for less different tile in last -ccount tiles" << std::endl; + std::cout << "Feature file: Each line is a feature instance and has the fields in the following order [tdfname] [xpos] [ypos] [zpos] [rotation yaxis] , please do not leave whitespaces at the end or it\n will give errors." << std::endl; + std::cout << "If you specify less than -490000 as ypos , it will calculate ypos depending on terrain height" << std::endl; } int main(int argc, char** argv) { - ilInit(); - if ( argc == 1 ) - { - - help(argv); - return 1; - }else{ - bool valid2 = false; - bool valid1 = false; - std::string outputname; - std::string texture; - std::string minimap; - std::string metalmap; - std::string typemap; - std::string heightmap; - std::string vegmap; - std::string featurefile; - bool smooth = false; - int tcount = 64; - float minh = 0.0f; - bool clamping = true; - float maxh = 1.0f; - int ct = COMPRESS_REASONABLE; - float th = 0.8; - for ( int i = 1; i < argc; i++ ) - { - if ( strlen(argv[i]) > 1 ) - { - if ( argv[i][0] == '-' ) - { - if ( strcmp(&argv[i][1],"t") == 0 ) - { - valid1 = true; - if ( i+1 < argc ) - { - texture = argv[++i]; - }else{ - goto error; - } - }else if ( strcmp(&argv[i][1],"m") == 0 )//Metal - { - if ( i+1 < argc ) - { - metalmap = argv[++i]; - }else{ - goto error; - } - - }else if ( strcmp(&argv[i][1],"z") == 0 )//Type - { - if ( i+1 < argc ) - { - typemap = argv[++i]; - }else{ - goto error; - } - - }else if ( strcmp(&argv[i][1],"h") == 0 )//Height - { - if ( i+1 < argc ) - { - heightmap = argv[++i]; - }else{ - goto error; - } - - }else if ( strcmp(&argv[i][1],"maxh") == 0 )//Max Height - { - if ( i+1 < argc ) - { - maxh = atof(argv[++i]); - }else{ - goto error; - } - - }else if ( strcmp(&argv[i][1],"minh") == 0 )//Min Height - { - if ( i+1 < argc ) - { - minh = atof(argv[++i]); - }else{ - goto error; - } - - }else if ( strcmp(&argv[i][1],"o") == 0 )//Output name - { - if ( i+1 < argc ) - { - outputname = argv[++i]; - }else{ - goto error; - } - valid2 = true; - - }else if ( strcmp(&argv[i][1],"minimap") == 0 )//Minimap - { - if ( i+1 < argc ) - { - minimap = argv[++i]; - }else{ - goto error; - } - - }else if ( strcmp(&argv[i][1],"th") == 0 )//Compression level - { - if ( i+1 < argc ) - { - th = atof(argv[++i]); - }else{ - goto error; - } - - } - else if ( strcmp(&argv[i][1],"ct") == 0 )//Compression mode - { - if ( i+1 < argc ) - { - ct = atoi(argv[++i]); - }else{ - goto error; - } - - }else if ( strcmp(&argv[i][1],"ccount") == 0 )//Compression , count of tiles to comapre in mode 2 and 4 - { - if ( i+1 < argc ) - { - tcount = atoi(argv[++i]); - }else{ - goto error; - } - - } - else if ( strcmp(&argv[i][1],"v") == 0 )//Vegetation map - { - if ( i+1 < argc ) - { - vegmap = argv[++i]; - }else{ - goto error; - } - - }else if ( strcmp(&argv[i][1],"noclamp") == 0 )//No heightmap clamp - { - clamping = false; - - }else if ( strcmp(&argv[i][1],"features") == 0 )//features file - { - - if ( i+1 < argc ) - { - featurefile = argv[++i]; - }else{ - goto error; - } - - } - else if ( strcmp(&argv[i][1],"smooth") == 0 )//Smooth - { - smooth = true; - - } - else if ( strncmp(&argv[i][1],"h",1) == 0 )//Help - { - goto error; - } - - - - - - - } - - } - - } - - if ( valid1 && valid2 ) - goto success; - error: - help(argv); - return 1; - success: - SMFMap * m = new SMFMap(outputname,texture); - m->SetBlur(smooth); - if ( heightmap.length() > 0 ) m->SetHeightMap(heightmap); - if ( metalmap.length() > 0 ) m->SetMetalMap(metalmap); - if ( typemap.length() > 0 ) m->SetTypeMap(typemap); - if ( minimap.length() > 0 ) m->SetMiniMap(minimap); - if ( vegmap.length() > 0 ) m->SetVegetationMap(vegmap); - m->SetCompareTileCount(tcount); - m->SetHeightRange(minh,maxh); - m->SetCompressionTol(th); - m->SetCompressionType(ct); - m->SetClamping(clamping); - if ( featurefile.length() > 0 ) - { - FILE * ff = fopen(featurefile.c_str(),"r"); - if (!ff) - { - std::cerr << "Cannot open feature file for reading!" <AddFeature(name,x,y,z,o); - } - fclose(ff); - + ilInit(); + if (argc == 1) { + + help(argv); + return 1; + } else { + bool valid2 = false; + bool valid1 = false; + std::string outputname; + std::string texture; + std::string minimap; + std::string metalmap; + std::string typemap; + std::string heightmap; + std::string vegmap; + std::string featurefile; + bool smooth = false; + int tcount = 64; + float minh = 0.0f; + bool clamping = true; + float maxh = 1.0f; + int ct = COMPRESS_REASONABLE; + float th = 0.8; + for (int i = 1; i < argc; i++) { + if (strlen(argv[i]) > 1) { + if (argv[i][0] == '-') { + if (strcmp(&argv[i][1], "t") == 0) { + valid1 = true; + if (i + 1 < argc) { + texture = argv[++i]; + } else { + goto error; + } + } else if (strcmp(&argv[i][1], "m") == 0) //Metal + { + if (i + 1 < argc) { + metalmap = argv[++i]; + } else { + goto error; + } + + } else if (strcmp(&argv[i][1], "z") == 0) //Type + { + if (i + 1 < argc) { + typemap = argv[++i]; + } else { + goto error; + } + + } else if (strcmp(&argv[i][1], "h") == 0) //Height + { + if (i + 1 < argc) { + heightmap = argv[++i]; + } else { + goto error; + } + + } else if (strcmp(&argv[i][1], "maxh") == 0) //Max Height + { + if (i + 1 < argc) { + maxh = atof(argv[++i]); + } else { + goto error; + } + + } else if (strcmp(&argv[i][1], "minh") == 0) //Min Height + { + if (i + 1 < argc) { + minh = atof(argv[++i]); + } else { + goto error; + } + + } else if (strcmp(&argv[i][1], "o") == 0) //Output name + { + if (i + 1 < argc) { + outputname = argv[++i]; + } else { + goto error; + } + valid2 = true; + + } else if (strcmp(&argv[i][1], "minimap") == 0) //Minimap + { + if (i + 1 < argc) { + minimap = argv[++i]; + } else { + goto error; + } + + } else if (strcmp(&argv[i][1], "th") == 0) //Compression level + { + if (i + 1 < argc) { + th = atof(argv[++i]); + } else { + goto error; + } + + } else if (strcmp(&argv[i][1], "ct") == 0) //Compression mode + { + if (i + 1 < argc) { + ct = atoi(argv[++i]); + } else { + goto error; + } + + } else if (strcmp(&argv[i][1], "ccount") == 0) //Compression , count of tiles to comapre in mode 2 and 4 + { + if (i + 1 < argc) { + tcount = atoi(argv[++i]); + } else { + goto error; + } + + } else if (strcmp(&argv[i][1], "v") == 0) //Vegetation map + { + if (i + 1 < argc) { + vegmap = argv[++i]; + } else { + goto error; + } + + } else if (strcmp(&argv[i][1], "noclamp") == 0) //No heightmap clamp + { + clamping = false; + + } else if (strcmp(&argv[i][1], "features") == 0) //features file + { + + if (i + 1 < argc) { + featurefile = argv[++i]; + } else { + goto error; + } + + } else if (strcmp(&argv[i][1], "smooth") == 0) //Smooth + { + smooth = true; + + } else if (strncmp(&argv[i][1], "h", 1) == 0) //Help + { + goto error; + } + } + } + } + + if (valid1 && valid2) + goto success; + error: + help(argv); + return 1; + success: + SMFMap* m = new SMFMap(outputname, texture); + m->SetBlur(smooth); + if (heightmap.length() > 0) + m->SetHeightMap(heightmap); + if (metalmap.length() > 0) + m->SetMetalMap(metalmap); + if (typemap.length() > 0) + m->SetTypeMap(typemap); + if (minimap.length() > 0) + m->SetMiniMap(minimap); + if (vegmap.length() > 0) + m->SetVegetationMap(vegmap); + m->SetCompareTileCount(tcount); + m->SetHeightRange(minh, maxh); + m->SetCompressionTol(th); + m->SetCompressionType(ct); + m->SetClamping(clamping); + if (featurefile.length() > 0) { + FILE* ff = fopen(featurefile.c_str(), "r"); + if (!ff) { + std::cerr << "Cannot open feature file for reading!" << std::endl; + return 1; + } + char line[512]; + while (fgets(line, 511, ff)) { + float x, y, z, o; + char name[512]; + if (strlen(line) < 1) + continue; + if (sscanf(line, "%s %f %f %f %f", name, &x, &y, &z, &o) != 5) { + std::cerr << "Parse error @ '" << line << "'" << std::endl; + return 1; + } + m->AddFeature(name, x, y, z, o); + } + fclose(ff); + } + m->Compile(); + delete m; } - m->Compile(); - delete m; - } } - From b4491b14f8034fa462f51e00be4b20cf1fbfd7d5 Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 22:44:07 +0200 Subject: [PATCH 20/38] header -> .cpp --- src/TileStorage.cpp | 16 ++++++++++++++++ src/TileStorage.h | 15 +-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/TileStorage.cpp b/src/TileStorage.cpp index e8ded53..9a2d4e7 100644 --- a/src/TileStorage.cpp +++ b/src/TileStorage.cpp @@ -25,6 +25,22 @@ #include #include #include + +inline uint64_t tilechecksum(uint8_t* data) +{ + uint64_t r = 0; + for (int x = 0; x < 32 * 32 * 4; x++) { + r += data[x] * 63018038201L * x * x; + r ^= 13091204281L; + r *= 13091204281L * x; + r *= 108086391056891903ULL * data[x]; + } + Crc32 c; + c.AddData(data, 32 * 32 * 4); + r *= c.GetCrc32(); + return r; +} + inline float tilediff(uint8_t* t1, uint8_t* t2) { float diff = 0.0; diff --git a/src/TileStorage.h b/src/TileStorage.h index e988930..22245a5 100644 --- a/src/TileStorage.h +++ b/src/TileStorage.h @@ -24,20 +24,7 @@ #include #include #include -inline uint64_t tilechecksum(uint8_t* data) -{ - uint64_t r = 0; - for (int x = 0; x < 32 * 32 * 4; x++) { - r += data[x] * 63018038201L * x * x; - r ^= 13091204281L; - r *= 13091204281L * x; - r *= 108086391056891903ULL * data[x]; - } - Crc32 c; - c.AddData(data, 32 * 32 * 4); - r *= c.GetCrc32(); - return r; -} + class InvalidTileIndexException { }; From fc913fe16894bde49afcaa8be59df636f003d28c Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 22:44:56 +0200 Subject: [PATCH 21/38] fix include --- src/TileStorage.cpp | 2 ++ src/TileStorage.h | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/TileStorage.cpp b/src/TileStorage.cpp index 9a2d4e7..fe50063 100644 --- a/src/TileStorage.cpp +++ b/src/TileStorage.cpp @@ -18,6 +18,8 @@ #include "TileStorage.h" +#include "CRC.h" + #include #include #include diff --git a/src/TileStorage.h b/src/TileStorage.h index 22245a5..138bfe0 100644 --- a/src/TileStorage.h +++ b/src/TileStorage.h @@ -18,7 +18,6 @@ #ifndef TILESTORAGE_H #define TILESTORAGE_H -#include "CRC.h" #include #include #include From 0fcf4e2ae3f435b6d3533bcf6e44ad5990fa3433 Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 22:49:20 +0200 Subject: [PATCH 22/38] cleanup header --- src/SMFMap.cpp | 4 ++++ src/SMFMap.h | 8 ++++++-- src/decompiler.cpp | 1 + src/main.cpp | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/SMFMap.cpp b/src/SMFMap.cpp index 5421282..42cf4a3 100644 --- a/src/SMFMap.cpp +++ b/src/SMFMap.cpp @@ -18,11 +18,15 @@ #include "SMFMap.h" +#include "Image.h" +#include "TileStorage.h" #include #include #include #include #include + + #ifndef bzero #define bzero(ptr, len) memset(ptr, 0, len) diff --git a/src/SMFMap.h b/src/SMFMap.h index 09ce902..6376ad2 100644 --- a/src/SMFMap.h +++ b/src/SMFMap.h @@ -19,9 +19,13 @@ #ifndef SMFMAP_H #define SMFMAP_H -#include "Image.h" -#include "TileStorage.h" #include +#include +#include +#include + +class Image; +class TileStorage; typedef struct { char magic[16]; ///< "spring map file\0" diff --git a/src/decompiler.cpp b/src/decompiler.cpp index bdf5154..ddfbea6 100644 --- a/src/decompiler.cpp +++ b/src/decompiler.cpp @@ -1,6 +1,7 @@ #include "SMFMap.h" #include #include +#include #include #ifdef WIN32 diff --git a/src/main.cpp b/src/main.cpp index 6bbd66e..674fca2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include "SMFMap.h" +#include "TileStorage.h" #include #include #include From 39d37314a1e699ad99a6c2984b7fd29c2ef18fe0 Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 22:52:30 +0200 Subject: [PATCH 23/38] fix travis compile --- src/SMFMap.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SMFMap.h b/src/SMFMap.h index 6376ad2..0d4bc20 100644 --- a/src/SMFMap.h +++ b/src/SMFMap.h @@ -23,6 +23,7 @@ #include #include #include +#include class Image; class TileStorage; From 4e6155a523f3a021b3bdd63cb07a9085b60f21bf Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 22:56:03 +0200 Subject: [PATCH 24/38] update to trusty --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 765bf46..6fe840b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: cpp +dist: trusty +sudo: required compiler: - gcc - clang From f2b0409ff33cdb6cf0ad1889ca85fce2451505ab Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 23:04:41 +0200 Subject: [PATCH 25/38] use c++11 --- CMakeLists.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 919a89f..adb83a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,17 @@ project(SpringMapConvNG) -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 2.8) + +macro(use_cxx11) + if (CMAKE_VERSION VERSION_LESS "3.1") + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set (CMAKE_CXX_FLAGS "--std=gnu++11 ${CMAKE_CXX_FLAGS}") + endif () + else () + set (CMAKE_CXX_STANDARD 11) + endif () +endmacro(use_cxx11) + +use_cxx11() LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") From 90ef2bdd61a6054dc2ce13413c6d0661c2c709e1 Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 23:08:27 +0200 Subject: [PATCH 26/38] fix include order --- src/SMFMap.h | 6 +++--- src/decompiler.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SMFMap.h b/src/SMFMap.h index 0d4bc20..2a2d8eb 100644 --- a/src/SMFMap.h +++ b/src/SMFMap.h @@ -19,11 +19,11 @@ #ifndef SMFMAP_H #define SMFMAP_H +#include +#include +#include #include #include -#include -#include -#include class Image; class TileStorage; diff --git a/src/decompiler.cpp b/src/decompiler.cpp index ddfbea6..79c1013 100644 --- a/src/decompiler.cpp +++ b/src/decompiler.cpp @@ -1,7 +1,7 @@ #include "SMFMap.h" +#include #include #include -#include #include #ifdef WIN32 From c106286d4ece07f936050d9a4164c80b1cab2d6c Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 23:13:11 +0200 Subject: [PATCH 27/38] fix ident --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0bfcc16..22f234c 100644 --- a/README.md +++ b/README.md @@ -10,5 +10,5 @@ for details see http://springrts.com/wiki/MapConvNG to compile install g++/clang, cmake, DevIL-dev. then run - cmake . - make + cmake . + make From 97b0149360a6e56e637ef801376d784d890b375f Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 11 Jul 2017 23:17:14 +0200 Subject: [PATCH 28/38] http -> https & add LICENSE info --- LICENSE | 339 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 +- src/CRC.cpp | 2 + src/CRC.h | 2 + src/Image.cpp | 19 +-- src/Image.h | 19 +-- src/SMFMap.cpp | 19 +-- src/SMFMap.h | 19 +-- src/TileStorage.cpp | 19 +-- src/TileStorage.h | 18 +-- src/decompiler.cpp | 2 + src/main.cpp | 2 +- 12 files changed, 353 insertions(+), 109 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d511905 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/README.md b/README.md index 22f234c..ea1388e 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ SpringMapConvNG is a map compiler for the spring rts engine. it also contains a decompiler, smfdecompiler. -for details see http://springrts.com/wiki/MapConvNG +for details see https://springrts.com/wiki/MapConvNG # compile diff --git a/src/CRC.cpp b/src/CRC.cpp index 48cb29b..0d49e8a 100644 --- a/src/CRC.cpp +++ b/src/CRC.cpp @@ -1,3 +1,5 @@ +/* This file is part of SpringMapConvNG (GPL v2 or later), see the LICENSE file */ + #include "CRC.h" static const uint32_t kCrc32Table[256] = { diff --git a/src/CRC.h b/src/CRC.h index 6f7692b..4b1b69d 100644 --- a/src/CRC.h +++ b/src/CRC.h @@ -1,3 +1,5 @@ +/* This file is part of SpringMapConvNG (GPL v2 or later), see the LICENSE file */ + #ifndef CRC_H #define CRC_H diff --git a/src/Image.cpp b/src/Image.cpp index cae92a0..00ca9e5 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -1,21 +1,4 @@ -/* - - Copyright (C) 2011 Tiziano - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - +/* This file is part of SpringMapConvNG (GPL v2 or later), see the LICENSE file */ #include "Image.h" diff --git a/src/Image.h b/src/Image.h index 656454c..621338e 100644 --- a/src/Image.h +++ b/src/Image.h @@ -1,21 +1,4 @@ -/* - - Copyright (C) 2011 Tiziano - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - +/* This file is part of SpringMapConvNG (GPL v2 or later), see the LICENSE file */ #ifndef IMAGE_H #define IMAGE_H diff --git a/src/SMFMap.cpp b/src/SMFMap.cpp index 42cf4a3..28c6432 100644 --- a/src/SMFMap.cpp +++ b/src/SMFMap.cpp @@ -1,21 +1,4 @@ -/* - - Copyright (C) 2011 Tiziano - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - +/* This file is part of SpringMapConvNG (GPL v2 or later), see the LICENSE file */ #include "SMFMap.h" #include "Image.h" diff --git a/src/SMFMap.h b/src/SMFMap.h index 2a2d8eb..cef12d1 100644 --- a/src/SMFMap.h +++ b/src/SMFMap.h @@ -1,21 +1,4 @@ -/* - - Copyright (C) 2011 Tiziano - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - +/* This file is part of SpringMapConvNG (GPL v2 or later), see the LICENSE file */ #ifndef SMFMAP_H #define SMFMAP_H diff --git a/src/TileStorage.cpp b/src/TileStorage.cpp index fe50063..f6c85ab 100644 --- a/src/TileStorage.cpp +++ b/src/TileStorage.cpp @@ -1,21 +1,4 @@ -/* - - Copyright (C) 2011 Tiziano - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - +/* This file is part of SpringMapConvNG (GPL v2 or later), see the LICENSE file */ #include "TileStorage.h" #include "CRC.h" diff --git a/src/TileStorage.h b/src/TileStorage.h index 138bfe0..5d0c4e5 100644 --- a/src/TileStorage.h +++ b/src/TileStorage.h @@ -1,20 +1,4 @@ -/* - Copyright (C) 2011 Tiziano - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - +/* This file is part of SpringMapConvNG (GPL v2 or later), see the LICENSE file */ #ifndef TILESTORAGE_H #define TILESTORAGE_H diff --git a/src/decompiler.cpp b/src/decompiler.cpp index 79c1013..71b99c5 100644 --- a/src/decompiler.cpp +++ b/src/decompiler.cpp @@ -1,3 +1,5 @@ +/* This file is part of SpringMapConvNG (GPL v2 or later), see the LICENSE file */ + #include "SMFMap.h" #include #include diff --git a/src/main.cpp b/src/main.cpp index 674fca2..21196fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ - +/* This file is part of SpringMapConvNG (GPL v2 or later), see the LICENSE file */ #include "SMFMap.h" #include "TileStorage.h" From 6f2146b8f36b17ad6c7d53bf30279826b8b5d369 Mon Sep 17 00:00:00 2001 From: abma Date: Wed, 14 Mar 2018 21:07:48 +0100 Subject: [PATCH 29/38] add hacks for cross compile with mxe --- .gitignore | 1 + CMakeLists.txt | 15 ++++- cmake/FindDevIL.cmake | 143 ------------------------------------------ 3 files changed, 13 insertions(+), 146 deletions(-) delete mode 100644 cmake/FindDevIL.cmake diff --git a/.gitignore b/.gitignore index add6e85..6b99d43 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ *.swp *.so *.a +*.exe /smfdecompiler /springMapConvNG /.ninja_deps diff --git a/CMakeLists.txt b/CMakeLists.txt index adb83a4..122ec49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ project(SpringMapConvNG) -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.0) macro(use_cxx11) if (CMAKE_VERSION VERSION_LESS "3.1") @@ -30,8 +30,17 @@ set(MAPCONV_FILES add_executable(springMapConvNG src/main.cpp ${MAPCONV_FILES}) add_executable(smfdecompiler src/decompiler.cpp ${MAPCONV_FILES}) -target_link_libraries(springMapConvNG ${IL_LIBRARIES}) -target_link_libraries(smfdecompiler ${IL_LIBRARIES}) +if(FALSE) # change to TRUE when compiling with statix mxe + add_definitions(-DIL_STATIC_LIB) + set(LINKLIBS png tiff lzma Half IlmImf IlmThread Iex jasper jpeg z) + set_target_properties(springMapConvNG PROPERTIES LINK_FLAGS "-static" ) + set_target_properties(smfdecompiler PROPERTIES LINK_FLAGS "-static" ) +endif() + +target_link_libraries(springMapConvNG ${IL_LIBRARIES} ${ILU_LIBRARIES} ${LINKLIBS}) +target_link_libraries(smfdecompiler ${IL_LIBRARIES} ${ILU_LIBRARIES} ${LINKLIBS}) + + install(TARGETS springMapConvNG smfdecompiler RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin ) diff --git a/cmake/FindDevIL.cmake b/cmake/FindDevIL.cmake deleted file mode 100644 index 1f4e286..0000000 --- a/cmake/FindDevIL.cmake +++ /dev/null @@ -1,143 +0,0 @@ -# Downloaded from: http://www-id.imag.fr/FLOWVR/manual/flowvr-suite-src/flowvr-render/cmake/ -# License: GPL v2, http://www-id.imag.fr/FLOWVR/manual/flowvr-suite-src/flowvr-render/COPYING -# -# Modifications: -# 2008.01.16 Tobi Vollebregt -- changed Devil->DEVIL for consistency -# -- added devil, ilu, ilut alternative names for MinGW -# -- removed "looking for devil" status message - -# - Find DevIL -# Find the native DevIL includes and libraries. -# -# IL_INCLUDE_DIR - Where to find "IL/il.h", "IL/ilu.h" and "IL/ilut.h" -# IL_IL_LIBRARY - Path to the IL shared library -# IL_ILU_LIBRARY - Path to the ILU shared library -# IL_ILUT_LIBRARY - Path to the ILUT shared library -# IL_LIBRARIES - List of libraries when using IL -# IL_FOUND - True if IL is found. - -INCLUDE(FindPackageHandleStandardArgs) - -IF (IL_INCLUDE_DIR AND IL_IL_LIBRARY) - # Already in cache, be silent - SET(DevIL_FIND_QUIETLY TRUE) -ENDIF (IL_INCLUDE_DIR AND IL_IL_LIBRARY) - - - -set(IL_FIND_LIB_STD_ARGS - PATH_SUFFIXES - lib64 - lib - libs64 - libs - libs/Win32 - libs/Win64 - PATHS - ${PROJECT_BINARY_DIR} - ${PROJECT_SOURCE_DIR} - $ENV{LD_LIBRARY_PATH} - $ENV{LIBRARY_PATH} - /usr - /usr/local - /usr/bin - ) - -FIND_LIBRARY(IL_IL_LIBRARY - NAMES - IL - devil - DevIL - ${IL_FIND_LIB_STD_ARGS} -) - -FIND_LIBRARY(IL_ILU_LIBRARY - NAMES - ilu - ILU - ${IL_FIND_LIB_STD_ARGS} -) - -FIND_LIBRARY(IL_ILUT_LIBRARY - NAMES - ilut - ILUT - ${IL_FIND_LIB_STD_ARGS} -) - -SET(IL_LIBRARIES "") -IF (IL_IL_LIBRARY) - LIST(APPEND IL_LIBRARIES ${IL_IL_LIBRARY}) -ENDIF (IL_IL_LIBRARY) -IF (IL_ILU_LIBRARY) - LIST(APPEND IL_LIBRARIES ${IL_ILU_LIBRARY}) -ENDIF (IL_ILU_LIBRARY) -IF (IL_ILUT_LIBRARY) - LIST(APPEND IL_LIBRARIES ${IL_ILUT_LIBRARY}) -ENDIF (IL_ILUT_LIBRARY) - -GET_FILENAME_COMPONENT(IL_LIBRARY_DIR "${IL_IL_LIBRARY}" PATH) -GET_FILENAME_COMPONENT(IL_LIBRARY_SUPER_DIR "${IL_LIBRARY_DIR}" PATH) - - - -set(IL_FIND_HEADER_STD_ARGS - PATHS - ${PROJECT_BINARY_DIR}/include - ${PROJECT_SOURCE_DIR}/include - ${IL_LIBRARY_SUPER_DIR}/include - $ENV{CPATH} - /usr/local/include - /usr/include - NO_DEFAULT_PATH - ) - -FIND_FILE(IL_IL_HEADER IL/il.h - ${IL_FIND_INCLUDE_STD_ARGS} -) - -FIND_FILE(IL_ILU_HEADER IL/ilu.h - ${IL_FIND_INCLUDE_STD_ARGS} -) - -FIND_FILE(IL_ILUT_HEADER IL/ilut.h - ${IL_FIND_INCLUDE_STD_ARGS} -) - -FIND_PATH(IL_INCLUDE_DIR IL/il.h - ${IL_FIND_INCLUDE_STD_ARGS} -) - - - -# handle the QUIETLY and REQUIRED arguments and set IL_FOUND to TRUE if -# all listed variables are TRUE -FIND_PACKAGE_HANDLE_STANDARD_ARGS(DevIL DEFAULT_MSG IL_IL_HEADER IL_INCLUDE_DIR IL_IL_LIBRARY IL_LIBRARIES) - -IF (IL_ILU_HEADER AND IL_ILU_LIBRARY) - SET(IL_ILU_FOUND TRUE) - IF (NOT DevIL_FIND_QUIETLY) - MESSAGE(STATUS "Found DevIL-ILU: ${IL_ILU_LIBRARY} - ${IL_ILU_HEADER}") - ENDIF (NOT DevIL_FIND_QUIETLY) -ELSE (IL_ILU_HEADER AND IL_ILU_LIBRARY) - SET(IL_ILU_FOUND FALSE) -ENDIF (IL_ILU_HEADER AND IL_ILU_LIBRARY) - -IF (IL_ILUT_HEADER AND IL_ILUT_LIBRARY) - SET(IL_ILUT_FOUND TRUE) - IF (NOT DevIL_FIND_QUIETLY) - MESSAGE(STATUS "Found DevIL-ILUT: ${IL_ILUT_LIBRARY} - ${IL_ILUT_HEADER}") - ENDIF (NOT DevIL_FIND_QUIETLY) -ELSE (IL_ILUT_HEADER AND IL_ILUT_LIBRARY) - SET(IL_ILUT_FOUND FALSE) -ENDIF (IL_ILUT_HEADER AND IL_ILUT_LIBRARY) - - - -MARK_AS_ADVANCED( - IL_INCLUDE_DIR - IL_IL_LIBRARY - IL_ILU_LIBRARY - IL_ILUT_LIBRARY - IL_LIBRARIES - ) From 01fe69b84bc8da5bcdaddb502608cac5c56f33aa Mon Sep 17 00:00:00 2001 From: abma Date: Mon, 10 Sep 2018 22:34:26 +0200 Subject: [PATCH 30/38] cleanup --- CMakeLists.txt | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 122ec49..10f1ee1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,7 @@ project(SpringMapConvNG) -cmake_minimum_required(VERSION 3.0) - -macro(use_cxx11) - if (CMAKE_VERSION VERSION_LESS "3.1") - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set (CMAKE_CXX_FLAGS "--std=gnu++11 ${CMAKE_CXX_FLAGS}") - endif () - else () - set (CMAKE_CXX_STANDARD 11) - endif () -endmacro(use_cxx11) - -use_cxx11() - -LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +cmake_minimum_required(VERSION 3.1) +set (CMAKE_CXX_STANDARD 11) find_package(DevIL REQUIRED) @@ -30,7 +17,9 @@ set(MAPCONV_FILES add_executable(springMapConvNG src/main.cpp ${MAPCONV_FILES}) add_executable(smfdecompiler src/decompiler.cpp ${MAPCONV_FILES}) -if(FALSE) # change to TRUE when compiling with statix mxe +option(MAPCONV_STATIC "link static" FALSE) + +if(MAPCONV_STATIC) add_definitions(-DIL_STATIC_LIB) set(LINKLIBS png tiff lzma Half IlmImf IlmThread Iex jasper jpeg z) set_target_properties(springMapConvNG PROPERTIES LINK_FLAGS "-static" ) From 363dec62ac958ea8de4f9e2136a60d53cb52faf0 Mon Sep 17 00:00:00 2001 From: abma Date: Wed, 4 Sep 2019 22:21:04 +0000 Subject: [PATCH 31/38] fix spring static build the dirty way --- CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10f1ee1..2cc560a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,11 +17,9 @@ set(MAPCONV_FILES add_executable(springMapConvNG src/main.cpp ${MAPCONV_FILES}) add_executable(smfdecompiler src/decompiler.cpp ${MAPCONV_FILES}) -option(MAPCONV_STATIC "link static" FALSE) - -if(MAPCONV_STATIC) +if(PREFER_STATIC_LIBS) # inside spring build add_definitions(-DIL_STATIC_LIB) - set(LINKLIBS png tiff lzma Half IlmImf IlmThread Iex jasper jpeg z) + set(LINKLIBS ${PNG_LIBRARY_RELEASE} ${TIFF_LIBRARY_RELEASE} ${JPEG_LIBRARY} ${ZLIB_LIBRARY_RELEASE}) set_target_properties(springMapConvNG PROPERTIES LINK_FLAGS "-static" ) set_target_properties(smfdecompiler PROPERTIES LINK_FLAGS "-static" ) endif() From 10e693aa377a24ebb9433ee027d4525766c42c8f Mon Sep 17 00:00:00 2001 From: abma Date: Sat, 5 Oct 2019 15:41:35 +0200 Subject: [PATCH 32/38] fix install path for spring --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cc560a..45085ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,5 +29,5 @@ target_link_libraries(smfdecompiler ${IL_LIBRARIES} ${ILU_LIBRARIES} ${LINKLIBS} -install(TARGETS springMapConvNG smfdecompiler RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin ) +install(TARGETS springMapConvNG smfdecompiler RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}) From 28e2335672abdf921288c047b90027098dc1aa38 Mon Sep 17 00:00:00 2001 From: abma Date: Sat, 5 Oct 2019 16:05:08 +0200 Subject: [PATCH 33/38] rename to mapcompile / mapdecompile --- .gitignore | 4 ++-- CMakeLists.txt | 19 +++++++++++-------- src/{main.cpp => mapcompile.cpp} | 0 src/{decompiler.cpp => mapdecompile.cpp} | 0 4 files changed, 13 insertions(+), 10 deletions(-) rename src/{main.cpp => mapcompile.cpp} (100%) rename src/{decompiler.cpp => mapdecompile.cpp} (100%) diff --git a/.gitignore b/.gitignore index 6b99d43..f6c71a9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,8 +7,8 @@ *.so *.a *.exe -/smfdecompiler -/springMapConvNG +/mapcompile +/mapdecompile /.ninja_deps /.ninja_log /build.ninja diff --git a/CMakeLists.txt b/CMakeLists.txt index 45085ab..360050b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,20 +14,23 @@ set(MAPCONV_FILES src/TileStorage.cpp ) -add_executable(springMapConvNG src/main.cpp ${MAPCONV_FILES}) -add_executable(smfdecompiler src/decompiler.cpp ${MAPCONV_FILES}) +add_executable(mapcompile src/mapcompile.cpp ${MAPCONV_FILES}) +add_executable(mapdecompile src/mapdecompile.cpp ${MAPCONV_FILES}) if(PREFER_STATIC_LIBS) # inside spring build add_definitions(-DIL_STATIC_LIB) set(LINKLIBS ${PNG_LIBRARY_RELEASE} ${TIFF_LIBRARY_RELEASE} ${JPEG_LIBRARY} ${ZLIB_LIBRARY_RELEASE}) - set_target_properties(springMapConvNG PROPERTIES LINK_FLAGS "-static" ) - set_target_properties(smfdecompiler PROPERTIES LINK_FLAGS "-static" ) + set_target_properties(mapcompile PROPERTIES LINK_FLAGS "-static" ) + set_target_properties(mapdecompile PROPERTIES LINK_FLAGS "-static" ) endif() -target_link_libraries(springMapConvNG ${IL_LIBRARIES} ${ILU_LIBRARIES} ${LINKLIBS}) -target_link_libraries(smfdecompiler ${IL_LIBRARIES} ${ILU_LIBRARIES} ${LINKLIBS}) +target_link_libraries(mapcompile ${IL_LIBRARIES} ${ILU_LIBRARIES} ${LINKLIBS}) +target_link_libraries(mapdecompile ${IL_LIBRARIES} ${ILU_LIBRARIES} ${LINKLIBS}) - -install(TARGETS springMapConvNG smfdecompiler RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}) +if (${BINDIR}) + install(TARGETS mapcompile mapdecompile RUNTIME DESTINATION ${BINDIR}) +else() + install(TARGETS mapcompile mapcompile RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) +endif() diff --git a/src/main.cpp b/src/mapcompile.cpp similarity index 100% rename from src/main.cpp rename to src/mapcompile.cpp diff --git a/src/decompiler.cpp b/src/mapdecompile.cpp similarity index 100% rename from src/decompiler.cpp rename to src/mapdecompile.cpp From 76429b4a64d7312c79aa95ef3f73e8c89478e63d Mon Sep 17 00:00:00 2001 From: abma Date: Mon, 14 Oct 2019 21:22:03 +0200 Subject: [PATCH 34/38] (try to) fix check --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 360050b..1abbbaa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ target_link_libraries(mapcompile ${IL_LIBRARIES} ${ILU_LIBRARIES} ${LINKLIBS}) target_link_libraries(mapdecompile ${IL_LIBRARIES} ${ILU_LIBRARIES} ${LINKLIBS}) -if (${BINDIR}) +if (DEFINED BINDIR) install(TARGETS mapcompile mapdecompile RUNTIME DESTINATION ${BINDIR}) else() install(TARGETS mapcompile mapcompile RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) From 0ddd86eaa8871dc0833c69f931f55cd856c5009d Mon Sep 17 00:00:00 2001 From: abma Date: Sun, 9 Jan 2022 12:55:22 +0100 Subject: [PATCH 35/38] fix some cmakelint warnings --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1abbbaa..56fe8d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ if(PREFER_STATIC_LIBS) # inside spring build set(LINKLIBS ${PNG_LIBRARY_RELEASE} ${TIFF_LIBRARY_RELEASE} ${JPEG_LIBRARY} ${ZLIB_LIBRARY_RELEASE}) set_target_properties(mapcompile PROPERTIES LINK_FLAGS "-static" ) set_target_properties(mapdecompile PROPERTIES LINK_FLAGS "-static" ) -endif() +endif () target_link_libraries(mapcompile ${IL_LIBRARIES} ${ILU_LIBRARIES} ${LINKLIBS}) target_link_libraries(mapdecompile ${IL_LIBRARIES} ${ILU_LIBRARIES} ${LINKLIBS}) @@ -30,7 +30,7 @@ target_link_libraries(mapdecompile ${IL_LIBRARIES} ${ILU_LIBRARIES} ${LINKLIBS}) if (DEFINED BINDIR) install(TARGETS mapcompile mapdecompile RUNTIME DESTINATION ${BINDIR}) -else() +else () install(TARGETS mapcompile mapcompile RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) -endif() +endif () From 80c41ff3649b3bcaa08b360efdf003f9c788581f Mon Sep 17 00:00:00 2001 From: abma Date: Sun, 8 Jan 2023 13:59:12 +0100 Subject: [PATCH 36/38] bump cmake --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 56fe8d9..9c7c965 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ project(SpringMapConvNG) -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.3) set (CMAKE_CXX_STANDARD 11) find_package(DevIL REQUIRED) From 4f5481053b1d2942d1901b3fe7f2a33b0eb15419 Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 17 Jan 2023 17:34:41 +0100 Subject: [PATCH 37/38] switch to pkgconfig --- .gitignore | 1 + CMakeLists.txt | 33 +++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index f6c71a9..5ab6702 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *.so *.a *.exe +*~ /mapcompile /mapdecompile /.ninja_deps diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c7c965..31451d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,11 +2,11 @@ project(SpringMapConvNG) cmake_minimum_required(VERSION 3.3) set (CMAKE_CXX_STANDARD 11) -find_package(DevIL REQUIRED) +find_package(PkgConfig REQUIRED) +pkg_check_modules(IL REQUIRED IL) +pkg_check_modules(ILU REQUIRED ILU) -include_directories(${IL_INCLUDE_DIR}) - set(MAPCONV_FILES src/CRC.cpp src/Image.cpp @@ -14,18 +14,27 @@ set(MAPCONV_FILES src/TileStorage.cpp ) + add_executable(mapcompile src/mapcompile.cpp ${MAPCONV_FILES}) add_executable(mapdecompile src/mapdecompile.cpp ${MAPCONV_FILES}) -if(PREFER_STATIC_LIBS) # inside spring build - add_definitions(-DIL_STATIC_LIB) - set(LINKLIBS ${PNG_LIBRARY_RELEASE} ${TIFF_LIBRARY_RELEASE} ${JPEG_LIBRARY} ${ZLIB_LIBRARY_RELEASE}) - set_target_properties(mapcompile PROPERTIES LINK_FLAGS "-static" ) - set_target_properties(mapdecompile PROPERTIES LINK_FLAGS "-static" ) -endif () - -target_link_libraries(mapcompile ${IL_LIBRARIES} ${ILU_LIBRARIES} ${LINKLIBS}) -target_link_libraries(mapdecompile ${IL_LIBRARIES} ${ILU_LIBRARIES} ${LINKLIBS}) +foreach(target mapcompile mapdecompile) + if(PREFER_STATIC_LIBS) # inside spring build + target_compile_definitions(${target} PRIVATE IL_STATIC_LIB) + set_target_properties(${target} PROPERTIES LINK_FLAGS "-static" ) + endif () + + target_link_libraries(${target} + PRIVATE + ${IL_LINK_LIBRARIES} + ${ILU_LINK_LIBRARIES} + ) + target_include_directories(${target} + PRIVATE + ${IL_INCLUDE_DIRS} + ${ILU_INCLUDE_DIRS} + ) +endforeach() if (DEFINED BINDIR) From b68099706beadc57dfebac9a4bebbd807d99f65f Mon Sep 17 00:00:00 2001 From: abma Date: Tue, 17 Jan 2023 18:04:25 +0100 Subject: [PATCH 38/38] try to fix linking --- CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31451d8..6627d16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.3) set (CMAKE_CXX_STANDARD 11) find_package(PkgConfig REQUIRED) -pkg_check_modules(IL REQUIRED IL) pkg_check_modules(ILU REQUIRED ILU) @@ -26,12 +25,10 @@ foreach(target mapcompile mapdecompile) target_link_libraries(${target} PRIVATE - ${IL_LINK_LIBRARIES} ${ILU_LINK_LIBRARIES} ) target_include_directories(${target} PRIVATE - ${IL_INCLUDE_DIRS} ${ILU_INCLUDE_DIRS} ) endforeach()