@@ -19,6 +19,13 @@ MapTest::MapTest() {
1919 continue ;
2020 _mapSelections.push_back (levelName);
2121 }
22+
23+ _selectedLevelName = _mapSelections.front ();
24+ onLevelChanged (_selectedLevelName);
25+ if (!_selectedLevelAltName.empty ()) {
26+ _selectedLevelAltName = _mapAltSelections.front ();
27+ loadTile (_selectedLevelAltName);
28+ }
2229}
2330
2431void MapTest::onLevelChanged (const std::string &levelName) {
@@ -94,7 +101,7 @@ void MapTest::processEvent(const SDL_Event &event) {
94101 Abyss::AbyssEngine::getInstance ().getMouseState ().getPosition (mx, my);
95102 _mousePressedPosition.x = mx;
96103 _mousePressedPosition.y = my;
97- _startCameraPosition = _cameraPosition ;
104+ _mapEngine-> getCameraPosition ( _startCameraPosition. x , _startCameraPosition. y ) ;
98105 SDL_CaptureMouse (SDL_TRUE);
99106 break ;
100107 }
@@ -113,8 +120,8 @@ void MapTest::processEvent(const SDL_Event &event) {
113120 int mx;
114121 int my;
115122 Abyss::AbyssEngine::getInstance ().getMouseState ().getPosition (mx, my);
116- _cameraPosition. x = _startCameraPosition.x + (_mousePressedPosition.x - mx);
117- _cameraPosition. y = _startCameraPosition.y + (_mousePressedPosition.y - my);
123+ _mapEngine-> setCameraPosition ( _startCameraPosition.x + (_mousePressedPosition.x - mx),
124+ _startCameraPosition.y + (_mousePressedPosition.y - my) );
118125 }
119126 break ;
120127 }
@@ -131,7 +138,6 @@ void MapTest::loadTile(const std::string &altName) {
131138 const auto &levelType = getLevelType (levelTypeId);
132139 const auto &palette = Common::PaletteManager::getInstance ().getPalette (" Act" + std::to_string (act));
133140
134- _dt1s.clear ();
135141 std::vector<std::string> dt1sToLoad{};
136142
137143 for (int i = 1 ; i <= 31 ; ++i) {
@@ -141,15 +147,14 @@ void MapTest::loadTile(const std::string &altName) {
141147 if (dt1 != " None" && dt1 != " Expansion" && dt1 != " 0" && std::ranges::find (dt1sToLoad, dt1) == dt1sToLoad.end ()) {
142148 auto filePath = " /data/global/tiles/" + dt1;
143149 std::ranges::transform (filePath, filePath.begin (), [](const auto c) { return std::tolower (c); });
144- _dt1s.emplace_back (" /data/global/tiles/" + dt1, palette);
145150 dt1sToLoad.push_back (" /data/global/tiles/" + dt1);
146151 }
147152 }
148153
149- _ds1 = std::make_unique< Abyss::DataTypes::DS1> (" /data/global/tiles/" + altName);
154+ Abyss::DataTypes::DS1 ds1 (" /data/global/tiles/" + altName);
150155
151156 // Add all the DS1 files to the DT1s
152- for (auto &file : _ds1-> files ) {
157+ for (auto &file : ds1. files ) {
153158 std::ranges::replace (file, ' \\ ' , ' /' );
154159 if (file.starts_with (" /d2/" )) // Because why not?
155160 file = file.substr (3 );
@@ -161,99 +166,43 @@ void MapTest::loadTile(const std::string &altName) {
161166 if (file.starts_with (" /d2/" ))
162167 file = file.substr (3 );
163168
164- _dt1s.emplace_back (file, palette);
165169 dt1sToLoad.push_back (file);
166170 }
167171 }
168172
169- _ds1->bindTileReferences (_dt1s);
173+ const auto dsSubIndex = std::ranges::find (_mapAltSelections, altName) - _mapAltSelections.begin ();
174+ // Load all dt1s into a vector
175+ std::vector<Abyss::DataTypes::DT1> dt1s{};
176+ dt1s.reserve (dt1sToLoad.size ());
177+ for (const auto &dt1 : dt1sToLoad)
178+ dt1s.emplace_back (dt1, palette);
179+
180+ const auto mapWidth = ds1.width ;
181+ const auto mapHeight = ds1.height ;
182+
183+ _mapEngine = std::make_unique<Abyss::MapEngine::MapEngine>(mapWidth, mapHeight, std::move (dt1s), std::vector{std::move (ds1)});
184+ _mapEngine->stampDs1 (0 , 0 , 0 );
170185
171- // // Center the map
172- const auto mapCenterX = _ds1-> width / 2 ;
173- const auto mapCenterY = _ds1-> height / 2 ;
174- //
175- // // Convert center to ortho
186+ // Center the map
187+ const auto mapCenterX = mapWidth / 2 ;
188+ const auto mapCenterY = mapHeight / 2 ;
189+
190+ // Convert center to ortho
176191 const auto orthoCenterX = (mapCenterX - mapCenterY) * 80 ;
177192 const auto orthoCenterY = (mapCenterX + mapCenterY) * 40 ;
178193
179194 // Adjust camera position
180- _cameraPosition.x = orthoCenterX - 320 ;
181- _cameraPosition.y = orthoCenterY - 260 ;
182-
195+ _mapEngine->setCameraPosition (orthoCenterX, orthoCenterY);
183196}
184197
185198void MapTest::render () {
186- const auto &renderer = Abyss::AbyssEngine::getInstance ().getRenderer ();
187- SDL_SetRenderDrawColor (renderer, 0 , 0 , 0 , 255 );
188- SDL_RenderClear (renderer);
189-
190- if (_ds1) {
191- for (int tileY = 0 ; tileY < _ds1->height ; ++tileY) {
192- for (int tileX = 0 ; tileX < _ds1->width ; ++tileX) {
193- const auto posX = (tileX - tileY) * 80 ;
194- const auto posY = (tileX + tileY) * 40 ;
195-
196- // Draw lower walls
197- for (const auto &layer : _ds1->layers .wall ) {
198- if (const auto &tile = layer[tileX + tileY * _ds1->width ];
199- tile.dt1Ref && tile.type >= Abyss::DataTypes::TileType::LowerWallsEquivalentToLeftWall)
200- tile.dt1Ref ->drawTile (posX - _cameraPosition.x , posY - _cameraPosition.y , tile.dt1Index );
201- }
199+ SDL_SetRenderDrawColor (Abyss::AbyssEngine::getInstance ().getRenderer (), 0 , 0 , 0 , 255 );
200+ SDL_RenderClear (Abyss::AbyssEngine::getInstance ().getRenderer ());
202201
203- // Draw floors
204- for (const auto &layer : _ds1->layers .floor ) {
205- if (const auto &tile = layer[tileX + tileY * _ds1->width ]; tile.dt1Ref )
206- tile.dt1Ref ->drawTile (posX - _cameraPosition.x , posY - _cameraPosition.y , tile.dt1Index );
207- }
208- // Draw shadows
209- for (const auto &layer : _ds1->layers .shadow ) {
210- if (const auto &tile = layer[tileX + tileY * _ds1->width ]; tile.dt1Ref )
211- tile.dt1Ref ->drawTile (posX - _cameraPosition.x , posY - _cameraPosition.y , tile.dt1Index );
212- }
213- }
214- }
215-
216- for (int tileY = 0 ; tileY < _ds1->height ; ++tileY) {
217- for (int tileX = 0 ; tileX < _ds1->width ; ++tileX) {
218- const auto posX = (tileX - tileY) * 80 ;
219- const auto posY = (tileX + tileY) * 40 ;
220-
221- // Draw upper
222- for (const auto &layer : _ds1->layers .wall ) {
223- if (const auto &tile = layer[tileX + tileY * _ds1->width ];
224- tile.dt1Ref && ((tile.type >= Abyss::DataTypes::TileType::LeftWall && tile.type <=
225- Abyss::DataTypes::TileType::RightWallWithDoor) || (
226- tile.type >= Abyss::DataTypes::TileType::PillarsColumnsAndStandaloneObjects && tile.type <=
227- Abyss::DataTypes::TileType::Tree))) {
228- tile.dt1Ref ->drawTile (posX - _cameraPosition.x , posY - _cameraPosition.y + 96 , tile.dt1Index );
229-
230- // Super special condition. This was fun to figure out :(
231- if (tile.type == Abyss::DataTypes::TileType::RightPartOfNorthCornerWall)
232- tile.dt1Ref ->drawTile (posX - _cameraPosition.x , posY - _cameraPosition.y + 96 , tile.dt1IndexAlt );
233- }
234-
235- }
202+ if (_mapEngine)
203+ _mapEngine->render ();
236204
237- }
238- }
239-
240- for (int tileY = 0 ; tileY < _ds1->height ; ++tileY) {
241- for (int tileX = 0 ; tileX < _ds1->width ; ++tileX) {
242- const auto posX = (tileX - tileY) * 80 ;
243- const auto posY = (tileX + tileY) * 40 ;
244-
245- // Draw Roof
246- for (const auto &layer : _ds1->layers .wall ) {
247- if (const auto &tile = layer[tileX + tileY * _ds1->width ];
248- tile.dt1Ref && tile.type == Abyss::DataTypes::TileType::Roof)
249- tile.dt1Ref ->drawTile (posX - _cameraPosition.x , posY - _cameraPosition.y - 72 , tile.dt1Index );
250- }
251-
252- }
253- }
254- }
255-
256- ImGui::SetNextWindowSize (ImVec2 (250 , 200 ), ImGuiCond_FirstUseEver);
205+ ImGui::SetNextWindowSize (ImVec2 (350 , 200 ), ImGuiCond_FirstUseEver);
257206 ImGui::Begin (" Debug" );
258207
259208 // Level selection
@@ -264,7 +213,9 @@ void MapTest::render() {
264213 if (_selectedLevelName != levelName) {
265214 onLevelChanged (levelName);
266215 _selectedLevelName = levelName;
267- _selectedLevelAltName = " " ;
216+ _selectedLevelAltName = _mapAltSelections.empty () ? " " : _mapAltSelections.front ();
217+ if (!_selectedLevelAltName.empty ())
218+ loadTile (_selectedLevelAltName);
268219 }
269220
270221 if (isSelected)
@@ -291,6 +242,22 @@ void MapTest::render() {
291242 }
292243 }
293244
245+ ImGui::Separator ();
246+
247+ // Show map information
248+ if (_mapEngine) {
249+ int mapWidth;
250+ int mapHeight;
251+ _mapEngine->getMapSize (mapWidth, mapHeight);
252+ int cameraPosX;
253+ int cameraPosY;
254+ _mapEngine->getCameraPosition (cameraPosX, cameraPosY);
255+
256+ ImGui::LabelText (" Map size" , " %d, %d" , mapWidth, mapHeight);
257+ ImGui::LabelText (" Camera position" , " %d, %d" , cameraPosX, cameraPosY);
258+ ImGui::LabelText (" DS1" , " %s" , _selectedLevelAltName.c_str ());
259+ }
260+
294261 ImGui::End ();
295262}
296263
0 commit comments