mirror of
https://github.com/glest/glest-source.git
synced 2025-08-18 06:01:17 +02:00
First steps for new terrain texturing. In tileset xml do:
<surface partsize="64"> <texture path="textures/512.png"/> </surface>
This commit is contained in:
@@ -183,7 +183,9 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
|
|||||||
|
|
||||||
//surfaces
|
//surfaces
|
||||||
const XmlNode *surfacesNode= tilesetNode->getChild("surfaces");
|
const XmlNode *surfacesNode= tilesetNode->getChild("surfaces");
|
||||||
|
int partsize= 0;
|
||||||
for(int i=0; i < surfCount; ++i) {
|
for(int i=0; i < surfCount; ++i) {
|
||||||
|
|
||||||
const XmlNode *surfaceNode;
|
const XmlNode *surfaceNode;
|
||||||
if(surfacesNode->hasChildAtIndex("surface",i)){
|
if(surfacesNode->hasChildAtIndex("surface",i)){
|
||||||
surfaceNode= surfacesNode->getChild("surface", i);
|
surfaceNode= surfacesNode->getChild("surface", i);
|
||||||
@@ -193,25 +195,61 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
|
|||||||
surfaceNode= surfacesNode->getChild("surface", 2);
|
surfaceNode= surfacesNode->getChild("surface", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(surfaceNode->hasAttribute("partsize")){
|
||||||
int childCount= surfaceNode->getChildCount();
|
partsize=surfaceNode->getAttribute("partsize",true)->getIntValue();
|
||||||
surfPixmaps[i].resize(childCount);
|
}
|
||||||
surfProbs[i].resize(childCount);
|
else{
|
||||||
|
partsize=0;
|
||||||
for(int j = 0; j < childCount; ++j) {
|
|
||||||
surfPixmaps[i][j] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int j = 0; j < childCount; ++j) {
|
if(partsize==0){
|
||||||
const XmlNode *textureNode= surfaceNode->getChild("texture", j);
|
int childCount= surfaceNode->getChildCount();
|
||||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) {
|
surfPixmaps[i].resize(childCount);
|
||||||
surfPixmaps[i][j] = new Pixmap2D();
|
surfProbs[i].resize(childCount);
|
||||||
surfPixmaps[i][j]->init(3);
|
|
||||||
surfPixmaps[i][j]->load(textureNode->getAttribute("path")->getRestrictedValue(currentPath));
|
|
||||||
}
|
|
||||||
loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile,textureNode->getAttribute("path")->getRestrictedValue()));
|
|
||||||
|
|
||||||
surfProbs[i][j]= textureNode->getAttribute("prob")->getFloatValue();
|
for(int j = 0; j < childCount; ++j) {
|
||||||
|
surfPixmaps[i][j] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int j = 0; j < childCount; ++j) {
|
||||||
|
const XmlNode *textureNode= surfaceNode->getChild("texture", j);
|
||||||
|
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) {
|
||||||
|
surfPixmaps[i][j] = new Pixmap2D();
|
||||||
|
surfPixmaps[i][j]->init(3);
|
||||||
|
surfPixmaps[i][j]->load(textureNode->getAttribute("path")->getRestrictedValue(currentPath));
|
||||||
|
}
|
||||||
|
loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile,textureNode->getAttribute("path")->getRestrictedValue()));
|
||||||
|
|
||||||
|
surfProbs[i][j]= textureNode->getAttribute("prob")->getFloatValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// read single big texture and cut it into pieces
|
||||||
|
const XmlNode *textureNode= surfaceNode->getChild("texture", 0);
|
||||||
|
Pixmap2D *pixmap=new Pixmap2D();
|
||||||
|
pixmap->init(3);
|
||||||
|
pixmap->load(textureNode->getAttribute("path")->getRestrictedValue(currentPath));
|
||||||
|
loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile,textureNode->getAttribute("path")->getRestrictedValue()));
|
||||||
|
int width=pixmap->getW();
|
||||||
|
int heith=pixmap->getW();
|
||||||
|
assert(width==heith);
|
||||||
|
assert(width%64==0);
|
||||||
|
assert(width%partsize==0);
|
||||||
|
int parts=width/partsize;
|
||||||
|
int numberOfPieces=parts*parts;
|
||||||
|
partsArray[i]=parts;
|
||||||
|
surfPixmaps[i].resize(numberOfPieces);
|
||||||
|
surfProbs[i].resize(numberOfPieces);
|
||||||
|
int j=0;
|
||||||
|
for(int x = 0; x < parts; ++x) {
|
||||||
|
for(int y = 0; y < parts; ++y) {
|
||||||
|
surfPixmaps[i][j] = new Pixmap2D();
|
||||||
|
surfPixmaps[i][j]->init(partsize,partsize,3);
|
||||||
|
surfPixmaps[i][j]->copyImagePart(x*partsize,y*partsize,pixmap);
|
||||||
|
surfProbs[i][j]=-1;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -391,23 +429,33 @@ const Pixmap2D *Tileset::getSurfPixmap(int type, int var) const{
|
|||||||
return surfPixmaps[type][var % vars];
|
return surfPixmaps[type][var % vars];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tileset::addSurfTex(int leftUp, int rightUp, int leftDown, int rightDown, Vec2f &coord, const Texture2D *&texture) {
|
void Tileset::addSurfTex(int leftUp, int rightUp, int leftDown, int rightDown, Vec2f &coord, const Texture2D *&texture, int mapX, int mapY) {
|
||||||
//center textures
|
//center textures
|
||||||
if(leftUp == rightUp && leftUp == leftDown && leftUp == rightDown) {
|
if(leftUp == rightUp && leftUp == leftDown && leftUp == rightDown) {
|
||||||
//texture variation according to probability
|
//texture variation according to probability
|
||||||
float r= random.randRange(0.f, 1.f);
|
float r= random.randRange(0.f, 1.f);
|
||||||
int var= 0;
|
int var= 0;
|
||||||
float max= 0.f;
|
float max= 0.f;
|
||||||
for(int i=0; i < surfProbs[leftUp].size(); ++i) {
|
const Pixmap2D* pixmap;
|
||||||
max+= surfProbs[leftUp][i];
|
if(surfProbs[leftUp][0]<0)
|
||||||
if(r <= max) {
|
{// big textures use coordinates
|
||||||
var= i;
|
int parts=partsArray[leftUp];
|
||||||
break;
|
pixmap=getSurfPixmap(leftUp, (mapY%parts)*parts+(mapX%parts));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
SurfaceInfo si(getSurfPixmap(leftUp, var));
|
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);
|
surfaceAtlas.addSurface(&si);
|
||||||
coord= si.getCoord();
|
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();
|
texture= si.getTexture();
|
||||||
}
|
}
|
||||||
//spatted textures
|
//spatted textures
|
||||||
|
@@ -132,6 +132,9 @@ private:
|
|||||||
SurfProbs surfProbs[surfCount];
|
SurfProbs surfProbs[surfCount];
|
||||||
SurfPixmaps surfPixmaps[surfCount];
|
SurfPixmaps surfPixmaps[surfCount];
|
||||||
|
|
||||||
|
int partsArray[surfCount];
|
||||||
|
//int partsizes[surfCount];
|
||||||
|
|
||||||
RandomGen random;
|
RandomGen random;
|
||||||
Texture3D *waterTex;
|
Texture3D *waterTex;
|
||||||
bool waterEffects;
|
bool waterEffects;
|
||||||
@@ -181,7 +184,7 @@ public:
|
|||||||
|
|
||||||
//surface textures
|
//surface textures
|
||||||
const Pixmap2D *getSurfPixmap(int type, int var) const;
|
const Pixmap2D *getSurfPixmap(int type, int var) const;
|
||||||
void addSurfTex(int leftUp, int rightUp, int leftDown, int rightDown, Vec2f &coord, const Texture2D *&texture);
|
void addSurfTex(int leftUp, int rightUp, int leftDown, int rightDown, Vec2f &coord, const Texture2D *&texture, int mapX, int mapY);
|
||||||
|
|
||||||
//sounds
|
//sounds
|
||||||
AmbientSounds *getAmbientSounds() {return &ambientSounds;}
|
AmbientSounds *getAmbientSounds() {return &ambientSounds;}
|
||||||
|
@@ -1717,7 +1717,7 @@ void World::initSplattedTextures() {
|
|||||||
sc10->getSurfaceType(),
|
sc10->getSurfaceType(),
|
||||||
sc01->getSurfaceType(),
|
sc01->getSurfaceType(),
|
||||||
sc11->getSurfaceType(),
|
sc11->getSurfaceType(),
|
||||||
coord, texture);
|
coord, texture,j,i);
|
||||||
sc00->setSurfTexCoord(coord);
|
sc00->setSurfTexCoord(coord);
|
||||||
sc00->setSurfaceTexture(texture);
|
sc00->setSurfaceTexture(texture);
|
||||||
}
|
}
|
||||||
|
@@ -293,6 +293,7 @@ public:
|
|||||||
void lerp(float t, const Pixmap2D *pixmap1, const Pixmap2D *pixmap2);
|
void lerp(float t, const Pixmap2D *pixmap1, const Pixmap2D *pixmap2);
|
||||||
void copy(const Pixmap2D *sourcePixmap);
|
void copy(const Pixmap2D *sourcePixmap);
|
||||||
void subCopy(int x, int y, const Pixmap2D *sourcePixmap);
|
void subCopy(int x, int y, const Pixmap2D *sourcePixmap);
|
||||||
|
void copyImagePart(int x, int y, const Pixmap2D *sourcePixmap);
|
||||||
string getPath() const { return path;}
|
string getPath() const { return path;}
|
||||||
uint64 getPixelByteCount() const;
|
uint64 getPixelByteCount() const;
|
||||||
|
|
||||||
|
@@ -1286,6 +1286,27 @@ void Pixmap2D::subCopy(int x, int y, const Pixmap2D *sourcePixmap){
|
|||||||
delete [] pixel;
|
delete [] pixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// uses a a part of a bigger source image to fill this image.
|
||||||
|
void Pixmap2D::copyImagePart(int x, int y, const Pixmap2D *sourcePixmap){
|
||||||
|
assert(components==sourcePixmap->getComponents());
|
||||||
|
|
||||||
|
if(x+w>sourcePixmap->getW() && y+h>sourcePixmap->getH()){
|
||||||
|
throw megaglest_runtime_error("Pixmap2D::copyImagePart(), bad dimensions");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8 *pixel= new uint8[components];
|
||||||
|
|
||||||
|
for(int i=x; i<x+w; ++i){
|
||||||
|
for(int j=y; j<y+h; ++j){
|
||||||
|
sourcePixmap->getPixel(i, j, pixel);
|
||||||
|
setPixel(i-x, j-y, pixel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CalculatePixelsCRC(pixels,getPixelByteCount(), crc);
|
||||||
|
|
||||||
|
delete [] pixel;
|
||||||
|
}
|
||||||
|
|
||||||
bool Pixmap2D::doDimensionsAgree(const Pixmap2D *pixmap){
|
bool Pixmap2D::doDimensionsAgree(const Pixmap2D *pixmap){
|
||||||
return pixmap->getW() == w && pixmap->getH() == h;
|
return pixmap->getW() == w && pixmap->getH() == h;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user