Exemple #1
0
void tp_collect(TP) {
    int n;
    for (n=0; n<tp->white->len; n++) {
        tp_obj r = tp->white->items[n];
        if (*r.gci.data) { continue; }
        tp_delete(tp,r);
    }
    tp->white->len = 0;
    tp_reset(tp);
}
Exemple #2
0
/* Function: tp_deinit
 * Destroys a VM instance.
 * 
 * When you no longer need an instance of tinypy, you can use this to free all
 * memory used by it. Even when you are using only a single tinypy instance, it
 * may be good practice to call this function on shutdown.
 */
void tp_deinit(TP) {
    while (tp->root.list.val->len) {
        _tp_list_pop(tp,tp->root.list.val,0,"tp_deinit");
    }
    tp_full(tp); tp_full(tp);
    tp_delete(tp,tp->root);
    tp_gc_deinit(tp);
    tp->mem_used -= sizeof(tp_vm); 
    free(tp);
}
Exemple #3
0
void tp_collect(TP) {
    int n;
    for (n=0; n<tp->white->len; n++) {
        tp_obj r = tp->white->items[n];
        if (*r.gci.data) { continue; }
        if (r.type == TP_STRING) {
            /*this can't be moved into tp_delete, because tp_delete is
               also used by tp_track_s to delete redundant strings*/
            _tp_dict_del(tp,tp->strings,r,"tp_collect");
        }
        tp_delete(tp,r);
    }
    tp->white->len = 0;
    tp_reset(tp);
}
Exemple #4
0
tp_obj tp_track(TP,tp_obj v) {
    if (v.type == TP_STRING) {
        int i = _tp_dict_find(tp,tp->strings,v);
        if (i != -1) {
            tp_delete(tp,v);
            v = tp->strings->items[i].key;
            tp_grey(tp,v);
            return v;
        }
        _tp_dict_setx(tp,tp->strings,v,tp_True);
    }
    tp_gcinc(tp);
    tp_grey(tp,v);
    return v;
}
Exemple #5
0
int
main(int argc, char *argv[])
{
    SDL_Surface *screen;

    TPool *tpool;
    CIList *cil;
    CImage *ci;

    int i, ch;
    unsigned int rw, rh; // requested window size
    unsigned long int fcount, do_jpeg;
    double ticks_start, load_fade, aspect;

    /* Copyright notice */
    printf("\n  Continuous Imaging 'fly'\n  Copyright (C) 2008-2012  David Lowy & Tom Rathborne\n\n");

    /* Get options --jpeg / -j and --geometry / -g */
    static struct option longopts[] = {
        { "jpeg",       no_argument,        NULL, 'j' },
        { "geometry",   required_argument,  NULL, 'g' },
        { NULL,         0,                  NULL, 0 }
    };

    /* Defaults */
    do_jpeg = 0;
    rw = 0;
    rh = 0;

    while ((ch = getopt_long(argc, argv, "jg:", longopts, NULL)) != -1)
        switch(ch) {
            case 'j':
                do_jpeg = 1;
                break;
            case 'g':
                if (sscanf(optarg, "%ux%u", &rw, &rh) != 2) {
                    printf("Unhandled geometry '%s': format is WxH\n", optarg);
                    rw = 0;
                    rh = 0;
                }
                break;
            default:
                printf("Unrecognized option %c ignored\n", ch);
        }

    argc -= optind;
    argv += optind;

    /* Get SDL+GL screen */
    screen = init_sdl_gl(CI_BPC, CI_BITS, rw, rh);
    if(!screen) {
        fprintf(stderr, "Failed to init SDL GL context.\n");
        return (0);
    }

#ifndef CI_LINUX
    SDL_ShowCursor(SDL_DISABLE);
#endif
    SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);

    /* Set up JPEG if necessary */
    if (do_jpeg) jpeg_alloc(screen->w, screen->h);

    aspect = CI_ASPECT / ((double)screen->w / (double)screen->h);

    /* time entire program */
    ticks_start = SDL_GetTicks();

    /* Init texture pool */
    tpool = tp_create(65535, 800); // This was supposed to keep fewer textures in VRAM, but it just fills VRAM.

    /* create CI List */
    cil = cil_create(tpool, "thumb/%s.jpg", "image/%s.jpg");

    /* Load all dbs, make links */
    cil_load_scidb(cil, "cidb.db");

    /* Load image data and textures - and draw 'em! */
    for(i = 0; i < cil->rcount; i++) {
        ci = cil->list[i];
        assert(ci);
        assert(ci->subs);

        cil_ci_imgprep(cil, ci, 0); /* load images to N levels */
        ci_load_tx(ci, 0); /* load textures to N level */

        // Render
        load_fade = sqrt(1.0 - ((double) i / (double) cil->rcount));
        glLoadIdentity();
        glScalef(load_fade, load_fade / aspect, 1.0);
        // glRotatef(360.0 * ((double) i / (double) cil->rcount), 0.0, 0.0, 1.0);
        glTranslatef(-0.5, -0.5, 0.0);

        glClear(GL_COLOR_BUFFER_BIT);
        glColor4f(1.0, 1.0, 1.0, sqrt(load_fade));
        glBindTexture(GL_TEXTURE_2D, ci->tid);
        glCallList(cil->gl_list);
        SDL_GL_SwapBuffers();
    }

    for(i = 0; i < cil->rcount; i++) {
        ci = cil->list[i];
        assert(ci);
        assert(ci->subs);
        ci_mklist(ci, cil->gl_list);
    }

    printf("Startup took %.2fs.\n", (SDL_GetTicks() - ticks_start) / 1000.0);

    /* Main loop */
    ticks_start = SDL_GetTicks();

    SDL_WarpMouse(screen->w/2, screen->h/2);
    SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
    fcount = fly(screen, cil, do_jpeg);

    printf("Average FPS: %.2f\n", fcount * 1000.0 / (SDL_GetTicks() - ticks_start));

    printf("Cleaning up ...\n");

    cil_cleanup(cil);

    /* cleanup */
    cil_delete(cil);

    /* drop our data */
    tp_delete(tpool);

    /* JPEG cleanup */
    if (do_jpeg) jpeg_free();

    SDL_Quit();

    return (0);
}