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

Method Factory

Sources/Jazz2/Scripting/ScriptActorWrapper.cpp:174–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 1

GetNameMethod · 0.45

Tested by

no test coverage detected