Esempio n. 1
0
/// Create an entity within this slice and store it in the entity list.
///
/// @param[in] pType                 Type of entity to create.
/// @param[in] rPosition             EntityDefinition position.
/// @param[in] rRotation             EntityDefinition rotation.
/// @param[in] rScale                EntityDefinition scale.
/// @param[in] pTemplate             Template from which to create the entity.
/// @param[in] name                  Object name to assign to the entity, or a null name to automatically generate a
///                                  name based on the entity type.
/// @param[in] bAssignInstanceIndex  True to assign an instance index to the entity, false to not include an
///                                  instance index.
///
/// @return  Pointer to the entity instance if created successfully, null if not.
///
/// @see DestroyEntity()
Entity* Slice::CreateEntity(EntityDefinition *pEntityDefinition, ParameterSet *pParameterSet)
{
    HELIUM_ASSERT( pEntityDefinition );
    if( !pEntityDefinition )
    {
        HELIUM_TRACE( TraceLevels::Error, TXT( "Slice::CreateEntity(): EntityDefinition is NULL.\n" ) );
        return NULL;
    }

    EntityPtr entity = pEntityDefinition->CreateEntity();
    HELIUM_ASSERT( entity.Get() );
    if (!entity)
    {
        HELIUM_TRACE( TraceLevels::Error, TXT( "Slice::CreateEntity(): Call to EntityDefinition::CreateEntity failed.\n" ) );
        return NULL;
    }
    
    size_t sliceIndex = m_entities.Push( entity );
    HELIUM_ASSERT( IsValid( sliceIndex ) );
    entity->SetSliceInfo( this, sliceIndex );

    pEntityDefinition->FinalizeEntity(entity, pParameterSet);

    return entity.Get();
}
static duk_ret_t EntityReference_LookupParent_Entity(duk_context* ctx)
{
    EntityReference* thisObj = GetThisValueObject<EntityReference>(ctx, EntityReference_ID);
    Entity* entity = GetWeakObject<Entity>(ctx, 0);
    EntityPtr ret = thisObj->LookupParent(entity);
    PushWeakObject(ctx, ret.Get());
    return 1;
}
static duk_ret_t EntityReference_Lookup_Scene(duk_context* ctx)
{
    EntityReference* thisObj = GetThisValueObject<EntityReference>(ctx, EntityReference_ID);
    Scene* scene = GetWeakObject<Scene>(ctx, 0);
    EntityPtr ret = thisObj->Lookup(scene);
    PushWeakObject(ctx, ret.Get());
    return 1;
}