Leistungsstarkes Game Framework
The game framework based on game framework by Woei Kae Chen
Loading...
Searching...
No Matches
audio.h
Go to the documentation of this file.
1/*
2 * gamelib.h: 本檔案儲遊戲相關的class的interface
3 * Copyright (C) 2002-2008 Woei-Kae Chen <wkc@csie.ntut.edu.tw>
4 *
5 * This file is part of game, a free game development framework for windows.
6 *
7 * game is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * game is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * History:
22 * 2002-03-04 V3.1
23 * 1. Add ENABLE_AUDIO flag.
24 * 2004-03-02 V4.0
25 * 1. Add CInteger class.
26 * 2. Add CGameState abstract class and adjust CGame to apply
27 * state pattern for switching game states.
28 * 2004-03-08 V4.1
29 * 1. Add OPEN_AS_FULLSCREEN flag.
30 * 2. The Game Engine now becomes a framework.
31 * 2005-07-28
32 * 1. Add GAME_ASSERT macro to display run time errors gracefully.
33 * 2. Remove CDDarw::CheckSystem(). It is useless.
34 * 2005-09-08
35 * 1. Eliminate CSpecialEffect::Abort. It is useless now.
36 * 2. Add SHOW_GAME_CYCLE_TIME flag.
37 * 3. Add DEFAULT_BG_COLOR flag;
38 * 2005-09-20 V4.2Beta1.
39 * 2005-09-29 V4.2Beta2.
40 * 1. Add MOUSEMOVE Handler for CGame and CGameState.
41 * 2. Add _TRACE preprocessor flag for VC++.net.
42 * 2006-02-08 V4.2
43 * 1. Rename OnInitialUpdate() -> OnInit().
44 * 2. Remove constantness of CAnimation::DELAY_COUNT.
45 * 3. Enhance CAnimation to support SetDelayCount(), Reset(), and IsFinalBitmap().
46 * 4. Remove CAnimation::GetLocation() and CMovingBitmap::GetLocation().
47 * 5. Bitmap coordinate can no longer be set by CMovingBitmap::LoadBitmap().
48 * Defauts to (0,0).
49 * 2006-09-09 V4.3
50 * 1. Rename Move() and Show() as OnMove and OnShow() to emphasize that they are
51 * event driven.
52 * 2. Fix bug: audio is now correctly recovered after a sleep or suspension of windows.
53 * 3. Support ENABLE_GAME_PAUSE.
54 * 2008-02-15 V4.4
55 * 1. Add setup project for Visual studio 2005.
56 * 2. Support bitmap scaling when ShowBitmap(scale) is called.
57 * 3. Add namespace game_framework.
58 * 4. Make the class CGame a singleton so that MFC can access it easily.
59 * 5. Support loading of bitmap from bmp file.
60 * 6. Support ShowInitProgress(percent) to display loading progress.
61 * 2010-03-23 V4.6
62 * 1. Rewrite CAudio with MCI commands to eliminate dependency with DirectMusic.
63*/
64
65#include <list>
66#include <vector>
67#include <map>
68using namespace std;
69
71// 這個class會建立DirectX Audio物件,以提供音效
72// 每個Public Interface的用法都要懂,Implementation可以不懂
73// 注意事項:音效檔案可以用WAVE檔(.wav)或MIDI檔(.mid),數個音效檔案可以
74// 混合(同時)撥放,但是其中只能混合一個MIDI檔,兩個MIDI檔案不
75// 能同時撥放,如果同時撥放兩個MIDI檔的話,前一個MIDI檔會被停
76// 掉。
78
79namespace game_framework {
80
81class CAudio {
82public:
83 ~CAudio();
84 void Close(); // 關閉Direct Sound介面
85 static CAudio* Instance(); // 取得CAudio的Instance
86 bool Load(unsigned, char *); // 載入編號i的聲音,指定MIDI檔案
87 bool Open(); // 開啟Direct Sound介面
88 void Pause(); // 暫停播放所有音效
89 void Play(unsigned, bool=false); // 開始撥放編號i的聲音,指定是否重覆撥放
90 void Resume(); // 復原暫停播放的音效
91 void SetPowerResume(); // 電源恢復
92 void Stop(unsigned); // 停止撥放編號i的聲音
93private:
94 class Info {
95 public:
96 Info() {
97 repeat = isGood = false;
98 }
99 bool repeat, isGood;
100 string fileName;
101 };
102 static void MCIThread(HANDLE); // MCI thread method
103 static void ExecuteMciCommand(char *); //
104 void SendMciCommand(char *); //
105 CAudio(); // private constructor
106 static CAudio audio; // 自動destruct
107 map<int, Info> info;
108 bool isOpened;
109 HANDLE hThread; // MCI command thread
110 HANDLE hWriteEnd; // Pipe write handle for thread
111 const static int MAX_MCI_COMMAND_SIZE = 400;
112};
113
114}
Definition: audio.h:81
bool Open()
Definition: audio.cpp:265
static CAudio * Instance()
Definition: audio.cpp:212
void SetPowerResume()
Definition: audio.cpp:311
void Play(unsigned, bool=false)
Definition: audio.cpp:293
bool Load(unsigned, char *)
Definition: audio.cpp:217
void Stop(unsigned)
Definition: audio.cpp:329
~CAudio()
Definition: audio.cpp:91
void Resume()
Definition: audio.cpp:317
void Close()
Definition: audio.cpp:198
void Pause()
Definition: audio.cpp:279
Definition: mygame.h:42