Skip to content

Commit 73b16ba

Browse files
committed
Initial upload
1 parent 7950d1b commit 73b16ba

File tree

10 files changed

+4144
-1
lines changed

10 files changed

+4144
-1
lines changed

COPYING.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2018 Timur Gafarov
2+
3+
Boost Software License - Version 1.0 - August 17th, 2003
4+
5+
Permission is hereby granted, free of charge, to any person or organization
6+
obtaining a copy of the software and accompanying documentation covered by
7+
this license (the "Software") to use, reproduce, display, distribute,
8+
execute, and transmit the Software, and to prepare derivative works of the
9+
Software, and to permit third-parties to whom the Software is furnished to
10+
do so, all subject to the following:
11+
12+
The copyright notices in the Software and this entire statement, including
13+
the above license grant, this restriction and the following disclaimer,
14+
must be included in all copies of the Software, in whole or in part, and
15+
all derivative works of the Software, unless such copies or derivative
16+
works are solely in the form of machine-executable object code generated by
17+
a source language processor.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25+
DEALINGS IN THE SOFTWARE.
26+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# bindbc-soloud
2-
BindBC binding to SoLoud
2+
BindBC binding to [SoLoud sound engine](https://github.com/jarikomppa/soloud).

dub.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "bindbc-soloud",
3+
"description": "BindBC binding to SoLoud",
4+
"homepage": "https://github.com/gecko0307/bindbc-soloud",
5+
"license": "BSL-1.0",
6+
"authors": [
7+
"Timur Gafarov"
8+
],
9+
10+
"importPaths": ["src"],
11+
"sourcePaths": ["src"],
12+
13+
"dependencies": {
14+
"bindbc-loader": "~>0.1.1"
15+
},
16+
17+
"buildRequirements":[
18+
"allowWarnings"
19+
],
20+
21+
"configurations": [
22+
{
23+
"name": "library",
24+
"targetType": "library"
25+
}
26+
],
27+
}

src/bindbc/soloud/binddynamic.d

Lines changed: 1195 additions & 0 deletions
Large diffs are not rendered by default.

src/bindbc/soloud/constants.d

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Boost Software License - Version 1.0 - August 17th, 2003
3+
4+
Permission is hereby granted, free of charge, to any person or organization
5+
obtaining a copy of the software and accompanying documentation covered by
6+
this license (the "Software") to use, reproduce, display, distribute,
7+
execute, and transmit the Software, and to prepare derivative works of the
8+
Software, and to permit third-parties to whom the Software is furnished to
9+
do so, all subject to the following:
10+
11+
The copyright notices in the Software and this entire statement, including
12+
the above license grant, this restriction and the following disclaimer,
13+
must be included in all copies of the Software, in whole or in part, and
14+
all derivative works of the Software, unless such copies or derivative
15+
works are solely in the form of machine-executable object code generated by
16+
a source language processor.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24+
DEALINGS IN THE SOFTWARE.
25+
*/
26+
module bindbc.soloud.constants;
27+
28+
import bindbc.soloud.types;

src/bindbc/soloud/generate.py

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
""" SoLoud D wrapper generator """
2+
3+
import soloud_codegen
4+
5+
fo = open("binddynamic.d", "w")
6+
7+
C_TO_D_TYPES = {
8+
"string":"string",
9+
"int":"int",
10+
"void":"void",
11+
"const char *":"const(char)*",
12+
"char *":"char*",
13+
"unsigned int":"uint",
14+
"float":"float",
15+
"double":"double",
16+
"float *":"float[]",
17+
"File *":"SoloudObject",
18+
"unsigned char *":"ubyte*",
19+
"unsigned char":"ubyte",
20+
"short *":"short[]"
21+
}
22+
23+
for soloud_type in soloud_codegen.soloud_type:
24+
C_TO_D_TYPES[soloud_type + " *"] = "SoloudObject"
25+
26+
def has_ex_variant(funcname):
27+
""" Checks if this function has an "Ex" variant """
28+
if funcname[-2::] == "Ex":
29+
# Already an Ex..
30+
return False
31+
for func in soloud_codegen.soloud_func:
32+
if func[1] == (funcname + "Ex"):
33+
return True
34+
return False
35+
36+
# Forward declare ALL THE CLASSES
37+
for soloud_type in soloud_codegen.soloud_type:
38+
#fo.write("public class %s;\n"%(soloud_type))
39+
pass
40+
41+
def external_pointer_fix(param):
42+
if param == "SoloudObject":
43+
return "int*"
44+
return param
45+
46+
function_signatures = ""
47+
function_decls = ""
48+
function_loaders = ""
49+
50+
for x in soloud_codegen.soloud_type:
51+
first = True
52+
for y in soloud_codegen.soloud_func:
53+
if (x + "_") == y[1][0:len(x)+1:]:
54+
if first:
55+
# Declare creator and destroyer
56+
function_signatures += (' alias @nogc nothrow int* function() da_%s_create;\n'%(x))
57+
function_decls += (' da_%s_create %s_create;\n'%(x, x))
58+
function_loaders += (' lib.bindSymbol(cast(void**)&%s_create, \"%s_create\");\n'%(x, x))
59+
60+
function_signatures += (' alias @nogc nothrow int* function(int* aObjHandle) da_%s_destroy;\n'%(x))
61+
function_decls += (' da_%s_destroy %s_destroy;\n'%(x, x))
62+
function_loaders += (' lib.bindSymbol(cast(void**)&%s_destroy, \"%s_destroy\");\n'%(x, x))
63+
64+
first = False
65+
66+
funcname = y[1][len(x)+1::]
67+
# If the function has the name "Ex", remove the subfix
68+
if funcname[-2::] == "Ex":
69+
funcname = funcname[:len(funcname)-2]
70+
# Skip generating functions that have an Ex variant
71+
if funcname == "create" or funcname == "destroy" or has_ex_variant(y[1]):
72+
pass # omit create/destroy, handled by __exit__ / close
73+
else:
74+
ret = C_TO_D_TYPES[y[0]]
75+
function_signatures += (' alias @nogc nothrow %s function(int* aObjHandle'%(ret))
76+
77+
for z in y[2]:
78+
if len(z) > 1:
79+
if z[1] == 'a'+x:
80+
pass # skip the 'self' pointer
81+
else:
82+
function_signatures += ', '
83+
function_signatures += external_pointer_fix(C_TO_D_TYPES[z[0]]) + ' ' + z[1]
84+
function_signatures += ') da_%s;\n' % y[1]
85+
86+
function_decls += ' da_%s %s;\n' % (y[1], y[1])
87+
function_loaders += (' lib.bindSymbol(cast(void**)&%s, \"%s\");\n'%(y[1], y[1]))
88+
89+
fo.write(
90+
"""/*
91+
Boost Software License - Version 1.0 - August 17th, 2003
92+
93+
Permission is hereby granted, free of charge, to any person or organization
94+
obtaining a copy of the software and accompanying documentation covered by
95+
this license (the "Software") to use, reproduce, display, distribute,
96+
execute, and transmit the Software, and to prepare derivative works of the
97+
Software, and to permit third-parties to whom the Software is furnished to
98+
do so, all subject to the following:
99+
100+
The copyright notices in the Software and this entire statement, including
101+
the above license grant, this restriction and the following disclaimer,
102+
must be included in all copies of the Software, in whole or in part, and
103+
all derivative works of the Software, unless such copies or derivative
104+
works are solely in the form of machine-executable object code generated by
105+
a source language processor.
106+
107+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
108+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
109+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
110+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
111+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
112+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
113+
DEALINGS IN THE SOFTWARE.
114+
*/
115+
116+
module bindbc.soloud.binddynamic;
117+
118+
import bindbc.loader;
119+
import bindbc.soloud.types;
120+
"""
121+
)
122+
123+
fo.write(
124+
"""
125+
extern(C)
126+
{
127+
%s
128+
}
129+
""" % function_signatures
130+
)
131+
132+
fo.write(
133+
"""
134+
__gshared
135+
{
136+
%s
137+
}
138+
""" % function_decls
139+
)
140+
141+
fo.write(
142+
"""
143+
private
144+
{
145+
SharedLib lib;
146+
SLSupport loadedVersion;
147+
}
148+
149+
void unloadOpenCL()
150+
{
151+
if (lib != invalidHandle)
152+
{
153+
lib.unload();
154+
}
155+
}
156+
157+
SLSupport loadedSoloudVersion() { return loadedVersion; }
158+
bool isSoloudLoaded() { return lib != invalidHandle; }
159+
160+
SLSupport loadSoloud()
161+
{
162+
version(Windows)
163+
{
164+
version(X86)
165+
{
166+
const(char)[][2] libNames =
167+
[
168+
\"soloud.dll\",
169+
\"soloud_x86.dll\"
170+
];
171+
}
172+
else version(X86_64)
173+
{
174+
const(char)[][2] libNames =
175+
[
176+
\"soloud.dll\",
177+
\"soloud_x64.dll\"
178+
];
179+
}
180+
}
181+
else version(OSX)
182+
{
183+
const(char)[][1] libNames =
184+
[
185+
\"libsoloud.dylib\"
186+
];
187+
}
188+
else version(Posix)
189+
{
190+
const(char)[][2] libNames =
191+
[
192+
\"libsoloud.so.1\",
193+
\"libsoloud.so\"
194+
];
195+
}
196+
else static assert(0, \"bindbc-soloud is not yet supported on this platform.\");
197+
198+
SLSupport ret;
199+
foreach(name; libNames)
200+
{
201+
ret = loadSoloud(name.ptr);
202+
if (ret != SLSupport.noLibrary)
203+
break;
204+
}
205+
return ret;
206+
}
207+
208+
"""
209+
)
210+
211+
fo.write(
212+
"""
213+
SLSupport loadSoloud(const(char)* libName)
214+
{
215+
lib = load(libName);
216+
if(lib == invalidHandle)
217+
{
218+
return SLSupport.noLibrary;
219+
}
220+
221+
auto errCount = errorCount();
222+
loadedVersion = SLSupport.badLibrary;
223+
224+
%s
225+
226+
loadedVersion = SLSupport.sl20181119;
227+
228+
if (errorCount() != errCount)
229+
return SLSupport.badLibrary;
230+
231+
return loadedVersion;
232+
}
233+
""" % function_loaders
234+
)
235+
236+
fo.close()
237+
238+
print("soloud.d generated")

src/bindbc/soloud/package.d

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Boost Software License - Version 1.0 - August 17th, 2003
3+
4+
Permission is hereby granted, free of charge, to any person or organization
5+
obtaining a copy of the software and accompanying documentation covered by
6+
this license (the "Software") to use, reproduce, display, distribute,
7+
execute, and transmit the Software, and to prepare derivative works of the
8+
Software, and to permit third-parties to whom the Software is furnished to
9+
do so, all subject to the following:
10+
11+
The copyright notices in the Software and this entire statement, including
12+
the above license grant, this restriction and the following disclaimer,
13+
must be included in all copies of the Software, in whole or in part, and
14+
all derivative works of the Software, unless such copies or derivative
15+
works are solely in the form of machine-executable object code generated by
16+
a source language processor.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24+
DEALINGS IN THE SOFTWARE.
25+
*/
26+
27+
module bindbc.soloud;
28+
29+
public import bindbc.soloud.constants;
30+
public import bindbc.soloud.types;
31+
32+
//version(BindBC_Static) version = BindOpenCL_Static;
33+
//version(BindFreetype_Static) public import bindbc.freetype.bindstatic;
34+
//else public import bindbc.freetype.binddynamic;
35+
36+
public import bindbc.soloud.binddynamic;
37+

0 commit comments

Comments
 (0)