From a42ffed5cb5418e0c7e3710d0344fba0f3376a16 Mon Sep 17 00:00:00 2001 From: Joel Teichroeb Date: Fri, 27 May 2011 16:04:22 -0700 Subject: [PATCH] Some cleanup of scene and scene related code. --- engines/grim/lua_v1_actor.cpp | 13 +++++++------ engines/grim/scene.cpp | 15 +++++++++++---- engines/grim/scene.h | 28 ++++++++++++---------------- engines/grim/walkplane.cpp | 2 +- engines/grim/walkplane.h | 2 +- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/engines/grim/lua_v1_actor.cpp b/engines/grim/lua_v1_actor.cpp index 116f0abb7ce..af96f032c58 100644 --- a/engines/grim/lua_v1_actor.cpp +++ b/engines/grim/lua_v1_actor.cpp @@ -1186,7 +1186,7 @@ void L1_WalkActorVector() { moveVert = luaL_check_number(4); // Get the direction the camera is pointing - Graphics::Vector3d cameraVector = g_grim->getCurrScene()->_currSetup->_interest - g_grim->getCurrScene()->_currSetup->_pos; + Graphics::Vector3d cameraVector = g_grim->getCurrScene()->getCurrSetup()->_interest - g_grim->getCurrScene()->getCurrSetup()->_pos; // find the angle the camera direction is around the unit circle float cameraYaw = cameraVector.unitCircleAngle(); @@ -1292,20 +1292,21 @@ void L1_PutActorAtInterest() { return; Actor *actor = getactor(actorObj); - if (!g_grim->getCurrScene()) + Scene *scene = g_grim->getCurrScene(); + if (!scene) return; - Graphics::Vector3d p = g_grim->getCurrScene()->_currSetup->_interest; + Graphics::Vector3d p = scene->getCurrSetup()->_interest; Graphics::Vector3d resultPt = p; float minDist = -1.f; - for (int i = 0; i < g_grim->getCurrScene()->getSectorCount(); ++i) { - Sector *sector = g_grim->getCurrScene()->getSectorBase(i); + for (int i = 0; i < scene->getSectorCount(); ++i) { + Sector *sector = scene->getSectorBase(i); if (sector->getType() != Sector::WalkType || !sector->isVisible()) continue; Graphics::Vector3d closestPt = sector->getClosestPoint(p); - if (g_grim->getCurrScene()->findPointSector(closestPt, Sector::HotType)) + if (scene->findPointSector(closestPt, Sector::HotType)) continue; float thisDist = (closestPt - p).magnitude(); if (minDist < 0 || thisDist < minDist) { diff --git a/engines/grim/scene.cpp b/engines/grim/scene.cpp index eaf88e82639..c7691ce7f45 100644 --- a/engines/grim/scene.cpp +++ b/engines/grim/scene.cpp @@ -521,7 +521,7 @@ void Scene::drawBitmaps(ObjectState::Position stage) { } } -Sector *Scene::findPointSector(Graphics::Vector3d p, Sector::SectorType type) { +Sector *Scene::findPointSector(const Graphics::Vector3d &p, Sector::SectorType type) { for (int i = 0; i < _numSectors; i++) { Sector *sector = _sectors[i]; if (sector && (sector->getType() & type) && sector->isVisible() && sector->isPointInSector(p)) @@ -530,7 +530,7 @@ Sector *Scene::findPointSector(Graphics::Vector3d p, Sector::SectorType type) { return NULL; } -void Scene::findClosestSector(Graphics::Vector3d p, Sector **sect, Graphics::Vector3d *closestPoint) { +void Scene::findClosestSector(const Graphics::Vector3d &p, Sector **sect, Graphics::Vector3d *closestPoint) { Sector *resultSect = NULL; Graphics::Vector3d resultPt = p; float minDist = 0.0; @@ -588,7 +588,7 @@ void Scene::setLightIntensity(int light, float intensity) { _lightsConfigured = false; } -void Scene::setLightPosition(const char *light, Graphics::Vector3d pos) { +void Scene::setLightPosition(const char *light, const Graphics::Vector3d &pos) { for (int i = 0; i < _numLights; ++i) { Light &l = _lights[i]; if (l._name == light) { @@ -599,7 +599,7 @@ void Scene::setLightPosition(const char *light, Graphics::Vector3d pos) { } } -void Scene::setLightPosition(int light, Graphics::Vector3d pos) { +void Scene::setLightPosition(int light, const Graphics::Vector3d &pos) { Light &l = _lights[light]; l._pos = pos; _lightsConfigured = false; @@ -626,6 +626,13 @@ void Scene::setSoundPosition(const char *soundName, Graphics::Vector3d pos, int //g_imuse->setPan(soundName, pan); } +Sector *Scene::getSectorBase(int id) { + if ((_numSectors >= 0) && (id < _numSectors)) + return _sectors[id]; + else + return NULL; +} + void Scene::setSoundParameters(int minVolume, int maxVolume) { _minVolume = minVolume; _maxVolume = maxVolume; diff --git a/engines/grim/scene.h b/engines/grim/scene.h index a4ad1221875..8d58caa1583 100644 --- a/engines/grim/scene.h +++ b/engines/grim/scene.h @@ -73,24 +73,19 @@ public: } void setLightIntensity(const char *light, float intensity); void setLightIntensity(int light, float intensity); - void setLightPosition(const char *light, Graphics::Vector3d pos); - void setLightPosition(int light, Graphics::Vector3d pos); + void setLightPosition(const char *light, const Graphics::Vector3d &pos); + void setLightPosition(int light, const Graphics::Vector3d &pos); void setSetup(int num); int getSetup() const { return _currSetup - _setups; } // Sector access functions - int getSectorCount() { - return _numSectors; - } - Sector *getSectorBase(int id) { - if ((_numSectors >= 0) && (id < _numSectors)) - return _sectors[id]; - else - return NULL; - } - Sector *findPointSector(Graphics::Vector3d p, Sector::SectorType type); - void findClosestSector(Graphics::Vector3d p, Sector **sect, Graphics::Vector3d *closestPt); + int getSectorCount() { return _numSectors; } + + Sector *getSectorBase(int id); + + Sector *findPointSector(const Graphics::Vector3d &p, Sector::SectorType type); + void findClosestSector(const Graphics::Vector3d &p, Sector **sect, Graphics::Vector3d *closestPt); void addObjectState(ObjectState *s) { _states.push_back(s); @@ -125,14 +120,16 @@ public: float _intensity, _umbraangle, _penumbraangle; }; - bool _locked; CMap *getCMap() { if (!_cmaps || ! _numCmaps) return NULL; return _cmaps[0]; }; + Setup *getCurrSetup() { return _currSetup; } + private: + bool _locked; void setId(int32 id); Common::String _name; int _numCmaps; @@ -143,9 +140,8 @@ private: Light *_lights; Setup *_setups; bool _lightsConfigured; -public: + Setup *_currSetup; -private: typedef Common::List StateList; StateList _states; diff --git a/engines/grim/walkplane.cpp b/engines/grim/walkplane.cpp index 444392d1d15..f7a3e867550 100644 --- a/engines/grim/walkplane.cpp +++ b/engines/grim/walkplane.cpp @@ -162,7 +162,7 @@ void Sector::setVisible(bool vis) { _visible = vis; } -bool Sector::isPointInSector(Graphics::Vector3d point) const { +bool Sector::isPointInSector(const Graphics::Vector3d &point) const { // The algorithm: for each edge A->B, check whether the z-component // of (B-A) x (P-A) is >= 0. Then the point is at least in the // cylinder above&below the polygon. (This works because the polygons' diff --git a/engines/grim/walkplane.h b/engines/grim/walkplane.h index d841b6d89bc..0fcbd88f2e8 100644 --- a/engines/grim/walkplane.h +++ b/engines/grim/walkplane.h @@ -63,7 +63,7 @@ public: int getSectorId() const { return _id; } SectorType getType() const { return _type; } // FIXME: Implement type de-masking bool isVisible() const { return _visible; } - bool isPointInSector(Graphics::Vector3d point) const; + bool isPointInSector(const Graphics::Vector3d &point) const; Common::List getBridgesTo(Sector *sector) const; Graphics::Vector3d getProjectionToPlane(const Graphics::Vector3d &point) const;