| 195 | } |
| 196 | |
| 197 | void Registry::update(double dt) |
| 198 | { |
| 199 | std::vector<sol::object> dependencyValues; |
| 200 | mBindingTree.traverse([this, &dependencyValues, dt](Id node) { |
| 201 | sol::main_object newValue = mValues[node]; |
| 202 | std::vector<Binding>& bindings = mBindings[node]; |
| 203 | bindings.erase(std::remove_if(bindings.begin(), bindings.end(), |
| 204 | [&](const Binding& binding) { |
| 205 | if (!binding.mCallback.isValid()) |
| 206 | return true; |
| 207 | |
| 208 | dependencyValues.clear(); |
| 209 | for (Id parent : binding.mDependencies) |
| 210 | dependencyValues.push_back(mValues[parent]); |
| 211 | try |
| 212 | { |
| 213 | newValue = sol::main_object( |
| 214 | binding.mCallback.call(dt, newValue, sol::as_args(dependencyValues))); |
| 215 | } |
| 216 | catch (std::exception& e) |
| 217 | { |
| 218 | if (!validateActionValue(newValue, mInfo[node].mType)) |
| 219 | Log(Debug::Error) |
| 220 | << "Error due to invalid value of action \"" << mKeys[node] |
| 221 | << "\"(\"" << LuaUtil::toString(newValue) << "\"): " << e.what(); |
| 222 | else |
| 223 | Log(Debug::Error) << "Error in callback: " << e.what(); |
| 224 | } |
| 225 | return false; |
| 226 | }), |
| 227 | bindings.end()); |
| 228 | |
| 229 | if (!validateActionValue(newValue, mInfo[node].mType)) |
| 230 | Log(Debug::Error) << "Invalid value of action \"" << mKeys[node] |
| 231 | << "\": " << LuaUtil::toString(newValue); |
| 232 | if (mValues[node] != newValue) |
| 233 | { |
| 234 | mValues[node] = sol::object(newValue); |
| 235 | std::vector<LuaUtil::Callback>& handlers = mHandlers[node]; |
| 236 | handlers.erase(std::remove_if(handlers.begin(), handlers.end(), |
| 237 | [&](const LuaUtil::Callback& handler) { |
| 238 | if (!handler.isValid()) |
| 239 | return true; |
| 240 | handler.tryCall(newValue); |
| 241 | return false; |
| 242 | }), |
| 243 | handlers.end()); |
| 244 | } |
| 245 | }); |
| 246 | } |
| 247 | |
| 248 | void Registry::clear(bool force) |
| 249 | { |
nothing calls this directly
no test coverage detected