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