From dc81075ee14c4df36b621ad0f3197c9ef3a7e653 Mon Sep 17 00:00:00 2001 From: lzwdgc Date: Tue, 31 Jul 2018 01:28:23 +0300 Subject: [PATCH] Switch to cppan. --- .gitignore | 12 +- .gitmodules | 0 CMakeLists.txt | 48 ------ cppan.yml | 172 +++++++++++++++++++ src/CMakeLists.txt | 92 ---------- src/common/buffer.cpp | 5 +- src/{db_extractor => common}/db.cpp | 0 src/{db_extractor => common}/db.h | 0 src/common/dxt5.h | 26 +-- src/common/objects.cpp | 2 +- src/common/objects.h | 4 +- src/common/tga.h | 64 +++---- src/common/types.h | 10 +- src/db_add_language/db_add_language.cpp | 15 +- src/db_extractor/db_extractor.cpp | 17 +- src/mmm_extractor/mmm_extractor.cpp | 14 +- src/mmo_extractor/mmo_extractor.cpp | 33 ++-- src/mmo_extractor/other.h | 8 +- src/mmp_extractor/mmp.cpp | 21 ++- src/mmp_extractor/mmp_extractor.cpp | 14 +- src/mod_converter/fbx.cpp | 2 +- src/mod_converter/mod_converter.cpp | 77 +-------- src/mod_reader/mod_reader.cpp | 48 +----- src/mpj_loader/mpj_loader.cpp | 17 +- src/save_loader/save.h | 2 + src/save_loader/save_loader.cpp | 23 +-- src/script2txt/CMakeLists.txt | 48 ------ src/script2txt/ParserDriver.cpp | 62 ------- src/script2txt/ParserDriver.h | 54 ------ src/script2txt/script.h | 4 +- src/script2txt/script2txt.cpp | 26 +-- src/script2txt/{lexer.ll => script2txt.ll} | 18 +- src/script2txt/{grammar.yy => script2txt.yy} | 40 ++--- src/tm_converter/tm_converter.cpp | 26 +-- 34 files changed, 342 insertions(+), 662 deletions(-) delete mode 100644 .gitmodules delete mode 100644 CMakeLists.txt delete mode 100644 src/CMakeLists.txt rename src/{db_extractor => common}/db.cpp (100%) rename src/{db_extractor => common}/db.h (100%) delete mode 100644 src/script2txt/CMakeLists.txt delete mode 100644 src/script2txt/ParserDriver.cpp delete mode 100644 src/script2txt/ParserDriver.h rename src/script2txt/{lexer.ll => script2txt.ll} (88%) rename src/script2txt/{grammar.yy => script2txt.yy} (93%) diff --git a/.gitignore b/.gitignore index 27ac7de..60784fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ -win* -build -.cppan \ No newline at end of file +win* +build +bin +.cppan + +*.dll +*.lnk +*.exe +*.bat diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29..0000000 diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 0260f20..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -# -# A.I.M. Tools -# - -cmake_minimum_required(VERSION 2.8) - -set(output_dir ${CMAKE_BINARY_DIR}/bin) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${output_dir}) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${output_dir}) - -# Use solution folders. -set_property(GLOBAL PROPERTY USE_FOLDERS ON) -set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake Targets") - -project(aim_tools) - -find_package(BISON 3.0 REQUIRED) -find_package(FLEX 2.5.35 REQUIRED) -find_package(Git) - -if (MSVC) - set(disable_msvc_warnings "/W1 /wd4996") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP ${disable_msvc_warnings}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP ${disable_msvc_warnings} /std:c++17") -else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++17") -endif(MSVC) - -add_definitions(-DPOLYGON4_TOOLS=1) -add_definitions(-DPOLYGON4_STATIC=1) - -set(CPPAN_BUILD_SHARED_LIBS 0) -add_subdirectory(.cppan) - -if (Git_FOUND) - add_custom_target(version ALL - COMMAND git rev-list HEAD --count > ${CMAKE_CURRENT_BINARY_DIR}/version.h_ - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/version.h_ ${CMAKE_CURRENT_BINARY_DIR}/version.h.in - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) - set_target_properties(version PROPERTIES FOLDER Helpers) -else() - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/version.h.in "0") -endif() - -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -add_subdirectory(src) diff --git a/cppan.yml b/cppan.yml index d6000d1..cac07bc 100644 --- a/cppan.yml +++ b/cppan.yml @@ -6,3 +6,175 @@ local_settings: - pvt.egorpugin.primitives.executor: master - pvt.cppan.demo.unicode.icu.i18n: "*" - pvt.cppan.demo.taywee.args: "*" + + #build_dir_type: local + use_shared_libs: false + rc_enabled: false + builds: + vs_release: + generator: Visual Studio 15 2017 + vs_release64: + generator: Visual Studio 15 2017 Win64 + vs_preview: + c_compiler: c:/Program Files (x86)/Microsoft Visual Studio/Preview/Community/VC/Tools/MSVC/14.11.25325/bin/HostX64/x86/cl.exe + cxx_compiler: c:/Program Files (x86)/Microsoft Visual Studio/Preview/Community/VC/Tools/MSVC/14.11.25325/bin/HostX64/x86/cl.exe + cxx_flags: /std:c++17 + gcc8: + c_compiler: gcc-8 + cxx_compiler: g++-8 + #generator: Ninja + macos: + c_compiler: clang + cxx_compiler: clang++ + vs_llvm: + toolset: LLVM-vs2014 + win_clang_ninja: + generator: Ninja + c_compiler: clang-cl + cxx_compiler: clang-cl + use_cache: false + +add_directories: + - d:/dev/primitives + - dir: d:/dev/ue4/AIM/DataManager + name: data_manager + +common_settings: + c++: 17 + +projects: + common: + type: lib + static_only: true + root_dir: src/common + dependencies: + - name: pvt.egorpugin.primitives.filesystem + version: master + local: primitives.filesystem + - name: pvt.egorpugin.primitives.sw.main + version: master + local: primitives.sw.main + + db_add_language: + root_dir: src/db_add_language + dependencies: + - common + - name: pvt.lzwdgc.polygon4.data_manager.data_manager + version: master + local: data_manager.data_manager + - name: pvt.egorpugin.primitives.executor + version: master + local: primitives.executor + + db_extractor: + root_dir: src/db_extractor + dependencies: + - common + + unpaker: + root_dir: src/unpaker + + mmm_extractor: + root_dir: src/mmm_extractor + dependencies: + - common + - name: pvt.lzwdgc.polygon4.data_manager.data_manager + version: master + local: data_manager.data_manager + + mmo_extractor: + root_dir: src/mmo_extractor + dependencies: + - common + - name: pvt.lzwdgc.polygon4.data_manager.data_manager + version: master + local: data_manager.data_manager + + mmp_extractor: + root_dir: src/mmp_extractor + dependencies: + - common + + model: + type: lib + static_only: true + root_dir: src/model + dependencies: + - common + - pvt.cppan.demo.unicode.icu.i18n: "*" + + mod_converter: + root_dir: src/mod_converter + dependencies: + - model + post_sources: | + set(FBX_SDK_ROOT "d:/arh/apps/Autodesk/FBX/FBX SDK/2019.0/") + target_link_libraries(${this} PUBLIC + debug "${FBX_SDK_ROOT}/lib/vs2015/x86/debug/libfbxsdk-md.lib" + optimized "${FBX_SDK_ROOT}/lib/vs2015/x86/release/libfbxsdk-md.lib" + ) + target_include_directories(${this} PUBLIC + "${FBX_SDK_ROOT}/include" + ) + + mod_reader: + root_dir: src/mod_reader + dependencies: + - model + + mpj_loader: + root_dir: src/mpj_loader + dependencies: + - common + + tm_converter: + root_dir: src/tm_converter + dependencies: + - common + + name_generator: + root_dir: src/name_generator + + save_loader: + root_dir: src/save_loader + dependencies: + - common + + script2txt: + root_dir: src/script2txt + files: .* + dependencies: + - common + - name: pvt.lzwdgc.polygon4.data_manager.schema + version: master + local: data_manager.schema + - name: pvt.cppan.demo.lexxmark.winflexbison.flex + version: master + ref: flex + condition: + - WIN32 + - name: pvt.cppan.demo.lexxmark.winflexbison.bison + version: master + ref: bison + condition: + - WIN32 + post_target: | + cppan_flex_bison_pair(LALR1_CPP_VARIANT_PARSER script2txt) + + + + + + + + + + + + + + + + + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 0c59b9e..0000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,92 +0,0 @@ -file(GLOB common_src "common/*") -add_library(common ${common_src}) -target_include_directories(common PUBLIC common) -target_link_libraries(common - pvt.egorpugin.primitives.filesystem - pvt.egorpugin.primitives.executor -) -add_dependencies(common version) - -if (WIN32) -file(GLOB db_add_language_src "db_add_language/*") -add_executable(db_add_language ${db_add_language_src} db_extractor/db.cpp) -target_link_libraries(db_add_language - common - pvt.lzwdgc.polygon4.data_manager.data_manager -) - -file(GLOB db_extractor_src "db_extractor/*") -add_executable(db_extractor ${db_extractor_src}) -target_link_libraries(db_extractor common) - -file(GLOB unpaker_src "unpaker/*") -add_executable(unpaker ${unpaker_src}) -endif() - -file(GLOB mmm_extractor_src "mmm_extractor/*") -add_executable(mmm_extractor ${mmm_extractor_src}) -target_link_libraries(mmm_extractor - common - pvt.lzwdgc.polygon4.data_manager.data_manager -) - -file(GLOB mmo_extractor_src "mmo_extractor/*") -add_executable(mmo_extractor ${mmo_extractor_src}) -target_link_libraries(mmo_extractor - common - pvt.lzwdgc.polygon4.data_manager.data_manager - pvt.cppan.demo.taywee.args -) - -file(GLOB mmp_extractor_src "mmp_extractor/*") -add_executable(mmp_extractor ${mmp_extractor_src}) -target_link_libraries(mmp_extractor - common -) - -file(GLOB model_src "model/*") -add_library(model ${model_src}) -target_link_libraries(model - common - pvt.cppan.demo.unicode.icu.i18n -) -target_include_directories(model PUBLIC model) - -if (DEFINED FBX_SDK_ROOT) - file(GLOB mod_converter_src "mod_converter/*") - add_executable(mod_converter ${mod_converter_src}) - target_link_libraries(mod_converter - common - model - #pvt.cppan.demo.eigen - pvt.cppan.demo.taywee.args - debug "${FBX_SDK_ROOT}/lib/vs2015/x86/debug/libfbxsdk-md.lib" - optimized "${FBX_SDK_ROOT}/lib/vs2015/x86/release/libfbxsdk-md.lib" - ) - target_include_directories(mod_converter - PUBLIC "${FBX_SDK_ROOT}/include" - ) -else() - message(STATUS "provide fbx sdk path to build mod converter") -endif() - -file(GLOB mod_reader_src "mod_reader/*") -add_executable(mod_reader ${mod_reader_src}) -target_link_libraries(mod_reader model) - -file(GLOB mpj_loader_src "mpj_loader/*") -add_executable(mpj_loader ${mpj_loader_src}) -target_link_libraries(mpj_loader common) - -file(GLOB tm_converter_src "tm_converter/*") -add_executable(tm_converter ${tm_converter_src}) -target_link_libraries(tm_converter common) - -file(GLOB name_generator_src "name_generator/*") -add_executable(name_generator ${name_generator_src}) - -file(GLOB save_loader_src "save_loader/*") -add_executable(save_loader ${save_loader_src}) -target_link_libraries(save_loader common) - -add_subdirectory(script2txt) diff --git a/src/common/buffer.cpp b/src/common/buffer.cpp index 6a2a226..e4743f8 100644 --- a/src/common/buffer.cpp +++ b/src/common/buffer.cpp @@ -24,10 +24,11 @@ #include -const int build_version = -#include +const int build_version = 0 +//#include ; +// use as getVersionString() from settings? std::string version() { using namespace std; diff --git a/src/db_extractor/db.cpp b/src/common/db.cpp similarity index 100% rename from src/db_extractor/db.cpp rename to src/common/db.cpp diff --git a/src/db_extractor/db.h b/src/common/db.h similarity index 100% rename from src/db_extractor/db.h rename to src/common/db.h diff --git a/src/common/dxt5.h b/src/common/dxt5.h index a8d307b..c4b77fe 100644 --- a/src/common/dxt5.h +++ b/src/common/dxt5.h @@ -60,19 +60,19 @@ struct dxt5_block a[1] = this->a[1]; if (a[0] > a[1]) { - a[2] = double(6 * a[0] + 1 * a[1]) / 7.0; - a[3] = double(5 * a[0] + 2 * a[1]) / 7.0; - a[4] = double(4 * a[0] + 3 * a[1]) / 7.0; - a[5] = double(3 * a[0] + 4 * a[1]) / 7.0; - a[6] = double(2 * a[0] + 5 * a[1]) / 7.0; - a[7] = double(1 * a[0] + 6 * a[1]) / 7.0; + a[2] = (uint8_t)(double(6 * a[0] + 1 * a[1]) / 7.0); + a[3] = (uint8_t)(double(5 * a[0] + 2 * a[1]) / 7.0); + a[4] = (uint8_t)(double(4 * a[0] + 3 * a[1]) / 7.0); + a[5] = (uint8_t)(double(3 * a[0] + 4 * a[1]) / 7.0); + a[6] = (uint8_t)(double(2 * a[0] + 5 * a[1]) / 7.0); + a[7] = (uint8_t)(double(1 * a[0] + 6 * a[1]) / 7.0); } else { - a[2] = double(4 * a[0] + 1 * a[1]) / 5.0; - a[3] = double(3 * a[0] + 2 * a[1]) / 5.0; - a[4] = double(2 * a[0] + 3 * a[1]) / 5.0; - a[5] = double(1 * a[0] + 4 * a[1]) / 5.0; + a[2] = (uint8_t)(double(4 * a[0] + 1 * a[1]) / 5.0); + a[3] = (uint8_t)(double(3 * a[0] + 2 * a[1]) / 5.0); + a[4] = (uint8_t)(double(2 * a[0] + 3 * a[1]) / 5.0); + a[5] = (uint8_t)(double(1 * a[0] + 4 * a[1]) / 5.0); a[6] = 0; a[7] = 255; } @@ -103,7 +103,7 @@ struct dxt5_block { color r; for (int i = 0; i < 4; i++) - r.byte[i] = c0.byte[i] * m + c1.byte[i] * (1 - m); + r.byte[i] = uint8_t(c0.byte[i] * m + c1.byte[i] * (1 - m)); return r; } }; @@ -134,7 +134,7 @@ struct dxt5 mat m(width, height); auto big_xsegs = width / 64; auto big_ysegs = height / 64; - for (int seg = 0; seg < blocks.size(); seg++) + for (size_t seg = 0; seg < blocks.size(); seg++) { auto &d = blocks[seg]; int big_seg = seg / 256; @@ -151,7 +151,7 @@ struct dxt5 { mat m(width, height); auto xsegs = width / 4; - for (int seg = 0; seg < blocks.size(); seg++) + for (size_t seg = 0; seg < blocks.size(); seg++) { auto &d = blocks[seg]; auto xseg = seg % xsegs; diff --git a/src/common/objects.cpp b/src/common/objects.cpp index 69e8c11..d276a5e 100644 --- a/src/common/objects.cpp +++ b/src/common/objects.cpp @@ -86,7 +86,7 @@ void Objects::load(const buffer &b) uint32_t n_segments = 0; READ(b, n_segments); - for (int s = 0; s < n_segments; s++) + for (uint32_t s = 0; s < n_segments; s++) { auto seg = Segment::create_segment(b); if (!seg) diff --git a/src/common/objects.h b/src/common/objects.h index 13cddd0..5582486 100644 --- a/src/common/objects.h +++ b/src/common/objects.h @@ -80,7 +80,7 @@ struct SegmentObjects : public Segment virtual void load(const buffer &b) { - for (int i = 0; i < n_objects; i++) + for (uint32_t i = 0; i < n_objects; i++) { T* o = new T; o->load(b); @@ -126,7 +126,7 @@ struct MapObjectWithArray : public MapObject READ(b, len); unk0.resize(len); - for (int i = 0; i < len; i++) + for (uint32_t i = 0; i < len; i++) READ(b, unk0[i]); } }; diff --git a/src/common/tga.h b/src/common/tga.h index 860199f..29d765e 100644 --- a/src/common/tga.h +++ b/src/common/tga.h @@ -6,8 +6,8 @@ #pragma pack(push, 1) -// http://paulbourke.net/dataformats/tga/ -struct tga +// http://paulbourke.net/dataformats/tga/ +struct tga { uint8_t idlength; // label length uint8_t colourmaptype = 0; @@ -20,33 +20,33 @@ struct tga uint16_t width; uint16_t height; uint8_t bitsperpixel = 32; - uint8_t imagedescriptor = 0x28; - - tga() - { - idlength = strlen(label()); - } - constexpr const char *label() const - { - return "AIMTMConverter"; - } - - void write(buffer &b) - { - b.write(idlength); - b.write(colourmaptype); - b.write(datatypecode); - b.write(colourmaporigin); - b.write(colourmaplength); - b.write(colourmapdepth); - b.write(x_origin); - b.write(y_origin); - b.write(width); - b.write(height); - b.write(bitsperpixel); - b.write(imagedescriptor); - b.write(label(), idlength); - } -}; - -#pragma pack(pop) + uint8_t imagedescriptor = 0x28; + + tga() + { + idlength = (uint8_t)strlen(label()); + } + constexpr const char *label() const + { + return "AIMTMConverter"; + } + + void write(buffer &b) + { + b.write(idlength); + b.write(colourmaptype); + b.write(datatypecode); + b.write(colourmaporigin); + b.write(colourmaplength); + b.write(colourmapdepth); + b.write(x_origin); + b.write(y_origin); + b.write(width); + b.write(height); + b.write(bitsperpixel); + b.write(imagedescriptor); + b.write(label(), idlength); + } +}; + +#pragma pack(pop) diff --git a/src/common/types.h b/src/common/types.h index ffa308d..24e3093 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -193,7 +193,7 @@ struct BuildingGoods READ_STRING(b, name); READ(b, n); - for (int i = 0; i < n; i++) + for (uint32_t i = 0; i < n; i++) { Good g; g.load(b); @@ -217,7 +217,7 @@ struct MapMusic auto read_values = [&b](auto &v, auto &n) { - for (int i = 0; i < n; i++) + for (uint32_t i = 0; i < n; i++) v.push_back(b.read_string()); }; @@ -240,7 +240,7 @@ struct OrganizationConfig { READ(b, n_configs); configs.resize(n_configs, std::string(0x20, 0)); - for (int i = 0; i < n_configs; i++) + for (uint32_t i = 0; i < n_configs; i++) READ_N(b, configs[i][0], 0x20); } }; @@ -272,7 +272,7 @@ struct Organizations READ(b, len); uint32_t n = 0; READ(b, n); - for (int i = 0; i < n; i++) + for (uint32_t i = 0; i < n; i++) { Organization s; s.load(b); @@ -303,7 +303,7 @@ struct OrganizationBases { uint32_t n = 0; READ(b, n); - for (int i = 0; i < n; i++) + for (uint32_t i = 0; i < n; i++) { OrganizationBase s; s.load(b); diff --git a/src/db_add_language/db_add_language.cpp b/src/db_add_language/db_add_language.cpp index 6b39bf0..0e4a2e9 100644 --- a/src/db_add_language/db_add_language.cpp +++ b/src/db_add_language/db_add_language.cpp @@ -16,15 +16,15 @@ * along with this program. If not, see . */ -#include "../db_extractor/db.h" - #include +#include #include #include #include #include #include +#include #include #include @@ -284,7 +284,6 @@ void process_lang(polygon4::Storage &s, const path &p, polygon4::String polygon4 } int main(int argc, char *argv[]) -try { if (argc != 3) { @@ -321,13 +320,3 @@ try return 0; } -catch (std::exception &e) -{ - printf("error: %s\n", e.what()); - return 1; -} -catch (...) -{ - printf("error: unknown exception\n"); - return 1; -} diff --git a/src/db_extractor/db_extractor.cpp b/src/db_extractor/db_extractor.cpp index 20a8e82..a872874 100644 --- a/src/db_extractor/db_extractor.cpp +++ b/src/db_extractor/db_extractor.cpp @@ -18,11 +18,13 @@ #include "db.h" -#include - #include #include +#include + +#include + void create_sql(std::string path, const db &db) { std::ofstream ofile(path + ".sql"); @@ -122,7 +124,6 @@ void create_sql(std::string path, const db &db) } int main(int argc, char *argv[]) -try { if (argc != 2) { @@ -135,13 +136,3 @@ try create_sql(p.string(), db); return 0; } -catch (std::exception &e) -{ - printf("error: %s\n", e.what()); - return 1; -} -catch (...) -{ - printf("error: unknown exception\n"); - return 1; -} diff --git a/src/mmm_extractor/mmm_extractor.cpp b/src/mmm_extractor/mmm_extractor.cpp index 10b0d45..65ec776 100644 --- a/src/mmm_extractor/mmm_extractor.cpp +++ b/src/mmm_extractor/mmm_extractor.cpp @@ -25,6 +25,7 @@ #include #include +#include using namespace std; @@ -64,7 +65,6 @@ void process_mmm(const path &fn) } int main(int argc, char *argv[]) -try { if (argc != 2) { @@ -78,7 +78,7 @@ try { auto files = enumerate_files_like(p, ".*\\.mmm", false); for (auto &f : files) - { + { std::cout << "processing: " << f << "\n"; process_mmm(f); } @@ -87,13 +87,3 @@ try throw std::runtime_error("Bad fs object"); return 0; } -catch (std::exception &e) -{ - printf("error: %s\n", e.what()); - return 1; -} -catch (...) -{ - printf("error: unknown exception\n"); - return 1; -} diff --git a/src/mmo_extractor/mmo_extractor.cpp b/src/mmo_extractor/mmo_extractor.cpp index 8a40dfa..45dd15e 100644 --- a/src/mmo_extractor/mmo_extractor.cpp +++ b/src/mmo_extractor/mmo_extractor.cpp @@ -33,7 +33,8 @@ #include #include #include -#include +#include +#include #include #include @@ -229,7 +230,7 @@ void write_mmo(Storage *storage, const mmo_storage &s) // protect against nans object->m_rotate_z[2].z = ASSIGN(object->m_rotate_z[2].z, 1); - detail::MapObject mb; + polygon4::detail::MapObject mb; mb.text_id = object->name2; mb.map = this_map; mb.object = storage->objects[bld_ids[object->name1]]; @@ -268,19 +269,15 @@ void write_mmo(Storage *storage, const mmo_storage &s) } int main(int argc, char *argv[]) -try { - args::ArgumentParser parser("mmo extractor"); - args::HelpFlag help(parser, "help", "Display this help menu", { 'h', "help" }); - args::Flag m2(parser, "m2", "m2 .mmo file", { "m2" }); - args::Flag print_mechanoids(parser, "print_mechanoids", "Print mechanoids", { "print_mechanoids" }); - args::ValueFlag db_path(parser, "db_path", "Database file", {'d', "db"}); - args::Positional file_path(parser, "file or directory", ".mmo file or directory with .mmo files"); - parser.Prog(argv[0]); + cl::opt m2("m2", cl::desc("m2 .mmo file")); + cl::opt print_mechanoids("print_mechanoids", cl::desc("print mechanoids")); + cl::opt db_path("db", cl::desc("database file")); + cl::alias db_pathA("d", cl::aliasopt(db_path)); + cl::opt p(cl::Positional, cl::desc(".mmo file or directory with .mmo files"), cl::value_desc("file or directory"), cl::Required); - parser.ParseCLI(argc, argv); + cl::ParseCommandLineOptions(argc, argv); - const path p = file_path.Get(); gameType = m2 ? GameType::Aim2 : GameType::Aim1; /*{ @@ -320,7 +317,7 @@ try } else { - auto storage = initStorage(db_path.Get()); + auto storage = initStorage(db_path.u8string()); storage->load(); action([&storage](const path &, const auto &m) {write_mmo(storage.get(), m); }); if (inserted_all) @@ -329,13 +326,3 @@ try return 0; } -catch (std::exception &e) -{ - printf("error: %s\n", e.what()); - return 1; -} -catch (...) -{ - printf("error: unknown exception\n"); - return 1; -} diff --git a/src/mmo_extractor/other.h b/src/mmo_extractor/other.h index e770c4e..0fcac33 100644 --- a/src/mmo_extractor/other.h +++ b/src/mmo_extractor/other.h @@ -76,7 +76,7 @@ struct MechGroup uint32_t len = 0; READ(b, len); t.resize(len); - for (int i = 0; i < len; i++) + for (uint32_t i = 0; i < len; i++) READ(b, t[i]); type_data = t; } @@ -93,7 +93,7 @@ struct MechGroup assert(false); } - for (int i = 0; i < number_of_mechanoids; i++) + for (uint32_t i = 0; i < number_of_mechanoids; i++) { std::string t; READ_STRING_N(b, t, 0x20); @@ -119,7 +119,7 @@ struct MechGroups READ(b, n); READ(b, unk0); - for (int s = 0; s < n; s++) + for (uint32_t s = 0; s < n; s++) { MechGroup mg; mg.load(b); @@ -145,7 +145,7 @@ struct MapGoods uint32_t n = 0; READ(b, n); - for (int i = 0; i < n; i++) + for (uint32_t i = 0; i < n; i++) { BuildingGoods bg; bg.load(b); diff --git a/src/mmp_extractor/mmp.cpp b/src/mmp_extractor/mmp.cpp index 8c8d522..3ecba91 100644 --- a/src/mmp_extractor/mmp.cpp +++ b/src/mmp_extractor/mmp.cpp @@ -146,7 +146,7 @@ void mmp::process() textures.erase(0); auto textures_per_color = std::max(1U, textures.size() / 3); auto color_step = 200 / std::max(1U, textures.size()); - for (int i = 0; i < textures.size(); i++) + for (size_t i = 0; i < textures.size(); i++) { int color_id = i / textures_per_color; color c = { 0 }; @@ -185,14 +185,14 @@ void mmp::process() const auto &data = s.d; int y1 = s.desc.min.y / 10; int y2 = s.desc.max.y / 10; - if (y2 > h.length) + if (y2 > (int)h.length) y2 = h.length; for (int y = 0; y1 < y2; y1++, y++) { int x1 = s.desc.min.x / 10; int x2 = s.desc.max.x / 10; auto dx = x2 - x1; - if (x2 > h.width) + if (x2 >(int)h.width) x2 = h.width; for (int x = 0; x1 < x2; x1++, x++) { @@ -232,14 +232,14 @@ void mmp::process() { int y1 = s.desc.min.y / 10; int y2 = s.desc.max.y / 10; - if (y2 > h.length) + if (y2 > (int)h.length) y2 = h.length; for (int y = 0; y1 < y2; y1++, y++) { int x1 = s.desc.min.x / 10; int x2 = s.desc.max.x / 10; auto dx = x2 - x1; - if (x2 > h.width) + if (x2 > (int)h.width) x2 = h.width; for (int x = 0; x1 < x2; x1++, x++) { @@ -319,7 +319,16 @@ void mmp::writeTextureAlphaMaps() { for (auto &t : alpha_maps) { - auto fn = filename + ".texmap." + std::to_string(t.first) + ".bmp"; + int tex_id = 0; + for (auto &[tid, tex] : textures_map) + { + if (tex.g == t.first) + { + tex_id = tid; + break; + } + } + auto fn = filename + ".texmap." + std::to_string(t.first) + "." + std::to_string(tex_id) + ".bmp"; write_mat_bmp(fn, t.second); } } diff --git a/src/mmp_extractor/mmp_extractor.cpp b/src/mmp_extractor/mmp_extractor.cpp index 59da10a..4ba266b 100644 --- a/src/mmp_extractor/mmp_extractor.cpp +++ b/src/mmp_extractor/mmp_extractor.cpp @@ -19,6 +19,7 @@ #include "mmp.h" #include +#include #include #include @@ -29,7 +30,6 @@ using namespace std; int main(int argc, char *argv[]) -try { if (argc < 2 || argc > 3) { @@ -45,7 +45,7 @@ try m.load(p.string()); m.process(); m.writeFileInfo(); - //m.writeTexturesList(); + m.writeTexturesList(); m.writeHeightMap(); //m.writeHeightMapSegmented(); m.writeTextureMap(); @@ -73,13 +73,3 @@ try return 0; } -catch (std::exception &e) -{ - printf("error: %s\n", e.what()); - return 1; -} -catch (...) -{ - printf("error: unknown exception\n"); - return 1; -} diff --git a/src/mod_converter/fbx.cpp b/src/mod_converter/fbx.cpp index 6d6ef39..d84d5e1 100644 --- a/src/mod_converter/fbx.cpp +++ b/src/mod_converter/fbx.cpp @@ -51,7 +51,7 @@ void DestroySdkObjects(FbxManager* pManager, bool pExitStatus) bool SaveScene(FbxManager* pManager, FbxDocument* pScene, const char* pFilename, bool blender = false) { - int lMajor, lMinor, lRevision; + //int lMajor, lMinor, lRevision; bool lStatus = true; // Create an exporter. diff --git a/src/mod_converter/mod_converter.cpp b/src/mod_converter/mod_converter.cpp index 2569f64..8964c16 100644 --- a/src/mod_converter/mod_converter.cpp +++ b/src/mod_converter/mod_converter.cpp @@ -21,7 +21,8 @@ #include "model.h" #include -#include +#include +#include #include #include @@ -36,9 +37,7 @@ using namespace std; // options bool silent = false; bool printMaxPolygonBlock = false; -path p; - -bool parse_cmd(int argc, char *argv[]); +cl::opt p(cl::Positional, cl::desc("MOD_ file or directory with MOD_ files"), cl::value_desc("file or directory"), cl::Required); void convert_model(const path &fn) { @@ -60,23 +59,17 @@ void convert_model(const path &fn) } int main(int argc, char *argv[]) -try { - args::ArgumentParser parser("mmo extractor"); - args::HelpFlag help(parser, "help", "Display this help menu", { 'h', "help" }); - args::Flag af(parser, "a", "All formats", { 'a' }); - args::Flag mr(parser, "mr", "AIM Racing MOD file", { "mr" }); - args::Positional file_path(parser, "file or directory", "MOD_ file or directory with MOD_ files"); - parser.Prog(argv[0]); + cl::opt af("a", cl::desc("All formats")); + cl::opt mr("mr", cl::desc("AIM Racing MOD file")); - parser.ParseCLI(argc, argv); + cl::ParseCommandLineOptions(argc, argv); if (mr) gameType = GameType::AimR; if (af) all_formats = true; - p = file_path.Get(); if (fs::is_regular_file(p)) convert_model(p); else if (fs::is_directory(p)) @@ -101,61 +94,3 @@ try throw std::runtime_error("Bad fs object"); return 0; } -/*catch (std::runtime_error &e) -{ - if (silent) - return 1; - string error; - error += p.string(); - error += "\n"; - error += "fatal error: "; - error += e.what(); - error += "\n"; - ofstream ofile(p.string() + ".error.txt"); - ofile << error; - return 1; -}*/ -catch (std::exception &e) -{ - if (silent) - return 1; - printf("%s\n", p.string().c_str()); - printf("error: %s\n", e.what()); - return 1; -} -catch (...) -{ - if (silent) - return 1; - printf("%s\n", p.string().c_str()); - printf("error: unknown exception\n"); - return 1; -} - -bool parse_cmd(int argc, char *argv[]) -{ - for (int i = 1; i < argc; i++) - { - auto arg = argv[i]; - if (*arg != '-') - { - if (i != argc - 1) - return false; - p = arg; - continue; - } - switch (arg[1]) - { - case 'a': - all_formats = true; - break; - case 's': - silent = true; - break; - case 'm': - printMaxPolygonBlock = true; - break; - } - } - return true; -} diff --git a/src/mod_reader/mod_reader.cpp b/src/mod_reader/mod_reader.cpp index 089a8ed..5036231 100644 --- a/src/mod_reader/mod_reader.cpp +++ b/src/mod_reader/mod_reader.cpp @@ -16,6 +16,12 @@ * along with this program. If not, see . */ +#include +#include + +#include +#include + #include #include #include @@ -24,11 +30,6 @@ #include #include -#include -#include - -#include - using namespace std; // options @@ -54,7 +55,6 @@ void convert_model(const path &fn) } int main(int argc, char *argv[]) -try { if (argc < 2 || !parse_cmd(argc, argv)) { @@ -67,9 +67,9 @@ try { auto files = enumerate_files(p, false); for (auto &f : files) - { - if (f.has_extension()) - continue; + { + if (f.has_extension()) + continue; std::cout << "processing: " << f << "\n"; convert_model(f); } @@ -78,36 +78,6 @@ try throw std::runtime_error("Bad fs object"); return 0; } -catch (std::runtime_error &e) -{ - if (silent) - return 1; - string error; - error += p.string(); - error += "\n"; - error += "fatal error: "; - error += e.what(); - error += "\n"; - ofstream ofile(p.string() + ".error.txt"); - ofile << error; - return 1; -} -catch (std::exception &e) -{ - if (silent) - return 1; - printf("%s\n", p.string().c_str()); - printf("error: %s\n", e.what()); - return 1; -} -catch (...) -{ - if (silent) - return 1; - printf("%s\n", p.string().c_str()); - printf("error: unknown exception\n"); - return 1; -} bool parse_cmd(int argc, char *argv[]) { diff --git a/src/mpj_loader/mpj_loader.cpp b/src/mpj_loader/mpj_loader.cpp index b3ac1a9..bfa72f7 100644 --- a/src/mpj_loader/mpj_loader.cpp +++ b/src/mpj_loader/mpj_loader.cpp @@ -16,18 +16,19 @@ * along with this program. If not, see . */ +#include "mpj.h" + +#include + #include #include #include #include #include -#include "mpj.h" - using namespace std; int main(int argc, char *argv[]) -try { if (argc != 2) { @@ -38,13 +39,3 @@ try m.load(argv[1]); return 0; } -catch (std::exception &e) -{ - printf("error: %s\n", e.what()); - return 1; -} -catch (...) -{ - printf("error: unknown exception\n"); - return 1; -} diff --git a/src/save_loader/save.h b/src/save_loader/save.h index 7372e85..0d108a8 100644 --- a/src/save_loader/save.h +++ b/src/save_loader/save.h @@ -23,6 +23,8 @@ #include #include +#include + // possible save operations struct changes diff --git a/src/save_loader/save_loader.cpp b/src/save_loader/save_loader.cpp index 92bb587..80da001 100644 --- a/src/save_loader/save_loader.cpp +++ b/src/save_loader/save_loader.cpp @@ -16,14 +16,15 @@ * along with this program. If not, see . */ +#include "save.h" + +#include +#include + #include #include -#include "save.h" -#include - int main(int argc, char *argv[]) -try { if (argc != 2) { @@ -53,7 +54,7 @@ try { auto files = enumerate_files_like(p, ".*\\.sav", false); for (auto &f : files) - { + { std::cout << "processing: " << f << "\n"; func(f); } @@ -63,15 +64,3 @@ try return 0; } -catch (std::exception &e) -{ - printf("%s\n", argv[1]); - printf("error: %s\n", e.what()); - return 1; -} -catch (...) -{ - printf("%s\n", argv[1]); - printf("error: unknown exception\n"); - return 1; -} diff --git a/src/script2txt/CMakeLists.txt b/src/script2txt/CMakeLists.txt deleted file mode 100644 index 90216a6..0000000 --- a/src/script2txt/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -# -# Polygon-4 Data generator -# - -set(BSRC ${CMAKE_CURRENT_BINARY_DIR}) - -set(_CPP ".*\\.cpp") -set(CPP "${_CPP}$") - -set(_H "(.*\\.h|.*\\.hpp)") -set(H "${_H}$") - -set(H_CPP "(${H}|${CPP})") - -source_group("Generated" "${BSRC}/${H_CPP}") - -BISON_TARGET(grammar - "${CMAKE_CURRENT_SOURCE_DIR}/grammar.yy" - "${CMAKE_CURRENT_BINARY_DIR}/grammar.cpp" -) -FLEX_TARGET(lexer - "${CMAKE_CURRENT_SOURCE_DIR}/lexer.ll" - "${CMAKE_CURRENT_BINARY_DIR}/lexer.cpp" - COMPILE_FLAGS --header-file=${CMAKE_CURRENT_BINARY_DIR}/lexer.h -) -ADD_FLEX_BISON_DEPENDENCY(lexer grammar) - -include_directories(${CMAKE_CURRENT_BINARY_DIR}) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - -set(parser_src - ${BISON_grammar_OUTPUTS} - ${FLEX_lexer_OUTPUTS} - ${CMAKE_CURRENT_BINARY_DIR}/lexer.h -) -set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/lexer.h PROPERTIES GENERATED TRUE) - -file(GLOB script2txt_src "*.cpp" "*.h") - -set(script2txt_src ${script2txt_src} - grammar.yy - lexer.ll - ${parser_src} - ${SCHEMA_FILE} -) - -add_executable (script2txt ${script2txt_src} ${script2txt_inc}) -target_link_libraries (script2txt common pvt.lzwdgc.polygon4.data_manager.schema) diff --git a/src/script2txt/ParserDriver.cpp b/src/script2txt/ParserDriver.cpp deleted file mode 100644 index 6436447..0000000 --- a/src/script2txt/ParserDriver.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Polygon-4 script2txt - * Copyright (C) 2015-2016 lzwdgc - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include "ParserDriver.h" - -#include -#include - -// Prevent using because of bug in flex. -#define YY_NO_UNISTD_H 1 -#define YY_DECL 1 -#include -extern yy::parser::symbol_type yylex(yyscan_t yyscanner, yy::location &loc); - -ParserDriver::ParserDriver() -{ - debug = false; -} - -yy::parser::symbol_type ParserDriver::lex() -{ - return yylex(scanner, location); -} - -int ParserDriver::parse(const std::string &s) -{ - yylex_init(&scanner); - yy_scan_string(s.c_str(), scanner); - - yy::parser parser(*this); - parser.set_debug_level(debug); - int res = parser.parse(); - - yylex_destroy(scanner); - - return res; -} - -void ParserDriver::error(const yy::location &l, const std::string &m) -{ - std::cerr << l << " " << m << std::endl; -} - -void ParserDriver::error(const std::string& m) -{ - std::cerr << m << std::endl; -} diff --git a/src/script2txt/ParserDriver.h b/src/script2txt/ParserDriver.h deleted file mode 100644 index 48b7b1f..0000000 --- a/src/script2txt/ParserDriver.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Polygon-4 script2txt - * Copyright (C) 2015-2016 lzwdgc - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include -#include - -#include - -class ParserDriver -{ -public: - ParserDriver(); - - yy::parser::symbol_type lex(); - int parse(const std::string &s); - - void error(const yy::location &l, const std::string &m); - void error(const std::string &m); - - void setContext(Context &&ctx) { context = std::move(ctx); } - const Context &getContext() const { return context; } - - // lex & parse -private: - void *scanner; - yy::location location; - bool debug; - - // data -private: - Context context; - - // other -public: - std::set functions; -}; diff --git a/src/script2txt/script.h b/src/script2txt/script.h index 7570310..4195437 100644 --- a/src/script2txt/script.h +++ b/src/script2txt/script.h @@ -18,11 +18,11 @@ #pragma once -#include - #include #include +#include + template inline bool replace_all(T &str, const T &from, const T &to) { diff --git a/src/script2txt/script2txt.cpp b/src/script2txt/script2txt.cpp index 29bef15..82092e9 100644 --- a/src/script2txt/script2txt.cpp +++ b/src/script2txt/script2txt.cpp @@ -16,19 +16,21 @@ * along with this program. If not, see . */ +#include "script.h" + +#include + +#include +#include + #include #include #include -#include "ParserDriver.h" -#include "script.h" -#include - using std::cout; using std::string; int main(int argc, char *argv[]) -try { if (argc != 2) { @@ -44,7 +46,7 @@ try s.load(b); auto str = s.get_text(); - ParserDriver driver; + Script2txtParserDriver driver; if (driver.parse(str)) { throw std::runtime_error("error during parsing input file"); @@ -83,7 +85,7 @@ try auto files2 = enumerate_files_like(p, ".*\\.QST", false); files.insert(files2.begin(), files2.end()); for (auto &f : files) - { + { std::cout << "processing: " << f << "\n"; func(f.string()); } @@ -93,13 +95,3 @@ try return 0; } -catch (std::exception &e) -{ - printf("error: %s\n", e.what()); - return 1; -} -catch (...) -{ - printf("error: unknown exception\n"); - return 1; -} diff --git a/src/script2txt/lexer.ll b/src/script2txt/script2txt.ll similarity index 88% rename from src/script2txt/lexer.ll rename to src/script2txt/script2txt.ll index 44a0be4..c7fad95 100644 --- a/src/script2txt/lexer.ll +++ b/src/script2txt/script2txt.ll @@ -17,20 +17,7 @@ * along with this program. If not, see . */ -#pragma warning(disable: 4005) -#include - -#include "grammar.hpp" - -#define YY_USER_ACTION loc.columns(yyleng); - -#define PUSH_STATE(x) BEGIN(x) -#define POP_STATE() BEGIN(0) - -#define YY_DECL yy::parser::symbol_type yylex(yyscan_t yyscanner, yy::location &loc) - -#define MAKE(x) yy::parser::make_ ## x(loc) -#define MAKE_VALUE(x, v) yy::parser::make_ ## x((v), loc) +#include %} %option nounistd @@ -41,17 +28,14 @@ %option reentrant %option noyywrap - DIGIT [0-9] DIGITS {DIGIT}{DIGIT}* INTEGER {DIGITS}[Ff]? STRING [[:alpha:]_-][[:alnum:]_-]* - %x user_string - %% %{ diff --git a/src/script2txt/grammar.yy b/src/script2txt/script2txt.yy similarity index 93% rename from src/script2txt/grammar.yy rename to src/script2txt/script2txt.yy index 079c86d..82293ee 100644 --- a/src/script2txt/grammar.yy +++ b/src/script2txt/script2txt.yy @@ -17,45 +17,48 @@ * along with this program. If not, see . */ -#include -#include -#include - -#include "ParserDriver.h" - -#define yylex(p) p.lex() +#include %} //////////////////////////////////////// // general settings %require "3.0" -%debug +//%debug %start file %locations %verbose -%no-lines +//%no-lines %error-verbose //////////////////////////////////////// // c++ skeleton and options %skeleton "lalr1.cc" - %define api.value.type variant %define api.token.constructor // C++ style of handling variants %define parse.assert // check C++ variant types +%code provides { #include } +%parse-param { MY_PARSER_DRIVER &driver } // param to yy::parser() constructor (the parsing context) %code requires // forward decl of C++ driver (our parser) in HPP { #include -class ParserDriver; -} - -// param to yy::parser() constructor -// the parsing context -%param { ParserDriver &driver } +#include +} + +%code provides +{ +struct MY_PARSER_DRIVER : MY_PARSER +{ + void setContext(Context &&ctx) { context = std::move(ctx); } + const Context &getContext() const { return context; } + + Context context; + std::set functions; +}; +} //////////////////////////////////////// @@ -327,8 +330,3 @@ integer: INTEGER ; %% - -void yy::parser::error(const location_type& l, const std::string& m) -{ - driver.error(l, m); -} diff --git a/src/tm_converter/tm_converter.cpp b/src/tm_converter/tm_converter.cpp index 36e2b00..ab1d179 100644 --- a/src/tm_converter/tm_converter.cpp +++ b/src/tm_converter/tm_converter.cpp @@ -16,6 +16,13 @@ * along with this program. If not, see . */ +#include +#include +#include + +#include +#include + #include #include #include @@ -24,12 +31,6 @@ #include #include -#include -#include -#include - -#include - using namespace std; void convert_simple(buffer &dst, const buffer &src, int width, int height) @@ -80,7 +81,6 @@ void convert(const path &fn) } int main(int argc, char *argv[]) -try { if (argc != 2) { @@ -103,15 +103,3 @@ try throw std::runtime_error("Bad fs object"); return 0; } -catch (std::exception &e) -{ - printf("%s\n", argv[1]); - printf("error: %s\n", e.what()); - return 1; -} -catch (...) -{ - printf("%s\n", argv[1]); - printf("error: unknown exception\n"); - return 1; -}