Skip to content

Commit

Permalink
Remove private functions from CinematicSound.h
Browse files Browse the repository at this point in the history
  • Loading branch information
dscharrer committed Jul 15, 2012
1 parent 5842da0 commit 9c156b6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 62 deletions.
14 changes: 7 additions & 7 deletions src/io/CinematicLoad.cpp
Expand Up @@ -219,12 +219,15 @@ bool parseCinematic(Cinematic * c, const char * data, size_t size) {
LogDebug("nsounds " << nsounds);
for(int i = 0; i < nsounds; i++) {

s16 id = 0;
bool reuse = true;
s8 id = 0;
if(version >= CINEMATIC_VERSION_1_76) {
if(!safeGet(id, data, size)) {
u8 noreuse;
if(!safeGet(noreuse, data, size) || !safeGet(id, data, size)) {
LogError << "error reading sound id";
return false;
}
reuse = (noreuse == 0); // TODO see if this is actually ever false
}

const char * str = safeGetString(data, size);
Expand All @@ -234,12 +237,9 @@ bool parseCinematic(Cinematic * c, const char * data, size_t size) {
}
LogDebug("sound " << i << ": \"" << str << '"');
res::path path = fixSoundPath(str);
LogDebug("adding sound " << i << " (0x" << std::hex << std::setfill('0')
<< std::setw(4) << id << std::dec << "): " << path);
LogDebug("adding sound " << i << ": " << path << " (" << int(id) << ')');

if(AddSoundToList(path, id) < 0) {
LogError << "AddSoundToList failed for " << path;
}
AddSoundToList(path, id, reuse);
}

// Load track and keys.
Expand Down
84 changes: 48 additions & 36 deletions src/scene/CinematicSound.cpp
Expand Up @@ -43,103 +43,115 @@ ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.

#include "scene/CinematicSound.h"

#include <iomanip>

#include "audio/AudioTypes.h"
#include "graphics/Math.h"
#include "io/log/Logger.h"
#include "io/resource/ResourcePath.h"
#include "scene/GameSound.h"

using std::string;

CinematicSound TabSound[MAX_SOUND];
namespace {

struct CinematicSound {

CinematicSound();

bool exists;
s8 id;
res::path file;
audio::SourceId handle;

};

extern char DirectoryChoose[];
CinematicSound TabSound[256];

CinematicSound::CinematicSound() : active(0), file(), handle(audio::INVALID_ID) { }
CinematicSound::CinematicSound() : exists(false), id(0), file(), handle(audio::INVALID_ID) { }

CinematicSound * GetFreeSound(int * num) {
} // anonymous namespace

static CinematicSound * GetFreeSound() {

for(size_t i = 0; i < MAX_SOUND; i++) {
if(!TabSound[i].active) {
*num = i;
for(size_t i = 0; i < ARRAY_SIZE(TabSound); i++) {
if(!TabSound[i].exists) {
return &TabSound[i];
}
}

return NULL;
}

bool DeleteFreeSound(int num) {
static bool DeleteFreeSound(int num) {

if(!TabSound[num].active) {
if(!TabSound[num].exists) {
return false;
}

TabSound[num].file.clear();

TabSound[num].active = 0;
TabSound[num].exists = false;

return true;
}

void DeleteAllSound(void) {

for(size_t i = 0; i < MAX_SOUND; i++) {
for(size_t i = 0; i < ARRAY_SIZE(TabSound); i++) {
DeleteFreeSound(i);
}
}

static int findSound(const res::path & file, s16 id) {
static int findSound(const res::path & file, s8 id) {

for(size_t i = 0; i < MAX_SOUND; i++) {

for(size_t i = 0; i < ARRAY_SIZE(TabSound); i++) {
const CinematicSound & cs = TabSound[i];

if(!cs.active || (cs.active & 0xFF00) != id) {
continue;
}

if(cs.file == file) {
if(cs.exists && cs.id == id && cs.file == file) {
return i;
}

}

return -1;
}

int AddSoundToList(const res::path & path, s16 id) {
void AddSoundToList(const res::path & path, s8 id, bool reuse) {

int num = findSound(path, id);
if(num >= 0) {
return num;
if(reuse) {
if(findSound(path, id) >= 0) {
LogWarning << "reusing sound slot for sound " << path << " (" << int(id) << ')';
return;
}
}

CinematicSound * cs = GetFreeSound(&num);
CinematicSound * cs = GetFreeSound();
if(!cs) {
return -1;
LogError << "AddSoundToList failed for " << path;
return;
}

cs->file = path;
cs->active = id | s16(1);

return num;
cs->id = id;
cs->exists = true;
}

bool PlaySoundKeyFramer(int id) {
bool PlaySoundKeyFramer(int index) {

if(!TabSound[id].active) {
if(index < 0 || size_t(index) >= ARRAY_SIZE(TabSound) || !TabSound[index].exists) {
return false;
}

TabSound[id].handle = ARX_SOUND_PlayCinematic(TabSound[id].file);
TabSound[index].handle = ARX_SOUND_PlayCinematic(TabSound[index].file);

return true;
}

void StopSoundKeyFramer() {

for(size_t i = 0; i < MAX_SOUND; i++) {
if(TabSound[i].active) {
ARX_SOUND_Stop(TabSound[i].handle), TabSound[i].handle = audio::INVALID_ID;
for(size_t i = 0; i < ARRAY_SIZE(TabSound); i++) {
if(TabSound[i].exists) {
ARX_SOUND_Stop(TabSound[i].handle);
TabSound[i].handle = audio::INVALID_ID;
}
}
}
22 changes: 3 additions & 19 deletions src/scene/CinematicSound.h
Expand Up @@ -20,28 +20,12 @@
#ifndef ARX_SCENE_CINEMATICSOUND_H
#define ARX_SCENE_CINEMATICSOUND_H

#include "audio/AudioTypes.h"
#include "io/resource/ResourcePath.h"
#include "platform/Platform.h"

#define MAX_SOUND 256

struct CinematicSound {

CinematicSound();

s16 active;
res::path file;
audio::SourceId handle;

};

void DeleteAllSound();

CinematicSound * GetFreeSound(int * num);
bool DeleteFreeSound(int num);
int AddSoundToList(const res::path & path, s16 id);
bool PlaySoundKeyFramer(int id);
void StopSoundKeyFramer(void);
void AddSoundToList(const res::path & path, s8 id, bool reuse);
bool PlaySoundKeyFramer(int index);
void StopSoundKeyFramer();

#endif // ARX_SCENE_CINEMATICSOUND_H

0 comments on commit 9c156b6

Please sign in to comment.