Download Tutorial C Files H Files

dg_entity_get_component

This function is used to get a component from a entity.

Usage

void *dg_entity_get_component(dg_entity_t *entity, char *name);

Example

dg_animator_t *animator = (dg_animator_t *)(dg_entity_get_component(entity, "animator"));

Source code

void *dg_entity_get_component(dg_entity_t *entity, char *name)
{
    dg_array_t *tmp = 0;
    dg_component_t *component = 0;

    if (!entity || !name)
        return 0;
    tmp = entity->components;
    while (tmp && tmp->data) {
        component = ((dg_component_t *)(tmp->data));
        if (!dg_strcmp(component->name, name))
            return (component->data);
        tmp = tmp->next;
    }
    return 0;
}