<commit_before>#include "engine.h"
#include <iostream>
#include <algorithm>
#include "engine_config.h"

namespace engine {

typedef std::chrono::duration<unsigned int, std::micro> DurationMicros;
typedef std::chrono::time_point<std::chrono::high_resolution_clock, DurationMicros> TimePointMicros;

void Engine::Initialize()	{
  std::cout << "Initializing Engine." << std::endl;
  std::cout << "Version: " 
    << ENGINE_VERSION_MAJOR << "."
    << ENGINE_VERSION_MINOR << "."
    << ENGINE_VERSION_PATCH << "."
    << ENGINE_VERSION_TWEAK
    << std::endl;
}

void Engine::Start() {
  // TODO(Jelle): load the game loop settings from a configuration file. 

  is_running_ = true;
  RunGameLoop();
}

void Engine::Stop() {
  is_running_ = false;
}

void Engine::Terminate() {
  std::cout << "Terminating Engine." << std::endl;
}

void Engine::RunGameLoop() {
  // TODO(Jelle): implement the actual, flexible game loop.
  DurationMicros time_step_micros{ time_step_micros_ };
  TimePointMicros time_previous = std::chrono::time_point_cast<DurationMicros>(std::chrono::high_resolution_clock::now());
  DurationMicros lag{ 0 };

  while (is_running_) {
    TimePointMicros time_current = std::chrono::time_point_cast<DurationMicros>(std::chrono::high_resolution_clock::now());
    DurationMicros time_since_last_update = (time_current - time_previous);
    time_previous = time_current;
    lag += time_since_last_update;

    while (lag >= time_step_micros) {
      Update(time_step_micros_);
      lag -= time_step_micros;
    }

    Draw(std::min(1.0f,((float)lag.count())/((float)time_step_micros_)));
  }
}

void Engine::Update(unsigned int delta_time_micros) {
  // Update game timing information first, as it is used by all other updates. 
  game_time_.Update(delta_time_micros);

  // TODO(Jelle): Remove this when the flexible game loop is finilized. 
  std::cout << "Update (" << game_time_.GetUpdateCount() << "): total = " << game_time_.GetTotalTimeMicros() << ", delta = " << game_time_.GetDeltaTimeMicros() << std::endl;
}

void Engine::Draw(float frame_interpolation) {
  // Update game timing information first, as it is used by all other draws. 
  game_time_.Draw(frame_interpolation);<commit_msg>Implemented drawing enabled vs disabled setting for game loops. See #3 for more info.<commit_after>#include "engine.h"
#include <iostream>
#include <algorithm>
#include "engine_config.h"

namespace engine {

typedef std::chrono::duration<unsigned int, std::micro> DurationMicros;
typedef std::chrono::time_point<std::chrono::high_resolution_clock, DurationMicros> TimePointMicros;

void Engine::Initialize()	{
  std::cout << "Initializing Engine." << std::endl;
  std::cout << "Version: " 
    << ENGINE_VERSION_MAJOR << "."
    << ENGINE_VERSION_MINOR << "."
    << ENGINE_VERSION_PATCH << "."
    << ENGINE_VERSION_TWEAK
    << std::endl;
}

void Engine::Start() {
  // TODO(Jelle): load the game loop settings from a configuration file. 

  is_running_ = true;
  RunGameLoop();
}

void Engine::Stop() {
  is_running_ = false;
}

void Engine::Terminate() {
  std::cout << "Terminating Engine." << std::endl;
}

void Engine::RunGameLoop() {
  // TODO(Jelle): implement the actual, flexible game loop.
  DurationMicros time_step_micros{ time_step_micros_ };
  TimePointMicros time_previous = std::chrono::time_point_cast<DurationMicros>(std::chrono::high_resolution_clock::now());
  DurationMicros lag{ 0 };

  while (is_running_) {
    TimePointMicros time_current = std::chrono::time_point_cast<DurationMicros>(std::chrono::high_resolution_clock::now());
    DurationMicros time_since_last_update = (time_current - time_previous);
    time_previous = time_current;
    lag += time_since_last_update;

    while (lag >= time_step_micros) {
      Update(time_step_micros_);
      lag -= time_step_micros;
    }

    if (drawing_is_enabled_) 
      Draw(std::min(1.0f,((float)lag.count())/((float)time_step_micros_)));
  }
}

void Engine::Update(unsigned int delta_time_micros) {
  // Update game timing information first, as it is used by all other updates. 
  game_time_.Update(delta_time_micros);

  // TODO(Jelle): Remove this when the flexible game loop is finilized. 
  std::cout << "Update (" << game_time_.GetUpdateCount() << "): total = " << game_time_.GetTotalTimeMicros() << ", delta = " << game_time_.GetDeltaTimeMicros() << std::endl;
}

void Engine::Draw(float frame_interpolation) {
  // Update game timing information first, as it is used by all other draws. 
  game_time_.Draw(frame_interpolation);
{'fraction_non_alphanumeric': 0.13859416445623343, 'fraction_numerical': 0.0015473032714412025, 'mean_word_length': 5.041388518024032, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 17, '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': '4180103', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1447, 'n_words': 310}