| 244 | #endif |
| 245 | |
| 246 | void ScriptingService::Update() |
| 247 | { |
| 248 | PROFILE_CPU_NAMED("Scripting::Update"); |
| 249 | INVOKE_EVENT(Update); |
| 250 | |
| 251 | // Flush update actions |
| 252 | _objectsLocker.Lock(); |
| 253 | int32 count = UpdateActions.Count(); |
| 254 | for (int32 i = 0; i < count; i++) |
| 255 | { |
| 256 | UpdateActions[i](); |
| 257 | } |
| 258 | int32 newlyAdded = UpdateActions.Count() - count; |
| 259 | if (newlyAdded == 0) |
| 260 | UpdateActions.Clear(); |
| 261 | else |
| 262 | { |
| 263 | // Someone added another action within current callback |
| 264 | Array<Function<void()>> tmp; |
| 265 | for (int32 i = newlyAdded; i < UpdateActions.Count(); i++) |
| 266 | tmp.Add(UpdateActions[i]); |
| 267 | UpdateActions.Clear(); |
| 268 | UpdateActions.Add(tmp); |
| 269 | } |
| 270 | _objectsLocker.Unlock(); |
| 271 | |
| 272 | #if defined(USE_NETCORE) && !USE_EDITOR |
| 273 | // Force GC to run in background periodically to avoid large blocking collections causing hitches |
| 274 | if (Time::Update.TicksCount % 60 == 0) |
| 275 | { |
| 276 | MCore::GC::Collect(MCore::GC::MaxGeneration(), MGCCollectionMode::Forced, false, false); |
| 277 | } |
| 278 | #endif |
| 279 | } |
| 280 | |
| 281 | void ScriptingService::LateUpdate() |
| 282 | { |