src/map/tileitem.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  *****************************************************************************/
00019 
00020 #ifndef TILEITEM_H
00021 #define TILEITEM_H
00022 
00023 #include "graphic/surface.h"
00024 
00025 const Point2i CELL_SIZE(64, 64);
00026 
00027 #ifdef DEBUG
00028 //#define DBG_TILE
00029 #endif
00030 
00031 class TileItem
00032 {
00033 public:
00034   TileItem () {};
00035   virtual ~TileItem () {};
00036 
00037   bool IsEmpty ();
00038   virtual unsigned char GetAlpha(const Point2i &pos) = 0;
00039   virtual void Dig(const Point2i &position, const Surface& dig) = 0;
00040   virtual void Dig(const Point2i &center, const uint radius) = 0;
00041   virtual void MergeSprite(const Point2i &position, Surface& spr) {};
00042   virtual Surface GetSurface() = 0;
00043   virtual void Draw(const Point2i &pos) = 0;
00044   virtual bool IsTotallyEmpty() const = 0;
00045 #ifdef DBG_TILE
00046   virtual void FillWithRGB(Uint8 r, Uint8 g, Uint8 b) {};
00047 #endif
00048 };
00049 
00050 class TileItem_Empty : public TileItem
00051 {
00052 public:
00053   TileItem_Empty () {};
00054   ~TileItem_Empty () {};
00055 
00056   unsigned char GetAlpha (const Point2i &pos){return 0;};
00057   void Dig(const Point2i &position, const Surface& dig){};
00058   Surface GetSurface(){return *new Surface();};
00059   void Dig(const Point2i &center, const uint radius) {};
00060   void Draw(const Point2i &pos);
00061   bool IsTotallyEmpty() const {return true;};
00062 };
00063 
00064 class TileItem_AlphaSoftware : public TileItem
00065 {
00066   unsigned char* last_filled_pixel;
00067 
00068 public:
00069   bool need_check_empty;
00070   bool need_delete;
00071 
00072 TileItem_AlphaSoftware(const Point2i &size);
00073   ~TileItem_AlphaSoftware();
00074 
00075   unsigned char GetAlpha(const Point2i &pos);
00076   void Dig(const Point2i &position, const Surface& dig);
00077   void Dig(const Point2i &center, const uint radius);
00078   void MergeSprite(const Point2i &position, Surface& spr);
00079   void Draw(const Point2i &pos);
00080 
00081   bool NeedDelete() const {return need_delete; };
00082   void CheckEmpty();
00083   void ResetEmptyCheck();
00084 
00085   bool IsTotallyEmpty() const {return false;};
00086 
00087 private:
00088   TileItem_AlphaSoftware(const TileItem_AlphaSoftware &copy);
00089   unsigned char (TileItem_AlphaSoftware::*_GetAlpha)(const Point2i &pos);
00090   unsigned char GetAlpha_Index0(const Point2i &pos);
00091   inline unsigned char GetAlpha_Index3(const Point2i &pos);
00092   inline unsigned char GetAlpha_Generic(const Point2i &pos);
00093   Surface GetSurface();
00094 
00095   void Empty(const int start_x, const int end_x, unsigned char* buf, const int bpp);
00096   void Darken(const int start_x, const int end_x, unsigned char* buf, const int bpp);
00097 
00098   Point2i m_size;
00099   Surface m_surface;
00100 
00101 #ifdef DBG_TILE
00102   void FillWithRGB(Uint8 r, Uint8 g, Uint8 b);
00103 #endif
00104 };
00105 
00106 #endif

Generated on Mon Jan 1 13:10:58 2007 for Wormux by  doxygen 1.4.7