Subversion Repositories spk

Rev

Rev 79 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 79 Rev 123
Line 11... Line 11...
11
#define TYPERATE 200
11
#define TYPERATE 200
12
#define KEYDOWN(name,key) (name[key] & 0x80)
12
#define KEYDOWN(name,key) (name[key] & 0x80)
13
 
13
 
14
#include <spk.h>
14
#include <spk.h>
15
#include <stdio.h>
15
#include <stdio.h>
-
 
16
#ifdef FMOD
16
#include <fmod.hpp>
17
#include <fmod.hpp>
17
 
18
 
18
typedef struct SStoredSound {
19
typedef struct SStoredSound {
19
	struct SStoredSound () { pSound = NULL; pChannel = NULL; }
20
	struct SStoredSound () { pSound = NULL; pChannel = NULL; }
20
	FMOD::Sound *pSound;
21
	FMOD::Sound *pSound;
21
	FMOD::Channel *pChannel;
22
	FMOD::Channel *pChannel;
22
	CyString sFilename;
23
	CyString sFilename;
23
} SStoredSound;
24
} SStoredSound;
-
 
25
#endif
24
 
26
 
25
class COverlay
27
class COverlay
26
{
28
{
27
public:
29
public:
28
	COverlay ()
30
	COverlay ()
Line 34... Line 36...
34
		m_pMouseDevice = NULL;
36
		m_pMouseDevice = NULL;
35
		m_bGetKeyboard = false;
37
		m_bGetKeyboard = false;
36
		m_iMouseX = m_iMouseY = 0;
38
		m_iMouseX = m_iMouseY = 0;
37
		m_bHaltMouse = false;
39
		m_bHaltMouse = false;
38
		m_bSound = false;
40
		m_bSound = false;
-
 
41
#ifdef FMOD
39
		m_pSystem = NULL;
42
		m_pSystem = NULL;
-
 
43
#endif
40
	}
44
	}
41
 
45
 
42
	virtual ~COverlay ()
46
	virtual ~COverlay ()
43
	{
47
	{
-
 
48
#ifdef FMOD
44
		for ( SStoredSound *sound = m_lSounds.First(); sound; sound = m_lSounds.Next() )
49
		for ( SStoredSound *sound = m_lSounds.First(); sound; sound = m_lSounds.Next() )
45
		{
50
		{
46
			if ( sound->pSound )
51
			if ( sound->pSound )
47
				sound->pSound->release();
52
				sound->pSound->release();
48
			delete sound;
53
			delete sound;
49
		}
54
		}
50
		m_lSounds.clear();
55
		m_lSounds.clear();
51
 
-
 
52
		if ( m_pSystem )
56
		if ( m_pSystem )
53
		{
57
		{
54
			m_pSystem->close();
58
			m_pSystem->close();
55
			m_pSystem->release();
59
			m_pSystem->release();
56
		}
60
		}
-
 
61
#endif
57
	}
62
	}
58
 
-
 
59
 
63
 
60
	bool GetKeyboard () { return m_bGetKeyboard; }
64
	bool GetKeyboard () { return m_bGetKeyboard; }
61
 
65
 
62
	virtual bool HaltMouse () { return m_bHaltMouse; }
66
	virtual bool HaltMouse () { return m_bHaltMouse; }
63
	virtual bool MouseClick ( int but ) { return false; }
67
	virtual bool MouseClick ( int but ) { return false; }
64
	virtual void MouseRelease ( int but ) { }
68
	virtual void MouseRelease ( int but ) { }
65
	virtual bool KeyDown ( int key ) { return false; }
69
	virtual bool KeyDown ( int key ) { return false; }
66
	virtual void KeyReleased ( int key ) { }
70
	virtual void KeyReleased ( int key ) { }
67
 
71
 
-
 
72
#ifdef FMOD
68
	virtual bool PlaySound ( FMOD::Sound *sound )
73
	virtual bool PlaySound ( FMOD::Sound *sound )
69
	{
74
	{
70
		SStoredSound *s = NULL;
75
		SStoredSound *s = NULL;
71
		for ( s = m_lSounds.First(); s; s = m_lSounds.Next() )
76
		for ( s = m_lSounds.First(); s; s = m_lSounds.Next() )
72
		{
77
		{
73
			if ( s->pSound == sound )
78
			if ( s->pSound == sound )
74
				return (PlaySound (s));
79
				return (PlaySound (s));
75
		}
80
		}
76
		return false;
81
		return false;
77
 
82
 
78
	}
-
 
79
	virtual bool PlaySound ( CyString filename )
-
 
80
	{
-
 
81
		filename.ToUpper();
-
 
82
		SStoredSound *s = NULL;
-
 
83
		for ( s = m_lSounds.First(); s; s = m_lSounds.Next() )
-
 
84
		{
-
 
85
			if ( s->sFilename == filename )
-
 
86
				return (PlaySound (s));
-
 
87
		}
-
 
88
		return false;
-
 
89
	}
83
	}
-
 
84
#endif
90
 
85
 
91
	virtual void Send ( CyString data ) {}
-
 
92
	virtual FMOD::Sound *CreateSound ( CyString filename )
86
	virtual bool CreateSound(CyString filename)
93
	{
87
	{
-
 
88
#ifdef FMOD
94
		filename.ToUpper();
89
		filename.ToUpper();
95
		SStoredSound *s;
90
		SStoredSound *s;
96
		for ( s = m_lSounds.First(); s; s = m_lSounds.Next() )
91
		for (s = m_lSounds.First(); s; s = m_lSounds.Next())
97
		{
92
		{
98
			if ( s->sFilename == filename )
93
			if (s->sFilename == filename)
99
				return s->pSound;
94
				return s->pSound;
100
		}
95
		}
101
 
96
 
102
		s = new SStoredSound;
97
		s = new SStoredSound;
103
		s->sFilename = filename;
98
		s->sFilename = filename;
Line 105... Line 100...
105
		/*
100
		/*
106
		FMOD_RESULT result = m_pSystem->createSound ( filename.c_str(), FMOD_HARDWARE, 0, &s->pSound );
101
		FMOD_RESULT result = m_pSystem->createSound ( filename.c_str(), FMOD_HARDWARE, 0, &s->pSound );
107
		if ( result == FMOD_OK )
102
		if ( result == FMOD_OK )
108
		{
103
		{
109
			m_lSounds.push_back ( s );
104
			m_lSounds.push_back ( s );
110
			return s->pSound;
105
			return true;
111
		}*/
106
		}*/
-
 
107
#endif
112
		delete s;
108
		return false;
-
 
109
	}
-
 
110
 
-
 
111
	virtual bool PlaySound ( CyString filename )
-
 
112
	{
-
 
113
		filename.ToUpper();
-
 
114
#ifdef FMOD
-
 
115
		SStoredSound *s = NULL;
-
 
116
		for ( s = m_lSounds.First(); s; s = m_lSounds.Next() )
-
 
117
		{
-
 
118
			if ( s->sFilename == filename )
-
 
119
				return (PlaySound (s));
-
 
120
		}
-
 
121
#endif
113
		return NULL;
122
		return false;
114
	}
123
	}
-
 
124
 
-
 
125
	virtual void Send ( CyString data ) {}
115
 
126
 
116
	void MoveMouseY ( int y ) { m_iMouseY += y; if ( m_iMouseY > m_iHeight ) m_iMouseY = m_iHeight; if ( m_iMouseY < 0 ) m_iMouseY = 0; }
127
	void MoveMouseY ( int y ) { m_iMouseY += y; if ( m_iMouseY > m_iHeight ) m_iMouseY = m_iHeight; if ( m_iMouseY < 0 ) m_iMouseY = 0; }
117
	void MoveMouseX ( int x ) { m_iMouseX += x; if ( m_iMouseX > m_iWidth  ) m_iMouseX = m_iWidth;  if ( m_iMouseX < 0 ) m_iMouseX = 0; }
128
	void MoveMouseX ( int x ) { m_iMouseX += x; if ( m_iMouseX > m_iWidth  ) m_iMouseX = m_iWidth;  if ( m_iMouseX < 0 ) m_iMouseX = 0; }
118
 
129
 
119
	void SetKeyboardDevice ( IDirectInputDevice8 *device )
130
	void SetKeyboardDevice ( IDirectInputDevice8 *device )
120
	{
131
	{
121
		m_pKeyboardDevice = device;
132
		m_pKeyboardDevice = device;
122
	}
133
	}
123
	void SetMouseDevice ( IDirectInputDevice8 *device )
134
	void SetMouseDevice ( IDirectInputDevice8 *device )
Line 133... Line 144...
133
		return false;
144
		return false;
134
	}
145
	}
135
	virtual void render (MyDirect3DDevice9 *device) = 0;
146
	virtual void render (MyDirect3DDevice9 *device) = 0;
136
	virtual void init (MyDirect3DDevice9 *device) 
147
	virtual void init (MyDirect3DDevice9 *device) 
137
	{
148
	{
-
 
149
#ifdef FMOD
138
		m_bSound = true;
150
		m_bSound = true;
139
		FMOD_RESULT result;
151
		FMOD_RESULT result;
140
 
152
 
141
		result = FMOD::System_Create( &m_pSystem );		// Create the main system object.
153
		result = FMOD::System_Create( &m_pSystem );		// Create the main system object.
142
		if (result != FMOD_OK)
154
		if (result != FMOD_OK)
Line 151... Line 163...
151
		if ( (!m_bSound) && (m_pSystem) )
163
		if ( (!m_bSound) && (m_pSystem) )
152
		{
164
		{
153
			m_pSystem->close();
165
			m_pSystem->close();
154
			m_pSystem->release();
166
			m_pSystem->release();
155
		}
167
		}
-
 
168
#else
-
 
169
		m_bSound = false;
-
 
170
#endif
156
	}
171
	}
157
 
172
 
158
	virtual bool SetKeyBuffer ( DWORD size, char *buff )
173
	virtual bool SetKeyBuffer ( DWORD size, char *buff )
159
	{
174
	{
160
		// if old buffer is the wrong size, delete it
175
		// if old buffer is the wrong size, delete it
Line 213... Line 228...
213
	}
228
	}
214
 
229
 
215
	virtual void SetWindowSize ( int width, int height ) { m_iWidth = width; m_iHeight = height; m_iMouseX = (width / 2); m_iMouseY = (height / 2); }
230
	virtual void SetWindowSize ( int width, int height ) { m_iWidth = width; m_iHeight = height; m_iMouseX = (width / 2); m_iMouseY = (height / 2); }
216
 
231
 
217
protected:
232
protected:
-
 
233
#ifdef FMOD
218
	virtual bool PlaySound ( SStoredSound *sound )
234
	virtual bool PlaySound ( SStoredSound *sound )
219
	{
235
	{
220
		if ( !sound )
236
		if ( !sound )
221
			return false;
237
			return false;
222
		
238
		
Line 226... Line 242...
226
		if ( result == FMOD_OK )
242
		if ( result == FMOD_OK )
227
			return true;
243
			return true;
228
			*/
244
			*/
229
		return false;
245
		return false;
230
	}
246
	}
-
 
247
#endif
231
 
248
 
232
	int m_iWidth, m_iHeight;
249
	int m_iWidth, m_iHeight;
233
 
250
 
234
	char *m_cKeyBuffer;
251
	char *m_cKeyBuffer;
235
	DWORD m_lKeySize;
252
	DWORD m_lKeySize;
Line 243... Line 260...
243
 
260
 
244
	bool m_bHaltMouse;
261
	bool m_bHaltMouse;
245
	int m_iMouseX, m_iMouseY;
262
	int m_iMouseX, m_iMouseY;
246
 
263
 
247
	bool m_bSound;
264
	bool m_bSound;
-
 
265
#ifdef FMOD
248
	FMOD::System *m_pSystem;
266
	FMOD::System *m_pSystem;
249
 
267
 
250
	CLinkList<SStoredSound> m_lSounds;
268
	CLinkList<SStoredSound> m_lSounds;
-
 
269
#endif
251
};
270
};
252
 
271
 
253
#endif //__OVERLAY_H__
272
#endif //__OVERLAY_H__