From 2ff7020ed6327a49abd3c57491c1286c34a62d40 Mon Sep 17 00:00:00 2001 From: UnavailableDev Date: Tue, 4 Apr 2023 14:38:48 +0200 Subject: dynamic tilemap integration (without pallets) --- src/static/Source.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/static/Source.cpp (limited to 'src/static/Source.cpp') diff --git a/src/static/Source.cpp b/src/static/Source.cpp new file mode 100644 index 0000000..0bba7c6 --- /dev/null +++ b/src/static/Source.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include + +int main(int argc, char** argv) { + + std::ifstream f; + f.open("out.csv"); /* open file with filename as argument */ + if (!f.is_open()) { /* validate file open for reading */ + std::cerr << "error: file open failed '" << argv[1] << "'.\n"; + return 0; + } + + + std::string line, val; /* string for line & value */ + std::vector> array; /* vector of vector */ + + while (std::getline(f, line)) { /* read each line */ + std::vector v; /* row vector v */ + std::stringstream s(line); /* stringstream line */ + while (getline(s, val, ',')) /* get each value (',' delimited) */ + v.push_back(std::stoi(val)); /* add to row vector */ + array.push_back(v); /* add row vector to array */ + } + + std::vector flat_array; /* create 1D vector */ + for (auto& row : array) { /* iterate over rows */ + for (auto& val : row) /* iterate over vals */ + flat_array.push_back(val); /* add to 1D vector */ + } + + int* array1d = flat_array.data(); /* get pointer to data */ + int size = flat_array.size(); /* get size of 1D array */ + + std::ofstream out_file("out.bin", std::ios::binary); /* create binary file */ + out_file.write((char*)&size, sizeof(size)); /* write size of 1D array to file */ + out_file.write((char*)array1d, size * sizeof(int)); /* write 1D array to file */ + out_file.close(); /* close file */ + + return 0; +} -- cgit v1.2.3