fixed REALLY bad threading bugs with audio
[fishladder.git] / fishladder_resources.h
1 // TEXTURES
2 // ===========================================================================================================
3
4 vg_tex2d tex_tile_data = { .path = "textures/tileset.png" };
5 vg_tex2d tex_tile_detail = { .path = "textures/tile_overlays.png" };
6 vg_tex2d tex_wood = { .path = "textures/wood.png" };
7 vg_tex2d tex_ball = { .path = "textures/ball.png", .flags = VG_TEXTURE_CLAMP };
8
9 vg_tex2d *texture_list[] = { &tex_tile_detail, &tex_tile_data, &tex_wood, &tex_ball };
10
11 // AUDIO
12 // ===========================================================================================================
13
14 sfx_vol_control audio_volume_sfx = { .val = 1.0f, .name = "Sound effects" };
15 sfx_vol_control audio_volume_music = { .val = 1.0f, .name = "Music" };
16
17 sfx_system audio_system_sfx =
18 {
19 .vol = 1.f,
20 .ch = 1,
21 .vol_src = &audio_volume_sfx,
22 .name = "sfx"
23 };
24
25 sfx_set audio_tile_mod =
26 {
27 .sources = "\
28 sound/mod_01.ogg\0\
29 sound/mod_02.ogg\0\
30 sound/mod_03.ogg\0\
31 sound/mod_04.ogg\0\
32 sound/mod_05.ogg\0\
33 sound/mod_06.ogg\0",
34 .flags = 0
35 };
36
37 sfx_set audio_splitter =
38 {
39 .sources = "\
40 sound/splitter_01.ogg\0"
41 };
42
43 sfx_set audio_rolls =
44 {
45 .sources = "\
46 sound/rolling_01.ogg\0\
47 sound/rolling_02.ogg\0"
48 };
49
50 sfx_set audio_random =
51 {
52 .sources = "\
53 sound/random_01.ogg\0\
54 sound/random_02.ogg\0\
55 sound/random_03.ogg\0\
56 sound/random_04.ogg\0\
57 sound/random_05.ogg\0\
58 sound/random_06.ogg\0\
59 sound/random_07.ogg\0\
60 sound/random_08.ogg\0"
61 };
62
63 // One two or three layers of rolling noise
64 sfx_system audio_system_balls_rolling =
65 {
66 .vol = 1.f, .ch = 1, .vol_src = &audio_volume_sfx,
67 .name = "Balls Rolling", .flags = SFX_FLAG_REPEAT
68 };
69
70 // Various oneshots
71 sfx_system audio_system_balls_switching =
72 {
73 .vol = 1.f, .ch = 1, .vol_src = &audio_volume_sfx,
74 .name = "Balls Switching"
75 };
76
77 // Gameplay critical sounds eg. splitter sound rocking
78 sfx_system audio_system_balls_important =
79 {
80 .vol = 1.f, .ch = 1, .vol_src = &audio_volume_sfx,
81 .name = "Balls Gameplay"
82 };
83
84 // Suplemental sounds
85 sfx_system audio_system_balls_extra =
86 {
87 .vol = 1.f, .ch = 1, .vol_src = &audio_volume_sfx,
88 .name = "Balls Extra"
89 };
90
91 static void resource_load_main(void)
92 {
93 // Textures
94 vg_tex2d_init( texture_list, vg_list_size( texture_list ) );
95
96 // Audio
97 sfx_set_init( &audio_tile_mod, NULL );
98 sfx_set_init( &audio_splitter, NULL );
99 sfx_set_init( &audio_rolls, NULL );
100 sfx_set_init( &audio_random, NULL );
101 }
102
103 static void resource_free_main(void)
104 {
105 vg_tex2d_free( texture_list, vg_list_size( texture_list ) );
106
107 sfx_set_free( &audio_tile_mod );
108 sfx_set_free( &audio_splitter );
109 sfx_set_free( &audio_rolls );
110 sfx_set_free( &audio_random );
111 }
112
113 // SHADERS
114 // ===========================================================================================================
115
116 SHADER_DEFINE( shader_tile_colour,
117
118 // VERTEX
119 "layout (location=0) in vec2 a_co;"
120 "uniform mat3 uPv;"
121 "uniform vec3 uOffset;"
122 ""
123 "void main()"
124 "{"
125 "gl_Position = vec4( uPv * vec3( a_co * uOffset.z + uOffset.xy, 1.0 ), 1.0 );"
126 "}",
127
128 // FRAGMENT
129 "out vec4 FragColor;"
130 "uniform vec4 uColour;"
131 ""
132 "void main()"
133 "{"
134 "FragColor = uColour;"
135 "}"
136 ,
137 UNIFORMS({ "uPv", "uOffset", "uColour" })
138 )
139
140 SHADER_DEFINE( shader_ball,
141 // VERTEX
142 "layout (location=0) in vec2 a_co;"
143 "uniform vec2 uOffset;"
144 "uniform mat3 uPv;"
145 ""
146 "out vec2 aTexCoords;"
147 ""
148 "void main()"
149 "{"
150 // Create texture coords
151 "aTexCoords = a_co;"
152
153 // Vertex transform
154 "vec3 worldpos = vec3( a_co * 0.5 - 0.25 + uOffset, 1.0 );"
155 "gl_Position = vec4( uPv * worldpos, 1.0 );"
156 "}",
157
158 // FRAGMENT
159 "out vec4 FragColor;"
160 ""
161 "uniform sampler2D uTexMain;"
162 "uniform vec3 uColour;"
163 ""
164 "in vec2 aTexCoords;"
165 ""
166 "void main()"
167 "{"
168 "vec4 glyph = texture( uTexMain, aTexCoords );"
169 "FragColor = vec4( uColour + glyph.rgb * 0.2, glyph.a );"
170 "}"
171 ,
172 UNIFORMS({ "uTexMain", "uColour", "uOffset", "uPv" })
173 )
174
175 SHADER_DEFINE( shader_tile_main,
176 // VERTEX
177 "layout (location=0) in vec2 a_co;"
178 "uniform vec4 uOffset;" // Tile x/y, uv x/y
179 "uniform mat3 uPv;"
180 "uniform mat2 uSubTransform;"
181 ""
182 "out vec4 aTexCoords;"
183 "out vec2 aWorldCoords;"
184 ""
185 "vec2 hash22(vec2 p)"
186 "{"
187 "vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));"
188 "p3 += dot(p3, p3.yzx+33.33);"
189 "return fract((p3.xx+p3.yz)*p3.zy);"
190 "}"
191 ""
192 "void main()"
193 "{"
194 // Vertex transform
195 "vec2 subtransform = uSubTransform * (a_co-0.5) + 0.5;"
196 "vec3 worldpos = vec3( subtransform + uOffset.xy, 1.0 );"
197 "gl_Position = vec4( uPv * worldpos, 1.0 );"
198
199 // Create texture coords
200 "vec2 random_offset = floor(hash22(uOffset.xy) * 4.0) * 0.25;"
201 "vec2 edge_safe_coords = a_co * 0.98 + 0.01;"
202 "aTexCoords = vec4((edge_safe_coords + uOffset.zw) * 0.25, edge_safe_coords * 0.25 + random_offset );"
203 "aWorldCoords = worldpos.xy;"
204 "}",
205
206 // FRAGMENT
207 "out vec4 FragColor;"
208 ""
209 "uniform sampler2D uTexGlyphs;"
210 "uniform sampler2D uTexWood;"
211 "uniform float uGhost;"
212 "uniform vec2 uMousePos;"
213 "uniform vec4 uColour;"
214 ""
215 "in vec4 aTexCoords;"
216 "in vec2 aWorldCoords;"
217 ""
218 "void main()"
219 "{"
220 "vec3 shadowing_colour = vec3( 0.93, 0.88536, 0.8184 );"
221 "vec4 glyph = texture( uTexGlyphs, aTexCoords.xy );"
222 "vec4 wood = texture( uTexWood, aTexCoords.zw );"
223 "vec4 wood_secondary = texture( uTexWood, aTexCoords.zw + 0.25 );"
224 "vec3 wood_comp = mix( wood_secondary.rgb * shadowing_colour, wood.rgb, clamp( glyph.b * 2.0 - 1.0, 0.0, 1.0 ) );"
225
226 "vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );"
227
228 "vec4 output_regular = vec4( wood_comp * shadows, glyph.b );"
229
230 "float ghost_dist = clamp( 1.5 - distance(uMousePos, aWorldCoords), 0.0, 1.0 );"
231 "vec4 output_ghost = vec4( 1.0, 1.0, 1.0, glyph.g * ghost_dist );"
232
233 "FragColor = mix( output_regular, output_ghost, uGhost ) * uColour;"
234 "}"
235 ,
236 UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos", "uColour" })
237 )
238
239 void vg_register(void)
240 {
241 SHADER_INIT( shader_tile_colour );
242 SHADER_INIT( shader_tile_main );
243 SHADER_INIT( shader_ball );
244 }