Exemple #1
0
/* entry point */
int main (int argc, char *argv[])
{
    int c;
    int pitch, size;
    BYTE* framebuffer;
    DWORD t0, t1;

    /* setup engine */
    TLN_Init (WIDTH,HEIGHT, MAX_LAYER, 0, 1);
    TLN_SetRasterCallback (raster_callback);
    TLN_SetBGColor (0,128,238);

    /* load resources*/
    LoadLayer (LAYER_FOREGROUND, "Sonic_md_fg1");
    LoadLayer (LAYER_BACKGROUND, "Sonic_md_bg1");

    /* load sequences */
    sp = TLN_LoadSequencePack ("Sonic_md_seq.sqx");
    sequence = TLN_FindSequence (sp, "seq_water");

    /* assign color sequence to various entries in palette */
    palette = TLN_GetTilesetPalette (layers[LAYER_BACKGROUND].tileset);
    TLN_SetPaletteAnimation (0, palette, sequence, false);

    /* compute increments for variable background scrolling speeds */
    inc_background[0] = float2fix(0.562f);
    inc_background[1] = float2fix(0.437f);
    inc_background[2] = float2fix(0.375f);
    inc_background[3] = float2fix(0.625f);
    inc_background[4] = float2fix(1.0f);
    inc_background[5] = float2fix(2.0f);

    /* framebuffer */
    pitch = WIDTH*4;
    size = pitch*HEIGHT;
    framebuffer = malloc (size);
    TLN_SetRenderTarget (framebuffer, pitch);

    /* main loop */
    printf ("Rendering 5 seconds... ");
    speed = 1.0;
    t0 = t1 = TLN_GetTicks ();
    while (t1 - t0 < 5000)
    {
        /* timekeeper */
        time = frame;

        /* scroll */
        pos_foreground += (int2fix(3)*speed);
        TLN_SetLayerPosition (LAYER_FOREGROUND, fix2int(pos_foreground), ypos);
        for (c=0; c<6; c++)
            pos_background[c] += (inc_background[c] * speed);

        /* render to window */
        TLN_UpdateFrame (time);
        frame++;
        t1 = TLN_GetTicks ();
    }
    printf ("%d fps\n", frame*1000/(t1 - t0));

    /* deinit */
    free (framebuffer);
    FreeLayer (LAYER_FOREGROUND);
    FreeLayer (LAYER_BACKGROUND);
    TLN_DeleteSequencePack (sp);
    TLN_Deinit ();

    return 0;
}
JNIEXPORT jint JNICALL Java_Tilengine_GetTilesetPalette (JNIEnv* env, jobject thisobj, jint tileset)
{
	return (jint)TLN_GetTilesetPalette ((TLN_Tileset)tileset);
}