示例#1
0
文件: scene.c 项目: ifzz/merriment
void scene_deserialize(Scene* scene, cmp_ctx_t* context) {
    uint32_t key_count;
    char key[32];
    uint32_t key_len;

    cmp_read_map(context, &key_count);

    int k;
    for(k = 0 ; k < key_count ; ++k) {
        key_len = sizeof(key);
        cmp_read_str(context, key, &key_len);
        key[key_len] = 0;

        if(strcmp("path", key) == 0) {
            uint32_t path_len = 65;
            cmp_read_str(context, scene->path, &path_len);
            scene->path[path_len] = 0;
        } else if (strcmp("entities", key) == 0) {
            uint32_t entities_size;
            cmp_read_array(context, &entities_size);

            int i;
            for(i = 0; i < entities_size ; ++i) {
                Entity* entity = entitypool_add(scene->entities);
                entity_deserialize(entity, scene, context);
            }
        } else if(strcmp("source", key) == 0) {
            uint32_t source_len = 65;
            char source[source_len];
            cmp_read_str(context, source, &source_len);
        }
    }
}
示例#2
0
文件: physics.c 项目: andi2/cgame
void physics_add(Entity ent)
{
    PhysicsInfo *info;

    if (entitypool_get(pool, ent))
        return; /* already has physics */

    transform_add(ent);

    info = entitypool_add(pool, ent);

    info->mass = 1.0;
    info->type = PB_DYNAMIC;

    /* create, init cpBody */
    info->body = cpSpaceAddBody(space, cpBodyNew(info->mass, 1.0));
    cpBodySetUserData(info->body, ent); /* for cpBody -> Entity mapping */
    cpBodySetPos(info->body, cpv_of_vec2(transform_get_position(ent)));
    cpBodySetAngle(info->body, transform_get_rotation(ent));
    info->last_dirty_count = transform_get_dirty_count(ent);

    /* initially no shapes */
    info->shapes = array_new(ShapeInfo);

    /* initialize last_pos/last_ang info for kinematic bodies */
    info->last_pos = cpBodyGetPos(info->body);
    info->last_ang = cpBodyGetAngle(info->body);

    info->collisions = NULL;
}