Skip to main content
Rollback to Revision 2
Source Link
user35344
user35344

Tilemap data is stored in a 2D array.

It is saved using the following pseudocodecode

FUNCTION
void SAVEChunk::save_to_file() {
OPEN FILE   
FOR I, J, IN 2D// ARRAYFILENAME
WRITE 2D_ARRAY[I, J] TO FILEstd::string filename = std::to_string(chunk_seed);
WRITE
    std::fstream file;
    file.open(filename + ".chunk", std::ios::out);

    for (int i = 0; i < Constants::BIOMESIZE; i++) {
        for (int j = 0; j < Constants::BIOMESIZE; j++) {
            file << std::to_string(chunk[i][j]);
            file << ",";
 TO FILE      }
CLOSE FILE   }
END 
 FUNCTION   file.close();
    
}


And it is loaded using the following pseudocodecode

FUNCTION
void LOADChunk::load_from_file() {
OPEN FILE   // FILENAME
READ DATA   // The chunk will be located at hash(chunk_x, chunk_y) ^ seed = chunk_seed
SPLIT DATA BY GIVEN DELIMITERstd::string INTOfilename 1D= ARRAYstd::to_string(chunk_seed);
FOR I, J  // Data within file
    std::string data;

    std::fstream file;
    file.open(filename + ".chunk", INstd::ios::in);
 2D DATA ARRAY file >> data;
2D_ARRAY[I    file.close();

    std::vector<std::string> tokens = split(data, J]',');
    
    for (unsigned int i = SPLITTED_DATA[I0; i < Constants::BIOMESIZE; i++) {
        for (unsigned int j = 0; j < Constants::BIOMESIZE; j++) {
            chunk[i][j] = std::stoi(tokens[i + Jj * 2D_ARRAY_DIMENSION]Constants::BIOMESIZE]);
        }
    }
}

Assuming a square 2D array.

Tilemaps are loaded using the loading function when the program is started up and displayed.

Tilemaps are saved using the saving function when the program is exited.

They do not display the same way each time.

I have pinpointed that the problem is in the saving function.

This is because I commented out the saving part and when I was only loading the same files it worked and had the same output each time.

It appears as though the saving function rotates the tilemap by 180 degrees each time I save it.

How can this be fixed?

Tilemap data is stored in a 2D array.

It is saved using the following pseudocode

FUNCTION SAVE
OPEN FILE
FOR I, J, IN 2D ARRAY
WRITE 2D_ARRAY[I, J] TO FILE
WRITE "," TO FILE
CLOSE FILE
END FUNCTION

And it is loaded using the following pseudocode

FUNCTION LOAD
OPEN FILE
READ DATA
SPLIT DATA BY GIVEN DELIMITER INTO 1D ARRAY
FOR I, J, IN 2D DATA ARRAY
2D_ARRAY[I, J] = SPLITTED_DATA[I + J * 2D_ARRAY_DIMENSION]

Assuming a square 2D array.

Tilemaps are loaded using the loading function when the program is started up and displayed.

Tilemaps are saved using the saving function when the program is exited.

They do not display the same way each time.

I have pinpointed that the problem is in the saving function.

This is because I commented out the saving part and when I was only loading the same files it worked and had the same output each time.

It appears as though the saving function rotates the tilemap by 180 degrees each time I save it.

How can this be fixed?

Tilemap data is stored in a 2D array.

It is saved using the following code


void Chunk::save_to_file() {
    
    // FILENAME
    std::string filename = std::to_string(chunk_seed);

    std::fstream file;
    file.open(filename + ".chunk", std::ios::out);

    for (int i = 0; i < Constants::BIOMESIZE; i++) {
        for (int j = 0; j < Constants::BIOMESIZE; j++) {
            file << std::to_string(chunk[i][j]);
            file << ",";
        }
    }
 
    file.close();
    
}


And it is loaded using the following code


void Chunk::load_from_file() {
    // FILENAME
    // The chunk will be located at hash(chunk_x, chunk_y) ^ seed = chunk_seed
    std::string filename = std::to_string(chunk_seed);
    // Data within file
    std::string data;

    std::fstream file;
    file.open(filename + ".chunk", std::ios::in);
    file >> data;
    file.close();

    std::vector<std::string> tokens = split(data, ',');
    
    for (unsigned int i = 0; i < Constants::BIOMESIZE; i++) {
        for (unsigned int j = 0; j < Constants::BIOMESIZE; j++) {
            chunk[i][j] = std::stoi(tokens[i + j * Constants::BIOMESIZE]);
        }
    }
}

Tilemaps are loaded using the loading function when the program is started up and displayed.

Tilemaps are saved using the saving function when the program is exited.

They do not display the same way each time.

I have pinpointed that the problem is in the saving function.

This is because I commented out the saving part and when I was only loading the same files it worked and had the same output each time.

It appears as though the saving function rotates the tilemap by 180 degrees each time I save it.

How can this be fixed?

deleted 623 characters in body
Source Link

Tilemap data is stored in a 2D array.

It is saved using the following codepseudocode


void Chunk::save_to_file() {
    
    // FILENAME
    std::string filename =FUNCTION std::to_string(chunk_seed);
SAVE
    std::fstreamOPEN file;FILE
    file.open(filename +FOR ".chunk"I, std::ios::out);

    for (int i = 0; i < Constants::BIOMESIZE; i++) {
        for (int j = 0; j <J, Constants::BIOMESIZE;IN j++)2D {ARRAY
          WRITE 2D_ARRAY[I, fileJ] <<TO std::to_string(chunk[i][j]);FILE
            file <<WRITE ",";
        }
  " TO }
FILE
   CLOSE file.close();FILE
   END 
}

FUNCTION

And it is loaded using the following codepseudocode


void Chunk::load_from_file() {
    // FILENAME
    // The chunk will be located at hash(chunk_x, chunk_y) ^ seed = chunk_seed
    std::string filename = std::to_string(chunk_seed);
    // Data within file
    std::stringFUNCTION data;
LOAD
    std::fstreamOPEN file;FILE
    file.open(filename + ".chunk",READ std::ios::in);DATA
   SPLIT fileDATA >>BY data;
GIVEN DELIMITER INTO 1D file.close();
ARRAY
    std::vector<std::string> tokens =FOR split(dataI, 'J,');
    
    for (unsigned int i = 0; i < Constants::BIOMESIZE; i++) {
        for (unsigned int j = 0; j <IN Constants::BIOMESIZE;2D j++)DATA {ARRAY
           2D_ARRAY[I, chunk[i][j]J] = std::stoi(tokens[iSPLITTED_DATA[I + jJ * Constants::BIOMESIZE]);
        }
    }
}
2D_ARRAY_DIMENSION]

Assuming a square 2D array.

Tilemaps are loaded using the loading function when the program is started up and displayed.

Tilemaps are saved using the saving function when the program is exited.

They do not display the same way each time.

I have pinpointed that the problem is in the saving function.

This is because I commented out the saving part and when I was only loading the same files it worked and had the same output each time.

It appears as though the saving function rotates the tilemap by 180 degrees each time I save it.

How can this be fixed?

Tilemap data is stored in a 2D array.

It is saved using the following code


void Chunk::save_to_file() {
    
    // FILENAME
    std::string filename = std::to_string(chunk_seed);

    std::fstream file;
    file.open(filename + ".chunk", std::ios::out);

    for (int i = 0; i < Constants::BIOMESIZE; i++) {
        for (int j = 0; j < Constants::BIOMESIZE; j++) {
            file << std::to_string(chunk[i][j]);
            file << ",";
        }
    }

    file.close();
    
}


And it is loaded using the following code


void Chunk::load_from_file() {
    // FILENAME
    // The chunk will be located at hash(chunk_x, chunk_y) ^ seed = chunk_seed
    std::string filename = std::to_string(chunk_seed);
    // Data within file
    std::string data;

    std::fstream file;
    file.open(filename + ".chunk", std::ios::in);
    file >> data;
    file.close();

    std::vector<std::string> tokens = split(data, ',');
    
    for (unsigned int i = 0; i < Constants::BIOMESIZE; i++) {
        for (unsigned int j = 0; j < Constants::BIOMESIZE; j++) {
            chunk[i][j] = std::stoi(tokens[i + j * Constants::BIOMESIZE]);
        }
    }
}

Tilemaps are loaded using the loading function when the program is started up and displayed.

Tilemaps are saved using the saving function when the program is exited.

They do not display the same way each time.

I have pinpointed that the problem is in the saving function.

This is because I commented out the saving part and when I was only loading the same files it worked and had the same output each time.

It appears as though the saving function rotates the tilemap by 180 degrees each time I save it.

How can this be fixed?

Tilemap data is stored in a 2D array.

It is saved using the following pseudocode

FUNCTION SAVE
OPEN FILE
FOR I, J, IN 2D ARRAY
WRITE 2D_ARRAY[I, J] TO FILE
WRITE "," TO FILE
CLOSE FILE
END FUNCTION

And it is loaded using the following pseudocode

FUNCTION LOAD
OPEN FILE
READ DATA
SPLIT DATA BY GIVEN DELIMITER INTO 1D ARRAY
FOR I, J, IN 2D DATA ARRAY
2D_ARRAY[I, J] = SPLITTED_DATA[I + J * 2D_ARRAY_DIMENSION]

Assuming a square 2D array.

Tilemaps are loaded using the loading function when the program is started up and displayed.

Tilemaps are saved using the saving function when the program is exited.

They do not display the same way each time.

I have pinpointed that the problem is in the saving function.

This is because I commented out the saving part and when I was only loading the same files it worked and had the same output each time.

It appears as though the saving function rotates the tilemap by 180 degrees each time I save it.

How can this be fixed?

added 802 characters in body
Source Link

Tilemap data is stored in a 2D array.

It is saved using the following code

enter image description here


void Chunk::save_to_file() {
    
    // FILENAME
    std::string filename = std::to_string(chunk_seed);

    std::fstream file;
    file.open(filename + ".chunk", std::ios::out);

    for (int i = 0; i < Constants::BIOMESIZE; i++) {
        for (int j = 0; j < Constants::BIOMESIZE; j++) {
            file << std::to_string(chunk[i][j]);
            file << ",";
        }
    }

    file.close();
    
}


And it is loaded using the following code

enter image description here


void Chunk::load_from_file() {
    // FILENAME
    // The chunk will be located at hash(chunk_x, chunk_y) ^ seed = chunk_seed
    std::string filename = std::to_string(chunk_seed);
    // Data within file
    std::string data;

    std::fstream file;
    file.open(filename + ".chunk", std::ios::in);
    file >> data;
    file.close();

    std::vector<std::string> tokens = split(data, ',');
    
    for (unsigned int i = 0; i < Constants::BIOMESIZE; i++) {
        for (unsigned int j = 0; j < Constants::BIOMESIZE; j++) {
            chunk[i][j] = std::stoi(tokens[i + j * Constants::BIOMESIZE]);
        }
    }
}

Tilemaps are loaded using the loading function when the program is started up and displayed.

Tilemaps are saved using the saving function when the program is exited.

They do not display the same way each time.

I have pinpointed that the problem is in the saving function.

This is because I commented out the saving part and when I was only loading the same files it worked and had the same output each time.

It appears as though the saving function rotates the tilemap by 180 degrees each time I save it.

How can this be fixed?

Tilemap data is stored in a 2D array.

It is saved using the following code

enter image description here

And it is loaded using the following code

enter image description here

Tilemaps are loaded using the loading function when the program is started up and displayed.

Tilemaps are saved using the saving function when the program is exited.

They do not display the same way each time.

I have pinpointed that the problem is in the saving function.

This is because I commented out the saving part and when I was only loading the same files it worked and had the same output each time.

It appears as though the saving function rotates the tilemap by 180 degrees each time I save it.

How can this be fixed?

Tilemap data is stored in a 2D array.

It is saved using the following code


void Chunk::save_to_file() {
    
    // FILENAME
    std::string filename = std::to_string(chunk_seed);

    std::fstream file;
    file.open(filename + ".chunk", std::ios::out);

    for (int i = 0; i < Constants::BIOMESIZE; i++) {
        for (int j = 0; j < Constants::BIOMESIZE; j++) {
            file << std::to_string(chunk[i][j]);
            file << ",";
        }
    }

    file.close();
    
}


And it is loaded using the following code


void Chunk::load_from_file() {
    // FILENAME
    // The chunk will be located at hash(chunk_x, chunk_y) ^ seed = chunk_seed
    std::string filename = std::to_string(chunk_seed);
    // Data within file
    std::string data;

    std::fstream file;
    file.open(filename + ".chunk", std::ios::in);
    file >> data;
    file.close();

    std::vector<std::string> tokens = split(data, ',');
    
    for (unsigned int i = 0; i < Constants::BIOMESIZE; i++) {
        for (unsigned int j = 0; j < Constants::BIOMESIZE; j++) {
            chunk[i][j] = std::stoi(tokens[i + j * Constants::BIOMESIZE]);
        }
    }
}

Tilemaps are loaded using the loading function when the program is started up and displayed.

Tilemaps are saved using the saving function when the program is exited.

They do not display the same way each time.

I have pinpointed that the problem is in the saving function.

This is because I commented out the saving part and when I was only loading the same files it worked and had the same output each time.

It appears as though the saving function rotates the tilemap by 180 degrees each time I save it.

How can this be fixed?

Source Link
Loading