示例#1
0
文件: wizard.c 项目: dmalves/cage
/* **level\_data** is created and populated with
 * level specific entities. Some entities require further
 * initialization, such as the timeline.
 * A timeline allows creating a sequence of events
 * on a, well.. time line. Each event has a start time,
 * duration and callback function the will get called
 * each time the timeline is updated and if the event
 * is active.
 * We use a timeline to animate the title, creating 3
 * events: (1) slide the title into the screen (2)
 * make the title "bling" and (3) slide the title out
 * of the screen.
 * Using the SECOND and SECONDS constant is for
 * the sake of readability only.
 */
static struct level_data* create_level_data(void)
{
    struct level_data* ldata = calloc(1, sizeof(*ldata));
    if (ldata == NULL) goto error;

    ldata->wizard = create_wizard();
    if (ldata->wizard == NULL) goto cleanup_level_data;

    if (prepare_title(&ldata->title) != 0) goto cleanup_level_data;
    if (prepare_tree(&ldata->tree) != 0) goto cleanup_level_data;

    ldata->grass_tile = create_image("res/grass_tile.png");
    if (ldata->grass_tile == NULL) goto cleanup_level_data;

    ldata->earth_tile = create_image("res/earth_tile.png");
    if (ldata->earth_tile == NULL) goto cleanup_level_data;

    play_animation(ldata->tree.sprite, ldata->tree.windblow);

    ldata->timeline = create_timeline();
    if (ldata->timeline == NULL) goto cleanup_level_data;
    append_event(ldata->timeline, 0, 1 * SECOND, before_title_in);
    append_event(ldata->timeline, 0, 1 * SECOND, slide_title_in);
    append_event(ldata->timeline, 0, 4 * SECONDS, bling_title);
    append_event(ldata->timeline, 0, 1 * SECOND, slide_title_out);

    ldata->font = create_font("res/font.png", 32, 4);
    if (ldata->font == NULL) goto cleanup_level_data;

    ldata->music = create_sound("res/wizard.ogg");
    play_sound(ldata->music, -1);
    return ldata;

cleanup_level_data:
    destroy_level_data(ldata);

error:
    ERROR("Unable to create level data");
    return NULL;
}
示例#2
0
/*
this function is an optimized version of tdb_cons_append_subset_lexicon():
instead of mapping items to strings and back, we know that all entries from
the lexicon will be needed, so we can merge the lexicons and add remap items
in db to items in cons, without going through strings.
*/
static tdb_error tdb_cons_append_full_lexicon(tdb_cons *cons, const tdb *db)
{
    tdb_val **lexicon_maps = NULL;
    uint64_t i, trail_id;
    int ret = 0;

    tdb_cursor *cursor = tdb_cursor_new(db);
    if (!cursor)
        return TDB_ERR_NOMEM;

    if (db->min_timestamp < cons->min_timestamp)
        cons->min_timestamp = db->min_timestamp;

    if (!(lexicon_maps = append_lexicons(cons, db))){
        ret = TDB_ERR_NOMEM;
        goto done;
    }

    for (trail_id = 0; trail_id < tdb_num_trails(db); trail_id++){
        __uint128_t uuid_key;
        Word_t *uuid_ptr;
        const tdb_event *event;

        memcpy(&uuid_key, tdb_get_uuid(db, trail_id), 16);
        uuid_ptr = j128m_insert(&cons->trails, uuid_key);

        if ((ret = tdb_get_trail(cursor, trail_id)))
            goto done;

        while ((event = tdb_cursor_next(cursor)))
            append_event(cons, event, uuid_ptr, lexicon_maps);
    }
done:
    if (lexicon_maps){
        for (i = 0; i < cons->num_ofields; i++)
            free(lexicon_maps[i]);
        free(lexicon_maps);
    }
    tdb_cursor_free(cursor);
    return ret;
}
示例#3
0
文件: print.c 项目: Henauxg/minix
static krb5_error_code
entry2string_int (krb5_context context, krb5_storage *sp, hdb_entry *ent)
{
    char *p;
    size_t i;
    krb5_error_code ret;

    /* --- principal */
    ret = krb5_unparse_name(context, ent->principal, &p);
    if(ret)
	return ret;
    append_string(context, sp, "%s ", p);
    free(p);
    /* --- kvno */
    append_string(context, sp, "%d", ent->kvno);
    /* --- keys */
    for(i = 0; i < ent->keys.len; i++){
	/* --- mkvno, keytype */
	if(ent->keys.val[i].mkvno)
	    append_string(context, sp, ":%d:%d:",
			  *ent->keys.val[i].mkvno,
			  ent->keys.val[i].key.keytype);
	else
	    append_string(context, sp, "::%d:",
			  ent->keys.val[i].key.keytype);
	/* --- keydata */
	append_hex(context, sp, &ent->keys.val[i].key.keyvalue);
	append_string(context, sp, ":");
	/* --- salt */
	if(ent->keys.val[i].salt){
	    append_string(context, sp, "%u/", ent->keys.val[i].salt->type);
	    append_hex(context, sp, &ent->keys.val[i].salt->salt);
	}else
	    append_string(context, sp, "-");
    }
    append_string(context, sp, " ");
    /* --- created by */
    append_event(context, sp, &ent->created_by);
    /* --- modified by */
    append_event(context, sp, ent->modified_by);

    /* --- valid start */
    if(ent->valid_start)
	append_string(context, sp, "%s ", time2str(*ent->valid_start));
    else
	append_string(context, sp, "- ");

    /* --- valid end */
    if(ent->valid_end)
	append_string(context, sp, "%s ", time2str(*ent->valid_end));
    else
	append_string(context, sp, "- ");

    /* --- password ends */
    if(ent->pw_end)
	append_string(context, sp, "%s ", time2str(*ent->pw_end));
    else
	append_string(context, sp, "- ");

    /* --- max life */
    if(ent->max_life)
	append_string(context, sp, "%d ", *ent->max_life);
    else
	append_string(context, sp, "- ");

    /* --- max renewable life */
    if(ent->max_renew)
	append_string(context, sp, "%d ", *ent->max_renew);
    else
	append_string(context, sp, "- ");

    /* --- flags */
    append_string(context, sp, "%d ", HDBFlags2int(ent->flags));

    /* --- generation number */
    if(ent->generation) {
	append_string(context, sp, "%s:%d:%d ", time2str(ent->generation->time),
		      ent->generation->usec,
		      ent->generation->gen);
    } else
	append_string(context, sp, "- ");

    /* --- extensions */
    if(ent->extensions && ent->extensions->len > 0) {
	for(i = 0; i < ent->extensions->len; i++) {
	    void *d;
	    size_t size, sz = 0;

	    ASN1_MALLOC_ENCODE(HDB_extension, d, size,
			       &ent->extensions->val[i], &sz, ret);
	    if (ret) {
		krb5_clear_error_message(context);
		return ret;
	    }
	    if(size != sz)
		krb5_abortx(context, "internal asn.1 encoder error");

	    if (hex_encode(d, size, &p) < 0) {
		free(d);
		krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
		return ENOMEM;
	    }

	    free(d);
	    append_string(context, sp, "%s%s", p,
			  ent->extensions->len - 1 != i ? ":" : "");
	    free(p);
	}
    } else
	append_string(context, sp, "-");


    return 0;
}
示例#4
0
static krb5_error_code
entry2string_int (krb5_context context, krb5_storage *sp, hdb_entry *ent)
{
    char *p;
    int i;
    krb5_error_code ret;

    /* --- principal */
    ret = krb5_unparse_name(context, ent->principal, &p);
    if(ret)
	return ret;
    append_string(context, sp, "%s ", p);
    free(p);
    /* --- kvno */
    append_string(context, sp, "%d", ent->kvno);
    /* --- keys */
    for(i = 0; i < ent->keys.len; i++){
	/* --- mkvno, keytype */
	if(ent->keys.val[i].mkvno)
	    append_string(context, sp, ":%d:%d:", 
			  *ent->keys.val[i].mkvno, 
			  ent->keys.val[i].key.keytype);
	else
	    append_string(context, sp, "::%d:", 
			  ent->keys.val[i].key.keytype);
	/* --- keydata */
	append_hex(context, sp, &ent->keys.val[i].key.keyvalue);
	append_string(context, sp, ":");
	/* --- salt */
	if(ent->keys.val[i].salt){
	    append_string(context, sp, "%u/", ent->keys.val[i].salt->type);
	    append_hex(context, sp, &ent->keys.val[i].salt->salt);
	}else
	    append_string(context, sp, "-");
    }
    append_string(context, sp, " ");
    /* --- created by */
    append_event(context, sp, &ent->created_by);
    /* --- modified by */
    append_event(context, sp, ent->modified_by);

    /* --- valid start */
    if(ent->valid_start)
	append_string(context, sp, "%s ", time2str(*ent->valid_start));
    else
	append_string(context, sp, "- ");

    /* --- valid end */
    if(ent->valid_end)
	append_string(context, sp, "%s ", time2str(*ent->valid_end));
    else
	append_string(context, sp, "- ");
    
    /* --- password ends */
    if(ent->pw_end)
	append_string(context, sp, "%s ", time2str(*ent->pw_end));
    else
	append_string(context, sp, "- ");

    /* --- max life */
    if(ent->max_life)
	append_string(context, sp, "%d ", *ent->max_life);
    else
	append_string(context, sp, "- ");

    /* --- max renewable life */
    if(ent->max_renew)
	append_string(context, sp, "%d ", *ent->max_renew);
    else
	append_string(context, sp, "- ");
    
    /* --- flags */
    append_string(context, sp, "%d ", HDBFlags2int(ent->flags));

    /* --- generation number */
    if(ent->generation) {
	append_string(context, sp, "%s:%d:%d", time2str(ent->generation->time),
		      ent->generation->usec,
		      ent->generation->gen);
    } else
	append_string(context, sp, "-");
    
    return 0;
}