Ejemplo n.º 1
0
int main() {
    struct diana *diana = allocate_diana(malloc, free);
    struct velocity ev = {1.5, 0};
    unsigned int i = 0;

    positionComponent = diana_createComponent(diana, "position", sizeof(struct position), DL_COMPONENT_FLAG_INLINE);
    DEBUG(diana);
    velocityComponent = diana_createComponent(diana, "velocity", sizeof(struct velocity), DL_COMPONENT_FLAG_INLINE);
    DEBUG(diana);
    rendererComponent = diana_createComponent(diana, "renderer", sizeof(struct renderer), DL_COMPONENT_FLAG_INLINE);
    DEBUG(diana);

    unsigned int movementSystem = diana_createSystem(diana, "movement", NULL, movementSystem_process, NULL, NULL, NULL, NULL, DL_SYSTEM_FLAG_NORMAL);
    DEBUG(diana);
    diana_watch(diana, movementSystem, positionComponent);
    DEBUG(diana);
    diana_watch(diana, movementSystem, velocityComponent);
    DEBUG(diana);

    unsigned int renderSystem = diana_createSystem(diana, "render", NULL, renderSystem_process, NULL, NULL, NULL, NULL, DL_SYSTEM_FLAG_PASSIVE);
    DEBUG(diana);
    diana_watch(diana, renderSystem, positionComponent);
    DEBUG(diana);
    diana_watch(diana, renderSystem, rendererComponent);
    DEBUG(diana);

    diana_initialize(diana);
    DEBUG(diana);

    unsigned int e = diana_spawn(diana);
    DEBUG(diana);
    diana_setComponent(diana, e, positionComponent, NULL);
    DEBUG(diana);
    diana_setComponent(diana, e, velocityComponent, &ev);
    DEBUG(diana);
    diana_signal(diana, e, DL_ENTITY_ADDED);
    DEBUG(diana);

    unsigned int e1 = diana_spawn(diana);
    DEBUG(diana);
    diana_setComponent(diana, e1, positionComponent, NULL);
    DEBUG(diana);
    diana_setComponent(diana, e1, rendererComponent, NULL);
    DEBUG(diana);
    diana_signal(diana, e1, DL_ENTITY_ADDED);
    DEBUG(diana);

    while(1) {
        // 30 fps
        diana_process(diana, 1.0/30.0);
        DEBUG(diana);
        sleep(1);

        if(i++ % 2 == 0) {
            diana_processSystem(diana, renderSystem, 1.0/30.0);
            DEBUG(diana);
        }
    }
}
Ejemplo n.º 2
0
void System::setWorld(World *world) {
	_world = world;
	diana_createSystem(world->getDiana(), _name.c_str(), _system_starting, _system_process, _system_ending, _system_subscribed, _system_unsubscribed, this, systemFlags(), &_id);
	addWatches();
}