Vesa. Parallax scrolling.

This is a discussion on Vesa. Parallax scrolling. within the Game Programming forums, part of the General Programming Boards category; Hi. I would like to have a little suggestion. I have been writing a 2D tile engine for a platform ...

  1. #1
    r0x
    r0x is offline
    Registered User
    Join Date
    Jun 2002
    Posts
    5

    Question 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! ), but I've time to spend to do it!

    So ... please help me!

    Bye.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    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.

    Code:
    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.

  3. #3
    r0x
    r0x is offline
    Registered User
    Join Date
    Jun 2002
    Posts
    5
    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 ) referring to mapped screen memory:

    Code:
    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!
    Last edited by r0x; 06-09-2002 at 02:50 PM.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    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.

  5. #5
    r0x
    r0x is offline
    Registered User
    Join Date
    Jun 2002
    Posts
    5
    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.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    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:



    Code:
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scrolling background?
    By Deo in forum Game Programming
    Replies: 6
    Last Post: 06-09-2005, 05:40 PM
  2. Scrolling text in a DOS CONSOLE box
    By Blizzarddog in forum C++ Programming
    Replies: 4
    Last Post: 04-06-2004, 02:27 PM
  3. Scrolling Text
    By fushigidane in forum C++ Programming
    Replies: 4
    Last Post: 01-04-2004, 10:43 AM
  4. Scrolling
    By PJYelton in forum Windows Programming
    Replies: 10
    Last Post: 03-24-2003, 09:04 AM
  5. Bitmap scrolling with scroll bars
    By solar3147 in forum Windows Programming
    Replies: 0
    Last Post: 03-17-2003, 01:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21