GAME: syntax for defining game entry point with game-loop attributes
parent
ab2a61bfa4
commit
6bbfa0b6d8
|
@ -243,9 +243,8 @@ M: object close-window
|
||||||
|
|
||||||
HOOK: beep ui-backend ( -- )
|
HOOK: beep ui-backend ( -- )
|
||||||
|
|
||||||
: parse-main-window ( class -- attributes quot )
|
: parse-main-window-attributes ( class -- attributes )
|
||||||
"{" expect dup all-slots parse-tuple-literal-slots
|
"{" expect dup all-slots parse-tuple-literal-slots ;
|
||||||
parse-definition ;
|
|
||||||
|
|
||||||
: define-main-window ( word attributes quot -- )
|
: define-main-window ( word attributes quot -- )
|
||||||
[
|
[
|
||||||
|
@ -253,4 +252,7 @@ HOOK: beep ui-backend ( -- )
|
||||||
] [ 2drop current-vocab (>>main) ] 3bi ;
|
] [ 2drop current-vocab (>>main) ] 3bi ;
|
||||||
|
|
||||||
SYNTAX: MAIN-WINDOW:
|
SYNTAX: MAIN-WINDOW:
|
||||||
CREATE world-attributes parse-main-window define-main-window ;
|
CREATE
|
||||||
|
world-attributes parse-main-window-attributes
|
||||||
|
parse-definition
|
||||||
|
define-main-window ;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
USING: accessors game.input game.loop kernel math ui.gadgets
|
USING: accessors combinators fry game.input game.loop generic kernel math
|
||||||
ui.gadgets.worlds ui.gestures threads ;
|
parser sequences ui ui.gadgets ui.gadgets.worlds ui.gestures threads
|
||||||
|
words ;
|
||||||
IN: game.worlds
|
IN: game.worlds
|
||||||
|
|
||||||
TUPLE: game-world < world
|
TUPLE: game-world < world
|
||||||
|
@ -24,3 +25,26 @@ M: game-world end-world
|
||||||
TUPLE: game-attributes < world-attributes
|
TUPLE: game-attributes < world-attributes
|
||||||
{ tick-interval-micros fixnum read-only } ;
|
{ tick-interval-micros fixnum read-only } ;
|
||||||
|
|
||||||
|
: verify-game-attributes ( attributes -- )
|
||||||
|
world-class>> { f world } member?
|
||||||
|
[ "GAME: must be given a custom world-class" throw ] when ;
|
||||||
|
|
||||||
|
: define-game-tick-interval-micros ( attributes -- )
|
||||||
|
[ world-class>> \ tick-interval-micros create-method ]
|
||||||
|
[ tick-interval-micros>> '[ drop _ ] ] bi
|
||||||
|
define ;
|
||||||
|
|
||||||
|
: define-game-methods ( attributes -- )
|
||||||
|
{
|
||||||
|
[ verify-game-attributes ]
|
||||||
|
[ define-game-tick-interval-micros ]
|
||||||
|
} cleave ;
|
||||||
|
|
||||||
|
: define-game ( word attributes -- )
|
||||||
|
[ [ ] define-main-window ]
|
||||||
|
[ nip define-game-methods ] 2bi ;
|
||||||
|
|
||||||
|
SYNTAX: GAME:
|
||||||
|
CREATE
|
||||||
|
game-attributes parse-main-window-attributes
|
||||||
|
define-game ;
|
||||||
|
|
|
@ -7,7 +7,7 @@ io io.encodings.ascii io.files io.files.temp kernel locals math
|
||||||
math.matrices math.vectors.simd math.parser math.vectors
|
math.matrices math.vectors.simd math.parser math.vectors
|
||||||
method-chains namespaces sequences splitting threads ui ui.gadgets
|
method-chains namespaces sequences splitting threads ui ui.gadgets
|
||||||
ui.gadgets.worlds ui.pixel-formats specialized-arrays
|
ui.gadgets.worlds ui.pixel-formats specialized-arrays
|
||||||
specialized-vectors ;
|
specialized-vectors literals ;
|
||||||
FROM: alien.c-types => float ;
|
FROM: alien.c-types => float ;
|
||||||
SPECIALIZED-ARRAY: float
|
SPECIALIZED-ARRAY: float
|
||||||
SPECIALIZED-VECTOR: uint
|
SPECIALIZED-VECTOR: uint
|
||||||
|
@ -293,24 +293,19 @@ M: bunny-world draw-world*
|
||||||
AFTER: bunny-world resize-world
|
AFTER: bunny-world resize-world
|
||||||
[ sobel>> framebuffer>> ] [ dim>> ] bi resize-framebuffer ;
|
[ sobel>> framebuffer>> ] [ dim>> ] bi resize-framebuffer ;
|
||||||
|
|
||||||
M: bunny-world pref-dim* drop { 1024 768 } ;
|
|
||||||
M: bunny-world tick-interval-micros drop 1000000 60 /i ;
|
|
||||||
M: bunny-world wasd-movement-speed drop 1/160. ;
|
M: bunny-world wasd-movement-speed drop 1/160. ;
|
||||||
M: bunny-world wasd-near-plane drop 1/32. ;
|
M: bunny-world wasd-near-plane drop 1/32. ;
|
||||||
M: bunny-world wasd-far-plane drop 256.0 ;
|
M: bunny-world wasd-far-plane drop 256.0 ;
|
||||||
|
|
||||||
: bunny-window ( -- )
|
GAME: bunny-game {
|
||||||
[
|
{ world-class bunny-world }
|
||||||
f T{ world-attributes
|
{ title "Bunny" }
|
||||||
{ world-class bunny-world }
|
{ pixel-format-attributes {
|
||||||
{ title "Bunny" }
|
windowed
|
||||||
{ pixel-format-attributes {
|
double-buffered
|
||||||
windowed
|
T{ depth-bits { value 24 } }
|
||||||
double-buffered
|
} }
|
||||||
T{ depth-bits { value 24 } }
|
{ grab-input? t }
|
||||||
} }
|
{ pref-dim { 1024 768 } }
|
||||||
{ grab-input? t }
|
{ tick-interval-micros $[ 1,000,000 60 /i ] }
|
||||||
} open-window
|
}
|
||||||
] with-ui ;
|
|
||||||
|
|
||||||
MAIN: bunny-window
|
|
||||||
|
|
|
@ -92,21 +92,16 @@ M: raytrace-world draw-world*
|
||||||
{ "vertex-array" [ vertex-array>> ] }
|
{ "vertex-array" [ vertex-array>> ] }
|
||||||
} <render-set> render ;
|
} <render-set> render ;
|
||||||
|
|
||||||
M: raytrace-world pref-dim* drop { 1024 768 } ;
|
|
||||||
M: raytrace-world tick-interval-micros drop 1000000 60 /i ;
|
|
||||||
M: raytrace-world wasd-movement-speed drop 1/4. ;
|
M: raytrace-world wasd-movement-speed drop 1/4. ;
|
||||||
|
|
||||||
: raytrace-window ( -- )
|
GAME: raytrace-game {
|
||||||
[
|
{ world-class raytrace-world }
|
||||||
f T{ world-attributes
|
{ title "Raytracing" }
|
||||||
{ world-class raytrace-world }
|
{ pixel-format-attributes {
|
||||||
{ title "Raytracing" }
|
windowed
|
||||||
{ pixel-format-attributes {
|
double-buffered
|
||||||
windowed
|
} }
|
||||||
double-buffered
|
{ grab-input? t }
|
||||||
} }
|
{ pref-dim { 1024 768 } }
|
||||||
{ grab-input? t }
|
{ tick-interval-micros $[ 1,000,000 60 /i ] }
|
||||||
} open-window
|
}
|
||||||
] with-ui ;
|
|
||||||
|
|
||||||
MAIN: raytrace-window
|
|
||||||
|
|
|
@ -55,9 +55,6 @@ TUPLE: terrain-world < game-world
|
||||||
float-4{ 0.0 0.0 0.0 1.0 } >>velocity
|
float-4{ 0.0 0.0 0.0 1.0 } >>velocity
|
||||||
VELOCITY-MODIFIER-NORMAL >>velocity-modifier ;
|
VELOCITY-MODIFIER-NORMAL >>velocity-modifier ;
|
||||||
|
|
||||||
M: terrain-world tick-interval-micros
|
|
||||||
drop 1000000 60 /i ;
|
|
||||||
|
|
||||||
: frustum ( dim -- -x x -y y near far )
|
: frustum ( dim -- -x x -y y near far )
|
||||||
dup first2 min v/n
|
dup first2 min v/n
|
||||||
NEAR-PLANE FOV / v*n first2 [ [ neg ] keep ] bi@
|
NEAR-PLANE FOV / v*n first2 [ [ neg ] keep ] bi@
|
||||||
|
@ -290,20 +287,15 @@ M: terrain-world draw-world*
|
||||||
] with-gl-program ]
|
] with-gl-program ]
|
||||||
} cleave gl-error ;
|
} cleave gl-error ;
|
||||||
|
|
||||||
M: terrain-world pref-dim* drop { 1024 768 } ;
|
GAME: terrain-game {
|
||||||
|
{ world-class terrain-world }
|
||||||
: terrain-window ( -- )
|
{ title "Terrain" }
|
||||||
[
|
{ pixel-format-attributes {
|
||||||
f T{ world-attributes
|
windowed
|
||||||
{ world-class terrain-world }
|
double-buffered
|
||||||
{ title "Terrain" }
|
T{ depth-bits { value 24 } }
|
||||||
{ pixel-format-attributes {
|
} }
|
||||||
windowed
|
{ grab-input? t }
|
||||||
double-buffered
|
{ pref-dim { 1024 768 } }
|
||||||
T{ depth-bits { value 24 } }
|
{ tick-interval-micros $[ 1,000,000 60 /i ] }
|
||||||
} }
|
}
|
||||||
{ grab-input? t }
|
|
||||||
} open-window
|
|
||||||
] with-ui ;
|
|
||||||
|
|
||||||
MAIN: terrain-window
|
|
||||||
|
|
Loading…
Reference in New Issue