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

http://github.com/abeaumont/factor · Factor · 68 lines · 57 code · 9 blank · 2 comment · 1 complexity · 53d4bfbaf30d20d25c1daa5a3f0beef9 MD5 · raw file

  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. :: clear-screen ( color -- )
  11. system-framebuffer {
  12. { default-attachment color }
  13. } clear-framebuffer ;
  14. : deg>rad ( d -- r )
  15. 180 / pi * ;
  16. :: draw-debug-tests ( world -- )
  17. world [ wasd-p-matrix ] [ wasd-mv-matrix ] bi m. :> mvp-matrix
  18. { 0 0 0 } clear-screen
  19. [
  20. { 0 0 0 } { 1 0 0 } COLOR: red debug-line
  21. { 0 0 0 } { 0 1 0 } COLOR: green debug-line
  22. { 0 0 0 } { 0 0 1 } COLOR: blue debug-line
  23. { -1.2 0 0 } { 0 1 0 } 0 deg>rad rotation-matrix3 debug-axes
  24. { 3 5 -2 } { 3 2 1 } COLOR: white debug-box
  25. { 0 9 0 } 8 2 COLOR: blue debug-cylinder
  26. ] float-array{ } make
  27. mvp-matrix draw-debug-lines
  28. [
  29. { 0 4.0 0 } COLOR: red debug-point
  30. { 0 4.1 0 } COLOR: green debug-point
  31. { 0 4.2 0 } COLOR: blue debug-point
  32. ] float-array{ } make
  33. mvp-matrix draw-debug-points
  34. "Frame: " world frame#>> number>string append
  35. COLOR: purple { 5 5 } world dim>> draw-text
  36. world [ 1 + ] change-frame# drop ;
  37. TUPLE: tests-world < wasd-world frame# ;
  38. M: tests-world draw-world* draw-debug-tests ;
  39. M: tests-world wasd-movement-speed drop 1/16. ;
  40. M: tests-world wasd-near-plane drop 1/32. ;
  41. M: tests-world wasd-far-plane drop 1024.0 ;
  42. M: tests-world begin-game-world
  43. init-gpu
  44. 0 >>frame#
  45. { 0.0 0.0 2.0 } 0 0 set-wasd-view drop ;
  46. GAME: run-tests {
  47. { world-class tests-world }
  48. { title "game.debug.tests" }
  49. { pixel-format-attributes {
  50. windowed
  51. double-buffered
  52. T{ depth-bits { value 24 } }
  53. } }
  54. { grab-input? t }
  55. { use-game-input? t }
  56. { pref-dim { 1024 768 } }
  57. { tick-interval-nanos $[ 60 fps ] }
  58. } ;
  59. MAIN: run-tests