]> git.localhorst.tv Git - l2e.git/blobdiff - src/map/MapState.cpp
extracted map loading/unloading
[l2e.git] / src / map / MapState.cpp
index 8c5ef6bcf1c53ec612c3ba86d043b003127563b8..7e6d7328d2756bb533527cf41efc25a9a2b6f703 100644 (file)
@@ -37,6 +37,7 @@ MapState::MapState(Map *map)
 
 void MapState::EnterState(Application &ctrl, SDL_Surface *screen) {
        camera.Resize(screen->w, screen->h);
+       LoadMap(map);
 }
 
 void MapState::ExitState(Application &ctrl, SDL_Surface *screen) {
@@ -287,17 +288,28 @@ void MapState::StopFollowers(Entity &e) {
 
 
 void MapState::Transition(Map *newMap, const Vector<int> &coordinates) {
+       UnloadMap();
        Vector<int> position(coordinates * map->Tileset()->Size());
-       entities.clear();
        for (Entity *e(controlled); e; e = e->Follower()) {
                e->Position() = position;
                e->SetOrientation(controlled->GetOrientation());
-               entities.push_back(e);
        }
-       map = newMap;
+       LoadMap(newMap);
        skipLock = true;
 }
 
+void MapState::UnloadMap() {
+       entities.clear();
+}
+
+void MapState::LoadMap(Map *m) {
+       map = m;
+       entities.insert(entities.end(), m->EntitiesBegin(), m->EntitiesEnd());
+       for (Entity *e(controlled); e; e = e->Follower()) {
+               entities.push_back(e);
+       }
+}
+
 
 void MapState::Render(SDL_Surface *screen) {
        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));