From caa4c876623ae3637bb9adcb66e7ed7e3544c657 Mon Sep 17 00:00:00 2001 From: hppeng Date: Sat, 1 Apr 2023 22:09:00 -0700 Subject: [PATCH] Start working on powders translation taking a pause to clean up load code --- js/c++/Makefile | 10 ++++++---- js/c++/definitions.cpp | 1 + js/c++/definitions.h | 7 +++++++ js/c++/powders.cpp | 37 +++++++++++++++++++++++++++++++++++++ js/c++/powders.h | 18 ++++++++++++++++++ js/c++/utils/base64.h | 2 +- js/c++/utils/bitvector.cpp | 3 +++ js/c++/utils/bitvector.h | 4 ++-- 8 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 js/c++/definitions.cpp create mode 100644 js/c++/definitions.h diff --git a/js/c++/Makefile b/js/c++/Makefile index 0997374..bf24b08 100644 --- a/js/c++/Makefile +++ b/js/c++/Makefile @@ -3,13 +3,15 @@ CXXFLAGS=-sENVIRONMENT=web -sSINGLE_FILE -sMODULARIZE -sWASM_ASYNC_COMPILATION=0 all: utils.js powders.js -%.js: - $(CXX) $(CXXFLAGS) -sEXPORT_NAME=create_$* -o $@.out $^ +%.js: %.js.out cat $@.out $@.in > ../$@ -powders.js: powders.cpp +%.js.out: + $(CXX) $(CXXFLAGS) -sEXPORT_NAME=create_$* -o $@ $^ -utils.js: utils.cpp utils/math_utils.cpp utils/base64.cpp utils/bitvector.cpp +powders.js.out: powders.cpp definitions.cpp + +utils.js.out: utils.cpp utils/math_utils.cpp utils/base64.cpp utils/bitvector.cpp .PHONY: clean clean: diff --git a/js/c++/definitions.cpp b/js/c++/definitions.cpp new file mode 100644 index 0000000..af6c37b --- /dev/null +++ b/js/c++/definitions.cpp @@ -0,0 +1 @@ +#include "definitions.h" diff --git a/js/c++/definitions.h b/js/c++/definitions.h new file mode 100644 index 0000000..bf29ccf --- /dev/null +++ b/js/c++/definitions.h @@ -0,0 +1,7 @@ +#pragma once + +#include +#include + +static const std::vector skp_order { "str", "dex", "int", "def", "agi" }; +static const std::vector skp_elements {"e","t","w","f","a"}; diff --git a/js/c++/powders.cpp b/js/c++/powders.cpp index a88f9fc..a6e42c7 100644 --- a/js/c++/powders.cpp +++ b/js/c++/powders.cpp @@ -4,7 +4,44 @@ using namespace emscripten; #endif #include "powders.h" +#include "definitions.h" +#include + +const std::map powderIDs = []{ + std::map m; + int powder_id = 0; + for (const auto& x : skp_elements) { + for (int i = 0; i < 6; ++i) { + m[x + std::to_string(i)] = i; + m[(char)toupper(x[0]) + std::to_string(i)] = i; + powder_id++; + } + } + return m; +}(); + +const std::map powderNames = []{ + std::map m; + for (const auto& kv : powderIDs) { + m[kv.second] = kv.first; + } + return m; +}(); + +Powder::Powder(int min, int max, int conv, int defPlus, int defMinus) : + min(min), max(max), convert(conv), defPlus(defPlus), defMinus(defMinus) {} + +const std::vector powderStats = []{ + auto _p = [](int a, int b, int c, int d, int e){ return Powder(a,b,c,d,e); }; + return std::vector { + _p(3,6,17,2,1), _p(5,8,21,4,2), _p(6,10,25,8,3), _p(7,10,31,14,5), _p(9,11,38,22,9), _p(11,13,46,30,13), + _p(1,8,9,3,1), _p(1,12,11,5,1), _p(2,15,13,9,2), _p(3,15,17,14,4), _p(4,17,22,20,7), _p(5,20,28,28,10), + _p(3,4,13,3,1), _p(4,6,15,6,1), _p(5,8,17,11,2), _p(6,8,21,18,4), _p(7,10,26,28,7), _p(9,11,32,40,10), + _p(2,5,14,3,1), _p(4,8,16,5,2), _p(5,9,19,9,3), _p(6,9,24,16,5), _p(8,10,30,25,9), _p(10,12,37,36,13), + _p(2,6,11,3,1), _p(3,10,14,6,2), _p(4,11,17,10,3), _p(5,11,22,16,5), _p(7,12,28,24,9), _p(8,14,35,34,13) + }; +}(); #ifdef __EMSCRIPTEN__ EMSCRIPTEN_BINDINGS(powders) { diff --git a/js/c++/powders.h b/js/c++/powders.h index 6f70f09..5f6b7a7 100644 --- a/js/c++/powders.h +++ b/js/c++/powders.h @@ -1 +1,19 @@ #pragma once +#include +#include +#include + +extern const std::map powderIDs; +extern const std::map powderNames; + +struct Powder { + int min; + int max; + int convert; + int defPlus; + int defMinus; + + Powder(int min, int max, int conv, int defPlus, int defMinus); +}; + +extern const std::vector powderStats; diff --git a/js/c++/utils/base64.h b/js/c++/utils/base64.h index a8d472e..eafa5ec 100644 --- a/js/c++/utils/base64.h +++ b/js/c++/utils/base64.h @@ -14,7 +14,7 @@ namespace Base64 { // v v v v v v v v v "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+-"; - const std::map digitsMap = []{ + static const std::map digitsMap = []{ std::map m; for (size_t i = 0; i < digits.length(); ++i) { m[digits[i]] = i; diff --git a/js/c++/utils/bitvector.cpp b/js/c++/utils/bitvector.cpp index fc46029..50e4f41 100644 --- a/js/c++/utils/bitvector.cpp +++ b/js/c++/utils/bitvector.cpp @@ -4,6 +4,9 @@ #include #include +BitVector::BitVector() {}; +BitVector::BitVector(const BitVector& other) : data(other.data), length(other.length) {}; + BitVector::BitVector(const std::string b64_data) { length = b64_data.length() * 6; data.reserve(length/bitvec_data_s + 1); diff --git a/js/c++/utils/bitvector.h b/js/c++/utils/bitvector.h index cb74b43..9fda58a 100644 --- a/js/c++/utils/bitvector.h +++ b/js/c++/utils/bitvector.h @@ -23,8 +23,8 @@ public: * * The structure of the Uint32Array should be [[last, ..., first], ..., [last, ..., first], [empty space, last, ..., first]] */ - BitVector() {}; - BitVector(const BitVector& other) : data(other.data), length(other.length) {}; + BitVector(); + BitVector(const BitVector& other); BitVector(const std::string b64_data); BitVector(bitvec_data_t num, size_t length);