Guest User

Untitled

a guest
Jul 5th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.03 KB | None | 0 0
  1. // Take in a list of strings (one per block) and make an actual room
  2. Room* CreateRoomFromStrings(vector<string> s) {
  3.     // Get room dimensions from data
  4.     const char* c;
  5.     c = s[1].c_str(); // Convert to old fashioned string
  6.     int sizeX = atoi(c); // "to long"
  7.     printf("X size is %d\n", sizeX);
  8.     c = s[2].c_str(); // Convert to old fashioned string
  9.     int sizeY = atoi(c); // "to long"
  10.     printf("Y size is %d\n", sizeY);
  11.     c = s[3].c_str(); // Convert to old fashioned string
  12.     int sizeZ = atoi(c); // "to long"
  13.     printf("Z size is %d\n", sizeZ);
  14.  
  15.     // Create block array based on data
  16. //    for (int i = 0; i < s[1].size(); i ++) {
  17. //        printf("Character %d = %c\n", i, s[1][i]);
  18. //    }
  19.     block* b[sizeX * sizeY * sizeZ];
  20.     char type;
  21.     char scratch;
  22.     bool swap[3];
  23.     bool flip[3];
  24.     block* newBlock;
  25.     int blockCount = 0;
  26.     int cubes = 0;
  27.     int ramps = 0;
  28.     int empty = 0;
  29.     int blockX;
  30.     int blockY;
  31.     int blockZ;
  32.     for (int i = 4; i < s.size(); i ++) {
  33.         // Get type
  34.         type = s[i][0];
  35.         // Get axis swaps
  36.         for (int i2 = 0; i2 < 3; i2 ++) {
  37.             swap[i2] = (s[i][i2 + 1] == 's');
  38.         }
  39.         // Get axis flips
  40.         for (int i2 = 0; i2 < 3; i2 ++) {
  41.             flip[i2] = (s[i][i2 + 4] == 'f');
  42.         }
  43.         //printf("Type = %c\n", type);
  44.         // Create one block
  45.         blockZ = blockCount / (sizeX * sizeY);
  46.         blockY = (blockCount % (sizeX * sizeY)) / sizeX;
  47.         blockX = (blockCount % (sizeX * sizeY)) % sizeX;
  48.         if (type == 49) {
  49. //            printf("Block %d:\n", i);
  50. //            printf("Creating cube\n");
  51. //            printf("Flip state: %d %d %d\n", flip[0], flip[1], flip[2]);
  52. //            printf("Swap state: %d %d %d\n", swap[0], flip[1], flip[2]);
  53.             newBlock = new block(blockX, blockY, blockZ, CUBE);
  54.             b[blockCount] = newBlock;
  55.             cubes ++;
  56.         }
  57.         else if (type == 50) {
  58. //            printf("Block %d:\n", i);
  59. //            printf("Creating ramp\n");
  60. //            printf("Flip state: %d %d %d\n", flip[0], flip[1], flip[2]);
  61. //            printf("Swap state: %d %d %d\n", swap[0], flip[1], flip[2]);
  62.             newBlock = new block(blockX, blockY, blockZ, CUBE);
  63.             b[blockCount] = newBlock;
  64.             ramps ++;
  65.         }
  66.         else {
  67.             b[blockCount] = NULL;
  68.             // What do we do for empty cells?
  69.             // Are null pointers okay?
  70.             /*
  71.             Perhaps we want objects for empty cells.
  72.             We do want to store lighting information,
  73.             and perhaps there will be other things
  74.             we'll want to store later
  75.             It seems heavy, though.
  76.             */
  77. //            printf("Block %d:\n", i);
  78. //            printf("Creating empty cell\n");
  79.             empty ++;
  80.         }
  81.         blockCount ++;
  82.     }
  83.     printf("\n\n%d cubes, %d ramps, %d empty cells\n", cubes, ramps, empty);
  84.     Room* room = new Room(b, sizeX, sizeY, sizeZ);
  85.     return room;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment