From 5458127d9706d2c124d907edc5be06e58384d562 Mon Sep 17 00:00:00 2001 From: D G Turner Date: Sun, 10 Jun 2012 16:00:26 +0100 Subject: TOON: Migrate Pathfinding API x,y coordinates to int16. This harmonises the usage with Common::Point. --- engines/toon/character.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines/toon/character.cpp') diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp index 0e5189957b..3ac454983d 100644 --- a/engines/toon/character.cpp +++ b/engines/toon/character.cpp @@ -173,7 +173,9 @@ bool Character::walkTo(int32 newPosX, int32 newPosY) { _vm->getPathFinding()->addBlockingEllipse(_vm->getDrew()->getFinalX(), _vm->getDrew()->getFinalY(), sizeX, sizeY); } - _vm->getPathFinding()->findClosestWalkingPoint(newPosX, newPosY, &_finalX, &_finalY, _x, _y); + int16 tempFinalX, tempFinalY; + _vm->getPathFinding()->findClosestWalkingPoint(newPosX, newPosY, &tempFinalX, &tempFinalY, _x, _y); + _finalX = tempFinalX, _finalY = tempFinalY; // FIXME - Bodge to match types... if (_x == _finalX && _y == _finalY) return true; -- cgit v1.2.3 From fcfff28c5f3cabf193d83846cfe9d90f0153d187 Mon Sep 17 00:00:00 2001 From: D G Turner Date: Sun, 10 Jun 2012 21:12:01 +0100 Subject: TOON: Minor type fixes and cleanups in Pathfinding class. --- engines/toon/character.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/toon/character.cpp') diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp index 3ac454983d..260296cc9f 100644 --- a/engines/toon/character.cpp +++ b/engines/toon/character.cpp @@ -186,7 +186,7 @@ bool Character::walkTo(int32 newPosX, int32 newPosY) { int32 smoothDx = 0; int32 smoothDy = 0; - for (int32 a = 0; a < _vm->getPathFinding()->getPathNodeCount(); a++) { + for (uint32 a = 0; a < _vm->getPathFinding()->getPathNodeCount(); a++) { _currentPathX[a] = _vm->getPathFinding()->getPathNodeX(a); _currentPathY[a] = _vm->getPathFinding()->getPathNodeY(a); } -- cgit v1.2.3 From 87eb651886ef911d8026d777abec72c88ffdf32f Mon Sep 17 00:00:00 2001 From: D G Turner Date: Thu, 14 Jun 2012 00:19:34 +0100 Subject: TOON: Migrate Character API x,y coordinates and subclasses to int16. This harmonises the usage with Common::Point. --- engines/toon/character.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'engines/toon/character.cpp') diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp index 260296cc9f..2a28642f6a 100644 --- a/engines/toon/character.cpp +++ b/engines/toon/character.cpp @@ -81,7 +81,7 @@ Character::~Character(void) { void Character::init() { } -void Character::forceFacing( int32 facing ) { +void Character::forceFacing(int32 facing) { debugC(4, kDebugCharacter, "forceFacing(%d)", facing); _facing = facing; } @@ -136,8 +136,7 @@ void Character::setFacing(int32 facing) { _facing = facing; } -void Character::forcePosition(int32 x, int32 y) { - +void Character::forcePosition(int16 x, int16 y) { debugC(5, kDebugCharacter, "forcePosition(%d, %d)", x, y); setPosition(x, y); @@ -145,7 +144,7 @@ void Character::forcePosition(int32 x, int32 y) { _finalY = y; } -void Character::setPosition(int32 x, int32 y) { +void Character::setPosition(int16 x, int16 y) { debugC(5, kDebugCharacter, "setPosition(%d, %d)", x, y); _x = x; @@ -155,7 +154,7 @@ void Character::setPosition(int32 x, int32 y) { return; } -bool Character::walkTo(int32 newPosX, int32 newPosY) { +bool Character::walkTo(int16 newPosX, int16 newPosY) { debugC(1, kDebugCharacter, "walkTo(%d, %d)", newPosX, newPosY); if (!_visible) @@ -168,21 +167,19 @@ bool Character::walkTo(int32 newPosX, int32 newPosY) { // don't allow flux to go at the same position as drew if (_id == 1 ) { - int32 sizeX = MAX(5, 30 * _vm->getDrew()->getScale() / 1024); - int32 sizeY = MAX(2, 20 * _vm->getDrew()->getScale() / 1024); + int16 sizeX = MAX(5, 30 * _vm->getDrew()->getScale() / 1024); + int16 sizeY = MAX(2, 20 * _vm->getDrew()->getScale() / 1024); _vm->getPathFinding()->addBlockingEllipse(_vm->getDrew()->getFinalX(), _vm->getDrew()->getFinalY(), sizeX, sizeY); } - int16 tempFinalX, tempFinalY; - _vm->getPathFinding()->findClosestWalkingPoint(newPosX, newPosY, &tempFinalX, &tempFinalY, _x, _y); - _finalX = tempFinalX, _finalY = tempFinalY; // FIXME - Bodge to match types... + _vm->getPathFinding()->findClosestWalkingPoint(newPosX, newPosY, &_finalX, &_finalY, _x, _y); if (_x == _finalX && _y == _finalY) return true; if (_vm->getPathFinding()->findPath(_x, _y, _finalX, _finalY)) { - int32 localFinalX = _finalX; - int32 localFinalY = _finalY; + int16 localFinalX = _finalX; + int16 localFinalY = _finalY; int32 smoothDx = 0; int32 smoothDy = 0; @@ -266,10 +263,11 @@ int32 Character::getFlag() { return _flags; } -int32 Character::getX() { +int16 Character::getX() { return _x; } -int32 Character::getY() { + +int16 Character::getY() { return _y; } @@ -529,7 +527,7 @@ void Character::update(int32 timeIncrement) { } // adapted from Kyra -int32 Character::getFacingFromDirection(int32 dx, int32 dy) { +int32 Character::getFacingFromDirection(int16 dx, int16 dy) { debugC(4, kDebugCharacter, "getFacingFromDirection(%d, %d)", dx, dy); static const int facingTable[] = { @@ -640,7 +638,7 @@ void Character::load(Common::ReadStream *stream) { // "not visible" flag. if (_flags & 0x100) { _flags &= ~0x100; - setVisible(false); + setVisible(false); } } @@ -1080,11 +1078,11 @@ void Character::setDefaultSpecialAnimationId(int32 defaultAnimationId) { _animSpecialDefaultId = defaultAnimationId; } -int32 Character::getFinalX() { +int16 Character::getFinalX() { return _finalX; } -int32 Character::getFinalY() { +int16 Character::getFinalY() { return _finalY; } -- cgit v1.2.3 From d2eab05e7d08bd5e4e615ee786e62be64293060a Mon Sep 17 00:00:00 2001 From: D G Turner Date: Thu, 14 Jun 2012 13:38:45 +0100 Subject: TOON: Replace Character _currentPath static buffers with Common::Array. --- engines/toon/character.cpp | 57 ++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 30 deletions(-) (limited to 'engines/toon/character.cpp') diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp index 2a28642f6a..c9073de587 100644 --- a/engines/toon/character.cpp +++ b/engines/toon/character.cpp @@ -56,7 +56,6 @@ Character::Character(ToonEngine *vm) : _vm(vm) { _animScriptId = -1; _animSpecialId = -1; _animSpecialDefaultId = 0; - _currentPathNodeCount = 0; _currentPathNode = 0; _currentWalkStamp = 0; _visible = true; @@ -123,7 +122,7 @@ void Character::setFacing(int32 facing) { _lastWalkTime = _vm->getOldMilli(); } - if (_currentPathNode == 0) + if (_currentPathNode == 0) playStandingAnim(); else playWalkAnim(0, 0); @@ -166,7 +165,7 @@ bool Character::walkTo(int16 newPosX, int16 newPosY) { _vm->getPathFinding()->resetBlockingRects(); // don't allow flux to go at the same position as drew - if (_id == 1 ) { + if (_id == 1) { int16 sizeX = MAX(5, 30 * _vm->getDrew()->getScale() / 1024); int16 sizeY = MAX(2, 20 * _vm->getDrew()->getScale() / 1024); _vm->getPathFinding()->addBlockingEllipse(_vm->getDrew()->getFinalX(), _vm->getDrew()->getFinalY(), sizeX, sizeY); @@ -183,11 +182,9 @@ bool Character::walkTo(int16 newPosX, int16 newPosY) { int32 smoothDx = 0; int32 smoothDy = 0; - for (uint32 a = 0; a < _vm->getPathFinding()->getPathNodeCount(); a++) { - _currentPathX[a] = _vm->getPathFinding()->getPathNodeX(a); - _currentPathY[a] = _vm->getPathFinding()->getPathNodeY(a); - } - _currentPathNodeCount = _vm->getPathFinding()->getPathNodeCount(); + _currentPath.clear(); + for (uint32 a = 0; a < _vm->getPathFinding()->getPathNodeCount(); a++) + _currentPath.push_back(Common::Point(_vm->getPathFinding()->getPathNodeX(a), _vm->getPathFinding()->getPathNodeY(a))); _currentPathNode = 0; stopSpecialAnim(); @@ -202,12 +199,12 @@ bool Character::walkTo(int16 newPosX, int16 newPosY) { int32 localWalkStamp = _currentWalkStamp; if (_blockingWalk) { - while ((_x != newPosX || _y != newPosY) && _currentPathNode < _currentPathNodeCount && !_vm->shouldQuitGame()) { - if (_currentPathNode < _currentPathNodeCount - 4) { - int32 delta = MIN(4, _currentPathNodeCount - _currentPathNode); + while ((_x != newPosX || _y != newPosY) && _currentPathNode < _currentPath.size() && !_vm->shouldQuitGame()) { + if (_currentPathNode < _currentPath.size() - 4) { + int32 delta = MIN(4, _currentPath.size() - _currentPathNode); - int32 dx = _currentPathX[_currentPathNode+delta] - _x; - int32 dy = _currentPathY[_currentPathNode+delta] - _y; + int16 dx = _currentPath[_currentPathNode+delta].x - _x; + int16 dy = _currentPath[_currentPathNode+delta].y - _y; // smooth the facing computation. It prevents some ugly flickering from happening if (!smoothDx && !smoothDy) { @@ -226,9 +223,9 @@ bool Character::walkTo(int16 newPosX, int16 newPosY) { _numPixelToWalk += _speed * (_vm->getSystem()->getMillis() - _lastWalkTime) * _scale / 1024; _lastWalkTime = _vm->getSystem()->getMillis(); - while (_numPixelToWalk >= 1000 && _currentPathNode < _currentPathNodeCount) { - _x = _currentPathX[_currentPathNode]; - _y = _currentPathY[_currentPathNode]; + while (_numPixelToWalk >= 1000 && _currentPathNode < _currentPath.size()) { + _x = _currentPath[_currentPathNode].x; + _y = _currentPath[_currentPathNode].y; _currentPathNode += 1; _numPixelToWalk -= 1000; } @@ -244,7 +241,7 @@ bool Character::walkTo(int16 newPosX, int16 newPosY) { playStandingAnim(); _flags &= ~0x1; _currentPathNode = 0; - _currentPathNodeCount = 0; + _currentPath.clear(); if (_x != localFinalX || _y != localFinalY) { return false; @@ -348,12 +345,12 @@ void Character::stopSpecialAnim() { void Character::update(int32 timeIncrement) { debugC(5, kDebugCharacter, "update(%d)", timeIncrement); - if ((_flags & 0x1) && _currentPathNodeCount > 0) { - if (_currentPathNode < _currentPathNodeCount) { - if (_currentPathNode < _currentPathNodeCount - 10) { - int32 delta = MIN(10, _currentPathNodeCount - _currentPathNode); - int32 dx = _currentPathX[_currentPathNode+delta] - _x; - int32 dy = _currentPathY[_currentPathNode+delta] - _y; + if ((_flags & 0x1) && _currentPath.size() > 0) { + if (_currentPathNode < _currentPath.size()) { + if (_currentPathNode < _currentPath.size() - 10) { + int32 delta = MIN(10, _currentPath.size() - _currentPathNode); + int16 dx = _currentPath[_currentPathNode+delta].x - _x; + int16 dy = _currentPath[_currentPathNode+delta].y - _y; setFacing(getFacingFromDirection(dx, dy)); playWalkAnim(0, 0); } @@ -362,9 +359,9 @@ void Character::update(int32 timeIncrement) { _numPixelToWalk += _speed * (_vm->getSystem()->getMillis() - _lastWalkTime) * _scale / 1024; _lastWalkTime = _vm->getSystem()->getMillis(); - while (_numPixelToWalk > 1000 && _currentPathNode < _currentPathNodeCount) { - _x = _currentPathX[_currentPathNode]; - _y = _currentPathY[_currentPathNode]; + while (_numPixelToWalk > 1000 && _currentPathNode < _currentPath.size()) { + _x = _currentPath[_currentPathNode].x; + _y = _currentPath[_currentPathNode].y; _currentPathNode += 1; _numPixelToWalk -= 1000; } @@ -372,7 +369,7 @@ void Character::update(int32 timeIncrement) { } else { playStandingAnim(); _flags &= ~0x1; - _currentPathNodeCount = 0; + _currentPath.clear(); } } @@ -664,7 +661,7 @@ void Character::stopWalk() { _finalY = _y; _flags &= ~0x1; _currentPathNode = 0; - _currentPathNodeCount = 0; + _currentPath.clear(); } const SpecialCharacterAnimation *Character::getSpecialAnimation(int32 characterId, int32 animationId) { @@ -996,8 +993,8 @@ bool Character::loadShadowAnimation(const Common::String &animName) { } void Character::plotPath(Graphics::Surface& surface) { - for (int i = 0; i < _currentPathNodeCount; i++) { - *(byte *)surface.getBasePtr(_currentPathX[i], _currentPathY[i]) = ( i < _currentPathNode); + for (uint32 i = 0; i < _currentPath.size(); i++) { + *(byte *)surface.getBasePtr(_currentPath[i].x, _currentPath[i].y) = (i < _currentPathNode); } } -- cgit v1.2.3