<commit_before>#include "common.h"
#include <iomanip>
#include <glm/gtc/random.hpp>
#include "Freefall.h"
#include "Polar.h"
#include "JobManager.h"
#include "EventManager.h"
#include "AssetManager.h"
#include "InputManager.h"
#include "ConfigManager.h"
#include "Integrator.h"
#include "Tweener.h"
#include "AudioManager.h"
#include "GL32Renderer.h"
#include "World.h"
#include "MenuSystem.h"
#include "CreditsSystem.h"
#include "LevelSwitcher.h"
#include "TitlePlayerController.h"
#include "HumanPlayerController.h"
#include "Text.h"
#include "Level.h"

enum class ConfigFloat : int {
	BaseDetail,
	Grain,
	PixelFactor,
	VoxelFactor,
	FarLimiter,
	FarFocus,
	ScanIntesity
};

enum class ConfigBool : int {
	Bloom,
	Cel,
	Mute
};

std::istream & operator>>(std::istream &s, ConfigFloat &x) {
	int y;
	s >> y;
	x = ConfigFloat(y);
	return s;
}

std::istream & operator>>(std::istream &s, ConfigBool &x) {
	int y;
	s >> y;
	x = ConfigBool(y);
	return s;
}

std::ostream & operator<<(std::ostream &s, const ConfigFloat x) {
	return s << int(x);
}

std::ostream & operator<<(std::ostream &s, const ConfigBool x) {
	return s << int(x);
}

using ConfigFloatM = ConfigManager<ConfigFloat, float>;
using ConfigBoolM = ConfigManager<ConfigBool, bool>;

void Freefall::Run(const std::vector<std::string> &args) {
	const double secsPerBeat = 1.2631578947368421;

	Polar engine;
	IDType playerID;

	srand((unsigned int)time(0));
	std::mt19937_64 rng(time(0));

	engine.AddState("root", [] (Polar *engine, EngineState &st) {
		st.transitions.emplace("forward", Transition{Push("world"), Push("notplaying"), Push("title")});

		//st.AddSystem<JobManager>();
		st.AddSystem<EventManager>();
		st.AddSystem<ConfigFloatM>("float.cfg", 0);
		st.AddSystem<ConfigBoolM>("bool.cfg", false);
		st.AddSystem<InputManager>();
		st.AddSystem<AssetManager>();
		st.AddSystem<Integrator>();
		st.AddSystem<Tweener<float>>();
		st.AddSystem<AudioManager>();
		st.AddSystemAs<Renderer, GL32Renderer, const boost::container::vector<std::string> &>({ "perlin"/*, "fxaa", "bloom"*/ });
		st.AddSystem<LevelSwitcher>();

		auto configFloatM = engine->GetSystem<ConfigFloatM>().lock();
		auto configBoolM = engine->GetSystem<ConfigBoolM>().lock();

		auto SetPipeline = [] (Polar *engine) {
			auto configBoolM = engine->GetSystem<ConfigBoolM>().lock();
			boost::container::vector<std::string> names = { "perlin" };
			if(configBoolM->Get(ConfigBool::Bloom)) { names.emplace_back("bloom"); }
			if(configBoolM->Get(ConfigBool::Cel)) { names.emplace_back("fxaa"); }
			engine->GetSystem<Renderer>().lock()->SetPipeline(names);
		};

		configFloatM->On(ConfigFloat::BaseDetail, [] (Polar *engine, ConfigFloat, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_baseDetail", x);
		});
		configFloatM->On(ConfigFloat::Grain, [] (Polar *engine, ConfigFloat, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_grain", x);
		});
		configFloatM->On(ConfigFloat::ScanIntesity, [] (Polar *engine, ConfigFloat, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_scanIntensity", x);
		});
		configFloatM->On(ConfigFloat::PixelFactor, [] (Polar *engine, ConfigFloat, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_pixelFactor", x);
		});
		configFloatM->On(ConfigFloat::VoxelFactor, [] (Polar *engine, ConfigFloat, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_voxelFactor", x);
		});
		configFloatM->On(ConfigFloat::FarLimiter, [] (Polar *engine, ConfigFloat, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_farLimiter", x);
		});
		configFloatM->On(ConfigFloat::FarFocus, [] (Polar *engine, ConfigFloat, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_farFocus", x);
		});
		configBoolM->On(ConfigBool::Bloom, [SetPipeline] (Polar *engine, ConfigBool, bool bloom) { SetPipeline(engine); });
		configBoolM->On(ConfigBool::Cel,   [SetPipeline] (Polar *engine, ConfigBool, bool bloom) { SetPipeline(engine); });
		configBoolM->On(ConfigBool::Mute, [] (Polar *engine, ConfigBool, bool mute) {
			engine->GetSystem<AudioManager>().lock()->muted = mute;
		});

		configFloatM->Set(ConfigFloat::BaseDetail, 10);
		configFloatM->Set(ConfigFloat::FarLimiter, 2);
		configFloatM->Set(ConfigFloat::FarFocus, 1);

		configFloatM->Load();
		configBoolM->Load();

		auto assetM = engine->GetSystem<AssetManager>().lock();
		assetM->Get<AudioAsset>("nexus");
		assetM->Get<AudioAsset>("laser");
		assetM->Get<AudioAsset>("beep1");
		assetM->Get<AudioAsset>("menu1");
		assetM->Get<AudioAsset>("30");
		assetM->Get<AudioAsset>("60");
		assetM->Get<AudioAsset>("1");
		assetM->Get<AudioAsset>("2");
		assetM->Get<AudioAsset>("3");
		assetM->Get<AudioAsset>("4");
		assetM->Get<AudioAsset>("5");
		assetM->Get<AudioAsset>("6");
		assetM->Get<AudioAsset>("7");
		assetM->Get<AudioAsset>("8");
		assetM->Get<AudioAsset>("9");
		assetM->Get<AudioAsset>("seconds");
		assetM->Get<AudioAsset>("hundred");
		assetM->Get<AudioAsset>("fifty");
		assetM->Get<AudioAsset>("freefall");

		engine->GetSystem<Renderer>().lock()->SetUniform("u_exposure", Point3(1));
		auto tweener = engine->GetSystem<Tweener<float>>().lock();
		st.dtors.emplace_back(tweener->Tween(1.0f, 0.0f, 2.0f, false, [] (Polar *engine, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_exposure", Point3(x));
		}));

		engine->transition = "forward";
	});

	engine.AddState("world", [&playerID] (Polar *engine, EngineState &st) {
		auto assetM = engine->GetSystem<AssetManager>().lock();

		st.dtors.emplace_back(engine->AddObject(&playerID));

		Point3 seed = glm::ballRand(Decimal(1000.0));
		engine->AddComponent<PositionComponent>(playerID, seed);
		engine->AddComponent<OrientationComponent>(playerID);

		st.AddSystem<World>(engine->GetSystem<LevelSwitcher>().lock()->GetLevel(), false);
	});

	boost::shared_ptr<Destructor> soundDtor;

	engine.AddState("notplaying", [&soundDtor] (Polar *engine, EngineState &st) {
		auto assetM = engine->GetSystem<AssetManager>().lock();
		auto inputM = engine->GetSystem<InputManager>().lock();
<commit_msg>Do not load all audio assets at startup<commit_after>#include "common.h"
#include <iomanip>
#include <glm/gtc/random.hpp>
#include "Freefall.h"
#include "Polar.h"
#include "JobManager.h"
#include "EventManager.h"
#include "AssetManager.h"
#include "InputManager.h"
#include "ConfigManager.h"
#include "Integrator.h"
#include "Tweener.h"
#include "AudioManager.h"
#include "GL32Renderer.h"
#include "World.h"
#include "MenuSystem.h"
#include "CreditsSystem.h"
#include "LevelSwitcher.h"
#include "TitlePlayerController.h"
#include "HumanPlayerController.h"
#include "Text.h"
#include "Level.h"

enum class ConfigFloat : int {
	BaseDetail,
	Grain,
	PixelFactor,
	VoxelFactor,
	FarLimiter,
	FarFocus,
	ScanIntesity
};

enum class ConfigBool : int {
	Bloom,
	Cel,
	Mute
};

std::istream & operator>>(std::istream &s, ConfigFloat &x) {
	int y;
	s >> y;
	x = ConfigFloat(y);
	return s;
}

std::istream & operator>>(std::istream &s, ConfigBool &x) {
	int y;
	s >> y;
	x = ConfigBool(y);
	return s;
}

std::ostream & operator<<(std::ostream &s, const ConfigFloat x) {
	return s << int(x);
}

std::ostream & operator<<(std::ostream &s, const ConfigBool x) {
	return s << int(x);
}

using ConfigFloatM = ConfigManager<ConfigFloat, float>;
using ConfigBoolM = ConfigManager<ConfigBool, bool>;

void Freefall::Run(const std::vector<std::string> &args) {
	const double secsPerBeat = 1.2631578947368421;

	Polar engine;
	IDType playerID;

	srand((unsigned int)time(0));
	std::mt19937_64 rng(time(0));

	engine.AddState("root", [] (Polar *engine, EngineState &st) {
		st.transitions.emplace("forward", Transition{Push("world"), Push("notplaying"), Push("title")});

		//st.AddSystem<JobManager>();
		st.AddSystem<EventManager>();
		st.AddSystem<ConfigFloatM>("float.cfg", 0);
		st.AddSystem<ConfigBoolM>("bool.cfg", false);
		st.AddSystem<InputManager>();
		st.AddSystem<AssetManager>();
		st.AddSystem<Integrator>();
		st.AddSystem<Tweener<float>>();
		st.AddSystem<AudioManager>();
		st.AddSystemAs<Renderer, GL32Renderer, const boost::container::vector<std::string> &>({ "perlin"/*, "fxaa", "bloom"*/ });
		st.AddSystem<LevelSwitcher>();

		auto configFloatM = engine->GetSystem<ConfigFloatM>().lock();
		auto configBoolM = engine->GetSystem<ConfigBoolM>().lock();

		auto SetPipeline = [] (Polar *engine) {
			auto configBoolM = engine->GetSystem<ConfigBoolM>().lock();
			boost::container::vector<std::string> names = { "perlin" };
			if(configBoolM->Get(ConfigBool::Bloom)) { names.emplace_back("bloom"); }
			if(configBoolM->Get(ConfigBool::Cel)) { names.emplace_back("fxaa"); }
			engine->GetSystem<Renderer>().lock()->SetPipeline(names);
		};

		configFloatM->On(ConfigFloat::BaseDetail, [] (Polar *engine, ConfigFloat, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_baseDetail", x);
		});
		configFloatM->On(ConfigFloat::Grain, [] (Polar *engine, ConfigFloat, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_grain", x);
		});
		configFloatM->On(ConfigFloat::ScanIntesity, [] (Polar *engine, ConfigFloat, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_scanIntensity", x);
		});
		configFloatM->On(ConfigFloat::PixelFactor, [] (Polar *engine, ConfigFloat, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_pixelFactor", x);
		});
		configFloatM->On(ConfigFloat::VoxelFactor, [] (Polar *engine, ConfigFloat, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_voxelFactor", x);
		});
		configFloatM->On(ConfigFloat::FarLimiter, [] (Polar *engine, ConfigFloat, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_farLimiter", x);
		});
		configFloatM->On(ConfigFloat::FarFocus, [] (Polar *engine, ConfigFloat, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_farFocus", x);
		});
		configBoolM->On(ConfigBool::Bloom, [SetPipeline] (Polar *engine, ConfigBool, bool bloom) { SetPipeline(engine); });
		configBoolM->On(ConfigBool::Cel,   [SetPipeline] (Polar *engine, ConfigBool, bool bloom) { SetPipeline(engine); });
		configBoolM->On(ConfigBool::Mute, [] (Polar *engine, ConfigBool, bool mute) {
			engine->GetSystem<AudioManager>().lock()->muted = mute;
		});

		configFloatM->Set(ConfigFloat::BaseDetail, 10);
		configFloatM->Set(ConfigFloat::FarLimiter, 2);
		configFloatM->Set(ConfigFloat::FarFocus, 1);

		configFloatM->Load();
		configBoolM->Load();

		auto assetM = engine->GetSystem<AssetManager>().lock();
		/*assetM->Get<AudioAsset>("nexus");
		assetM->Get<AudioAsset>("laser");
		assetM->Get<AudioAsset>("beep1");
		assetM->Get<AudioAsset>("menu1");
		assetM->Get<AudioAsset>("30");
		assetM->Get<AudioAsset>("60");
		assetM->Get<AudioAsset>("1");
		assetM->Get<AudioAsset>("2");
		assetM->Get<AudioAsset>("3");
		assetM->Get<AudioAsset>("4");
		assetM->Get<AudioAsset>("5");
		assetM->Get<AudioAsset>("6");
		assetM->Get<AudioAsset>("7");
		assetM->Get<AudioAsset>("8");
		assetM->Get<AudioAsset>("9");
		assetM->Get<AudioAsset>("seconds");
		assetM->Get<AudioAsset>("hundred");
		assetM->Get<AudioAsset>("fifty");
		assetM->Get<AudioAsset>("freefall");*/

		engine->GetSystem<Renderer>().lock()->SetUniform("u_exposure", Point3(1));
		auto tweener = engine->GetSystem<Tweener<float>>().lock();
		st.dtors.emplace_back(tweener->Tween(1.0f, 0.0f, 2.0f, false, [] (Polar *engine, float x) {
			engine->GetSystem<Renderer>().lock()->SetUniform("u_exposure", Point3(x));
		}));

		engine->transition = "forward";
	});

	engine.AddState("world", [&playerID] (Polar *engine, EngineState &st) {
		auto assetM = engine->GetSystem<AssetManager>().lock();

		st.dtors.emplace_back(engine->AddObject(&playerID));

		Point3 seed = glm::ballRand(Decimal(1000.0));
		engine->AddComponent<PositionComponent>(playerID, seed);
		engine->AddComponent<OrientationComponent>(playerID);

		st.AddSystem<World>(engine->GetSystem<LevelSwitcher>().lock()->GetLevel(), false);
	});

	boost::shared_ptr<Destructor> soundDtor;

	engine.AddState("notplaying", [&soundDtor] (Polar *engine, EngineState &st) {
		auto assetM = engine->GetSystem<AssetManager>().lock();
		auto inputM = engine->GetSystem<InputManager>().lock();

{'fraction_non_alphanumeric': 0.1976725127028356, 'fraction_numerical': 0.010653991148991968, 'mean_word_length': 6.377871825876663, 'pattern_counts': {'":': 0, '<': 145, '<?xml version=': 0, '>': 291, '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': '1430622', 'n_tokens_mistral': 4570, 'n_tokens_neox': 4273, 'n_words': 683}