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 #ifndef KYRA_ACTION_INCLUDED
00033 #define KYRA_ACTION_INCLUDED
00034
00035 #ifdef _MSC_VER
00036 #pragma warning( disable : 4530 )
00037 #pragma warning( disable : 4786 )
00038 #endif
00039
00040 #include <string>
00041 #include <vector>
00042
00043 #include "SDL.h"
00044 #include "rle.h"
00045
00046 class KrCanvasResource;
00047 class KrEncoder;
00048 class KrCollisionMap;
00049
00050
00055 class KrAction
00056 {
00057 public:
00058
00059
00060
00061 KrAction( const std::string& name );
00062
00064 KrAction( SDL_RWops* data );
00065
00066 ~KrAction();
00067
00069 const std::string& Name() const { return name; }
00071 U32 Id() const { return id; }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 void Draw( KrPaintInfo* paintInfo,
00083 int frame,
00084 const KrMatrix2& matrix,
00085 const KrColorTransform& cForm,
00086 const grinliz::Rectangle2I& clip );
00087
00089 int NumFrames() const { return numFrames; }
00090
00092 const KrRle& Frame( int i ) const { GLASSERT( i >= 0 );
00093 GLASSERT( i < numFrames );
00094 return frame[ i ]; }
00095
00096
00097
00098 KrRle* GetFrame( int i ) const { GLASSERT( i >= 0 );
00099 GLASSERT( i < numFrames );
00100 return &frame[ i ]; }
00101
00102 bool HitTestTransformed( int frame, int x, int y, int hitFlags );
00103
00104
00105 void CacheScale( GlFixed xScale, GlFixed yScale );
00106 bool IsScaleCached( GlFixed xScale, GlFixed yScale );
00107 void FreeScaleCache();
00108 KrCollisionMap* GetCollisionMap( GlFixed xScale, GlFixed yScale, int frame );
00109
00110 void AddFrame() { GrowFrameArray( numFrames + 1 ); }
00111
00115 KrCanvasResource* CreateCanvasResource( int frame, int* hotx, int* hoty );
00116
00117 void CalculateBounds( int frame, const KrMatrix2& xForm, grinliz::Rectangle2I* bounds );
00118
00119 void Save( KrEncoder* encoder );
00120
00121 private:
00122 struct CachedBlock
00123 {
00124 GlFixed xScale,
00125 yScale;
00126 KrRle** frame;
00127
00128 bool operator==( const CachedBlock& ) { GLASSERT( 0 ); return false; }
00129 };
00130 void GrowFrameArray( int newSize );
00131
00132 std::vector< CachedBlock > cache;
00133
00134 std::string name;
00135 U32 id;
00136 KrRle* frame;
00137 int numFrames;
00138 };
00139
00140
00141 #endif