| 2957 | |
| 2958 | |
| 2959 | void cChunkMap::AddChunkStay(cChunkStay & a_ChunkStay) |
| 2960 | { |
| 2961 | cCSLock Lock(m_CSLayers); |
| 2962 | |
| 2963 | // Add it to the list: |
| 2964 | ASSERT(std::find(m_ChunkStays.begin(), m_ChunkStays.end(), &a_ChunkStay) == m_ChunkStays.end()); // Has not yet been added |
| 2965 | m_ChunkStays.push_back(&a_ChunkStay); |
| 2966 | |
| 2967 | // Schedule all chunks to be loaded / generated, and mark each as locked: |
| 2968 | const cChunkCoordsVector & WantedChunks = a_ChunkStay.GetChunks(); |
| 2969 | for (cChunkCoordsVector::const_iterator itr = WantedChunks.begin(); itr != WantedChunks.end(); ++itr) |
| 2970 | { |
| 2971 | cChunkPtr Chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ); |
| 2972 | if (Chunk == NULL) |
| 2973 | { |
| 2974 | continue; |
| 2975 | } |
| 2976 | Chunk->Stay(true); |
| 2977 | if (Chunk->IsValid()) |
| 2978 | { |
| 2979 | if (a_ChunkStay.ChunkAvailable(itr->m_ChunkX, itr->m_ChunkZ)) |
| 2980 | { |
| 2981 | // The chunkstay wants to be deactivated, disable it and bail out: |
| 2982 | a_ChunkStay.Disable(); |
| 2983 | return; |
| 2984 | } |
| 2985 | } |
| 2986 | } // for itr - WantedChunks[] |
| 2987 | } |
| 2988 | |
| 2989 | |
| 2990 | |