<commit_before>#include "GameManagerSystem.hpp"

#include "GameManagerWorldComponent.hpp"
#include "CameraMovementComponent.hpp"
#include "Level.hpp"

#include <DeferredTaskSystem.hpp>
#include <TransformComponent.hpp>
#include <Physics2DColliders.hpp>
#include <Rigidbody2DComponent.hpp>
#include <MeshRenderingComponent.hpp>
#include <CameraComponent.hpp>
#include <FreeFloatMovementComponent.hpp>
#include <LightSourceComponent.hpp>
#include "TileComponent.hpp"
#include "PlayerControllerComponent.hpp"
#include "Physics2DWorldComponent.hpp"
#include <SoundEmitterComponent.hpp>
#include <SoundSystem.hpp>


using namespace SGJ;
using namespace Poly;


void SGJ::GameManagerSystem::LoadLevel(Poly::World* world, const Poly::String& path)
{
	GameManagerWorldComponent* gameMgrCmp = world->GetWorldComponent<GameManagerWorldComponent>();
	gameMgrCmp->Levels.PushBack(new Level(path));
}

void SGJ::GameManagerSystem::Update(Poly::World* world)
{
	GameManagerWorldComponent* manager = world->GetWorldComponent<GameManagerWorldComponent>();

	// Proces sound entities
	for (size_t i=0; i < manager->SoundSampleEntities.GetSize();)
	{
		UniqueID soundEnt = manager->SoundSampleEntities[i];
		if (!SoundSystem::IsEmmiterActive(world, soundEnt))
		{
			manager->SoundSampleEntities.RemoveByIdx(i);
			DeferredTaskSystem::DestroyEntity(world, soundEnt);
		}
		else
			++i;
	}

	PlayerControllerComponent* playerCmp = world->GetComponent<PlayerControllerComponent>(manager->Player);
	if (playerCmp->DeathCoolDowntime > 0)
		return;

	// Proces triggers
	for (Physics2DWorldComponent::Collision col : world->GetWorldComponent<Physics2DWorldComponent>()->GetCollidingBodies(world->GetComponent<RigidBody2DComponent>(manager->Player)))
	{
		TileComponent* obstacle = col.rb->GetSibling<TileComponent>();


		if (!obstacle) continue;

		switch (obstacle->GetTileType())
 		{
		case eTileType::SPIKESBOTTOM:
		case eTileType::SPIKESTOP:
		case eTileType::SPIKESLEFT:
		case eTileType::SPIKESRIGHT:
		{
			PlayerUpdateSystem::KillPlayer(world);
			PlayerUpdateSystem::PushPlayer(world, -col.Normal, 40.0f);
			return;
		}
		case eTileType::PLAYERENDPOS:
		{
			manager->CurrentLevelID = (manager->CurrentLevelID + 1) % manager->Levels.GetSize();
			SpawnLevel(world, manager->CurrentLevelID);
			return;
		}
		break;
		case eTileType::FASTERCHARACTER:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::INCREASED_SPEED);
			break;
		case eTileType::HIGHJUMP:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::HIGH_JUMP);
			break;
		case eTileType::LARGERCHARACTER:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::INCREASED_SIZE);
			break;
		case eTileType::SMALLERCHARACTER:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::DECREASED_SIZE);
			break;
		case eTileType::POGOJUMP:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::POGO_JUMP);
			break;
		case eTileType::REVERSEDCONTROLS:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::REVERSED_CONTROLS);
			break;
		case eTileType::LOWJUMP:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::LOW_JUMP);
			break;
		case eTileType::INVERSEDGRAVITY:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::INVERSED_GRAVITY);
			break;
		default:
			break;
		}
	}
}

Poly::UniqueID GameManagerSystem::CreateTileObject(Poly::World* world, const Poly::Vector& position, eTileType tileType, String meshSource,
	eRigidBody2DType physicsProperties = eRigidBody2DType::STATIC, const Vector& size = Vector(1, 1, 1), const Color& color = Color(0, 0, 0), bool colliding = true)
{
	UniqueID tile = DeferredTaskSystem::SpawnEntityImmediate(world);
	DeferredTaskSystem::AddComponentImmediate<TransformComponent>(world, tile);
	DeferredTaskSystem::AddComponentImmediate<TileComponent>(world, tile, tileType);
	DeferredTaskSystem::AddComponentImmediate<Box2DColliderComponent>(world, tile, size * 2);

	if (colliding)
	{
		DeferredTaskSystem::AddComponentImmediate<RigidBody2DComponent>(world, tile, world, physicsProperties, tileType == eTileType::RIGIDBODYGROUND ? 0.5f : 1.0f);
	}
	else
	{
		DeferredTaskSystem::AddComponentImmediate<RigidBody2DComponent>(world, tile, world, physicsProperties, RigidBody2DSensorTag());
	}

	TransformComponent* tileTrans = world->GetComponent<TransformComponent>(tile);

	UniqueID mesh = DeferredTaskSystem::SpawnEntityImmediate(world);
	DeferredTaskSystem::AddComponentImmediate<Poly::TransformComponent>(world, mesh);
	DeferredTaskSystem::AddComponentImmediate<MeshRenderingComponent>(world, mesh, meshSource, eResourceSource::GAME);
	world->GetComponent<MeshRenderingComponent>(tile)->SetMaterial(0, PhongMaterial(color, color, color, 8.0f));
	<commit_msg>Crash fix.<commit_after>#include "GameManagerSystem.hpp"

#include "GameManagerWorldComponent.hpp"
#include "CameraMovementComponent.hpp"
#include "Level.hpp"

#include <DeferredTaskSystem.hpp>
#include <TransformComponent.hpp>
#include <Physics2DColliders.hpp>
#include <Rigidbody2DComponent.hpp>
#include <MeshRenderingComponent.hpp>
#include <CameraComponent.hpp>
#include <FreeFloatMovementComponent.hpp>
#include <LightSourceComponent.hpp>
#include "TileComponent.hpp"
#include "PlayerControllerComponent.hpp"
#include "Physics2DWorldComponent.hpp"
#include <SoundEmitterComponent.hpp>
#include <SoundSystem.hpp>


using namespace SGJ;
using namespace Poly;


void SGJ::GameManagerSystem::LoadLevel(Poly::World* world, const Poly::String& path)
{
	GameManagerWorldComponent* gameMgrCmp = world->GetWorldComponent<GameManagerWorldComponent>();
	gameMgrCmp->Levels.PushBack(new Level(path));
}

void SGJ::GameManagerSystem::Update(Poly::World* world)
{
	GameManagerWorldComponent* manager = world->GetWorldComponent<GameManagerWorldComponent>();

	// Proces sound entities
	for (size_t i=0; i < manager->SoundSampleEntities.GetSize();)
	{
		UniqueID soundEnt = manager->SoundSampleEntities[i];
		if (!SoundSystem::IsEmmiterActive(world, soundEnt))
		{
			manager->SoundSampleEntities.RemoveByIdx(i);
			DeferredTaskSystem::DestroyEntity(world, soundEnt);
		}
		else
			++i;
	}

	PlayerControllerComponent* playerCmp = world->GetComponent<PlayerControllerComponent>(manager->Player);
	if (playerCmp->DeathCoolDowntime > 0)
		return;

	// Proces triggers
	for (Physics2DWorldComponent::Collision col : world->GetWorldComponent<Physics2DWorldComponent>()->GetCollidingBodies(world->GetComponent<RigidBody2DComponent>(manager->Player)))
	{
		TileComponent* obstacle = col.rb->GetSibling<TileComponent>();


		if (!obstacle) continue;

		switch (obstacle->GetTileType())
 		{
		case eTileType::SPIKESBOTTOM:
		case eTileType::SPIKESTOP:
		case eTileType::SPIKESLEFT:
		case eTileType::SPIKESRIGHT:
		{
			PlayerUpdateSystem::KillPlayer(world);
			PlayerUpdateSystem::PushPlayer(world, -col.Normal, 40.0f);
			return;
		}
		case eTileType::PLAYERENDPOS:
		{
			manager->CurrentLevelID = (manager->CurrentLevelID + 1) % manager->Levels.GetSize();
			SpawnLevel(world, manager->CurrentLevelID);
			return;
		}
		break;
		case eTileType::FASTERCHARACTER:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::INCREASED_SPEED);
			break;
		case eTileType::HIGHJUMP:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::HIGH_JUMP);
			break;
		case eTileType::LARGERCHARACTER:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::INCREASED_SIZE);
			break;
		case eTileType::SMALLERCHARACTER:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::DECREASED_SIZE);
			break;
		case eTileType::POGOJUMP:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::POGO_JUMP);
			break;
		case eTileType::REVERSEDCONTROLS:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::REVERSED_CONTROLS);
			break;
		case eTileType::LOWJUMP:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::LOW_JUMP);
			break;
		case eTileType::INVERSEDGRAVITY:
			PlayerUpdateSystem::PickupPowerup(world, ePowerup::INVERSED_GRAVITY);
			break;
		default:
			break;
		}
	}
}

Poly::UniqueID GameManagerSystem::CreateTileObject(Poly::World* world, const Poly::Vector& position, eTileType tileType, String meshSource,
	eRigidBody2DType physicsProperties = eRigidBody2DType::STATIC, const Vector& size = Vector(1, 1, 1), const Color& color = Color(0, 0, 0), bool colliding = true)
{
	UniqueID tile = DeferredTaskSystem::SpawnEntityImmediate(world);
	DeferredTaskSystem::AddComponentImmediate<TransformComponent>(world, tile);
	DeferredTaskSystem::AddComponentImmediate<TileComponent>(world, tile, tileType);
	DeferredTaskSystem::AddComponentImmediate<Box2DColliderComponent>(world, tile, size * 2);

	if (colliding)
	{
		DeferredTaskSystem::AddComponentImmediate<RigidBody2DComponent>(world, tile, world, physicsProperties, tileType == eTileType::RIGIDBODYGROUND ? 0.5f : 1.0f);
	}
	else
	{
		DeferredTaskSystem::AddComponentImmediate<RigidBody2DComponent>(world, tile, world, physicsProperties, RigidBody2DSensorTag());
	}

	TransformComponent* tileTrans = world->GetComponent<TransformComponent>(tile);

	UniqueID mesh = DeferredTaskSystem::SpawnEntityImmediate(world);
	DeferredTaskSystem::AddComponentImmediate<Poly::TransformComponent>(world, mesh);
	DeferredTaskSystem::AddComponentImmediate<MeshRenderingComponent>(world, mesh, meshSource, eResourceSource::GAME);
	world->GetComponent<MeshRenderingComponent>(mesh)->SetMaterial(0, PhongMaterial(color, color, color, 8.0f));
	
{'fraction_non_alphanumeric': 0.11952662721893491, 'fraction_numerical': 0.006885422270037655, 'mean_word_length': 7.844909609895338, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 99, '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': '6809546', 'n_tokens_mistral': 3253, 'n_tokens_neox': 3003, 'n_words': 471}