-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMap.cpp
More file actions
executable file
·49 lines (36 loc) · 1.42 KB
/
Map.cpp
File metadata and controls
executable file
·49 lines (36 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// Created by Иван Ильин on 15.03.2021.
//
#include "Map.h"
#include <iostream>
#include <fstream>
void Map::addCube(const Vec3D& pos, Cube::Type t) {
std::string cubeName = "cube_X_" + std::to_string((int)pos.x()) + "_Y_" + std::to_string((int)pos.y()) + "_Z_" + std::to_string((int)pos.z());
world->addBody(std::make_shared<Cube>(pos, t));
cubes.insert({cubeName, {t, pos}});
}
Cube::Type Map::removeCube(const Vec3D& pos) {
std::string cubeName = "cube_X_" + std::to_string((int)pos.x()) + "_Y_" + std::to_string((int)pos.y()) + "_Z_" + std::to_string((int)pos.z());
world->removeBody(ObjectNameTag(cubeName));
if(cubes.count(cubeName)) {
Cube::Type t = cubes.at(cubeName).first;
cubes.erase(cubeName);
return t;
}
return Cube::none;
}
void Map::saveMap(const std::string& mapName) {
std::ofstream outfile (mapName, std::fstream::trunc);
for(auto& cube : cubes)
outfile << cube.second.first << "\t" << (int)cube.second.second.x() << "\t" << (int)cube.second.second.y() << "\t" << (int)cube.second.second.z() << std::endl;
outfile.close();
}
void Map::loadMap(const std::string &mapName) {
std::ifstream infile (mapName, std::fstream::out);
while (!infile.eof()) {
int t, posX, posY, posZ;
infile >> t >> posX >> posY >> posZ;
addCube(Vec3D(posX, posY, posZ), static_cast<Cube::Type>(t));
}
infile.close();
}