step1 for cliffs; enable manually in map.cpp in Map::smoothSurface(...) ; set minCliffHeightDifference to 3.0f

This commit is contained in:
Titus Tscharntke 2011-02-06 01:36:55 +00:00
parent ef3aaacbc2
commit f2caf186f9
7 changed files with 64 additions and 24 deletions

View File

@ -1 +1 @@
../../data/glest_game/data ../../data/glest_game/data/

View File

@ -3,6 +3,9 @@
VERSION=`./mg-version.sh --version` VERSION=`./mg-version.sh --version`
RELEASENAME=megaglest-source RELEASENAME=megaglest-source
RELEASEDIR="`pwd`/release/$RELEASENAME-$VERSION" RELEASEDIR="`pwd`/release/$RELEASENAME-$VERSION"
RELEASESOURCEDIR=$RELEASEDIR/source
MKDIR=$RELEASEDIR/mk
CMAKEDIR=$MKDIR/cmake
echo "Creating source package in $RELEASEDIR" echo "Creating source package in $RELEASEDIR"
@ -27,10 +30,12 @@ popd
popd popd
cp -p ../../docs/readme*.txt ../../docs/*license*.txt $RELEASEDIR cp -p ../../docs/readme*.txt ../../docs/*license*.txt $RELEASEDIR
cp -p ../../build-mg*.sh $RELEASEDIR
cp -p ../../CMakeLists.txt $RELEASEDIR
cp -p glest.ini $RELEASEDIR cp -p glest.ini $RELEASEDIR
cp -p glestkeys.ini $RELEASEDIR cp -p glestkeys.ini $RELEASEDIR
cp -p servers.ini $RELEASEDIR cp -p servers.ini $RELEASEDIR
cp -p glest.ico $RELEASEDIR cp -p megaglest.ico $RELEASEDIR
cp -p glest.ico $RELEASEDIR cp -p glest.ico $RELEASEDIR
cp -p ../../CMake* $RELEASEDIR cp -p ../../CMake* $RELEASEDIR

View File

@ -271,9 +271,9 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
return mapChecksum; return mapChecksum;
} }
void Map::init() { void Map::init(Tileset *tileset) {
Logger::getInstance().add("Heightmap computations", true); Logger::getInstance().add("Heightmap computations", true);
smoothSurface(); smoothSurface(tileset);
computeNormals(); computeNormals();
computeInterpolatedHeights(); computeInterpolatedHeights();
computeNearSubmerged(); computeNearSubmerged();
@ -1076,34 +1076,61 @@ void Map::computeInterpolatedHeights(){
} }
void Map::smoothSurface(){ void Map::smoothSurface(Tileset *tileset) {
float *oldHeights= new float[getSurfaceCellArraySize()]; float minCliffHeightDifference=0.0f;
float *oldHeights = new float[getSurfaceCellArraySize()];
for(int i=0; i < getSurfaceCellArraySize(); ++i) { for (int i = 0; i < getSurfaceCellArraySize(); ++i) {
oldHeights[i]= surfaceCells[i].getHeight(); oldHeights[i] = surfaceCells[i].getHeight();
} }
for(int i=1; i<surfaceW-1; ++i){ for (int i = 1; i < surfaceW - 1; ++i) {
for(int j=1; j<surfaceH-1; ++j){ for (int j = 1; j < surfaceH - 1; ++j) {
float height= 0.f; float height = 0.f;
for(int k=-1; k<=1; ++k){ float numUsedToSmooth = 0.f;
for(int l=-1; l<=1; ++l){ for (int k = -1; k <= 1; ++k) {
height+= oldHeights[(j+k)*surfaceW+(i+l)]; for (int l = -1; l <= 1; ++l) {
if (minCliffHeightDifference<=0.1f || minCliffHeightDifference > abs(oldHeights[(j) * surfaceW + (i)]
- oldHeights[(j + k) * surfaceW + (i + l)])) {
height += oldHeights[(j + k) * surfaceW + (i + l)];
numUsedToSmooth++;
} else {
// we have something which should not be smoothed!
// This is a cliff and must be textured -> set cliff texture
getSurfaceCell(i, j)->setSurfaceType(5);
//set invisible blocking object and replace resource objects
//and non blocking objects with invisible blocker too
Object *formerObject =
getSurfaceCell(i, j)->getObject();
if (formerObject != NULL) {
if (formerObject->getWalkable()
|| formerObject->getResource() != NULL) {
delete formerObject;
formerObject = NULL;
}
}
if (formerObject == NULL) {
Object *o = new Object(tileset->getObjectType(9),
getSurfaceCell(i, j)->getVertex(), Vec2i(i,
j));
getSurfaceCell(i, j)->setObject(o);
}
}
} }
} }
height/= 9.f;
height /= numUsedToSmooth;
getSurfaceCell(i, j)->setHeight(height); getSurfaceCell(i, j)->setHeight(height);
Object *object= getSurfaceCell(i, j)->getObject(); Object *object = getSurfaceCell(i, j)->getObject();
if(object!=NULL){ if (object != NULL) {
object->setHeight(height); object->setHeight(height);
} }
} }
} }
delete[] oldHeights;
delete [] oldHeights;
} }
void Map::computeNearSubmerged(){ void Map::computeNearSubmerged(){

View File

@ -175,7 +175,7 @@ public:
~Map(); ~Map();
Checksum * getChecksumValue() { return &checksumValue; } Checksum * getChecksumValue() { return &checksumValue; }
void init(); void init(Tileset *tileset);
Checksum load(const string &path, TechTree *techTree, Tileset *tileset); Checksum load(const string &path, TechTree *techTree, Tileset *tileset);
//get //get
@ -250,7 +250,7 @@ public:
private: private:
//compute //compute
void smoothSurface(); void smoothSurface(Tileset *tileset);
void computeNearSubmerged(); void computeNearSubmerged();
void computeCellColors(); void computeCellColors();
}; };

View File

@ -136,7 +136,15 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
//surfaces //surfaces
const XmlNode *surfacesNode= tilesetNode->getChild("surfaces"); const XmlNode *surfacesNode= tilesetNode->getChild("surfaces");
for(int i=0; i<surfCount; ++i){ for(int i=0; i<surfCount; ++i){
const XmlNode *surfaceNode= surfacesNode->getChild("surface", i); const XmlNode *surfaceNode;
if(surfacesNode->hasChildAtIndex("surface",i)){
surfaceNode= surfacesNode->getChild("surface", i);
}
else {
// cliff texture does not exist, use texture 2 instead
surfaceNode= surfacesNode->getChild("surface", 2);
}
int childCount= surfaceNode->getChildCount(); int childCount= surfaceNode->getChildCount();
surfPixmaps[i].resize(childCount); surfPixmaps[i].resize(childCount);

View File

@ -100,7 +100,7 @@ public:
class Tileset{ class Tileset{
public: public:
static const int waterTexCount= 1; static const int waterTexCount= 1;
static const int surfCount= 5; static const int surfCount= 6;
static const int objCount= 10; static const int objCount= 10;
static const int transitionVars= 2; //number or different transition textures static const int transitionVars= 2; //number or different transition textures

View File

@ -1224,7 +1224,7 @@ void World::initUnits() {
void World::initMap() { void World::initMap() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
map.init(); map.init(&tileset);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }