* added more "familiar" camera control ;)
* added skydome and some test fog * added some debug output in the window * code cleanups
This commit is contained in:
parent
cf9fcb3d20
commit
fc3632a889
BIN
bin/data/misc/sky.jpg
Normal file
BIN
bin/data/misc/sky.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 374 KiB |
@ -55,6 +55,7 @@ void DefScriptPackage::_InitDefScriptInterface(void)
|
|||||||
AddFunc("getopcodeid",&DefScriptPackage::SCGetOpcodeID);
|
AddFunc("getopcodeid",&DefScriptPackage::SCGetOpcodeID);
|
||||||
AddFunc("bbgetpackedguid",&DefScriptPackage::SCBBGetPackedGuid);
|
AddFunc("bbgetpackedguid",&DefScriptPackage::SCBBGetPackedGuid);
|
||||||
AddFunc("bbputpackedguid",&DefScriptPackage::SCBBPutPackedGuid);
|
AddFunc("bbputpackedguid",&DefScriptPackage::SCBBPutPackedGuid);
|
||||||
|
AddFunc("gui",&DefScriptPackage::SCGui);
|
||||||
}
|
}
|
||||||
|
|
||||||
DefReturnResult DefScriptPackage::SCshdn(CmdSet& Set)
|
DefReturnResult DefScriptPackage::SCshdn(CmdSet& Set)
|
||||||
@ -957,6 +958,24 @@ DefReturnResult DefScriptPackage::SCBBPutPackedGuid(CmdSet &Set)
|
|||||||
return true;
|
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)
|
void DefScriptPackage::My_LoadUserPermissions(VarSet &vs)
|
||||||
{
|
{
|
||||||
static char *prefix = "USERS::";
|
static char *prefix = "USERS::";
|
||||||
|
|||||||
@ -46,5 +46,6 @@ DefReturnResult SCGetOpcodeName(CmdSet&);
|
|||||||
DefReturnResult SCGetOpcodeID(CmdSet&);
|
DefReturnResult SCGetOpcodeID(CmdSet&);
|
||||||
DefReturnResult SCBBGetPackedGuid(CmdSet&);
|
DefReturnResult SCBBGetPackedGuid(CmdSet&);
|
||||||
DefReturnResult SCBBPutPackedGuid(CmdSet&);
|
DefReturnResult SCBBPutPackedGuid(CmdSet&);
|
||||||
|
DefReturnResult SCGui(CmdSet&);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -162,7 +162,7 @@ void PseuGUI::Run(void)
|
|||||||
while(_device && _device->run() && !_mustdie)
|
while(_device && _device->run() && !_mustdie)
|
||||||
{
|
{
|
||||||
_lastpasstime = _passtime;
|
_lastpasstime = _passtime;
|
||||||
_passtime = _timer->getTime() / 1000.0f;
|
_passtime = _timer->getTime();
|
||||||
_passtimediff = _passtime - _lastpasstime;
|
_passtimediff = _passtime - _lastpasstime;
|
||||||
// _HandleWindowResize(); // not yet used; doesnt work
|
// _HandleWindowResize(); // not yet used; doesnt work
|
||||||
|
|
||||||
|
|||||||
@ -92,7 +92,7 @@ private:
|
|||||||
SceneState _scenestate, _scenestate_new;
|
SceneState _scenestate, _scenestate_new;
|
||||||
Scene *_scene;
|
Scene *_scene;
|
||||||
irr::ITimer *_timer;
|
irr::ITimer *_timer;
|
||||||
float _passtime, _lastpasstime, _passtimediff;
|
uint32 _passtime, _lastpasstime, _passtimediff;
|
||||||
irr::core::dimension2d<irr::s32> _screendimension;
|
irr::core::dimension2d<irr::s32> _screendimension;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -21,7 +21,7 @@ void Scene::OnDelete(void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::OnUpdate(f32)
|
void Scene::OnUpdate(s32)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,7 @@ class Scene
|
|||||||
public:
|
public:
|
||||||
Scene(PseuGUI *g);
|
Scene(PseuGUI *g);
|
||||||
~Scene();
|
~Scene();
|
||||||
virtual void OnUpdate(f32);
|
virtual void OnUpdate(s32);
|
||||||
virtual void OnDraw(void);
|
virtual void OnDraw(void);
|
||||||
virtual void OnDelete(void);
|
virtual void OnDelete(void);
|
||||||
protected:
|
protected:
|
||||||
@ -44,7 +44,10 @@ private:
|
|||||||
|
|
||||||
class ShTlTerrainSceneNode;
|
class ShTlTerrainSceneNode;
|
||||||
class MCameraFPS;
|
class MCameraFPS;
|
||||||
|
class MCameraOrbit;
|
||||||
class MyEventReceiver;
|
class MyEventReceiver;
|
||||||
|
class MapMgr;
|
||||||
|
class WorldSession;
|
||||||
|
|
||||||
class SceneWorld : public Scene
|
class SceneWorld : public Scene
|
||||||
{
|
{
|
||||||
@ -52,12 +55,21 @@ public:
|
|||||||
SceneWorld(PseuGUI *gui);
|
SceneWorld(PseuGUI *gui);
|
||||||
void OnDraw(void);
|
void OnDraw(void);
|
||||||
void OnDelete(void);
|
void OnDelete(void);
|
||||||
void OnUpdate(f32);
|
void OnUpdate(s32);
|
||||||
|
void UpdateTerrain(void);
|
||||||
|
void InitTerrain(void);
|
||||||
private:
|
private:
|
||||||
ShTlTerrainSceneNode *terrain;
|
ShTlTerrainSceneNode *terrain;
|
||||||
MCameraFPS *camera;
|
MCameraFPS *camera;
|
||||||
MyEventReceiver *eventrecv;
|
MyEventReceiver *eventrecv;
|
||||||
ZThread::FastMutex mutex;
|
ZThread::FastMutex mutex;
|
||||||
|
PseuGUI *gui;
|
||||||
|
uint32 map_gridX, map_gridY;
|
||||||
|
s32 mapsize, tilesize, meshsize;
|
||||||
|
WorldSession *wsession;
|
||||||
|
MapMgr *mapmgr;
|
||||||
|
IGUIStaticText *debugText;
|
||||||
|
bool debugmode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#include <sstream>
|
||||||
|
#include <math.h>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "PseuGUI.h"
|
#include "PseuGUI.h"
|
||||||
#include "PseuWoW.h"
|
#include "PseuWoW.h"
|
||||||
@ -9,118 +11,25 @@
|
|||||||
#include "MInput.h"
|
#include "MInput.h"
|
||||||
#include "WorldSession.h"
|
#include "WorldSession.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include <sstream>
|
|
||||||
|
#define MOUSE_SENSIVITY 0.5f
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SceneWorld::SceneWorld(PseuGUI *g) : Scene(g)
|
SceneWorld::SceneWorld(PseuGUI *g) : Scene(g)
|
||||||
{
|
{
|
||||||
DEBUG(logdebug("SceneWorld: Initializing..."));
|
DEBUG(logdebug("SceneWorld: Initializing..."));
|
||||||
|
debugmode = false;
|
||||||
|
|
||||||
s32 mapsize = 9 * 16 * 3; // 9 height floats in 16 chunks per tile per axis in 3 MapTiles
|
// store some pointers right now to prevent repeated ptr dereferencing later (speeds up code)
|
||||||
s32 tilesize = UNITSIZE;
|
gui = g;
|
||||||
s32 meshsize = CHUNKSIZE*3;
|
wsession = gui->GetInstance()->GetWSession();
|
||||||
vector3df terrainPos(0.0f, 0.0f, 0.0f); // TODO: use PseuWoW's world coords here?
|
mapmgr = wsession->GetWorld()->GetMapMgr();
|
||||||
|
|
||||||
eventrecv = new MyEventReceiver();
|
// TODO: hardcoded for now, make this adjustable later
|
||||||
device->setEventReceiver(eventrecv);
|
float fogdist = 100;
|
||||||
|
|
||||||
camera = new MCameraFPS(smgr);
|
ILightSceneNode* light = smgr->addLightSceneNode(0, core::vector3df(0,0,0), SColorf(255, 255, 255, 255), 1000.0f);
|
||||||
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; j<terrain->getSize().Height+1; j++)
|
|
||||||
for(s32 i=0; i<terrain->getSize().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);
|
|
||||||
SLight ldata = light->getLightData();
|
SLight ldata = light->getLightData();
|
||||||
ldata.AmbientColor = video::SColorf(0.2f,0.2f,0.2f);
|
ldata.AmbientColor = video::SColorf(0.2f,0.2f,0.2f);
|
||||||
ldata.DiffuseColor = video::SColorf(1.0f,1.0f,1.0f);
|
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);
|
ldata.Position = core::vector3df(-10,5,-5);
|
||||||
light->setLightData(ldata);
|
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<s32>(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!"));
|
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);
|
static position2d<s32> mouse_pos;
|
||||||
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);
|
|
||||||
|
|
||||||
// mouse directional control
|
UpdateTerrain();
|
||||||
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);
|
|
||||||
|
|
||||||
|
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
|
// camera height control
|
||||||
if (eventrecv->mouse.wheel < 10) eventrecv->mouse.wheel = 10;
|
if (eventrecv->mouse.wheel < 10) eventrecv->mouse.wheel = 10;
|
||||||
camera->setHeight( eventrecv->mouse.wheel + terrain->getHeight(camera->getPosition()) );
|
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)
|
void SceneWorld::OnDraw(void)
|
||||||
@ -160,3 +179,124 @@ void SceneWorld::OnDelete(void)
|
|||||||
{
|
{
|
||||||
DEBUG(logdebug("~SceneWorld()"));
|
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; j<terrain->getSize().Height+1; j++)
|
||||||
|
for(s32 i=0; i<terrain->getSize().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; j<terrain->getSize().Height+1; j++)
|
||||||
|
for(s32 i=0; i<terrain->getSize().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();
|
||||||
|
}
|
||||||
|
|||||||
@ -134,31 +134,10 @@ bool PseuInstance::Init(void)
|
|||||||
// TODO: find a better loaction where to place this block!
|
// TODO: find a better loaction where to place this block!
|
||||||
if(GetConf()->enablegui)
|
if(GetConf()->enablegui)
|
||||||
{
|
{
|
||||||
uint16 x,y,depth;
|
if(InitGUI())
|
||||||
uint8 driver;
|
logdebug("GUI: Init successful.");
|
||||||
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);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
logerror("GUI: incorrect settings!");
|
logerror("GUI: Init failed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(GetConf()->rmcontrolport)
|
if(GetConf()->rmcontrolport)
|
||||||
@ -184,6 +163,42 @@ bool PseuInstance::Init(void)
|
|||||||
return true;
|
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)
|
void PseuInstance::Run(void)
|
||||||
{
|
{
|
||||||
if(!_initialized)
|
if(!_initialized)
|
||||||
|
|||||||
@ -87,7 +87,8 @@ public:
|
|||||||
inline void SetError(void) { _error = true; }
|
inline void SetError(void) { _error = true; }
|
||||||
SCPDatabaseMgr dbmgr;
|
SCPDatabaseMgr dbmgr;
|
||||||
|
|
||||||
bool Init();
|
bool Init(void);
|
||||||
|
bool InitGUI(void);
|
||||||
void SaveAllCache(void);
|
void SaveAllCache(void);
|
||||||
inline void Stop(void) { _stop = true; }
|
inline void Stop(void) { _stop = true; }
|
||||||
inline bool Stopped(void) { return _stop; }
|
inline bool Stopped(void) { return _stop; }
|
||||||
@ -108,7 +109,7 @@ private:
|
|||||||
WorldSession *_wsession;
|
WorldSession *_wsession;
|
||||||
PseuInstanceConf *_conf;
|
PseuInstanceConf *_conf;
|
||||||
DefScriptPackage *_scp;
|
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 _initialized;
|
||||||
bool _stop,_fastquit;
|
bool _stop,_fastquit;
|
||||||
bool _startrealm;
|
bool _startrealm;
|
||||||
|
|||||||
@ -18,6 +18,9 @@ public:
|
|||||||
MapTile *GetNearTile(int32, int32);
|
MapTile *GetNearTile(int32, int32);
|
||||||
inline bool Loaded(void) { return _mapsLoaded; }
|
inline bool Loaded(void) { return _mapsLoaded; }
|
||||||
uint32 GetLoadedMapsCount(void);
|
uint32 GetLoadedMapsCount(void);
|
||||||
|
inline uint32 GetGridX(void) { return _gridx; }
|
||||||
|
inline uint32 GetGridY(void) { return _gridy; }
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MapTileStorage *_tiles;
|
MapTileStorage *_tiles;
|
||||||
|
|||||||
@ -14,10 +14,22 @@ World::World(WorldSession *s)
|
|||||||
|
|
||||||
World::~World()
|
World::~World()
|
||||||
{
|
{
|
||||||
|
Clear();
|
||||||
if(_mapmgr)
|
if(_mapmgr)
|
||||||
delete _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)
|
void World::Update(void)
|
||||||
{
|
{
|
||||||
if(_mapmgr)
|
if(_mapmgr)
|
||||||
|
|||||||
@ -13,10 +13,11 @@ public:
|
|||||||
|
|
||||||
inline uint32 GetMapId(void) { return _mapId; }
|
inline uint32 GetMapId(void) { return _mapId; }
|
||||||
inline WorldSession *GetSession(void) { return _session; }
|
inline WorldSession *GetSession(void) { return _session; }
|
||||||
|
void Clear(void);
|
||||||
void Update(void);
|
void Update(void);
|
||||||
void UpdatePos(float,float,uint32);
|
void UpdatePos(float,float,uint32);
|
||||||
void UpdatePos(float,float);
|
void UpdatePos(float,float);
|
||||||
inline float GetPosZ(float x, float y);
|
float GetPosZ(float x, float y);
|
||||||
inline MapMgr *GetMapMgr(void) { return _mapmgr; }
|
inline MapMgr *GetMapMgr(void) { return _mapmgr; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -29,7 +29,7 @@ WorldSession::WorldSession(PseuInstance *in)
|
|||||||
_socket=NULL;
|
_socket=NULL;
|
||||||
_myGUID=0; // i dont have a guid yet
|
_myGUID=0; // i dont have a guid yet
|
||||||
_channels = new Channel(this);
|
_channels = new Channel(this);
|
||||||
_world = NULL;
|
_world = new World(this);
|
||||||
_sh.SetAutoCloseSockets(false);
|
_sh.SetAutoCloseSockets(false);
|
||||||
objmgr.SetInstance(in);
|
objmgr.SetInstance(in);
|
||||||
//...
|
//...
|
||||||
@ -752,10 +752,11 @@ void WorldSession::_HandleNewWorldOpcode(WorldPacket& recvPacket)
|
|||||||
if(GetMyChar())
|
if(GetMyChar())
|
||||||
GetMyChar()->ClearSpells(); // will be resent by server
|
GetMyChar()->ClearSpells(); // will be resent by server
|
||||||
// TODO: clear action buttons
|
// TODO: clear action buttons
|
||||||
if(_world)
|
|
||||||
delete _world;
|
// clear world data and load required maps
|
||||||
_world = new World(this);
|
_world->Clear();
|
||||||
_world->UpdatePos(x,y,mapid);
|
_world->UpdatePos(x,y,mapid);
|
||||||
|
_world->Update();
|
||||||
|
|
||||||
if(GetInstance()->GetScripts()->ScriptExists("_onteleport"))
|
if(GetInstance()->GetScripts()->ScriptExists("_onteleport"))
|
||||||
{
|
{
|
||||||
@ -948,17 +949,14 @@ void WorldSession::_HandleLoginVerifyWorldOpcode(WorldPacket& recvPacket)
|
|||||||
float x,y,z,o;
|
float x,y,z,o;
|
||||||
uint32 m;
|
uint32 m;
|
||||||
recvPacket >> m >> x >> y >> z >> o;
|
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);
|
logdebug("LoginVerifyWorld: map=%u x=%f y=%f z=%f o=%f",m,x,y,z,o);
|
||||||
_OnEnterWorld();
|
_OnEnterWorld();
|
||||||
if(_world)
|
// update the world as soon as the server confirmed that we are where we are.
|
||||||
delete _world;
|
|
||||||
_world = new World(this);
|
|
||||||
_world->UpdatePos(x,y,m);
|
_world->UpdatePos(x,y,m);
|
||||||
|
_world->Update();
|
||||||
|
|
||||||
// temp. solution to test terrain rendering
|
// temp. solution to test terrain rendering
|
||||||
PseuGUI *gui = GetInstance()->GetGUI();
|
if(PseuGUI *gui = GetInstance()->GetGUI())
|
||||||
if(gui)
|
|
||||||
{
|
{
|
||||||
gui->SetSceneState(SCENESTATE_WORLD);
|
gui->SetSceneState(SCENESTATE_WORLD);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,10 @@
|
|||||||
|
|
||||||
#include "ByteBuffer.h"
|
#include "ByteBuffer.h"
|
||||||
|
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.14159265358979323846
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user