MCPcopy Create free account
hub / github.com/atraczyk/2d-engine / load

Method load

engine/src/tile.cpp:71–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71void TileMap::load(const char *filename, TileAtlas *ptexatlas,
72 Camera *pcamera) {
73 has_c_Map = false;
74 atlas = ptexatlas;
75
76 imageLayer.clear();
77 collisionLayer.clear();
78 animatedTiles.clear();
79 t_mapSize = Point(0, 0);
80 t_cmapSize = Point(0, 0);
81
82 string line;
83 ifstream file(resolveResourcePath(filename));
84 int index, col = 0, row = 0;
85 bool done = false;
86
87 if (file.is_open()) {
88 getline(file, line);
89 if (line.compare(0, 3, "\xEF\xBB\xBF") == 0)
90 line.erase(0, 3);
91 istringstream ssf(line);
92 ssf >> has_c_Map >> position.x >> position.y >> w_tileSize.x >>
93 w_tileSize.y >> w_depth;
94
95 while (!done) {
96 getline(file, line);
97 col = 0;
98 imageLayer.push_back(vector<ITile>());
99 istringstream ss(line);
100 while (ss >> index) {
101 if (index == -2) {
102 done = true;
103 continue;
104 }
105 bool animated = isAnimatedTile(index) ? true : false;
106 if (animated)
107 animatedTiles.push_back(
108 AnimatedTile(Point(row, col), tileAnimations[index - 240]));
109 imageLayer.back().push_back(ITile(index, animated ? index : 0, NULL));
110 col++;
111 }
112 row++;
113 }
114 if (!imageLayer.empty()) {
115 t_mapSize = Point(static_cast<int>(imageLayer.size()),
116 static_cast<int>(imageLayer[0].size()));
117 } else {
118 t_mapSize = Point(0, 0);
119 }
120
121 if (has_c_Map) {
122 done = false;
123 while (getline(file, line) && !done) {
124 collisionLayer.push_back(vector<CTile>());
125 istringstream ss(line);
126 while (ss >> index) {
127 if (index == -2) {
128 done = true;

Callers 2

loadLevelMethod · 0.45
G_initializeGameFunction · 0.45

Calls 6

PointClass · 0.85
resolveResourcePathFunction · 0.85
isAnimatedTileFunction · 0.85
AnimatedTileClass · 0.85
ITileClass · 0.85
CTileClass · 0.85

Tested by

no test coverage detected