From e44c6b47f3c1cb6f57f076b6c7335773d88887fa Mon Sep 17 00:00:00 2001 From: mateuszb Date: Sun, 6 Jan 2008 18:07:03 +0000 Subject: [PATCH] - rename - partially written CCreatureAnimation --- CMT.cpp | 2 +- hch/CCreatureHandler.cpp | 272 +++++++++++++++++++++++++++++++++++++++ hch/CCreatureHandler.h | 38 ++++++ 3 files changed, 311 insertions(+), 1 deletion(-) diff --git a/CMT.cpp b/CMT.cpp index 0c73ed7f6..04b21051a 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -56,7 +56,7 @@ #endif #define CHUNK 16384 -const char * NAME = "VCMI 0.4 \"Vingilot\""; +const char * NAME = "VCMI 0.5 \"Tirion\""; SDL_Surface * ekran, * screen, * screen2; TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM; diff --git a/hch/CCreatureHandler.cpp b/hch/CCreatureHandler.cpp index 475edcabf..b8e7051d7 100644 --- a/hch/CCreatureHandler.cpp +++ b/hch/CCreatureHandler.cpp @@ -518,3 +518,275 @@ void CCreatureHandler::loadUnitAnimations() i+=2; } } + +int CCreatureAnimation::getType() const +{ + return type; +} + +void CCreatureAnimation::setType(int type) +{ + this->type = type; + curFrame = 0; +} + +CCreatureAnimation::CCreatureAnimation(std::string name) +{ + //load main file + std::string data2 = CGI->spriteh->getTextFile(name); + FDef = new unsigned char[data2.size()]; + for(int g=0; g=amp/2) + { + ret = ret-amp; + } + return ret; +} + +int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y) +{ + if(dest->format->BytesPerPixel<3) + return -1; //not enough depth + + int SIndex = curFrame++; //TODO: finish + + long BaseOffset, + SpriteWidth, SpriteHeight, //format sprite'a + LeftMargin, RightMargin, TopMargin,BottomMargin, + i, add, FullHeight,FullWidth, + TotalRowLength, // dlugosc przeczytanego segmentu + NextSpriteOffset, RowAdd; + std::ifstream Fdef; + unsigned char SegmentType, SegmentLength, BL, BR; + unsigned char * TempDef; //memory + + std::string FTemp; + + i=BaseOffset=SEntries[SIndex].offset; + int prSize=readNormalNr(i,4,FDef);i+=4; + int defType2 = readNormalNr(i,4,FDef);i+=4; + FullWidth = readNormalNr(i,4,FDef);i+=4; + FullHeight = readNormalNr(i,4,FDef);i+=4; + SpriteWidth = readNormalNr(i,4,FDef);i+=4; + SpriteHeight = readNormalNr(i,4,FDef);i+=4; + LeftMargin = readNormalNr(i,4,FDef);i+=4; + TopMargin = readNormalNr(i,4,FDef);i+=4; + RightMargin = FullWidth - SpriteWidth - LeftMargin; + BottomMargin = FullHeight - SpriteHeight - TopMargin; + + BMPHeader tb; + tb.x = FullWidth; + tb.y = FullHeight; + tb.dataSize2 = tb.dataSize1 = tb.x*tb.y; + tb.fullSize = tb.dataSize1+436; + tb._h3=tb.fullSize-36; + + //add = (int)(4*(((float)1) - ((int)(((int)((float)FullWidth/(float)4))-((float)FullWidth/(float)4))))); + add = 4 - FullWidth%4; + /*if (add==4) + add=0;*/ //moved to defcompression dependent block + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + int rmask = 0xff000000; + int gmask = 0x00ff0000; + int bmask = 0x0000ff00; + int amask = 0x000000ff; +#else + int rmask = 0x000000ff; + int gmask = 0x0000ff00; + int bmask = 0x00ff0000; + int amask = 0xff000000; +#endif + + //ret = SDL_CreateRGBSurface(SDL_SWSURFACE, FullWidth, FullHeight, 8, 0, 0, 0, 0); + //int tempee2 = readNormalNr(0,4,((unsigned char *)tempee.c_str())); + + int BaseOffsetor = BaseOffset = i; + + /*for(int i=0; i<256; ++i) + { + SDL_Color pr; + pr.r = palette[i].R; + pr.g = palette[i].G; + pr.b = palette[i].B; + pr.unused = palette[i].F; + (*(ret->format->palette->colors+i))=pr; + }*/ + + for (int i=0;i<800;i++) + fbuffer[i]=0; + + if (defType2==1) //as it should be allways in creature animations + { + if (add==4) + add=0; ////////was 3 + if (TopMargin>0) + { + for (int i=0;i0) + { + for (int j=0;j=SpriteWidth) + break; + } + BaseOffset+=SegmentLength+1;//// + TotalRowLength+=SegmentLength+1; + } + else + { + for (int k=0;k0) + { + for (int j=0;j0) + { + for (int j=0;j0) + { + for (int i=0;ipixels + dest->format->BytesPerPixel * ((i + y)*dest->pitch + j + x)) = FTemp[i*(FullWidth+add)+j]; + } + } + + return 0; +} diff --git a/hch/CCreatureHandler.h b/hch/CCreatureHandler.h index ffe3f1fb2..78489e6fb 100644 --- a/hch/CCreatureHandler.h +++ b/hch/CCreatureHandler.h @@ -4,6 +4,7 @@ #include #include #include +#include "CDefHandler.h" class CDefHandler; struct SDL_Surface; @@ -56,4 +57,41 @@ public: void loadUnitAnimations(); }; +class CCreatureAnimation +{ +private: + int totalEntries, DEFType, totalBlocks, fullWidth, fullHeight; + unsigned char fbuffer[800]; + bool allowRepaint; + int length; + BMPPalette palette[256]; + unsigned int * RWEntries; + int * RLEntries; + struct SEntry + { + std::string name; + int offset; + int group; + } ; + std::vector SEntries ; + char id[2]; + std::string defName, curDir; + int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false); + + //////////// + + unsigned char * FDef; //animation raw data + unsigned int curFrame; //number of currently displayed frame + unsigned int frames; //number of frames + int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1]) +public: + CCreatureAnimation(std::string name); //c-tor + //~CCreatureAnimation(); //d-tor //not necessery ATM + + void setType(int type); //sets type of animation and cleares framecount + int getType() const; //returns type of animation + + int nextFrame(SDL_Surface * dest, int x, int y); //0 - success, any other - error //print next +}; + #endif //CCREATUREHANDLER_H \ No newline at end of file