refactor: Return normal, not squared distances from public functions
This is to reduce ambiguity at the cost of performance.
This commit is contained in:
parent
117012b750
commit
9d6b107fb5
12 changed files with 15 additions and 24 deletions
|
@ -40,7 +40,7 @@ namespace reone {
|
|||
namespace game {
|
||||
|
||||
static const float kKeepPathDuration = 1000.0f;
|
||||
static const float kMaxConversationDistance = 8.0f;
|
||||
static const float kMaxConversationDistance = 3.0f;
|
||||
|
||||
ActionExecutor::ActionExecutor(Game *game) : _game(game) {
|
||||
if (!game) {
|
||||
|
@ -142,7 +142,7 @@ bool ActionExecutor::navigateCreature(Creature &creature, const glm::vec3 &dest,
|
|||
const glm::vec3 &origin = creature.position();
|
||||
float distToDest = glm::distance2(origin, dest);
|
||||
|
||||
if (distToDest <= distance) {
|
||||
if (distToDest <= distance * distance) {
|
||||
creature.setMovementType(Creature::MovementType::None);
|
||||
creature.clearPath();
|
||||
return true;
|
||||
|
|
|
@ -73,7 +73,7 @@ bool CollisionDetector::rayTestObjects(const RaycastProperties &props, RaycastRe
|
|||
if (props.flags & kRaycastSelectable && !object->isSelectable()) continue;
|
||||
|
||||
float dist = object->distanceTo(glm::vec2(props.origin));
|
||||
if (dist > props.maxDistance * props.maxDistance) continue;
|
||||
if (dist > props.maxDistance) continue;
|
||||
|
||||
invTransform = glm::inverse(object->transform());
|
||||
origin = invTransform * glm::vec4(props.origin, 1.0f);
|
||||
|
|
|
@ -100,7 +100,9 @@ bool SelectionOverlay::handleMouseMotion(const SDL_MouseMotionEvent &event) {
|
|||
}
|
||||
|
||||
bool SelectionOverlay::handleMouseButtonDown(const SDL_MouseButtonEvent &event) {
|
||||
if (event.clicks > 1 || _selectedActionIdx == -1) return false;
|
||||
if (event.clicks > 1 ||
|
||||
_selectedActionIdx == -1 |
|
||||
_selectedActionIdx >= _actions.size()) return false;
|
||||
|
||||
shared_ptr<Area> area(_game->module()->area());
|
||||
ObjectSelector &selector = area->objectSelector();
|
||||
|
|
|
@ -57,9 +57,7 @@ namespace reone {
|
|||
namespace game {
|
||||
|
||||
static const float kDefaultFieldOfView = 75.0f;
|
||||
static const float kDrawDebugDistance = 64.0f;
|
||||
static const float kPartyMemberFollowDistance = 4.0f;
|
||||
static const float kMaxDistanceToTestCollision = 64.0f;
|
||||
static const float kMaxDistanceToTestCollision = 8.0f;
|
||||
static const float kElevationTestZ = 1024.0f;
|
||||
static const float kCreatureObstacleTestZ = 0.1f;
|
||||
static const int kMaxSoundCount = 4;
|
||||
|
@ -596,7 +594,7 @@ shared_ptr<SpatialObject> Area::getObjectAt(int x, int y) const {
|
|||
props.direction = glm::normalize(toWorld - fromWorld);
|
||||
props.objectTypes = { ObjectType::Creature, ObjectType::Door, ObjectType::Placeable };
|
||||
props.except = partyLeader.get();
|
||||
props.maxDistance = 1000.0f;
|
||||
props.maxDistance = 2.0f * kSelectionDistance;
|
||||
|
||||
RaycastResult result;
|
||||
|
||||
|
@ -746,7 +744,7 @@ void Area::updateSounds() {
|
|||
float minDist = blueprint->minDistance();
|
||||
|
||||
float dist = soundPtr->distanceTo(cameraPosition);
|
||||
if (dist < minDist * minDist || dist > maxDist * maxDist) continue;
|
||||
if (dist < minDist || dist > maxDist) continue;
|
||||
|
||||
soundDistances.push_back(make_pair(soundPtr, dist));
|
||||
}
|
||||
|
|
|
@ -41,11 +41,11 @@ void SpatialObject::addItem(const shared_ptr<Item> &item) {
|
|||
}
|
||||
|
||||
float SpatialObject::distanceTo(const glm::vec2 &point) const {
|
||||
return glm::distance2(glm::vec2(_position), point);
|
||||
return glm::distance(glm::vec2(_position), point);
|
||||
}
|
||||
|
||||
float SpatialObject::distanceTo(const glm::vec3 &point) const {
|
||||
return glm::distance2(_position, point);
|
||||
return glm::distance(_position, point);
|
||||
}
|
||||
|
||||
bool SpatialObject::contains(const glm::vec3 &point) const {
|
||||
|
|
|
@ -33,8 +33,6 @@ namespace reone {
|
|||
|
||||
namespace game {
|
||||
|
||||
static const float kSelectionDistance = 64.0f;
|
||||
|
||||
ObjectSelector::ObjectSelector(const Area *area, const Party *party) :
|
||||
_area(area), _party(party) {
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ namespace reone {
|
|||
|
||||
namespace game {
|
||||
|
||||
const float kSelectionDistance = 8.0f;
|
||||
|
||||
class Area;
|
||||
class Party;
|
||||
|
||||
|
|
|
@ -40,9 +40,7 @@ void Pathfinder::load(const vector<Path::Point> &points, const unordered_map<int
|
|||
for (auto &adjPointIdx : point.adjPoints) {
|
||||
const Path::Point &adjPoint = points[adjPointIdx];
|
||||
adjPointVec = glm::vec3(adjPoint.x, adjPoint.y, pointZ.find(adjPointIdx)->second);
|
||||
|
||||
float distance = glm::distance2(pointVec, adjPointVec);
|
||||
|
||||
_edges[i].push_back({ static_cast<uint16_t>(adjPointIdx), distance });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,11 +128,6 @@ void ModelNodeSceneNode::renderSingle() const {
|
|||
mesh->render(_modelSceneNode->textureOverride());
|
||||
}
|
||||
|
||||
float ModelNodeSceneNode::getDistanceFromCenter(const glm::vec3 &point) const {
|
||||
glm::vec3 center(_absoluteTransform * glm::vec4(_modelNode->getCenterOfAABB(), 1.0f));
|
||||
return glm::distance2(center, point);
|
||||
}
|
||||
|
||||
const ModelSceneNode *ModelNodeSceneNode::modelSceneNode() const {
|
||||
return _modelSceneNode;
|
||||
}
|
||||
|
|
|
@ -38,8 +38,6 @@ public:
|
|||
|
||||
void renderSingle() const;
|
||||
|
||||
float getDistanceFromCenter(const glm::vec3 &point) const;
|
||||
|
||||
bool shouldRender() const;
|
||||
bool isTransparent() const;
|
||||
|
||||
|
|
|
@ -156,7 +156,7 @@ void SceneGraph::getLightsAt(const glm::vec3 &position, vector<LightSceneNode *>
|
|||
for (auto &light : _lights) {
|
||||
float distance = light->distanceTo(position);
|
||||
float radius = light->radius();
|
||||
if (distance > radius * radius) continue;
|
||||
if (distance > radius) continue;
|
||||
|
||||
distances.insert(make_pair(light, distance));
|
||||
lights.push_back(light);
|
||||
|
|
|
@ -56,7 +56,7 @@ void SceneNode::render() const {
|
|||
}
|
||||
|
||||
float SceneNode::distanceTo(const glm::vec3 &point) const {
|
||||
return glm::distance2(glm::vec3(_absoluteTransform[3]), point);
|
||||
return glm::distance(glm::vec3(_absoluteTransform[3]), point);
|
||||
}
|
||||
|
||||
const SceneNode *SceneNode::parent() const {
|
||||
|
|
Loading…
Reference in a new issue