View Full Version : Vesa. Parallax scrolling.
Hi.
I would like to have a little suggestion. I have been writing a 2D tile engine for a platform game for 2-3 months, and I learned 13h and then Mode X, but now I'm getting into Vesa high-resolution modes instead of low-res 320x200 or annoying tweaked planar modes.
I'm working on a Pentium Pro 150 MHz, and I'm using the linear frame buffer Vesa 2.0 provides. The screen resolution is 640x480, 256 colours.
Here is my question: I have to do parallax scrolling, but I don't know what could be the best choice between page flipping and double buffering. I'm in trouble because I have a 3-layers scrolling, and I have to flush them every tile-map movement. My goal is to write a Sonic-like game (hm, AMBITIOUS! :D), but I've time to spend to do it!
So ... please help me! :)
Bye.
Bubba
06-08-2002, 08:51 PM
Well Im not sure that you can page flip in those modes. They take up a lot of memory in themselves so there may not be any extra room in the VRAM for page flipping. You can use double buffering, but don't use memcpy. It only uses bytes on most compilers and this is slow in hi-res hi-color modes.
Here is a 32-bit memcpy written in MASM source:
size is specified in bytes not DWORDS. I could write another one that is specified in DWORDs but converting from bytes to DWORDS is trivial and it makes the function easier to use to specify the length in bytes.
This uses the ARG directive which might be slower - you don't have to use the ARG directive just make sure you know where on the stack each parameter is.
memcpy32 proc
ARG source:DWORD,dest:DWORD,size:DWORD
push bp
mov bp,sp ;must do this
push ds ;preserve ds
push edi ;preserve edi
push esi ;preserve esi
cld ;set direction flag
lds esi,[source] ;load full pointer source into DS:ESI
les edi,[dest] ;load full pointer dest into ES:EDI
mov ecx,[size] ;load size in ecx
shr ecx,2 ;convert to DWORDs
rep movsd ;do the copy operation
pop esi ;restore esi
pop edi ;restore edi
pop ds ;restore ds
pop bp ;restore bp
ret ;return to caller
memcpy32 endp
If this does not work, PM me on the board because I have one that does. I just wrote this off the top of my head here so I'm not guaranteeing there are no errors. But I don't want to frustrate you so if there are problems simply PM me and I will get you a copy that works.
This will copy extremely fast since the default data fetch for modern CPUs is 32-bits. I've used this and it works very well for full screen 16 and 32-bit memory copies and double buffering or back buffering. It's not as fast as page flipping but it's the next best thing to it.
Thanks a lot for your interest! :)
However, the problem isn't copying memory. This is my routine in C++, and it's pretty close to yours, where [eax+disp] expressions are class members (fuc*ing WASM :D) referring to mapped screen memory:
void Vesa::Flush() const
{
WaitRetrace();
__asm
{
mov esi, dword ptr [eax+24]
mov edi, dword ptr [eax+20]
mov ecx, dword ptr [eax+16]
shr ecx, 2
cld
rep movsd
}
}
Then I noticed that page flipping is available for my 2 MB Matrox too, and I think I will use that. ;)
Now my problem is HOW to perform a FAST 3-layers scrolling on a Pentium Pro 150, DOS 32-bit. I know how to do it, but it's slOOOw!
So can anyone tell me some common technique for parallax scrolling? Or any good resource? I've been googl-ing around with this, and didn't found what I was exactly looking for. Incredible? Maybe...
So please help me! :(
Bye!
Bubba
06-09-2002, 04:10 PM
Well if you have 640x480x16 bit that is
640x480*2 bytes for page flipping. Basically that is 1.2MB or so of video memory that you need to page flip. This is trivial in DirectX, but I don't know how to do it in DOS.
I have 640x480x8, and I know how to do page flipping in VESA. I need some suggestion on how to do a good 3-layers parallax.
Bubba
06-10-2002, 05:39 PM
Well first decide what your layers will be.
For instance:
Layer 1 - Sky background
Layer 2 - Level graphics
Layer 3 - Sprites
Probably a tile based approach is best. In order to do this you must have some code that will clip bitmaps at the edges of the screen. I have an assembly functions that does this automatically and also accounts for transparency - PM me if you are interested in it.
the code would be something like this:
int tile_x=0,tile_y=0;
int world_x=0,world_y=0;
int screen_x=0,screen_y=0;
int offset_x,offset_y;
while (screen_y<max_y)
{
while (screen_x<max_x)
{
//Draw Tile[ tile_x][tile_y] at
//(screen_x+offset_x,screen_y+offset_y)
screen_x+=Tile_Width;
tile_x++;
}
screen_x=0;
screen_y+=Tile_Height;
tile_y++;
tile_x=0;
}
The offset_x and offset_y are for smooth pixel based scrolling.
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.