Procházet zdrojové kódy

Sound now also global service

Thomas Buck před 10 roky
rodič
revize
b986369a1b
5 změnil soubory, kde provedl 21 přidání a 40 odebrání
  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 Zobrazit soubor

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

+ 2
- 0
include/main.h Zobrazit soubor

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

+ 4
- 4
src/Game.cpp Zobrazit soubor

@@ -84,7 +84,7 @@ void Game::destroy() {
84 84
 
85 85
     mWorld.destroy();
86 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 90
 int Game::loadLevel(const char *level) {
@@ -265,7 +265,7 @@ int Game::command(std::vector<char *> *args) {
265 265
         }
266 266
     } else if (strcmp(cmd, "sound") == 0) {
267 267
         if (args->size() > 1) {
268
-            getOpenRaider().mSound->play(atoi(args->at(1)));
268
+            getSound().play(atoi(args->at(1)));
269 269
         } else {
270 270
             getConsole().print("Invalid use of sound command!");
271 271
             return -11;
@@ -390,7 +390,7 @@ void Game::processPakSounds()
390 390
     {
391 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 395
         //if (((i + 1) == TR_SOUND_F_PISTOL) && (id > 0))
396 396
         //{
@@ -404,7 +404,7 @@ void Game::processPakSounds()
404 404
         //pos[0] = sound[i].x;
405 405
         //pos[1] = sound[i].y;
406 406
         //pos[2] = sound[i].z;
407
-        //getOpenRaider().mSound->SourceAt(id, pos);
407
+        //getSound().SourceAt(id, pos);
408 408
 
409 409
         //printf(".");
410 410
         //fflush(stdout);

+ 2
- 29
src/OpenRaider.cpp Zobrazit soubor

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

+ 13
- 4
src/main.cpp Zobrazit soubor

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

Loading…
Zrušit
Uložit