├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── assets ├── music │ ├── space-of-atmos.mp3 │ ├── space-of-atmos.wav │ ├── space-of-jazz.mp3 │ ├── space-of-jazz.wav │ ├── space-of-silence.mp3 │ └── space-of-silence.wav ├── shaders │ ├── 150_core.glslf │ └── 150_core.glslv ├── sounds │ ├── explosion-guitar.mp3 │ ├── explosion-guitar.wav │ ├── explosion.wav │ ├── explosion2.wav │ ├── explosion3.wav │ ├── laser-guitar-2.mp3 │ ├── laser-guitar-2.wav │ ├── laser-guitar-3.mp3 │ ├── laser-guitar-3.wav │ ├── laser-guitar-4.mp3 │ ├── laser-guitar-4.wav │ ├── laser-guitar-5.mp3 │ ├── laser-guitar-5.wav │ ├── laser-guitar-6.mp3 │ ├── laser-guitar-6.wav │ ├── laser-guitar-7.mp3 │ ├── laser-guitar-7.wav │ ├── laser-guitar.mp3 │ ├── laser-guitar.wav │ ├── laser-pulse-2.mp3 │ ├── laser-pulse-2.wav │ ├── laser-pulse-3.mp3 │ ├── laser-pulse-3.wav │ ├── laser-pulse-4.mp3 │ ├── laser-pulse-4.wav │ ├── laser-pulse-5.mp3 │ ├── laser-pulse-5.wav │ ├── laser-pulse-6.mp3 │ ├── laser-pulse-6.wav │ ├── laser-pulse-7.mp3 │ ├── laser-pulse-7.wav │ ├── laser-pulse.mp3 │ ├── laser-pulse.wav │ ├── laser.wav │ ├── laser2.wav │ └── laser3.wav ├── spaceship.blend ├── spaceship.mtl └── spaceship.obj ├── images └── screenshot.png └── src ├── assets.dyon ├── bullets.dyon ├── comets.dyon ├── engine ├── math.rs ├── mod.rs ├── obj.rs ├── shader.rs └── sound.rs ├── explosions.dyon ├── game.dyon ├── input.dyon ├── lib.dyon ├── main.dyon ├── main.rs ├── space.dyon ├── spaceship.dyon └── std ├── math.dyon ├── math2.dyon ├── math3.dyon ├── render.dyon └── utils.dyon /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | [root] 2 | name = "dyon_asteroids" 3 | version = "0.1.0" 4 | dependencies = [ 5 | "current 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 6 | "dyon 0.7.0 (git+https://github.com/PistonDevelopers/dyon/)", 7 | "glium 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", 8 | "piston 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)", 9 | "piston-dyon_interactive 0.1.0 (git+https://github.com/PistonDevelopers/dyon/)", 10 | "piston2d-glium_graphics 0.25.0 (registry+https://github.com/rust-lang/crates.io-index)", 11 | "pistoncore-sdl2_window 0.30.2 (registry+https://github.com/rust-lang/crates.io-index)", 12 | "sdl2 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", 13 | "sdl2_mixer 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", 14 | "vecmath 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 15 | "wavefront_obj 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 16 | ] 17 | 18 | [[package]] 19 | name = "android_glue" 20 | version = "0.1.3" 21 | source = "registry+https://github.com/rust-lang/crates.io-index" 22 | 23 | [[package]] 24 | name = "backtrace" 25 | version = "0.1.8" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | dependencies = [ 28 | "backtrace-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 29 | "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 30 | "dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 31 | "debug-builders 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 32 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 33 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 34 | "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 35 | ] 36 | 37 | [[package]] 38 | name = "backtrace-sys" 39 | version = "0.1.4" 40 | source = "registry+https://github.com/rust-lang/crates.io-index" 41 | dependencies = [ 42 | "gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", 43 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 44 | ] 45 | 46 | [[package]] 47 | name = "bitflags" 48 | version = "0.3.3" 49 | source = "registry+https://github.com/rust-lang/crates.io-index" 50 | 51 | [[package]] 52 | name = "bitflags" 53 | version = "0.6.0" 54 | source = "registry+https://github.com/rust-lang/crates.io-index" 55 | 56 | [[package]] 57 | name = "bitflags" 58 | version = "0.7.0" 59 | source = "registry+https://github.com/rust-lang/crates.io-index" 60 | 61 | [[package]] 62 | name = "byteorder" 63 | version = "0.5.3" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | 66 | [[package]] 67 | name = "cfg-if" 68 | version = "0.1.0" 69 | source = "registry+https://github.com/rust-lang/crates.io-index" 70 | 71 | [[package]] 72 | name = "cgl" 73 | version = "0.1.5" 74 | source = "registry+https://github.com/rust-lang/crates.io-index" 75 | dependencies = [ 76 | "gleam 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 77 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 78 | ] 79 | 80 | [[package]] 81 | name = "cocoa" 82 | version = "0.3.3" 83 | source = "registry+https://github.com/rust-lang/crates.io-index" 84 | dependencies = [ 85 | "bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 86 | "core-graphics 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 87 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 88 | "objc 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 89 | ] 90 | 91 | [[package]] 92 | name = "color_quant" 93 | version = "1.0.0" 94 | source = "registry+https://github.com/rust-lang/crates.io-index" 95 | 96 | [[package]] 97 | name = "cookie" 98 | version = "0.2.5" 99 | source = "registry+https://github.com/rust-lang/crates.io-index" 100 | dependencies = [ 101 | "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", 102 | "url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 103 | ] 104 | 105 | [[package]] 106 | name = "core-foundation" 107 | version = "0.2.2" 108 | source = "registry+https://github.com/rust-lang/crates.io-index" 109 | dependencies = [ 110 | "core-foundation-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 111 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 112 | ] 113 | 114 | [[package]] 115 | name = "core-foundation-sys" 116 | version = "0.2.2" 117 | source = "registry+https://github.com/rust-lang/crates.io-index" 118 | dependencies = [ 119 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 120 | ] 121 | 122 | [[package]] 123 | name = "core-graphics" 124 | version = "0.3.2" 125 | source = "registry+https://github.com/rust-lang/crates.io-index" 126 | dependencies = [ 127 | "core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 128 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 129 | "serde 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", 130 | ] 131 | 132 | [[package]] 133 | name = "crossbeam" 134 | version = "0.2.9" 135 | source = "registry+https://github.com/rust-lang/crates.io-index" 136 | 137 | [[package]] 138 | name = "current" 139 | version = "0.1.1" 140 | source = "registry+https://github.com/rust-lang/crates.io-index" 141 | 142 | [[package]] 143 | name = "dbghelp-sys" 144 | version = "0.2.0" 145 | source = "registry+https://github.com/rust-lang/crates.io-index" 146 | dependencies = [ 147 | "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 148 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 149 | ] 150 | 151 | [[package]] 152 | name = "debug-builders" 153 | version = "0.1.0" 154 | source = "registry+https://github.com/rust-lang/crates.io-index" 155 | 156 | [[package]] 157 | name = "deque" 158 | version = "0.3.1" 159 | source = "registry+https://github.com/rust-lang/crates.io-index" 160 | dependencies = [ 161 | "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 162 | ] 163 | 164 | [[package]] 165 | name = "dlib" 166 | version = "0.3.0" 167 | source = "registry+https://github.com/rust-lang/crates.io-index" 168 | dependencies = [ 169 | "libloading 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 170 | ] 171 | 172 | [[package]] 173 | name = "dwmapi-sys" 174 | version = "0.1.0" 175 | source = "registry+https://github.com/rust-lang/crates.io-index" 176 | dependencies = [ 177 | "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 178 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 179 | ] 180 | 181 | [[package]] 182 | name = "dyon" 183 | version = "0.7.0" 184 | source = "git+https://github.com/PistonDevelopers/dyon/#e3f17b50f1e6fd76b7ff44d209302143d77ea03d" 185 | dependencies = [ 186 | "hyper 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)", 187 | "piston_meta 0.26.1 (registry+https://github.com/rust-lang/crates.io-index)", 188 | "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 189 | "range 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 190 | "read_color 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 191 | ] 192 | 193 | [[package]] 194 | name = "enum_primitive" 195 | version = "0.1.0" 196 | source = "registry+https://github.com/rust-lang/crates.io-index" 197 | dependencies = [ 198 | "num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 199 | ] 200 | 201 | [[package]] 202 | name = "euclid" 203 | version = "0.6.6" 204 | source = "registry+https://github.com/rust-lang/crates.io-index" 205 | dependencies = [ 206 | "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 207 | "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 208 | "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", 209 | ] 210 | 211 | [[package]] 212 | name = "flate2" 213 | version = "0.2.14" 214 | source = "registry+https://github.com/rust-lang/crates.io-index" 215 | dependencies = [ 216 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 217 | "miniz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 218 | ] 219 | 220 | [[package]] 221 | name = "freetype-rs" 222 | version = "0.8.0" 223 | source = "registry+https://github.com/rust-lang/crates.io-index" 224 | dependencies = [ 225 | "bitflags 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 226 | "freetype-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 227 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 228 | ] 229 | 230 | [[package]] 231 | name = "freetype-sys" 232 | version = "0.3.1" 233 | source = "registry+https://github.com/rust-lang/crates.io-index" 234 | dependencies = [ 235 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 236 | "libz-sys 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 237 | "pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 238 | ] 239 | 240 | [[package]] 241 | name = "fs2" 242 | version = "0.2.4" 243 | source = "registry+https://github.com/rust-lang/crates.io-index" 244 | dependencies = [ 245 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 246 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 247 | "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 248 | ] 249 | 250 | [[package]] 251 | name = "gcc" 252 | version = "0.3.28" 253 | source = "registry+https://github.com/rust-lang/crates.io-index" 254 | 255 | [[package]] 256 | name = "gdi32-sys" 257 | version = "0.1.1" 258 | source = "registry+https://github.com/rust-lang/crates.io-index" 259 | dependencies = [ 260 | "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 261 | ] 262 | 263 | [[package]] 264 | name = "gif" 265 | version = "0.8.0" 266 | source = "registry+https://github.com/rust-lang/crates.io-index" 267 | dependencies = [ 268 | "color_quant 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 269 | "lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 270 | ] 271 | 272 | [[package]] 273 | name = "gl" 274 | version = "0.6.0" 275 | source = "registry+https://github.com/rust-lang/crates.io-index" 276 | dependencies = [ 277 | "gl_generator 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 278 | ] 279 | 280 | [[package]] 281 | name = "gl_generator" 282 | version = "0.5.1" 283 | source = "registry+https://github.com/rust-lang/crates.io-index" 284 | dependencies = [ 285 | "khronos_api 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 286 | "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 287 | "xml-rs 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", 288 | ] 289 | 290 | [[package]] 291 | name = "gleam" 292 | version = "0.2.19" 293 | source = "registry+https://github.com/rust-lang/crates.io-index" 294 | dependencies = [ 295 | "gl_generator 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 296 | ] 297 | 298 | [[package]] 299 | name = "glium" 300 | version = "0.14.0" 301 | source = "registry+https://github.com/rust-lang/crates.io-index" 302 | dependencies = [ 303 | "backtrace 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 304 | "gl_generator 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 305 | "glutin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", 306 | "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", 307 | "smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 308 | ] 309 | 310 | [[package]] 311 | name = "glob" 312 | version = "0.2.11" 313 | source = "registry+https://github.com/rust-lang/crates.io-index" 314 | 315 | [[package]] 316 | name = "glutin" 317 | version = "0.5.2" 318 | source = "registry+https://github.com/rust-lang/crates.io-index" 319 | dependencies = [ 320 | "android_glue 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 321 | "cgl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 322 | "cocoa 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 323 | "core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 324 | "core-graphics 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 325 | "dwmapi-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 326 | "gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 327 | "gl_generator 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 328 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 329 | "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 330 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 331 | "objc 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 332 | "osmesa-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 333 | "shared_library 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 334 | "shell32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 335 | "user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 336 | "wayland-client 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)", 337 | "wayland-kbd 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 338 | "wayland-window 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 339 | "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 340 | "x11-dl 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 341 | ] 342 | 343 | [[package]] 344 | name = "hpack" 345 | version = "0.2.0" 346 | source = "registry+https://github.com/rust-lang/crates.io-index" 347 | dependencies = [ 348 | "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 349 | ] 350 | 351 | [[package]] 352 | name = "httparse" 353 | version = "1.1.2" 354 | source = "registry+https://github.com/rust-lang/crates.io-index" 355 | 356 | [[package]] 357 | name = "hyper" 358 | version = "0.9.7" 359 | source = "registry+https://github.com/rust-lang/crates.io-index" 360 | dependencies = [ 361 | "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", 362 | "httparse 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 363 | "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 364 | "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 365 | "mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 366 | "num_cpus 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 367 | "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", 368 | "solicit 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", 369 | "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", 370 | "traitobject 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 371 | "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 372 | "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 373 | "url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 374 | ] 375 | 376 | [[package]] 377 | name = "idna" 378 | version = "0.1.0" 379 | source = "registry+https://github.com/rust-lang/crates.io-index" 380 | dependencies = [ 381 | "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 382 | "unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 383 | "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 384 | ] 385 | 386 | [[package]] 387 | name = "image" 388 | version = "0.10.0" 389 | source = "registry+https://github.com/rust-lang/crates.io-index" 390 | dependencies = [ 391 | "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", 392 | "enum_primitive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 393 | "gif 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 394 | "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", 395 | "jpeg-decoder 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 396 | "num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 397 | "num-rational 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 398 | "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 399 | "png 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 400 | ] 401 | 402 | [[package]] 403 | name = "inflate" 404 | version = "0.1.1" 405 | source = "registry+https://github.com/rust-lang/crates.io-index" 406 | 407 | [[package]] 408 | name = "interpolation" 409 | version = "0.1.0" 410 | source = "registry+https://github.com/rust-lang/crates.io-index" 411 | 412 | [[package]] 413 | name = "jpeg-decoder" 414 | version = "0.1.4" 415 | source = "registry+https://github.com/rust-lang/crates.io-index" 416 | dependencies = [ 417 | "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", 418 | "euclid 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", 419 | "num-rational 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 420 | "rayon 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 421 | ] 422 | 423 | [[package]] 424 | name = "kernel32-sys" 425 | version = "0.2.2" 426 | source = "registry+https://github.com/rust-lang/crates.io-index" 427 | dependencies = [ 428 | "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 429 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 430 | ] 431 | 432 | [[package]] 433 | name = "khronos_api" 434 | version = "1.0.0" 435 | source = "registry+https://github.com/rust-lang/crates.io-index" 436 | 437 | [[package]] 438 | name = "language-tags" 439 | version = "0.2.2" 440 | source = "registry+https://github.com/rust-lang/crates.io-index" 441 | 442 | [[package]] 443 | name = "lazy_static" 444 | version = "0.1.16" 445 | source = "registry+https://github.com/rust-lang/crates.io-index" 446 | 447 | [[package]] 448 | name = "lazy_static" 449 | version = "0.2.1" 450 | source = "registry+https://github.com/rust-lang/crates.io-index" 451 | 452 | [[package]] 453 | name = "libc" 454 | version = "0.2.12" 455 | source = "registry+https://github.com/rust-lang/crates.io-index" 456 | 457 | [[package]] 458 | name = "libloading" 459 | version = "0.2.2" 460 | source = "registry+https://github.com/rust-lang/crates.io-index" 461 | dependencies = [ 462 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 463 | "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 464 | "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 465 | ] 466 | 467 | [[package]] 468 | name = "libz-sys" 469 | version = "1.0.4" 470 | source = "registry+https://github.com/rust-lang/crates.io-index" 471 | dependencies = [ 472 | "gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", 473 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 474 | "pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 475 | ] 476 | 477 | [[package]] 478 | name = "log" 479 | version = "0.3.6" 480 | source = "registry+https://github.com/rust-lang/crates.io-index" 481 | 482 | [[package]] 483 | name = "lzw" 484 | version = "0.10.0" 485 | source = "registry+https://github.com/rust-lang/crates.io-index" 486 | 487 | [[package]] 488 | name = "malloc_buf" 489 | version = "0.0.6" 490 | source = "registry+https://github.com/rust-lang/crates.io-index" 491 | dependencies = [ 492 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 493 | ] 494 | 495 | [[package]] 496 | name = "matches" 497 | version = "0.1.2" 498 | source = "registry+https://github.com/rust-lang/crates.io-index" 499 | 500 | [[package]] 501 | name = "memmap" 502 | version = "0.2.3" 503 | source = "registry+https://github.com/rust-lang/crates.io-index" 504 | dependencies = [ 505 | "fs2 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", 506 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 507 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 508 | "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 509 | ] 510 | 511 | [[package]] 512 | name = "mime" 513 | version = "0.2.0" 514 | source = "registry+https://github.com/rust-lang/crates.io-index" 515 | dependencies = [ 516 | "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 517 | ] 518 | 519 | [[package]] 520 | name = "miniz-sys" 521 | version = "0.1.7" 522 | source = "registry+https://github.com/rust-lang/crates.io-index" 523 | dependencies = [ 524 | "gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", 525 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 526 | ] 527 | 528 | [[package]] 529 | name = "num" 530 | version = "0.1.32" 531 | source = "registry+https://github.com/rust-lang/crates.io-index" 532 | dependencies = [ 533 | "num-bigint 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 534 | "num-complex 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 535 | "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 536 | "num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 537 | "num-rational 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 538 | "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 539 | ] 540 | 541 | [[package]] 542 | name = "num-bigint" 543 | version = "0.1.32" 544 | source = "registry+https://github.com/rust-lang/crates.io-index" 545 | dependencies = [ 546 | "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 547 | "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 548 | "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 549 | "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", 550 | ] 551 | 552 | [[package]] 553 | name = "num-complex" 554 | version = "0.1.32" 555 | source = "registry+https://github.com/rust-lang/crates.io-index" 556 | dependencies = [ 557 | "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 558 | "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", 559 | ] 560 | 561 | [[package]] 562 | name = "num-integer" 563 | version = "0.1.32" 564 | source = "registry+https://github.com/rust-lang/crates.io-index" 565 | dependencies = [ 566 | "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 567 | ] 568 | 569 | [[package]] 570 | name = "num-iter" 571 | version = "0.1.32" 572 | source = "registry+https://github.com/rust-lang/crates.io-index" 573 | dependencies = [ 574 | "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 575 | "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 576 | ] 577 | 578 | [[package]] 579 | name = "num-rational" 580 | version = "0.1.32" 581 | source = "registry+https://github.com/rust-lang/crates.io-index" 582 | dependencies = [ 583 | "num-bigint 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 584 | "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 585 | "num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 586 | "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", 587 | ] 588 | 589 | [[package]] 590 | name = "num-traits" 591 | version = "0.1.32" 592 | source = "registry+https://github.com/rust-lang/crates.io-index" 593 | 594 | [[package]] 595 | name = "num_cpus" 596 | version = "0.2.12" 597 | source = "registry+https://github.com/rust-lang/crates.io-index" 598 | dependencies = [ 599 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 600 | ] 601 | 602 | [[package]] 603 | name = "objc" 604 | version = "0.2.1" 605 | source = "registry+https://github.com/rust-lang/crates.io-index" 606 | dependencies = [ 607 | "malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 608 | ] 609 | 610 | [[package]] 611 | name = "osmesa-sys" 612 | version = "0.1.0" 613 | source = "registry+https://github.com/rust-lang/crates.io-index" 614 | dependencies = [ 615 | "shared_library 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 616 | ] 617 | 618 | [[package]] 619 | name = "piston" 620 | version = "0.22.1" 621 | source = "registry+https://github.com/rust-lang/crates.io-index" 622 | dependencies = [ 623 | "pistoncore-event_loop 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)", 624 | "pistoncore-input 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", 625 | "pistoncore-window 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", 626 | ] 627 | 628 | [[package]] 629 | name = "piston-dyon_interactive" 630 | version = "0.1.0" 631 | source = "git+https://github.com/PistonDevelopers/dyon/#e3f17b50f1e6fd76b7ff44d209302143d77ea03d" 632 | dependencies = [ 633 | "current 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 634 | "dyon 0.7.0 (git+https://github.com/PistonDevelopers/dyon/)", 635 | "piston 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)", 636 | "piston2d-graphics 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", 637 | ] 638 | 639 | [[package]] 640 | name = "piston-float" 641 | version = "0.2.0" 642 | source = "registry+https://github.com/rust-lang/crates.io-index" 643 | 644 | [[package]] 645 | name = "piston-shaders_graphics2d" 646 | version = "0.1.0" 647 | source = "registry+https://github.com/rust-lang/crates.io-index" 648 | 649 | [[package]] 650 | name = "piston-texture" 651 | version = "0.4.0" 652 | source = "registry+https://github.com/rust-lang/crates.io-index" 653 | 654 | [[package]] 655 | name = "piston-viewport" 656 | version = "0.2.0" 657 | source = "registry+https://github.com/rust-lang/crates.io-index" 658 | dependencies = [ 659 | "piston-float 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 660 | ] 661 | 662 | [[package]] 663 | name = "piston2d-glium_graphics" 664 | version = "0.25.0" 665 | source = "registry+https://github.com/rust-lang/crates.io-index" 666 | dependencies = [ 667 | "freetype-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 668 | "glium 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", 669 | "image 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 670 | "piston 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)", 671 | "piston-shaders_graphics2d 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 672 | "piston-texture 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 673 | "piston2d-graphics 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", 674 | "pistoncore-glutin_window 0.26.1 (registry+https://github.com/rust-lang/crates.io-index)", 675 | "shader_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 676 | ] 677 | 678 | [[package]] 679 | name = "piston2d-graphics" 680 | version = "0.16.0" 681 | source = "registry+https://github.com/rust-lang/crates.io-index" 682 | dependencies = [ 683 | "interpolation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 684 | "piston-texture 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 685 | "piston-viewport 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 686 | "read_color 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 687 | "vecmath 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 688 | ] 689 | 690 | [[package]] 691 | name = "piston_meta" 692 | version = "0.26.1" 693 | source = "registry+https://github.com/rust-lang/crates.io-index" 694 | dependencies = [ 695 | "range 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 696 | "read_token 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", 697 | ] 698 | 699 | [[package]] 700 | name = "pistoncore-event_loop" 701 | version = "0.22.1" 702 | source = "registry+https://github.com/rust-lang/crates.io-index" 703 | dependencies = [ 704 | "piston-viewport 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 705 | "pistoncore-input 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", 706 | "pistoncore-window 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", 707 | "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", 708 | ] 709 | 710 | [[package]] 711 | name = "pistoncore-glutin_window" 712 | version = "0.26.1" 713 | source = "registry+https://github.com/rust-lang/crates.io-index" 714 | dependencies = [ 715 | "gl 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 716 | "glutin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", 717 | "pistoncore-input 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", 718 | "pistoncore-window 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", 719 | "shader_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 720 | ] 721 | 722 | [[package]] 723 | name = "pistoncore-input" 724 | version = "0.12.0" 725 | source = "registry+https://github.com/rust-lang/crates.io-index" 726 | dependencies = [ 727 | "bitflags 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 728 | "piston-viewport 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 729 | "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", 730 | ] 731 | 732 | [[package]] 733 | name = "pistoncore-sdl2_window" 734 | version = "0.30.2" 735 | source = "registry+https://github.com/rust-lang/crates.io-index" 736 | dependencies = [ 737 | "gl 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 738 | "pistoncore-input 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", 739 | "pistoncore-window 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", 740 | "sdl2 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", 741 | "shader_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 742 | ] 743 | 744 | [[package]] 745 | name = "pistoncore-window" 746 | version = "0.19.0" 747 | source = "registry+https://github.com/rust-lang/crates.io-index" 748 | dependencies = [ 749 | "pistoncore-input 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", 750 | "shader_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 751 | ] 752 | 753 | [[package]] 754 | name = "pkg-config" 755 | version = "0.3.8" 756 | source = "registry+https://github.com/rust-lang/crates.io-index" 757 | 758 | [[package]] 759 | name = "png" 760 | version = "0.5.1" 761 | source = "registry+https://github.com/rust-lang/crates.io-index" 762 | dependencies = [ 763 | "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 764 | "flate2 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", 765 | "inflate 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 766 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 767 | "num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 768 | ] 769 | 770 | [[package]] 771 | name = "rand" 772 | version = "0.3.14" 773 | source = "registry+https://github.com/rust-lang/crates.io-index" 774 | dependencies = [ 775 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 776 | ] 777 | 778 | [[package]] 779 | name = "range" 780 | version = "0.3.1" 781 | source = "registry+https://github.com/rust-lang/crates.io-index" 782 | 783 | [[package]] 784 | name = "rayon" 785 | version = "0.3.1" 786 | source = "registry+https://github.com/rust-lang/crates.io-index" 787 | dependencies = [ 788 | "deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 789 | "num_cpus 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 790 | "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 791 | ] 792 | 793 | [[package]] 794 | name = "read_color" 795 | version = "0.1.0" 796 | source = "registry+https://github.com/rust-lang/crates.io-index" 797 | 798 | [[package]] 799 | name = "read_token" 800 | version = "0.6.1" 801 | source = "registry+https://github.com/rust-lang/crates.io-index" 802 | dependencies = [ 803 | "range 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 804 | ] 805 | 806 | [[package]] 807 | name = "rustc-serialize" 808 | version = "0.3.19" 809 | source = "registry+https://github.com/rust-lang/crates.io-index" 810 | 811 | [[package]] 812 | name = "rustc_version" 813 | version = "0.1.7" 814 | source = "registry+https://github.com/rust-lang/crates.io-index" 815 | dependencies = [ 816 | "semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", 817 | ] 818 | 819 | [[package]] 820 | name = "sdl2" 821 | version = "0.19.0" 822 | source = "registry+https://github.com/rust-lang/crates.io-index" 823 | dependencies = [ 824 | "bitflags 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 825 | "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 826 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 827 | "num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 828 | "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 829 | "sdl2-sys 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", 830 | ] 831 | 832 | [[package]] 833 | name = "sdl2-sys" 834 | version = "0.19.0" 835 | source = "registry+https://github.com/rust-lang/crates.io-index" 836 | dependencies = [ 837 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 838 | ] 839 | 840 | [[package]] 841 | name = "sdl2_mixer" 842 | version = "0.18.0" 843 | source = "registry+https://github.com/rust-lang/crates.io-index" 844 | dependencies = [ 845 | "bitflags 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 846 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 847 | "sdl2 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", 848 | "sdl2-sys 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", 849 | ] 850 | 851 | [[package]] 852 | name = "semver" 853 | version = "0.1.20" 854 | source = "registry+https://github.com/rust-lang/crates.io-index" 855 | 856 | [[package]] 857 | name = "serde" 858 | version = "0.7.9" 859 | source = "registry+https://github.com/rust-lang/crates.io-index" 860 | 861 | [[package]] 862 | name = "shader_version" 863 | version = "0.2.1" 864 | source = "registry+https://github.com/rust-lang/crates.io-index" 865 | 866 | [[package]] 867 | name = "shared_library" 868 | version = "0.1.4" 869 | source = "registry+https://github.com/rust-lang/crates.io-index" 870 | dependencies = [ 871 | "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", 872 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 873 | ] 874 | 875 | [[package]] 876 | name = "shell32-sys" 877 | version = "0.1.1" 878 | source = "registry+https://github.com/rust-lang/crates.io-index" 879 | dependencies = [ 880 | "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 881 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 882 | ] 883 | 884 | [[package]] 885 | name = "smallvec" 886 | version = "0.1.7" 887 | source = "registry+https://github.com/rust-lang/crates.io-index" 888 | 889 | [[package]] 890 | name = "solicit" 891 | version = "0.4.4" 892 | source = "registry+https://github.com/rust-lang/crates.io-index" 893 | dependencies = [ 894 | "hpack 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 895 | "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 896 | ] 897 | 898 | [[package]] 899 | name = "tempfile" 900 | version = "2.1.3" 901 | source = "registry+https://github.com/rust-lang/crates.io-index" 902 | dependencies = [ 903 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 904 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 905 | "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", 906 | "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 907 | "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 908 | ] 909 | 910 | [[package]] 911 | name = "time" 912 | version = "0.1.35" 913 | source = "registry+https://github.com/rust-lang/crates.io-index" 914 | dependencies = [ 915 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 916 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 917 | "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 918 | ] 919 | 920 | [[package]] 921 | name = "traitobject" 922 | version = "0.0.1" 923 | source = "registry+https://github.com/rust-lang/crates.io-index" 924 | 925 | [[package]] 926 | name = "typeable" 927 | version = "0.1.2" 928 | source = "registry+https://github.com/rust-lang/crates.io-index" 929 | 930 | [[package]] 931 | name = "unicase" 932 | version = "1.4.0" 933 | source = "registry+https://github.com/rust-lang/crates.io-index" 934 | dependencies = [ 935 | "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 936 | ] 937 | 938 | [[package]] 939 | name = "unicode-bidi" 940 | version = "0.2.3" 941 | source = "registry+https://github.com/rust-lang/crates.io-index" 942 | dependencies = [ 943 | "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 944 | ] 945 | 946 | [[package]] 947 | name = "unicode-normalization" 948 | version = "0.1.2" 949 | source = "registry+https://github.com/rust-lang/crates.io-index" 950 | 951 | [[package]] 952 | name = "url" 953 | version = "1.1.1" 954 | source = "registry+https://github.com/rust-lang/crates.io-index" 955 | dependencies = [ 956 | "idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 957 | "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 958 | ] 959 | 960 | [[package]] 961 | name = "user32-sys" 962 | version = "0.1.2" 963 | source = "registry+https://github.com/rust-lang/crates.io-index" 964 | dependencies = [ 965 | "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 966 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 967 | ] 968 | 969 | [[package]] 970 | name = "vecmath" 971 | version = "0.2.0" 972 | source = "registry+https://github.com/rust-lang/crates.io-index" 973 | dependencies = [ 974 | "piston-float 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 975 | ] 976 | 977 | [[package]] 978 | name = "wavefront_obj" 979 | version = "3.0.0" 980 | source = "registry+https://github.com/rust-lang/crates.io-index" 981 | 982 | [[package]] 983 | name = "wayland-client" 984 | version = "0.5.12" 985 | source = "registry+https://github.com/rust-lang/crates.io-index" 986 | dependencies = [ 987 | "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 988 | "crossbeam 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", 989 | "dlib 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 990 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 991 | "wayland-scanner 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)", 992 | "wayland-sys 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)", 993 | ] 994 | 995 | [[package]] 996 | name = "wayland-kbd" 997 | version = "0.3.6" 998 | source = "registry+https://github.com/rust-lang/crates.io-index" 999 | dependencies = [ 1000 | "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 1001 | "dlib 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 1002 | "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", 1003 | "memmap 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 1004 | "wayland-client 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)", 1005 | ] 1006 | 1007 | [[package]] 1008 | name = "wayland-scanner" 1009 | version = "0.5.11" 1010 | source = "registry+https://github.com/rust-lang/crates.io-index" 1011 | dependencies = [ 1012 | "xml-rs 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", 1013 | ] 1014 | 1015 | [[package]] 1016 | name = "wayland-sys" 1017 | version = "0.5.11" 1018 | source = "registry+https://github.com/rust-lang/crates.io-index" 1019 | dependencies = [ 1020 | "dlib 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 1021 | "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", 1022 | ] 1023 | 1024 | [[package]] 1025 | name = "wayland-window" 1026 | version = "0.2.3" 1027 | source = "registry+https://github.com/rust-lang/crates.io-index" 1028 | dependencies = [ 1029 | "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", 1030 | "tempfile 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 1031 | "wayland-client 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)", 1032 | ] 1033 | 1034 | [[package]] 1035 | name = "winapi" 1036 | version = "0.2.7" 1037 | source = "registry+https://github.com/rust-lang/crates.io-index" 1038 | 1039 | [[package]] 1040 | name = "winapi-build" 1041 | version = "0.1.1" 1042 | source = "registry+https://github.com/rust-lang/crates.io-index" 1043 | 1044 | [[package]] 1045 | name = "x11-dl" 1046 | version = "2.6.0" 1047 | source = "registry+https://github.com/rust-lang/crates.io-index" 1048 | dependencies = [ 1049 | "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 1050 | "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", 1051 | ] 1052 | 1053 | [[package]] 1054 | name = "xml-rs" 1055 | version = "0.3.4" 1056 | source = "registry+https://github.com/rust-lang/crates.io-index" 1057 | dependencies = [ 1058 | "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 1059 | ] 1060 | 1061 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dyon_asteroids" 3 | version = "0.1.0" 4 | authors = ["Sven Nilsen "] 5 | exclude = ["/images/"] 6 | 7 | [dependencies.piston-dyon_interactive] 8 | git = "https://github.com/PistonDevelopers/dyon/" 9 | # path = "../dyon/interactive" 10 | 11 | [dependencies.dyon] 12 | git = "https://github.com/PistonDevelopers/dyon/" 13 | # path = "../dyon" 14 | 15 | [dependencies] 16 | piston2d-glium_graphics = "0.25.0" 17 | glium = "0.14.0" 18 | piston = "0.22.0" 19 | current = "0.1.1" 20 | pistoncore-sdl2_window = "0.30.0" 21 | sdl2_mixer = "0.18.0" 22 | sdl2 = "0.19.0" 23 | wavefront_obj = "3.0.0" 24 | vecmath = "0.2.0" 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 PistonDevelopers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dyon_asteroids 2 | A demo game project for Dyon/Piston/Glium to test Dyon and research design for dyon_interactive 3 | 4 | Current screenshot (work in progress): 5 | 6 | ![screenshot](./images/screenshot.png) 7 | 8 | ### How to install and run 9 | 10 | The demo game is in early development stage and Dyon has not yet added a feature for shipping binaries. 11 | This means you need to compile the engine and run it from source: 12 | 13 | 1. Install [Rust](https://www.rust-lang.org/) 14 | 1. Fork the repo 15 | 2. Open up the Terminal window and go the project directory 16 | 3. Type `cargo run --release` 17 | -------------------------------------------------------------------------------- /assets/music/space-of-atmos.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/music/space-of-atmos.mp3 -------------------------------------------------------------------------------- /assets/music/space-of-atmos.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/music/space-of-atmos.wav -------------------------------------------------------------------------------- /assets/music/space-of-jazz.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/music/space-of-jazz.mp3 -------------------------------------------------------------------------------- /assets/music/space-of-jazz.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/music/space-of-jazz.wav -------------------------------------------------------------------------------- /assets/music/space-of-silence.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/music/space-of-silence.mp3 -------------------------------------------------------------------------------- /assets/music/space-of-silence.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/music/space-of-silence.wav -------------------------------------------------------------------------------- /assets/shaders/150_core.glslf: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | out vec4 o_Color; 4 | 5 | uniform vec4 color; 6 | 7 | void main() { 8 | o_Color = color; 9 | } 10 | -------------------------------------------------------------------------------- /assets/shaders/150_core.glslv: -------------------------------------------------------------------------------- 1 | #version 150 core 2 | 3 | in vec3 pos; 4 | in vec3 norm; 5 | 6 | uniform mat4 mvp; 7 | 8 | void main() { 9 | gl_Position = mvp * vec4(pos, 1.0); 10 | } 11 | -------------------------------------------------------------------------------- /assets/sounds/explosion-guitar.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/explosion-guitar.mp3 -------------------------------------------------------------------------------- /assets/sounds/explosion-guitar.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/explosion-guitar.wav -------------------------------------------------------------------------------- /assets/sounds/explosion.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/explosion.wav -------------------------------------------------------------------------------- /assets/sounds/explosion2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/explosion2.wav -------------------------------------------------------------------------------- /assets/sounds/explosion3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/explosion3.wav -------------------------------------------------------------------------------- /assets/sounds/laser-guitar-2.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-guitar-2.mp3 -------------------------------------------------------------------------------- /assets/sounds/laser-guitar-2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-guitar-2.wav -------------------------------------------------------------------------------- /assets/sounds/laser-guitar-3.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-guitar-3.mp3 -------------------------------------------------------------------------------- /assets/sounds/laser-guitar-3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-guitar-3.wav -------------------------------------------------------------------------------- /assets/sounds/laser-guitar-4.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-guitar-4.mp3 -------------------------------------------------------------------------------- /assets/sounds/laser-guitar-4.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-guitar-4.wav -------------------------------------------------------------------------------- /assets/sounds/laser-guitar-5.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-guitar-5.mp3 -------------------------------------------------------------------------------- /assets/sounds/laser-guitar-5.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-guitar-5.wav -------------------------------------------------------------------------------- /assets/sounds/laser-guitar-6.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-guitar-6.mp3 -------------------------------------------------------------------------------- /assets/sounds/laser-guitar-6.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-guitar-6.wav -------------------------------------------------------------------------------- /assets/sounds/laser-guitar-7.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-guitar-7.mp3 -------------------------------------------------------------------------------- /assets/sounds/laser-guitar-7.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-guitar-7.wav -------------------------------------------------------------------------------- /assets/sounds/laser-guitar.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-guitar.mp3 -------------------------------------------------------------------------------- /assets/sounds/laser-guitar.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-guitar.wav -------------------------------------------------------------------------------- /assets/sounds/laser-pulse-2.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-pulse-2.mp3 -------------------------------------------------------------------------------- /assets/sounds/laser-pulse-2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-pulse-2.wav -------------------------------------------------------------------------------- /assets/sounds/laser-pulse-3.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-pulse-3.mp3 -------------------------------------------------------------------------------- /assets/sounds/laser-pulse-3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-pulse-3.wav -------------------------------------------------------------------------------- /assets/sounds/laser-pulse-4.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-pulse-4.mp3 -------------------------------------------------------------------------------- /assets/sounds/laser-pulse-4.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-pulse-4.wav -------------------------------------------------------------------------------- /assets/sounds/laser-pulse-5.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-pulse-5.mp3 -------------------------------------------------------------------------------- /assets/sounds/laser-pulse-5.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-pulse-5.wav -------------------------------------------------------------------------------- /assets/sounds/laser-pulse-6.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-pulse-6.mp3 -------------------------------------------------------------------------------- /assets/sounds/laser-pulse-6.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-pulse-6.wav -------------------------------------------------------------------------------- /assets/sounds/laser-pulse-7.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-pulse-7.mp3 -------------------------------------------------------------------------------- /assets/sounds/laser-pulse-7.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-pulse-7.wav -------------------------------------------------------------------------------- /assets/sounds/laser-pulse.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-pulse.mp3 -------------------------------------------------------------------------------- /assets/sounds/laser-pulse.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser-pulse.wav -------------------------------------------------------------------------------- /assets/sounds/laser.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser.wav -------------------------------------------------------------------------------- /assets/sounds/laser2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser2.wav -------------------------------------------------------------------------------- /assets/sounds/laser3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/sounds/laser3.wav -------------------------------------------------------------------------------- /assets/spaceship.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/assets/spaceship.blend -------------------------------------------------------------------------------- /assets/spaceship.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'spaceship.blend' 2 | # Material Count: 2 3 | 4 | newmtl glass 5 | Ns 96.078431 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.052386 0.031654 0.088551 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.000000 11 | d 1.000000 12 | illum 2 13 | 14 | newmtl metal 15 | Ns 96.078431 16 | Ka 1.000000 1.000000 1.000000 17 | Kd 0.439131 0.640000 0.258569 18 | Ks 0.500000 0.500000 0.500000 19 | Ke 0.000000 0.000000 0.000000 20 | Ni 1.000000 21 | d 1.000000 22 | illum 2 23 | -------------------------------------------------------------------------------- /assets/spaceship.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.77 (sub 0) OBJ File: 'spaceship.blend' 2 | # www.blender.org 3 | mtllib spaceship.mtl 4 | o Cube.009 5 | v 0.500000 1.000000 -1.000000 6 | v 0.500000 1.000000 1.000000 7 | v -1.500000 1.000000 1.000000 8 | v -1.500000 1.000000 -1.000000 9 | v 0.500000 2.000000 -0.999999 10 | v 0.499999 2.000000 1.000001 11 | v -1.500000 2.000000 1.000000 12 | v -1.500000 2.000000 -1.000000 13 | vn 0.0000 -1.0000 -0.0000 14 | vn 0.0000 1.0000 -0.0000 15 | vn 1.0000 0.0000 0.0000 16 | vn -0.0000 -0.0000 1.0000 17 | vn -1.0000 -0.0000 -0.0000 18 | vn 0.0000 0.0000 -1.0000 19 | usemtl glass 20 | s off 21 | f 1//1 2//1 3//1 4//1 22 | f 5//2 8//2 7//2 6//2 23 | f 1//3 5//3 6//3 2//3 24 | f 2//4 6//4 7//4 3//4 25 | f 3//5 7//5 8//5 4//5 26 | f 5//6 1//6 4//6 8//6 27 | o Cube.008 28 | v 2.500000 1.000000 -1.000000 29 | v 2.500000 1.000000 1.000000 30 | v 0.500000 1.000000 1.000000 31 | v 0.500000 1.000000 -1.000000 32 | v 2.500000 1.000000 -0.999999 33 | v 2.499999 1.000000 1.000001 34 | v 0.500000 2.000000 1.000000 35 | v 0.500000 2.000000 -1.000000 36 | vn 0.0000 -1.0000 -0.0000 37 | vn 0.4472 0.8944 0.0000 38 | vn 0.0000 1.0000 0.0000 39 | vn -0.0000 -0.0000 1.0000 40 | vn -1.0000 -0.0000 -0.0000 41 | vn 0.0000 0.0000 -1.0000 42 | usemtl glass 43 | s off 44 | f 9//7 10//7 11//7 12//7 45 | f 13//8 16//8 15//8 14//8 46 | f 9//9 13//9 14//9 10//9 47 | f 10//10 14//10 15//10 11//10 48 | f 11//11 15//11 16//11 12//11 49 | f 13//12 9//12 12//12 16//12 50 | o Cube.007 51 | v -1.500000 0.000000 -1.000000 52 | v -1.500000 0.000000 1.000000 53 | v -3.500000 0.000000 1.000000 54 | v -3.500000 0.000000 -1.000000 55 | v -1.500000 1.000000 -0.999999 56 | v -1.500001 1.000000 1.000001 57 | v -3.500000 1.000000 1.000000 58 | v -3.500000 1.000000 -1.000000 59 | vn 0.0000 -1.0000 0.0000 60 | vn 0.0000 1.0000 0.0000 61 | vn 1.0000 0.0000 0.0000 62 | vn -0.0000 -0.0000 1.0000 63 | vn -1.0000 -0.0000 -0.0000 64 | vn 0.0000 0.0000 -1.0000 65 | usemtl metal 66 | s off 67 | f 17//13 18//13 19//13 20//13 68 | f 21//14 24//14 23//14 22//14 69 | f 17//15 21//15 22//15 18//15 70 | f 18//16 22//16 23//16 19//16 71 | f 19//17 23//17 24//17 20//17 72 | f 21//18 17//18 20//18 24//18 73 | o Cube.006 74 | v 0.500000 0.000000 -1.000000 75 | v 0.500000 0.000000 1.000000 76 | v -1.500000 0.000000 1.000000 77 | v -1.500000 0.000000 -1.000000 78 | v 0.500000 1.000000 -0.999999 79 | v 0.499999 1.000000 1.000001 80 | v -1.500000 1.000000 1.000000 81 | v -1.500000 1.000000 -1.000000 82 | vn 0.0000 -1.0000 0.0000 83 | vn 0.0000 1.0000 -0.0000 84 | vn 1.0000 0.0000 0.0000 85 | vn -0.0000 -0.0000 1.0000 86 | vn -1.0000 -0.0000 -0.0000 87 | vn 0.0000 0.0000 -1.0000 88 | usemtl metal 89 | s off 90 | f 25//19 26//19 27//19 28//19 91 | f 29//20 32//20 31//20 30//20 92 | f 25//21 29//21 30//21 26//21 93 | f 26//22 30//22 31//22 27//22 94 | f 27//23 31//23 32//23 28//23 95 | f 29//24 25//24 28//24 32//24 96 | o Cube.005 97 | v 0.500000 0.000000 -3.000000 98 | v 0.500000 0.000000 -1.000000 99 | v -1.500000 0.000000 -1.000000 100 | v -1.500000 0.000000 -4.000000 101 | v 0.500000 1.000000 -3.000000 102 | v 0.499999 1.000000 -0.999999 103 | v -1.500000 1.000000 -1.000000 104 | v -1.500000 1.000000 -4.000000 105 | vn 0.0000 -1.0000 0.0000 106 | vn 0.0000 1.0000 -0.0000 107 | vn 1.0000 0.0000 0.0000 108 | vn -0.0000 -0.0000 1.0000 109 | vn -1.0000 -0.0000 -0.0000 110 | vn 0.4472 0.0000 -0.8944 111 | usemtl metal 112 | s off 113 | f 33//25 34//25 35//25 36//25 114 | f 37//26 40//26 39//26 38//26 115 | f 33//27 37//27 38//27 34//27 116 | f 34//28 38//28 39//28 35//28 117 | f 35//29 39//29 40//29 36//29 118 | f 37//30 33//30 36//30 40//30 119 | o Cube.004 120 | v 0.500000 0.000000 1.000000 121 | v 0.500000 0.000000 3.000000 122 | v -1.500000 0.000000 4.000000 123 | v -1.500000 0.000000 1.000000 124 | v 0.500000 1.000000 1.000000 125 | v 0.499999 1.000000 3.000000 126 | v -1.500000 1.000000 4.000000 127 | v -1.500000 1.000000 1.000000 128 | vn 0.0000 -1.0000 0.0000 129 | vn 0.0000 1.0000 -0.0000 130 | vn 1.0000 0.0000 0.0000 131 | vn 0.4472 0.0000 0.8944 132 | vn -1.0000 -0.0000 -0.0000 133 | vn 0.0000 0.0000 -1.0000 134 | usemtl metal 135 | s off 136 | f 41//31 42//31 43//31 44//31 137 | f 45//32 48//32 47//32 46//32 138 | f 41//33 45//33 46//33 42//33 139 | f 42//34 46//34 47//34 43//34 140 | f 43//35 47//35 48//35 44//35 141 | f 45//36 41//36 44//36 48//36 142 | o Cube.003 143 | v 2.500000 0.000000 1.000000 144 | v 2.500000 0.000000 2.500000 145 | v 0.500000 0.000000 3.000000 146 | v 0.500000 0.000000 1.000000 147 | v 2.500000 1.000000 1.000000 148 | v 2.499999 1.000000 2.500000 149 | v 0.500000 1.000000 3.000000 150 | v 0.500000 1.000000 1.000000 151 | vn 0.0000 -1.0000 0.0000 152 | vn 0.0000 1.0000 0.0000 153 | vn 1.0000 -0.0000 0.0000 154 | vn 0.2425 0.0000 0.9701 155 | vn -1.0000 -0.0000 -0.0000 156 | vn 0.0000 0.0000 -1.0000 157 | usemtl metal 158 | s off 159 | f 49//37 50//37 51//37 52//37 160 | f 53//38 56//38 55//38 54//38 161 | f 49//39 53//39 54//39 50//39 162 | f 50//40 54//40 55//40 51//40 163 | f 51//41 55//41 56//41 52//41 164 | f 53//42 49//42 52//42 56//42 165 | o Cube.002 166 | v 2.500000 0.000000 -2.500000 167 | v 2.500000 0.000000 -1.000000 168 | v 0.500000 0.000000 -1.000000 169 | v 0.500000 0.000000 -3.000000 170 | v 2.500000 1.000000 -2.500000 171 | v 2.499999 1.000000 -0.999999 172 | v 0.500000 1.000000 -1.000000 173 | v 0.500000 1.000000 -3.000000 174 | vn 0.0000 -1.0000 0.0000 175 | vn 0.0000 1.0000 0.0000 176 | vn 1.0000 0.0000 0.0000 177 | vn -0.0000 -0.0000 1.0000 178 | vn -1.0000 -0.0000 -0.0000 179 | vn 0.2425 0.0000 -0.9701 180 | usemtl metal 181 | s off 182 | f 57//43 58//43 59//43 60//43 183 | f 61//44 64//44 63//44 62//44 184 | f 57//45 61//45 62//45 58//45 185 | f 58//46 62//46 63//46 59//46 186 | f 59//47 63//47 64//47 60//47 187 | f 61//48 57//48 60//48 64//48 188 | o Cube.001 189 | v 4.500000 0.000000 -0.500000 190 | v 4.500000 0.000000 0.500000 191 | v 2.500000 0.000000 1.000000 192 | v 2.500000 0.000000 -1.000000 193 | v 4.500000 1.000000 -0.500000 194 | v 4.500000 1.000000 0.500000 195 | v 2.500000 1.000000 1.000000 196 | v 2.500000 1.000000 -1.000000 197 | vn 0.0000 -1.0000 0.0000 198 | vn 0.0000 1.0000 0.0000 199 | vn 1.0000 -0.0000 0.0000 200 | vn 0.2425 0.0000 0.9701 201 | vn -1.0000 -0.0000 -0.0000 202 | vn 0.2425 0.0000 -0.9701 203 | usemtl metal 204 | s off 205 | f 65//49 66//49 67//49 68//49 206 | f 69//50 72//50 71//50 70//50 207 | f 65//51 69//51 70//51 66//51 208 | f 66//52 70//52 71//52 67//52 209 | f 67//53 71//53 72//53 68//53 210 | f 69//54 65//54 68//54 72//54 211 | o Cube 212 | v 2.500000 0.000000 -1.000000 213 | v 2.500000 0.000000 1.000000 214 | v 0.500000 0.000000 1.000000 215 | v 0.500000 0.000000 -1.000000 216 | v 2.500000 1.000000 -0.999999 217 | v 2.499999 1.000000 1.000001 218 | v 0.500000 1.000000 1.000000 219 | v 0.500000 1.000000 -1.000000 220 | vn 0.0000 -1.0000 0.0000 221 | vn 0.0000 1.0000 0.0000 222 | vn 1.0000 0.0000 0.0000 223 | vn -0.0000 -0.0000 1.0000 224 | vn -1.0000 -0.0000 -0.0000 225 | vn 0.0000 0.0000 -1.0000 226 | usemtl metal 227 | s off 228 | f 73//55 74//55 75//55 76//55 229 | f 77//56 80//56 79//56 78//56 230 | f 73//57 77//57 78//57 74//57 231 | f 74//58 78//58 79//58 75//58 232 | f 75//59 79//59 80//59 76//59 233 | f 77//60 73//60 76//60 80//60 234 | -------------------------------------------------------------------------------- /images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/dyon_asteroids/51f944cac511e26b4d772c57e1ea245ffab280a1/images/screenshot.png -------------------------------------------------------------------------------- /src/assets.dyon: -------------------------------------------------------------------------------- 1 | sound_laser_offset() = 0 2 | sound_laser_count() = 3 3 | sound_explosion_offset() = sound_laser_offset() + sound_laser_count() 4 | sound_explosion_count() = 4 5 | 6 | fn load_assets() -> res { 7 | 8 | spaceship_material := load(material: "assets/spaceship.mtl")? 9 | spaceship_material_index := material(spaceship_material)? 10 | println("MATERIALS") 11 | print(link { 12 | "name: "spaceship_material"\n" 13 | "index: "spaceship_material_index"\n" 14 | }) 15 | materials := materials() 16 | println(materials) 17 | 18 | println("\nOBJs") 19 | spaceship_obj := load(obj: "assets/spaceship.obj")? 20 | println(info(obj: spaceship_obj, short: true)?) 21 | objs := objs() 22 | println(objs) 23 | 24 | println("\nPREPARE") 25 | 26 | materials := ["metal", "glass"] 27 | for i { 28 | mat := prepare(obj: 0, material: materials[i]) 29 | println(len(mat.vertices)) 30 | println(len(mat.normals)) 31 | println(len(mat.indices)) 32 | 33 | vertex_buffer := create_vertex_buffer(size: len(mat.vertices))? 34 | fill_vertex_buffer(buffer: vertex_buffer, pos: mat.vertices, norm: mat.normals) 35 | index_buffer := create_index_buffer(size: len(mat.indices))? 36 | fill_index_buffer(buffer: index_buffer, data: mat.indices) 37 | } 38 | 39 | /* TEST triangle 40 | vb := create_vertex_buffer(size: 3)? 41 | fill_vertex_buffer(buffer: vb, pos: [ 42 | (0, -0.5), (0, 0.5), (0.5, -0.5) 43 | ], norm: [(0, 0, 1); 3]) 44 | ib := create_index_buffer(size: 3)? 45 | fill_index_buffer(buffer: ib, data: [0, 1, 2]) 46 | */ 47 | 48 | println(count_vertex_buffers()) 49 | println(count_index_buffers()) 50 | 51 | println("\nPROGRAMS") 52 | vshader := load_string(file: "assets/shaders/150_core.glslv")? 53 | fshader := load_string(file: "assets/shaders/150_core.glslf")? 54 | default := load_program( 55 | name: "default", 56 | vshader: vshader, 57 | fshader: fshader 58 | )? 59 | println(default) 60 | default_index := program(default)? 61 | println(default_index) 62 | 63 | println("\nMUSIC") 64 | music := load(music: "assets/music/space-of-atmos.wav")? 65 | println(music) 66 | 67 | music_index := music(music)? 68 | play_forever(music: music_index) 69 | 70 | println("|- LASER") 71 | _ := prepare(sound: "assets/sounds/laser-pulse.wav")? 72 | _ := prepare(sound: "assets/sounds/laser-pulse-2.wav")? 73 | _ := prepare(sound: "assets/sounds/laser-pulse-3.wav")? 74 | // _ := prepare(sound: "assets/sounds/laser.wav")? 75 | // _ := prepare(sound: "assets/sounds/laser2.wav")? 76 | // _ := prepare(sound: "assets/sounds/laser3.wav")? 77 | println("|- EXPLOSION") 78 | _ := prepare(sound: "assets/sounds/laser-pulse-4.wav")? 79 | _ := prepare(sound: "assets/sounds/laser-pulse-5.wav")? 80 | _ := prepare(sound: "assets/sounds/laser-pulse-6.wav")? 81 | _ := prepare(sound: "assets/sounds/laser-pulse-7.wav")? 82 | // _ := prepare(sound: "assets/sounds/explosion-guitar.wav")? 83 | // _ := prepare(sound: "assets/sounds/explosion.wav")? 84 | // _ := prepare(sound: "assets/sounds/explosion2.wav")? 85 | // _ := prepare(sound: "assets/sounds/explosion3.wav")? 86 | 87 | return ok("Assets loaded") 88 | } 89 | 90 | fn prepare__sound(file: str) -> res { 91 | file := load(sound: file)? 92 | println(file) 93 | index := sound(file)? 94 | println(index) 95 | ok(index) 96 | } 97 | 98 | fn prepare__obj_material(obj: f64, material: str) -> Indices {} { 99 | indices := [] 100 | vertices := [] 101 | normals := [] 102 | oc := object_count(obj: obj) 103 | for o oc { 104 | pos := [] 105 | norm := [] 106 | geometry := geometry(obj: obj, object: o) 107 | for g, k { 108 | if geometry[g].material_name == none() { continue } 109 | mat := unwrap(geometry[g].material_name) 110 | if mat != material { 111 | continue 112 | } 113 | for i := 0; i < len(geometry[g].shapes[k]); i += 3 { 114 | for j 3 { 115 | push(mut pos, geometry[g].shapes[k][i+j][0]) 116 | push(mut norm, unwrap(geometry[g].shapes[k][i+j][2])) 117 | } 118 | } 119 | } 120 | vs := vertices(obj: obj, object: o) 121 | ns := normals(obj: obj, object: o) 122 | for i { 123 | // Flip z and y axis. 124 | p := vs[pos[i]] 125 | pos := (xzy vs[pos[i]],) 126 | norm := ns[norm[i]] 127 | added := any i { 128 | (vertices[i] == pos) && (normals[i] == norm) 129 | } 130 | if added { 131 | hit := why(added) 132 | push(mut indices, hit[0]) 133 | } else { 134 | push(mut indices, len(vertices)) 135 | push(mut vertices, pos) 136 | push(mut normals, norm) 137 | } 138 | } 139 | } 140 | return {vertices: clone(vertices), normals: clone(normals), indices: clone(indices)} 141 | } 142 | 143 | /* 144 | fn prepare_geometry(geometry: {}) -> [Strip {}] { 145 | strips := [] 146 | pos := [] 147 | norm := [] 148 | for k { 149 | for i := 0; i < len(geometry.shapes[k]); i += 3 { 150 | n := len(pos) 151 | if n > 0 { 152 | a := geometry.shapes[k][i][0] 153 | b := geometry.shapes[k][i+1][0] 154 | an := unwrap(geometry.shapes[k][i][2]) 155 | bn := unwrap(geometry.shapes[k][i+1][2]) 156 | // Both position and normal must differ. 157 | if (a == pos[n-3]) && 158 | (b == pos[n-1]) && 159 | (an == norm[n-3]) && 160 | (bn == norm[n-1]) { 161 | push(mut pos, geometry.shapes[k][i+2][0]) 162 | push(mut norm, unwrap(geometry.shapes[k][i+2][2])) 163 | continue 164 | } else { 165 | push(mut strips, {pos: pos, norm: norm}) 166 | pos = [] 167 | norm = [] 168 | } 169 | } 170 | for j 3 { 171 | push(mut pos, geometry.shapes[k][i+j][0]) 172 | push(mut norm, unwrap(geometry.shapes[k][i+j][2])) 173 | } 174 | } 175 | } 176 | if len(pos) > 0 { 177 | push(mut strips, {pos: pos, norm: norm}) 178 | } 179 | return clone(strips) 180 | } 181 | */ 182 | 183 | fn all_quads(strips: [Strip {}]) -> bool { 184 | return all i { len(strips[i].pos) == 4 } 185 | } 186 | 187 | fn info__obj_short(obj: str, short: bool) -> res[link] { 188 | obj_index := obj(obj)? 189 | material_library := material_library(obj: obj_index)? 190 | objects := objects(obj: obj_index) 191 | return ok(link { 192 | "name: "obj"\n" 193 | "index: "obj_index"\n" 194 | "material_library: "material_library"\n" 195 | "objects: ["{ 196 | l := link {} 197 | for i { 198 | l += "\n{name: " 199 | l += json_string(objects[i]) 200 | l += ", " 201 | 202 | n := vertex_count(obj: obj_index, object: i) 203 | if short { 204 | l += "vs: " 205 | l += n 206 | l += ", " 207 | } 208 | if !short { 209 | l += "\nvertices: " 210 | l += str(vertices(obj: obj_index, object: i)) 211 | l += ", " 212 | } 213 | 214 | n := tex_vertex_count(obj: obj_index, object: i) 215 | if short { 216 | l += "uvs: " 217 | l += n 218 | l += ", " 219 | } 220 | if !short { 221 | l += "\ntex_vertices: " 222 | l += str(tex_vertices(obj: obj_index, object: i)) 223 | l += ", " 224 | } 225 | 226 | n := normal_count(obj: obj_index, object: i) 227 | if short { 228 | l += "ns: " 229 | l += n 230 | l += ", " 231 | } 232 | if !short { 233 | l += "\nnormals: " 234 | l += str(normals(obj: obj_index, object: i)) 235 | l += ", " 236 | } 237 | 238 | n := geometry_count(obj: obj_index, object: i) 239 | if short { 240 | l += "gs: " 241 | l += n 242 | l += ", " 243 | } 244 | if !short { 245 | l += "\ngeometry: " 246 | l += str(geometry(obj: obj_index, object: i)) 247 | l += ", " 248 | } 249 | 250 | l += "}, " 251 | } 252 | clone(l) 253 | }"]\n" 254 | }) 255 | } 256 | -------------------------------------------------------------------------------- /src/bullets.dyon: -------------------------------------------------------------------------------- 1 | bullet_pos() = 0 2 | bullet_angle() = 1 3 | bullet_vel() = 2 4 | 5 | // Reserve space for 100 bullets. 6 | // Stores [position, angle, velocity] 7 | fn init_bullets() -> [Bullet []] { 8 | return [[(0, 0), 0, (0, 0)]; 200] 9 | } 10 | 11 | fn move_bullets() 12 | ~ world: World, 13 | mut bullets: [Bullet []], 14 | dt: f64 15 | { 16 | POS := bullet_pos() 17 | VEL := bullet_vel() 18 | 19 | for i world.free_bullet_slot { 20 | bullets[i][POS] += dt * bullets[i][VEL] 21 | /* // Warp position of bullets. 22 | bullets[i][0] = warp(pos: bullets[i][0], space: space, 23 | offset: world.space_settings.offset) 24 | */ 25 | } 26 | } 27 | 28 | fn remove_hidden_bullets__world_offset(mut world, offset) 29 | ~ mut bullets: [Bullet []], space: vec4 { 30 | for i := world.free_bullet_slot - 1; i >= 0; i -= 1 { 31 | if is_outside(pos: bullets[i][0], space: space, offset: offset) { 32 | world.free_bullet_slot = swap_remove(mut bullets, i, world.free_bullet_slot) 33 | } 34 | } 35 | } 36 | 37 | fn fire__world_dt(mut world, dt) ~ mut bullets: [Bullet []] { 38 | POS := bullet_pos() 39 | ANGLE := bullet_angle() 40 | VEL := bullet_vel() 41 | 42 | world.spaceship.fire_dt += dt 43 | if world.spaceship.fire_dt < world.bullet_settings.interval { return } 44 | if world.input_state.fire != 1 { return } 45 | world.spaceship.fire_dt = 0 46 | if (world.free_bullet_slot + 1) < len(bullets) { 47 | n := world.free_bullet_slot 48 | bullets[n][POS] = clone(world.spaceship.pos) 49 | bullets[n][ANGLE] = clone(world.spaceship.angle) 50 | bullets[n][VEL] = world.spaceship.vel + 51 | world.bullet_settings.speed * dir(angle: world.spaceship.angle) 52 | world.free_bullet_slot += 1 53 | 54 | SOUND := sound_laser_offset() 55 | COUNT := sound_laser_count() 56 | play_once(sound: world.bullet_settings.sound % COUNT + SOUND) 57 | world.bullet_settings.sound += 1 58 | } 59 | } 60 | 61 | fn draw__bullets_active(bullets: [Bullet []], active: f64) 62 | ~ mut draw_list 63 | { 64 | POS := bullet_pos() 65 | ANGLE := bullet_angle() 66 | 67 | color := #ffff00 68 | reset_transform() 69 | for i active { 70 | line(color: color, radius: 1, 71 | from: bullets[i][POS], to: bullets[i][POS] + 15 * dir(angle: bullets[i][ANGLE])) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/comets.dyon: -------------------------------------------------------------------------------- 1 | comet_pos() = 0 2 | comet_angle() = 1 3 | comet_vel() = 2 4 | comet_angle_vel() = 3 5 | comet_radius() = 4 6 | 7 | // Reserve space for 100 comets 8 | // Stores [position, angle, velocity, angle_velocity, radius] 9 | fn init_comets() -> [Comet []] { 10 | return [[(0, 0), 0, (0, 0), 0, 0]; 20] 11 | } 12 | 13 | fn init_collision_grid_settings(settings) -> CollisionGrid [[f64]] { 14 | return [[0; settings.h]; settings.w] 15 | } 16 | 17 | fn spawn_comets() 18 | ~ dt: f64, 19 | mut world: World, 20 | mut comets: [Comet []] 21 | { 22 | if (random() * dt) >= world.comet_settings.spawn_probability { return } 23 | n := world.free_comet_slot 24 | if (n + 1) >= len(comets) { return } 25 | 26 | world.free_comet_slot += create_comet( 27 | slot: n, 28 | pos: window_size() / 2 + dir(angle: random() * tau()) * x(window_size()), 29 | radius: none(), 30 | angle: none() 31 | ) 32 | } 33 | 34 | fn create_comet__slot_pos_radius_angle(slot: f64, pos: vec4, radius: opt[f64], angle: opt[f64]) 35 | ~ world: World, 36 | mut comets: [Comet []] 37 | -> f64 38 | { 39 | if slot >= len(comets) { return 0 } 40 | new_radius := if radius == none() { 41 | (random() + 0.1) * world.comet_settings.radius 42 | } else { 43 | unwrap(radius) / 2 44 | } 45 | if new_radius < world.comet_settings.min_radius { return 0 } 46 | 47 | POS := comet_pos() 48 | VEL := comet_vel() 49 | ANGLE_VEL := comet_angle_vel() 50 | RADIUS := comet_radius() 51 | 52 | offset := world.space_settings.offset 53 | // Position. 54 | comets[slot][POS] = clamp( 55 | pos: pos, 56 | aa: (0, 0) - offset, 57 | bb: window_size() + offset 58 | ) 59 | // Velocity. 60 | comets[slot][VEL] = if angle == none() { 61 | world.comet_settings.speed * dir(angle: random() * tau()) 62 | } else { 63 | dir(angle: unwrap(angle)) * world.comet_settings.speed 64 | } 65 | // Angle velocity. 66 | comets[slot][ANGLE_VEL] = (random() - 0.5) * tau() 67 | // Radius. 68 | comets[slot][RADIUS] = clone(new_radius) 69 | return 1 70 | } 71 | 72 | fn move_comets() 73 | ~ world: World, 74 | mut comets: [Comet []], 75 | dt: f64 76 | { 77 | POS := comet_pos() 78 | VEL := comet_vel() 79 | ANGLE := comet_angle() 80 | ANGLE_VEL := comet_angle_vel() 81 | RADIUS := comet_radius() 82 | 83 | for i world.free_comet_slot { 84 | comets[i][POS] += dt * comets[i][VEL] 85 | comets[i][POS] = warp(pos: comets[i][POS], 86 | offset: world.space_settings.offset) 87 | comets[i][ANGLE] += dt * comets[i][ANGLE_VEL] 88 | } 89 | } 90 | 91 | fn shoot_comets() 92 | ~ mut world: World, 93 | mut comets: [Comet []], 94 | dt: f64, 95 | mut collision_grid: CollisionGrid [[f64]], 96 | mut bullets: [Bullet []] 97 | { 98 | POS := comet_pos() 99 | VEL := comet_vel() 100 | ANGLE := comet_angle() 101 | ANGLE_VEL := comet_angle_vel() 102 | RADIUS := comet_radius() 103 | BULLET_ANGLE := bullet_angle() 104 | 105 | units := world.collision_settings.units 106 | w := world.collision_settings.w 107 | h := world.collision_settings.h 108 | 109 | loop { 110 | changed := false 111 | 112 | for i, j { 113 | collision_grid[i][j] = 0 114 | } 115 | 116 | for i world.free_bullet_slot { 117 | pos := bullets[i][0] 118 | x := x(pos) / units 119 | y := y(pos) / units 120 | if (x < 0) || (x >= w) { continue } 121 | if (y < 0) || (y >= h) { continue } 122 | collision_grid[x][y] = i + 1 123 | } 124 | 125 | 'comet: for i world.free_comet_slot { 126 | pos := comets[i][POS] 127 | vel := comets[i][VEL] 128 | radius := comets[i][RADIUS] 129 | for rx := -radius; rx < radius; rx += units { 130 | for ry := -radius; ry < radius; ry += units { 131 | x := (x(pos) + rx) / units 132 | y := (y(pos) + ry) / units 133 | if (x < 0) || (x >= w) { continue } 134 | if (y < 0) || (y >= h) { continue } 135 | bullet := collision_grid[x][y] 136 | if bullet > 0 { 137 | bullet -= 1 138 | bullet_angle := bullets[bullet][BULLET_ANGLE] 139 | bend := tau() / 4 140 | create_explosion(pos: pos, vel: vel, radius: radius) 141 | world.free_comet_slot = swap_remove(mut comets, i, world.free_comet_slot) 142 | world.free_bullet_slot = swap_remove(mut bullets, bullet, world.free_bullet_slot) 143 | world.free_comet_slot += create_comet( 144 | slot: world.free_comet_slot, 145 | pos: pos, 146 | radius: some(radius), 147 | angle: some(bullet_angle + bend) 148 | ) 149 | world.free_comet_slot += create_comet( 150 | slot: world.free_comet_slot, 151 | pos: pos, 152 | radius: some(radius), 153 | angle: some(bullet_angle - bend) 154 | ) 155 | // Exit loop because list is changed. 156 | changed := true 157 | break 'comet 158 | } 159 | } 160 | } 161 | } 162 | if !changed { break } 163 | } 164 | } 165 | 166 | fn draw__comets_active 167 | (comets: [Comet []], active: f64) 168 | ~ mut draw_list 169 | { 170 | color := #ff0000 171 | reset_transform() 172 | for i active { 173 | center := comets[i][comet_pos()] 174 | radius := comets[i][comet_radius()] 175 | transform(center: center, angle: comets[i][comet_angle()]) 176 | circle(color: color, center: center, radius: radius, resolution: 5) 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /src/engine/math.rs: -------------------------------------------------------------------------------- 1 | pub use vecmath::col_mat4_mul as mul; 2 | 3 | pub fn rotate_angle(angle: f32) -> [[f32; 4]; 4] { 4 | [ 5 | [angle.cos(), angle.sin(), 0.0, 0.0], 6 | [-angle.sin(), angle.cos(), 0.0, 0.0], 7 | [0.0, 0.0, 1.0, 0.0], 8 | [0.0, 0.0, 0.0, 1.0] 9 | ] 10 | } 11 | 12 | pub fn rotate_angle_x(angle: f32) -> [[f32; 4]; 4] { 13 | [ 14 | [1.0, 0.0, 0.0, 0.0], 15 | [0.0, angle.cos(), angle.sin(), 0.0], 16 | [0.0, -angle.sin(), angle.cos(), 0.0], 17 | [0.0, 0.0, 0.0, 1.0] 18 | ] 19 | } 20 | 21 | pub fn scale(s: f32) -> [[f32; 4]; 4] { 22 | [ 23 | [s, 0.0, 0.0, 0.0], 24 | [0.0, s, 0.0, 0.0], 25 | [0.0, 0.0, s, 0.0], 26 | [0.0, 0.0, 0.0, 1.0] 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /src/engine/mod.rs: -------------------------------------------------------------------------------- 1 | pub use self::obj::*; 2 | pub use self::shader::*; 3 | pub use self::sound::*; 4 | 5 | mod obj; 6 | mod shader; 7 | pub mod math; 8 | mod sound; 9 | -------------------------------------------------------------------------------- /src/engine/obj.rs: -------------------------------------------------------------------------------- 1 | use wavefront_obj::mtl::MtlSet; 2 | use wavefront_obj::obj::{self, ObjSet}; 3 | use std::sync::Arc; 4 | use current::Current; 5 | use dyon::*; 6 | use dyon::embed::{PushVariable, PopVariable}; 7 | 8 | pub type Materials = Vec<(Arc, MtlSet)>; 9 | pub type ObjSets = Vec<(Arc, ObjSet)>; 10 | 11 | pub fn register_obj(module: &mut Module) { 12 | module.add(Arc::new("load__material".into()), 13 | load__material, PreludeFunction { 14 | lts: vec![Lt::Default], 15 | tys: vec![Type::Text], 16 | ret: Type::Result(Box::new(Type::Text)) 17 | }); 18 | module.add(Arc::new("material".into()), 19 | material, PreludeFunction { 20 | lts: vec![Lt::Default], 21 | tys: vec![Type::Text], 22 | ret: Type::Option(Box::new(Type::F64)) 23 | }); 24 | module.add(Arc::new("materials".into()), 25 | materials, PreludeFunction { 26 | lts: vec![], 27 | tys: vec![], 28 | ret: Type::Array(Box::new(Type::Text)) 29 | }); 30 | module.add(Arc::new("load__obj".into()), 31 | load__obj, PreludeFunction { 32 | lts: vec![Lt::Default], 33 | tys: vec![Type::Text], 34 | ret: Type::Result(Box::new(Type::Text)) 35 | }); 36 | module.add(Arc::new("obj".into()), 37 | obj, PreludeFunction { 38 | lts: vec![Lt::Default], 39 | tys: vec![Type::Text], 40 | ret: Type::Option(Box::new(Type::F64)) 41 | }); 42 | module.add(Arc::new("objs".into()), 43 | objs, PreludeFunction { 44 | lts: vec![], 45 | tys: vec![], 46 | ret: Type::Array(Box::new(Type::Text)) 47 | }); 48 | module.add(Arc::new("material_library__obj".into()), 49 | material_library__obj, PreludeFunction { 50 | lts: vec![Lt::Default], 51 | tys: vec![Type::F64], 52 | ret: Type::Option(Box::new(Type::Text)) 53 | }); 54 | module.add(Arc::new("object_count__obj".into()), 55 | object_count__obj, PreludeFunction { 56 | lts: vec![Lt::Default], 57 | tys: vec![Type::F64], 58 | ret: Type::F64 59 | }); 60 | module.add(Arc::new("objects__obj".into()), 61 | objects__obj, PreludeFunction { 62 | lts: vec![Lt::Default], 63 | tys: vec![Type::F64], 64 | ret: Type::Array(Box::new(Type::Text)) 65 | }); 66 | module.add(Arc::new("vertex_count__obj_object".into()), 67 | vertex_count__obj_object, PreludeFunction { 68 | lts: vec![Lt::Default; 2], 69 | tys: vec![Type::F64; 2], 70 | ret: Type::F64 71 | }); 72 | module.add(Arc::new("tex_vertex_count__obj_object".into()), 73 | tex_vertex_count__obj_object, PreludeFunction { 74 | lts: vec![Lt::Default; 2], 75 | tys: vec![Type::F64; 2], 76 | ret: Type::F64 77 | }); 78 | module.add(Arc::new("normal_count__obj_object".into()), 79 | normal_count__obj_object, PreludeFunction { 80 | lts: vec![Lt::Default; 2], 81 | tys: vec![Type::F64; 2], 82 | ret: Type::F64 83 | }); 84 | module.add(Arc::new("geometry_count__obj_object".into()), 85 | geometry_count__obj_object, PreludeFunction { 86 | lts: vec![Lt::Default; 2], 87 | tys: vec![Type::F64; 2], 88 | ret: Type::F64 89 | }); 90 | module.add(Arc::new("vertex__obj_object_vertex".into()), 91 | vertex__obj_object_vertex, PreludeFunction { 92 | lts: vec![Lt::Default; 3], 93 | tys: vec![Type::F64; 3], 94 | ret: Type::Vec4 95 | }); 96 | module.add(Arc::new("tex_vertex__obj_object_tex_vertex".into()), 97 | tex_vertex__obj_object_tex_vertex, PreludeFunction { 98 | lts: vec![Lt::Default; 3], 99 | tys: vec![Type::F64; 3], 100 | ret: Type::Vec4 101 | }); 102 | module.add(Arc::new("normal__obj_object_normal".into()), 103 | normal__obj_object_normal, PreludeFunction { 104 | lts: vec![Lt::Default; 3], 105 | tys: vec![Type::F64; 3], 106 | ret: Type::Vec4 107 | }); 108 | module.add(Arc::new("vertices__obj_object".into()), 109 | vertices__obj_object, PreludeFunction { 110 | lts: vec![Lt::Default; 2], 111 | tys: vec![Type::F64; 2], 112 | ret: Type::Array(Box::new(Type::Vec4)) 113 | }); 114 | module.add(Arc::new("tex_vertices__obj_object".into()), 115 | tex_vertices__obj_object, PreludeFunction { 116 | lts: vec![Lt::Default; 2], 117 | tys: vec![Type::F64; 2], 118 | ret: Type::Array(Box::new(Type::Vec4)) 119 | }); 120 | module.add(Arc::new("normals__obj_object".into()), 121 | normals__obj_object, PreludeFunction { 122 | lts: vec![Lt::Default; 2], 123 | tys: vec![Type::F64; 2], 124 | ret: Type::Array(Box::new(Type::Vec4)) 125 | }); 126 | module.add(Arc::new("geometry__obj_object".into()), 127 | geometry__obj_object, PreludeFunction { 128 | lts: vec![Lt::Default; 2], 129 | tys: vec![Type::F64; 2], 130 | ret: Type::Array(Box::new(Type::object())) 131 | }); 132 | } 133 | 134 | dyon_fn!{fn load__material(file: Arc) -> Result, String> { 135 | use wavefront_obj::mtl::parse; 136 | use std::fs::File; 137 | use std::io::Read; 138 | use std::error::Error; 139 | 140 | let materials = unsafe { &mut *Current::::new() }; 141 | 142 | let mut f = try!(File::open(&**file).map_err(|err| String::from(err.description()))); 143 | let mut s = String::new(); 144 | try!(f.read_to_string(&mut s).map_err(|err| String::from(err.description()))); 145 | 146 | let mtlset = try!(parse(s).map_err(|err| 147 | format!("Error when parsing `{}`:\n{}:{}", file, err.line_number, err.message))); 148 | materials.push((file.clone(), mtlset)); 149 | Ok(file) 150 | }} 151 | 152 | dyon_fn!{fn load__obj(file: Arc) -> Result, String> { 153 | use wavefront_obj::obj::parse; 154 | use std::fs::File; 155 | use std::io::Read; 156 | use std::error::Error; 157 | 158 | let obj_sets = unsafe { &mut *Current::::new() }; 159 | 160 | let mut f = try!(File::open(&**file).map_err(|err| String::from(err.description()))); 161 | let mut s = String::new(); 162 | try!(f.read_to_string(&mut s).map_err(|err| String::from(err.description()))); 163 | 164 | let obj_set = try!(parse(s).map_err(|err| 165 | format!("Error when parsing `{}`:\n{}:{}", file, err.line_number, err.message))); 166 | obj_sets.push((file.clone(), obj_set)); 167 | Ok(file) 168 | }} 169 | 170 | dyon_fn!{fn material(file: Arc) -> Option { 171 | let materials = unsafe { &*Current::::new() }; 172 | for (i, mat) in materials.iter().enumerate() { 173 | if &mat.0 == &file { return Some(i); } 174 | } 175 | None 176 | }} 177 | 178 | dyon_fn!{fn obj(file: Arc) -> Option { 179 | let obj_sets = unsafe { &*Current::::new() }; 180 | for (i, obj_set) in obj_sets.iter().enumerate() { 181 | if &obj_set.0 == &file { return Some(i); } 182 | } 183 | None 184 | }} 185 | 186 | dyon_fn!{fn materials() -> Vec> { 187 | let materials = unsafe { &*Current::::new() }; 188 | materials.iter().map(|n| n.0.clone()).collect() 189 | }} 190 | 191 | dyon_fn!{fn objs() -> Vec> { 192 | let obj_sets = unsafe { &*Current::::new() }; 193 | obj_sets.iter().map(|n| n.0.clone()).collect() 194 | }} 195 | 196 | dyon_fn!{fn material_library__obj(ind: usize) -> Option> { 197 | let obj_sets = unsafe { &*Current::::new() }; 198 | obj_sets[ind].1.material_library.as_ref().map(|n| Arc::new(n.clone())) 199 | }} 200 | 201 | dyon_fn!{fn object_count__obj(ind: usize) -> usize { 202 | let obj_sets = unsafe { &*Current::::new() }; 203 | obj_sets[ind].1.objects.len() 204 | }} 205 | 206 | dyon_fn!{fn objects__obj(ind: usize) -> Vec> { 207 | let obj_sets = unsafe { &*Current::::new() }; 208 | obj_sets[ind].1.objects.iter().map(|n| Arc::new(n.name.clone())).collect() 209 | }} 210 | 211 | dyon_fn!{fn vertex_count__obj_object(obj: usize, object: usize) -> usize { 212 | let obj_sets = unsafe { &*Current::::new() }; 213 | obj_sets[obj].1.objects[object].vertices.len() 214 | }} 215 | 216 | dyon_fn!{fn tex_vertex_count__obj_object(obj: usize, object: usize) -> usize { 217 | let obj_sets = unsafe { &*Current::::new() }; 218 | obj_sets[obj].1.objects[object].tex_vertices.len() 219 | }} 220 | 221 | dyon_fn!{fn normal_count__obj_object(obj: usize, object: usize) -> usize { 222 | let obj_sets = unsafe { &*Current::::new() }; 223 | obj_sets[obj].1.objects[object].normals.len() 224 | }} 225 | 226 | dyon_fn!{fn geometry_count__obj_object(obj: usize, object: usize) -> usize { 227 | let obj_sets = unsafe { &*Current::::new() }; 228 | obj_sets[obj].1.objects[object].geometry.len() 229 | }} 230 | 231 | dyon_fn!{fn vertex__obj_object_vertex 232 | (obj: usize, object: usize, vertex: usize) -> Vec4 { 233 | let obj_sets = unsafe { &*Current::::new() }; 234 | let vertex = obj_sets[obj].1.objects[object].vertices[vertex]; 235 | [vertex.x, vertex.y, vertex.z].into() 236 | }} 237 | 238 | dyon_fn!{fn tex_vertex__obj_object_tex_vertex 239 | (obj: usize, object: usize, tex_vertex: usize) -> Vec4 { 240 | let obj_sets = unsafe { &*Current::::new() }; 241 | let tex_vertex = obj_sets[obj].1.objects[object].tex_vertices[tex_vertex]; 242 | [tex_vertex.x, tex_vertex.y].into() 243 | }} 244 | 245 | dyon_fn!{fn normal__obj_object_normal 246 | (obj: usize, object: usize, normal: usize) -> Vec4 { 247 | let obj_sets = unsafe { &*Current::::new() }; 248 | let normal = obj_sets[obj].1.objects[object].normals[normal]; 249 | [normal.x, normal.y, normal.z].into() 250 | }} 251 | 252 | dyon_fn!{fn vertices__obj_object(obj: usize, object: usize) -> Vec { 253 | let obj_sets = unsafe { &*Current::::new() }; 254 | obj_sets[obj].1.objects[object].vertices.iter() 255 | .map(|vertex| [vertex.x, vertex.y, vertex.z].into()).collect() 256 | }} 257 | 258 | dyon_fn!{fn tex_vertices__obj_object(obj: usize, object: usize) -> Vec { 259 | let obj_sets = unsafe { &*Current::::new() }; 260 | obj_sets[obj].1.objects[object].tex_vertices.iter() 261 | .map(|tex_vertex| [tex_vertex.x, tex_vertex.y].into()).collect() 262 | }} 263 | 264 | dyon_fn!{fn normals__obj_object(obj: usize, object: usize) -> Vec { 265 | let obj_sets = unsafe { &*Current::::new() }; 266 | obj_sets[obj].1.objects[object].normals.iter() 267 | .map(|normal| [normal.x, normal.y, normal.z].into()).collect() 268 | }} 269 | 270 | pub struct Geometry { 271 | pub material_name: Option>, 272 | pub smooth_shading_group: usize, 273 | pub shapes: Vec, 274 | } 275 | 276 | impl<'a> From<&'a obj::Geometry> for Geometry { 277 | fn from(val: &'a obj::Geometry) -> Geometry { 278 | Geometry { 279 | material_name: val.material_name.as_ref().map(|n| Arc::new(n.clone())), 280 | smooth_shading_group: val.smooth_shading_group, 281 | shapes: val.shapes.iter().map(|n| Shape(n.clone())).collect() 282 | } 283 | } 284 | } 285 | 286 | dyon_obj!{Geometry { material_name, smooth_shading_group, shapes }} 287 | 288 | dyon_fn!{fn geometry__obj_object(obj: usize, object: usize) -> Vec { 289 | let obj_sets = unsafe { &*Current::::new() }; 290 | obj_sets[obj].1.objects[object].geometry.iter() 291 | .map(|geometry| geometry.into()).collect() 292 | }} 293 | 294 | /// Wraps a shape from OBJ library. 295 | pub struct Shape(pub obj::Shape); 296 | 297 | impl PopVariable for Shape { 298 | fn pop_var(rt: &Runtime, var: &Variable) -> Result { 299 | if let &Variable::Array(ref arr) = var { 300 | Ok(match arr.len() { 301 | 1 => { 302 | Shape(obj::Shape::Point(try!(rt.var(&arr[0])))) 303 | } 304 | 2 => { 305 | Shape(obj::Shape::Line(try!(rt.var(&arr[0])), 306 | try!(rt.var(&arr[1])))) 307 | } 308 | 3 => { 309 | Shape(obj::Shape::Triangle(try!(rt.var(&arr[0])), 310 | try!(rt.var(&arr[1])), 311 | try!(rt.var(&arr[2])))) 312 | } 313 | _ => return Err(rt.expected(var, "array of length 1, 2, 3")) 314 | }) 315 | } else { 316 | Err(rt.expected(var, "array")) 317 | } 318 | } 319 | } 320 | 321 | impl PushVariable for Shape { 322 | fn push_var(&self) -> Variable { 323 | match self.0 { 324 | obj::Shape::Point(ref p) => Variable::Array(Arc::new(vec![p.push_var()])), 325 | obj::Shape::Line(ref a, ref b) => Variable::Array(Arc::new(vec![ 326 | a.push_var(), b.push_var() 327 | ])), 328 | obj::Shape::Triangle(ref a, ref b, ref c) => Variable::Array(Arc::new(vec![ 329 | a.push_var(), b.push_var(), c.push_var() 330 | ])) 331 | } 332 | } 333 | } 334 | -------------------------------------------------------------------------------- /src/engine/shader.rs: -------------------------------------------------------------------------------- 1 | use std::sync::Arc; 2 | use glium; 3 | use current::Current; 4 | use dyon::*; 5 | 6 | use Window; 7 | 8 | pub type Programs = Vec<(Arc, glium::Program)>; 9 | pub type VertexBuffers = Vec>; 10 | pub type IndexBuffers = Vec>; 11 | 12 | #[derive(Copy, Clone)] 13 | pub struct Vertex { 14 | pos: [f32; 3], 15 | norm: [f32; 3], 16 | } 17 | 18 | implement_vertex!{Vertex, pos, norm} 19 | 20 | pub fn register_shader(module: &mut Module) { 21 | module.add(Arc::new("load_program__name_vshader_fshader".into()), 22 | load_program__name_vshader_fshader, PreludeFunction { 23 | lts: vec![Lt::Default; 3], 24 | tys: vec![Type::Text; 3], 25 | ret: Type::Result(Box::new(Type::Text)) 26 | }); 27 | module.add(Arc::new("program".into()), 28 | program, PreludeFunction { 29 | lts: vec![Lt::Default], 30 | tys: vec![Type::Text], 31 | ret: Type::Option(Box::new(Type::F64)) 32 | }); 33 | module.add(Arc::new("count_vertex_buffers".into()), 34 | count_vertex_buffers, PreludeFunction { 35 | lts: vec![], 36 | tys: vec![], 37 | ret: Type::F64 38 | }); 39 | module.add(Arc::new("count_index_buffers".into()), 40 | count_index_buffers, PreludeFunction { 41 | lts: vec![], 42 | tys: vec![], 43 | ret: Type::F64 44 | }); 45 | module.add(Arc::new("create_vertex_buffer__size".into()), 46 | create_vertex_buffer__size, PreludeFunction { 47 | lts: vec![Lt::Default], 48 | tys: vec![Type::F64], 49 | ret: Type::Result(Box::new(Type::F64)) 50 | }); 51 | module.add(Arc::new("create_index_buffer__size".into()), 52 | create_index_buffer__size, PreludeFunction { 53 | lts: vec![Lt::Default], 54 | tys: vec![Type::F64], 55 | ret: Type::Result(Box::new(Type::F64)) 56 | }); 57 | module.add(Arc::new("fill_vertex_buffer__buffer_pos_norm".into()), 58 | fill_vertex_buffer__buffer_pos_norm, PreludeFunction { 59 | lts: vec![Lt::Default; 3], 60 | tys: vec![Type::F64, Type::Array(Box::new(Type::Vec4)), 61 | Type::Array(Box::new(Type::Vec4))], 62 | ret: Type::Void 63 | }); 64 | module.add(Arc::new("fill_index_buffer__buffer_data".into()), 65 | fill_index_buffer__buffer_data, PreludeFunction { 66 | lts: vec![Lt::Default; 2], 67 | tys: vec![Type::F64, Type::Array(Box::new(Type::F64))], 68 | ret: Type::Void 69 | }); 70 | module.add(Arc::new("clear_depth".into()), 71 | clear_depth, PreludeFunction { 72 | lts: vec![], 73 | tys: vec![], 74 | ret: Type::Void 75 | }); 76 | module.add(Arc::new("draw__program_vbuf_ibuf_pos_angle_scale_color_anglex".into()), 77 | draw__program_vbuf_ibuf_pos_angle_scale_color_anglex, PreludeFunction { 78 | lts: vec![Lt::Default; 8], 79 | tys: vec![Type::F64, Type::F64, Type::F64, 80 | Type::Vec4, Type::F64, Type::F64, 81 | Type::Vec4, Type::F64], 82 | ret: Type::Void 83 | }); 84 | } 85 | 86 | dyon_fn!{fn load_program__name_vshader_fshader( 87 | name: Arc, 88 | vshader: Arc, 89 | fshader: Arc 90 | ) -> Result, String> { 91 | use std::error::Error; 92 | 93 | let programs = unsafe { &mut *Current::::new() }; 94 | let window = unsafe { &*Current::::new() }; 95 | 96 | let program = try!(glium::Program::from_source( 97 | &window.context, &vshader, &fshader, None).map_err(|err| 98 | match err { 99 | glium::program::ProgramCreationError::CompilationError(err) => err, 100 | _ => String::from(err.description()) 101 | } 102 | )); 103 | programs.push((name.clone(), program)); 104 | 105 | Ok(name) 106 | }} 107 | 108 | dyon_fn!{fn program(name: Arc) -> Option { 109 | let programs = unsafe { &*Current::::new() }; 110 | for (i, n) in programs.iter().enumerate() { 111 | if &n.0 == &name { return Some(i) } 112 | } 113 | None 114 | }} 115 | 116 | dyon_fn!{fn count_vertex_buffers() -> usize { 117 | let vertex_buffers = unsafe { &*Current::::new() }; 118 | vertex_buffers.len() 119 | }} 120 | 121 | dyon_fn!{fn count_index_buffers() -> usize { 122 | let index_buffers = unsafe { &*Current::::new() }; 123 | index_buffers.len() 124 | }} 125 | 126 | dyon_fn!{fn create_vertex_buffer__size(size: usize) -> Result { 127 | use std::error::Error; 128 | 129 | let vertex_buffers = unsafe { &mut *Current::::new() }; 130 | let window = unsafe { &*Current::::new() }; 131 | let n = vertex_buffers.len(); 132 | vertex_buffers.push(try!(glium::VertexBuffer::empty(&window.context, size).map_err(|err| 133 | String::from(err.description()) 134 | ))); 135 | Ok(n) 136 | }} 137 | 138 | dyon_fn!{fn create_index_buffer__size(size: usize) -> Result { 139 | use std::error::Error; 140 | 141 | let index_buffers = unsafe { &mut *Current::::new() }; 142 | let window = unsafe { &*Current::::new() }; 143 | let n = index_buffers.len(); 144 | index_buffers.push(try!(glium::IndexBuffer::empty( 145 | &window.context, glium::index::PrimitiveType::TrianglesList, size).map_err(|err| { 146 | String::from(err.description()) 147 | }))); 148 | Ok(n) 149 | }} 150 | 151 | dyon_fn!{fn fill_vertex_buffer__buffer_pos_norm 152 | (buffer: usize, pos: Vec, norm: Vec) { 153 | let vertex_buffers = unsafe { &mut *Current::::new() }; 154 | 155 | let n = pos.len(); 156 | let slice = vertex_buffers[buffer].slice(0..n).unwrap(); 157 | slice.write({ 158 | &(0..n).map(|i| Vertex { pos: pos[i].into(), norm: norm[i].into() }).collect::>() 159 | }); 160 | }} 161 | 162 | dyon_fn!{fn fill_index_buffer__buffer_data(buffer: usize, data: Vec) { 163 | let index_buffers = unsafe { &*Current::::new() }; 164 | 165 | index_buffers[buffer].write(&data); 166 | }} 167 | 168 | dyon_fn!{fn clear_depth() { 169 | use glium::{Frame, Surface}; 170 | 171 | let target = unsafe { &mut *Current::::new() }; 172 | target.clear_depth(1.0); 173 | }} 174 | 175 | dyon_fn!{fn draw__program_vbuf_ibuf_pos_angle_scale_color_anglex( 176 | program: usize, 177 | vbuf: usize, 178 | ibuf: usize, 179 | pos: Vec4, 180 | angle: f32, 181 | scale: f32, 182 | color: Vec4, 183 | angle_x: f32 184 | ) { 185 | use glium::{Depth, DepthTest, Frame, Surface}; 186 | use glium::draw_parameters::{DepthClamp, DrawParameters}; 187 | use piston::input::{Event, RenderEvent}; 188 | use super::math; 189 | 190 | let pos: [f32; 3] = pos.into(); 191 | let pos_transform = [ 192 | [1.0, 0.0, 0.0, 0.0], 193 | [0.0, 1.0, 0.0, 0.0], 194 | [0.0, 0.0, 1.0, 0.0], 195 | [pos[0], pos[1], pos[2], 1.0] 196 | ]; 197 | let e = unsafe { &*Current::>::new() }; 198 | let mat: [[f32; 4]; 4] = if let Some(args) = e.as_ref().unwrap().render_args() { 199 | let mat: [[f32; 3]; 2] = args.viewport().abs_transform(); 200 | let sz = -0.01; 201 | [ 202 | [mat[0][0], mat[1][0], 0.0, 0.0], 203 | [mat[0][1], mat[1][1], 0.0, 0.0], 204 | [0.0, 0.0, sz, 0.0], 205 | [mat[0][2], mat[1][2], 0.0, 1.0] 206 | ] 207 | } else { 208 | panic!("No render event"); 209 | }; 210 | let programs = unsafe { &*Current::::new() }; 211 | let vertex_buffers = unsafe { &*Current::::new() }; 212 | let index_buffers = unsafe { &*Current::::new() }; 213 | let target = unsafe { &mut *Current::::new() }; 214 | let mvp = math::mul(mat, math::mul( 215 | pos_transform, 216 | math::mul( 217 | math::mul( 218 | math::rotate_angle(angle), 219 | math::scale(scale) 220 | ), 221 | math::rotate_angle_x(angle_x) 222 | ) 223 | )); 224 | /* 225 | let mvp: [[f32; 4]; 4] = [ 226 | [1.0, 0.0, 0.0, 0.0], 227 | [0.0, 1.0, 0.0, 0.0], 228 | [0.0, 0.0, 1.0, 0.0], 229 | [0.0, 0.0, 0.0, 1.0] 230 | ]; 231 | */ 232 | target.draw(&vertex_buffers[vbuf], &index_buffers[ibuf], &programs[program].1, 233 | &uniform!{mvp: mvp, color: color.0}, &DrawParameters { 234 | depth: Depth { 235 | test: DepthTest::IfLess, 236 | write: true, 237 | range: (0.0, 1.0), 238 | clamp: DepthClamp::NoClamp, 239 | }, 240 | ..Default::default() 241 | }).unwrap(); 242 | }} 243 | -------------------------------------------------------------------------------- /src/engine/sound.rs: -------------------------------------------------------------------------------- 1 | 2 | use std::sync::Arc; 3 | 4 | use sdl2_mixer as mix; 5 | use current::Current; 6 | use dyon::*; 7 | 8 | pub type MusicTracks = Vec<(Arc, mix::Music)>; 9 | pub type SoundTracks = Vec<(Arc, mix::Chunk)>; 10 | 11 | pub fn register_sound(module: &mut Module) { 12 | module.add(Arc::new("load__music".into()), load__music, PreludeFunction { 13 | lts: vec![Lt::Default], 14 | tys: vec![Type::Text], 15 | ret: Type::Result(Box::new(Type::Text)) 16 | }); 17 | module.add(Arc::new("load__sound".into()), load__sound, PreludeFunction { 18 | lts: vec![Lt::Default], 19 | tys: vec![Type::Text], 20 | ret: Type::Result(Box::new(Type::Text)) 21 | }); 22 | module.add(Arc::new("music".into()), music, PreludeFunction { 23 | lts: vec![Lt::Default], 24 | tys: vec![Type::Text], 25 | ret: Type::Option(Box::new(Type::F64)) 26 | }); 27 | module.add(Arc::new("sound".into()), sound, PreludeFunction { 28 | lts: vec![Lt::Default], 29 | tys: vec![Type::Text], 30 | ret: Type::Option(Box::new(Type::F64)) 31 | }); 32 | module.add(Arc::new("play_forever__music".into()), play_forever__music, PreludeFunction { 33 | lts: vec![Lt::Default], 34 | tys: vec![Type::F64], 35 | ret: Type::Void 36 | }); 37 | module.add(Arc::new("play_once__music".into()), play_once__music, PreludeFunction { 38 | lts: vec![Lt::Default], 39 | tys: vec![Type::F64], 40 | ret: Type::Void 41 | }); 42 | module.add(Arc::new("play_once__sound".into()), play_once__sound, PreludeFunction { 43 | lts: vec![Lt::Default], 44 | tys: vec![Type::F64], 45 | ret: Type::Void 46 | }); 47 | module.add(Arc::new("set__sound_volume".into()), set__sound_volume, PreludeFunction { 48 | lts: vec![Lt::Default; 2], 49 | tys: vec![Type::F64; 2], 50 | ret: Type::Void 51 | }); 52 | } 53 | 54 | dyon_fn!{fn load__music(file: Arc) -> Result, String> { 55 | use std::path::Path; 56 | 57 | let music_tracks = unsafe { &mut *Current::::new() }; 58 | 59 | let track = { 60 | let path = Path::new(&**file); 61 | try!(mix::Music::from_file(&path)) 62 | }; 63 | music_tracks.push((file.clone(), track)); 64 | 65 | Ok(file) 66 | }} 67 | 68 | dyon_fn!{fn load__sound(file: Arc) -> Result, String> { 69 | use std::path::Path; 70 | 71 | let sound_tracks = unsafe { &mut *Current::::new() }; 72 | 73 | let track = { 74 | let path = Path::new(&**file); 75 | try!(mix::Chunk::from_file(&path)) 76 | }; 77 | sound_tracks.push((file.clone(), track)); 78 | 79 | Ok(file) 80 | }} 81 | 82 | dyon_fn!{fn music(name: Arc) -> Option { 83 | let music_tracks = unsafe { &*Current::::new() }; 84 | 85 | for (i, &(ref track, _)) in music_tracks.iter().enumerate() { 86 | if track == &name { return Some(i); } 87 | } 88 | None 89 | }} 90 | 91 | dyon_fn!{fn sound(name: Arc) -> Option { 92 | let sound_tracks = unsafe { &*Current::::new() }; 93 | 94 | for (i, &(ref track, _)) in sound_tracks.iter().enumerate() { 95 | if track == &name { return Some(i); } 96 | } 97 | None 98 | }} 99 | 100 | dyon_fn!{fn play_forever__music(ind: usize) { 101 | let music_tracks = unsafe { &*Current::::new() }; 102 | 103 | let _ = music_tracks[ind].1.play(-1); 104 | }} 105 | 106 | dyon_fn!{fn play_once__music(ind: usize) { 107 | let music_tracks = unsafe { &*Current::::new() }; 108 | 109 | let _ = music_tracks[ind].1.play(0); 110 | }} 111 | 112 | dyon_fn!{fn play_once__sound(ind: usize) { 113 | let sound_tracks = unsafe { &*Current::::new() }; 114 | 115 | let _ = mix::Channel::all().play(&sound_tracks[ind].1, 0); 116 | }} 117 | 118 | dyon_fn!{fn set__sound_volume(ind: usize, volume: f64) { 119 | let sound_tracks = unsafe { &mut *Current::::new() }; 120 | 121 | sound_tracks[ind].1.set_volume(volume as isize); 122 | }} 123 | -------------------------------------------------------------------------------- /src/explosions.dyon: -------------------------------------------------------------------------------- 1 | explosion_pos() = 0 2 | explosion_vel() = 1 3 | explosion_radius() = 2 4 | explosion_border() = 3 5 | explosion_time() = 4 6 | 7 | /// Stores [position, velocity, radius, border, time] 8 | fn init_explosions() -> [Explosion []] { 9 | return [[(0, 0), (0, 0), 0, 0, 0]; 30] 10 | } 11 | 12 | fn create_explosion__pos_vel_radius(pos: vec4, vel: vec4, radius: f64) 13 | ~ mut world: World, 14 | mut explosions: [Explosion []] 15 | { 16 | n := world.free_explosion_slot 17 | if n >= len(explosions) { return } 18 | 19 | POS := explosion_pos() 20 | VEL := explosion_vel() 21 | RADIUS := explosion_radius() 22 | BORDER := explosion_border() 23 | TIME := explosion_time() 24 | 25 | explosions[n][POS] = clone(pos) 26 | explosions[n][VEL] = clone(vel) 27 | explosions[n][RADIUS] = 0.5 * radius 28 | explosions[n][BORDER] = 0.5 * radius 29 | explosions[n][TIME] = 0 30 | 31 | world.free_explosion_slot += 1 32 | 33 | SOUND := sound_explosion_offset() 34 | COUNT := sound_explosion_count() 35 | play_once(sound: (world.explosion_settings.sound % COUNT) + SOUND) 36 | world.explosion_settings.sound += 1 37 | } 38 | 39 | fn move_explosions() 40 | ~ world: World, 41 | mut explosions: [Explosion []], 42 | dt: f64 43 | { 44 | POS := explosion_pos() 45 | VEL := explosion_vel() 46 | RADIUS := explosion_radius() 47 | TIME := explosion_time() 48 | 49 | expand_speed := world.explosion_settings.expand_speed 50 | for i world.free_explosion_slot { 51 | explosions[i][POS] += dt * explosions[i][VEL] 52 | explosions[i][RADIUS] += dt * expand_speed 53 | explosions[i][TIME] += dt 54 | } 55 | } 56 | 57 | fn remove_old_explosions() 58 | ~ mut world: World, 59 | mut explosions: [Explosion []] 60 | { 61 | TIME := explosion_time() 62 | 63 | max_time := world.explosion_settings.max_time 64 | for i := world.free_explosion_slot - 1; i >= 0; i -= 1 { 65 | if explosions[i][TIME] > max_time { 66 | world.free_explosion_slot = swap_remove(mut explosions, i, world.free_explosion_slot) 67 | } 68 | } 69 | } 70 | 71 | 72 | fn draw__explosions_active 73 | (explosions: [Explosion []], active: f64) 74 | ~ mut draw_list: [[]], world: World 75 | { 76 | POS := explosion_pos() 77 | VEL := explosion_vel() 78 | RADIUS := explosion_radius() 79 | BORDER := explosion_border() 80 | TIME := explosion_time() 81 | 82 | color := #ffffee 83 | max_time := world.explosion_settings.max_time 84 | reset_transform() 85 | for i active { 86 | center := explosions[i][POS] 87 | radius := explosions[i][RADIUS] 88 | border := explosions[i][BORDER] 89 | color := (xyz color, 1 - explosions[i][TIME] / max_time) 90 | circle(border: border, color: color, center: center, radius: radius, resolution: 32) 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/game.dyon: -------------------------------------------------------------------------------- 1 | 2 | fn init_world() -> World { 3 | comet_hit_radius := 10 4 | return { 5 | paused: false, 6 | input_state: { 7 | left: 0, 8 | right: 0, 9 | forward: 0, 10 | backward: 0, 11 | fire: 0, 12 | }, 13 | input_settings: { 14 | angle_vel: 0.015, 15 | acceleration_forward: 1.0, 16 | acceleration_backward: 1.0, 17 | }, 18 | spaceship: { 19 | pos: (300, 300), 20 | vel: (10, 0), 21 | angle: 0, 22 | fire_dt: 0, 23 | roll: 0, // The roll angle of spaceship. 24 | roll_change: 20, // How fast to change roll angle. 25 | roll_max: 1.0, 26 | }, 27 | free_bullet_slot: 0, 28 | free_comet_slot: 0, 29 | free_explosion_slot: 0, 30 | bullet_settings: { 31 | speed: 1000, 32 | interval: 0.285, 33 | sound: 0, 34 | }, 35 | comet_settings: { 36 | radius: 30, 37 | hit_radius: clone(comet_hit_radius), 38 | min_radius: 10, 39 | speed: 30, 40 | spawn_probability: 0.0001, 41 | }, 42 | explosion_settings: { 43 | max_time: 2, 44 | expand_speed: 20, 45 | sound: 0, 46 | }, 47 | space_settings: { 48 | offset: 30, 49 | }, 50 | collision_settings: { 51 | window_size := window_size() 52 | units := comet_hit_radius / sqrt(2) 53 | 54 | { 55 | units: clone(units), 56 | w: ceil(x(window_size) / units), 57 | h: ceil(y(window_size) / units) 58 | } 59 | } 60 | } 61 | } 62 | 63 | fn render_world() 64 | ~ world: World, 65 | bullets: [Bullet []], 66 | comets: [Comet []], 67 | explosions: [Explosion []], 68 | mut draw_list: [[]] 69 | { 70 | clear(color: #000000) 71 | draw(explosions: explosions, active: world.free_explosion_slot) 72 | draw(bullets: bullets, active: world.free_bullet_slot) 73 | draw(comets: comets, active: world.free_comet_slot) 74 | // draw(spaceship: world.spaceship) 75 | draw(draw_list) 76 | clear(mut draw_list) 77 | 78 | // TEST 79 | clear_depth() 80 | draw_spaceship_3d(world.spaceship) 81 | } 82 | 83 | fn update_world() 84 | ~ mut world: World, 85 | dt: f64, 86 | mut bullets: [Bullet []], 87 | mut comets: [Comet []], 88 | mut collision_grid: CollisionGrid [[f64]] 89 | { 90 | if world.paused { return } 91 | 92 | ~ space := window_size() 93 | 94 | spawn_comets() 95 | fire(world: mut world, dt: dt) 96 | move_spaceship() 97 | move_bullets() 98 | move_comets() 99 | move_explosions() 100 | shoot_comets() 101 | remove_hidden_bullets(world: mut world, offset: world.space_settings.offset) 102 | remove_old_explosions() 103 | } 104 | -------------------------------------------------------------------------------- /src/input.dyon: -------------------------------------------------------------------------------- 1 | key_a() = 97 2 | key_d() = 100 3 | key_w() = 119 4 | key_s() = 115 5 | key_space() = 32 6 | key_up() = 1073741906 7 | key_left() = 1073741904 8 | key_right() = 1073741903 9 | key_down() = 1073741905 10 | key_p() = 112 11 | 12 | forward(key: f64) = (key == key_w()) || (key == key_up()) 13 | turn_left(key: f64) = (key == key_a()) || (key == key_left()) 14 | turn_right(key: f64) = (key == key_d()) || (key == key_right()) 15 | backward(key: f64) = (key == key_s()) || (key == key_down()) 16 | pause(key: f64) = key == key_p() 17 | 18 | fn event() { 19 | handle(key: press_keyboard_key(), value: 1) 20 | handle(key: release_keyboard_key(), value: 0) 21 | } 22 | 23 | fn handle__key_value(key: opt[f64], val: f64) ~ mut world: World { 24 | if key == none() { return } 25 | key := unwrap(key) 26 | if pause(key) && (val == 1) { 27 | world.paused = !world.paused 28 | } else if turn_left(key) { 29 | world.input_state.left = clone(val) 30 | } else if turn_right(key) { 31 | world.input_state.right = clone(val) 32 | } else if forward(key) { 33 | world.input_state.forward = clone(val) 34 | } else if backward(key) { 35 | world.input_state.backward = clone(val) 36 | } else if key == key_space() { 37 | world.input_state.fire = clone(val) 38 | } else { 39 | // print("Key: ") 40 | // println(key) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/lib.dyon: -------------------------------------------------------------------------------- 1 | /// Renders a list of draw commands. 2 | fn draw(draw_list: []) { ... } 3 | 4 | /// Returns `true` if there is a next event. 5 | fn next_event() -> bool { ... } 6 | 7 | /// ==== OBJ ==== 8 | 9 | /// Loads a material from file, returning `ok(file)` if successful. 10 | fn load_material(file: str) -> res[str] { ... } 11 | 12 | /// Gets the index of a material. 13 | fn material(name: str) -> opt[f64] { ... } 14 | 15 | /// Get list of materials. 16 | fn materials() -> [str] { ... } 17 | 18 | /// Loads a 3D object from file, returning `ok(file)` if successful. 19 | fn load_obj(file: str) -> res[str] { ... } 20 | 21 | /// Gets the index of a 3D object. 22 | fn obj(name: str) -> opt[f64] { ... } 23 | 24 | /// Get a list of objects. 25 | fn objs() -> [str] { ... } 26 | 27 | /// Gets material library from 3D object index. 28 | fn material_library_obj(obj: f64) -> opt[str] { ... } 29 | 30 | /// Gets number of objects in a 3D obj. 31 | fn object_count_obj(obj: f64) -> f64 { ... } 32 | 33 | /// Gets list of objects from 3D object index. 34 | fn objects_obj(obj: f64) -> [str] { ... } 35 | 36 | /// Gets number of vertices of an object. 37 | fn vertex_count_obj_object(obj: f64, object: f64) -> f64 { ... } 38 | 39 | /// Gets number of texture coordinates of an object. 40 | fn tex_vertex_count_obj_object(obj: f64, object: f64) -> f64 { ... } 41 | 42 | /// Gets number of normals from an object. 43 | fn normal_count_obj_object(obj: f64, object: f64) -> f64 { ... } 44 | 45 | /// Gets number of geometries of an object. 46 | fn geometry_count_obj_object(obj: f64, object: f64) -> f64 { ... } 47 | 48 | /// Gets a single vertex. 49 | fn vertex_obj_object_vertex(obj: f64, object: f64, vertex: f64) -> vec4 { ... } 50 | 51 | /// Gets a single texture coordinate. 52 | fn tex_vertex_obj_object_tex_vertex(obj: f64, object: f64, tex_vertex: f64) -> vec4 { ... } 53 | 54 | /// Gets a single normal. 55 | fn normal_obj_object_normal(obj: f64, object: f64, normal: f64) -> vec4 { ... } 56 | 57 | /// Gets vertices of an object. 58 | fn vertices_obj_object(obj: f64, object: f64) -> [vec4] { ... } 59 | 60 | /// Gets texture coordinates of an object. 61 | fn tex_vertices_obj_object(obj: f64, object: f64) -> [vec4] { ... } 62 | 63 | /// Gets normals of an object. 64 | fn normals_obj_object(obj: f64, object: f64) -> [vec4] { ... } 65 | 66 | /// Gets geometry of an object. 67 | fn geometry_obj_object(obj: f64, object: f64) -> [{}] { ... } 68 | 69 | /// ==== SHADER ==== 70 | 71 | /// Loads program from a vertex and fragment shader. 72 | /// Returns `ok(name)` if program is created successfully. 73 | fn load_program_name_vshader_fshader(name: str, vshader: str, fshader: str) -> res[str] { ... } 74 | 75 | /// Gets the index of a shader program. 76 | fn program(name: str) -> opt[f64] { ... } 77 | 78 | /// Creates a new empty vertex buffer. 79 | fn create_vertex_buffer_size(size: f64) -> res[f64] { ... } 80 | 81 | /// Creates a new empty index buffer. 82 | fn create_index_buffer_size(size: f64) -> res[f64] { ... } 83 | 84 | /// Fills a vertex buffer. 85 | fn fill_vertex_buffer_buffer_pos_norm(buffer: f64, pos: [vec4], norm: [vec4]) { ... } 86 | 87 | /// Fills an index buffer. 88 | fn fill_index_buffer_buffer_data(buffer: f64, data: [f64]) { ... } 89 | -------------------------------------------------------------------------------- /src/main.dyon: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println(link { 3 | "Dyon: ASTEROIDS\n" 4 | "===============\n" 5 | "Use W,A,S,D or arrows to steer, SPACE to shoot\n" 6 | }) 7 | 8 | // TEST 9 | assets := unwrap(load("src/assets.dyon")) 10 | _ := unwrap(call_ret(assets, "load_assets", [])) 11 | 12 | test_math := false 13 | test_utils := false 14 | 15 | math := unwrap(load("src/std/math3.dyon")) 16 | if test_math { 17 | call(math, "test", []) 18 | return 19 | } 20 | 21 | utils := unwrap(load("src/std/utils.dyon")) 22 | if test_utils { 23 | call(utils, "test", []) 24 | return 25 | } 26 | 27 | input := unwrap(load("src/input.dyon")) 28 | render := unwrap(load(source: "src/std/render.dyon", imports: [math])) 29 | space := unwrap(load(source: "src/space.dyon", imports: [utils])) 30 | bullets := unwrap(load(source: "src/bullets.dyon", imports: [space, render, assets])) 31 | spaceship := unwrap(load(source: "src/spaceship.dyon", imports: [bullets])) 32 | explosions := unwrap(load(source: "src/explosions.dyon", imports: [utils, render, assets])) 33 | comets := unwrap(load(source: "src/comets.dyon", imports: [bullets, explosions])) 34 | game := unwrap(load(source: "src/game.dyon", 35 | imports: [input, spaceship, bullets, comets, explosions])) 36 | ~ world := call_ret(game, "init_world", []) 37 | ~ bullets := call_ret(game, "init_bullets", []) 38 | ~ comets := call_ret(game, "init_comets", []) 39 | ~ explosions := call_ret(game, "init_explosions", []) 40 | ~ collision_grid := call_ret(game, "init_collision_grid_settings", 41 | [world.collision_settings]) 42 | ~ draw_list := [] 43 | loop { 44 | if !next_event() { break } 45 | if render() { 46 | call(game, "render_world", []) 47 | } else if update() { 48 | ~ dt := unwrap(update_dt()) 49 | call(game, "update_world", []) 50 | } else { 51 | call(game, "event", []) 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate glium_graphics; 2 | #[macro_use] 3 | extern crate glium; 4 | extern crate piston; 5 | #[macro_use] 6 | extern crate dyon; 7 | extern crate current; 8 | extern crate dyon_interactive; 9 | extern crate sdl2_window; 10 | extern crate sdl2; 11 | extern crate sdl2_mixer; 12 | extern crate wavefront_obj; 13 | extern crate vecmath; 14 | 15 | use sdl2_window::Sdl2Window; 16 | use sdl2_mixer as mix; 17 | use glium_graphics::{Glium2d, GliumWindow, OpenGL}; 18 | use piston::window::WindowSettings; 19 | use piston::input::Event; 20 | use dyon::{error, load, Module, Runtime}; 21 | use current::CurrentGuard; 22 | 23 | use engine::{IndexBuffers, Materials, MusicTracks, ObjSets, Programs, 24 | SoundTracks, VertexBuffers}; 25 | 26 | mod engine; 27 | 28 | type Window = GliumWindow; 29 | 30 | fn main() { 31 | let opengl = OpenGL::V3_2; 32 | let ref mut window: Window = WindowSettings::new("Dyon: Asteroids!", [512, 512]) 33 | .opengl(opengl).samples(4).exit_on_esc(true).build().unwrap(); 34 | 35 | let mut runtime = Runtime::new(); 36 | let module = match load_module() { 37 | None => return, 38 | Some(m) => m 39 | }; 40 | 41 | init_audio(); 42 | 43 | let (audio, timer) = { 44 | let ref sdl = window.window.borrow().sdl_context; 45 | (sdl.audio().unwrap(), sdl.timer().unwrap()) 46 | }; 47 | 48 | let mut g2d = Glium2d::new(opengl, window); 49 | let mut e: Option = None; 50 | let mut target = window.draw(); 51 | let mut materials: Materials = vec![]; 52 | let mut obj_sets: ObjSets = vec![]; 53 | let mut programs: Programs = vec![]; 54 | let mut vertex_buffers: VertexBuffers = vec![]; 55 | let mut index_buffers: IndexBuffers = vec![]; 56 | let mut music_tracks: MusicTracks = vec![]; 57 | let mut sound_tracks: SoundTracks = vec![]; 58 | 59 | { 60 | let window_guard = CurrentGuard::new(window); 61 | let event_guard: CurrentGuard> = CurrentGuard::new(&mut e); 62 | let g2d_guard = CurrentGuard::new(&mut g2d); 63 | let target_guard = CurrentGuard::new(&mut target); 64 | let materials_guard = CurrentGuard::new(&mut materials); 65 | let obj_sets_guard = CurrentGuard::new(&mut obj_sets); 66 | let programs_guard = CurrentGuard::new(&mut programs); 67 | let vertex_buffers_guard = CurrentGuard::new(&mut vertex_buffers); 68 | let index_buffers_guard = CurrentGuard::new(&mut index_buffers); 69 | let music_tracks_guard = CurrentGuard::new(&mut music_tracks); 70 | let sound_tracks_guard = CurrentGuard::new(&mut sound_tracks); 71 | if error(runtime.run(&module)) { 72 | return; 73 | } 74 | drop(sound_tracks_guard); 75 | drop(music_tracks_guard); 76 | drop(index_buffers_guard); 77 | drop(vertex_buffers_guard); 78 | drop(programs_guard); 79 | drop(obj_sets_guard); 80 | drop(materials_guard); 81 | drop(target_guard); 82 | drop(g2d_guard); 83 | drop(event_guard); 84 | drop(window_guard); 85 | } 86 | 87 | target.finish().unwrap(); 88 | 89 | drop(timer); 90 | drop(audio); 91 | drop(window); 92 | } 93 | 94 | fn init_audio() { 95 | // Load dynamic libraries. 96 | // Ignore formats that are not built in. 97 | let _ = mix::init( 98 | mix::INIT_MP3 99 | | mix::INIT_FLAC 100 | | mix::INIT_MOD 101 | | mix::INIT_FLUIDSYNTH 102 | | mix::INIT_MODPLUG 103 | | mix::INIT_OGG 104 | ); 105 | mix::open_audio( 106 | // Use cd quality to avoid noise artifacts. 107 | mix::DEFAULT_FREQUENCY * 2, 108 | mix::DEFAULT_FORMAT, 109 | mix::DEFAULT_CHANNELS, 110 | 1024 111 | ).unwrap(); 112 | // Allow up to 8 sounds playing at the same time. 113 | mix::allocate_channels(8); 114 | } 115 | 116 | fn load_module() -> Option { 117 | use std::sync::Arc; 118 | use dyon_functions::*; 119 | use dyon_interactive::add_functions; 120 | use dyon::{Lt, Module, PreludeFunction, Type}; 121 | 122 | let mut module = Module::new(); 123 | add_functions::(&mut module); 124 | module.add(Arc::new("draw".into()), draw, PreludeFunction { 125 | lts: vec![Lt::Default], 126 | tys: vec![Type::array()], 127 | ret: Type::Void 128 | }); 129 | module.add(Arc::new("next_event".into()), 130 | next_event, PreludeFunction { 131 | lts: vec![], 132 | tys: vec![], 133 | ret: Type::Bool 134 | }); 135 | engine::register_obj(&mut module); 136 | engine::register_shader(&mut module); 137 | engine::register_sound(&mut module); 138 | if error(load("src/main.dyon", &mut module)) { 139 | None 140 | } else { 141 | Some(module) 142 | } 143 | } 144 | 145 | mod dyon_functions { 146 | use dyon::Runtime; 147 | use dyon_interactive::{draw_2d, NO_EVENT}; 148 | use current::Current; 149 | use super::Window; 150 | 151 | pub fn draw(rt: &mut Runtime) -> Result<(), String> { 152 | use piston::input::*; 153 | use glium_graphics::Glium2d; 154 | use glium::Frame; 155 | 156 | let e = unsafe { &*Current::>::new() }; 157 | let g2d = unsafe { &mut *Current::::new() }; 158 | let target = unsafe { &mut *Current::::new() }; 159 | if let &Some(ref e) = e { 160 | if let Some(args) = e.render_args() { 161 | g2d.draw(target, args.viewport(), |c, g| { 162 | draw_2d(rt, c, g) 163 | }) 164 | } else { 165 | Ok(()) 166 | } 167 | } else { 168 | Err(NO_EVENT.into()) 169 | } 170 | } 171 | 172 | pub fn next_event(rt: &mut Runtime) -> Result<(), String> { 173 | use piston::input::*; 174 | use glium::Frame; 175 | 176 | let window = unsafe { &mut *Current::::new() }; 177 | let e = unsafe { &mut *Current::>::new() }; 178 | let target = unsafe { &mut *Current::::new() }; 179 | if let Some(new_e) = window.next() { 180 | if new_e.after_render_args().is_some() { 181 | target.set_finish().unwrap(); 182 | *target = window.draw(); 183 | } 184 | *e = Some(new_e); 185 | rt.push(true); 186 | } else { 187 | *e = None; 188 | rt.push(false); 189 | } 190 | Ok(()) 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /src/space.dyon: -------------------------------------------------------------------------------- 1 | fn is_outside__pos_space_offset(pos: vec4, space: vec4, offset: f64) -> bool { 2 | return any i 2 { 3 | (s(pos, i) < (-offset)) or (s(pos, i) > (s(space, i) + offset)) 4 | } 5 | } 6 | 7 | fn warp__pos_offset(pos: vec4, offset: f64) ~ space: vec4 -> vec4 { 8 | x := x(pos) 9 | y := y(pos) 10 | double_offset := offset * 2 11 | wx := x(space) 12 | wy := y(space) 13 | if x < -offset { x += wx + double_offset } 14 | if y < -offset { y += wy + double_offset } 15 | if x > wx + offset { x -= wx + double_offset } 16 | if y > wy + offset { y -= wy + double_offset } 17 | return (x, y) 18 | } 19 | -------------------------------------------------------------------------------- /src/spaceship.dyon: -------------------------------------------------------------------------------- 1 | 2 | fn move_spaceship() 3 | ~ mut world: World, 4 | dt: f64 5 | { 6 | world.spaceship.angle += angle_motion_left_right(world) 7 | dir := dir(angle: world.spaceship.angle) 8 | world.spaceship.vel += dir * acceleration_forward_backward(world) 9 | 10 | world.spaceship.pos += dt * world.spaceship.vel 11 | world.spaceship.pos = warp(pos: world.spaceship.pos, 12 | offset: world.space_settings.offset) 13 | 14 | target_roll := -world.spaceship.roll_max * (world.input_state.right - world.input_state.left) 15 | world.spaceship.roll += world.spaceship.roll_change * dt * (target_roll - world.spaceship.roll) 16 | } 17 | 18 | fn angle_motion_left_right(world: World) -> f64 { 19 | return world.input_settings.angle_vel * 20 | (world.input_state.right - world.input_state.left) 21 | } 22 | 23 | /// Computes the acceleration for the direction forward/backward. 24 | fn acceleration_forward_backward(world: World) -> f64 { 25 | return world.input_settings.acceleration_forward * 26 | world.input_state.forward - 27 | world.input_settings.acceleration_backward * 28 | world.input_state.backward 29 | } 30 | 31 | fn draw__spaceship(spaceship) ~ mut draw_list { 32 | color := #ffffff 33 | transform(center: spaceship.pos, angle: spaceship.angle) 34 | triangle(color: color, 35 | center: spaceship.pos, radius: 20) 36 | triangle(color: color, 37 | center: spaceship.pos + (15, 0), radius: 15) 38 | } 39 | 40 | fn draw_spaceship_3d(spaceship) ~ world { 41 | program := 0 42 | scale := 5 43 | metal_vbuf := 0 44 | metal_ibuf := 0 45 | glass_vbuf := 1 46 | glass_ibuf := 1 47 | anglex := spaceship.roll 48 | 49 | draw(program: program, vbuf: metal_vbuf, ibuf: metal_ibuf, pos: spaceship.pos, 50 | angle: spaceship.angle, scale: scale, color: #333333, anglex: anglex) 51 | draw(program: program, vbuf: glass_vbuf, ibuf: glass_ibuf, pos: spaceship.pos, 52 | angle: spaceship.angle, scale: scale, color: #111111, anglex: anglex) 53 | // draw(program: program, vbuf: 2, ibuf: 2, pos: spaceship.pos, 54 | // angle: spaceship.angle, scale: 20, color: #ffff00) 55 | } 56 | -------------------------------------------------------------------------------- /src/std/math.dyon: -------------------------------------------------------------------------------- 1 | δ(x: f64) = if x == 0 { 1 } else { 0 } 2 | 3 | fn multiply_mat_mat(a: [vec4], b: [vec4]) -> [vec4] { 4 | return sift i { vec4 j a[i] *. vec4 k s(b[k], j) } 5 | } 6 | 7 | fn identity() -> [vec4] { 8 | return sift i 4 { vec4 j δ(i - j) } 9 | } 10 | 11 | fn translate(v: vec4) -> [vec4] { 12 | return sift i 4 { 13 | vec4 j δ(i - j) + δ(j - 3) * s(v, i) 14 | } 15 | } 16 | 17 | rotate_angle(angle: f64) = [ 18 | (cos(angle), -sin(angle), 0, 0), 19 | (sin(angle), cos(angle), 0, 0), 20 | (0, 0, 1, 0), 21 | (0, 0, 0, 1) 22 | ] 23 | 24 | fn scale(s: f64) -> [vec4] { 25 | return sift i 4 { 26 | vec4 j if (i == j) and (i < 3) { s } 27 | else if i == j { 1 } 28 | else { 0 } 29 | } 30 | } 31 | 32 | shear(v: vec4) = [ 33 | (1, x(v), 0, 0), 34 | (y(v), 1, 0, 0), 35 | (0, 0, 1, 0), 36 | (0, 0, 0, 1) 37 | ] 38 | 39 | fn orient(pos: vec4) -> [vec4] { 40 | len := |pos| 41 | if len == 0 { return identity() } 42 | c := x(pos) / len 43 | s := y(pos) / len 44 | return [ 45 | (c, -s, 0, 0), 46 | (s, c, 0, 0), 47 | (0, 0, 1, 0), 48 | (0, 0, 0, 1) 49 | ] 50 | } 51 | 52 | fn print_mat(mat: [vec4]) { 53 | for i { 54 | print(x(mat[i])) 55 | print(",") 56 | print(y(mat[i])) 57 | print(",") 58 | print(z(mat[i])) 59 | print(",") 60 | print(w(mat[i])) 61 | println("") 62 | } 63 | println("") 64 | } 65 | 66 | fn test() { 67 | print(mat: identity()) 68 | print(mat: translate((2, 3, 4))) 69 | print(mat: rotate(angle: 0.1)) 70 | print(mat: orient((0, 1))) 71 | print(mat: scale(2)) 72 | print(mat: shear((1, 0))) 73 | 74 | mat := multiply(mat: translate((2, 3)), 75 | mat: rotate(angle: 0.1)) 76 | println(mat) 77 | } 78 | -------------------------------------------------------------------------------- /src/std/math2.dyon: -------------------------------------------------------------------------------- 1 | δ(x: f64) = if x == 0 { 1 } else { 0 } 2 | identity() = sift i 4, j 4 { δ(i - j) } 3 | multiply_mat_mat(a: [[f64]], b: [[f64]]) = 4 | sift i, j 4 { sum k { a[i][k] * b[k][j] } } 5 | translate(x: f64, y: f64, z: f64) = 6 | [ 7 | [1, 0, 0, clone(x)], 8 | [0, 1, 0, clone(y)], 9 | [0, 0, 1, clone(z)], 10 | [0, 0, 0, 1], 11 | ] 12 | rotate(angle) = 13 | [ 14 | [cos(angle), -sin(angle), 0, 0], 15 | [sin(angle), cos(angle), 0, 0], 16 | [0, 0, 1, 0], 17 | [0, 0, 0, 1] 18 | ] 19 | scale(s: f64) = 20 | [ 21 | [clone(s), 0, 0, 0], 22 | [0, clone(s), 0, 0], 23 | [0, 0, clone(s), 0], 24 | [0, 0, 0, 1] 25 | ] 26 | shear(x: f64, y: f64) = [ 27 | [1, clone(x), 0, 0], 28 | [clone(y), 1, 0, 0], 29 | [0, 0, 1, 0], 30 | [0, 0, 0, 1] 31 | ] 32 | orient(x: f64, y: f64) = { 33 | len := |(x, y)| 34 | if len == 0 { return identity() } 35 | c := x / len 36 | s := y / len 37 | [ 38 | [clone(c), -s, 0, 0], 39 | [clone(s), clone(c), 0, 0], 40 | [0, 0, 1, 0], 41 | [0, 0, 0, 1] 42 | ] 43 | } 44 | transform_mat_vec(mat: [[f64]], v: vec4) = vec4 i (vec4 j mat[i][j]) *. v 45 | point(v: vec4) = (xyz v, 1) 46 | 47 | fn test() { 48 | a := translate(xyz (1, 2)) 49 | b := translate(xyz (2, 1)) 50 | c := multiply(mat: a, mat: b) 51 | println(c) 52 | } 53 | -------------------------------------------------------------------------------- /src/std/math3.dyon: -------------------------------------------------------------------------------- 1 | pi() = 3.141592653589793 2 | tau() = 2 * pi() 3 | 4 | fn clamp__pos_aa_bb(pos: vec4, aa: vec4, bb: vec4) -> { 5 | return vec4 i { 6 | s := s(pos, i) 7 | if s < s(aa, i) { s = s(aa, i) } 8 | if s > s(bb, i) { s = s(bb, i) } 9 | clone(s) 10 | } 11 | } 12 | 13 | identity() = [ 14 | (1, 0, 0), 15 | (0, 1, 0) 16 | ] 17 | multiply__mat_mat(a: [vec4], b: [vec4]) = [ 18 | ( 19 | x(a[0]) * s(b[0], 0) + y(a[0]) * s(b[1], 0), 20 | x(a[0]) * s(b[0], 1) + y(a[0]) * s(b[1], 1), 21 | x(a[0]) * s(b[0], 2) + y(a[0]) * s(b[1], 2) + z(a[0]), 22 | ), 23 | ( 24 | x(a[1]) * s(b[0], 0) + y(a[1]) * s(b[1], 0), 25 | x(a[1]) * s(b[0], 1) + y(a[1]) * s(b[1], 1), 26 | x(a[1]) * s(b[0], 2) + y(a[1]) * s(b[1], 2) + z(a[1]), 27 | ) 28 | ] 29 | translate(x: f64, y: f64) = 30 | [ 31 | (1, 0, x), 32 | (0, 1, y), 33 | ] 34 | rotate(angle: f64) = 35 | [ 36 | (cos(angle), -sin(angle), 0), 37 | (sin(angle), cos(angle), 0) 38 | ] 39 | rotate__x_y_angle(x: f64, y: f64, angle: f64) = 40 | multiply(mat: multiply(mat: translate(x, y), mat: rotate(angle)), 41 | mat: translate(-x, -y)) 42 | /* 43 | scale(s: f64) = 44 | [ 45 | [clone(s), 0, 0, 0], 46 | [0, clone(s), 0, 0], 47 | [0, 0, clone(s), 0], 48 | [0, 0, 0, 1] 49 | ] 50 | shear(x: f64, y: f64) = [ 51 | [1, clone(x), 0, 0], 52 | [clone(y), 1, 0, 0], 53 | [0, 0, 1, 0], 54 | [0, 0, 0, 1] 55 | ] 56 | orient(x: f64, y: f64) = { 57 | len := |(x, y)| 58 | if len == 0 { return identity() } 59 | c := x / len 60 | s := y / len 61 | [ 62 | [clone(c), -s, 0, 0], 63 | [clone(s), clone(c), 0, 0], 64 | [0, 0, 1, 0], 65 | [0, 0, 0, 1] 66 | ] 67 | } 68 | transform_mat_vec(mat: [[f64]], v: vec4) = vec4 i (vec4 j mat[i][j]) *. v 69 | point(v: vec4) = (xyz v, 1) 70 | */ 71 | 72 | fn test() { 73 | a := translate(xy (1, 2)) 74 | b := translate(xy (2, 1)) 75 | c := multiply(mat: a, mat: b) 76 | println(c) 77 | } 78 | -------------------------------------------------------------------------------- /src/std/render.dyon: -------------------------------------------------------------------------------- 1 | /* 2 | Wraps a nice interface around draw list commands. 3 | */ 4 | 5 | fn clear__color(color: vec4) 6 | ~ mut draw_list: [[]] { 7 | push(mut draw_list, ["clear", color]) 8 | } 9 | 10 | fn line__color_radius_from_to(color: vec4, radius: f64, from: vec4, to: vec4) 11 | ~ mut draw_list: [[]] { 12 | push(mut draw_list, ["line_color_radius_from_to", color, radius, from, to]) 13 | } 14 | 15 | fn rectangle__color_corner_size(color: vec4, corner: vec4, size: vec4) 16 | ~ mut draw_list: [[]] { 17 | push(mut draw_list, ["rectangle_color_corner_size", color, corner, size]) 18 | } 19 | 20 | fn ellipse__color_corner_size(color: vec4, corner: vec4, size: vec4) 21 | ~ mut draw_list: [[]] { 22 | ellipse(color: color, corner: corner, size: size, resolution: 16) 23 | } 24 | 25 | fn ellipse__border_color_corner_size(border: f64, color: vec4, corner: vec4, size: vec4) 26 | ~ mut draw_list: [[]] { 27 | ellipse(border: border, color: color, corner: corner, size: size, resolution: 16) 28 | } 29 | 30 | fn ellipse__color_corner_size_resolution 31 | (color: vec4, corner: vec4, size: vec4, resolution: f64) 32 | ~ mut draw_list: [[]] { 33 | push(mut draw_list, ["ellipse_color_corner_size_resolution", color, corner, size, resolution]) 34 | } 35 | 36 | fn ellipse__border_color_corner_size_resolution 37 | (border: f64, color: vec4, corner: vec4, size: vec4, resolution: f64) 38 | ~ mut draw_list: [[]] { 39 | push(mut draw_list, ["ellipse_border_color_corner_size_resolution", 40 | border, color, corner, size, resolution]) 41 | } 42 | 43 | fn circle__color_center_radius(color: vec4, center: vec4, radius: f64) 44 | ~ mut draw_list: [[]] { 45 | width := 2 * radius 46 | ellipse(color: color, corner: center - radius, size: (width, width)) 47 | } 48 | 49 | fn circle__color_center_radius_resolution 50 | (color: vec4, center: vec4, radius: f64, resolution: f64) 51 | ~ mut draw_list: [[]] { 52 | width := 2 * radius 53 | ellipse(color: color, corner: center - radius, size: (width, width), 54 | resolution: resolution) 55 | } 56 | 57 | fn circle__border_color_center_radius(border: f64, color: vec4, center: vec4, radius: f64) 58 | ~ mut draw_list: [[]] { 59 | width := 2 * radius 60 | ellipse(border: border, color: color, corner: center - radius, size: (width, width)) 61 | } 62 | 63 | fn circle__border_color_center_radius_resolution 64 | (border: f64, color: vec4, center: vec4, radius: f64, resolution: f64) 65 | ~ mut draw_list: [[]] { 66 | width := 2 * radius 67 | ellipse(border: border, color: color, corner: center - radius, size: (width, width), 68 | resolution: resolution) 69 | } 70 | 71 | fn triangle__color_center_radius(color: vec4, center: vec4, radius: f64) 72 | ~ mut draw_list: [[]] { 73 | circle(color: color, center: center, radius: radius, resolution: 3) 74 | } 75 | 76 | fn transform__center_angle(center: vec4, angle: f64) 77 | ~ mut draw_list: [[]] { 78 | mat := rotate(x_y: xy center, angle: angle) 79 | push(mut draw_list, ["transform_rx_ry", mat[0], mat[1]]) 80 | } 81 | 82 | fn reset_transform() 83 | ~ mut draw_list: [[]] { 84 | mat := identity() 85 | push(mut draw_list, ["transform_rx_ry", mat[0], mat[1]]) 86 | } 87 | -------------------------------------------------------------------------------- /src/std/utils.dyon: -------------------------------------------------------------------------------- 1 | fn swap_remove(mut list: [], ind: f64, n: f64) -> f64 { 2 | if n == 0 { return clone(n) } 3 | if (ind + 1) < n { 4 | swap(mut list, ind, n - 1) 5 | } 6 | return n - 1 7 | } 8 | 9 | fn test() { 10 | list := [1, 2, 3, 4, 0] 11 | n := 4 12 | 13 | for i 3 { 14 | n = swap_remove(mut list, 0, n) 15 | print("list: ") 16 | println(list) 17 | print("n: ") 18 | println(n) 19 | } 20 | } 21 | --------------------------------------------------------------------------------