ASYLUM: Replace several pairs of (x, y) parameters by Common::Point

This commit is contained in:
Julien Templier 2011-07-09 17:28:51 -04:00 committed by Eugene Sandulenko
parent 90d21d0ad8
commit 1526593cf0
No known key found for this signature in database
GPG key ID: 014D387312D34F08
11 changed files with 73 additions and 81 deletions

View file

@ -213,10 +213,10 @@ void PuzzleTicTacToe::drawField() {
if (g_debugPolygons) {
for (uint32 p = 0; p < ARRAYSIZE(puzzleTicTacToePolygons); p += 4) {
getScreen()->drawLine(puzzleTicTacToePolygons[p].x, puzzleTicTacToePolygons[p].y, puzzleTicTacToePolygons[p + 1].x, puzzleTicTacToePolygons[p + 1].y);
getScreen()->drawLine(puzzleTicTacToePolygons[p + 1].x, puzzleTicTacToePolygons[p + 1].y, puzzleTicTacToePolygons[p + 2].x, puzzleTicTacToePolygons[p + 2].y);
getScreen()->drawLine(puzzleTicTacToePolygons[p + 2].x, puzzleTicTacToePolygons[p + 2].y, puzzleTicTacToePolygons[p + 3].x, puzzleTicTacToePolygons[p + 3].y);
getScreen()->drawLine(puzzleTicTacToePolygons[p + 3].x, puzzleTicTacToePolygons[p + 3].y, puzzleTicTacToePolygons[p].x, puzzleTicTacToePolygons[p].y);
getScreen()->drawLine(puzzleTicTacToePolygons[p], puzzleTicTacToePolygons[p + 1]);
getScreen()->drawLine(puzzleTicTacToePolygons[p + 1], puzzleTicTacToePolygons[p + 2]);
getScreen()->drawLine(puzzleTicTacToePolygons[p + 2], puzzleTicTacToePolygons[p + 3]);
getScreen()->drawLine(puzzleTicTacToePolygons[p + 3], puzzleTicTacToePolygons[p]);
}
}

View file

@ -1253,7 +1253,7 @@ void Actor::playSounds(ActorDirection direction, uint32 distance) {
_lastScreenUpdate = _vm->screenUpdateCount;
Common::Point sum(_point1.x + _point2.x, _point1.x + _point2.x);
int32 panning = getSound()->calculatePanningAtPoint(sum.x, sum.y);
int32 panning = getSound()->calculatePanningAtPoint(sum);
switch (_status) {
default:
@ -1272,7 +1272,7 @@ void Actor::playSounds(ActorDirection direction, uint32 distance) {
// Compute volume
int32 vol = sqrt((double)-Config.sfxVolume);
if (_index != getScene()->getPlayerIndex())
vol += sqrt((double)abs(getSound()->calculateVolumeAdjustement(sum.x, sum.y, 10, 0)));
vol += sqrt((double)abs(getSound()->calculateVolumeAdjustement(sum, 10, 0)));
int32 volume = (Config.sfxVolume + vol) * (Config.sfxVolume + vol);
if (volume > 10000)
@ -1309,7 +1309,7 @@ void Actor::playSounds(ActorDirection direction, uint32 distance) {
// Compute volume
int32 vol = getWorld()->actions[_actionIdx3]->volume;
if (_index != getScene()->getPlayerIndex())
vol += sqrt((double)abs(getSound()->calculateVolumeAdjustement(sum.x, sum.y, 10, 0)));
vol += sqrt((double)abs(getSound()->calculateVolumeAdjustement(sum, 10, 0)));
int32 volume = (Config.sfxVolume + vol) * (Config.sfxVolume + vol);
if (volume > 10000)
@ -2340,16 +2340,13 @@ void Actor::resetActors() {
getWorld()->tickCount1 = _vm->getTick() + 3000;
}
void Actor::updateNumbers(int32 reaction, int32 x, int32 y) {
void Actor::updateNumbers(int32 reaction, const Common::Point &point) {
if (reaction != 1)
return;
_numberStringX = x;
_numberStringY = y + 8;
_numberStringX = point.x;
_numberStringY = point.y + 8;
_numberStringWidth = 40;
// XXX use sprintf instead of itoa as itoa isn't part of standard
// C++ and therefore isn't available in GCC
sprintf(_numberString01, "%d", _numberValue01);
_numberFlag01 = 1;
@ -2444,7 +2441,7 @@ void Actor::setVolume() {
return;
// Compute volume
int32 volume = Config.voiceVolume + getSound()->calculateVolumeAdjustement(_point1.x + _point2.x, _point1.y + _point2.y, _field_968, 0);
int32 volume = Config.voiceVolume + getSound()->calculateVolumeAdjustement(_point1 + _point2, _field_968, 0);
if (volume < -10000)
volume = -10000;

View file

@ -482,10 +482,9 @@ private:
* Updates the actor "number" data if the reaction is "1".
*
* @param reaction The reaction.
* @param x The second int32.
* @param y The third int32.
* @param point The coordinates
*/
void updateNumbers(int32 reaction, int32 x, int32 y);
void updateNumbers(int32 reaction, const Common::Point &point);
/**
* Determine if the supplied point is in the action area

View file

@ -360,24 +360,23 @@ void Object::setNextFrame(int32 targetFlags) {
// Misc
/////////////////////////////////////////////////////////////////////////
void Object::playSounds() {
int32 soundX = 0;
int32 soundY = 0;
Common::Point point;
if (_soundX || _soundY) {
soundX = _soundX;
soundY = _soundY;
point.x = _soundX;
point.y = _soundY;
} else {
if (LOBYTE(flags) & kObjectFlag4) {
// Get object resource
ResourceEntry *resource = getResource()->get(_resourceId);
soundX = x + Common::Rational(resource->getData(1), 2).toInt();
soundY = y + Common::Rational(resource->getData(0), 2).toInt();
point.x = x + Common::Rational(resource->getData(1), 2).toInt();
point.y = y + Common::Rational(resource->getData(0), 2).toInt();
} else {
Common::Rect rect = GraphicResource::getFrameRect(_vm, _resourceId, _frameIndex);
soundX = x + (rect.width() * 2);
soundY = x + (rect.height() * 2);
point.x = x + (rect.width() * 2);
point.y = x + (rect.height() * 2);
}
}
@ -388,20 +387,20 @@ void Object::playSounds() {
continue;
if (item->field_4 && !getSound()->isPlaying(item->resourceId)) {
int32 volume = Config.sfxVolume + getSound()->calculateVolumeAdjustement(soundX, soundY, item->field_8, item->field_C);
int32 volume = Config.sfxVolume + getSound()->calculateVolumeAdjustement(point, item->field_8, item->field_C);
if (volume > -5000)
getSound()->playSound(item->resourceId, true, volume, getSound()->calculatePanningAtPoint(soundX, soundY));
getSound()->playSound(item->resourceId, true, volume, getSound()->calculatePanningAtPoint(point));
}
if (getSound()->isPlaying(item->resourceId)) {
int32 volume = Config.sfxVolume + getSound()->calculateVolumeAdjustement(soundX, soundY, item->field_8, item->field_C);
int32 volume = Config.sfxVolume + getSound()->calculateVolumeAdjustement(point, item->field_8, item->field_C);
if (volume > -5000) {
if (volume > 0)
volume = 0;
getSound()->setPanning(item->resourceId, getSound()->calculatePanningAtPoint(soundX, soundY));
getSound()->setPanning(item->resourceId, getSound()->calculatePanningAtPoint(point));
getSound()->setVolume(item->resourceId, volume);
} else {
getSound()->stop(item->resourceId);
@ -449,7 +448,8 @@ void Object::setVolume() {
Common::Rect frameRect = GraphicResource::getFrameRect(_vm, _resourceId, _frameIndex);
// Compute volume
int32 volume = Config.voiceVolume + getSound()->calculateVolumeAdjustement(Common::Rational(frameRect.width(), 2).toInt() + x, Common::Rational(frameRect.height(), 2).toInt() + y, _field_6A4, 0);
Common::Point coords(Common::Rational(frameRect.width(), 2).toInt() + x, Common::Rational(frameRect.height(), 2).toInt() + y);
int32 volume = Config.voiceVolume + getSound()->calculateVolumeAdjustement(coords, _field_6A4, 0);
if (volume < -10000)
volume = -10000;

View file

@ -425,8 +425,8 @@ void Special::chapter6(Object *object, ActorIndex actorIndex) {
if (actorIndex == 2 || actorIndex == 3) {
Actor *actor = getScene()->getActor(actorIndex);
getWorld()->ambientSounds[0].x = actor->getPoint2()->x + actor->getPoint1()->x;
getWorld()->ambientSounds[0].y = actor->getPoint2()->y + actor->getPoint1()->y;
getWorld()->ambientSounds[0].point.x = actor->getPoint2()->x + actor->getPoint1()->x;
getWorld()->ambientSounds[0].point.y = actor->getPoint2()->y + actor->getPoint1()->y;
}
}
@ -1287,44 +1287,43 @@ void Special::setPaletteGamma(ResourceId palette1, ResourceId palette2) {
void Special::playSoundPanning(ResourceId resourceId, int32 attenuation, Object *object) {
int32 adjustedVolume = Config.voiceVolume;
int32 x = 0;
int32 y = 0;
Common::Point point;
switch (object->getId()) {
default: {
Common::Rect frameRect = GraphicResource::getFrameRect(_vm, object->getResourceId(), object->getFrameIndex());
x = Common::Rational(frameRect.width(), 2).toInt() + object->x;
y = Common::Rational(frameRect.height(), 2).toInt() + object->y;
point.x = Common::Rational(frameRect.width(), 2).toInt() + object->x;
point.y = Common::Rational(frameRect.height(), 2).toInt() + object->y;
}
break;
case kObjectDennisStatusQuo:
x = 1382;
y = 1041;
point.x = 1382;
point.y = 1041;
break;
case kObjectSailorBoy:
x = 1646;
y = 1220;
point.x = 1646;
point.y = 1220;
break;
case kObjectSuckerSittingStatusQuo:
x = 1376;
y = 1148;
point.x = 1376;
point.y = 1148;
break;
case kObjectDennisStatus2:
x = 175;
y = 617;
point.x = 175;
point.y = 617;
break;
}
// Calculate volume adjustment
adjustedVolume += getSound()->calculateVolumeAdjustement(x, y, attenuation, 0);
adjustedVolume += getSound()->calculateVolumeAdjustement(point, attenuation, 0);
// Calculate panning
int32 panning = getSound()->calculatePanningAtPoint(x, y);
int32 panning = getSound()->calculatePanningAtPoint(point);
// Adjust object properties
object->setSoundResourceId(resourceId);
@ -1338,10 +1337,10 @@ void Special::playSoundPanning(ResourceId resourceId, int32 attenuation, ActorIn
// Calculate volume adjustment
int32 adjustedVolume = Config.voiceVolume;
adjustedVolume += getSound()->calculateVolumeAdjustement(actor->getPoint1()->x, actor->getPoint1()->y, attenuation, 0);
adjustedVolume += getSound()->calculateVolumeAdjustement(*actor->getPoint1(), attenuation, 0);
// Calculate panning
int32 panning = getSound()->calculatePanningAtPoint(actor->getPoint1()->x + actor->getPoint2()->x, actor->getPoint1()->y + actor->getPoint2()->y);
int32 panning = getSound()->calculatePanningAtPoint(*actor->getPoint1() + *actor->getPoint2());
getSound()->playSound(resourceId, false, adjustedVolume, panning);
}

View file

@ -178,8 +178,8 @@ void WorldStats::load(Common::SeekableReadStream *stream) {
for (int32 i = 0; i < 6; i++)
ambientSounds[s].flagNum[i] = (GameFlag)stream->readSint32LE();
ambientSounds[s].x = stream->readSint32LE();
ambientSounds[s].y = stream->readSint32LE();
ambientSounds[s].point.x = stream->readSint32LE();
ambientSounds[s].point.y = stream->readSint32LE();
}
numAmbientSounds = stream->readSint32LE();

View file

@ -319,7 +319,7 @@ void Screen::selectTransTable(uint32 index) {
//////////////////////////////////////////////////////////////////////////
// Graphic queue
//////////////////////////////////////////////////////////////////////////
void Screen::addGraphicToQueue(ResourceId resourceId, uint32 frameIndex, Common::Point point, DrawFlags flags, int32 transTableNum, int32 priority) {
void Screen::addGraphicToQueue(ResourceId resourceId, uint32 frameIndex, const Common::Point &point, DrawFlags flags, int32 transTableNum, int32 priority) {
GraphicQueueItem item;
item.priority = priority;
@ -333,7 +333,7 @@ void Screen::addGraphicToQueue(ResourceId resourceId, uint32 frameIndex, Common:
_queueItems.push_back(item);
}
void Screen::addGraphicToQueueMasked(ResourceId resourceId, uint32 frameIndex, Common::Point source, int32 resourceIdDestination, Common::Point destination, DrawFlags flags, int32 priority) {
void Screen::addGraphicToQueueMasked(ResourceId resourceId, uint32 frameIndex, const Common::Point &source, int32 resourceIdDestination, const Common::Point &destination, DrawFlags flags, int32 priority) {
GraphicQueueItem item;
item.priority = priority;
@ -497,8 +497,8 @@ void Screen::copyToBackBufferWithTransparency(byte *buffer, int32 pitch, int32 x
//////////////////////////////////////////////////////////////////////////
// Debug
//////////////////////////////////////////////////////////////////////////
void Screen::drawLine(int x0, int y0, int x1, int y1) {
_backBuffer.drawLine(x0, y0, x1, y1, 0xFF);
void Screen::drawLine(const Common::Point &source, const Common::Point &destination) {
_backBuffer.drawLine(source.x, source.y, destination.x, destination.y, 0xFF);
}
void Screen::copyToBackBufferClipped(Graphics::Surface *surface, int x, int y) {
@ -507,7 +507,7 @@ void Screen::copyToBackBufferClipped(Graphics::Surface *surface, int x, int y) {
animRect.clip(screenRect);
if (!animRect.isEmpty()) {
// Translate anim rectangle
// Translate animation rectangle
animRect.translate(-(int16)getWorld()->xLeft, -(int16)getWorld()->yTop);
int startX = animRect.right == 640 ? 0 : surface->w - animRect.width();

View file

@ -114,9 +114,9 @@ public:
byte *getTransTableIndex() { return _transTableIndex; }
// Graphic queue
void addGraphicToQueue(ResourceId resourceId, uint32 frameIndex, Common::Point point, DrawFlags flags, int32 transTableNum, int32 priority);
void addGraphicToQueue(ResourceId resourceId, uint32 frameIndex, const Common::Point &point, DrawFlags flags, int32 transTableNum, int32 priority);
void addGraphicToQueueCrossfade(ResourceId resourceId, uint32 frameIndex, Common::Point source, int32 objectResourceId, Common::Point destination, int32 transTableNum);
void addGraphicToQueueMasked(ResourceId resourceId, uint32 frameIndex, Common::Point point, int32 objectResourceId, Common::Point destination, DrawFlags flags, int32 priority);
void addGraphicToQueueMasked(ResourceId resourceId, uint32 frameIndex, const Common::Point &source, int32 objectResourceId, const Common::Point &destination, DrawFlags flags, int32 priority);
void addGraphicToQueue(GraphicQueueItem const &item);
void drawGraphicsInQueue();
void clearGraphicsInQueue();
@ -126,7 +126,7 @@ public:
void copyToBackBuffer(byte *buffer, int32 pitch, int32 x, int32 y, uint32 width, uint32 height, bool mirrored = false);
// Debug
void drawLine(int x0, int y0, int x1, int y1);
void drawLine(const Common::Point &origin, const Common::Point &destination);
void copyToBackBufferClipped(Graphics::Surface *surface, int x, int y);
private:

View file

@ -158,20 +158,21 @@ void Sound::setPanning(ResourceId resourceId, int32 panning) {
_mixer->setChannelBalance(item->handle, (int8)panning);
}
int32 Sound::calculateVolumeAdjustement(int32 x, int32 y, int32 attenuation, int32 delta) {
int32 Sound::calculateVolumeAdjustement(const Common::Point &point, int32 attenuation, int32 delta) {
if (!attenuation)
return -(delta * delta);
Common::Point adjusted(point);
Actor *player = getScene()->getActor();
if (getSharedData()->point.x == -1) {
x -= (player->getPoint1()->x + player->getPoint2()->x);
y -= (player->getPoint1()->y + player->getPoint2()->y);
adjusted.x -= (player->getPoint1()->x + player->getPoint2()->x);
adjusted.y -= (player->getPoint1()->y + player->getPoint2()->y);
} else {
x -= getSharedData()->point.x;
y -= getSharedData()->point.y;
adjusted.x -= getSharedData()->point.x;
adjusted.y -= getSharedData()->point.y;
}
int32 adjustedVolume = getAdjustedVolume(x * x + y * y);
int32 adjustedVolume = getAdjustedVolume(adjusted.x * adjusted.x + adjusted.y * adjusted.y);
Common::Rational invAtt(100, attenuation);
Common::Rational v;
@ -215,10 +216,10 @@ int32 Sound::getAdjustedVolume(int32 volume) {
return adjustedVolume;
}
int32 Sound::calculatePanningAtPoint(int32 x, int32) {
// y does not seem to be used at all :S
int32 Sound::calculatePanningAtPoint(const Common::Point &point) {
// point.y does not seem to be used at all :S
int delta = x - getWorld()->xLeft;
int delta = point.x - getWorld()->xLeft;
if (delta < 0)
return (getWorld()->reverseStereo ? 10000 : -10000);

View file

@ -31,6 +31,7 @@
#include "asylum/shared.h"
#include "common/array.h"
#include "common/rect.h"
#include "audio/mixer.h"
@ -80,8 +81,7 @@ struct AmbientSoundItem {
int32 attenuation;
int32 nextTick;
GameFlag flagNum[6];
int32 x;
int32 y;
Common::Point point;
AmbientSoundItem() {
field_0 = 0;
@ -91,8 +91,6 @@ struct AmbientSoundItem {
attenuation = 0;
nextTick = 0;
memset(&flagNum, 0, sizeof(flagNum));
x = 0;
y = 0;
}
};
@ -188,14 +186,13 @@ public:
/**
* Determine the amount to increase the supplied sound sample's volume based on the position.
*
* @param x The x coordinate.
* @param y The y coordinate.
* @param point The coordinates
* @param attenuation The attenuation.
* @param delta The delta.
* @param delta The delta.
*
* @return The calculated volume adjustement.
*/
int32 calculateVolumeAdjustement(int32 x, int32 y, int32 attenuation, int32 delta);
int32 calculateVolumeAdjustement(const Common::Point &point, int32 attenuation, int32 delta);
/**
* Gets an adjusted volume.
@ -209,12 +206,11 @@ public:
/**
* Calculates the panning at point.
*
* @param x The x coordinate.
* @param y The y coordinate.
* @param point The coordinates.
*
* @return The calculated panning at point.
*/
int32 calculatePanningAtPoint(int32 x, int32 y);
int32 calculatePanningAtPoint(const Common::Point &point);
//////////////////////////////////////////////////////////////////////////
// Stopping sounds

View file

@ -861,7 +861,7 @@ void Scene::updateAmbientSounds() {
if (_vm->sound()->isPlaying(snd->resourceId)) {
if (snd->field_0) {
int32 volume = Config.ambientVolume + getSound()->calculateVolumeAdjustement(snd->x, snd->y, snd->attenuation, snd->delta);
int32 volume = Config.ambientVolume + getSound()->calculateVolumeAdjustement(snd->point, snd->attenuation, snd->delta);
if (volume <= 0) {
if (volume < -10000)
@ -874,11 +874,11 @@ void Scene::updateAmbientSounds() {
}
} else {
int32 panning = (snd->field_0) ? getSound()->calculatePanningAtPoint(snd->x, snd->y) : 0;
int32 panning = (snd->field_0) ? getSound()->calculatePanningAtPoint(snd->point) : 0;
int32 volume = 0;
if (snd->field_0)
volume = getSound()->calculateVolumeAdjustement(snd->x, snd->y, snd->attenuation, snd->delta);
volume = getSound()->calculateVolumeAdjustement(snd->point, snd->attenuation, snd->delta);
else
volume = -pow((double)snd->delta, 2);