Skip to content

Commit baeecc8

Browse files
authored
Merge pull request #18 from Moros1138/develop
try installing dependencies to have full non-headless builds for ubuntu
2 parents ffa9332 + 1f30271 commit baeecc8

File tree

4 files changed

+128
-18
lines changed

4 files changed

+128
-18
lines changed

.github/workflows/build.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ jobs:
4848
with:
4949
submodules: 'recursive'
5050

51-
- name: Install zlib and libpng without interaction
51+
- name: Install Dependencies
5252
run: |
5353
sudo apt-get update
54-
sudo apt-get install -y zlib1g-dev libpng-dev
54+
sudo apt-get install -y zlib1g-dev libpng-dev libx11-dev libgl1-mesa-dev libglu1-mesa-dev
5555
5656
- name: Set default gcc and g++ versions to latest
5757
run: |
@@ -63,7 +63,7 @@ jobs:
6363
CC: gcc
6464
CXX: g++
6565
run: |
66-
cmake . -B build -DTEST=1
66+
cmake . -B build
6767
cmake --build build
6868
shell: bash
6969

CMakeLists.txt

+20-15
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ project(olcPGEX_MiniAudio)
66
# Options you can set via command-line
77
option(HAS_TERMINAL "Show a terminal window for STDOUT/STDERR" ON)
88
option(UPDATE_GIT_SUBMODULES "Update Git submodules" ON)
9-
option(TEST "Build In Test Mode" OFF)
109

1110
if (UPDATE_GIT_SUBMODULES)
1211
message(STATUS "Updating Git submodules...")
@@ -155,23 +154,17 @@ function(add_common_settings target)
155154
######################################################################
156155
if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
157156

158-
if (TEST)
159-
target_compile_definitions(${target} PRIVATE -DOLC_PGE_HEADLESS)
160-
endif()
161-
162157
# OpenGL
163-
if (NOT TEST)
164-
set(OpenGL_GL_PREFERENCE LEGACY)
165-
find_package(OpenGL REQUIRED)
166-
include_directories(${OpenGL_INCLUDE_DIRS})
167-
target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL)
158+
set(OpenGL_GL_PREFERENCE LEGACY)
159+
find_package(OpenGL REQUIRED)
160+
include_directories(${OpenGL_INCLUDE_DIRS})
161+
target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL)
168162

169-
# X11
170-
find_package(X11 REQUIRED)
171-
target_link_libraries(${target} X11::X11)
163+
# X11
164+
find_package(X11 REQUIRED)
165+
target_link_libraries(${target} X11::X11)
172166

173-
include_directories(${X11_INCLUDE_DIRS})
174-
endif()
167+
include_directories(${X11_INCLUDE_DIRS})
175168

176169
# Threads
177170
find_package(Threads REQUIRED)
@@ -264,6 +257,17 @@ add_executable(
264257
third_party/miniaudio/miniaudio.h
265258
)
266259

260+
add_executable(
261+
demo_spatialization
262+
demo/demo_spatialization.cpp
263+
demo/olcPGEX_MiniAudio.cpp
264+
demo/olcPixelGameEngine.cpp
265+
olcPGEX_MiniAudio.h
266+
third_party/olcPixelGameEngine/olcPixelGameEngine.h
267+
third_party/miniaudio/miniaudio.h
268+
)
269+
270+
267271
if (EMSCRIPTEN)
268272
# generate an HTML file
269273
set(CMAKE_EXECUTABLE_SUFFIX .html)
@@ -272,3 +276,4 @@ endif()
272276
add_common_settings(demo)
273277
add_common_settings(demo_synthesis)
274278
add_common_settings(demo_waveform)
279+
add_common_settings(demo_spatialization)

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ for cross-platform.
88

99
See the emscripten versions of the demos here:
1010
* [Main Demo](https://www.moros1138.com/demos/olcPGEX_MiniAudio/).
11+
* [Spatialization Demo](https://www.moros1138.com/demos/olcPGEX_MiniAudio/demo_spatialization.html).
1112
* [Waveform Demo](https://www.moros1138.com/demos/olcPGEX_MiniAudio/demo_waveform.html).
1213
* [Synthesis Demo](https://www.moros1138.com/demos/olcPGEX_MiniAudio/demo_synthesis.html).
1314

demo/demo_spatialization.cpp

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#include "olcPixelGameEngine.h"
2+
#include "olcPGEX_MiniAudio.h"
3+
#include <cmath>
4+
5+
constexpr float thirtyFramesPerSecond = 1.0f / 30.f;
6+
7+
class Demo : public olc::PixelGameEngine
8+
{
9+
public:
10+
Demo()
11+
{
12+
sAppName = "Demo MiniAudio";
13+
}
14+
15+
public:
16+
bool OnUserCreate() override
17+
{
18+
ma.SetBackgroundPlay(true);
19+
20+
song1 = ma.LoadSound("assets/sounds/song1.mp3");
21+
ma_sound_set_position(ma.GetSound(song1), 0.0f, 0.0f, 0.0f);
22+
ma_sound_set_attenuation_model(ma.GetSound(song1), ma_attenuation_model_linear);
23+
ma_sound_set_min_distance(ma.GetSound(song1), 0.0f);
24+
ma_sound_set_max_distance(ma.GetSound(song1), 20.0f);
25+
ma_sound_set_max_gain(ma.GetSound(song1), 1.0f);
26+
ma_sound_set_min_gain(ma.GetSound(song1), 0.0f);
27+
28+
centerScreen = GetScreenSize() / 2;
29+
return true;
30+
}
31+
32+
olc::vf2d position{0.0f, 0.0f};
33+
float direction = 0.0f;
34+
olc::vf2d centerScreen;
35+
36+
bool OnUserUpdate(float fElapsedTime) override
37+
{
38+
fElapsedTime = (fElapsedTime > thirtyFramesPerSecond) ? thirtyFramesPerSecond : fElapsedTime;
39+
40+
if(GetKey(olc::SPACE).bPressed)
41+
{
42+
ma.Toggle(song1);
43+
}
44+
45+
float forwardVelocity = 0.0f;
46+
float rotationVelocity = 0.0f;
47+
48+
if(GetKey(olc::W).bHeld || GetKey(olc::UP).bHeld) forwardVelocity += 1.0f;
49+
if(GetKey(olc::S).bHeld || GetKey(olc::DOWN).bHeld) forwardVelocity -= 1.0f;
50+
if(GetKey(olc::A).bHeld || GetKey(olc::LEFT).bHeld) rotationVelocity -= 1.0f;
51+
if(GetKey(olc::D).bHeld || GetKey(olc::RIGHT).bHeld) rotationVelocity += 1.0f;
52+
53+
direction += rotationVelocity * 5.0f * fElapsedTime;
54+
olc::vf2d directionVector = olc::vf2d{ cosf(direction), sinf(direction) };
55+
olc::vf2d velocity = directionVector * forwardVelocity * 20.0f * fElapsedTime;
56+
position += velocity;
57+
58+
ma_engine_listener_set_direction(ma.GetEngine(), 0, directionVector.x, 0.0f, directionVector.y);
59+
ma_engine_listener_set_position(ma.GetEngine(), 0, position.x, 0.0f, position.y);
60+
ma_engine_listener_set_velocity(ma.GetEngine(), 0, velocity.x, 0.0f, velocity.y);
61+
62+
Clear(olc::BLACK);
63+
64+
DrawCircle(centerScreen, 5, olc::YELLOW);
65+
DrawCircle(centerScreen, 15, olc::MAGENTA);
66+
67+
DrawCircle(centerScreen + position, 5, olc::WHITE);
68+
DrawLine(centerScreen + position, centerScreen + position + (directionVector * 5), olc::WHITE);
69+
70+
71+
DrawStringDecal({5, 5}, \
72+
"-------- INFO --- CONTROLS -\n" "\n"
73+
"Forward/Backward (" + std::to_string(forwardVelocity) + ") W,S or UP,DOWN\n" "\n"
74+
"Rotation (" + std::to_string(direction) + ") A,D or LEFT,RIGHT\n" "\n"
75+
"Position " + position.str() + "\n" "\n"
76+
"Position Mag (" + std::to_string(position.mag()) + ")\n" "\n"
77+
"Toggle Sound (" + (ma.IsPlaying(song1) ? "Playing) " : "Not Playing)") + " SPACE\n"
78+
,
79+
olc::WHITE, {0.5f, 0.5f});
80+
81+
DrawStringDecal({5, 160}, \
82+
"Music: Joy Ride [Full version] by MusicLFiles\n"
83+
"Free download: https://filmmusic.io/song/11627-joy-ride-full-version\n"
84+
"Licensed under CC BY 4.0: https://filmmusic.io/standard-license\n", \
85+
olc::WHITE, {0.5f, 0.5f});
86+
87+
#if defined(__EMSCRIPTEN__)
88+
return true;
89+
#else
90+
return !GetKey(olc::ESCAPE).bPressed;
91+
#endif
92+
}
93+
94+
olc::MiniAudio ma;
95+
int song1;
96+
};
97+
98+
int main()
99+
{
100+
Demo demo;
101+
if (demo.Construct(320, 180, 4, 4))
102+
demo.Start();
103+
return 0;
104+
}

0 commit comments

Comments
 (0)