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

aedUpdateManager.h

00001 
00002 /*
00003  * The aedUpdateManager class
00004  * This class controls how everything is updated on screen
00005  * Initial design by Eduardo B. Fonseca <ebf@aedsolucoes.com.br>
00006  * With lots of code from Paul H. Liu <paul@theV.net>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Library General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Library General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Library General Public
00019  * License along with this library; if not, write to the Free
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00024 #ifndef AEDUPDATEMANAGER_H
00025 #define AEDUPDATEMANAGER_H
00026 
00027 #include <vector>
00028 #include "SDL.h"
00029 #include "aedRect.h"
00030 
00031 /****************************************************************************************/
00032 // WARNING: This all has to be converted to template-using functions.
00033 // THIS IS ALL TEMPORARY
00034 
00035 typedef struct Rect_Set Rect_Set;
00036 typedef struct Rect_Clips
00037 {
00038     int length;
00039     SDL_Rect rects;
00040 
00041 } Rect_Clips;
00042 
00043 #define _VERTICAL       0
00044 #define _HORIZONAL      1
00045 
00046 #define _NOT_FOUND_ERR  -1
00047 #define _NO_ERR         0
00048 
00049 #define ABS(x) ((x) > 0 ? (x) : -(x))
00050 #define MAX(x, y) ((x) > (y) ? (x) : (y))
00051 
00052 #define RD(value, mask) ((value) & ~(mask))     // round down a value
00053 #define RU(value, mask) (((value) + (mask)) & ~(mask))  // round up a value
00054 
00055 // range_type is basically a dynamic sorted (ascending order) array that
00056 // grows exponentially. It is used to implement grid X/Y coordinates, and to
00057 // represent marked cells.
00058 typedef struct _range_type
00059 {
00060     int length, size;           // length refers to array, size to malloc
00061     int *points;
00062 } range_type;
00063 
00064 // a RectangleSet is just a grid of X/Y coordinates and marked cells.
00065 struct Rect_Set
00066 {
00067     range_type xs, ys, ms;      // the grid and marked cells.
00068 
00069     range_type xsum, ysum;      // this is used as a hash value of row's x
00070     // coordinates, and column's y coordinates
00071 
00072     Uint16 bits_mask;           // how many bits to mask off the X/Y values.
00073     // This is to improve efficiency by compromising
00074     // accuracy over large scale grids.
00075 };
00076 
00077 
00078 class DLLEXPORT aedUpdateManager
00079 {
00080   public:
00081     bool addRect(aedRect & position);
00082     bool addRect(SDL_Rect & rect);
00083     bool purge(void);
00084     void printRects(void);
00085     bool updateRects(SDL_Surface * surf);
00086 
00087   private:
00088       friend class DLLEXPORT aedApp;
00089 
00090       aedUpdateManager();
00091      ~aedUpdateManager();
00092     void operator=(const aedUpdateManager &);
00093       aedUpdateManager(const aedUpdateManager &);
00094 
00095     Sint32 checkRectForIntersections(aedRect & position);
00096     bool checkForIntersection(aedRect & rect1, aedRect & rect2);
00097 
00098     // TODO remove this all and convert this all to template-using functions
00099     Rect_Set *new_rects(int bits);
00100     void free_rects(Rect_Set * rects);
00101     void clear_rects(Rect_Set * rects);
00102     void rects_union(Rect_Set * rects, Sint16 x, Sint16 y, Uint16 w, Uint16 h);
00103     void rects_subtract(Rect_Set * rects, Sint16 x, Sint16 y, Uint16 w,
00104                         Uint16 h);
00105     void rects_intersect(Rect_Set * rects, Sint16 x, Sint16 y, Uint16 w,
00106                          Uint16 h);
00107     int rects_intersects(Rect_Set * rects, Sint16 x, Sint16 y, Uint16 w,
00108                          Uint16 h);
00109     Rect_Clips *rects_clip(Rect_Set * rs, SDL_Rect * r);
00110     void rects_print(Rect_Set * rs);
00111     int range_search(range_type * range, int value);
00112     void range_inserti(range_type * range, int pos, int value);
00113     int range_insert(range_type * range, int value, int *index);
00114     void range_removei(range_type * range, int pos);
00115     int range_remove(range_type * range, int value);
00116     int v_line_insert(Rect_Set * rs, int v);
00117     void v_line_remove(Rect_Set * rs, int v);
00118     int h_line_insert(Rect_Set * rs, int v);
00119     void h_line_remove(Rect_Set * rs, int v);
00120     int v_concentrate(Rect_Set * rs);
00121     int h_concentrate(Rect_Set * rs);
00122     void concentrate(Rect_Set * rs);
00123 
00124   private:
00125       std::vector < aedRect > m_Rects;
00126     // Convert this all to native, template-using functions
00127     Rect_Clips *m_Clips;
00128     Rect_Set *m_RectSet;
00129 };
00130 
00131 #ifdef AEDGUI
00132 extern DLLEXPORT aedUpdateManager *pUpdateMgr;
00133 #endif
00134 
00135 #endif

Generated on Mon Mar 1 19:56:18 2004 for aedGUI by doxygen 1.3.6