| 217 | } |
| 218 | |
| 219 | void WaveSimulation2D::update() { |
| 220 | if (mUseChangeGrid) { |
| 221 | const vec2<i16> min_max = mChangeGrid.minMax(); |
| 222 | const bool has_updates = min_max != vec2<i16>(0, 0); |
| 223 | for (u8 i = 0; i < mExtraFrames + 1; ++i) { |
| 224 | if (has_updates) { |
| 225 | // apply them |
| 226 | const u32 w = mChangeGrid.width(); |
| 227 | const u32 h = mChangeGrid.height(); |
| 228 | for (u32 x = 0; x < w; ++x) { |
| 229 | for (u32 y = 0; y < h; ++y) { |
| 230 | i16 v16 = mChangeGrid(x, y); |
| 231 | if (v16 != 0) { |
| 232 | mSim->seti16(x, y, v16); |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | mSim->update(); |
| 238 | } |
| 239 | // zero out mChangeGrid |
| 240 | mChangeGrid.clear(); |
| 241 | } else { |
| 242 | // When change grid is disabled, just run the simulation updates |
| 243 | for (u8 i = 0; i < mExtraFrames + 1; ++i) { |
| 244 | mSim->update(); |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | u32 WaveSimulation2D::getWidth() const { return mOuterWidth; } |
| 250 | u32 WaveSimulation2D::getHeight() const { return mOuterHeight; } |