| 110 | |
| 111 | |
| 112 | void cBiomeCache::HintViewArea(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ) |
| 113 | { |
| 114 | cTimer Timer("Cache: HintViewArea"); |
| 115 | |
| 116 | if ( |
| 117 | (a_MinChunkX == m_BaseX) && |
| 118 | (a_MaxChunkX == m_BaseX + m_Width - 1) && |
| 119 | (a_MinChunkZ == m_BaseZ) && |
| 120 | (a_MaxChunkZ == m_BaseZ + m_Height - 1) |
| 121 | ) |
| 122 | { |
| 123 | // The same set of parameters, bail out |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | if (m_Source != NULL) |
| 128 | { |
| 129 | m_Source->HintViewArea(a_MinChunkX, a_MaxChunkX, a_MinChunkZ, a_MaxChunkZ); |
| 130 | } |
| 131 | |
| 132 | int NewWidth = a_MaxChunkX - a_MinChunkX + 1; |
| 133 | int NewHeight = a_MaxChunkZ - a_MinChunkZ + 1; |
| 134 | |
| 135 | // Make a new empty cache table: |
| 136 | pItem * NewAvailable = new pItem[NewWidth * NewHeight]; |
| 137 | for (int i = NewWidth * NewHeight - 1; i >= 0; --i) |
| 138 | { |
| 139 | NewAvailable[i] = NULL; |
| 140 | } |
| 141 | |
| 142 | // Move the common contents of the old table into the new table: |
| 143 | cCSLock Lock(m_CS); |
| 144 | for (int z = 0; z < NewHeight; z++) |
| 145 | { |
| 146 | int OldZ = z + a_MinChunkZ - m_BaseZ; |
| 147 | if ((OldZ < 0) || (OldZ >= m_Height)) |
| 148 | { |
| 149 | continue; |
| 150 | } |
| 151 | for (int x = 0; x < NewWidth; x++) |
| 152 | { |
| 153 | int OldX = x + a_MinChunkX - m_BaseX; |
| 154 | if ((OldX < 0) || (OldX >= m_Width)) |
| 155 | { |
| 156 | continue; |
| 157 | } |
| 158 | NewAvailable[x + NewWidth * z] = m_Available[OldX + m_Width * OldZ]; |
| 159 | m_Available[OldX + m_Width * OldZ] = NULL; |
| 160 | } // for x |
| 161 | } // for z |
| 162 | |
| 163 | // All items that aren't common go into the pool: |
| 164 | for (int idx = 0, z = 0; z < m_Height; z++) |
| 165 | { |
| 166 | for (int x = 0; x < m_Width; ++x, ++idx) |
| 167 | { |
| 168 | if (m_Available[idx] != NULL) |
| 169 | { |