ソースを参照

Sound now also global service

Thomas Buck 11年前
コミット
b986369a1b
5個のファイルの変更21行の追加40行の削除
  1. 0
    3
      include/OpenRaider.h
  2. 2
    0
      include/main.h
  3. 4
    4
      src/Game.cpp
  4. 2
    29
      src/OpenRaider.cpp
  5. 13
    4
      src/main.cpp

+ 0
- 3
include/OpenRaider.h ファイルの表示

57
 
57
 
58
     //! \fixme should be private
58
     //! \fixme should be private
59
 
59
 
60
-    Sound *mSound;
61
-
62
     bool mMapListFilled;
60
     bool mMapListFilled;
63
     std::vector<char *> mMapList;
61
     std::vector<char *> mMapList;
64
 
62
 
88
 
86
 
89
     void fillMapList();
87
     void fillMapList();
90
 
88
 
91
-    bool mInit;
92
     bool mRunning;
89
     bool mRunning;
93
     bool mFPS;
90
     bool mFPS;
94
 
91
 

+ 2
- 0
include/main.h ファイルの表示

11
 #include "Game.h"
11
 #include "Game.h"
12
 #include "Menu.h"
12
 #include "Menu.h"
13
 #include "OpenRaider.h"
13
 #include "OpenRaider.h"
14
+#include "Sound.h"
14
 #include "Window.h"
15
 #include "Window.h"
15
 
16
 
16
 Console    &getConsole();
17
 Console    &getConsole();
17
 Game       &getGame();
18
 Game       &getGame();
18
 Menu       &getMenu();
19
 Menu       &getMenu();
19
 OpenRaider &getOpenRaider();
20
 OpenRaider &getOpenRaider();
21
+Sound      &getSound();
20
 Window     &getWindow();
22
 Window     &getWindow();
21
 
23
 
22
 /*!
24
 /*!

+ 4
- 4
src/Game.cpp ファイルの表示

84
 
84
 
85
     mWorld.destroy();
85
     mWorld.destroy();
86
     mRender->ClearWorld();
86
     mRender->ClearWorld();
87
-    getOpenRaider().mSound->clear(); // Remove all previously loaded sounds
87
+    getSound().clear(); // Remove all previously loaded sounds
88
 }
88
 }
89
 
89
 
90
 int Game::loadLevel(const char *level) {
90
 int Game::loadLevel(const char *level) {
265
         }
265
         }
266
     } else if (strcmp(cmd, "sound") == 0) {
266
     } else if (strcmp(cmd, "sound") == 0) {
267
         if (args->size() > 1) {
267
         if (args->size() > 1) {
268
-            getOpenRaider().mSound->play(atoi(args->at(1)));
268
+            getSound().play(atoi(args->at(1)));
269
         } else {
269
         } else {
270
             getConsole().print("Invalid use of sound command!");
270
             getConsole().print("Invalid use of sound command!");
271
             return -11;
271
             return -11;
390
     {
390
     {
391
         mTombRaider.getSoundSample(i, &riffSz, &riff);
391
         mTombRaider.getSoundSample(i, &riffSz, &riff);
392
 
392
 
393
-        getOpenRaider().mSound->addWave(riff, riffSz, &id, getOpenRaider().mSound->SoundFlagsNone);
393
+        getSound().addWave(riff, riffSz, &id, getSound().SoundFlagsNone);
394
 
394
 
395
         //if (((i + 1) == TR_SOUND_F_PISTOL) && (id > 0))
395
         //if (((i + 1) == TR_SOUND_F_PISTOL) && (id > 0))
396
         //{
396
         //{
404
         //pos[0] = sound[i].x;
404
         //pos[0] = sound[i].x;
405
         //pos[1] = sound[i].y;
405
         //pos[1] = sound[i].y;
406
         //pos[2] = sound[i].z;
406
         //pos[2] = sound[i].z;
407
-        //getOpenRaider().mSound->SourceAt(id, pos);
407
+        //getSound().SourceAt(id, pos);
408
 
408
 
409
         //printf(".");
409
         //printf(".");
410
         //fflush(stdout);
410
         //fflush(stdout);

+ 2
- 29
src/OpenRaider.cpp ファイルの表示

25
 #include "OpenRaider.h"
25
 #include "OpenRaider.h"
26
 
26
 
27
 OpenRaider::OpenRaider() {
27
 OpenRaider::OpenRaider() {
28
-    mInit = false;
29
     mRunning = false;
28
     mRunning = false;
30
     mFPS = false;
29
     mFPS = false;
31
     mBaseDir = NULL;
30
     mBaseDir = NULL;
34
     mDataDir = NULL;
33
     mDataDir = NULL;
35
     mMapListFilled = false;
34
     mMapListFilled = false;
36
 
35
 
37
-    mSound = new Sound();
38
-
39
     for (int i = 0; i < ActionEventCount; i++)
36
     for (int i = 0; i < ActionEventCount; i++)
40
         keyBindings[i] = unknown;
37
         keyBindings[i] = unknown;
41
 
38
 
44
 }
41
 }
45
 
42
 
46
 OpenRaider::~OpenRaider() {
43
 OpenRaider::~OpenRaider() {
47
-    if (mSound)
48
-        delete mSound;
49
-
50
     if (mBaseDir)
44
     if (mBaseDir)
51
         delete mBaseDir;
45
         delete mBaseDir;
52
 
46
 
307
             getConsole().print("set-audio-Error: Invalid value (%s)", value);
301
             getConsole().print("set-audio-Error: Invalid value (%s)", value);
308
             return -4;
302
             return -4;
309
         }
303
         }
310
-        mSound->setEnabled(audio);
304
+        getSound().setEnabled(audio);
311
     } else if (strcmp(var, "volume") == 0) {
305
     } else if (strcmp(var, "volume") == 0) {
312
         float vol = 1.0f;
306
         float vol = 1.0f;
313
         if (sscanf(value, "%f", &vol) != 1) {
307
         if (sscanf(value, "%f", &vol) != 1) {
314
             getConsole().print("set-volume-Error: Invalid value (%s)", value);
308
             getConsole().print("set-volume-Error: Invalid value (%s)", value);
315
             return -5;
309
             return -5;
316
         }
310
         }
317
-        mSound->setVolume(vol);
311
+        getSound().setVolume(vol);
318
     } else if (strcmp(var, "mouse_x") == 0) {
312
     } else if (strcmp(var, "mouse_x") == 0) {
319
         float sense = 1.0f;
313
         float sense = 1.0f;
320
         if (sscanf(value, "%f", &sense) != 1) {
314
         if (sscanf(value, "%f", &sense) != 1) {
542
 
536
 
543
     assert(dir != NULL);
537
     assert(dir != NULL);
544
     assert(dir[0] != '\0');
538
     assert(dir[0] != '\0');
545
-    assert(mInit == true);
546
     assert(mRunning == true);
539
     assert(mRunning == true);
547
 
540
 
548
     pakDir = opendir(dir);
541
     pakDir = opendir(dir);
589
 }
582
 }
590
 
583
 
591
 void OpenRaider::fillMapList() {
584
 void OpenRaider::fillMapList() {
592
-    assert(mInit == true);
593
     assert(mRunning == true);
585
     assert(mRunning == true);
594
 
586
 
595
     char *tmp = fullPath(mPakDir, '/');
587
     char *tmp = fullPath(mPakDir, '/');
598
     mMapListFilled = true;
590
     mMapListFilled = true;
599
 }
591
 }
600
 
592
 
601
-int OpenRaider::initialize() {
602
-    assert(mInit == false);
603
-    assert(mRunning == false);
604
-
605
-    // Initialize sound
606
-    if (mSound->initialize() != 0)
607
-        return -1;
608
-
609
-    mInit = true;
610
-
611
-    return 0;
612
-}
613
-
614
 void OpenRaider::run() {
593
 void OpenRaider::run() {
615
-    assert(mInit == true);
616
     assert(mRunning == false);
594
     assert(mRunning == false);
617
 
595
 
618
     static clock_t fpsSum = 0, fpsCount = 0;
596
     static clock_t fpsSum = 0, fpsCount = 0;
665
 
643
 
666
 void OpenRaider::handleKeyboard(KeyboardButton key, bool pressed) {
644
 void OpenRaider::handleKeyboard(KeyboardButton key, bool pressed) {
667
     assert(key < unknown);
645
     assert(key < unknown);
668
-    assert(mInit == true);
669
     assert(mRunning == true);
646
     assert(mRunning == true);
670
 
647
 
671
     if ((keyBindings[menuAction] == key) && pressed) {
648
     if ((keyBindings[menuAction] == key) && pressed) {
692
 void OpenRaider::handleText(char *text, bool notFinished) {
669
 void OpenRaider::handleText(char *text, bool notFinished) {
693
     assert(text != NULL);
670
     assert(text != NULL);
694
     assert(text[0] != '\0');
671
     assert(text[0] != '\0');
695
-    assert(mInit == true);
696
     assert(mRunning == true);
672
     assert(mRunning == true);
697
 
673
 
698
     if ((getConsole().isVisible()) && (!getMenu().isVisible())) {
674
     if ((getConsole().isVisible()) && (!getMenu().isVisible())) {
702
 
678
 
703
 void OpenRaider::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
679
 void OpenRaider::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
704
     assert(button < unknown);
680
     assert(button < unknown);
705
-    assert(mInit == true);
706
     assert(mRunning == true);
681
     assert(mRunning == true);
707
 
682
 
708
     if (getMenu().isVisible()) {
683
     if (getMenu().isVisible()) {
718
 
693
 
719
 void OpenRaider::handleMouseMotion(int xrel, int yrel) {
694
 void OpenRaider::handleMouseMotion(int xrel, int yrel) {
720
     assert((xrel != 0) || (yrel != 0));
695
     assert((xrel != 0) || (yrel != 0));
721
-    assert(mInit == true);
722
     assert(mRunning == true);
696
     assert(mRunning == true);
723
 
697
 
724
     if ((!getConsole().isVisible()) && (!getMenu().isVisible())) {
698
     if ((!getConsole().isVisible()) && (!getMenu().isVisible())) {
728
 
702
 
729
 void OpenRaider::handleMouseScroll(int xrel, int yrel) {
703
 void OpenRaider::handleMouseScroll(int xrel, int yrel) {
730
     assert((xrel != 0) || (yrel != 0));
704
     assert((xrel != 0) || (yrel != 0));
731
-    assert(mInit == true);
732
     assert(mRunning == true);
705
     assert(mRunning == true);
733
 
706
 
734
     if ((getConsole().isVisible()) && (!getMenu().isVisible())) {
707
     if ((getConsole().isVisible()) && (!getMenu().isVisible())) {

+ 13
- 4
src/main.cpp ファイルの表示

18
 Game *gGame = NULL;
18
 Game *gGame = NULL;
19
 Menu *gMenu = NULL;
19
 Menu *gMenu = NULL;
20
 OpenRaider *gOpenRaider = NULL;
20
 OpenRaider *gOpenRaider = NULL;
21
+Sound *gSound = NULL;
21
 Window *gWindow = NULL;
22
 Window *gWindow = NULL;
22
 
23
 
23
 Console &getConsole() {
24
 Console &getConsole() {
36
     return *gOpenRaider;
37
     return *gOpenRaider;
37
 }
38
 }
38
 
39
 
40
+Sound &getSound() {
41
+    return *gSound;
42
+}
43
+
39
 Window &getWindow() {
44
 Window &getWindow() {
40
     return *gWindow;
45
     return *gWindow;
41
 }
46
 }
53
     if (gOpenRaider)
58
     if (gOpenRaider)
54
         delete gOpenRaider;
59
         delete gOpenRaider;
55
 
60
 
61
+    if (gSound)
62
+        delete gSound;
63
+
56
     if (gWindow)
64
     if (gWindow)
57
         delete gWindow;
65
         delete gWindow;
58
 
66
 
101
     atexit(cleanupHandler);
109
     atexit(cleanupHandler);
102
     gOpenRaider = new OpenRaider();
110
     gOpenRaider = new OpenRaider();
103
     gWindow = new WindowSDL();
111
     gWindow = new WindowSDL();
112
+    gSound = new Sound();
104
     gConsole = new Console();
113
     gConsole = new Console();
105
     gMenu = new Menu();
114
     gMenu = new Menu();
106
     gGame = new Game();
115
     gGame = new Game();
135
         return 5;
144
         return 5;
136
     }
145
     }
137
 
146
 
138
-    error = gOpenRaider->initialize();
147
+    error = gSound->initialize();
139
     if (error != 0) {
148
     if (error != 0) {
140
-        printf("Could not initialize OpenRaider (%d)!\n", error);
141
-        return 6;
149
+        printf("Could not initialize Sound (%d)!\n", error);
150
+        return 7;
142
     }
151
     }
143
 
152
 
144
     // Initialize game engine
153
     // Initialize game engine
145
     error = gGame->initialize();
154
     error = gGame->initialize();
146
     if (error != 0) {
155
     if (error != 0) {
147
         printf("Could not initialize Game Engine (%d)!\n", error);
156
         printf("Could not initialize Game Engine (%d)!\n", error);
148
-        return 7;
157
+        return 8;
149
     }
158
     }
150
 
159
 
151
     gMenu->setVisible(true);
160
     gMenu->setVisible(true);

読み込み中…
キャンセル
保存