Skip to content

Commit

Permalink
Attenuate sounds played out of sight
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Sep 2, 2014
1 parent ca59d7e commit 4506ca8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/cdogs/algorithms.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ void XiaolinWuLineDraw(Vec2i from, Vec2i to, AlgoLineDrawData *data)
XiaolinWuLine(from, to, &bData);
}

bool FloodFill(Vec2i v, FloodFillData *data)
bool CFloodFill(Vec2i v, FloodFillData *data)
{
if (data->IsSame(data->data, v))
{
data->Fill(data->data, v);
FloodFill(Vec2iNew(v.x - 1, v.y), data);
FloodFill(Vec2iNew(v.x + 1, v.y), data);
FloodFill(Vec2iNew(v.x, v.y - 1), data);
FloodFill(Vec2iNew(v.x, v.y + 1), data);
CFloodFill(Vec2iNew(v.x - 1, v.y), data);
CFloodFill(Vec2iNew(v.x + 1, v.y), data);
CFloodFill(Vec2iNew(v.x, v.y - 1), data);
CFloodFill(Vec2iNew(v.x, v.y + 1), data);
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/cdogs/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ typedef struct
bool (*IsSame)(void *, Vec2i);
void *data;
} FloodFillData;
bool FloodFill(Vec2i v, FloodFillData *data);
bool CFloodFill(Vec2i v, FloodFillData *data);

#endif
2 changes: 1 addition & 1 deletion src/cdogs/mission_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ bool MissionStaticTrySetKey(Mission *m, int k, Vec2i pos)
mData.m = m;
mData.mask = mask;
data.data = &mData;
return FloodFill(pos, &data);
return CFloodFill(pos, &data);
}
static void MissionFillTile(void *data, Vec2i v)
{
Expand Down
14 changes: 14 additions & 0 deletions src/cdogs/sounds.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@

#include <tinydir/tinydir.h>

#include "algorithms.h"
#include "files.h"
#include "map.h"
#include "music.h"
#include "vector.h"

Expand Down Expand Up @@ -318,6 +320,11 @@ void SoundPlayAt(SoundDevice *device, Mix_Chunk *data, const Vec2i pos)
SoundPlayAtPlusDistance(device, data, pos, 0);
}

#define OUT_OF_SIGHT_DISTANCE_PLUS 200
static bool IsPosNoSee(void *data, Vec2i pos)
{
return MapGetTile(data, Vec2iToTile(pos))->flags & MAPTILE_NO_SEE;
}
void SoundPlayAtPlusDistance(
SoundDevice *device, Mix_Chunk *data,
const Vec2i pos, const int plusDistance)
Expand Down Expand Up @@ -353,6 +360,13 @@ void SoundPlayAtPlusDistance(
origin = CalcClosestPointOnLineSegmentToPoint(
closestLeftEar, closestRightEar, pos);
CalcChebyshevDistanceAndBearing(origin, pos, &distance, &bearing);
HasClearLineData lineData;
lineData.IsBlocked = IsPosNoSee;
lineData.data = &gMap;
if (!HasClearLineXiaolinWu(pos, origin, &lineData))
{
distance += OUT_OF_SIGHT_DISTANCE_PLUS;
}
SoundPlayAtPosition(&gSoundDevice, data, distance + plusDistance, bearing);
}

Expand Down
2 changes: 1 addition & 1 deletion src/cdogsed/editor_brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ EditorResult EditorBrushStartPainting(EditorBrush *b, Mission *m, int isMain)
pData.fromType = MissionGetTile(m, b->Pos) & MAP_MASKACCESS;
pData.toType = b->PaintType;
data.data = &pData;
if (FloodFill(b->Pos, &data))
if (CFloodFill(b->Pos, &data))
{
return EDITOR_RESULT_CHANGED;
}
Expand Down

0 comments on commit 4506ca8

Please sign in to comment.