Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
SoundCard.cpp
Go to the documentation of this file.
1
/* Project nGenEx
2
Destroyer Studios LLC
3
Copyright © 1997-2004. All Rights Reserved.
4
5
SUBSYSTEM: nGenEx.lib
6
FILE: SoundCard.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Abstract sound card class
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
SoundCard.h
"
17
#include "
Sound.h
"
18
19
// +--------------------------------------------------------------------+
20
21
DWORD WINAPI
SoundCardUpdateProc
(LPVOID link);
22
23
// +--------------------------------------------------------------------+
24
25
SoundCard::SoundCard
()
26
: status(SC_UNINITIALIZED), hthread(0), shutdown(false)
27
{
28
DWORD thread_id = 0;
29
hthread
= CreateThread(0, 4096,
SoundCardUpdateProc
,
30
(LPVOID)
this
, 0, &thread_id);
31
}
32
33
// +--------------------------------------------------------------------+
34
35
SoundCard::~SoundCard
()
36
{
37
shutdown
=
true
;
38
39
WaitForSingleObject(
hthread
, 500);
40
CloseHandle(
hthread
);
41
hthread
= 0;
42
43
sounds
.
destroy
();
44
status
=
SC_UNINITIALIZED
;
45
}
46
47
// +--------------------------------------------------------------------+
48
49
DWORD WINAPI
SoundCardUpdateProc
(LPVOID link)
50
{
51
SoundCard
* card = (
SoundCard
*) link;
52
53
if
(card)
54
return
card->
UpdateThread
();
55
56
return
(DWORD) E_POINTER;
57
}
58
59
// +--------------------------------------------------------------------+
60
61
DWORD
62
SoundCard::UpdateThread
()
63
{
64
while
(!
shutdown
) {
65
Update
();
66
Sleep(50);
67
}
68
69
return
0;
70
}
71
72
// +--------------------------------------------------------------------+
73
74
void
75
SoundCard::Update
()
76
{
77
AutoThreadSync
a(
sync
);
78
79
ListIter<Sound>
iter =
sounds
;
80
while
(++iter) {
81
Sound
* s = iter.
value
();
82
83
s->
Update
();
84
85
if
(s->
GetStatus
() ==
Sound::DONE
&&
86
!(s->
GetFlags
() &
Sound::LOCKED
)) {
87
88
delete
iter.
removeItem
();
89
}
90
}
91
}
92
93
// +--------------------------------------------------------------------+
94
95
void
96
SoundCard::AddSound
(
Sound
* s)
97
{
98
AutoThreadSync
a(
sync
);
99
100
if
(!
sounds
.
contains
(s))
101
sounds
.
append
(s);
102
}
103
nGenEx
SoundCard.cpp
Generated on Thu May 31 2012 16:30:59 for Starshatter_Open by
1.8.1