summaryrefslogtreecommitdiffhomepage
path: root/Stars45/RadioVox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Stars45/RadioVox.cpp')
-rw-r--r--Stars45/RadioVox.cpp220
1 files changed, 110 insertions, 110 deletions
diff --git a/Stars45/RadioVox.cpp b/Stars45/RadioVox.cpp
index 6974dc0..41aa10d 100644
--- a/Stars45/RadioVox.cpp
+++ b/Stars45/RadioVox.cpp
@@ -1,15 +1,15 @@
/* Project Starshatter 4.5
- Destroyer Studios LLC
- Copyright © 1997-2004. All Rights Reserved.
+ Destroyer Studios LLC
+ Copyright © 1997-2004. All Rights Reserved.
- SUBSYSTEM: Stars.exe
- FILE: RadioVox.cpp
- AUTHOR: John DiCamillo
+ SUBSYSTEM: Stars.exe
+ FILE: RadioVox.cpp
+ AUTHOR: John DiCamillo
- OVERVIEW
- ========
- View class for Radio Communications HUD Overlay
+ OVERVIEW
+ ========
+ View class for Radio Communications HUD Overlay
*/
#include "MemDebug.h"
@@ -32,19 +32,19 @@ DWORD WINAPI VoxUpdateProc(LPVOID link);
class RadioVoxController
{
public:
- enum { MAX_QUEUE = 5 };
+ enum { MAX_QUEUE = 5 };
- RadioVoxController();
- ~RadioVoxController();
+ RadioVoxController();
+ ~RadioVoxController();
- bool Add(RadioVox* vox);
- void Update();
- DWORD UpdateThread();
+ bool Add(RadioVox* vox);
+ void Update();
+ DWORD UpdateThread();
- bool shutdown;
- HANDLE hthread;
- List<RadioVox> queue;
- ThreadSync sync;
+ bool shutdown;
+ HANDLE hthread;
+ List<RadioVox> queue;
+ ThreadSync sync;
};
static RadioVoxController* controller = 0;
@@ -52,36 +52,36 @@ static RadioVoxController* controller = 0;
// +--------------------------------------------------------------------+
RadioVoxController::RadioVoxController()
- : hthread(0), shutdown(false)
+: hthread(0), shutdown(false)
{
- DWORD thread_id = 0;
- hthread = CreateThread(0, 4096, VoxUpdateProc,
- (LPVOID) this, 0, &thread_id);
+ DWORD thread_id = 0;
+ hthread = CreateThread(0, 4096, VoxUpdateProc,
+ (LPVOID) this, 0, &thread_id);
}
// +--------------------------------------------------------------------+
RadioVoxController::~RadioVoxController()
{
- shutdown = true;
+ shutdown = true;
- WaitForSingleObject(hthread, 500);
- CloseHandle(hthread);
- hthread = 0;
+ WaitForSingleObject(hthread, 500);
+ CloseHandle(hthread);
+ hthread = 0;
- queue.destroy();
+ queue.destroy();
}
// +--------------------------------------------------------------------+
DWORD WINAPI VoxUpdateProc(LPVOID link)
{
- RadioVoxController* controller = (RadioVoxController*) link;
+ RadioVoxController* controller = (RadioVoxController*) link;
- if (controller)
- return controller->UpdateThread();
+ if (controller)
+ return controller->UpdateThread();
- return (DWORD) E_POINTER;
+ return (DWORD) E_POINTER;
}
// +--------------------------------------------------------------------+
@@ -89,12 +89,12 @@ DWORD WINAPI VoxUpdateProc(LPVOID link)
DWORD
RadioVoxController::UpdateThread()
{
- while (!shutdown) {
- Update();
- Sleep(50);
- }
+ while (!shutdown) {
+ Update();
+ Sleep(50);
+ }
- return 0;
+ return 0;
}
// +--------------------------------------------------------------------+
@@ -102,30 +102,30 @@ RadioVoxController::UpdateThread()
void
RadioVoxController::Update()
{
- AutoThreadSync a(sync);
+ AutoThreadSync a(sync);
- if (queue.size()) {
- RadioVox* vox = queue.first();
+ if (queue.size()) {
+ RadioVox* vox = queue.first();
- if (!vox->Update())
- delete queue.removeIndex(0);
- }
+ if (!vox->Update())
+ delete queue.removeIndex(0);
+ }
}
bool
RadioVoxController::Add(RadioVox* vox)
{
- if (!vox || vox->sounds.isEmpty())
- return false;
+ if (!vox || vox->sounds.isEmpty())
+ return false;
- AutoThreadSync a(sync);
+ AutoThreadSync a(sync);
- if (queue.size() < MAX_QUEUE) {
- queue.append(vox);
- return true;
- }
+ if (queue.size() < MAX_QUEUE) {
+ queue.append(vox);
+ return true;
+ }
- return false;
+ return false;
}
// +====================================================================+
@@ -136,28 +136,28 @@ RadioVoxController::Add(RadioVox* vox)
void
RadioVox::Initialize()
{
- if (!controller) {
- controller = new(__FILE__,__LINE__) RadioVoxController;
- }
+ if (!controller) {
+ controller = new(__FILE__,__LINE__) RadioVoxController;
+ }
}
void
RadioVox::Close()
{
- delete controller;
- controller = 0;
+ delete controller;
+ controller = 0;
}
// +--------------------------------------------------------------------+
RadioVox::RadioVox(int n, const char* p, const char* m)
- : path(p), message(m), index(0), channel(n)
+: path(p), message(m), index(0), channel(n)
{
}
RadioVox::~RadioVox()
{
- sounds.destroy();
+ sounds.destroy();
}
// +--------------------------------------------------------------------+
@@ -165,40 +165,40 @@ RadioVox::~RadioVox()
bool
RadioVox::AddPhrase(const char* key)
{
- if (AudioConfig::VoxVolume() <= AudioConfig::Silence())
- return false;
+ if (AudioConfig::VoxVolume() <= AudioConfig::Silence())
+ return false;
- DataLoader* loader = DataLoader::GetLoader();
- if (!loader)
- return false;
+ DataLoader* loader = DataLoader::GetLoader();
+ if (!loader)
+ return false;
- if (key && *key) {
- char datapath[256];
- char filename[256];
+ if (key && *key) {
+ char datapath[256];
+ char filename[256];
- sprintf(datapath, "Vox/%s/", path.data());
- sprintf(filename, "%s.wav", key);
+ sprintf(datapath, "Vox/%s/", path.data());
+ sprintf(filename, "%s.wav", key);
- bool use_fs = loader->IsFileSystemEnabled();
- Sound* sound = 0;
+ bool use_fs = loader->IsFileSystemEnabled();
+ Sound* sound = 0;
- loader->UseFileSystem(true);
- loader->SetDataPath(datapath);
- loader->LoadSound(filename, sound, Sound::LOCALIZED, true); // optional sound
- loader->SetDataPath(0);
- loader->UseFileSystem(use_fs);
+ loader->UseFileSystem(true);
+ loader->SetDataPath(datapath);
+ loader->LoadSound(filename, sound, Sound::LOCALIZED, true); // optional sound
+ loader->SetDataPath(0);
+ loader->UseFileSystem(use_fs);
- if (sound) {
- sound->SetVolume(AudioConfig::VoxVolume());
- sound->SetFlags(Sound::LOCALIZED | Sound::LOCKED);
- sound->SetFilename(filename);
- sounds.append(sound);
+ if (sound) {
+ sound->SetVolume(AudioConfig::VoxVolume());
+ sound->SetFlags(Sound::LOCALIZED | Sound::LOCKED);
+ sound->SetFilename(filename);
+ sounds.append(sound);
- return true;
- }
- }
+ return true;
+ }
+ }
- return false;
+ return false;
}
// +--------------------------------------------------------------------+
@@ -206,44 +206,44 @@ RadioVox::AddPhrase(const char* key)
bool
RadioVox::Start()
{
- if (controller)
- return controller->Add(this);
+ if (controller)
+ return controller->Add(this);
- return false;
+ return false;
}
bool
RadioVox::Update()
{
- if (message.length()) {
- RadioView::Message(message);
- message = "";
- }
+ if (message.length()) {
+ RadioView::Message(message);
+ message = "";
+ }
- bool active = false;
+ bool active = false;
- while (!active && index < sounds.size()) {
- Sound* s = sounds[index];
+ while (!active && index < sounds.size()) {
+ Sound* s = sounds[index];
- if (s->IsReady()) {
- if (channel & 1)
- s->SetPan(channel * -3000);
- else
- s->SetPan(channel * 3000);
+ if (s->IsReady()) {
+ if (channel & 1)
+ s->SetPan(channel * -3000);
+ else
+ s->SetPan(channel * 3000);
- s->Play();
- active = true;
- }
+ s->Play();
+ active = true;
+ }
- else if (s->IsPlaying()) {
- s->Update();
- active = true;
- }
+ else if (s->IsPlaying()) {
+ s->Update();
+ active = true;
+ }
- else {
- index++;
- }
- }
+ else {
+ index++;
+ }
+ }
- return active;
+ return active;
}