View Single Post
Old 27 May 2019, 20:36   #2
balrogsoft
Registered User
 
Join Date: May 2006
Location: Spain
Age: 42
Posts: 76
I got the answer, one view, two bitmaps, creating two copperlist for each bitmap and changing the copper list of the view every frame, as explained here, good reading indeed:


https://wiki.amigaos.net/wiki/Classi...ffered_Display


Here is my implementation of this double buffer technique, it works on AOS 2.0 running at 50 fps.Anyway, any attempt to call ScrollVPort decreases performance at 25 fps, so this technique will not give you 50 fps for games that use scroll, I do not know if this is the best you can get using the system functions.

Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <exec/execbase.h>
#include <exec/memory.h>  
#include <graphics/gfxbase.h>
#include <devices/timer.h>

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/timer.h>   


#define WIDTH   320
#define HEIGHT  256*2+64
#define DEPTH   5

extern struct ExecBase *SysBase;
struct GfxBase *GfxBase;
struct Library *CyberGfxBase= NULL;
struct Library *TimerBase;      /* to get at the time comparison functions */
static struct IORequest timereq;

ULONG timer(void)
{
  static struct timeval tt;
  struct timeval a, b;

  GetSysTime(&a);
  b = a;
  SubTime(&b, &tt);
  tt = a;

  return b.tv_secs*1000 + b.tv_micro/1000;
}

int main(void)
{
    struct DimensionInfo dimsinfo;

        struct View view, *oldview=NULL; 
        struct ViewPort viewPort;

        struct BitMap bitMap1;
        struct BitMap bitMap2;
        struct RastPort rastPort1;
        struct RastPort rastPort2;
        struct RastPort *rastPort;

        struct RasInfo rasInfo;

        struct cprlist *LOCpr1;
        struct cprlist *SHCpr1;
        struct cprlist *LOCpr2;
        struct cprlist *SHCpr2;
        
        WORD fps=0;
        WORD fps_val=0;
        ULONG mtimer = 0, elapsed=0, depth;
    LONG oscan_height,frame=0;
        UBYTE numstr[16];


    OpenDevice("timer.device", 0, &timereq, 0);
        TimerBase = timereq.io_Device;
        
    GfxBase = (struct GfxBase *) OpenLibrary( "graphics.library", 0 );
                    
    GetDisplayInfoData(FindDisplayInfo(LORES_KEY), (UBYTE *)&dimsinfo,
                               sizeof(struct DimensionInfo), DTAG_DIMS,
                               NULL);
                               
    oscan_height = dimsinfo.MaxOScan.MaxY - dimsinfo.MaxOScan.MinY + 1;

        oldview = GfxBase->ActiView;

        InitView(&view); 

        InitBitMap(&bitMap1, DEPTH, WIDTH, HEIGHT);
            
        InitBitMap(&bitMap2, DEPTH, WIDTH, HEIGHT);

        for (depth=0; depth<DEPTH; depth++)
        {
            bitMap1.Planes[depth] = (PLANEPTR)AllocRaster(WIDTH, HEIGHT);
            bitMap2.Planes[depth] = (PLANEPTR)AllocRaster(WIDTH, HEIGHT);
        }

        
        InitRastPort(&rastPort1);
        rastPort1.BitMap = &bitMap1;
        SetRast(&rastPort1, 0);
        
        InitRastPort(&rastPort2);
        rastPort2.BitMap = &bitMap2;
        SetRast(&rastPort2, 0);
        
        rasInfo.BitMap = &bitMap1;
        rasInfo.RxOffset = 0;
        rasInfo.RyOffset = 0;
        rasInfo.Next = NULL;

        InitVPort(&viewPort);
        view.ViewPort = &viewPort;
        viewPort.RasInfo = &rasInfo;
        viewPort.DWidth = WIDTH;
        viewPort.DHeight = HEIGHT;

        MakeVPort(&view, &viewPort);

        MrgCop(&view);
        
        LOCpr1 = view.LOFCprList;
        SHCpr1 = view.SHFCprList;
        
        
        view.LOFCprList = 0;
        view.SHFCprList = 0;
        
        rasInfo.BitMap = &bitMap2;
        

        MakeVPort(&view, &viewPort);

        MrgCop(&view);
        
        LOCpr2 = view.LOFCprList;
        SHCpr2 = view.SHFCprList;
        
        LoadView(&view);

        elapsed = timer();
    while((*(UBYTE *)0xBFE001) & 0x40)
    {  
        WaitTOF();
                if (frame==0) {
                    view.LOFCprList = LOCpr1;
                    view.SHFCprList = SHCpr1;
                    rastPort = &rastPort1;
                }
                else {
                    view.LOFCprList = LOCpr2;
                    view.SHFCprList = SHCpr2;
                    rastPort = &rastPort2;
                }
                        
                elapsed = timer();
                
                mtimer+=elapsed;
                if (mtimer>1000)
                {
                        fps_val = fps;
                        fps = 0;
                        mtimer = mtimer - 1000;
                }
                
                sprintf(numstr, "%d fps", fps_val);
                                        
                SetAPen(rastPort, 31);
                Move(rastPort, 10, 10);
                Text(rastPort, numstr, strlen(numstr));
                
                LoadView(&view);
                
        frame ^= 1;
                fps++;
          
    }; 

        LoadView(oldview);
        
        WaitTOF();
        
        FreeCprList(LOCpr1);
        FreeCprList(LOCpr2);
        FreeCprList(SHCpr1);
        FreeCprList(SHCpr2);
        
        FreeVPortCopLists(&viewPort); 

        for(depth=0; depth<DEPTH; depth++)
        {
            if (bitMap1.Planes[depth])
                FreeRaster(bitMap1.Planes[depth], WIDTH, HEIGHT);
            if (bitMap2.Planes[depth])
                FreeRaster(bitMap2.Planes[depth], WIDTH, HEIGHT);
        }
    CloseDevice(&timereq);
        
        
    if(GfxBase)
        CloseLibrary((struct Library *)GfxBase);
        
    return 0;
}

Last edited by balrogsoft; 27 May 2019 at 21:27.
balrogsoft is offline  
 
Page generated in 0.04946 seconds with 11 queries