| 268 | } |
| 269 | |
| 270 | void LevelScriptLoader::OnLevelUpdate(float timeMult) |
| 271 | { |
| 272 | switch (GetContextType()) { |
| 273 | case ScriptContextType::Legacy: { |
| 274 | asIScriptFunction* onPlayer = GetMainModule()->GetFunctionByDecl("void onPlayer(jjPLAYER@)"); |
| 275 | |
| 276 | if (_onLevelUpdate == nullptr && onPlayer == nullptr) { |
| 277 | _onLevelUpdateLastFrame = (std::int32_t)_levelHandler->_elapsedFrames; |
| 278 | break; |
| 279 | } |
| 280 | |
| 281 | // Legacy context requires fixed frame count per second |
| 282 | OnBeforeScriptCall(); |
| 283 | asIScriptContext* ctx = GetEngine()->RequestContext(); |
| 284 | |
| 285 | // It should update at 70 FPS instead of 60 FPS |
| 286 | std::int32_t currentFrame = (std::int32_t)(_levelHandler->_elapsedFrames * (70.0f / 60.0f)); |
| 287 | while (_onLevelUpdateLastFrame <= currentFrame) { |
| 288 | if (_onLevelUpdate != nullptr) { |
| 289 | ctx->Prepare(_onLevelUpdate); |
| 290 | std::int32_t r = ctx->Execute(); |
| 291 | if (r == asEXECUTION_EXCEPTION) { |
| 292 | AS_LOG_EXCEPTION(ctx); |
| 293 | // Don't call the method again if an exception occurs |
| 294 | //_onLevelUpdate = nullptr; |
| 295 | } |
| 296 | } |
| 297 | if (onPlayer != nullptr) { |
| 298 | for (auto* player : _levelHandler->_players) { |
| 299 | ctx->Prepare(onPlayer); |
| 300 | |
| 301 | jjPLAYER* p = GetPlayerBackingStore(player); |
| 302 | ctx->SetArgObject(0, p); |
| 303 | |
| 304 | std::int32_t r = ctx->Execute(); |
| 305 | if (r == asEXECUTION_EXCEPTION) { |
| 306 | AS_LOG_EXCEPTION(ctx); |
| 307 | // Don't call the method again if an exception occurs |
| 308 | //_onLevelUpdate = nullptr; |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | _onLevelUpdateLastFrame++; |
| 313 | } |
| 314 | |
| 315 | GetEngine()->ReturnContext(ctx); |
| 316 | OnAfterScriptCall(); |
| 317 | break; |
| 318 | } |
| 319 | case ScriptContextType::Standard: { |
| 320 | _onLevelUpdateLastFrame = (int32_t)_levelHandler->_elapsedFrames; |
| 321 | if (_onLevelUpdate == nullptr) { |
| 322 | break; |
| 323 | } |
| 324 | |
| 325 | // Standard context supports floating frame rate |
| 326 | OnBeforeScriptCall(); |
| 327 | asIScriptContext* ctx = GetEngine()->RequestContext(); |
no test coverage detected