]> gitweb.factorcode.org Git - factor.git/blob - extra/game/debug/tests/tests.factor
b6bcacc780e497428e363e591b466f38c76090d8
[factor.git] / extra / game / debug / tests / tests.factor
1 ! Copyright (C) 2010 Erik Charlebois
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors colors.constants game.loop game.worlds gpu
4 gpu.framebuffers gpu.util.wasd game.debug kernel literals locals
5 make math math.constants math.matrices math.parser sequences
6 alien.c-types specialized-arrays ui.gadgets.worlds ui.pixel-formats ;
7 FROM: alien.c-types => float ;
8 SPECIALIZED-ARRAY: float
9 IN: game.debug.tests
10
11 :: clear-screen ( color -- )
12     system-framebuffer {
13         { default-attachment color }
14     } clear-framebuffer ;
15
16 : deg>rad ( d -- r )
17     180 / pi * ;
18
19 :: draw-debug-tests ( world -- )
20     world [ wasd-p-matrix ] [ wasd-mv-matrix ] bi m. :> mvp-matrix
21     { 0 0 0 } clear-screen
22     
23     [
24         { 0 0 0 } { 1 0 0 } COLOR: red   debug-line
25         { 0 0 0 } { 0 1 0 } COLOR: green debug-line
26         { 0 0 0 } { 0 0 1 } COLOR: blue  debug-line
27         { -1.2 0 0 } { 0 1 0 } 0 deg>rad rotation-matrix3 debug-axes
28         { 3 5 -2 } { 3 2 1 } COLOR: white debug-box
29         { 0 9 0 } 8 2 COLOR: blue debug-cylinder
30     ] float-array{ } make
31     mvp-matrix draw-debug-lines
32
33     [
34         { 0 4.0 0 } COLOR: red debug-point
35         { 0 4.1 0 } COLOR: green debug-point
36         { 0 4.2 0 } COLOR: blue debug-point
37     ] float-array{ } make
38     mvp-matrix draw-debug-points
39
40     "Frame: " world frame#>> number>string append
41     COLOR: purple { 5 5 } world dim>> draw-text
42     world [ 1 + ] change-frame# drop ;
43
44 TUPLE: tests-world < wasd-world frame# ;
45 M: tests-world draw-world* draw-debug-tests ;
46 M: tests-world wasd-movement-speed drop 1/16. ;
47 M: tests-world wasd-near-plane drop 1/32. ;
48 M: tests-world wasd-far-plane drop 1024.0 ;
49 M: tests-world begin-game-world
50     init-gpu
51     0 >>frame#
52     { 0.0 0.0 2.0 } 0 0 set-wasd-view drop ;
53
54 GAME: run-tests {
55         { world-class tests-world }
56         { title "game.debug.tests" }
57         { pixel-format-attributes {
58             windowed
59             double-buffered
60             T{ depth-bits { value 24 } }
61         } }
62         { grab-input? t }
63         { use-game-input? t }
64         { pref-dim { 1024 768 } }
65         { tick-interval-nanos $[ 60 fps ] }
66     } ;
67
68 MAIN: run-tests