Browse Source

Added sound debug UI, removed sound command

Thomas Buck 9 years ago
parent
commit
bdc9462674

+ 1
- 0
ChangeLog.md View File

@@ -5,6 +5,7 @@
5 5
     [ 20141127 ]
6 6
     * Started work on loading the object texture mapping, with debug UI
7 7
     * Textiles debug UI also draws triangles “properly”
8
+    * Removed Sound command, added Sound Debug UI
8 9
 
9 10
     [ 20141126 ]
10 11
     * Reduced code duplication for BinaryFile/BinaryMemory

+ 0
- 22
include/commands/CommandSound.h View File

@@ -1,22 +0,0 @@
1
-/*!
2
- * \file include/commands/CommandSound.h
3
- * \brief Sound Command interface
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#ifndef _COMMAND_SOUND_H_
9
-#define _COMMAND_SOUND_H_
10
-
11
-#include "commands/Command.h"
12
-
13
-class CommandSound : public Command {
14
-  public:
15
-    virtual std::string name();
16
-    virtual std::string brief();
17
-    virtual void printHelp();
18
-    virtual int execute(std::istream& args);
19
-};
20
-
21
-#endif
22
-

+ 2
- 3
src/Game.cpp View File

@@ -50,7 +50,7 @@ void Game::display() {
50 50
 void Game::destroy() {
51 51
     mLoaded = false;
52 52
     mLara = -1;
53
-    getRender().setMode(Render::modeDisabled);
53
+    getRender().setMode(Render::modeLoadScreen);
54 54
 
55 55
     getWorld().destroy();
56 56
     getRender().ClearWorld();
@@ -62,8 +62,7 @@ bool Game::isLoaded() {
62 62
 }
63 63
 
64 64
 int Game::loadLevel(const char* level) {
65
-    if (mLoaded)
66
-        destroy();
65
+    destroy();
67 66
 
68 67
     levelName = level;
69 68
 

+ 2
- 0
src/SoundAL.cpp View File

@@ -56,6 +56,8 @@ int SoundAL::initialize() {
56 56
 
57 57
 void SoundAL::setEnabled(bool on) {
58 58
     mEnabled = on;
59
+    if (on && (!mInit))
60
+        initialize();
59 61
 }
60 62
 
61 63
 void SoundAL::setVolume(float vol) {

+ 35
- 0
src/UI.cpp View File

@@ -14,6 +14,7 @@
14 14
 #include "Menu.h"
15 15
 #include "Render.h"
16 16
 #include "RunTime.h"
17
+#include "Sound.h"
17 18
 #include "TextureManager.h"
18 19
 #include "Window.h"
19 20
 #include "commands/Command.h"
@@ -287,6 +288,40 @@ void UI::display() {
287 288
             }
288 289
         }
289 290
 
291
+        if (ImGui::CollapsingHeader("SoundSamples")) {
292
+            if (!getSound().getEnabled()) {
293
+                ImGui::Text("Please enable Sound before loading a level!");
294
+                if (ImGui::Button("Enable Sound!")) {
295
+                    getSound().setEnabled(true);
296
+                }
297
+            } else if (getSound().registeredSources() == 0) {
298
+                ImGui::Text("Please load a level!");
299
+            } else {
300
+                static int index = 0;
301
+                ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
302
+                ImGui::SliderInt("##soundslide", &index, 0, getSound().registeredSources() - 1);
303
+                ImGui::PopItemWidth();
304
+                ImGui::SameLine();
305
+                if (ImGui::Button("+##soundplus", ImVec2(0, 0), true)) {
306
+                    if (index < (getSound().registeredSources() - 1))
307
+                        index++;
308
+                    else
309
+                        index = 0;
310
+                }
311
+                ImGui::SameLine();
312
+                if (ImGui::Button("-##soundminus", ImVec2(0, 0), true)) {
313
+                    if (index > 0)
314
+                        index--;
315
+                    else
316
+                        index = getSound().registeredSources() - 1;
317
+                }
318
+                ImGui::SameLine();
319
+                if (ImGui::Button("Play##soundplay")) {
320
+                    getSound().play(index);
321
+                }
322
+            }
323
+        }
324
+
290 325
         /*
291 326
         if (ImGui::CollapsingHeader("UI Help")) {
292 327
             ImGui::ShowUserGuide();

+ 0
- 1
src/commands/CMakeLists.txt View File

@@ -7,7 +7,6 @@ set (CMD_SRCS ${CMD_SRCS} "CommandGame.cpp")
7 7
 set (CMD_SRCS ${CMD_SRCS} "CommandMove.cpp")
8 8
 set (CMD_SRCS ${CMD_SRCS} "CommandRender.cpp")
9 9
 set (CMD_SRCS ${CMD_SRCS} "CommandSet.cpp")
10
-set (CMD_SRCS ${CMD_SRCS} "CommandSound.cpp")
11 10
 
12 11
 # Add library
13 12
 add_library (OpenRaider_commands OBJECT ${CMD_SRCS})

+ 0
- 2
src/commands/Command.cpp View File

@@ -19,7 +19,6 @@
19 19
 #include "commands/CommandMove.h"
20 20
 #include "commands/CommandRender.h"
21 21
 #include "commands/CommandSet.h"
22
-#include "commands/CommandSound.h"
23 22
 
24 23
 std::vector<std::shared_ptr<Command>> Command::commands;
25 24
 
@@ -41,7 +40,6 @@ void Command::fillCommandList() {
41 40
     commands.push_back(std::shared_ptr<Command>(new CommandMove()));
42 41
     commands.push_back(std::shared_ptr<Command>(new CommandMode()));
43 42
     commands.push_back(std::shared_ptr<Command>(new CommandRenderflag()));
44
-    commands.push_back(std::shared_ptr<Command>(new CommandSound()));
45 43
     commands.push_back(std::shared_ptr<Command>(new CommandPos()));
46 44
     commands.push_back(std::shared_ptr<Command>(new CommandViewmodel()));
47 45
     commands.push_back(std::shared_ptr<Command>(new CommandPigtail()));

+ 0
- 42
src/commands/CommandSound.cpp View File

@@ -1,42 +0,0 @@
1
-/*!
2
- * \file src/commands/CommandSound.cpp
3
- * \brief Sound command
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include "global.h"
9
-#include "Game.h"
10
-#include "Log.h"
11
-#include "RunTime.h"
12
-#include "Sound.h"
13
-#include "commands/CommandSound.h"
14
-
15
-std::string CommandSound::name() {
16
-    return "sound";
17
-}
18
-
19
-std::string CommandSound::brief() {
20
-    return "INT - Test play sound";
21
-}
22
-
23
-void CommandSound::printHelp() {
24
-    getLog() << "sound-Command Usage:" << Log::endl;
25
-    getLog() << "sound-Command Usage:" << Log::endl;
26
-    getLog() << "  sound INT" << Log::endl;
27
-    getLog() << "Where INT is a valid sound ID integer" << Log::endl;
28
-}
29
-
30
-int CommandSound::execute(std::istream& args) {
31
-    if (!getGame().isLoaded()) {
32
-        getLog() << "Use sound command interactively!" << Log::endl;
33
-        return -1;
34
-    }
35
-
36
-    std::string s;
37
-    args >> s;
38
-
39
-    getSound().play(atoi(s.c_str()));
40
-    return 0;
41
-}
42
-

+ 13
- 18
src/loader/LoaderTR2.cpp View File

@@ -13,6 +13,7 @@
13 13
 #include "Log.h"
14 14
 #include "Mesh.h"
15 15
 #include "Room.h"
16
+#include "Sound.h"
16 17
 #include "TextureManager.h"
17 18
 #include "utils/pixel.h"
18 19
 #include "loader/LoaderTR2.h"
@@ -687,8 +688,7 @@ void LoaderTR2::loadExternalSoundFile(std::string f) {
687 688
     }
688 689
 
689 690
     int riffCount = 0;
690
-    bool done = false;
691
-    while (!done) {
691
+    while (!sfx.eof()) {
692 692
         char test[5];
693 693
         test[4] = '\0';
694 694
         for (int i = 0; i < 4; i++)
@@ -700,27 +700,22 @@ void LoaderTR2::loadExternalSoundFile(std::string f) {
700 700
             return;
701 701
         }
702 702
 
703
+        // riffSize is (fileLength - 8)
703 704
         uint32_t riffSize = sfx.readU32();
704 705
 
705
-        for (int i = 0; i < 4; i++)
706
-            test[i] = sfx.read8();
706
+        unsigned char buff[riffSize + 8];
707
+        sfx.seek(sfx.tell() - 8);
708
+        for (int i = 0; i < (riffSize + 8); i++)
709
+            buff[i] = sfx.readU8();
707 710
 
708
-        if (std::string("WAVE") != std::string(test)) {
709
-            getLog() << "LoaderTR2: External SFX invalid! (" << riffCount
710
-                << ", \"" << test << "\" != \"WAVE\")" << Log::endl;
711
-            return;
712
-        }
711
+        unsigned long src;
712
+        int ret = getSound().addWave(buff, riffSize + 8, &src, 0);
713
+        assert(ret >= 0);
713 714
 
714
-        // TODO load riff somehow somewhere
715
-
716
-        // riffSize is (fileLength - 8)
717
-        sfx.seek(sfx.tell() + riffSize - 4);
718 715
         riffCount++;
719
-
720
-        if (sfx.eof()) {
721
-            done = true;
722
-            getLog() << "LoaderTR2: Found " << riffCount << " SoundSamples" << Log::endl;
723
-        }
724 716
     }
717
+
718
+    if (riffCount > 0)
719
+        getLog() << "LoaderTR2: Found " << riffCount << " SoundSamples" << Log::endl;
725 720
 }
726 721
 

Loading…
Cancel
Save