Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The application arrives at the following function seen below:
- void WorldMeshExporter::subDivideInGroups(TerrainManager *terrainManager, WorldHeader *header, WorldTile **tileList) {
- // This is the idea:
- // #0 - Retreive required data etc.
- // #1 - Scan for all the special corners and mark them.
- // #2 - For every marked tile we'll mark a line on the X and Y axis.
- // #0 - Retreive required data etc.
- unsigned int worldWidth = header->width;
- unsigned int worldHeight = header->height;
- // #1 - Scan for all the special corners and mark them.
- for(int i = 0; i < worldWidth; i++) {
- for(int j = 0; j < worldHeight; j++) {
- char tileType = terrainManager->getTileType(i, j);
- // Determine whether to save the tileType or not.
- if (tileType >= 6 && tileType <= 10) {
- tileMaskX[i][j] = 2;
- tileMaskY[i][j] = 2;
- }
- }
- }
- // #2 - For every marked "corner tile" we'll mark a line on the X and Y axis.
- for(int i = 0; i < worldWidth; i++) {
- for(int j = 0; j < worldHeight; j++) {
- // Mark a line on both Axis' in case there is a corner tile.
- if (tileMaskX[i][j] == 2) {
- markLines(tileMaskX, 1, true, true, false, i, j, 0, 0, worldWidth, worldHeight);
- markLines(tileMaskY, 1, true, false, true, i, j, 0, 0, worldWidth, worldHeight);
- }
- }
- }
- /////////////
- // X - DEBUG
- ////////////
- std::ofstream filex;
- filex.open("tileMaskX.txt");
- for(int i = 0; i < header->width; i++) {
- for(int j = 0; j < header->height; j++) {
- int length = 4 - stringc(tileMaskX[i][j]).size();
- for(int k = 0; k < length; k++) {
- filex << " ";
- }
- filex << tileMaskX[i][j];
- }
- filex << std::endl;
- }
- filex.close();
- /////////////
- // Y - DEBUG
- ////////////
- std::ofstream filey;
- filey.open("tileMaskY.txt");
- for(int i = 0; i < header->width; i++) {
- for(int j = 0; j < header->height; j++) {
- int length = 4 - stringc(tileMaskY[i][j]).size();
- for(int k = 0; k < length; k++) {
- filey << " ";
- }
- filey << tileMaskY[i][j];
- }
- filey << std::endl;
- }
- filey.close();
- }
- // markLines : Mark a line across the given axis.
- 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) {
- //==================================================================//
- // X-Axis. //
- //==================================================================//
- if (xAxis == true && x >= minX && x < maxX) {
- // Draw the line from x to the left.
- for(int i = x; i >= minX; i--) {
- // In case of "overWriteZeroOnly", we only want to overwrite tilemasks that are zero.
- if (overWriteZeroOnly == true && tileMask[i][y] == 0) {
- tileMask[i][y] = value;
- } else if (overWriteZeroOnly == false) {
- tileMask[i][y] = value;
- }
- }
- // Draw the line from x to the right.
- for(int i = x; i < maxX; i++) {
- // In case of "overWriteZeroOnly", we only want to overwrite tilemasks that are zero.
- if (overWriteZeroOnly == true && tileMask[i][y] == 0) {
- tileMask[i][y] = value;
- } else if (overWriteZeroOnly == false) {
- tileMask[i][y] = value;
- }
- }
- }
- //==================================================================//
- // Y-Axis. //
- //==================================================================//
- if (yAxis == true && y >= minY && y < maxY) {
- // Draw the line from y to the top.
- for(int i = y; i >= minY; i--) {
- // In case of "overWriteZeroOnly", we only want to overwrite tilemasks that are zero.
- if (overWriteZeroOnly == true && tileMask[x][i] == 0) {
- tileMask[x][i] = value;
- } else if (overWriteZeroOnly == false) {
- tileMask[x][i] = value;
- }
- }
- // Draw the line from y to the bottom.
- for(int i = y; i < maxY; i++) {
- // In case of "overWriteZeroOnly", we only want to overwrite tilemasks that are zero.
- if (overWriteZeroOnly == true && tileMask[x][i] == 0) {
- tileMask[x][i] = value;
- } else if (overWriteZeroOnly == false) {
- tileMask[x][i] = value;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment