MStatus atomExport::writer( const MFileObject& file, const MString& options, FileAccessMode mode) { MStatus status = MS::kFailure; MString fileName = file.fullName(); #if defined (OSMac_) char fname[MAXPATHLEN]; strcpy (fname, fileName.asChar()); ofstream animFile(fname); #else ofstream animFile(fileName.asChar()); #endif // Defaults. // MString copyFlags("copyKey -cb api -fea 1 "); int precision = kDefaultPrecision; bool statics = false; bool includeChildren = false; std::set<std::string> attrStrings; // Parse the options. The options syntax is in the form of // "flag=val;flag1=val;flag2=val" // bool useSpecifiedRange = false; bool useTemplate = false; bool cached = false; bool constraint = false; bool sdk = false; bool animLayers = true; MString templateName; MString viewName; MTime startTime = MAnimControl::animationStartTime(); MTime endTime = MAnimControl::animationEndTime(); MString exportEditsFile; MString exportFlags; if (options.length() > 0) { const MString flagPrecision("precision"); const MString flagStatics("statics"); const MString flagConstraint("constraint"); const MString flagSDK("sdk"); const MString flagAnimLayers("animLayers"); const MString flagCopyKeyCmd("copyKeyCmd"); const MString flagSelected("selected"); const MString flagTemplate("template"); const MString flagView("view"); const MString optionChildrenToo("childrenToo"); const MString optionTemplate("template"); const MString flagAttr("at"); const MString flagWhichRange("whichRange"); const MString flagRange("range"); const MString flagExportEdits("exportEdits"); const MString flagCached("baked"); // Start parsing. // MStringArray optionList; MStringArray theOption; options.split(';', optionList); unsigned nOptions = optionList.length(); for (unsigned i = 0; i < nOptions; i++) { theOption.clear(); optionList[i].split('=', theOption); if (theOption.length() < 1) { continue; } if (theOption[0] == flagPrecision && theOption.length() > 1) { if (theOption[1].isInt()) { precision = theOption[1].asInt(); } } else if( theOption[0] == flagTemplate && theOption.length() > 1) { templateName = theOption[1]; } else if( theOption[0] == flagView && theOption.length() > 1) { viewName = theOption[1]; } else if ( theOption[0] == flagWhichRange && theOption.length() > 1) { if (theOption[1].isInt()) useSpecifiedRange = (theOption[1].asInt() ==1) ? false : true; } else if ( theOption[0] == flagRange && theOption.length() > 1) { MStringArray rangeArray; theOption[1].split(':',rangeArray); if(rangeArray.length()==2) { if(rangeArray[0].isDouble()) { double val = rangeArray[0].asDouble(); startTime = MTime(val,MTime::uiUnit()); } else if(rangeArray[0].isInt()) { double val = (double)rangeArray[0].asInt(); startTime = MTime(val,MTime::uiUnit()); } if(rangeArray[1].isDouble()) { double val = rangeArray[1].asDouble(); endTime = MTime(val,MTime::uiUnit()); } else if(rangeArray[1].isInt()) { double val = (double)rangeArray[1].asInt(); endTime = MTime(val,MTime::uiUnit()); } } } else if ( theOption[0] == flagStatics && theOption.length() > 1) { if (theOption[1].isInt()) { statics = (theOption[1].asInt()) ? true : false; } } else if ( theOption[0] == flagSDK && theOption.length() > 1) { if (theOption[1].isInt()) { sdk = (theOption[1].asInt()) ? true : false; } } else if ( theOption[0] == flagConstraint && theOption.length() > 1) { if (theOption[1].isInt()) { constraint = (theOption[1].asInt()) ? true : false; } } else if ( theOption[0] == flagAnimLayers && theOption.length() > 1) { if (theOption[1].isInt()) { animLayers = (theOption[1].asInt()) ? true : false; } } else if ( theOption[0] == flagCached && theOption.length() > 1) { if (theOption[1].isInt()) { cached = (theOption[1].asInt()) ? true : false; } } else if (theOption[0] == flagSelected && theOption.length() > 1) { includeChildren = (theOption[1] == optionChildrenToo) ? true : false; if(theOption[1] == optionTemplate) useTemplate = true; } else if (theOption[0] == flagAttr && theOption.length() > 1) { std::string str(theOption[1].asChar()); attrStrings.insert(str); } else if ( theOption[0] == flagCopyKeyCmd && theOption.length() > 1) { // Replace any '>' characters with '"'. This is needed // since the file translator option boxes do not handle // escaped quotation marks. // const char *optStr = theOption[1].asChar(); size_t nChars = strlen(optStr); char *copyStr = new char[nChars+1]; copyStr = strcpy(copyStr, optStr); for (size_t j = 0; j < nChars; j++) { if (copyStr[j] == '>') { copyStr[j] = '"'; } } copyFlags += copyStr; delete [] copyStr; } else if (theOption[0] == flagExportEdits && theOption.length() > 1) { exportEditsFile = theOption[1]; } } } // Set the precision of the ofstream. // animFile.precision(precision); atomTemplateReader templateReader; if(useTemplate == true) { includeChildren = false; templateReader.setTemplate(templateName,viewName); templateReader.selectNodes(); //make the template nodes be the selection } status = exportSelected(animFile, copyFlags, attrStrings, includeChildren, useSpecifiedRange, startTime, endTime, statics, cached,sdk,constraint, animLayers, exportEditsFile,templateReader); animFile.flush(); animFile.close(); return status; }
MStatus atomImport::reader( const MFileObject& file, const MString& options, FileAccessMode mode) { MStatus status = MS::kFailure; MString fileName = file.fullName(); #if defined (OSMac_) char fname[MAXPATHLEN]; strcpy (fname, fileName.asChar()); ifstream animFile(fname); #else ifstream animFile(fileName.asChar()); #endif // Parse the options. The options syntax is in the form of // "flag=val;flag1=val;flag2=val" // if(animFile.good()==false) return status; MString pasteFlags; MString prefix; MString suffix; MString search; MString replace; MString mapFile; bool replaceLayers = false; MString exportEditsFile; bool includeChildren = false; atomNodeNameReplacer::ReplaceType type = atomNodeNameReplacer::eHierarchy; MString templateName; MString viewName; bool useTemplate = false; if (options.length() > 0) { // Set up the flags for the paste command. // const MString flagSrcTime("srcTime"); const MString flagDstTime("dstTime"); const MString flagOldDstTime("time"); const MString flagCopies("copies"); const MString flagOption("option"); const MString flagConnect("connect"); const MString flagMatch("match"); const MString flagSearch("search"); const MString flagReplace("replace"); const MString flagPrefix("prefix"); const MString flagSuffix("suffix"); const MString flagMapFile("mapFile"); const MString flagHierarchy("hierarchy"); const MString flagString("string"); const MString flagSelected("selected"); const MString flagTemplate("template"); const MString flagView("view"); const MString optionChildrenToo("childrenToo"); const MString optionTemplate("template"); const MString flagExportEdits("exportEdits"); MString copyValue; MString flagValue; MString connectValue; MString match; MString srcTimeValue; MString dstTimeValue; // Start parsing. // MStringArray optionList; MStringArray theOption; options.split(';', optionList); unsigned nOptions = optionList.length(); for (unsigned i = 0; i < nOptions; i++) { theOption.clear(); optionList[i].split('=', theOption); if (theOption.length() < 1) { continue; } if (theOption[0] == flagCopies && theOption.length() > 1) { copyValue = theOption[1];; } else if (theOption[0] == flagOption && theOption.length() > 1) { flagValue = theOption[1]; } else if (theOption[0] == flagConnect && theOption.length() > 1) { if (theOption[1].asInt() != 0) { connectValue += theOption[1]; } } else if( theOption[0] == flagTemplate && theOption.length() > 1) { templateName = theOption[1]; } else if( theOption[0] == flagView && theOption.length() > 1) { viewName = theOption[1]; } else if (theOption[0] == flagSrcTime && theOption.length() > 1) { srcTimeValue += theOption[1]; } else if ((theOption[0] == flagDstTime || theOption[0] == flagOldDstTime )&& theOption.length() > 1) { dstTimeValue += theOption[1]; } else if (theOption[0] == flagMatch && theOption.length() > 1) { match = theOption[1]; } else if (theOption[0] == flagSearch && theOption.length() > 1) { search = theOption[1]; } else if (theOption[0] == flagReplace && theOption.length() > 1) { replace = theOption[1]; } else if (theOption[0] == flagPrefix && theOption.length() > 1) { prefix = theOption[1]; } else if (theOption[0] == flagSuffix && theOption.length() > 1) { suffix = theOption[1]; } else if (theOption[0] == flagMapFile && theOption.length() > 1) { mapFile = theOption[1]; } else if (theOption[0] == flagSelected && theOption.length() > 1) { includeChildren = (theOption[1] == optionChildrenToo) ? true : false; if(theOption[1] == optionTemplate) useTemplate = true; } else if (theOption[0] == flagExportEdits && theOption.length() > 1) { exportEditsFile = theOption[1]; } } if (copyValue.length() > 0) { pasteFlags += " -copies "; pasteFlags += copyValue; pasteFlags += " "; } if (flagValue.length() > 0) { pasteFlags += " -option \""; pasteFlags += flagValue; pasteFlags += "\" "; if(flagValue == MString("replace")) replaceLayers = true; } if (connectValue.length() > 0) { pasteFlags += " -connect "; pasteFlags += connectValue; pasteFlags += " "; } if (dstTimeValue.length() > 0) { bool useQuotes = !dstTimeValue.isDouble(); pasteFlags += " -time "; if (useQuotes) pasteFlags += "\""; pasteFlags += dstTimeValue; if (useQuotes) pasteFlags += "\""; pasteFlags += " "; } if (srcTimeValue.length() > 0) { MTime lClipStartTime; MTime lClipEndTime; MStringArray lTimes; if ( MStatus::kSuccess == srcTimeValue.split( L':', lTimes ) ) { if ( lTimes.length() > 0 ) { double lImportStartFrame = lTimes[0].asDouble(); double lImportEndFrame = lImportStartFrame; if ( lTimes.length() > 1 ) { lImportEndFrame = lTimes[1].asDouble(); } fReader.setImportFrameRange( lImportStartFrame, lImportEndFrame ); } else { fReader.clearImportFrameRange(); } } } else { fReader.clearImportFrameRange(); } if(match.length() >0) { if(match == flagHierarchy) type = atomNodeNameReplacer::eHierarchy; else if(match == flagString) type = atomNodeNameReplacer::eSearchReplace; else if(match == flagMapFile) type = atomNodeNameReplacer::eMapFile; } //not set, then we leave what we had } // If the selection list is empty, there is nothing to import. // MSelectionList sList; std::vector<unsigned int> depths; atomTemplateReader templateReader; if(useTemplate == true) { templateReader.setTemplate(templateName,viewName); includeChildren = false; templateReader.selectNodes(); //make the selection set be us. } SelectionGetter::getSelectedObjects(includeChildren,sList,depths); if (sList.isEmpty()) { MString msg = MStringResource::getString(kNothingSelected, status); MGlobal::displayError(msg); return (MS::kFailure); } atomNodeNameReplacer replacer(type,sList,depths,prefix,suffix,search,replace,mapFile); if (mode == kImportAccessMode) { status = importAnim(sList,animFile,pasteFlags,replacer,exportEditsFile,templateReader,replaceLayers); } animFile.close(); return status; }
MStatus animExport::writer( const MFileObject& file, const MString& options, FileAccessMode mode) { MStatus status = MS::kFailure; MString fileName = file.fullName(); #if defined (OSMac_) char fname[MAXPATHLEN]; strcpy (fname, fileName.asChar()); ofstream animFile(fname); #else ofstream animFile(fileName.asChar()); #endif // Defaults. // MString copyFlags("copyKey -cb api -fea 1 "); int precision = kDefaultPrecision; bool nodeNames = true; bool verboseUnits = false; // Parse the options. The options syntax is in the form of // "flag=val;flag1=val;flag2=val" // MString exportFlags; if (options.length() > 0) { const MString flagPrecision("precision"); const MString flagNodeNames("nodeNames"); const MString flagVerboseUnits("verboseUnits"); const MString flagCopyKeyCmd("copyKeyCmd"); // Start parsing. // MStringArray optionList; MStringArray theOption; options.split(';', optionList); unsigned nOptions = optionList.length(); for (unsigned i = 0; i < nOptions; i++) { theOption.clear(); optionList[i].split('=', theOption); if (theOption.length() < 1) { continue; } if (theOption[0] == flagPrecision && theOption.length() > 1) { if (theOption[1].isInt()) { precision = theOption[1].asInt(); } } else if ( theOption[0] == flagNodeNames && theOption.length() > 1) { if (theOption[1].isInt()) { nodeNames = (theOption[1].asInt()) ? true : false; } } else if ( theOption[0] == flagVerboseUnits && theOption.length() > 1) { if (theOption[1].isInt()) { verboseUnits = (theOption[1].asInt()) ? true : false; } } else if ( theOption[0] == flagCopyKeyCmd && theOption.length() > 1) { // Replace any '>' characters with '"'. This is needed // since the file translator option boxes do not handle // escaped quotation marks. // const char *optStr = theOption[1].asChar(); size_t nChars = strlen(optStr); char *copyStr = new char[nChars+1]; copyStr = strcpy(copyStr, optStr); for (size_t j = 0; j < nChars; j++) { if (copyStr[j] == '>') { copyStr[j] = '"'; } } copyFlags += copyStr; delete [] copyStr; } } } // Set the precision of the ofstream. // animFile.precision(precision); status = exportSelected(animFile, copyFlags, nodeNames, verboseUnits); animFile.flush(); animFile.close(); return status; }
MStatus animImport::reader( const MFileObject& file, const MString& options, FileAccessMode mode) { MStatus status = MS::kFailure; MString fileName = file.fullName(); #if defined (OSMac_) char fname[MAXPATHLEN]; strcpy (fname, fileName.asChar()); ifstream animFile(fname); #else ifstream animFile(fileName.asChar()); #endif // Parse the options. The options syntax is in the form of // "flag=val;flag1=val;flag2=val" // MString pasteFlags; if (options.length() > 0) { // Set up the flags for the paste command. // const MString flagTargetTime("targetTime"); const MString flagTime("time"); const MString flagCopies("copies"); const MString flagOption("option"); const MString flagConnect("connect"); MString copyValue; MString flagValue; MString connectValue; MString timeValue; // Start parsing. // MStringArray optionList; MStringArray theOption; options.split(';', optionList); unsigned nOptions = optionList.length(); for (unsigned i = 0; i < nOptions; i++) { theOption.clear(); optionList[i].split('=', theOption); if (theOption.length() < 1) { continue; } if (theOption[0] == flagCopies && theOption.length() > 1) { copyValue = theOption[1];; } else if (theOption[0] == flagOption && theOption.length() > 1) { flagValue = theOption[1]; } else if (theOption[0] == flagConnect && theOption.length() > 1) { if (theOption[1].asInt() != 0) { connectValue += theOption[1]; } } else if (theOption[0] == flagTime && theOption.length() > 1) { timeValue += theOption[1]; } } if (copyValue.length() > 0) { pasteFlags += " -copies "; pasteFlags += copyValue; pasteFlags += " "; } if (flagValue.length() > 0) { pasteFlags += " -option \""; pasteFlags += flagValue; pasteFlags += "\" "; } if (connectValue.length() > 0) { pasteFlags += " -connect "; pasteFlags += connectValue; pasteFlags += " "; } if (timeValue.length() > 0) { bool useQuotes = !timeValue.isDouble(); pasteFlags += " -time "; if (useQuotes) pasteFlags += "\""; pasteFlags += timeValue; if (useQuotes) pasteFlags += "\""; pasteFlags += " "; } } if (mode == kImportAccessMode) { status = importAnim(animFile, pasteFlags); } animFile.close(); return status; }
void ResourceObject::Init(int type, std::string resType, std::string resObject) { /*dataTypes = new dataFile_Types[4]; dataTypes[DATAFILE_SPRITE_PHYSDATA].fileValueCount = 7; dataTypes[DATAFILE_SPRITE_UNITDATA].fileValueCount = 10; dataTypes[DATAFILE_SPRITE_ANIMDATA].fileValueCount = 4;*/ this->resInfo.type = resType; //this-> // if we're loading a single image containing all animations if (type == RES_TYPE_TILEMAP) { sstr.str(""); sstr<<"content\\"<<resType<<"\\"<<resObject<<"\\tileset.bmp"; str1 = sstr.str(); surface = load_image(str1,this->resInfo.alpha_r,this->resInfo.alpha_g,this->resInfo.alpha_b); this->resInfo.width = surface->w; this->resInfo.height = surface->h; this->resInfo.xTileSize = 32; this->resInfo.yTileSize = 32; long clips, framesMax, anglesMax; clips = 1; framesMax = 1; anglesMax = 1; animData = new animation_Data[clips]; stateToAnim.resize(states::COUNT_ANIM_STATE); animData[0].clipArray = new frame_Array[framesMax]; animData[0].clipArray[0].angles = new angle_Array[anglesMax]; animData[0].clipArray[0].angles[0].clip.x = 0; animData[0].clipArray[0].angles[0].clip.y = 0; animData[0].clipArray[0].angles[0].clip.w = surface->w; animData[0].clipArray[0].angles[0].clip.h = surface->h; stateToAnim.at(0) = &animData[0]; stateToAnim.at(1) = &animData[0]; stateToAnim.at(2) = &animData[0]; stateToAnim.at(10) = &animData[0]; } //If we're loading a series of files to merge to one else if (type == RES_TYPE_FILEMAP) { sstr.str(""); sstr<<"content\\"<<resType<<"\\"<<resObject<<"\\animdata.dat"; str1 = sstr.str(); std::ifstream animFile( str1.c_str() ); if( animFile == NULL ) { return; } long clips, framesMax, anglesMax; long resWidth = 0, resHeight = 0, totalFrameCount = 0; animFile >> clips; animFile >> framesMax; animFile >> anglesMax; animation_Data* animDataTemp = new animation_Data; animData = new animation_Data[clips]; //animData = new animation_Data[clips+2]; stateToAnim.resize(states::COUNT_ANIM_STATE); std::vector<animation_Data *>::iterator itaD = stateToAnim.begin(); //itaD = stateToAnim.begin(); //itaD+=0; animDataTemp->ID = -1; //stateToAnim.insert(itaD,animDataTemp); //stateToAnim.insert(itaD,animDataTemp); stateToAnim.at(0) = animDataTemp; stateToAnim.at(2) = animDataTemp; stateToAnim.at(10) = animDataTemp; itaD = stateToAnim.begin(); //stateToAnim = new animation_Data[COUNT_ANIM_STATE]; SDL_Rect biggestClip; animFile >> biggestClip.x; animFile >> biggestClip.y; animFile >> biggestClip.w; animFile >> biggestClip.h; int i; for (i = 0; i < clips; i++) { animFile >> animData[i].ID; animFile >> animData[i].frames; animFile >> animData[i].angles; animFile >> animData[i].execTime; animData[i].clipArray = new frame_Array[framesMax]; for (int k = 0; k < framesMax; k++) { animData[i].clipArray[k].angles = new angle_Array[anglesMax]; for (int l = 0; l < anglesMax; l++) { animData[i].clipArray[k].angles[l].clip.x = 0; animData[i].clipArray[k].angles[l].clip.y = 0; animData[i].clipArray[k].angles[l].clip.w = 0; animData[i].clipArray[k].angles[l].clip.h = 0; } } if (animData[i].angles == 0) { resWidth += (1 * biggestClip.w); totalFrameCount += animData[i].frames; } else { resWidth += (animData[i].frames * biggestClip.w); totalFrameCount += animData[i].frames * anglesMax; } //animData[i].Init(framesMax,anglesMax); //itaD = stateToAnim.begin(); //itaD+=animData[i].ID; //stateToAnim.insert(itaD,&animData[i]); stateToAnim.at(animData[i].ID) = &animData[i]; if (animData[i].ID == 1) { if (stateToAnim.at(0)->ID == -1) { stateToAnim.at(0) = &animData[i]; } if (stateToAnim.at(2)->ID == -1) { stateToAnim.at(2) = &animData[i]; } if (stateToAnim.at(10)->ID == -1) { stateToAnim.at(10) = &animData[i]; } } //update render and animate code to use this lookup vector, also update ai states to anim code } if (stateToAnim.at(0)->ID < 0) { int asdasd = stateToAnim.at(0)->ID; int sdf = 0; } //SDL_Rect lol = animData[4].frameArray[0][0]; //animData[4].frameArray[0][0] = lol; resHeight = anglesMax * biggestClip.h; if (animFile.fail()) { //ERROR animFile.close(); } animFile.close(); this->surface = SDL_CreateRGBSurface(SDL_HWSURFACE,resWidth,resHeight,32,0xff000000,0x00ff0000,0x0000ff00,0x000000ff); SDL_Surface* image = new SDL_Surface; SDL_Surface* mask = new SDL_Surface; SDL_Surface* temp = new SDL_Surface; SDL_Surface* temp2 = new SDL_Surface; SDL_Rect offset; SDL_Rect clip; //Flip vars int yOffset; int yOffsetFlipped = 16; bool bFlip; int maxWidth = 0; int maxHeight = 0; int clipNum = 0; int frameNum = 0; int angleNum = 0; int xTileStart = 0; SDL_Rect tPtr; //biggestClip.y = 99; //REMOVE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE //animData[4].frameArray[0][0] = lol; for (i = 0; i < totalFrameCount; i++) { float yTemp = (fmod(i*1.0f,anglesMax*1.0f)); bFlip = false; if (yTemp == 0) { yOffsetFlipped = 15; yOffset = 0; } if (fmod(yTemp,2) == 1) { if (yTemp != 1) { angleNum = yOffsetFlipped; yOffsetFlipped--; bFlip = true; } } else { angleNum = yOffset; yOffset++; } //this code determines where the next blit should be placed offset.y = angleNum*biggestClip.h; offset.x = ((int)(i/anglesMax))*biggestClip.w; offset.w = biggestClip.w; offset.h = biggestClip.h; std::string sZeroes; sstr.str(""); if (totalFrameCount < 10) { /*if (i < 10) { sstr<<"00"; } else if (i < 100) {*/ sstr<<""; //} } else if (totalFrameCount < 100) { if (i < 10) { sstr<<"0"; } else if (i < 100) { sstr<<""; } } else { if (i < 10) { sstr<<"00"; } else if (i < 100) { sstr<<"0"; } } /*sstr.str(""); sstr<<resType<<"\\"<<resObject<<"\\img\\"; str1 = sstr.str(); std::vector<std::string> results; this->lsdir(str1.c_str(),results);*/ //changed for vulture sZeroes = sstr.str(); //lol = animData[4].frameArray[0][0]; //animData[4].frameArray[0][0] = animData[4].frameArray[0][1]; sstr.str(""); sstr<<"content\\"<<resType<<"\\"<<resObject<<"\\img\\"<<resObject<<" "<<sZeroes<<i<<".bmp"; str1 = sstr.str(); image = load_image(str1,this->resInfo.alpha_r,this->resInfo.alpha_g,this->resInfo.alpha_b); //this->LoadTextures(); //animData[4].angles = 5; //lol = animData[4].frameArray[0][1]; clip.x = 0; clip.y = 0; clip.w = image->w; clip.h = image->h; //animData[4].clipArray[0].angles[0].clip = &clip; //image = SDL_CreateRGBSurface(SDL_HWSURFACE,128,128,32,0xff000000,0x00ff0000,0x0000ff00,0x000000ff); //mask = SDL_CreateRGBSurface(SDL_HWSURFACE,128,128,32,0xff000000,0x00ff0000,0x0000ff00,0x000000ff); temp = SDL_CreateRGBSurface(SDL_HWSURFACE,clip.w,clip.h,32,0xff000000,0x00ff0000,0x0000ff00,0x000000ff); temp2 = SDL_CreateRGBSurface(SDL_HWSURFACE,clip.w,clip.h,32,0xff000000,0x00ff0000,0x0000ff00,0x000000ff); this->test = SDL_CreateRGBSurface(SDL_HWSURFACE,clip.w,clip.h,32,0xff000000,0x00ff0000,0x0000ff00,0x000000ff); //temp = SDL_DisplayFormat(temp); if (bFlip) { SDL_BlitSurface(image,&image->clip_rect,temp,&temp->clip_rect); SDL_FillRect( image, &image->clip_rect, SDL_MapRGB( image->format,this->resInfo.alpha_r,this->resInfo.alpha_g,this->resInfo.alpha_b ) ); SDL_SetColorKey( image, SDL_SRCCOLORKEY, SDL_MapRGB( image->format,this->resInfo.alpha_r,this->resInfo.alpha_g,this->resInfo.alpha_b ) ); xFlip(temp,image); } sstr.str(""); sstr<<"content\\"<<resType<<"\\"<<resObject<<"\\img\\"<<resObject<<"_mask "<<sZeroes<<i<<".bmp"; str1 = sstr.str(); mask = load_image(str1,this->resInfo.alpha_r,this->resInfo.alpha_g,this->resInfo.alpha_b); //new SDL_FillRect( temp2, &temp2->clip_rect, SDL_MapRGB( temp2->format,this->resInfo.alpha_r,this->resInfo.alpha_g,this->resInfo.alpha_b ) ); SDL_BlitSurface(mask,&mask->clip_rect,temp2,&temp2->clip_rect); SDL_FillRect( mask, &mask->clip_rect, SDL_MapRGB( mask->format, 255, 255, 255 ) ); //SDL_SetColorKey( temp2, SDL_SRCCOLORKEY, SDL_MapRGB( temp2->format, 255, 255, 255 ) ); //SDL_FillRect( test, &test->clip_rect, SDL_MapRGB( test->format, 255, 255, 255 ) ); SDL_SetColorKey( mask, SDL_SRCCOLORKEY, SDL_MapRGB( mask->format, 255, 255, 255 ) ); this->invert_mask(temp2,mask); SDL_BlitSurface(mask,&mask->clip_rect,test,&test->clip_rect); if (bFlip) { SDL_BlitSurface(mask,&mask->clip_rect,temp,&temp->clip_rect); SDL_FillRect( mask, &mask->clip_rect, SDL_MapRGB( mask->format, 255, 255, 255 ) ); SDL_SetColorKey( mask, SDL_SRCCOLORKEY, SDL_MapRGB( mask->format, 255, 255, 255 ) ); xFlip(temp,mask); } //all this converts the black background to rgb 0 255 255 so its the new transparent color //without messing up the fact that black is used in these images normally SDL_FillRect( temp, &temp->clip_rect, SDL_MapRGB( temp->format, 0, 255, 255 ) ); SDL_BlitSurface(mask,&mask->clip_rect,temp,&temp->clip_rect); SDL_BlitSurface(image,&image->clip_rect,temp,&temp->clip_rect); int xTile = ((int)(i/anglesMax)); int yTile = (fmod(i*1.0f,anglesMax*1.0f)); //int frameNum = 0; //angleNum = yTile; // im setup above frameNum = xTile-xTileStart; //FIX THIS CODE, iterates through clips, i added clipnum++, right? //for (int j = 0; j < clips; j++) { if (frameNum >= animData[clipNum].frames) { frameNum = 0; xTileStart = xTile; clipNum++; int lol = 0; //tPtr = animData[clipNum].clipArray[frameNum].angles[angleNum].clip; } else { //clipNum = j; } //} tPtr = this->getVisualSize(temp,0,255,255); /*offset.x += biggestClip.x; offset.y += biggestClip.y; offset.w = biggestClip.w; offset.h = biggestClip.h;*/ SDL_Rect bufferClip = offset; bufferClip.x += ((biggestClip.w - tPtr.w)/2);//((tPtr.x - biggestClip.x));// + ((biggestClip.w - tPtr.w)/2);//-((tPtr.w)/2); bufferClip.y += ((biggestClip.h - tPtr.h)/2);//((tPtr.y - biggestClip.y));// + ((biggestClip.h - tPtr.h)/2);//-((tPtr.h)/2); (tPtr.y - biggestClip.y);//-((tPtr.h)/2); bufferClip.w = tPtr.w; bufferClip.h = tPtr.h; //REMOVE ME! //SDL_FillRect(surface,&offset,SDL_MapRGB(surface->format,0,(rand() % 255),0)); if (resObject == "vulture") { int asas = 0; } animData[clipNum].clipArray[frameNum].angles[angleNum].clip = bufferClip; // i think this is crashing cause it goes over clip max, also last frame isnt accounted for right, ling death animData[clipNum].clipArray[frameNum].angles[angleNum].xOffset = tPtr.x-biggestClip.x; animData[clipNum].clipArray[frameNum].angles[angleNum].yOffset = tPtr.y-biggestClip.y; SDL_BlitSurface( temp, &tPtr, surface, &bufferClip ); //keep this code to get the biggest clip size of other graphics for the data files if (tPtr.x < biggestClip.x) { biggestClip.x = tPtr.x; } if (tPtr.w > biggestClip.w) { biggestClip.w = tPtr.w; } if (tPtr.y < biggestClip.y) { biggestClip.y = tPtr.y; } if (tPtr.h > biggestClip.h) { biggestClip.h = tPtr.h; } } this->resInfo.width = surface->w; this->resInfo.height = surface->h; this->resInfo.xTileSize = biggestClip.w; this->resInfo.yTileSize = biggestClip.h; SDL_SetColorKey( surface, SDL_SRCCOLORKEY | SDL_HWSURFACE, SDL_MapRGB( surface->format, 0, 255, 255 ) ); surface = SDL_DisplayFormat( surface ); test = SDL_DisplayFormat( test ); //Free the old image //SDL_FreeSurface( loadedImage ); }
int main( int argc, char *argv[] ) { ASSERT( argc > 2, "merge [main file].x [anim file].x [name]" ); std::fstream mainFile( argv[1] ); ASSERT( mainFile.is_open(), std::string( "unable to open " ) + argv[1] + " file" ); std::ifstream animFile( argv[2] ); ASSERT( mainFile.is_open(), std::string( "unable to open " ) + argv[2] + " file" ); std::string setName; std::string baseName; // find the animation set in the anim file MovePastNext( animFile, "AnimationSet" ); int readPos = MovePastNext( animFile, "AnimationSet" ); animFile >> baseName; setName = ( argc > 3 ) ? argv[3] : baseName; animFile.seekg( readPos ); std::string header( "AnimationSet " + baseName ); int headerLen = (int)header.length() + 1; char *animSet; int animSetSize = ReadAnimSet( animSet, animFile, readPos + headerLen, setName ); int headerPos = -1; int writePos = -1; int backupPos = 0; // find position to insert animation set MovePastNext( mainFile, "AnimationSet" ); while ( !mainFile.eof() ) { headerPos = MovePastNext( mainFile, "AnimationSet" ); if ( headerPos == -1 ) break; std::string buf(""); mainFile >> buf; if ( buf == setName ) { backupPos = MovePastNext( mainFile, "AnimationSet" ); break; } } char *backup = NULL; int backupSize = 0; int endOfFile = 0; header = "AnimationSet " + setName; headerLen = (int)header.length() + 1; writePos = headerPos + headerLen; if ( headerPos == -1 ) { mainFile.clear(); mainFile.seekp( 0, std::ios_base::end ); } else { mainFile.seekg( 0, std::ios_base::end ); endOfFile = (int)mainFile.tellg(); backupSize = endOfFile - backupPos; backup = new char[backupSize]; mainFile.seekg( backupPos ); mainFile.read( backup, backupSize ); mainFile.clear(); // failbit will most likely be set from last read mainFile.seekp( headerPos ); } char newLine = '\n'; mainFile.write( &newLine, sizeof( newLine ) ); mainFile.write( animSet, animSetSize ); mainFile.write( &newLine, sizeof( newLine ) ); mainFile.write( &newLine, sizeof( newLine ) ); if ( backup ) { int last = backupSize - 1; while ( backup[last--] != '}' ) ; mainFile.write( backup, last + 2 ); int curPos = mainFile.tellp(); if ( curPos < endOfFile ) { int nEmptyBytes = endOfFile - curPos + 1; char *emptySpace = new char[nEmptyBytes]; memset( emptySpace, ' ', nEmptyBytes ); mainFile.write( emptySpace, nEmptyBytes ); SAFE_DELETE_ARRAY( emptySpace ); } } std::cout << "done" << std::endl; mainFile.close(); animFile.close(); SAFE_DELETE_ARRAY( animSet ); SAFE_DELETE_ARRAY( backup ); return 0; }