<commit_before>#include <Core/Game.h>
#include <Core/Resources.h>
#include <Core/World.h>
#include <Core/Device.h>
#include <Input/Input.h>
#include <Audio/Audio.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <imgui.h>
#include <imgui/imgui_impl_glfw_gl3.h>
#include <Tools/Profiler.h>
#include <cereal/archives/json.hpp>
#include <fstream>

using namespace Osm;
using namespace std;

CGame Osm::Game;

void GameSettings::LoadFromFile(const std::string& file)
{
	FilePath = file;
	ifstream fs;
	fs.open(FilePath);
	if (fs.is_open())
	{
		cereal::JSONInputArchive iarchive(fs);
		iarchive(cereal::make_nvp("Setttings", *this));
	}
	fs.close();
}

void GameSettings::SaveToFile()
{
	ofstream fs;
	fs.open(FilePath);

	{
		cereal::JSONOutputArchive oarchive(fs);
		oarchive(cereal::make_nvp("Setttings", *this));
	}
	fs.close();
}

void GameSettings::Inspect()
{
	ImGui::InputInt("Screen Width", &ScreenWidth, 320, 5600);
	ImGui::InputInt("Screen Height", &ScreenHeight, 240, 5600);
	ImGui::Checkbox("Full Screen", &FullScreen);
	ImGui::Checkbox("Native Resolution", &UseNativeResolution);
	ImGui::SliderFloat("Inspector Font Size", &InspectorFontSize, 0.5f, 2.0f);

	if (ImGui::Button("Save Settings"))
	{
		SaveToFile();
	}
}

void CGame::InitializeInternal()
{
	_initialized = true;

	_resources = CreateComponent<ResourceManager>();		

	_device = CreateComponent<GraphicsDevice>();

	_input = CreateComponent<InputManager>();

	_profiler = CreateComponent<Profiler>();

	_audio = CreateComponent<AudioManager>();

	ImGui_ImplGlfwGL3_Init(_device->GetWindow(), true);
}

void CGame::Initialize(const GameSettings& options)
{
	_settings = options;
	InitializeInternal();
}

void CGame::Shutdown()
{
	ASSERT(_initialized);

	// Remove component in the reverse order they were created
	while (_components.size() != 0)
		_components.erase(_components.end() - 1);
}

void CGame::Run()
{
	ASSERT(_initialized);

	auto lastFrame = glfwGetTime();
	while (!glfwWindowShouldClose(_device->GetWindow()) ||
			glfwGetKey(_device->GetWindow(), GLFW_KEY_ESCAPE))
	{
		glfwPollEvents();

		if (_event)
		{
			_event();
			_event = nullptr;
		}

		if (!_world)
			continue;		

		auto currentFrame = glfwGetTime();
		float deltaTime = (float)(currentFrame - lastFrame);
		lastFrame = currentFrame;
		if (deltaTime > 0.033f)
			deltaTime = 0.033f;

		// Update
		if (!_paused || _advanceFrame)
		{
			_profiler->StartFrame();
			uint updateID = _profiler->StartSection("Update");
			_input->Update();
			_world->Update(deltaTime);
			_profiler->EndSection(updateID);
			_advanceFrame = false;
		}


		uint renderID = _profiler->StartSection("Render");
		glViewport(0, 0, _device->GetScreenWidth(), _device->GetScreenHeight());				
		_world->Render();
		_profiler->EndSection(renderID);

		_profiler->EndFrame();

#ifdef INSPECTOR
		Inspect();
#endif

		glfwSwapBuffers(_device->GetWindow());

		// Escape hack
		auto joysticks = _input->GetActiveJoysticks();
		for (auto& j : joysticks)
		{
			if(_input->GetJoystickButtonPressed(j, JOYSTICK_BUTTON_BACK))
				return;
		}
	}
}

void CGame::SwapWorld(World* world)
{
	QueueEvent([this, world]()
	{
		if (_world)
			delete _world;
		_world = world;
	});
}

#ifdef INSPECTOR
void CGame::Inspect()
{
	if(_close_inspector)
		return;

	ImGui::GetIO().FontGlobalScale = _settings.InspectorFontSize;

	ImGuiWindowFlags window_flags = 0;
	//window_flags |= ImGuiWindowFlags_NoTitleBar;	
	window_flags |= ImGuiWindowFlags_MenuBar;

	ImGui_ImplGlfwGL3_NewFrame();

	bool p_open = true;

	ImGui::BeginMainMenuBar();
	if (ImGui::BeginMenu("Tools"))
	{
		ImGui::MenuItem("Game Inspector", nullptr, &_show_engine_compoents);
		// Just a reminder that this might be useful
		// ImGui::MenuItem("Log", NULL, &show_app_log);
		ImGui::MenuItem("World Inspector", nullptr, &_show_world_inspector);
		ImGui::MenuItem("Settings Inspector", nullptr, &_show_settings);
		ImGui::MenuItem("Profiler", nullptr, &_show_profiler);
		ImGui::MenuItem("ImGui Test", nullptr, &_show_imgui_test);
		ImGui::EndMenu();
	}
	<commit_msg>Added copyright in Toolbox (should move to settings)<commit_after>#include <Core/Game.h>
#include <Core/Resources.h>
#include <Core/World.h>
#include <Core/Device.h>
#include <Input/Input.h>
#include <Audio/Audio.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <imgui.h>
#include <imgui/imgui_impl_glfw_gl3.h>
#include <Tools/Profiler.h>
#include <cereal/archives/json.hpp>
#include <fstream>

using namespace Osm;
using namespace std;

CGame Osm::Game;

#define SHOW_IMGUI 0

void GameSettings::LoadFromFile(const std::string& file)
{
	FilePath = file;
	ifstream fs;
	fs.open(FilePath);
	if (fs.is_open())
	{
		cereal::JSONInputArchive iarchive(fs);
		iarchive(cereal::make_nvp("Setttings", *this));
	}
	fs.close();
}

void GameSettings::SaveToFile()
{
	ofstream fs;
	fs.open(FilePath);

	{
		cereal::JSONOutputArchive oarchive(fs);
		oarchive(cereal::make_nvp("Setttings", *this));
	}
	fs.close();
}

void GameSettings::Inspect()
{
	ImGui::InputInt("Screen Width", &ScreenWidth, 320, 5600);
	ImGui::InputInt("Screen Height", &ScreenHeight, 240, 5600);
	ImGui::Checkbox("Full Screen", &FullScreen);
	ImGui::Checkbox("Native Resolution", &UseNativeResolution);
	ImGui::SliderFloat("Inspector Font Size", &InspectorFontSize, 0.5f, 2.0f);

	if (ImGui::Button("Save Settings"))
	{
		SaveToFile();
	}
}

void CGame::InitializeInternal()
{
	_initialized = true;

	_resources = CreateComponent<ResourceManager>();		

	_device = CreateComponent<GraphicsDevice>();

	_input = CreateComponent<InputManager>();

	_profiler = CreateComponent<Profiler>();

	_audio = CreateComponent<AudioManager>();

	ImGui_ImplGlfwGL3_Init(_device->GetWindow(), true);
}

void CGame::Initialize(const GameSettings& options)
{
	_settings = options;
	InitializeInternal();
}

void CGame::Shutdown()
{
	ASSERT(_initialized);

	// Remove component in the reverse order they were created
	while (_components.size() != 0)
		_components.erase(_components.end() - 1);
}

void CGame::Run()
{
	ASSERT(_initialized);

	auto lastFrame = glfwGetTime();
	while (!glfwWindowShouldClose(_device->GetWindow()) ||
			glfwGetKey(_device->GetWindow(), GLFW_KEY_ESCAPE))
	{
		glfwPollEvents();

		if (_event)
		{
			_event();
			_event = nullptr;
		}

		if (!_world)
			continue;		

		auto currentFrame = glfwGetTime();
		float deltaTime = (float)(currentFrame - lastFrame);
		lastFrame = currentFrame;
		if (deltaTime > 0.033f)
			deltaTime = 0.033f;

		// Update
		if (!_paused || _advanceFrame)
		{
			_profiler->StartFrame();
			uint updateID = _profiler->StartSection("Update");
			_input->Update();
			_world->Update(deltaTime);
			_profiler->EndSection(updateID);
			_advanceFrame = false;
		}


		uint renderID = _profiler->StartSection("Render");
		glViewport(0, 0, _device->GetScreenWidth(), _device->GetScreenHeight());				
		_world->Render();
		_profiler->EndSection(renderID);

		_profiler->EndFrame();

#ifdef INSPECTOR
		Inspect();
#endif

		glfwSwapBuffers(_device->GetWindow());

		// Escape hack
		auto joysticks = _input->GetActiveJoysticks();
		for (auto& j : joysticks)
		{
			if(_input->GetJoystickButtonPressed(j, JOYSTICK_BUTTON_BACK))
				return;
		}
	}
}

void CGame::SwapWorld(World* world)
{
	QueueEvent([this, world]()
	{
		if (_world)
			delete _world;
		_world = world;
	});
}

#ifdef INSPECTOR
void CGame::Inspect()
{
	if(_close_inspector)
		return;

	ImGui::GetIO().FontGlobalScale = _settings.InspectorFontSize;

	ImGuiWindowFlags window_flags = 0;
	//window_flags |= ImGuiWindowFlags_NoTitleBar;	
	window_flags |= ImGuiWindowFlags_MenuBar;

	ImGui_ImplGlfwGL3_NewFrame();

	bool p_open = true;

	ImGui::BeginMainMenuBar();
	if (ImGui::BeginMenu("Tools"))
	{
		ImGui::MenuItem("Game Inspector", nullptr, &_show_engine_compoents);
		// Just a reminder that this might be useful
		// ImGui::MenuItem("Log", NULL, &show_app_log);
		ImGui::MenuItem("World Inspector", nullptr, &_show_world_inspector);
		ImGui::MenuItem("Settings Inspector", nullptr, &_show_settings);
		ImGui::MenuItem("Profiler", nullptr, &_show_profiler);
#if SHOW_IMGUI
		ImGui::MenuItem("ImGui Test", nullptr, &_show_imgui_test);
#endif
		ImGui::EndMenu();
	}

	if (ImGui::BeginMenu("About"))
	{
		string timestamp = __TIMESTAMP__;
		ImGui::MenuItem(("Built on: " + timestamp).c_str());
		ImGui::MenuItem("Copyright (C) <NAME> 2017");		
		ImGui::EndMenu();
	}
	
{'fraction_non_alphanumeric': 0.15378181383677858, 'fraction_numerical': 0.008961644162982434, 'mean_word_length': 5.408882082695253, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 76, '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': '1416109', 'n_tokens_mistral': 3246, 'n_tokens_neox': 2994, 'n_words': 556}