aboutsummaryrefslogtreecommitdiff
path: root/engines/toon
diff options
context:
space:
mode:
authorD G Turner2012-06-14 13:38:45 +0100
committerD G Turner2012-06-14 13:38:45 +0100
commitd2eab05e7d08bd5e4e615ee786e62be64293060a (patch)
treeba5350fccd67a24de750bb8a758a3081e5510674 /engines/toon
parent87eb651886ef911d8026d777abec72c88ffdf32f (diff)
downloadscummvm-rg350-d2eab05e7d08bd5e4e615ee786e62be64293060a.tar.gz
scummvm-rg350-d2eab05e7d08bd5e4e615ee786e62be64293060a.tar.bz2
scummvm-rg350-d2eab05e7d08bd5e4e615ee786e62be64293060a.zip
TOON: Replace Character _currentPath static buffers with Common::Array.
Diffstat (limited to 'engines/toon')
-rw-r--r--engines/toon/character.cpp57
-rw-r--r--engines/toon/character.h9
2 files changed, 32 insertions, 34 deletions
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<int16>(5, 30 * _vm->getDrew()->getScale() / 1024);
int16 sizeY = MAX<int16>(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<int32>(4, _currentPathNodeCount - _currentPathNode);
+ while ((_x != newPosX || _y != newPosY) && _currentPathNode < _currentPath.size() && !_vm->shouldQuitGame()) {
+ if (_currentPathNode < _currentPath.size() - 4) {
+ int32 delta = MIN<int32>(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<int32>(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<int32>(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);
}
}
diff --git a/engines/toon/character.h b/engines/toon/character.h
index d2d84a8c9b..d33c314bf7 100644
--- a/engines/toon/character.h
+++ b/engines/toon/character.h
@@ -23,6 +23,9 @@
#ifndef TOON_CHARACTER_H
#define TOON_CHARACTER_H
+#include "common/array.h"
+#include "common/rect.h"
+
#include "toon/toon.h"
namespace Toon {
@@ -137,10 +140,8 @@ protected:
Animation *_shadowAnim;
Animation *_specialAnim;
- int16 _currentPathX[4096];
- int16 _currentPathY[4096];
- int32 _currentPathNodeCount;
- int32 _currentPathNode;
+ Common::Array<Common::Point> _currentPath;
+ uint32 _currentPathNode;
int32 _currentWalkStamp;
};