void Tileset::addSurfTex(int leftUp, int rightUp, int leftDown, int rightDown, Vec2f &coord, const Texture2D *&texture) { //center textures if(leftUp == rightUp && leftUp == leftDown && leftUp == rightDown) { //texture variation according to probability float r= random.randRange(0.f, 1.f); int var= 0; float max= 0.f; for(int i=0; i < surfProbs[leftUp].size(); ++i) { max+= surfProbs[leftUp][i]; if(r <= max) { var= i; break; } } SurfaceInfo si(getSurfPixmap(leftUp, var)); surfaceAtlas.addSurface(&si); coord= si.getCoord(); texture= si.getTexture(); } //spatted textures else { int var= random.randRange(0, transitionVars); SurfaceInfo si( getSurfPixmap(leftUp, var), getSurfPixmap(rightUp, var), getSurfPixmap(leftDown, var), getSurfPixmap(rightDown, var)); surfaceAtlas.addSurface(&si); coord= si.getCoord(); texture= si.getTexture(); } }
void Tileset::addSurfTex(int leftUp, int rightUp, int leftDown, int rightDown, Vec2f &coord, const Texture2D *&texture, int mapX, int mapY) { //center textures if(leftUp == rightUp && leftUp == leftDown && leftUp == rightDown) { //texture variation according to probability float r= random.randRange(0.f, 1.f); int var= 0; float max= 0.f; const Pixmap2D* pixmap; if(surfProbs[leftUp][0]<0) {// big textures use coordinates int parts=partsArray[leftUp]; pixmap=getSurfPixmap(leftUp, (mapY%parts)*parts+(mapX%parts)); } else{ for(int i=0; i < surfProbs[leftUp].size(); ++i) { max+= surfProbs[leftUp][i]; if(r <= max) { var= i; break; } } pixmap=getSurfPixmap(leftUp, var); } SurfaceInfo si(pixmap); surfaceAtlas.addSurface(&si); coord= si.getCoord(); // only for 512px printf("coord.x=%f coord.y=%f mapX=%d mapY=%d result=%d\n",coord.x,coord.y,mapX,mapY,(mapY%8)*8+(mapX%8)); texture= si.getTexture(); } //spatted textures else { int var= random.randRange(0, transitionVars); SurfaceInfo si( getSurfPixmap(leftUp, var), getSurfPixmap(rightUp, var), getSurfPixmap(leftDown, var), getSurfPixmap(rightDown, var)); surfaceAtlas.addSurface(&si); coord= si.getCoord(); texture= si.getTexture(); } }