From 4cef295bed01c9d84fb71e3dad6989d3a6ac65ee Mon Sep 17 00:00:00 2001 From: false_genesis Date: Sun, 6 Apr 2008 21:00:19 +0000 Subject: [PATCH] * doodads are now displayed on the map * commented out a line in the M2 loader, it was causing a crash (?!) * added NormalizeFilename() in tools.cpp, please use this when formatting filenames for linux * TODO: remove doodads that are too far away or if the map is changed. currently its using A LOT of graphics power --- src/Client/GUI/CM2MeshFileLoader.cpp | 5 +++-- src/Client/GUI/DrawObject.cpp | 2 +- src/Client/GUI/Scene.h | 1 - src/Client/GUI/SceneWorld.cpp | 17 +++++++++++++++++ src/shared/ADTFile.cpp | 2 +- src/shared/ADTFileStructs.h | 8 ++++---- src/shared/MapTile.cpp | 24 ++++++++++++++++++++++++ src/shared/MapTile.h | 10 ++++++++++ src/shared/tools.cpp | 15 +++++++++++++++ src/shared/tools.h | 1 + 10 files changed, 76 insertions(+), 9 deletions(-) diff --git a/src/Client/GUI/CM2MeshFileLoader.cpp b/src/Client/GUI/CM2MeshFileLoader.cpp index 5b41cb9..edd445b 100644 --- a/src/Client/GUI/CM2MeshFileLoader.cpp +++ b/src/Client/GUI/CM2MeshFileLoader.cpp @@ -77,7 +77,7 @@ for(u32 i =0;iread(&tempM2MView,sizeof(ModelView)); M2MViews.push_back(tempM2MView); } -std::cout << "Read "<log("Using View 0 for all further operations",ELL_INFORMATION); std::cout<<"This View has "<seek(M2MTextureDef[i].texFileOfs); - file->read(&tempTexFileName[0],M2MTextureDef[i].texFileLen); + file->read((void*)tempTexFileName.c_str(),M2MTextureDef[i].texFileLen); + std::cout << "texture: '" << tempTexFileName << "'\n"; M2MTextureFiles.push_back(tempTexFileName.c_str()); std::cout<GetPosition(); - cube->setPosition(irr::core::vector3df(-pos.x,pos.z,-pos.y)); + cube->setPosition(WPToIrr(pos)); rotation.Y = O_TO_IRR(pos.o); float s = _obj->GetFloatValue(OBJECT_FIELD_SCALE_X); diff --git a/src/Client/GUI/Scene.h b/src/Client/GUI/Scene.h index 4c21fa1..84e365f 100644 --- a/src/Client/GUI/Scene.h +++ b/src/Client/GUI/Scene.h @@ -82,7 +82,6 @@ private: MapMgr *mapmgr; IGUIStaticText *debugText; bool debugmode; - gui::IGUIImage *icursor; }; diff --git a/src/Client/GUI/SceneWorld.cpp b/src/Client/GUI/SceneWorld.cpp index ffc36b9..146fe35 100644 --- a/src/Client/GUI/SceneWorld.cpp +++ b/src/Client/GUI/SceneWorld.cpp @@ -276,6 +276,7 @@ void SceneWorld::UpdateTerrain(void) { // apply map height data for(uint32 chy = 0; chy < 16; chy++) + { for(uint32 chx = 0; chx < 16; chx++) { MapChunk *chunk = maptile->GetChunk(chx, chy); @@ -290,6 +291,22 @@ void SceneWorld::UpdateTerrain(void) } } } + } + // create doodads + for(uint32 i = 0; i < maptile->GetDoodadCount(); i++) + { + Doodad *d = maptile->GetDoodad(i); + scene::IAnimatedMesh *mesh = smgr->getMesh(d->model.c_str()); + if(mesh) + { + scene::ISceneNode *doodad = smgr->addAnimatedMeshSceneNode(mesh); + if(doodad) + { + doodad->setPosition(core::vector3df(-d->x, d->z, -d->y)); + doodad->setRotation(core::vector3df(d->ox + 270.0f, d->oy, d->oz)); // +270 solves M2 models lying on the side + } + } + } } else { diff --git a/src/shared/ADTFile.cpp b/src/shared/ADTFile.cpp index 1694722..c28263f 100644 --- a/src/shared/ADTFile.cpp +++ b/src/shared/ADTFile.cpp @@ -142,7 +142,7 @@ bool ADTFile::LoadMem(ByteBuffer& buf) }*/ else if(!strcmp((char*)fourcc,"MDDF")) { - uint32 ndoodads = size / 36; + uint32 ndoodads = size / sizeof(MDDF_chunk); //DEBUG(printf("ADT: Loading %u doodads.\n",ndoodads)); for(uint32 i = 0; i_doodadsp.size())); + for(uint32 i = 0; i < adt->_doodadsp.size(); i++) + { + Doodad d; + MDDF_chunk& mddf = adt->_doodadsp[i]; + // and yet another coordinate system... + d.y = -(mddf.x - ZEROPOINT); + d.z = mddf.y; + d.x = -(mddf.z - ZEROPOINT); + d.ox = mddf.c; + d.oy = mddf.b - 90.0f; // wowdev states Y=B-90, but this doesnt really look as expected... + d.oz = -mddf.a; + d.flags = mddf.flags; + d.model = std::string("./data/model/") + NormalizeFilename(_PathToFileName(adt->_models[mddf.id])); + // this .mdx -> .m2 transformation is annoying >.< - replace "mdx" and end of string with "m2\0" + memcpy(&d.model[0] + d.model.size() - 3, "m2\0", 3); + d.scale = mddf.scale / 1024.0f; + if(d.scale < 0.00001f) + d.scale = 1; + _doodads.push_back(d); + } + _xbase = _chunks[0].basex; _ybase = _chunks[0].basey; _hbase = _chunks[0].baseheight; diff --git a/src/shared/MapTile.h b/src/shared/MapTile.h index a19b524..a0d9865 100644 --- a/src/shared/MapTile.h +++ b/src/shared/MapTile.h @@ -25,6 +25,13 @@ public: //... TODO: implement the rest of this }; +struct Doodad +{ + float x,y,z,ox,oy,oz,scale; + uint16 flags; + std::string model; +}; + // generic map tile class. stores the information previously stored in an ADT file // in an easier to use form. class MapTile @@ -39,12 +46,15 @@ public: inline float GetBaseX(void) { return _xbase; } inline float GetBaseY(void) { return _ybase; } inline float GetBaseHeight(void) { return _hbase; } + inline uint32 GetDoodadCount(void) { return _doodads.size(); } + inline Doodad *GetDoodad(uint32 i) { return &_doodads[i]; } private: MapChunk _chunks[256]; // 16x16 std::vector _textures; std::vector _wmos; std::vector _models; + std::vector _doodads; float _xbase,_ybase,_hbase; diff --git a/src/shared/tools.cpp b/src/shared/tools.cpp index cea1532..244c79c 100644 --- a/src/shared/tools.cpp +++ b/src/shared/tools.cpp @@ -231,4 +231,19 @@ std::string _PathToFileName(std::string str) return str; } +std::string NormalizeFilename(std::string s) +{ + uint32 p; + while( (p = s.find('\\')) != std::string::npos)//Replace \ by / + { + s.replace(p,1,"/"); + } + while( (p = s.find(' ')) != std::string::npos)//Replace space by _ + { + s.replace(p,1,"_"); + } + std::transform(s.begin(), s.end(), s.begin(), tolower); + return s; +} + diff --git a/src/shared/tools.h b/src/shared/tools.h index 2266888..0396483 100644 --- a/src/shared/tools.h +++ b/src/shared/tools.h @@ -22,5 +22,6 @@ uint32 getMSTime(void); uint32 GetFileSize(const char*); void _FixFileName(std::string&); std::string _PathToFileName(std::string); +std::string NormalizeFilename(std::string); #endif