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

spritemanager.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           spritemanager.h  -  description
00003                              -------------------
00004     begin                : Fri Mar 7 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 
00018 #ifndef __SPRITEMANAGER_H__
00019 #define __SPRITEMANAGER_H__
00020 
00021 #include <stdlib.h>
00022 #include "RotateImage.h"
00023 #include "Fxp.h"
00024 #include "rect.h"
00025 #include "rectlist.h"
00026 #include "sprite.h"
00027 #include "spritelist.h"
00028 #include "ticktimer.h"
00029 #include "spriteloader.h"
00030 
00031 #include <SDL/begin_code.h>
00032 
00035 
00045 #define MAX_RECTS       512
00046 
00047 #define SM_NONE         0x0000
00048 
00049 #define SM_RUNNING      0x0001
00050 
00051 #define SM_TOTALREDRAW  0x0002
00052 
00053 #define SM_PAUSED       0x0004
00054 
00055 #define SM_OWNBG        0x0008
00056 
00057 #define SM_DOUBLEBUF    0x0010
00058 
00059 
00061 enum SMRun_Return
00062 {
00064   SMRUN_OK=0,
00066   SMRUN_TIMESTEP
00067 };
00068 
00076 class DECLSPEC SpriteManager
00077 {
00078 public:
00086   SpriteManager(Uint16 w, Uint16 h, Uint8 depth, Uint32 vflags);
00088   SpriteManager(Uint16 flags=0,SDL_Surface *screenin=NULL, const char *bgnd=NULL);
00090 
00097   bool AddSprite(Sprite *spr);
00099   bool RemoveSprite(Sprite *spr);
00101   
00103   void SendEvent(int code, void *data1=NULL, void *data2=NULL);
00104 
00114   virtual int Event(int code, void *data1, void *data2);
00116   virtual void Idle();
00118   virtual void Handler(SDL_Event *event);
00120   virtual ~SpriteManager();
00122 
00131 
00133   SMRun_Return Run(Sint32 frametick);
00135   SMRun_Return Run(Sint32 frametick, Sint32 gametick);    
00136   
00138   void Preserve();
00140   void Move(Sint32 dtick);
00142   void Draw();  
00144   inline void Update()
00145   {
00146     if(flag&SM_DOUBLEBUF) /* SM_DOUBLEBUF forces use of SDL_Flip()  */
00147       SDL_Flip(screen);
00148     else                  /* Otherwise, do partial screen update    */
00149       rects.Update(screen);
00150     
00151     rects.Clear();
00152   }
00154 
00160 
00162   inline void Redraw()
00163   { flag|=SM_TOTALREDRAW; }    
00164 
00166   inline int Paused()
00167   { return(flag&SM_PAUSED);  }
00168 
00170   inline void Pause()
00171   {
00172     Lock();
00173     flag|=SM_PAUSED;
00174     Unlock();
00175   }
00176 
00178   inline void Unpause()
00179   {
00180     Lock();
00181     flag&=~SM_PAUSED;
00182     Unlock();
00183   }  
00185 
00193   SDL_Surface *CheckOutBG();    
00195   bool CheckInBG(SDL_Surface *bg_in);
00197   void DrawOnBG(SDL_Surface *src, SDL_Rect *srcrect, SDL_Rect *destrect);  
00199 
00201   inline bool AddUpdateRect(SDL_Rect &r)
00202   {
00203     bool retval;
00204 
00205     Lock();
00206     retval=rects.Push(Rect(r));
00207     Unlock();
00208 
00209     return(retval);
00210   }
00211 
00212 protected:
00213 
00215   inline void Lock()
00216   { SDL_mutexP(lock); }
00218   inline void Unlock()
00219   { SDL_mutexV(lock); }
00220 
00231   void SimpleBlit();
00233   void FastBlit();
00235   void QuadBlit();
00237 
00239   Uint16       flag;
00241   SDL_mutex   *lock;
00243   SDL_Surface *screen;
00245   SDL_Surface *bg;
00247   SpriteList   sprites;
00249   RectList     rects;
00250 };
00251 
00254 #include <SDL/close_code.h>
00255 
00256 #endif/*__SPRITEMANAGER_H__*/

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