aboutsummaryrefslogtreecommitdiff
path: root/src/static/Source.cpp
diff options
context:
space:
mode:
authorUnavailableDev <ggwildplay@gmail.com>2023-04-04 14:38:48 +0200
committerUnavailableDev <ggwildplay@gmail.com>2023-04-04 14:38:48 +0200
commit2ff7020ed6327a49abd3c57491c1286c34a62d40 (patch)
treea20c3af2bcd53c0cadacb141def6d6c61743acd6 /src/static/Source.cpp
parentabfb6d3667e0c1955f09636ed72e48ed17129c84 (diff)
dynamic tilemap integration
(without pallets)
Diffstat (limited to 'src/static/Source.cpp')
-rw-r--r--src/static/Source.cpp42
1 files changed, 42 insertions, 0 deletions
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 <iostream>
+#include <fstream>
+#include <sstream>
+#include <vector>
+
+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<std::vector<int>> array; /* vector of vector<int> */
+
+ while (std::getline(f, line)) { /* read each line */
+ std::vector<int> 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<int> 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;
+}