Skip to main content
gamedev.net
🔒 Locked

Tile blitting problem

Started by smokes 1 reply 500+ views
Original Post
smokes
smokes
hi Im working on a topdown (world seen from above, not isometric view) tile scroller for a little online game/chat thing. very simple.. no match even for me :-)... but still I have a problem :-(. speed!.. and I think its probably due to my lame blitting. I use OpenPTC (a nice little library, which wraps up DirectX, also referred to in flipcode''s Rendering a portal engine - series), which basically gives me a pointer to a linear framebuffer (640x480x256). I then use a library function to copy that into a library-managed directx backbuffer, and another which performs the flip etc.. my tiles are 32x32, 20x15 fills a screen.. I redraw the screen on every frame.. when I scroll one pixel per frame, it looks nice but scroll VERY slow.. oki I then tried scrolling 3 or 5 pixels per screen.. the world is moving quickly but I doesn''t look nice.. it looks like the framerate is too low to fool the eye.. I tried optimizing my blit routine, tried setting PTC to copy direct to vidmen.. PTC should not cause the problem cuz all the demos that comes with it are fast enough.. and if I use only a 320x200 window on the screen it renders remarkbably faster.. so I''ve come to the conclusion that its my blit routines which sucks big time.. I have thought implementing RLE sprites.. but should that really be necessary in these days? I mean its only a simple 2d tile scroller.. should it not be possible to update a 640x480 8 bit display in realtime? GTA does it in 24 bit.. here''s my blit routine: for (y1 = 0; y1 < height; y1++ ) { for (x1 = 0; x1 < width; x1++ ) { fx = x+x1; fy = y+y1; if( (fx>=0) && (fx<640) && (fy>=0) && (fy<480)) where[((fy << 9)+(fy << 7))+fx] = *image; image++; } } the if is the clipping.. the scrolling relies on it where is a pointer to my frame buffer.. I use the shifting instead of (640*Y)+X - although I saw no speed up after I implemented it. image is a pointer to the tile data (32x32 bytes) can anyone help? pleeeeeeeeas? :-)
zenic
zenic
i would recommend that you get rid of linear frame access!

more and more video cards have hardware blitters. if you set up your tiles as surfaces and use the directdraw functions to blit you will take advantage of that.

with linear buffer access you will always be limited to the speed at which you can pump the information to the card.

the following can speed up your routine you have above: (note that ddsd.lPitch is the pitch)
[source]
int ly = y+y1; // lower y
if (ly > 480) ly = 480;
int rx = x+x1; // right x
if (rx > 640) rx = 640;

LPBYTE p = where+(y*ddsd.lPitch)+x; // start of placement

for (; y{
memcpy(where, image, rx-x);
where += ddsd.lPitch;
}
smokes
smokes
zenic: thanks :-)
I have kindda solved the problem.. after I wrote the message I figured out that it was going slow because I let the CPU do all the drawing/blitting work instead of just calculating tile positions etc..

zenic: I don''t like direct draw very much.. hate the fact that I have to lock objects to draw etc.. PTC is a wrapper.. and I just figured out how I can use to blit and use hardware acceleration too.. but I will soon have to dump PTC cause its blitting routines have NO support for transparent bitmaps.. what a ripoff :-)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.