PageRenderTime 87ms CodeModel.GetById 73ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/extra/game/debug/tests/tests.factor

http://github.com/abeaumont/factor
Unknown | 68 lines | 59 code | 9 blank | 0 comment | 0 complexity | 53d4bfbaf30d20d25c1daa5a3f0beef9 MD5 | raw file
 1! Copyright (C) 2010 Erik Charlebois
 2! See http://factorcode.org/license.txt for BSD license.
 3USING: accessors colors.constants game.loop game.worlds gpu
 4gpu.framebuffers gpu.util.wasd game.debug kernel literals locals
 5make math math.constants math.matrices math.parser sequences
 6alien.c-types specialized-arrays ui.gadgets.worlds ui.pixel-formats ;
 7FROM: alien.c-types => float ;
 8SPECIALIZED-ARRAY: float
 9IN: 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
44TUPLE: tests-world < wasd-world frame# ;
45M: tests-world draw-world* draw-debug-tests ;
46M: tests-world wasd-movement-speed drop 1/16. ;
47M: tests-world wasd-near-plane drop 1/32. ;
48M: tests-world wasd-far-plane drop 1024.0 ;
49M: 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
54GAME: 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
68MAIN: run-tests