00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #ifndef KYRA_RLE_INCLUDED
00070 #define KYRA_RLE_INCLUDED
00071
00072 #include <stdlib.h>
00073
00074 #include "../util/gltypes.h"
00075 #include "../util/gldebug.h"
00076 #include "../engine/krmath.h"
00077 #include "../util/glmemorypool.h"
00078 #include "../util/glbitstream.h"
00079 #include "SDL.h"
00080 #include "painter.h"
00081
00082 class KrCanvasResource;
00083 class KrTexture;
00084 class KrCollisionMap;
00085
00086
00087 class KrRleSegment
00088 {
00089 friend class KrRle;
00090 public:
00091 KrRleSegment() : start( 0 ), end( 0 ), rgba( 0 ) {}
00092 ~KrRleSegment();
00093
00094 void Clear() { start = 0; end = 0; rgba = 0; }
00095
00096 U32 Alpha() { return flags.IsSet( ALPHA ); }
00097 U16 Start() { return start; }
00098 U16 End() { return end; }
00099 U16 Len() { return end - start + 1; }
00100
00101 KrRGBA* RGBA() { return rgba; }
00102 GlFlag<U32> Flags() { return flags; }
00103
00104
00105 bool Read( GlReadBitStream* reader, KrRGBA minColor, KrRGBA bits );
00106
00107
00108 bool Create( KrPaintInfo* surface,
00109 int x, int xMax, int y, int objectOriginX );
00110
00111 bool Write( GlWriteBitStream* writer, KrRGBA minColor, KrRGBA bits );
00112 void CalcRange( KrRGBA* minColor, KrRGBA* maxColor );
00113
00114 #ifdef DEBUG
00115 static U32 numRGBA;
00116 #endif
00117
00118 protected:
00119
00120
00121 enum {
00122 ALPHA = 0x01,
00123
00124
00125 BITS_USED = 3,
00126 MEMORYPOOL = 0x02,
00127 };
00128
00129 GlFlag<U32> flags;
00130 U16 start;
00131 U16 end;
00132 KrRGBA* rgba;
00133 };
00134
00135
00136 class KrRleLine
00137 {
00138 friend class KrRle;
00139 public:
00140 KrRleLine() : nSegments( 0 ), segment( 0 ) {}
00141 ~KrRleLine() { if (!flags.IsSet( MEMORYPOOL ) ) delete [] segment; }
00142
00143 void Clear() { nSegments = 0; segment = 0; }
00144 U32 Alpha() { return flags.IsSet( ALPHA ); }
00145 int NumSegments() { return nSegments; }
00146 KrRleSegment* Segment( int i ){ GLASSERT( i < nSegments );
00147 GLASSERT( segment );
00148 return &segment[i]; }
00149 int CalcSize() { if ( nSegments )
00150 return ( segment[ nSegments-1 ].End() - segment[ 0 ].Start() + 1 );
00151 else
00152 return 0; }
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 void DrawScaled(U8* target,
00164 KrPaintInfo* paintInfo,
00165 const KrRect& bounds,
00166 const KrRect& isect,
00167 const KrColorTransform& cForm,
00168 U32 xInc );
00169
00170
00171 bool Read( GlReadBitStream* writer, KrRGBA minColor, KrRGBA bits );
00172
00173
00174 bool Create( KrPaintInfo* surface, int x, int y, int w );
00175 bool Write( GlWriteBitStream* writer, KrRGBA minColor, KrRGBA bits );
00176 void CalcRange( KrRGBA* minColor, KrRGBA* maxColor );
00177
00178 protected:
00179 enum {
00180 ALPHA = 0x01,
00181 MEMORYPOOL = 0x02,
00182
00183 BITS_USED = 2
00184 };
00185
00186 GlFlag<U32> flags;
00187 int nSegments;
00188
00189 KrRleSegment* segment;
00190 };
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 class KrRle
00202 {
00203 public:
00204
00205
00206
00207 enum {
00208 ALPHA = 0x01,
00209 MEMORYPOOL = 0x02,
00210 };
00211
00212 KrRle() : line( 0 ), texture( 0 ), collisionMap( 0 )
00213 { deltaHotToOrigin.Set(); size.Set(); delta.Set(); }
00214 ~KrRle();
00215
00216 void Draw( KrPaintInfo* paintInfo,
00217 const KrMatrix2& matrix,
00218 const KrColorTransform& cForm,
00219 const KrRect& clipping,
00220 int openGLZ );
00221
00222
00223 bool Read( SDL_RWops* stream );
00224
00225
00226 bool Create( KrPaintInfo* surface,
00227 int x, int y, int width, int height,
00228 int hotx, int hoty,
00229 int deltax, int deltay );
00230
00231
00232 bool Write( SDL_RWops* stream );
00233
00234
00235 const KrVector2& StepSize() const { return delta; }
00236
00237 int Width() const { return size.x; }
00238 int Height() const { return size.y; }
00239
00240 bool Alpha() const { return flags.IsSet( ALPHA ); }
00241 const KrVector2& Delta() const { return delta; }
00242 KrVector2 Hotspot() const { KrVector2 hot = deltaHotToOrigin;
00243 hot.x = -hot.x; hot.y = -hot.y;
00244 return hot;
00245 }
00246
00247
00248
00249
00250 void CalculateBounds( const KrMatrix2& xForm,
00251 KrRect* bounds ) const;
00252
00253 bool HitTestTransformed( int x, int y, int hitFlags );
00254
00255
00256 void CountComponents( U32* numLines, U32* numSegments, U32* numRGBA );
00257
00258 KrCanvasResource* CreateCanvasResource( int* hotx, int* hoty );
00259 KrRle* CreateScaledRle( GlFixed xScale, GlFixed yScale, int* hotx, int* hoty );
00260 KrCollisionMap* GetCollisionMap( GlFixed xScale, GlFixed yScale );
00261
00262
00263
00264
00265 static void SetMemoryPools( GlLinearMemoryPool* _memoryPoolRgba,
00266 GlLinearMemoryPool* _memoryPoolLine,
00267 GlLinearMemoryPool* _memoryPoolSegment );
00268 static bool PoolOut();
00269
00270
00271
00272 static GlLinearMemoryPool* memoryPoolRGBA;
00273 static GlLinearMemoryPool* memoryPoolLine;
00274 static GlLinearMemoryPool* memoryPoolSegment;
00275
00276 protected:
00277 void DrawScaled( KrPaintInfo* paintInfo,
00278 const KrMatrix2& xForm,
00279 const KrColorTransform& cForm,
00280 const KrRect& clipping );
00281
00282 void DrawOpenGL( KrPaintInfo* paintInfo,
00283 const KrMatrix2& matrix,
00284 const KrColorTransform& cForm,
00285 const KrRect& clipping,
00286 int openGLZ );
00287
00288 GlFlag<U32> flags;
00289 KrRleLine* line;
00290 KrVector2 deltaHotToOrigin;
00291 KrVector2 size;
00292 KrVector2 delta;
00293 KrTexture* texture;
00294 KrCollisionMap* collisionMap;
00295 };
00296
00297
00298
00299 #endif