diff --git a/bin/data/misc/sky.jpg b/bin/data/misc/sky.jpg new file mode 100644 index 0000000..a7e2799 Binary files /dev/null and b/bin/data/misc/sky.jpg differ diff --git a/src/Client/DefScriptInterface.cpp b/src/Client/DefScriptInterface.cpp index 7977bee..7853b32 100644 --- a/src/Client/DefScriptInterface.cpp +++ b/src/Client/DefScriptInterface.cpp @@ -55,6 +55,7 @@ void DefScriptPackage::_InitDefScriptInterface(void) AddFunc("getopcodeid",&DefScriptPackage::SCGetOpcodeID); AddFunc("bbgetpackedguid",&DefScriptPackage::SCBBGetPackedGuid); AddFunc("bbputpackedguid",&DefScriptPackage::SCBBPutPackedGuid); + AddFunc("gui",&DefScriptPackage::SCGui); } DefReturnResult DefScriptPackage::SCshdn(CmdSet& Set) @@ -957,6 +958,24 @@ DefReturnResult DefScriptPackage::SCBBPutPackedGuid(CmdSet &Set) return true; } +DefReturnResult DefScriptPackage::SCGui(CmdSet &Set) +{ + PseuInstance *ins = (PseuInstance*)parentMethod; + if(ins->InitGUI()) + logdebug("SCGui: gui created"); + else + { + logerror("SCGui: failed"); + return false; + } + while(!ins->GetGUI() && !ins->GetGUI()->IsInitialized()) + Sleep(1); + ins->GetGUI()->SetSceneState(SCENESTATE_GUISTART); + // TODO: determine which SceneState to use here + return true; +} + + void DefScriptPackage::My_LoadUserPermissions(VarSet &vs) { static char *prefix = "USERS::"; diff --git a/src/Client/DefScriptInterfaceInclude.h b/src/Client/DefScriptInterfaceInclude.h index 666a316..c0d9bd4 100644 --- a/src/Client/DefScriptInterfaceInclude.h +++ b/src/Client/DefScriptInterfaceInclude.h @@ -46,5 +46,6 @@ DefReturnResult SCGetOpcodeName(CmdSet&); DefReturnResult SCGetOpcodeID(CmdSet&); DefReturnResult SCBBGetPackedGuid(CmdSet&); DefReturnResult SCBBPutPackedGuid(CmdSet&); +DefReturnResult SCGui(CmdSet&); #endif diff --git a/src/Client/GUI/PseuGUI.cpp b/src/Client/GUI/PseuGUI.cpp index 5d8b9e2..39eee75 100644 --- a/src/Client/GUI/PseuGUI.cpp +++ b/src/Client/GUI/PseuGUI.cpp @@ -162,7 +162,7 @@ void PseuGUI::Run(void) while(_device && _device->run() && !_mustdie) { _lastpasstime = _passtime; - _passtime = _timer->getTime() / 1000.0f; + _passtime = _timer->getTime(); _passtimediff = _passtime - _lastpasstime; // _HandleWindowResize(); // not yet used; doesnt work diff --git a/src/Client/GUI/PseuGUI.h b/src/Client/GUI/PseuGUI.h index 05613f8..e36fd6b 100644 --- a/src/Client/GUI/PseuGUI.h +++ b/src/Client/GUI/PseuGUI.h @@ -92,7 +92,7 @@ private: SceneState _scenestate, _scenestate_new; Scene *_scene; irr::ITimer *_timer; - float _passtime, _lastpasstime, _passtimediff; + uint32 _passtime, _lastpasstime, _passtimediff; irr::core::dimension2d _screendimension; }; diff --git a/src/Client/GUI/Scene.cpp b/src/Client/GUI/Scene.cpp index b8a6822..c9c83a3 100644 --- a/src/Client/GUI/Scene.cpp +++ b/src/Client/GUI/Scene.cpp @@ -21,7 +21,7 @@ void Scene::OnDelete(void) { } -void Scene::OnUpdate(f32) +void Scene::OnUpdate(s32) { } diff --git a/src/Client/GUI/Scene.h b/src/Client/GUI/Scene.h index 7de223a..6140b14 100644 --- a/src/Client/GUI/Scene.h +++ b/src/Client/GUI/Scene.h @@ -19,7 +19,7 @@ class Scene public: Scene(PseuGUI *g); ~Scene(); - virtual void OnUpdate(f32); + virtual void OnUpdate(s32); virtual void OnDraw(void); virtual void OnDelete(void); protected: @@ -44,7 +44,10 @@ private: class ShTlTerrainSceneNode; class MCameraFPS; +class MCameraOrbit; class MyEventReceiver; +class MapMgr; +class WorldSession; class SceneWorld : public Scene { @@ -52,12 +55,21 @@ public: SceneWorld(PseuGUI *gui); void OnDraw(void); void OnDelete(void); - void OnUpdate(f32); + void OnUpdate(s32); + void UpdateTerrain(void); + void InitTerrain(void); private: ShTlTerrainSceneNode *terrain; MCameraFPS *camera; MyEventReceiver *eventrecv; ZThread::FastMutex mutex; + PseuGUI *gui; + uint32 map_gridX, map_gridY; + s32 mapsize, tilesize, meshsize; + WorldSession *wsession; + MapMgr *mapmgr; + IGUIStaticText *debugText; + bool debugmode; }; diff --git a/src/Client/GUI/SceneWorld.cpp b/src/Client/GUI/SceneWorld.cpp index 935329d..ceefad7 100644 --- a/src/Client/GUI/SceneWorld.cpp +++ b/src/Client/GUI/SceneWorld.cpp @@ -1,3 +1,5 @@ +#include +#include #include "common.h" #include "PseuGUI.h" #include "PseuWoW.h" @@ -9,118 +11,25 @@ #include "MInput.h" #include "WorldSession.h" #include "World.h" -#include + +#define MOUSE_SENSIVITY 0.5f + SceneWorld::SceneWorld(PseuGUI *g) : Scene(g) { DEBUG(logdebug("SceneWorld: Initializing...")); + debugmode = false; - s32 mapsize = 9 * 16 * 3; // 9 height floats in 16 chunks per tile per axis in 3 MapTiles - s32 tilesize = UNITSIZE; - s32 meshsize = CHUNKSIZE*3; - vector3df terrainPos(0.0f, 0.0f, 0.0f); // TODO: use PseuWoW's world coords here? + // store some pointers right now to prevent repeated ptr dereferencing later (speeds up code) + gui = g; + wsession = gui->GetInstance()->GetWSession(); + mapmgr = wsession->GetWorld()->GetMapMgr(); - eventrecv = new MyEventReceiver(); - device->setEventReceiver(eventrecv); + // TODO: hardcoded for now, make this adjustable later + float fogdist = 100; - camera = new MCameraFPS(smgr); - camera->setNearValue(0.1f); - camera->setFarValue(tilesize*meshsize/2); - camera->setPosition(core::vector3df(mapsize*tilesize/2, 0, mapsize*tilesize/2) + terrainPos); - - terrain = new ShTlTerrainSceneNode(smgr,mapsize,mapsize,tilesize,meshsize); - terrain->drop(); - terrain->follow(camera->getNode()); - terrain->setMaterialTexture(0, driver->getTexture("data/misc/dirt_test.jpg")); - terrain->setDebugDataVisible(scene::EDS_FULL); - terrain->setMaterialFlag(video::EMF_LIGHTING, true); - terrain->setMaterialFlag(video::EMF_FOG_ENABLE, false); - terrain->setPosition(terrainPos); - - // randomize base color - for(s32 j=0; jgetSize().Height+1; j++) - for(s32 i=0; igetSize().Width+1; i++) - { - u32 g = (rand() % 150) + 80; - u32 r = (rand() % 50); - u32 b = (rand() % 50); - - terrain->setColor(i,j, video::SColor(255,r,g,b)); - } - - MapMgr *mapmgr = g->GetInstance()->GetWSession()->GetWorld()->GetMapMgr(); - - if(!mapmgr) - { - logerror("SceneWorld: MapMgr not present, cant create World GUI. Switching back GUI to idle."); - g->SetSceneState(SCENESTATE_GUISTART); - return; - } - - // TODO: better to do this with some ZThread Condition or FastMutex, but dont know how to. help plz! [FG] - if(!mapmgr->Loaded()) - { - logdebug("SceneWorld: Waiting until maps are loaded..."); - while(!mapmgr->Loaded()) - device->sleep(50); - } - - // TODO: as soon as WMO-only worlds are implemented, remove this!! - if(!mapmgr->GetLoadedMapsCount()) - { - logerror("SceneWorld: Error: No maps loaded, not able to draw any terrain. Switching back GUI to idle."); - logerror("SceneWorld: Hint: Be sure you are not in an WMO-only world (e.g. human capital city or most instances)!"); - g->SetSceneState(SCENESTATE_GUISTART); - return; - } - - // 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. - // 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++) - { - for(s32 tilex = 0; tilex < 3; tilex++) - { - MapTile *maptile = mapmgr->GetNearTile(tilex - 1, tiley - 1); - if(maptile) - { - // apply map height data - for(uint32 chy = 0; chy < 16; chy++) - for(uint32 chx = 0; chx < 16; chx++) - { - 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())); - } - } - else - { - logerror("SceneWorld: MapTile not loaded, can't apply heightmap!"); - } - } - } - mutex.release(); - - terrain->smoothNormals(); - - ILightSceneNode* light = smgr->addLightSceneNode(0, core::vector3df(0,0,0), - SColorf(255, 255, 255, 255), 1000.0f); + ILightSceneNode* light = smgr->addLightSceneNode(0, core::vector3df(0,0,0), SColorf(255, 255, 255, 255), 1000.0f); SLight ldata = light->getLightData(); ldata.AmbientColor = video::SColorf(0.2f,0.2f,0.2f); ldata.DiffuseColor = video::SColorf(1.0f,1.0f,1.0f); @@ -128,26 +37,136 @@ SceneWorld::SceneWorld(PseuGUI *g) : Scene(g) ldata.Position = core::vector3df(-10,5,-5); light->setLightData(ldata); - driver->setFog(video::SColor(255,100,101,140), true, tilesize*meshsize/4, tilesize*(meshsize-4)/2, 0.05f); + eventrecv = new MyEventReceiver(); + device->setEventReceiver(eventrecv); + + camera = new MCameraFPS(smgr); + camera->setNearValue(0.1f); + camera->setFarValue(12000); // TODO: adjust + + debugText = guienv->addStaticText(L"< debug text >",rect(0,0,driver->getScreenSize().Width,30),true,true,0,-1,true); + + smgr->addSkyDomeSceneNode(driver->getTexture("data/misc/sky.jpg"),64,64,1.0f,2.0f); + + driver->setFog(video::SColor(0,100,101,190), true, fogdist, fogdist + 30, 0.02f); + + // setup cursor + device->getCursorControl()->setVisible(false); + + InitTerrain(); + UpdateTerrain(); DEBUG(logdebug("SceneWorld: Init done!")); } -void SceneWorld::OnUpdate(f32 timediff) +void SceneWorld::OnUpdate(s32 timediff) { - if(eventrecv->key.pressed(KEY_KEY_W)) camera->moveForward(50 * timediff); - if(eventrecv->key.pressed(KEY_KEY_S)) camera->moveBack(50 * timediff); - if(eventrecv->key.pressed(KEY_KEY_D)) camera->moveRight(50 * timediff); - if(eventrecv->key.pressed(KEY_KEY_A)) camera->moveLeft(50 * timediff); + static position2d mouse_pos; - // mouse directional control - camera->turnRight(5 * (device->getCursorControl()->getRelativePosition().X - 0.5f)); - camera->turnUp(5 * (device->getCursorControl()->getRelativePosition().Y - 0.5f)); - //device->getCursorControl()->setPosition(0.5f, 0.5f); + UpdateTerrain(); + bool mouse_pressed_left = eventrecv->mouse.left_pressed(); + bool mouse_pressed_right = eventrecv->mouse.right_pressed(); + float timediff_f = timediff / 1000.0f; + + if(eventrecv->key.pressed(KEY_KEY_W) || (mouse_pressed_left && mouse_pressed_right)) + camera->moveForward(50 * timediff_f); + if(eventrecv->key.pressed(KEY_KEY_S)) + camera->moveBack(50 * timediff_f); + if(eventrecv->key.pressed(KEY_KEY_E)) + camera->moveRight(50 * timediff_f); + if(eventrecv->key.pressed(KEY_KEY_Q)) + camera->moveLeft(50 * timediff_f); + + // if right mouse button pressed, move in axis, if not, turn camera + if(eventrecv->key.pressed(KEY_KEY_D)) + { + if(mouse_pressed_right) + camera->moveRight(50 * timediff_f); + else + camera->turnRight(timediff_f * M_PI * 25); + } + if(eventrecv->key.pressed(KEY_KEY_A)) + { + if(mouse_pressed_right) + camera->moveLeft(50 * timediff_f); + else + camera->turnLeft(timediff_f * M_PI * 25); + } + + if(eventrecv->key.pressed_once(KEY_BACK)) + { + debugmode = !debugmode; + if(debugmode) + { + terrain->setDebugDataVisible(EDS_FULL); + } + else + { + terrain->setDebugDataVisible(EDS_OFF); + } + } + + if(eventrecv->key.pressed_once(KEY_INSERT)) + { + IImage *scrnshot = driver->createScreenShot(); + if(scrnshot) + { + CreateDir("screenshots"); + std::string date = getDateString(); + for(uint32 i = 0; i < date.length(); i++) + { + if(date[i] == ':') + date[i] = '_'; + } + driver->writeImageToFile(scrnshot, ("screenshots/PseuWoW " + date + ".jpg").c_str(), device->getTimer()->getRealTime()); + scrnshot->drop(); + } + } + + if(mouse_pressed_left || mouse_pressed_right) + { + //if(device->getCursorControl()->isVisible()) + //device->getCursorControl()->setVisible(false); + if(mouse_pos != device->getCursorControl()->getPosition()) + { + camera->turnRight(MOUSE_SENSIVITY * (device->getCursorControl()->getPosition().X - mouse_pos.X)); + // check if new camera pitch would cause camera to flip over; if thats the case keep current pitch + f32 upval = MOUSE_SENSIVITY * (device->getCursorControl()->getPosition().Y - mouse_pos.Y); + f32 newval = camera->getPitch() + upval; + if( newval > 270.1f || newval < 89.9f) + { + camera->turnUp(upval); + } + device->getCursorControl()->setPosition(mouse_pos); + } + } + else + { + device->getCursorControl()->setPosition(device->getCursorControl()->getPosition()); + //if(!device->getCursorControl()->isVisible()) + //device->getCursorControl()->setVisible(true); + mouse_pos = device->getCursorControl()->getPosition(); + } + // camera height control if (eventrecv->mouse.wheel < 10) eventrecv->mouse.wheel = 10; camera->setHeight( eventrecv->mouse.wheel + terrain->getHeight(camera->getPosition()) ); + + core::stringw str = L"Camera: pitch:"; + str += camera->getPitch(); + str += L" dir:"; + str += camera->getDirection().X; + str += L","; + str += camera->getDirection().Y; + str += L" Pos: "; + str = (((((str + camera->getPosition().X) + L" | ") + camera->getPosition().Y) + L" | ") + camera->getPosition().Z); + str += L" -- Terrain: Sectors: "; + str += (int)terrain->getSectorsRendered(); + str += L" / "; + str += (int)terrain->getSectorCount(); + debugText->setText(str.c_str()); + } void SceneWorld::OnDraw(void) @@ -160,3 +179,124 @@ void SceneWorld::OnDelete(void) { DEBUG(logdebug("~SceneWorld()")); } + +void SceneWorld::InitTerrain(void) +{ + if(!mapmgr) + { + logerror("SceneWorld: MapMgr not present, cant create World GUI. Switching back GUI to idle."); + gui->SetSceneState(SCENESTATE_GUISTART); + return; + } + + mapsize = 9 * 16 * 3; // 9 height floats in 16 chunks per tile per axis in 3 MapTiles + tilesize = UNITSIZE; + meshsize = CHUNKSIZE*3; + vector3df terrainPos(0.0f, 0.0f, 0.0f); // TODO: use PseuWoW's world coords here? + + camera->setPosition(core::vector3df(mapsize*tilesize/2, 0, mapsize*tilesize/2) + terrainPos); + + terrain = new ShTlTerrainSceneNode(smgr,mapsize,mapsize,tilesize,meshsize); + terrain->drop(); + terrain->follow(camera->getNode()); + terrain->setMaterialTexture(0, driver->getTexture("data/misc/dirt_test.jpg")); + terrain->setMaterialFlag(video::EMF_LIGHTING, true); + terrain->setMaterialFlag(video::EMF_FOG_ENABLE, true); + terrain->setPosition(terrainPos); + +} + + +void SceneWorld::UpdateTerrain(void) +{ + // check if we changed the maptile + if(map_gridX == mapmgr->GetGridX() && map_gridY == mapmgr->GetGridY()) + return; // grid not changed, not necessary to update tile data + + // ... if changed, do necessary stuff... + map_gridX = mapmgr->GetGridX(); + map_gridY = mapmgr->GetGridY(); + + // TODO: better to do this with some ZThread Condition or FastMutex, but dont know how to. help plz! [FG] + if(!mapmgr->Loaded()) + { + logdebug("SceneWorld: Waiting until maps are loaded..."); + while(!mapmgr->Loaded()) + device->sleep(1); + } + + // TODO: as soon as WMO-only worlds are implemented, remove this!! + if(!mapmgr->GetLoadedMapsCount()) + { + logerror("SceneWorld: Error: No maps loaded, not able to draw any terrain. Switching back GUI to idle."); + logerror("SceneWorld: Hint: Be sure you are not in an WMO-only world (e.g. human capital city or most instances)!"); + gui->SetSceneState(SCENESTATE_GUISTART); + return; + } + + // 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. + // 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 from deleting the maptile + logdebug("SceneWorld: Displaying MapTiles near grids x:%u y:%u",mapmgr->GetGridX(),mapmgr->GetGridY()); + for(s32 tiley = 0; tiley < 3; tiley++) + { + for(s32 tilex = 0; tilex < 3; tilex++) + { + MapTile *maptile = mapmgr->GetNearTile(tilex - 1, tiley - 1); + if(maptile) + { + // apply map height data + for(uint32 chy = 0; chy < 16; chy++) + for(uint32 chx = 0; chx < 16; chx++) + { + MapChunk *chunk = maptile->GetChunk(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 + u32 terrainx = (144 * tiley) + (9 * chx) + hx; + u32 terrainy = (144 * tilex) + (9 * chy) + hy; + terrain->setHeight(terrainx, terrainy, h); + } + } + } + } + else + { + logerror("SceneWorld: MapTile not loaded, can't apply heightmap!"); + } + } + } + mutex.release(); + + // find out highest/lowest spot + f32 highest = terrain->getHeight(0,0); + f32 lowest = terrain->getHeight(0,0); + f32 curheight; + for(s32 j=0; jgetSize().Height+1; j++) + for(s32 i=0; igetSize().Width+1; i++) + { + curheight = terrain->getHeight(i,j); + highest = max(highest,curheight); + lowest = min(lowest,curheight); + } + f32 heightdiff = highest - lowest; + + // randomize terrain color dependng on height + for(s32 j=0; jgetSize().Height+1; j++) + for(s32 i=0; igetSize().Width+1; i++) + { + curheight = terrain->getHeight(i,j); + u32 g = (curheight / highest * 120) + 125; + u32 r = (curheight / highest * 120) + 60; + u32 b = (curheight / highest * 120) + 60; + + terrain->setColor(i,j, video::SColor(255,r,g,b)); + } + + logdebug("SceneWorld: Smoothing terrain normals..."); + terrain->smoothNormals(); +} diff --git a/src/Client/PseuWoW.cpp b/src/Client/PseuWoW.cpp index e97be27..ca7429b 100644 --- a/src/Client/PseuWoW.cpp +++ b/src/Client/PseuWoW.cpp @@ -134,31 +134,10 @@ bool PseuInstance::Init(void) // TODO: find a better loaction where to place this block! if(GetConf()->enablegui) { - uint16 x,y,depth; - uint8 driver; - bool shadows,vsync,win; - - driver=(uint8)atoi(GetScripts()->variables.Get("GUI::DRIVER").c_str()); - vsync=(bool)atoi(GetScripts()->variables.Get("GUI::VSYNC").c_str()); - depth=(uint8)atoi(GetScripts()->variables.Get("GUI::DEPTH").c_str()); - x=(uint16)atoi(GetScripts()->variables.Get("GUI::RESX").c_str()); - y=(uint16)atoi(GetScripts()->variables.Get("GUI::RESY").c_str()); - win=(bool)atoi(GetScripts()->variables.Get("GUI::WINDOWED").c_str()); - shadows=(bool)atoi(GetScripts()->variables.Get("GUI::SHADOWS").c_str()); - log("GUI settings: driver=%u, depth=%u, res=%ux%u, windowed=%u, shadows=%u",driver,depth,x,y,win,shadows); - if(x>0 && y>0 && (depth==16 || depth==32) && driver>0 && driver<=5) - { - PseuGUIRunnable *rgui = new PseuGUIRunnable(); - _gui = rgui->GetGUI(); - _gui->SetInstance(this); - _gui->SetDriver(driver); - _gui->SetResolution(x,y,depth); - _gui->SetVSync(vsync); - _gui->UseShadows(shadows); - _guithread = new ZThread::Thread(rgui); - } + if(InitGUI()) + logdebug("GUI: Init successful."); else - logerror("GUI: incorrect settings!"); + logerror("GUI: Init failed!"); } if(GetConf()->rmcontrolport) @@ -184,6 +163,42 @@ bool PseuInstance::Init(void) return true; } +bool PseuInstance::InitGUI(void) +{ + if(GetGUI()) + { + logerror("GUI: Aborting init, GUI already exists!"); + return false; + } + uint16 x,y,depth; + uint8 driver; + bool shadows,vsync,win; + + driver=(uint8)atoi(GetScripts()->variables.Get("GUI::DRIVER").c_str()); + vsync=(bool)atoi(GetScripts()->variables.Get("GUI::VSYNC").c_str()); + depth=(uint8)atoi(GetScripts()->variables.Get("GUI::DEPTH").c_str()); + x=(uint16)atoi(GetScripts()->variables.Get("GUI::RESX").c_str()); + y=(uint16)atoi(GetScripts()->variables.Get("GUI::RESY").c_str()); + win=(bool)atoi(GetScripts()->variables.Get("GUI::WINDOWED").c_str()); + shadows=(bool)atoi(GetScripts()->variables.Get("GUI::SHADOWS").c_str()); + log("GUI settings: driver=%u, depth=%u, res=%ux%u, windowed=%u, shadows=%u",driver,depth,x,y,win,shadows); + if(x>0 && y>0 && (depth==16 || depth==32) && driver>0 && driver<=5) + { + PseuGUIRunnable *rgui = new PseuGUIRunnable(); + _gui = rgui->GetGUI(); + _gui->SetInstance(this); + _gui->SetDriver(driver); + _gui->SetResolution(x,y,depth); + _gui->SetVSync(vsync); + _gui->UseShadows(shadows); + _guithread = new ZThread::Thread(rgui); + return true; + } + else + logerror("GUI: incorrect settings!"); + return false; +} + void PseuInstance::Run(void) { if(!_initialized) diff --git a/src/Client/PseuWoW.h b/src/Client/PseuWoW.h index ad63f0d..8344c91 100644 --- a/src/Client/PseuWoW.h +++ b/src/Client/PseuWoW.h @@ -87,7 +87,8 @@ public: inline void SetError(void) { _error = true; } SCPDatabaseMgr dbmgr; - bool Init(); + bool Init(void); + bool InitGUI(void); void SaveAllCache(void); inline void Stop(void) { _stop = true; } inline bool Stopped(void) { return _stop; } @@ -108,7 +109,7 @@ private: WorldSession *_wsession; PseuInstanceConf *_conf; DefScriptPackage *_scp; - std::string _confdir,_scpdir; // _scpdir is the scipts dir, and NOT where SCP files are stored!! + std::string _confdir,_scpdir; // _scpdir is the scripts dir, and NOT where SCP files are stored!! bool _initialized; bool _stop,_fastquit; bool _startrealm; diff --git a/src/Client/World/MapMgr.h b/src/Client/World/MapMgr.h index 48535cc..20b7982 100644 --- a/src/Client/World/MapMgr.h +++ b/src/Client/World/MapMgr.h @@ -18,6 +18,9 @@ public: MapTile *GetNearTile(int32, int32); inline bool Loaded(void) { return _mapsLoaded; } uint32 GetLoadedMapsCount(void); + inline uint32 GetGridX(void) { return _gridx; } + inline uint32 GetGridY(void) { return _gridy; } + private: MapTileStorage *_tiles; diff --git a/src/Client/World/World.cpp b/src/Client/World/World.cpp index 4fa0b8d..387f833 100644 --- a/src/Client/World/World.cpp +++ b/src/Client/World/World.cpp @@ -14,10 +14,22 @@ World::World(WorldSession *s) World::~World() { + Clear(); if(_mapmgr) delete _mapmgr; } +// called on SMSG_NEW_WORLD +void World::Clear(void) +{ + if(_mapmgr) + { + _mapmgr->Flush(); + } + // TODO: clear WorldStates (-> SMSG_INIT_WORLD_STATES ?) and everything else thats required +} + + void World::Update(void) { if(_mapmgr) diff --git a/src/Client/World/World.h b/src/Client/World/World.h index 29e2b12..f933d7c 100644 --- a/src/Client/World/World.h +++ b/src/Client/World/World.h @@ -13,10 +13,11 @@ public: inline uint32 GetMapId(void) { return _mapId; } inline WorldSession *GetSession(void) { return _session; } + void Clear(void); void Update(void); void UpdatePos(float,float,uint32); void UpdatePos(float,float); - inline float GetPosZ(float x, float y); + float GetPosZ(float x, float y); inline MapMgr *GetMapMgr(void) { return _mapmgr; } private: diff --git a/src/Client/World/WorldSession.cpp b/src/Client/World/WorldSession.cpp index 1a415fc..cb87502 100644 --- a/src/Client/World/WorldSession.cpp +++ b/src/Client/World/WorldSession.cpp @@ -29,7 +29,7 @@ WorldSession::WorldSession(PseuInstance *in) _socket=NULL; _myGUID=0; // i dont have a guid yet _channels = new Channel(this); - _world = NULL; + _world = new World(this); _sh.SetAutoCloseSockets(false); objmgr.SetInstance(in); //... @@ -752,10 +752,11 @@ void WorldSession::_HandleNewWorldOpcode(WorldPacket& recvPacket) if(GetMyChar()) GetMyChar()->ClearSpells(); // will be resent by server // TODO: clear action buttons - if(_world) - delete _world; - _world = new World(this); + + // clear world data and load required maps + _world->Clear(); _world->UpdatePos(x,y,mapid); + _world->Update(); if(GetInstance()->GetScripts()->ScriptExists("_onteleport")) { @@ -948,17 +949,14 @@ void WorldSession::_HandleLoginVerifyWorldOpcode(WorldPacket& recvPacket) float x,y,z,o; uint32 m; recvPacket >> m >> x >> y >> z >> o; - // for now, init the world as soon as the server confirmed that we are where we are. logdebug("LoginVerifyWorld: map=%u x=%f y=%f z=%f o=%f",m,x,y,z,o); _OnEnterWorld(); - if(_world) - delete _world; - _world = new World(this); + // update the world as soon as the server confirmed that we are where we are. _world->UpdatePos(x,y,m); + _world->Update(); // temp. solution to test terrain rendering - PseuGUI *gui = GetInstance()->GetGUI(); - if(gui) + if(PseuGUI *gui = GetInstance()->GetGUI()) { gui->SetSceneState(SCENESTATE_WORLD); } diff --git a/src/shared/common.h b/src/shared/common.h index e2707b0..092d034 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -30,6 +30,10 @@ #include "ByteBuffer.h" +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + #endif