diff --git a/src/Client/GUI/Scene.h b/src/Client/GUI/Scene.h index c1ab379..7de223a 100644 --- a/src/Client/GUI/Scene.h +++ b/src/Client/GUI/Scene.h @@ -57,6 +57,7 @@ private: ShTlTerrainSceneNode *terrain; MCameraFPS *camera; MyEventReceiver *eventrecv; + ZThread::FastMutex mutex; }; diff --git a/src/Client/GUI/SceneWorld.cpp b/src/Client/GUI/SceneWorld.cpp index 83a8d20..4c4006a 100644 --- a/src/Client/GUI/SceneWorld.cpp +++ b/src/Client/GUI/SceneWorld.cpp @@ -11,13 +11,14 @@ #include "World.h" #include + SceneWorld::SceneWorld(PseuGUI *g) : Scene(g) { DEBUG(logdebug("SceneWorld: Initializing...")); - s32 mapsize = 9 * 16; // 9 height floats in 16 chunks per tile per axis + s32 mapsize = 9 * 16 * 3; // 9 height floats in 16 chunks per tile per axis in 3 MapTiles s32 tilesize = UNITSIZE; - s32 meshsize = CHUNKSIZE; + s32 meshsize = CHUNKSIZE*3; vector3df terrainPos(0.0f, 0.0f, 0.0f); // TODO: use PseuWoW's world coords here? eventrecv = new MyEventReceiver(); @@ -60,35 +61,45 @@ SceneWorld::SceneWorld(PseuGUI *g) : Scene(g) // something is not good here. we have terrain, but the chunks are read incorrectly. // need to find out where which formula is wrong - // the current terrain renderer code is just a test to see if ADT files are read correctly. apparantly not :D - MapTile *maptile = mapmgr->GetCurrentTile(); - if(maptile) + // the current terrain renderer code is just a test to see if ADT files are read correctly. + // EDIT: it seems to display fine now, but i am still not sure if the way it is done is correct... + mutex.acquire(); // prevent other threads deleting the maptile + for(s32 tiley = 0; tiley < 3; tiley++) { - // apply map height data - for(uint32 chx = 0; chx < 16; chx++) - for(uint32 chy = 0; chy < 16; chy++) + for(s32 tilex = 0; tilex < 3; tilex++) + { + MapTile *maptile = mapmgr->GetNearTile(tilex - 1, tiley - 1); + if(maptile) { - MapChunk *chunk = maptile->GetChunk(chx, chy); - std::stringstream ss; - DEBUG(logdebug("Apply MapChunk (%u, %u)",chx,chy)); - for(uint32 hy = 0; hy < 9; hy++) - { - for(uint32 hx = 0; hx < 9; hx++) + // apply map height data + for(uint32 chy = 0; chy < 16; chy++) + for(uint32 chx = 0; chx < 16; chx++) { - f32 h = chunk->hmap_rough[hy * 9 + hx]; - ss.precision(3); - ss << h << '\t'; - terrain->setHeight(9 * chx + hx, 9 * chy + hy, h); + MapChunk *chunk = maptile->GetChunk(chx, chy); + std::stringstream ss; + DEBUG(logdebug("Apply MapChunk (%u, %u)",chx,chy)); + for(uint32 hy = 0; hy < 9; hy++) + { + for(uint32 hx = 0; hx < 9; hx++) + { + f32 h = chunk->hmap_rough[hx * 9 + hy] + chunk->baseheight; // not sure if hx and hy are used correctly here + h *= -1; // as suggested by bLuma + ss.precision(3); + ss << h << '\t'; + terrain->setHeight((144 * tiley) + (9 * chx) + hx, (144 * tilex) + (9 * chy) + hy, h); + } + ss << "\n"; + } + //DEBUG(logdebug("\n%s\n",ss.str().c_str())); } - ss << "\n"; - } - DEBUG(logdebug("\n%s\n",ss.str().c_str())); } + else + { + logerror("SceneWorld: MapTile not loaded, can't apply heightmap!"); + } + } } - else - { - logerror("SceneWorld: MapTile not loaded, can't apply heightmap!"); - } + mutex.release(); terrain->smoothNormals(); diff --git a/src/Client/World/MapMgr.cpp b/src/Client/World/MapMgr.cpp index ab46545..a70a8c9 100644 --- a/src/Client/World/MapMgr.cpp +++ b/src/Client/World/MapMgr.cpp @@ -135,6 +135,11 @@ MapTile *MapMgr::GetCurrentTile(void) return GetTile(_gridx,_gridy); } +MapTile *MapMgr::GetNearTile(int32 xoffs, int32 yoffs) +{ + return GetTile(_gridx + xoffs, _gridy + yoffs); +} + uint32 MapMgr::GetGridCoord(float f) { return (ZEROPOINT - f) / TILESIZE; diff --git a/src/Client/World/MapMgr.h b/src/Client/World/MapMgr.h index 1eabd7c..9215a2b 100644 --- a/src/Client/World/MapMgr.h +++ b/src/Client/World/MapMgr.h @@ -15,6 +15,7 @@ public: uint32 GetGridCoord(float f); MapTile *GetTile(uint32 xg, uint32 yg, bool forceLoad = false); MapTile *GetCurrentTile(void); + MapTile *GetNearTile(int32, int32); inline bool Loaded(void) { return _mapsLoaded; } private: diff --git a/src/shared/MapTile.cpp b/src/shared/MapTile.cpp index 74afc57..ead0d8a 100644 --- a/src/shared/MapTile.cpp +++ b/src/shared/MapTile.cpp @@ -2,7 +2,6 @@ #include "MapTile.h" #include "log.h" - MapTile::MapTile() { } diff --git a/src/shared/MapTile.h b/src/shared/MapTile.h index 375cdc4..4e7a066 100644 --- a/src/shared/MapTile.h +++ b/src/shared/MapTile.h @@ -17,6 +17,7 @@ class MapChunk public: float hmap_rough[9*9]; float hmap_fine[8*8]; + float hmap[17*17]; // combined rough and fine hmap float basex,basey,baseheight; //... TODO: implement the rest of this };