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 ENCODER_INCLUDED
00070 #define ENCODER_INCLUDED
00071
00072 #include "SDL.h"
00073 #include "../tinyxml/tinyxml.h"
00074 #include "../util/gltypes.h"
00075 #include "../engine/color.h"
00076 #include "../util/gllist.h"
00077 #include "kyraresource.h"
00078 #include "namefield.h"
00079 #include "vault.h"
00080
00081
00082 class KrRle;
00083 class KrCanvasResource;
00084 class KrPixelBlock;
00085 class KrCachedWrite;
00086 class KrConsole;
00087 class KrEngine;
00088
00089
00090 typedef SDL_Surface* (*ImageLoaderFunc)( const char* );
00091
00092
00093 class KrEncoder
00094 {
00095 public:
00096 KrEncoder( SDL_RWops* stream );
00097
00098
00099 bool StartDat();
00100
00101
00102
00103
00104
00105
00106 bool ProcessDoc( const TiXmlDocument& doc,
00107 KrEngine* engine,
00108 KrConsole* output );
00109
00110
00111 bool EndDat();
00112
00113 void WriteHeader( const char* name,
00114 FILE* stream,
00115 const char* prefix );
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 enum
00128 {
00129 RGBA,
00130 UpperLeft,
00131 LowerLeft,
00132 UpperRight,
00133 LowerRight
00134 };
00135
00136 struct Transparent
00137 {
00138 int type;
00139 KrRGBA rgba;
00140 };
00141
00142
00143
00144
00145
00146
00147
00148 static void SetImageLoader( ImageLoaderFunc i ) { ImageLoader = i; }
00149
00150 static SDL_Surface* Load32Surface( const char* filename,
00151 Transparent* transparent,
00152 int nTransparent,
00153 std::string* error );
00154
00155
00156
00157
00158
00159 static KrCanvasResource* Load32Canvas( const char* filename,
00160 const KrRGBA* transparent,
00161 int nTransparent,
00162 std::string* error );
00163
00164
00165
00166
00167
00168 static KrFontResource* CreateFixedFontResource( const char* resourceName,
00169 const U8* buffer,
00170 int bufferSize );
00171
00172
00173
00174 void StartTag( U32 tag );
00175 void EndTag();
00176 void WriteCached( const std::string& name ) { cachedWrite.Write( name ); }
00177 SDL_RWops* Stream() { return stream; }
00178 void AddCount( U32 _numLines, U32 _numSegments, U32 _numRGBA )
00179 {
00180 GLASSERT( _numRGBA >= _numSegments );
00181
00182 numLine += _numLines;
00183 numSegment += _numSegments;
00184 numRGBA += _numRGBA;
00185 GLASSERT( numRGBA >= numSegment );
00186
00187 }
00188 void KrEncoder::Save();
00189
00190 KrResourceVault* GetVault() { return &vault; }
00191
00192 private:
00193 static ImageLoaderFunc ImageLoader;
00194
00195
00196
00197 enum
00198 {
00199 TYPE_NONE,
00200 TYPE_SPRITE,
00201 TYPE_TILE,
00202 TYPE_FONT
00203 };
00204
00205 enum
00206 {
00207 SUBTYPE_FIXEDFONT,
00208 SUBTYPE_SFONT,
00209 };
00210
00211 struct AllInfo
00212 {
00213 AllInfo() : type( 0 ),
00214 subType( 0 ),
00215 name( "NONE" ), action( "NONE" ),
00216 useEntireImage( false ),
00217 frameCount( 0 ),
00218 x( 0 ), y( 0 ),
00219 width( 0 ), height( 0 ),
00220
00221 hotx( 0 ), hoty( 0 ),
00222
00223 deltax( 0 ), deltay( 0 ),
00224 isoTargetWidth( 0 ),
00225 fontStart( 0 ),
00226 fontLength( 0 ),
00227 space( 0 ) { keyColor.Set( 0, 0, 0, 0 ); }
00228
00229 int type;
00230 int subType;
00231
00232 std::string name;
00233 std::string action;
00234
00235 bool useEntireImage;
00236 int frameCount;
00237 int x, y;
00238 int width, height;
00239 int hotx, hoty;
00240 int deltax, deltay;
00241 int isoTargetWidth;
00242 int fontStart;
00243 int fontLength;
00244 int space;
00245 KrRGBA keyColor;
00246 GlDynArray< int > rotation;
00247 };
00248
00249 void CalcAllInfo( TiXmlNode* node, AllInfo* info, SDL_Surface* );
00250
00251 void CreateIsoTile( KrPaintInfo* info,
00252 KrConsole* console,
00253 int x, int y,
00254 int width, int height,
00255 KrRle* rle,
00256 int isoIdealWidth,
00257 int rotation );
00258
00259 void IsoToSource( GlFixed x, GlFixed y, GlFixed isoWidth,
00260 GlFixed sourceW, GlFixed sourceH,
00261 GlFixed* sourceX, GlFixed* sourceY,
00262 int rotation, GlFixed increment );
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 bool EncodeSFontFrames( SDL_Surface* surface, const AllInfo& allInfo, KrConsole* console );
00276 bool EncodeFixedFontFrames( SDL_Surface* surface, const AllInfo& allInfo, KrConsole* console );
00277
00278
00279 bool EncodeSprite( SDL_Surface* surface, const AllInfo& allInfo, KrConsole* console );
00280 bool EncodeFont( SDL_Surface* surface, const AllInfo& allInfo, KrConsole* console );
00281 bool EncodeTile( SDL_Surface* surface, const AllInfo& allInfo, KrConsole* console );
00282
00283
00284 bool EncodeColorKey( SDL_Surface* surface, const AllInfo& allInfo, KrConsole* console );
00285
00286
00287 bool EncodeBinary( TiXmlElement* e, KrConsole* console );
00288 bool EncodeText( TiXmlElement* e, KrConsole* console );
00289
00290
00291 void PrintSprite( KrConsole*, const std::string& spriteName, const std::string& actionName,
00292 int frameNum, KrRle* rle );
00293 void PrintTile( KrConsole*, const std::string& tileName, KrTileResource* tile );
00294
00295 SDL_Surface* LoadSurface( TiXmlElement* definition, std::string* error );
00296
00297 U32 tagpos;
00298
00299
00300
00301 enum
00302 {
00303 SPRITE,
00304 TILE,
00305 ACTION,
00306 NUM_NAME_BINS,
00307 };
00308
00309 enum
00310 {
00311 DEFINITION,
00312 DIRECT
00313 };
00314
00315 struct Scan
00316 {
00317 Scan() { Init(); }
00318 void Init() { x = 0; y = 0; }
00319
00320 int x;
00321 int y;
00322 };
00323
00324 Scan scan;
00325
00326 int mode;
00327
00328
00329 int thisLine;
00330 int nextLine;
00331 int outputX;
00332 SDL_Surface* output;
00333
00334
00335 U32 numRGBA, numLine, numSegment;
00336 U32 numRlePos;
00337
00338 KrResourceVault vault;
00339
00340 KrCachedWrite cachedWrite;
00341 SDL_RWops* stream;
00342 };
00343
00344 #endif
00345