Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

blitter.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           blitter.cpp  -  description
00003                              -------------------
00004     begin                : Thu Oct 9 2003
00005     copyright            : (C) 2003 by Tyler Montbriand
00006     email                : tsm@accesscomm.ca
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 #include "spritemanager.h"
00018 
00025 
00026 #define XQUADS 8
00027 #define YQUADS 8
00028 
00029 Uint8 Quadrants[YQUADS][XQUADS];
00030 
00035 void SpriteManager::QuadBlit()
00036 {
00037   Sprite *spr=NULL;
00038   int x=-1,y=-1;
00039   int quadw=screen->w/XQUADS;
00040   int quadh=screen->h/YQUADS;
00041   Rect quadrect(0,0,quadw,quadh);
00042 
00043   memset(Quadrants,0,sizeof(Quadrants));
00044 
00045   spr=sprites.Head();
00046   while(spr!=NULL)
00047   {
00048     if(spr->Moved()||spr->Expired())
00049     {
00050       Rect r=spr->CurRect();
00051       Rect prev=spr->PrevRect();
00052 
00053       if(!r.Merge(prev))
00054       {
00055         for(y=prev.y/quadh;  y<=(prev.y+prev.h)/quadh; y++)
00056           for(x=prev.x/quadw;  x<=(prev.x+prev.w)/quadw; x++)
00057             Quadrants[y][x]=1;
00058       }
00059 
00060       for(y=r.y/quadh;  y<=(r.y+r.h)/quadh; y++)
00061         for(x=r.x/quadw;  x<=(r.x+r.w)/quadw; x++)
00062           Quadrants[y][x]=1;
00063     }
00064 
00065     if(spr->Expired())
00066     {
00067       Sprite *tmp=spr->next;
00068       sprites.Extract(spr);
00069       
00070       if(spr->Deleteable()) delete spr;
00071       
00072       spr=tmp;      
00073     }
00074     else
00075       spr=spr->next;
00076   }
00077 
00078   for(y=0; y<YQUADS; y++)
00079     for(x=0; x<XQUADS; x++)
00080       if(Quadrants[y][x])
00081       {
00082         quadrect.MoveTo(quadw*x,quadh*y);        
00083         SDL_BlitSurface(bg,&quadrect,screen,&quadrect);
00084         rects.Push(quadrect);
00085       }
00086 
00087   for(spr=sprites.Head(); spr!=NULL; spr=spr->next)
00088   {
00089     if(spr->Expired()) continue;
00090     
00091     Rect r=spr->CurRect();    
00092     for(y=r.y/quadh;  y<=(r.y+r.h)/quadh; y++)
00093       for(x=r.x/quadw;  x<=(r.x+r.w)/quadw; x++)
00094         if(Quadrants[y][x])
00095         {
00096           quadrect.MoveTo(quadw*x,quadh*y);
00097           spr->Draw(screen,quadrect);
00098         }
00099   }  
00100 }
00101 
00107 void SpriteManager::SimpleBlit()
00108 {
00109   Sprite *spr=NULL;
00110   rects.Clear();
00111   rects.Push(Rect(0,0,bg->w,bg->h));
00112 
00113   SDL_BlitSurface(bg,NULL,screen,NULL);
00114 
00115   spr=sprites.Head();
00116 
00117   while(spr!=NULL)
00118   {
00119     if(spr->Expired())
00120     {
00121       Sprite *tmp=spr->next;
00122       if(sprites.Extract(spr))
00123       {
00124         if(spr->Deleteable()) delete spr;
00125         spr=tmp;
00126       }
00127     }
00128     else
00129     {
00130       spr->Draw(screen);
00131       spr=spr->next;
00132     }
00133   }
00134 }
00135 
00136 
00142 void SpriteManager::FastBlit()
00143 {
00144   Sprite *spr=NULL;
00145 
00146   spr=sprites.Head();
00147   while(spr!=NULL)
00148   {
00149     Rect rect,prev;
00150     rect=spr->CurRect();
00151     prev=spr->PrevRect();
00152 
00153     if(rect.Merge(prev))
00154     {
00155       SDL_BlitSurface(bg,&rect,screen,&rect);
00156       rects.Push(rect);
00157     }
00158     else
00159     {
00160       SDL_BlitSurface(bg,&rect,screen,&rect);
00161       SDL_BlitSurface(bg,&prev,screen,&prev);
00162       rects.Push(rect);
00163       rects.Push(prev);
00164     }
00165 
00166     spr=spr->next;
00167   }
00168 
00169   spr=sprites.Head();
00170   while(spr!=NULL)
00171   {
00172     if(spr->Expired())
00173     {
00174       Sprite *tmp=spr->next;
00175       if(sprites.Extract(spr))
00176       {
00177         if(spr->Deleteable()) delete spr;
00178       }
00179 
00180       spr=tmp;
00181     }
00182     else
00183     {
00184       spr->Draw(screen);
00185       spr=spr->next;
00186     }
00187   }
00188 }

Generated on Sat Oct 11 13:19:25 2003 for Spritelib by doxygen 1.3.4