<commit_before>#pragma once

#include <atomic>
#include <boost/container/vector.hpp>
#include <boost/unordered_set.hpp>
#include <boost/unordered_map.hpp>
#include <glm/gtc/noise.hpp>
#include "System.h"
#include "Renderer.h"
#include "Level.h"

class World : public System {
private:
	Level level;

	void SetUniforms() {
		auto kf = level.GetNow();
		auto renderer = engine->GetSystem<Renderer>().lock();
		renderer->SetUniform("u_baseThreshold", kf.baseThreshold);
		renderer->SetUniform("u_beatTicks",     kf.beatTicks);
		renderer->SetUniform("u_beatPower",     kf.beatPower);
		renderer->SetUniform("u_beatStrength",  kf.beatStrength);
		renderer->SetUniform("u_waveTicks",     kf.waveTicks);
		renderer->SetUniform("u_wavePower",     kf.wavePower);
		renderer->SetUniform("u_waveStrength",  kf.waveStrength);
		renderer->SetUniform("u_worldScale",    kf.worldScale);
		size_t iColor = kf.ticks / kf.colorTicks % kf.colors.size();
		renderer->SetUniform("u_color",         kf.colors[iColor]);
	}
protected:
	void Init() override final {
		SetUniforms();
	}

	void Update(DeltaTicks &dt) override final {
		auto renderer = engine->GetSystem<Renderer>().lock();
		renderer->SetUniform("u_time", (uint32_t)level.ticks);

		if(active) {
			level.ticks += dt.Ticks();
			SetUniforms();
		}
	}
public:
	bool active;

	static bool IsSupported() { return true; }

	World(Polar *engine, std::shared_ptr<Level> level, bool active = true) : System(engine), level(*level), active(active) {}

	uint64_t GetTicks() const { return level.ticks; }
	void SetLevel(std::shared_ptr<Level> lvl) {
		level = *lvl;
		SetUniforms();
	}

	float Threshold() {<commit_msg>Lerp when changing level<commit_after>#pragma once

#include <atomic>
#include <boost/container/vector.hpp>
#include <boost/unordered_set.hpp>
#include <boost/unordered_map.hpp>
#include <glm/gtc/noise.hpp>
#include "System.h"
#include "Renderer.h"
#include "Level.h"

class World : public System {
private:
	Level oldLevel;
	Level level;
	float alpha = 1;

	void SetUniforms() {
		auto kf = level.GetNow();
		if(alpha < 1) {
			auto oldKf = oldLevel.GetNow();
			kf = kf * alpha + oldKf * (1 - alpha);
		}

		auto renderer = engine->GetSystem<Renderer>().lock();
		renderer->SetUniform("u_time", (uint32_t)level.ticks);
		renderer->SetUniform("u_baseThreshold", kf.baseThreshold);
		renderer->SetUniform("u_beatTicks",     kf.beatTicks);
		renderer->SetUniform("u_beatPower",     kf.beatPower);
		renderer->SetUniform("u_beatStrength",  kf.beatStrength);
		renderer->SetUniform("u_waveTicks",     kf.waveTicks);
		renderer->SetUniform("u_wavePower",     kf.wavePower);
		renderer->SetUniform("u_waveStrength",  kf.waveStrength);
		renderer->SetUniform("u_worldScale",    kf.worldScale);
		size_t iColor = kf.ticks / kf.colorTicks % kf.colors.size();
		renderer->SetUniform("u_color",         kf.colors[iColor]);
	}
protected:
	void Init() override final {
		SetUniforms();
	}

	void Update(DeltaTicks &dt) override final {
		if(active) {
			level.ticks += dt.Ticks();
		}

		if(alpha < 1) {
			alpha = glm::min(Decimal(1.0), alpha + dt.Seconds() * Decimal(8.0));
		}

		SetUniforms();
	}
public:
	bool active;

	static bool IsSupported() { return true; }

	World(Polar *engine, std::shared_ptr<Level> level, bool active = true) : System(engine), level(*level), active(active) {}

	uint64_t GetTicks() const { return level.ticks; }

	void SetLevel(std::shared_ptr<Level> lvl) {
		oldLevel = level;
		level = *lvl;
		alpha = 0;
		SetUniforms();
	}

	float Threshold() {
{'fraction_non_alphanumeric': 0.15776009096077317, 'fraction_numerical': 0.004832291074474133, 'mean_word_length': 4.648475120385233, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 43, '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': '2817727', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1273, 'n_words': 241}