<commit_before>! (c)2009 <NAME> bsd license
USING: accessors combinators fry game.input game.loop generic kernel math
parser sequences ui ui.gadgets ui.gadgets.worlds ui.gestures threads
words audio.engine destructors ;
IN: game.worlds

TUPLE: game-world < world
    game-loop
    audio-engine
    { tick-interval-micros fixnum }
    { use-game-input? boolean }
    { use-audio-engine? boolean }
    { audio-engine-device initial: f }
    { audio-engine-voice-count initial: 16 }
    { tick-slice float initial: 0.0 } ;

GENERIC: begin-game-world ( world -- )
M: object begin-game-world drop ;

GENERIC: end-game-world ( world -- )
M: object end-game-world drop ;

GENERIC: tick-game-world ( world -- )
M: object tick-game-world drop ;

M: game-world tick*
    [ tick-game-world ]
    [ audio-engine>> [ update-audio ] when* ] bi ;

M: game-world draw*
    swap >>tick-slice relayout-1 yield ;

<PRIVATE

: open-game-audio-engine ( game-world -- audio-engine )
    {
        [ audio-engine-device>> ]
        [ audio-engine-voice-count>> ]
    } cleave <audio-engine>
    [ start-audio* ] keep ; inline

PRIVATE>

M: game-world begin-world
    dup use-game-input?>> [ open-game-input ] when
    dup use-audio-engine?>> [ dup open-game-audio-engine >>audio-engine ] when
    dup begin-game-world
    dup [ tick-interval-micros>> ] [ ] bi <game-loop> [ >>game-loop ] keep start-loop
    drop ;

M: game-world end-world
    [ [ stop-loop ] when* f ] change-game-loop
    [ end-game-world ]
    [ audio-engine>> [ dispose ] when* ]
    [ use-game-input?>> [ close-game-input ] when ] tri ;

TUPLE: game-attributes < world-attributes
    { tick-interval-micros fixnum }
    { use-game-input? boolean initial: f }
    { use-audio-engine? boolean initial: f }
    { audio-engine-device initial: f }
    { audio-engine-voice-count initial: 16 } ;

M: game-world apply-world-attributes
    {
        [ tick-interval-micros>> >>tick-interval-micros ]
        [ use-game-input?>> >>use-game-input? ]
        [ use-audio-engine?>> >>use-audio-engine? ]
        [ audio-engine-device>> >>audio-engine-device ]
        [ audio-engine-voice-count>> >>audio-engine-voice-count ]
        [ call-next-method ]
    } cleave ;<commit_msg>game.worlds: construct game-loop object before begin-game-world is called so begin-game-world can change it before the loop is started<commit_after>! (c)2009 <NAME> bsd license
USING: accessors combinators fry game.input game.loop generic kernel math
parser sequences ui ui.gadgets ui.gadgets.worlds ui.gestures threads
words audio.engine destructors ;
IN: game.worlds

TUPLE: game-world < world
    game-loop
    audio-engine
    { tick-interval-micros fixnum }
    { use-game-input? boolean }
    { use-audio-engine? boolean }
    { audio-engine-device initial: f }
    { audio-engine-voice-count initial: 16 }
    { tick-slice float initial: 0.0 } ;

GENERIC: begin-game-world ( world -- )
M: object begin-game-world drop ;

GENERIC: end-game-world ( world -- )
M: object end-game-world drop ;

GENERIC: tick-game-world ( world -- )
M: object tick-game-world drop ;

M: game-world tick*
    [ tick-game-world ]
    [ audio-engine>> [ update-audio ] when* ] bi ;

M: game-world draw*
    swap >>tick-slice relayout-1 yield ;

<PRIVATE

: open-game-audio-engine ( game-world -- audio-engine )
    {
        [ audio-engine-device>> ]
        [ audio-engine-voice-count>> ]
    } cleave <audio-engine>
    [ start-audio* ] keep ; inline

PRIVATE>

M: game-world begin-world
    dup use-game-input?>> [ open-game-input ] when
    dup use-audio-engine?>> [ dup open-game-audio-engine >>audio-engine ] when
    dup [ tick-interval-micros>> ] [ ] bi <game-loop>
    [ >>game-loop begin-game-world ] keep start-loop ;

M: game-world end-world
    [ [ stop-loop ] when* f ] change-game-loop
    [ end-game-world ]
    [ audio-engine>> [ dispose ] when* ]
    [ use-game-input?>> [ close-game-input ] when ] tri ;

TUPLE: game-attributes < world-attributes
    { tick-interval-micros fixnum }
    { use-game-input? boolean initial: f }
    { use-audio-engine? boolean initial: f }
    { audio-engine-device initial: f }
    { audio-engine-voice-count initial: 16 } ;

M: game-world apply-world-attributes
    {
        [ tick-interval-micros>> >>tick-interval-micros ]
        [ use-game-input?>> >>use-game-input? ]
        [ use-audio-engine?>> >>use-audio-engine? ]
        [ audio-engine-device>> >>audio-engine-device ]
        [ audio-engine-voice-count>> >>audio-engine-voice-count ]
        [ call-next-method ]
    } cleave ;
{'fraction_non_alphanumeric': 0.14546654929577466, 'fraction_numerical': 0.0048415492957746475, 'mean_word_length': 2.7376644736842106, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 95, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5085324', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1511, 'n_words': 349}