converter now takes the Level to convert as input

This commit is contained in:
Steffen Fündgens 2014-11-24 13:21:52 +01:00
parent 89a31c62b3
commit a4fc18f944
2 changed files with 45 additions and 53 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 B

View File

@ -4,64 +4,56 @@
#include <vector> #include <vector>
#include <iostream> #include <iostream>
//global variable level: int main( int argc, char *argv[] ){
unsigned int level; unsigned int level=atoi(argv[1]);
int main( int argc, char *argv[] ){
//TODO: always update this:
unsigned int numLevels=1;
Converter conv; Converter conv;
//iterate over all Levels bool idFound[256][256];
for (level=1; level<=numLevels; level++){ for (int i=0; i<256; i++){
bool idFound[256][256]; for (int j=0; j<256; j++){
for (int i=0; i<256; i++){ idFound[i][j] = false;
for (int j=0; j<256; j++){
idFound[i][j] = false;
}
} }
//read the setup png }
char levelChar[2]; //read the setup png
sprintf (levelChar,"%i", level); char levelChar[2];
std::string levelString = levelChar; sprintf (levelChar,"%i", level);
std::string filePath = "../Levels/setupLvl" + levelString + ".png"; std::string levelString = levelChar;
//printf("%s", filePath); std::string filePath = "../Levels/ObjectSetups/Lvl" + levelString + ".png";
std::vector<unsigned char> image; //the raw pixels std::vector<unsigned char> image; //the raw pixels
unsigned int width, height; unsigned int width, height;
unsigned error = lodepng::decode(image, width, height, filePath); unsigned error = lodepng::decode(image, width, height, filePath);
if (error) { if (error) {
std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl;
} }
//iterate over all pixels of the image //iterate over all pixels of the image
for(unsigned int rowNum = 0; rowNum < height; rowNum++){ for(unsigned int rowNum = 0; rowNum < height; rowNum++){
for(unsigned int columnNum = 0; columnNum < width; columnNum++){ for(unsigned int columnNum = 0; columnNum < width; columnNum++){
unsigned int pixel = (rowNum*width+columnNum)*4; unsigned int pixel = (rowNum*width+columnNum)*4;
//if there is a composition here, adjust the xml and image //if there is a composition here, adjust the xml and image
if(image[pixel]!=0){ if(image[pixel]!=0){
if(image[pixel+1]==0 && image[pixel+2]==0){ if(image[pixel+1]==0 && image[pixel+2]==0){
std::vector<unsigned int> temp; std::vector<unsigned int> temp;
temp = conv.newComposition(image[pixel], rowNum, columnNum); temp = conv.newComposition(image[pixel], rowNum, columnNum);
idFound[temp[0]][temp[1]] = true; idFound[temp[0]][temp[1]] = true;
image[pixel+1] = temp[0]; image[pixel+1] = temp[0];
image[pixel+2] = temp[1]; image[pixel+2] = temp[1];
}else{ }else{
conv.updateComposition(image[pixel], image[pixel+1], image[pixel+2], rowNum, columnNum); conv.updateComposition(image[pixel], image[pixel+1], image[pixel+2], rowNum, columnNum);
idFound[image[pixel+1]][image[pixel+2]] = true; idFound[image[pixel+1]][image[pixel+2]] = true;
}
} }
} }
} }
//write ids back to the setup png }
error = lodepng::encode(filePath, image, width, height); //write ids back to the setup png
if(error) { error = lodepng::encode(filePath, image, width, height);
std::cout << "encoder error " << error << ": "<< lodepng_error_text(error) << std::endl; if(error) {
} std::cout << "encoder error " << error << ": "<< lodepng_error_text(error) << std::endl;
//delete compositions that were not in the png anymore }
for (int i=0; i<256; i++){ //delete compositions that were not in the png anymore
for (int j=0; j<256; j++){ for (int i=0; i<256; i++){
if (idFound[i][j] == false){ for (int j=0; j<256; j++){
//TODO if (exists)? if (idFound[i][j] == false){
conv.deleteComposition(i,j); //TODO if (exists)?
} conv.deleteComposition(i,j);
} }
} }
} }