Guest User

Untitled

a guest
Oct 16th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 22.55 KB | None | 0 0
  1.  
  2. void runTCR()
  3. {  
  4.     if(!TCR_BM) return;
  5.     tcr_cellhighlight = true;
  6.     dword  *ti_addr32 ; //tile image pixel address pointer
  7.     dword  *si_addr32 ; //source image pixel address pointer
  8.     dword  *osi_addr32; //old source image pixel address pointer
  9.     dword  c_col = 0  ;
  10.     dword  i,i2,i3,iw,ih ;  
  11.     dword  nextrow,rowjump ; //number of pixels to skip in order to get to the next desired row of pixels
  12.     //dword  tilerow = bmpwidth/cellwidth;
  13.     dword  uniquetiles  = 0; //also used as tile id
  14.     dword  uniquecolors = 0;
  15.     dword  ci_tilesize  = cellwidth * cellheight; //bmpwidth * bmpheight * 4;//valid image dword size
  16.     dword numFreeSlots  = 100; // number of free tile slots to allocate, used in tiletransfers
  17.     //etileset1.nextid;
  18.     //dword  tmp_tilecount= ci_tilecount;
  19.     dword ddtstresult; //deduping/uniqueness test result
  20.     dword bmpsize = bmpwidth * bmpheight; // total size of bitmap
  21.     dword *colfreq; // color frequency list used in sorting colors into most used first
  22.     dword nummetatiles = ci_tilecount/4;
  23.     fmap* newmap = NULL;
  24.     //dword tcrdirnamesize  = strlen(getcwd(0,0));    // byte size of current image file directory name
  25.     //dword tcrfilenamesize = strlen(TCR_filename); // byte size of current image file name
  26.  
  27.     bool tilematch;
  28.     fmap  *submapptr;  //sub map/mini map data
  29.     ftile *submtileptr; //sub map tiles
  30.    
  31.     TCR_PB->value = 0;
  32.     TCR_PB->setUnits(ci_tilecount);
  33.     // set up tile source names properly
  34.    
  35.     // ETSCALED2X
  36.        
  37.     TCR_FT->width =  cellwidth  * 2+2;
  38.     TCR_FT->height = cellheight * 2+2;
  39.     TCR_FT->updatePos(true);
  40.     //msg(buildstr("%i",sizeof(char))); = 1 so give it 2
  41.     //allocate temporary 32 bit bitmap data for initial image data copy
  42.     byte* tmpmem_head = (byte*)malloc(((ci_tilecount) * (sizeof(bitmap)+4+4+2+2) * (strlen(getcwd(0,0))+strlen(TCR_filename)) +
  43.                                       (ci_tilecount * 1024 * 4 )+(bmpsize *2) + 264))+sizeof(palette)+256*10;
  44.     _messages__on = true;
  45.     msg("here");
  46.     //msg(buildstr("%i",sizeof(char))); = 1 so give it 2
  47.     //allocate temporary 32 bit bitmap data for initial image data copy
  48.     //byte* tmpmem_head = (byte*)malloc((ci_tilecount) * (sizeof(bitmap)+4+4+2+2+tcrdirnamesize + tcrfilenamesize) *
  49.     //                                (ci_tilecount * ci_tilesize * 4)+32);
  50.     /*  [X] tmp bitmaps  mem
  51.         [X] isunique     mem
  52.         [X] bitmapimage  mem
  53.         [X] color freq.  mem
  54.     */ 
  55.     ////
  56.     byte* tmpmem = tmpmem_head;
  57.  
  58.     //allocate palette memory
  59.     newpalette =  (palette*)malloc(sizeof(palette)*5);
  60.    
  61.     newpalette->flags = palette_32bit;
  62.     //newpalette->col32 = (dword*) malloc(bmpwidth * bmpheight*4); // seperately so we can realloc
  63.  
  64.     //set color frequency list data
  65.     colfreq  = (dword*)tmpmem;
  66.     //memset(colfreq,0,bmpsize*4);
  67.     tmpmem += 4* bmpsize;
  68.        
  69.     bitmap *tmp32bitbmp = (bitmap*)tmpmem;
  70.     tmpmem += sizeof(bitmap) * ci_tilecount;
  71.     //[NOTE] tmp32bitbmp[0] is used as a 32 temp comparison surface for the previously existing 8 bit tiles
  72.     dword *isunique = (dword*)tmpmem;
  73.     tmpmem+= 4 * ci_tilecount;
  74.  
  75.     dword *tmpflipvalues = (dword*)tmpmem;
  76.     tmpmem+= 4 * ci_tilecount;
  77.  
  78.     //retreive free 32x32 tiles for tile data storage and final image storage
  79.     /*  -Retrieved here to :
  80.           *allow me to generate linker data without a second pass
  81.           *the extra tiles will be used by the bucket system next time tiles are needed
  82.         -use array of pointers to buckets here so that :
  83.           * i can delete tiles, push up the pointers and still access the newtiles as an array durring mapping and such
  84.             then later on i can delete tiles, update the links and send them
  85.         -...however to new tilesets need to be accessed as an array ?
  86.         if not then ... allocate a new tileset linked list, and link all tilesets
  87.     */
  88.    
  89.     //msg(buildstr("%i %i",sizeof(editertile32x32**),sizeof(editertile32x32)));
  90.     //newtiles32x32 = (editertile32x32**)malloc(sizeof(editertile32x32) * ci_tilecount);
  91.    
  92.     //allocate newtile space
  93.     newtiles32x32 = (editertile32x32**)malloc(ptrsize * (ci_tilecount+numFreeSlots));
  94.     allocbucket(editertile32x32,newtiles32x32[0],flags,0x8,ci_tilecount,"new tiles");
  95.     for(i = 1; i < ci_tilecount; i++)           //[addition]32 additional slots for tiletransfers
  96.     {   allocbucket(editertile32x32,newtiles32x32[i],flags,0x8,1,"new tiles");
  97.     }
  98.  
  99.     //allocate new metatile space
  100.     if(TCR_CMT_CB->value)
  101.     {   newmetatiles = (editermetatile**)malloc(ptrsize * nummetatiles);
  102.         allocbucket(editermetatile,newmetatiles[0],flags,0x8,nummetatiles,"new tiles");
  103.         for(i = 1; i < nummetatiles; i++)           //[addition]32 additional slots for tiletransfers
  104.         {   allocbucket(editermetatile,newmetatiles[i],flags,0x8,1,"new tiles");
  105.         }
  106.     }
  107.     else newmetatiles = NULL;
  108.  
  109.     //retrieve sufficient free tile link data structure for rare 100% unique linkage cases
  110.     linkedtiledata  *tmplink;
  111.     allocbucket(linkedtiledata,tmplink,flags,0x8,ci_tilecount,"new tile links");
  112.    
  113.     //retrieve and init a new tileset to store the new tiles in
  114.     allocbucket(editertilecluster,newetileset.clusters[newtileclustercount],flags,0x8,10,"new tileset"); // assume we cut at least 10 images every time
  115.    
  116.     newetileset.clusters[newtileclustercount]->tiles32x32   = newtiles32x32;
  117.     newetileset.clusters[newtileclustercount]->metatiles    = newmetatiles;
  118.     newetileset.clusters[newtileclustercount]->numFreeSlots = numFreeSlots ;
  119.  
  120.     //set the highlighter rect starting point
  121.     hl_rectx = TCR_CI->actx1 + 2;  
  122.     hl_recty = TCR_CI->acty1 + 2;  
  123.    
  124.     //init a new submap if needed
  125.     dword tmptilesize = cellwidth;
  126.     if(TCR_S2X_CB->value) tmptilesize*=2;
  127.  
  128.     if(TCR_GM_CB->value)
  129.     {   //allocbucket(fmap,newcuttermaps[newctrmapcount],flags,0x8,10,"new editersubmap");
  130.         //allocbucket(fmap,newmap,flags,0x8,10,"new editersubmap");
  131.         //newetileset.clusters[newtileclustercount]->submap = newmap;
  132.         submapptr = &newetileset.clusters[newtileclustercount]->submap;
  133.         submapptr->numLayers = 1;
  134.         submapptr->layers[0].numCols = tilecols;
  135.         submapptr->layers[0].numRows = tilerows;
  136.         submapptr->layers[0].numTiles = ci_tilesize;
  137.         submapptr->name = strdup(strtok(TCR_filename,"."));
  138.         strcat(submapptr->name,"_submap");
  139.         submapptr->layers[0].tiles  = (ftile*)malloc(sizeof(ftile)*ci_tilecount);
  140.         submapptr->layers[0].tileSize = tmptilesize;
  141.         memset(submapptr->layers[0].tiles,0,sizeof(ftile)*ci_tilecount);
  142.         submtileptr = submapptr->layers[0].tiles;
  143.        
  144.     }
  145.  
  146.     //init row progression data
  147.     nextrow  = TCR_BM->width - cellwidth;         //X
  148.     rowjump  = TCR_BM->width - bmpwidth;  //- 1 ? //take extra image x pixels left over into account
  149.     si_addr32 = (dword*)TCR_BM->pixel;    //X
  150.     i  = 0;
  151.    
  152.     //check for black in image
  153.     i=0;
  154.     do
  155.     {   if((*si_addr32 & 0x00ffffff))
  156.         {   newpalette->col_32[0] = 0; // first color is black [note] = 0;
  157.             uniquecolors = 1;
  158.             break; 
  159.         }
  160.         si_addr32++;
  161.         i++;
  162.     }while(i < bmpsize);
  163.    
  164.     //build color palette for new tiles
  165.     si_addr32 = (dword*)TCR_BM->pixel;    //X
  166.     i=0;
  167.     ih = 0;
  168.     iw = 0;
  169.    
  170.     //try{
  171.     do
  172.     {   iw = 0;
  173.         do
  174.         {   dword colormatch = false;
  175.            
  176.             for(i = 0; i < uniquecolors; i++)
  177.             {   if(uniquecolors > 256)goto end_palbuild;
  178.                 if(newpalette->col_32[i] == *si_addr32)
  179.                 { colormatch = true; break;}
  180.             }
  181.            
  182.             ///if((*si_addr32 & 0x00ffffff) == 0)//ignore alpha
  183.             //*si_addr32 = 0;
  184.                
  185.             //add new color
  186.             if(!colormatch /*&& !((*si_addr32 & 0x00ffffff)==0)*/ )
  187.             {   newpalette->col_32[uniquecolors] = *si_addr32;                 
  188.                 //colfreq[uniquecolors]++;
  189.                 uniquecolors++;
  190.             }
  191.            
  192.             //update frequency
  193.             //else colfreq[i]++;
  194.            
  195.             si_addr32++;
  196.         }while(iw++ < bmpwidth-1);
  197.         si_addr32+=rowjump; // only get colors in the celled part of the image
  198.     }while(ih++ < bmpheight-1);
  199. /* 
  200. }catch(...)
  201.     {   msg("error",buildstr("(unique colors %i",uniquecolors));
  202.     }
  203.     */
  204. end_palbuild:
  205.     //sort pal colors by frequency
  206.     /*
  207.     dword tmpnum;
  208.     i  = 0;
  209.     i2 = 0;
  210.    
  211.     do
  212.     {   do
  213.         {   if(colfreq[i] < colfreq[i2])
  214.             {  
  215.                 //tmpnum = newpalette->col32[i2];
  216.                 //newpalette->col32[i2] = newpalette->col32[i];
  217.                 //newpalette->col32[i]  = tmpnum;
  218.  
  219.                 //swap
  220.                 //tmpnum = colfreq[i2];
  221.                 //colfreq[i2] = colfreq[i];
  222.                 //colfreq[i]  = tmpnum;
  223.                 swapdw(newpalette->col_32[i2],newpalette->col_32[i]);
  224.                 swapdw(colfreq[i2],colfreq[i]);
  225.             }  
  226.         }while(++i < uniquecolors);
  227.     }while(++i2 < uniquecolors);
  228.     */
  229.     //newpalette->
  230.     newpalette->size = uniquecolors;
  231.     newpalette->flags |= bitmap_32bit;
  232.     //realloc(newpalette->col32 , uniquecolors * 4);
  233.     TCR_UC_LB->setname(buildstr("Unique Colors:  %i",uniquecolors));
  234.     i=0;
  235.     //initialize bitmap and tile data
  236.     for(int i2 = 0; i2 <  ci_tilecount  ; i2++)    //&& i <1920 [for steve] i = 1966080 instead of under 1920 or ci_tilecount      
  237.     {  
  238.         //init bitmap data
  239.         tmp32bitbmp[i2].pixel  = tmpmem;
  240.         tmpmem += (ci_tilesize*4);
  241.         tmp32bitbmp[i2].width  = cellwidth;
  242.         tmp32bitbmp[i2].height = cellheight;
  243.         tmp32bitbmp[i2].pitch  = cellwidth + cellwidth;
  244.         tmp32bitbmp[i2].psize  = ci_tilesize;
  245.         tmp32bitbmp[i2].flags  = bitmap_32bit;
  246.        
  247.         //init links to NULL
  248.         newtiles32x32[i2]->toplist    = NULL;
  249.         newtiles32x32[i2]->rightlist  = NULL;
  250.         newtiles32x32[i2]->bottomlist = NULL;
  251.         newtiles32x32[i2]->leftlist   = NULL;
  252.         newtiles32x32[i2]->palnumber = 0;
  253.         newtiles32x32[i2]->pal  = newpalette;
  254.         newtiles32x32[i2]->size = cellwidth*2;
  255.         //newtiles32x32[i]->flags      = 0;
  256.         newtiles32x32[i2]->t_linkcount = 0;
  257.         newtiles32x32[i2]->r_linkcount = 0;
  258.         newtiles32x32[i2]->b_linkcount = 0;
  259.         newtiles32x32[i2]->l_linkcount = 0;
  260.         //set tiles source dir and file name
  261.         //newtiles32x32[i]->srcpathname = strdup(getcwd(0,0));
  262.         //newtiles32x32[i]->srcfilename = strdup(TCR_filename);
  263.     }
  264.  
  265.     //initialize tileset data
  266.     //newetileclusters[newtileclustercount]->pals = newpalette;
  267.     newetileset.clusters[newtileclustercount]->pals = newpalette;
  268.     //init bitmap data
  269.  
  270.     //init pixel transfer data
  271.     osi_addr32= si_addr32 = (dword*)TCR_BM->pixel; //X
  272.     ti_addr32 = (dword*)tmp32bitbmp[0].pixel;      //X
  273.     TCR_CO->setname("copying cells to tiles...");
  274.  
  275.     //process tiles
  276.     //dword tmp;
  277.    
  278.     i = 0;
  279.     do
  280.     {   ih = 0;
  281.         do  
  282.         {   //for(iw=0; ++iw < cellwidth; *ti_addr32++ = *si_addr32++);
  283.             iw = 0;
  284.             do
  285.             {   //copy & build checksum
  286.                 *ti_addr32 = *si_addr32;                    //unpalatized color copy
  287.                 newtiles32x32[i]->checksum += *si_addr32;   //checksum build
  288.                 dword tmp = (dword)*si_addr32;
  289.                 //msg(buildstr("%i",*si_addr32));
  290.                
  291.                 if((*si_addr32 & 0x00ffffff)==0 && !(newtiles32x32[i]->stdflags & TRANS))
  292.                 {   newtiles32x32[i]->stdflags |= TRANS; //black pixel/set transparent flag
  293.                 //  msg("trans");
  294.                     //*ti_addr32 = 0;//[note]edited out
  295.                 }
  296.  
  297.                 si_addr32++;
  298.                 ti_addr32++;
  299.                 //deduplicate(phase 1) & map
  300.             }while(++iw < cellwidth);
  301.             si_addr32 += nextrow;
  302.         }while(++ih < cellheight); //end 1 tile process
  303.         si_addr32 -= nextrow;
  304.         hl_rectx += cellwidth;
  305.        
  306.         //correct checksum for inflated images
  307.         if(TCR_S2X_CB->value) newtiles32x32[i]->checksum *= 2;
  308.    
  309.         /*
  310.         [note] this proves the tiles are copied properly initially
  311.         drawbitmap(&tmp32bitbmp[0],0,0);
  312.         update();
  313.         while(true);
  314.         */
  315.  
  316.         //end of row tile advance
  317.         if(++c_col > tilecols-1)
  318.         {   c_col = 0;
  319.             osi_addr32 = si_addr32 = si_addr32+rowjump;
  320.             hl_recty+=cellheight;
  321.             hl_rectx=TCR_CI->actx1 + 2;
  322.         }
  323.        
  324.         //normal tile advance
  325.         else osi_addr32 = si_addr32 = osi_addr32 + cellwidth;
  326.        
  327.         //check for uniqueness
  328.         i2 = 0;
  329.         bool tilematch = false;
  330.        
  331.         //test against new tiles
  332.         while(i2 < i) //do
  333.         {   //checksum match test
  334.             if(i != i2 && newtiles32x32[i]->checksum == newtiles32x32[i2]->checksum)
  335.             {   ddtstresult = ideduptest(&tmp32bitbmp[i],&tmp32bitbmp[i2],true,true);
  336.                 if(ddtstresult)
  337.                 {   tilematch = true;
  338.                     //if(i == 0)msg("0");
  339.                     //isunique[i] = false;         
  340.                     //note the flip value and use it for flagging that in the maps
  341.                     //but what if it's a flip of a tile in the map but a different flip of a tile
  342.                     //in the exisitng tileset ? gonna have to account for that
  343.                    
  344.                     //set sub map data
  345.                     submtileptr[i].id = newtiles32x32[i2]->id;
  346.                     //submtileptr[i].flipvalue = ddtstresult;
  347.                     tmpflipvalues[i]  = ddtstresult;
  348.                     gettileflips(&submtileptr[i],ddtstresult);     
  349.                     if(newtiles32x32[i2]->stdflags & TRANS)submtileptr[i].flags |=TRANS;
  350.                                    
  351.                     //find ID number for this tile, if it exists
  352.                     settarget(tsttile32);
  353.                     if(TCR_S2X_CB->value)
  354.                     {   scale32to32_2X(&tmp32bitbmp[i2]);
  355.                         newtiles32x32[i]->stdflags |= ETSCALED2X;
  356.                     }
  357.                     else
  358.                     {   //blt32to32(&tmp32bitbmp[i2],0,0);
  359.                         memcpy(tsttile32->pixel,tmp32bitbmp[i2].pixel,ci_tilesize*4);
  360.                    
  361.                     }
  362.                     settarget(NULL);
  363.                    
  364.                     i3 = 1;
  365.                     while(i3 < tilecount)
  366.                     {   settarget(tsttile32_2);
  367.                         drawetile32x32_32b(0,0,tilebank[i3]);
  368.                         settarget(NULL);
  369.                            
  370.                         ddtstresult = ideduptest(tsttile32,tsttile32_2,true,true);
  371.                         if(ddtstresult)
  372.                         {   submtileptr[i].id = i3;
  373.                             gettileflips(&submtileptr[i],ddtstresult);
  374.                             if(tilebank[i3]->stdflags & TRANS)submtileptr[i].flags |=TRANS;
  375.                    
  376.                         }
  377.                         i3++;
  378.                     }
  379.                    
  380.                     break;  //break since there is no need to find more matches    
  381.                 }
  382.                 else
  383.                 {   // rare case no pix match with color match
  384.                 }
  385.             }
  386.             i2++;
  387.         }//while(i2++ < i) ??
  388.  
  389.         if(tilematch)
  390.         {   //i++;
  391.             //continue;
  392.             //mark tile as a dup
  393.         }
  394.        
  395.         else //no match yet
  396.         {  
  397.             //dedup(phase2): test against all previous unique tiles
  398.             //scale tile image by X2
  399.             /*notes:
  400.                 -make sure the first cell is copied over to tsttile32
  401.                 -make sure that all pal colors register properly every time
  402.                 -
  403.                 -
  404.                 -
  405.                 -
  406.             */
  407.             settarget(tsttile32);
  408.             if(TCR_S2X_CB->value)
  409.             {      
  410.                 scale32to32_2X(&tmp32bitbmp[i2]);
  411.                 newtiles32x32[i]->stdflags |= ETSCALED2X;
  412.             }
  413.             else
  414.             {   memcpy(tsttile32->pixel,tmp32bitbmp[i2].pixel,ci_tilesize*4);
  415.            
  416.             }
  417.            
  418.             settarget(NULL);
  419.  
  420.             /*[note] this proves the first tile is being resized to 2X at this point
  421.             drawbitmap(tsttile32,0,0);
  422.             update();
  423.             if(i == 0)msg("0");
  424.             while(true);
  425.             */
  426.            
  427.             TCR_FT->image = tsttile32;
  428.            
  429.             i2=1;
  430.             //test against main tiles
  431.            
  432.             while(i2 < tilecount)
  433.             {   settarget(tsttile32_2);
  434.                 //drawetile32x32_32b(0,0,tilebank[i2]);
  435.                 settarget(NULL);
  436.        
  437.                 //convert old tile to 32 bit for testing
  438.                 ddtstresult = ideduptest(tsttile32,tsttile32_2,true,true);
  439.                 if(ddtstresult)
  440.                 {   tilematch = true;
  441.                 //  msg("match");
  442.                     //note the flip value and use it for flagging that in the maps
  443.                     //but what if it's a flip of a tile in the map but a differnt flip of a tile
  444.                     //in the exisitng tileset ? gonna have to account for that
  445.                     //msg("match");
  446.                     isunique[i] = false;   
  447.                     submtileptr[i].id = tilebank[i2]->id;
  448.                 //  submtileptr[i].flipvalue = ddtstresult;
  449.                     //newtiles32x32[uniquetiles]->id = uniquetiles;
  450.                     tmpflipvalues[i] = ddtstresult;
  451.                     gettileflips(&submtileptr[i],ddtstresult);
  452.                     if(tilebank[i2]->stdflags & TRANS)submtileptr[i].flags |=TRANS;
  453.                     break;  //break since there is no need to find more matches    
  454.                 }
  455.                 else
  456.                 {    isunique[i] = true;
  457.                 }
  458.                 //}//[x] end if
  459.                 i2++;
  460.             }
  461.            
  462.             if(!tilematch)
  463.             {   //if(i==0)msg("0 no tilematch"); this point is reached
  464.                 //increase unique tile amount
  465.                 //submtileptr[i].id = newtiles32x32[i]->id = uniquetiles;
  466.                 //
  467.                 newetileset.clusters[newtileclustercount]->numTiles = uniquetiles;
  468.                 dword tmp_id = newetileset.gettileid(newetileset.numclusters+1);
  469.                
  470.                 submtileptr[i].id = newtiles32x32[i]->id = tmp_id;
  471.                 TCR_UT_LB->setname(buildstr("Unique Tiles:   %i",uniquetiles));
  472.                 //newtiles32x32[uniquetiles]->id = uniquetiles;
  473.                 newtiles32x32[uniquetiles]->id = tmp_id;
  474.                
  475.                 //if(i==0)uniquetiles++;
  476.                 //if(uniquetiles)
  477.                 //{ if(i==0)msg("0 createtile");
  478.                     //8 bit palatize upscaled tile data to new tile
  479.                     byte  *tpadrr8    = newtiles32x32[uniquetiles]->pixel;
  480.                     dword *cpyaddrr32 = (dword*)tsttile32->pixel;
  481.                     //TCR_FT->image   = tsttile32;
  482.  
  483.                     iw = 0;
  484.                     do
  485.                     {   *tpadrr8++ = getpalentry32(newpalette,*cpyaddrr32++);
  486.                     }while(++iw < psize32X32);
  487.                 //}
  488.  
  489.                 uniquetiles++;
  490.                
  491.                
  492.             }//[x]
  493.             //process unique tile?
  494.         }
  495.  
  496.         //update gui
  497.         //TCR_CT->image = &tmp32bitbmp[i];
  498.         TCR_CT->image = &tmp32bitbmp[i];
  499.         TCR_PB->increment();
  500.         guiupdate();
  501.         //msg(buildstr("tile: %i",i));
  502.         //msg(buildstr("tile: %i",i));
  503.     }while(++i < ci_tilecount);
  504.     //TCR_CT->image = NULL;
  505.     tcr_cellhighlight = false;
  506.    
  507.    
  508.  
  509.     //[NOTE]
  510.     //handle metatiles
  511.     if(TCR_CMT_CB->value)
  512.     {   dword mtid=1;
  513.         //msg(buildstr("%i",tilerow));
  514.        
  515.         //for(i = 0; i < nummetatiles; i++)
  516.         //{ /*
  517.         //  newmetatiles[i]->tiles[0] = newtiles32x32[mtid];       
  518.         //  newmetatiles[i]->tiles[1] = newtiles32x32[mtid+1];
  519.         //  newmetatiles[i]->tiles[2] = newtiles32x32[mtid+tilerow];   
  520.         //  newmetatiles[i]->tiles[3] = newtiles32x32[mtid+tilerow+1];
  521.         //  */
  522.         //}
  523.         dword mtilerows = tilerows/2;
  524.         dword mtilecols = tilecols/2;
  525.         //msg(buildstr("mrow %i, mcol %i",mtilerows, mtilecols));
  526.  
  527.         i=0;
  528.         for(i2= 0; i2 < mtilerows; i2++)//caught
  529.         {   for(i3= 0; i3 < mtilecols; i3++)
  530.             {   newmetatiles[i]->id1       = mtid;     
  531.                 newmetatiles[i]->id2       = mtid+1;
  532.                 newmetatiles[i]->id3       = mtid+tilecols;
  533.                 newmetatiles[i]->id4     = mtid+tilecols+1;
  534.                 newmetatiles[i++]->flags = 0;
  535.                 mtid+=2;
  536.             }
  537.             mtid+=tilecols;
  538.         }
  539.     //  msg(buildstr("nummetatiles %i",i));
  540.     }
  541.  
  542.  
  543.    
  544.     //generate new tile link data
  545.     TCR_PB->value = 0;
  546.     TCR_CO->setname("Generating Tile Link DataBase...");
  547.     i  = 0;
  548.     ih = 0;
  549.     //seperate loops to avoid ifs ?
  550.     /*
  551.     do  
  552.     {   iw = 0;
  553.         do
  554.         {   //update right links
  555.             if(iw < tilecols-1)createtilelink(newtiles32x32[i],RIGHTLINK,newtiles32x32[i+1]->id,0);
  556.             //update left links
  557.             if(iw > 0)createtilelink(newtiles32x32[i],LEFTLINK,newtiles32x32[i-1]->id,0);
  558.             //update top links
  559.             if(ih > 0)createtilelink(newtiles32x32[i],TOPLINK,newtiles32x32[i-tilecols]->id,0);
  560.             //update bottom links
  561.             if(ih > tilerows-1)createtilelink(newtiles32x32[i],BOTTOMLINK,newtiles32x32[i+i+tilecols]->id,0);
  562.             i++;
  563.         TCR_PB->increment();        
  564.         guiupdate();                
  565.         //tiles32x32[i2]              
  566.         }while(++iw < tilecols);    
  567.     }while(++ih < tilerows);         //end 1 tile process
  568.     */
  569.     //createtilelink(editertile32x32 *tile,dword linktype, dword id,dword flipvalue)
  570.     //new
  571.     /*
  572.     do  
  573.     {   iw = 0;
  574.         do  
  575.         {   //update right links
  576.            
  577.             if(iw < tilecols-1) // use subtimes as tilelist instead of new tile
  578.                 newtiles32x32[i]->r_linkcount += createtilelink(&newtiles32x32[i]->rightlist,submtileptr[i+1].id,submtileptr[i+1].flags); //submtileptr instead of newtile
  579.             //update left links
  580.             if(iw > 0)
  581.                 newtiles32x32[i]->l_linkcount += createtilelink(&newtiles32x32[i]->leftlist,submtileptr[i-1].id,submtileptr[i-1].flags);
  582.             //update top links
  583.             if(ih > 0)
  584.                 newtiles32x32[i]->t_linkcount += createtilelink(&newtiles32x32[i]->toplist,submtileptr[i-tilecols].id,submtileptr[i-tilecols].flags);
  585.             //update bottom links
  586.             if(ih > tilerows-1)
  587.                 newtiles32x32[i]->b_linkcount += createtilelink(&newtiles32x32[i]->bottomlist,submtileptr[i+tilecols].id,submtileptr[i+tilecols].flags);
  588.             i++;
  589.         TCR_PB->increment();   
  590.         guiupdate();
  591.         }while(iw++ < tilecols);
  592.        
  593.     }while(ih++ < tilerows); //end 1 tile process
  594.     */
  595.     /*
  596.     do  
  597.     {   iw = 0;
  598.         do  
  599.         {   //update right links
  600.             if(i < uniquetiles)
  601.             {
  602.                
  603.                 if(iw < tilecols-1) // use subtimes as tilelist instead of new tile
  604.                     newtiles32x32[i]->r_linkcount += createtilelink(&newtiles32x32[submtileptr[i].id]->rightlist,submtileptr[i+1].id,submtileptr[i+1].flags); //submtileptr instead of newtile
  605.                 //update left links
  606.                 if(iw > 0)
  607.                 newtiles32x32[i]->l_linkcount += createtilelink(&newtiles32x32[submtileptr[i].id]->leftlist,submtileptr[i-1].id,submtileptr[i-1].flags);
  608.                 //update top links
  609.                 if(ih > 0)
  610.                 newtiles32x32[i]->t_linkcount += createtilelink(&newtiles32x32[submtileptr[i].id]->toplist,submtileptr[i-tilecols].id,submtileptr[i-tilecols].flags);
  611.                 //update bottom links
  612.                 if(ih > tilerows-1)
  613.                 newtiles32x32[i]->b_linkcount += createtilelink(&newtiles32x32[submtileptr[i].id]->bottomlist,submtileptr[i+tilecols].id,submtileptr[i+tilecols].flags);
  614.                
  615.                 //msg(buildstr("max %i, id %i",uniquetiles,submtileptr[i].id));
  616.             }
  617.             i++;
  618.         TCR_PB->increment();   
  619.         guiupdate();
  620.         }while(iw++ < tilecols);
  621.        
  622.     }while(ih++ < tilerows ); //end 1 tile process
  623.    
  624.     */
  625.    
  626.    
  627.    
  628.     // generate map
  629.     /*   
  630.         -store map ids as pointers to the actual tiles ids
  631.          *we will allready be pointing to the right numbers for ids from the main tiles by the end of the tile copy loop
  632.         -when perfectly new tiles are deleted we set their map values to point to a 0 value for no tile
  633.         -new tiles are in fact assigned their perminent id here when they are detected as new,
  634.             * to address the problem of what to do when a new tile with a perm id is deleted, just subtract all subsequent tile ids
  635.               for new tiles that followed that one by 1, that way the mini map ids will be updated automatically. problem solved.
  636.    */
  637.  /* i = 0;
  638.     do
  639.     {              
  640.  
  641.     }while(++i < ci_tilecount);
  642.    
  643.     // illiminate duplicates within the new batch of tiles
  644. //  TCR_CO->setname("deduplication (phase 1 : newtiles vs newtiles)...");
  645. /*CR_PB->value = 0;
  646.  
  647.     //free temp memory
  648.     TCR_CT->image = NULL;  
  649.    
  650.     free(tmpmem_head);
  651.  
  652.     //TSMaddnewtileset(newetilesets[newtilesetcount]);
  653.     /*
  654.     newetileclusters[newtileclustercount]->size          = TCR_CS_LC->value;
  655.     newetileclusters[newtileclustercount]->numTiles      = uniquetiles;
  656.     newetileclusters[newtileclustercount]->icontile32x32 = newtiles32x32[1];// change to 0
  657.     */
  658.     //handle pal data
  659.     paletteconvert(newpalette,bitmap_16bit);
  660.     etileset1.numpalettes++;
  661.  
  662.     newetileset.clusters[newtileclustercount]->size          = TCR_CS_LC->value;
  663.     newetileset.clusters[newtileclustercount]->numTiles      = uniquetiles;
  664.     newetileset.clusters[newtileclustercount]->numMetaTiles  = nummetatiles;
  665.     newetileset.clusters[newtileclustercount]->icontile32x32 = newtiles32x32[1];
  666.     newetileset.clusters[newtileclustercount]->icontileID    = 1;
  667.     newetileset.clusters[newtileclustercount]->id            = newtileclustercount;
  668.     newetileset.totaltiles += uniquetiles;
  669.  
  670.     newtileclustercount++;
  671.     newetileset.numclusters = newtileclustercount;
  672.    
  673.    
  674.  
  675.     //tksetmap(submapptr);
  676.     //}catch(...)
  677.     //{ msg("Tile cutter error", "generic");
  678.     //}
  679.     //TSM_P2->create
  680.     //updateWTSM_M2();
  681.     //msg("1");
  682.     //msg(buildstr("%i",newtiles32x32[0]->id));
  683.     //msg(buildstr("nummetatiles %i",nummetatiles));
  684.     updateWTSM_M2_2();
  685.     //TSM_MTM2->setItem1(0,buildstr("Name :\nSet    : %i [Temp]\nTiles  : %i",newtilesetcount,uniquetiles),tsmsetfolder,NULL,0);
  686.     //FEIMAGE *tmpimage = TSM_MTM2->menu1.components
  687.     showWTSM();
  688.    
  689. //  msg("end");
  690.     return;
  691. }
Add Comment
Please, Sign In to add comment