From c4795eb6cb945fe613d54aca2333c1b6be979a70 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 25 Feb 2011 04:15:22 +0000 Subject: [PATCH] - more fixing of map corner position actions causing memory access violations (this will further stabilize the code) --- source/glest_game/graphics/renderer.cpp | 14 ++------------ source/glest_game/type_instances/unit.cpp | 13 ++++++++++--- source/glest_game/world/world.cpp | 7 ------- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 33f3c71e..6ccb30dd 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -2660,12 +2660,7 @@ void Renderer::renderSelectionEffects() { } else { Vec2i pos= c->getPos(); - if(pos.x < 0) { - pos.x = 0; - } - if(pos.y < 0) { - pos.y = 0; - } + map->clampPos(pos); arrowTarget= Vec3f(pos.x, map->getCell(pos)->getHeight(), pos.y); } @@ -2677,12 +2672,7 @@ void Renderer::renderSelectionEffects() { //meeting point arrow if(unit->getType()->getMeetingPoint()) { Vec2i pos= unit->getMeetingPos(); - if(pos.x < 0) { - pos.x = 0; - } - if(pos.y < 0) { - pos.y = 0; - } + map->clampPos(pos); Vec3f arrowTarget= Vec3f(pos.x, map->getCell(pos)->getHeight(), pos.y); renderArrow(unit->getCurrVectorFlat(), arrowTarget, Vec3f(0.f, 0.f, 1.f), 0.3f); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index f00928c0..0f29bd22 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -641,7 +641,9 @@ void Unit::setPos(const Vec2i &pos) { this->lastPos= this->pos; this->pos= pos; + map->clampPos(this->pos); this->meetingPos= pos - Vec2i(1); + map->clampPos(this->meetingPos); // Attempt to improve performance this->exploreCells(); @@ -656,6 +658,8 @@ void Unit::setTargetPos(const Vec2i &targetPos) { } Vec2i relPos= targetPos - pos; + //map->clampPos(relPos); + Vec2f relPosf= Vec2f((float)relPos.x, (float)relPos.y); #ifdef USE_STREFLOP targetRotation= radToDeg(streflop::atan2(relPosf.x, relPosf.y)); @@ -669,6 +673,7 @@ void Unit::setTargetPos(const Vec2i &targetPos) { //this->targetPos = Vec2i(0); this->targetPos= targetPos; + map->clampPos(this->targetPos); logSynchData(__FILE__,__LINE__); } @@ -1856,11 +1861,13 @@ void Unit::setTargetVec(const Vec3f &targetVec) { } void Unit::setMeetingPos(const Vec2i &meetingPos) { - if(map->isInside(meetingPos) == false || map->isInsideSurface(map->toSurfCoords(meetingPos)) == false) { - throw runtime_error("#8 Invalid path position = " + meetingPos.getString()); + this->meetingPos= meetingPos; + map->clampPos(this->meetingPos); + + if(map->isInside(this->meetingPos) == false || map->isInsideSurface(map->toSurfCoords(this->meetingPos)) == false) { + throw runtime_error("#8 Invalid path position = " + this->meetingPos.getString()); } - this->meetingPos= meetingPos; logSynchData(__FILE__,__LINE__); } diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 4b9bf627..597e57aa 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -557,13 +557,6 @@ bool World::placeUnit(const Vec2i &startLoc, int radius, Unit *unit, bool spacia if(freeSpace) { unit->setPos(pos); Vec2i meetingPos = pos-Vec2i(1); - if(meetingPos.x < 0) { - meetingPos.x = 0; - } - if(meetingPos.y < 0) { - meetingPos.y = 0; - } - unit->setMeetingPos(meetingPos); return true; }