Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CRT and set FPS bugs
#4
Hi,

I've found the explanation for both issues:

CRT filter

The problem here is that the background bitmap is smaller than the framebuffer. When thete's no background bitmap, each frame is cleared with the default background color. A background bitmap is supposed to cover the entire framebuffer, so the background color clear is disabled. The CRT effect applies a slight blurring, and because the rightmost part of the framebuffer isn't being cleared between frames, a feedback effect appears.

If you make the layer scroll, you'll see how the right part outside the background bitmap gets smeared even if you don't enable the CRT effect.

Just make sure that your background bitmap is at least as big as the framebuffer.

FPS throttling

The animation data inside the tmx file is expressed as delay between frames, in milliseconds. No matter how you play with fps, the delay between frames is respected, that's why you see the flowers always running at the same speed.

I've tweaked a bit your example.
  • To get an estimate of fps is not enough to sample just one frame, it's better to average some. So here I average each 500 ms (twice per second) to get a better estimate.
  • I've made the front layer scroll at constant speed of 1 pixel/frame
Now if you play with the TLN_SetTargetFps()function, you'll see how the average fps output on the console approximates the value you set, and that the layer scrolling speed varies, the higher the fps, the faster it scrolls.

Hope to have answered your questions!


Code:
#include "Tilengine.h"

int main(void) {
    TLN_Init (400, 240, 1, 0, 0);
    TLN_Bitmap bm = TLN_LoadBitmap("elis.bmp");
    TLN_Tilemap tm = TLN_LoadTilemap("assets/sonic/Sonic_md_fg1.tmx", NULL);
    TLN_SetBGBitmap(bm);
    TLN_SetLayerTilemap(0, tm);
    TLN_CreateWindow (NULL, CWF_S3|CWF_NOVSYNC);
    TLN_SetTargetFps(200);

    uint32_t time = 0;
    uint32_t numframes = 0;
    uint32_t t0 = TLN_GetTicks();
    int x = 0;
    while (TLN_ProcessWindow()) {
        /* adjust game logic pacing to target fps */
        uint32_t begin = TLN_GetTicks();
        TLN_DrawFrame(0);
        uint32_t end = TLN_GetTicks();
        time += (end - begin);
        numframes += 1;
       
        /* autoscroll */
        x += 1;
        TLN_SetLayerPosition(0, x, 0);
       
        /* average each 500 ms */
        if (end - t0 >= 500) {
            printf("FPS = %.02f\n", (1000.0 * numframes) / (float)time);
            t0 = end;
            time = numframes = 0;
        }
    }

    TLN_Deinit ();
}
Reply


Messages In This Thread
CRT and set FPS bugs - by System64 - 03-28-2024, 07:29 AM
RE: CRT and set FPS bugs - by megamarc - 04-02-2024, 04:20 AM
RE: CRT and set FPS bugs - by System64 - 04-02-2024, 10:36 AM
RE: CRT and set FPS bugs - by megamarc - 04-04-2024, 03:18 AM

Forum Jump:


Users browsing this thread: 4 Guest(s)