<commit_before>//
//  Game.swift
//  GPEngine
//
//  Created by <NAME> on 12/01/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

/// Represents a game object, which is the core object of this engine.
/// Games contains spaces and systems, and manages the interactions between them.
open class Game: GameEventDispatcherDelegate {
    
    /// The list of spaces currently registered on this game
    internal(set) open var spaces: [Space]
    /// The list of systems that can manipulate the spaces
    internal(set) open var systems: [System]
    
    /// The last update time interval tick. Used to calculate a delta time (time
    /// difference) between frames
    fileprivate var lastUpdateTime: DeltaTimeInterval = 0
    
    /// The event dispatcher that handles event handling on the game
    internal(set) open var eventDispatcher: GameEventDispatcher = GameEventDispatcher()
    
    public init() {
        spaces = [Space]()
        systems = [System]()
        
        eventDispatcher.delegate = self
    }
    
    open func gameEventDispatcher(_ eventDispatcher: GameEventDispatcher, wihhDispatch event: GameEvent) {
        
        // Forward to spaces
        for space in spaces {
            space.eventDispatcher.dispatchEvent(event)
        }
    }
    
    /// Method called before each frame is rendered on the screen
    open func updateWithTimeSinceLastUpdate(_ timeSinceLast: DeltaTimeInterval) {
        /* Called before each frame is rendered */
        
    }
    
    /// Updates this game object, with a specified time since the last frame in 
    /// milliseconds
    open func updateAndRender(_ dt: DeltaTimeInterval) {
        // Handle time delta.
        // If we drop below 60fps, we still want everything to move the same
        // distance.
        var timeSinceLast = dt - self.lastUpdateTime
        self.lastUpdateTime = dt
        
        if (timeSinceLast > 1) {
            // more than a second since last update
            timeSinceLast = 1.0 / 60.0
            self.lastUpdateTime = dt
        }
        
        self.updateWithTimeSinceLastUpdate(timeSinceLast)
        
        for system in systems {
            system.update(spaces: spaces.filter { $0.active }, interval: dt)<commit_msg>Flattening implementation of update/render loop, and dropping support for updateAndRender()<commit_after>//
//  Game.swift
//  GPEngine
//
//  Created by <NAME> on 12/01/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

/// Represents a game object, which is the core object of this engine.
/// Games contains spaces and systems, and manages the interactions between them.
open class Game: GameEventDispatcherDelegate {
    
    /// The list of spaces currently registered on this game
    internal(set) open var spaces: [Space]
    /// The list of systems that can manipulate the spaces
    internal(set) open var systems: [System]
    
    /// The event dispatcher that handles event handling on the game
    internal(set) open var eventDispatcher: GameEventDispatcher = GameEventDispatcher()
    
    public init() {
        spaces = [Space]()
        systems = [System]()
        
        eventDispatcher.delegate = self
    }
    
    open func gameEventDispatcher(_ eventDispatcher: GameEventDispatcher, wihhDispatch event: GameEvent) {
        
        // Forward to spaces
        for space in spaces {
            space.eventDispatcher.dispatchEvent(event)
        }
    }
    
    /// Updates this game object, with a specified time since the last frame in 
    /// milliseconds
    open func update(_ dt: DeltaTimeInterval) {
        for system in systems {
            system.update(spaces: spaces.filter { $0.active }, interval: dt)
{'fraction_non_alphanumeric': 0.08007549204637368, 'fraction_numerical': 0.008358047991372337, 'mean_word_length': 2.3213965980304385, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '1523626', 'n_tokens_mistral': 984, 'n_tokens_neox': 926, 'n_words': 365}