MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / CScriptArray

Method CScriptArray

src/server/angelscript/add_on/scriptarray/scriptarray.cpp:373–464  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

371}
372
373CScriptArray::CScriptArray(asITypeInfo *ti, void *buf)
374{
375 // The object type should be the template instance of the array
376 assert( ti && string(ti->GetName()) == "array" );
377
378 refCount = 1;
379 gcFlag = false;
380 objType = ti;
381 objType->AddRef();
382 buffer = 0;
383
384 Precache();
385
386 asIScriptEngine *engine = ti->GetEngine();
387
388 // Determine element size
389 if( subTypeId & asTYPEID_MASK_OBJECT )
390 elementSize = sizeof(asPWORD);
391 else
392 elementSize = engine->GetSizeOfPrimitiveType(subTypeId);
393
394 // Determine the initial size from the buffer
395 asUINT length = *(asUINT*)buf;
396
397 // Make sure the array size isn't too large for us to handle
398 if( !CheckMaxSize(length) )
399 {
400 // Don't continue with the initialization
401 return;
402 }
403
404 // Copy the values of the array elements from the buffer
405 if( (ti->GetSubTypeId() & asTYPEID_MASK_OBJECT) == 0 )
406 {
407 CreateBuffer(&buffer, length);
408
409 // Copy the values of the primitive type into the internal buffer
410 if( length > 0 )
411 memcpy(At(0), (((asUINT*)buf)+1), length * elementSize);
412 }
413 else if( ti->GetSubTypeId() & asTYPEID_OBJHANDLE )
414 {
415 CreateBuffer(&buffer, length);
416
417 // Copy the handles into the internal buffer
418 if( length > 0 )
419 memcpy(At(0), (((asUINT*)buf)+1), length * elementSize);
420
421 // With object handles it is safe to clear the memory in the received buffer
422 // instead of increasing the ref count. It will save time both by avoiding the
423 // call the increase ref, and also relieve the engine from having to release
424 // its references too
425 memset((((asUINT*)buf)+1), 0, length * elementSize);
426 }
427 else if( ti->GetSubType()->GetFlags() & asOBJ_REF )
428 {
429 // Only allocate the buffer, but not the objects
430 subTypeId |= asTYPEID_OBJHANDLE;

Callers

nothing calls this directly

Calls 10

GetFlagsMethod · 0.80
AssignScriptObjectMethod · 0.80
GetNameMethod · 0.45
AddRefMethod · 0.45
GetEngineMethod · 0.45
GetSubTypeIdMethod · 0.45
GetSubTypeMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected