MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / OnHandleCollision

Method OnHandleCollision

Sources/Jazz2/Scripting/ScriptActorWrapper.cpp:379–443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

377 }
378
379 bool ScriptActorWrapper::OnHandleCollision(std::shared_ptr<ActorBase> other)
380 {
381 if (_onHandleCollision != nullptr) {
382 if (auto* otherWrapper = runtime_cast<ScriptActorWrapper>(other.get())) {
383 asIScriptEngine* engine = _obj->GetEngine();
384 asITypeInfo* typeInfo = _levelScripts->GetMainModule()->GetTypeInfoByName(AsClassName);
385 if (typeInfo != nullptr) {
386 asIScriptContext* ctx = engine->RequestContext();
387
388 CScriptHandle handle(otherWrapper->_obj, typeInfo);
389 ctx->Prepare(_onHandleCollision);
390 ctx->SetObject(_obj);
391 std::int32_t p = ctx->SetArgObject(0, &handle);
392 std::int32_t r = ctx->Execute();
393 bool result;
394 if (r == asEXECUTION_EXCEPTION) {
395 LOGE("An exception \"{}\" occurred in \"{}\". Please correct the code and try again.",
396 ctx->GetExceptionString(), ctx->GetExceptionFunction()->GetDeclaration());
397 result = true;
398 } else {
399 result = (ctx->GetReturnByte() != 0);
400 }
401
402 engine->ReturnContext(ctx);
403
404 if (result) {
405 return true;
406 }
407 }
408 } else if (auto* player = runtime_cast<Player>(other.get())) {
409 asIScriptEngine* engine = _obj->GetEngine();
410 asITypeInfo* typeInfo = engine->GetTypeInfoByName("Player");
411 if (typeInfo != nullptr) {
412 asIScriptContext* ctx = engine->RequestContext();
413
414 void* mem = asAllocMem(sizeof(ScriptPlayerWrapper));
415 ScriptPlayerWrapper* playerWrapper = new(mem) ScriptPlayerWrapper(_levelScripts, player);
416
417 CScriptHandle handle(playerWrapper, typeInfo);
418 ctx->Prepare(_onHandleCollision);
419 ctx->SetObject(_obj);
420 std::int32_t p = ctx->SetArgObject(0, &handle);
421 std::int32_t r = ctx->Execute();
422 bool result;
423 if (r == asEXECUTION_EXCEPTION) {
424 LOGE("An exception \"{}\" occurred in \"{}\". Please correct the code and try again.",
425 ctx->GetExceptionString(), ctx->GetExceptionFunction()->GetDeclaration());
426 result = true;
427 } else {
428 result = (ctx->GetReturnByte() != 0);
429 }
430
431 engine->ReturnContext(ctx);
432
433 playerWrapper->Release();
434
435 if (result) {
436 return true;

Callers

nothing calls this directly

Calls 7

GetEngineMethod · 0.80
GetMainModuleMethod · 0.80
ExecuteMethod · 0.80
GetSpeedMethod · 0.80
NextFloatMethod · 0.80
getMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected