Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Take in a list of strings (one per block) and make an actual room
- Room* CreateRoomFromStrings(vector<string> s) {
- // Get room dimensions from data
- const char* c;
- c = s[1].c_str(); // Convert to old fashioned string
- int sizeX = atoi(c); // "to long"
- printf("X size is %d\n", sizeX);
- c = s[2].c_str(); // Convert to old fashioned string
- int sizeY = atoi(c); // "to long"
- printf("Y size is %d\n", sizeY);
- c = s[3].c_str(); // Convert to old fashioned string
- int sizeZ = atoi(c); // "to long"
- printf("Z size is %d\n", sizeZ);
- // Create block array based on data
- // for (int i = 0; i < s[1].size(); i ++) {
- // printf("Character %d = %c\n", i, s[1][i]);
- // }
- block* b[sizeX * sizeY * sizeZ];
- char type;
- char scratch;
- bool swap[3];
- bool flip[3];
- block* newBlock;
- int blockCount = 0;
- int cubes = 0;
- int ramps = 0;
- int empty = 0;
- int blockX;
- int blockY;
- int blockZ;
- for (int i = 4; i < s.size(); i ++) {
- // Get type
- type = s[i][0];
- // Get axis swaps
- for (int i2 = 0; i2 < 3; i2 ++) {
- swap[i2] = (s[i][i2 + 1] == 's');
- }
- // Get axis flips
- for (int i2 = 0; i2 < 3; i2 ++) {
- flip[i2] = (s[i][i2 + 4] == 'f');
- }
- //printf("Type = %c\n", type);
- // Create one block
- blockZ = blockCount / (sizeX * sizeY);
- blockY = (blockCount % (sizeX * sizeY)) / sizeX;
- blockX = (blockCount % (sizeX * sizeY)) % sizeX;
- if (type == 49) {
- // printf("Block %d:\n", i);
- // printf("Creating cube\n");
- // printf("Flip state: %d %d %d\n", flip[0], flip[1], flip[2]);
- // printf("Swap state: %d %d %d\n", swap[0], flip[1], flip[2]);
- newBlock = new block(blockX, blockY, blockZ, CUBE);
- b[blockCount] = newBlock;
- cubes ++;
- }
- else if (type == 50) {
- // printf("Block %d:\n", i);
- // printf("Creating ramp\n");
- // printf("Flip state: %d %d %d\n", flip[0], flip[1], flip[2]);
- // printf("Swap state: %d %d %d\n", swap[0], flip[1], flip[2]);
- newBlock = new block(blockX, blockY, blockZ, CUBE);
- b[blockCount] = newBlock;
- ramps ++;
- }
- else {
- b[blockCount] = NULL;
- // What do we do for empty cells?
- // Are null pointers okay?
- /*
- Perhaps we want objects for empty cells.
- We do want to store lighting information,
- and perhaps there will be other things
- we'll want to store later
- It seems heavy, though.
- */
- // printf("Block %d:\n", i);
- // printf("Creating empty cell\n");
- empty ++;
- }
- blockCount ++;
- }
- printf("\n\n%d cubes, %d ramps, %d empty cells\n", cubes, ramps, empty);
- Room* room = new Room(b, sizeX, sizeY, sizeZ);
- return room;
- }
Advertisement
Add Comment
Please, Sign In to add comment