created skeletal implementation of png to xml converter
This commit is contained in:
parent
4039bad9f9
commit
b7834b08a5
@ -127,3 +127,10 @@ SET (LIBRARIES ${LIBRARIES} ${CMAKE_SOURCE_DIR}/extern/bullet/build/src/BulletSo
|
||||
|
||||
ADD_EXECUTABLE(${CMAKE_PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES} ${SHADER_FILES} ${README_FILES})
|
||||
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME} ${LIBRARIES})
|
||||
|
||||
FILE(GLOB_RECURSE SOURCE_FILES_CONV "${CMAKE_SOURCE_DIR}/converter/*.cc")
|
||||
SET(SOURCE_FILES_CONV ${SOURCE_FILES_CONV})
|
||||
|
||||
FILE(GLOB_RECURSE HEADER_FILES_CONV "${CMAKE_SOURCE_DIR}/converter/*.hh")
|
||||
SET(HEADER_FILES_CONV ${HEADER_FILES})
|
||||
ADD_EXECUTABLE(converter ${SOURCE_FILES_CONV} ${HEADER_FILES_CONV})
|
||||
|
28
converter/converter.cc
Normal file
28
converter/converter.cc
Normal file
@ -0,0 +1,28 @@
|
||||
#include "converter.hh"
|
||||
|
||||
Converter::Converter(){
|
||||
}
|
||||
|
||||
Converter::~Converter(){
|
||||
}
|
||||
|
||||
void Converter::updateComposition(unsigned int type, unsigned int idG, unsigned int idB, unsigned int posX, unsigned int posZ){
|
||||
//TODO
|
||||
}
|
||||
|
||||
|
||||
std::vector<unsigned int> Converter::newComposition(unsigned int type, unsigned int posX, unsigned int posZ){
|
||||
//TODO
|
||||
std::vector<unsigned int> ret = {0,0};
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Converter::deleteComposition(unsigned int idG, unsigned int idB){
|
||||
//TODO
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Converter::newObject(unsigned int type, unsigned int idG, unsigned int idB, unsigned int posX, unsigned int posZ){
|
||||
//TODO
|
||||
}
|
16
converter/converter.hh
Normal file
16
converter/converter.hh
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef CONVERTER_INCLUDED
|
||||
#define CONVERTER_INCLUDED
|
||||
#include <vector>
|
||||
|
||||
class Converter {
|
||||
public:
|
||||
Converter();
|
||||
~Converter();
|
||||
void updateComposition(unsigned int type, unsigned int idG, unsigned int idB, unsigned int posX, unsigned int posZ);
|
||||
std::vector<unsigned int> newComposition(unsigned int type, unsigned int posX, unsigned int posZ);
|
||||
void deleteComposition(unsigned int idG, unsigned int idB);
|
||||
|
||||
private:
|
||||
void newObject(unsigned int type, unsigned int idG, unsigned int idB, unsigned int posX, unsigned int posZ);
|
||||
};
|
||||
#endif
|
6096
converter/lodepng.cpp
Normal file
6096
converter/lodepng.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1702
converter/lodepng.h
Normal file
1702
converter/lodepng.h
Normal file
File diff suppressed because it is too large
Load Diff
69
converter/main.cc
Normal file
69
converter/main.cc
Normal file
@ -0,0 +1,69 @@
|
||||
#include "lodepng.h"
|
||||
#include <string>
|
||||
#include "converter.hh"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
//global variable level:
|
||||
unsigned int level;
|
||||
|
||||
int main( int argc, char *argv[] ){
|
||||
//TODO: always update this:
|
||||
unsigned int numLevels=1;
|
||||
Converter conv;
|
||||
//iterate over all Levels
|
||||
for (level=1; level<=numLevels; level++){
|
||||
bool idFound[256][256];
|
||||
for (int i=0; i<256; i++){
|
||||
for (int j=0; j<256; j++){
|
||||
idFound[i][j] = false;
|
||||
}
|
||||
}
|
||||
//read the setup png
|
||||
char levelChar[2];
|
||||
sprintf (levelChar,"%i", level);
|
||||
std::string levelString = levelChar;
|
||||
std::string filePath = "../Levels/setupLvl" + levelString + ".png";
|
||||
//printf("%s", filePath);
|
||||
std::vector<unsigned char> image; //the raw pixels
|
||||
unsigned int width, height;
|
||||
unsigned error = lodepng::decode(image, width, height, filePath);
|
||||
if (error) {
|
||||
std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl;
|
||||
}
|
||||
//iterate over all pixels of the image
|
||||
for(unsigned int rowNum = 0; rowNum < height; rowNum++){
|
||||
for(unsigned int columnNum = 0; columnNum < width; columnNum++){
|
||||
unsigned int pixel = (rowNum*width+columnNum)*4;
|
||||
//if there is a composition here, adjust the xml and image
|
||||
if(image[pixel]!=0){
|
||||
if(image[pixel+1]==0 && image[pixel+2]==0){
|
||||
std::vector<unsigned int> temp;
|
||||
temp = conv.newComposition(image[pixel], rowNum, columnNum);
|
||||
idFound[temp[0]][temp[1]] = true;
|
||||
image[pixel+1] = temp[0];
|
||||
image[pixel+2] = temp[1];
|
||||
}else{
|
||||
conv.updateComposition(image[pixel], image[pixel+1], image[pixel+2], rowNum, columnNum);
|
||||
idFound[image[pixel+1]][image[pixel+2]] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//write ids back to the setup png
|
||||
error = lodepng::encode(filePath, image, width, height);
|
||||
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++){
|
||||
for (int j=0; j<256; j++){
|
||||
if (idFound[i][j] == false){
|
||||
//TODO if (exists)?
|
||||
conv.deleteComposition(i,j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
level.cc
2
level.cc
@ -4,7 +4,7 @@
|
||||
|
||||
Level::Level(std::string filePath){
|
||||
this->filePath = filePath;
|
||||
this->terrain = Terrain(filePath + "/terrain");
|
||||
this->terrain = Terrain(filePath + "/terrain"); //TODO change this, fileSystem got reworked
|
||||
skyboxSize = 50.0f;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ void Terrain::load() {
|
||||
for(unsigned int rowNum = 0; rowNum < this->heightmapHeight; rowNum++){ //read in the heightmap
|
||||
this->heightmap[rowNum] = new float[this->heightmapWidth];
|
||||
for(unsigned int columnNum = 0; columnNum < this->heightmapWidth; columnNum++){
|
||||
this->heightmap[rowNum][columnNum] = (float)(image[(rowNum*heightmapWidth+columnNum)*4]) / 32;
|
||||
this->heightmap[rowNum][columnNum] = (float)(image[(rowNum*heightmapWidth+columnNum)*4]) / 32;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user