| 172 | } |
| 173 | |
| 174 | ScriptActorWrapper* ScriptActorWrapper::Factory(std::int32_t actorType) |
| 175 | { |
| 176 | auto ctx = asGetActiveContext(); |
| 177 | auto owner = ScriptLoader::FromActiveContext<LevelScriptLoader>(); |
| 178 | |
| 179 | // Get the function that is calling the factory, so we can be certain it is the our internal script class |
| 180 | asIScriptFunction* func = ctx->GetFunction(0); |
| 181 | if (func->GetObjectType() == nullptr || StringView(func->GetObjectType()->GetName()) != StringView(AsClassName)) { |
| 182 | ctx->SetException("Cannot manually instantiate " AsClassNameInternal); |
| 183 | return nullptr; |
| 184 | } |
| 185 | |
| 186 | asIScriptObject* obj = static_cast<asIScriptObject*>(ctx->GetThisPointer()); |
| 187 | switch (actorType) { |
| 188 | default: |
| 189 | case 0: { |
| 190 | void* mem = asAllocMem(sizeof(ScriptActorWrapper)); |
| 191 | return new(mem) ScriptActorWrapper(owner, obj); |
| 192 | } |
| 193 | case 1: { |
| 194 | void* mem = asAllocMem(sizeof(ScriptCollectibleWrapper)); |
| 195 | return new(mem) ScriptCollectibleWrapper(owner, obj); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | void ScriptActorWrapper::AddRef() |
| 201 | { |