Guest User

Untitled

a guest
Dec 11th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.14 KB | None | 0 0
  1. // The application arrives at the following function seen below:
  2. void WorldMeshExporter::subDivideInGroups(TerrainManager *terrainManager, WorldHeader *header, WorldTile **tileList) {
  3.     // This is the idea:
  4.     // #0 - Retreive required data etc.
  5.     // #1 - Scan for all the special corners and mark them.
  6.     // #2 - For every marked tile we'll mark a line on the X and Y axis.
  7.  
  8.     // #0 - Retreive required data etc.
  9.     unsigned int worldWidth     = header->width;
  10.     unsigned int worldHeight    = header->height;
  11.  
  12.     // #1 - Scan for all the special corners and mark them.
  13.     for(int i = 0; i < worldWidth; i++) {
  14.         for(int j = 0; j < worldHeight; j++) {
  15.             char tileType   = terrainManager->getTileType(i, j);
  16.  
  17.             // Determine whether to save the tileType or not.
  18.             if (tileType >= 6 && tileType <= 10) {
  19.                 tileMaskX[i][j] = 2;
  20.                 tileMaskY[i][j] = 2;
  21.             }
  22.         }
  23.     }
  24.    
  25.     // #2 - For every marked "corner tile" we'll mark a line on the X and Y axis.
  26.     for(int i = 0; i < worldWidth; i++) {
  27.         for(int j = 0; j < worldHeight; j++) {
  28.             // Mark a line on both Axis' in case there is a corner tile.
  29.             if (tileMaskX[i][j] == 2) {
  30.                 markLines(tileMaskX, 1, true, true, false, i, j, 0, 0, worldWidth, worldHeight);
  31.                 markLines(tileMaskY, 1, true, false, true, i, j, 0, 0, worldWidth, worldHeight);
  32.             }
  33.         }
  34.     }
  35.    
  36.     /////////////
  37.     // X - DEBUG
  38.     ////////////
  39.     std::ofstream filex;
  40.     filex.open("tileMaskX.txt");
  41.  
  42.     for(int i = 0; i < header->width; i++) {
  43.         for(int j = 0; j < header->height; j++) {  
  44.             int length = 4 - stringc(tileMaskX[i][j]).size();
  45.  
  46.             for(int k = 0; k < length; k++) {
  47.                 filex << " ";
  48.             }
  49.  
  50.             filex << tileMaskX[i][j];
  51.         }
  52.         filex << std::endl;
  53.     }
  54.     filex.close();
  55.     /////////////
  56.     // Y - DEBUG
  57.     ////////////
  58.     std::ofstream filey;
  59.     filey.open("tileMaskY.txt");
  60.  
  61.     for(int i = 0; i < header->width; i++) {
  62.         for(int j = 0; j < header->height; j++) {  
  63.             int length = 4 - stringc(tileMaskY[i][j]).size();
  64.  
  65.             for(int k = 0; k < length; k++) {
  66.                 filey << " ";
  67.             }
  68.  
  69.             filey << tileMaskY[i][j];
  70.         }
  71.         filey << std::endl;
  72.     }
  73.     filey.close();
  74. }
  75.  
  76. // markLines : Mark a line across the given axis.
  77. void WorldMeshExporter::markLines(long **tileMask, long value, bool overWriteZeroOnly, bool xAxis, bool yAxis, int x, int y, int minX, int minY, int maxX, int maxY) {
  78.     //==================================================================//
  79.     // X-Axis.                                                          //
  80.     //==================================================================//
  81.     if (xAxis == true && x >= minX && x < maxX) {
  82.         // Draw the line from x to the left.
  83.         for(int i = x; i >= minX; i--) {
  84.             // In case of "overWriteZeroOnly", we only want to overwrite tilemasks that are zero.
  85.             if (overWriteZeroOnly == true && tileMask[i][y] == 0) {
  86.                 tileMask[i][y] = value;
  87.             } else if (overWriteZeroOnly == false) {
  88.                 tileMask[i][y] = value;
  89.             }
  90.         }
  91.  
  92.         // Draw the line from x to the right.
  93.         for(int i = x; i < maxX; i++) {
  94.             // In case of "overWriteZeroOnly", we only want to overwrite tilemasks that are zero.
  95.             if (overWriteZeroOnly == true && tileMask[i][y] == 0) {
  96.                 tileMask[i][y] = value;
  97.             } else if (overWriteZeroOnly == false) {
  98.                 tileMask[i][y] = value;
  99.             }
  100.         }
  101.     }
  102.  
  103.     //==================================================================//
  104.     // Y-Axis.                                                          //
  105.     //==================================================================//
  106.     if (yAxis == true && y >= minY && y < maxY) {
  107.         // Draw the line from y to the top.
  108.         for(int i = y; i >= minY; i--) {
  109.             // In case of "overWriteZeroOnly", we only want to overwrite tilemasks that are zero.
  110.             if (overWriteZeroOnly == true && tileMask[x][i] == 0) {
  111.                 tileMask[x][i] = value;
  112.             } else if (overWriteZeroOnly == false) {
  113.                 tileMask[x][i] = value;
  114.             }
  115.         }
  116.  
  117.         // Draw the line from y to the bottom.
  118.         for(int i = y; i < maxY; i++) {
  119.             // In case of "overWriteZeroOnly", we only want to overwrite tilemasks that are zero.
  120.             if (overWriteZeroOnly == true && tileMask[x][i] == 0) {
  121.                 tileMask[x][i] = value;
  122.             } else if (overWriteZeroOnly == false) {
  123.                 tileMask[x][i] = value;
  124.             }
  125.         }
  126.     }
  127. }
Add Comment
Please, Sign In to add comment