00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "ScriptedEvent.h"
00019
00020 #ifdef __COMPILE_WITH_ANGELSCRIPT__
00021
00022 #include "../../core/GameManager.h"
00023
00024
00025
00026
00027 ScriptedEvent::ScriptedEvent(asIScriptObject *object, const std::string &function)
00028 : mObject(object), mFunction(function)
00029 {
00030
00031 mObject->AddRef();
00032 mContext = GameManager::Instance()->getScriptManager()->getEngine()->CreateContext();
00033 }
00034
00035
00036 ScriptedEvent::~ScriptedEvent()
00037 {
00038
00039 mObject->Release();
00040 }
00041
00042
00043 void ScriptedEvent::onEvent(void *p)
00044 {
00045 int id = mObject->GetObjectType()->GetMethodIdByName(mFunction.c_str());
00046
00047 mContext->Prepare(id);
00048 mContext->SetObject(mObject);
00049 mContext->SetArgAddress(0, p);
00050 mContext->Execute();
00051 }
00052
00053
00054 void ScriptedEvent::onDisconnect(void *p)
00055 {
00056 drop();
00057 }
00058
00059 #endif // __COMPILE_WITH_ANGELSCRIPT__
00060
00061