Skip to content

Commit 0c08a63

Browse files
authored
Feature/fmod plugins (#343)
* feat: Add plugin support for all platforms
1 parent 3e7dd07 commit 0c08a63

21 files changed

+673
-12
lines changed

SConstruct

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ sources = [
3939
Glob('src/helpers/*.cpp'),
4040
Glob('src/nodes/*.cpp'),
4141
Glob('src/resources/*.cpp'),
42-
Glob('src/studio/*.cpp')
42+
Glob('src/studio/*.cpp'),
43+
Glob('src/plugins/*.cpp')
4344
]
4445

4546
lfix = ""

demo/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ mono_crash.*.json
2020
logs/
2121
**/*.aar
2222
android/build
23-
android/.build_version
23+
android/

demo/android/.build_version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.1.2.stable
1+
4.4.1.stable
-13 KB
Binary file not shown.
-12.9 KB
Binary file not shown.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Plugins
2+
3+
!!! warning
4+
This feature is experimental. Please report any bug you find.
5+
6+
This addon supports FMOD plugins.
7+
First you'll need to add plugins libraries (`.dll`, `.dylib`, `.so`, `.a`) in a project's folder.
8+
In this documentation we will use `assets/plugins` as an example.
9+
In this directory you have to create one directory per os, like:
10+
```
11+
assets
12+
└───── plugins
13+
├────── windows
14+
│ └────── .dll for windows goes here
15+
├────── linux
16+
│ └────── .so for linux goes here
17+
├────── macos
18+
│ └────── .dylib for macos goes here
19+
├────── android
20+
│ ├────── x86_64
21+
│ │ └────── .so for android x86 goes here
22+
│ └────── arm64
23+
│ └────── .so for android arm64 goes here
24+
└────── ios
25+
└────── .a for ios goes here
26+
```
27+
If there are some dependent libraries needed for a plugin, just place it next to plugin's library, all libraries in
28+
those folders are exported.
29+
30+
In order to add plugins you first need to create an `FmodPluginsSettings` resource in your project:
31+
![plugins-create-settings-resource]
32+
First you need to configure the directory containing the plugins libraries. In this example `res://assets/plugins/`
33+
Then you have to configure the plugin lists.
34+
There is two lists to configure:
35+
- `Dynamic Plugin List` is used for all platforms except `iOS`
36+
- `Static Plugins Methods` is used for `iOS` only
37+
38+
For dynamic plugins you have to enter the name of the library for the plugin (without the lib prefix). As an example for
39+
steam plugin it will be `phonon_fmod`.
40+
In static plugins methods you have to place the methods from the documentation of your plugin. As and example for steam
41+
plugin it will be:
42+
- `FMOD_SteamAudio_Spatialize_GetDSPDescription`, with DSP type
43+
- `FMOD_SteamAudio_MixerReturn_GetDSPDescription`, with DSP type
44+
- `FMOD_SteamAudio_Reverb_GetDSPDescription`, with DSP type
45+
46+
Here is what the configuration looks like for this example:
47+
![fmod-plugins-settings-resource]
48+
49+
Then you have to set the path of this resource in project's settings, in the `Fmod/Plugins` section:
50+
![plugins-project-settings]
51+
52+
53+
[plugins-create-settings-resource]: ./assets/plugins-create-settings-resource.png
54+
[fmod-plugins-settings-resource]: ./assets/fmod-plugins-settings-resource.png
55+
[plugins-project-settings]: ./assets/plugins-project-settings.png
71.5 KB
Loading
35.9 KB
Loading
54.5 KB
Loading

src/fmod_cache.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
#include "fmod_cache.h"
33

44
#include "helpers/common.h"
5+
#include "classes/project_settings.hpp"
56

67
using namespace godot;
78

8-
FmodCache::FmodCache(FMOD::Studio::System* p_system) {
9-
system = p_system;
9+
FmodCache::FmodCache(FMOD::Studio::System* p_system, FMOD::System* p_core_system) :
10+
system(p_system), core_system(p_core_system) {
11+
1012
}
1113

1214
FmodCache::~FmodCache() {
1315
system = nullptr;
16+
core_system = nullptr;
1417
}
1518

1619
void FmodCache::update_pending() {
@@ -72,6 +75,43 @@ Ref<FmodBank> FmodCache::get_bank(const String& bankPath) {
7275
return banks.get(bankPath);
7376
}
7477

78+
#ifndef IOS_ENABLED
79+
80+
uint32_t FmodCache::add_plugin(const String& p_plugin_path, uint32_t p_priority) {
81+
uint32_t handle;
82+
#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)
83+
const char* plugin_path = p_plugin_path.utf8().get_data();
84+
#else
85+
const char* plugin_path = ProjectSettings::get_singleton()->globalize_path(p_plugin_path).utf8().get_data();
86+
#endif
87+
ERROR_CHECK(core_system->loadPlugin(plugin_path, &handle, p_priority));
88+
plugin_handles.append(handle);
89+
return handle;
90+
}
91+
92+
#else
93+
94+
void FmodCache::add_plugin(uint32_t p_plugin_handle) {
95+
plugin_handles.append(p_plugin_handle);
96+
}
97+
98+
#endif
99+
100+
bool FmodCache::has_plugin(uint32_t p_plugin_handle) const {
101+
return plugin_handles.has(p_plugin_handle);
102+
}
103+
104+
void FmodCache::remove_plugin(uint32_t p_plugin_handle) {
105+
if (!has_plugin(p_plugin_handle)) {
106+
GODOT_LOG_ERROR(vformat("Cannot unload plugin with handle %s, not in cache.", p_plugin_handle));
107+
return;
108+
}
109+
110+
ERROR_CHECK(core_system->unloadPlugin(p_plugin_handle));
111+
plugin_handles.erase(p_plugin_handle);
112+
}
113+
114+
75115
Ref<FmodFile> FmodCache::add_file(const String& file_path, unsigned int flag) {
76116
FMOD::System* core = nullptr;
77117
ERROR_CHECK(system->getCoreSystem(&core));

0 commit comments

Comments
 (0)