<commit_before>#include <assert.h>
#include <math.h>
#include "LevelViewContext.h"
#include "PtrStream.h"
#include "QuakeEntityParser.h"
#include "QuakeViewerDefs.h"

CLevelViewContext::CLevelViewContext(CPakFile* pakFile, const char* levelPath)
: CContextBase(pakFile)
, m_mousePosition(0, 0)
, m_commandMode(COMMAND_MODE_IDLE)
, m_cameraPosition(0, 0, 0)
, m_cameraHAngle(0)
, m_cameraVAngle(0)
, m_dragHAngle(0)
, m_dragVAngle(0)
, m_dragPosition(0, 0)
, m_bspFile(nullptr)
, m_elapsed(0)
{
	m_viewerPackage = Athena::CPackage::Create("viewer");

	m_skyTexture = Athena::CGraphicDevice::GetInstance().CreateCubeTextureFromFile("./data/viewer/skybox.dds");

	{
		uint8* fileData = NULL;
		uint32 fileSize = 0;
		if(!m_pakFile->ReadFile(levelPath, &fileData, &fileSize))
		{
			throw std::runtime_error("Couldn't open file.");
		}
		Framework::CPtrStream inputStream(fileData, fileSize);
		m_bspFile = new CBspFile(inputStream);
		delete fileData;
	}

	{
		m_bspMapResourceProvider = new CBspMapResourceProvider();
		m_bspMapResourceProvider->LoadResources(*m_bspFile, *m_pakFile);
	}

	CVector3 originPosition(0, 0, 0);
	{
		QuakeEntityList entities = CQuakeEntityParser::Parse(m_bspFile->GetEntities());
		const QUAKE_ENTITY* info_player_entity = QuakeEntity::FindFirstEntityWithClassName(entities, "info_player_deathmatch");
		if(info_player_entity)
		{
			auto originValueIterator = info_player_entity->values.find("origin");
			if(originValueIterator != std::end(info_player_entity->values))
			{
				originPosition = QuakeEntity::ParseEntityVector(originValueIterator->second.c_str());
			}
		}
	}

	m_sphereBasePosition = originPosition;
	m_cameraPosition = originPosition + CVector3(0, 50, 0);

	InitializeReflectionMap();
	InitializeMapViewport();
	InitializeHudViewport();

	UpdateCamera();
}

CLevelViewContext::~CLevelViewContext()
{
	Athena::CGraphicDevice::GetInstance().RemoveViewport(m_mapViewport.get());
	Athena::CGraphicDevice::GetInstance().RemoveViewport(m_hudViewport.get());
	delete m_bspMapResourceProvider;
	delete m_bspFile;
}

void CLevelViewContext::InitializeMapViewport()
{
	m_bspMapMeshProvider = BspMapMeshProviderPtr(new CBspMapMeshProvider(m_bspFile, m_bspMapResourceProvider));

	m_mapViewport = Athena::CViewport::Create();

	m_mapCamera = Athena::CCamera::Create();
	CVector2 screenSize = Athena::CGraphicDevice::GetInstance().GetScreenSize();
	m_mapCamera->SetPerspectiveProjection(M_PI / 4, screenSize.x / screenSize.y, 1, 10000);
	m_mapViewport->SetCamera(m_mapCamera);

	Athena::CGraphicDevice::GetInstance().AddViewport(m_mapViewport.get());

	Athena::SceneNodePtr sceneRoot = m_mapViewport->GetSceneRoot();

	//Create skybox
	{
		Athena::MeshPtr skyBox = Athena::CCubeMesh::Create();
		skyBox->SetIsPeggedToOrigin(true);
		skyBox->SetScale(CVector3(50, 50, 50));
		skyBox->GetMaterial()->SetCullingMode(Athena::CULLING_CW);
		skyBox->GetMaterial()->SetTexture(0, m_skyTexture);
		skyBox->GetMaterial()->SetTextureCoordSource(0, Athena::TEXTURE_COORD_CUBE_POS);
		sceneRoot->AppendChild(skyBox);
	}

	sceneRoot->AppendChild(m_bspMapMeshProvider);

	//Create reflective sphere
	{
		Athena::MeshPtr sphere = Athena::CSphereMesh::Create();
		sphere->SetPosition(m_sphereBasePosition);
		sphere->SetScale(CVector3(25, 25, 25));
		sphere->GetMaterial()->SetTexture(0, m_reflectionRenderTarget);
		sphere->GetMaterial()->SetTextureCoordSource(0, Athena::TEXTURE_COORD_CUBE_REFLECT);
		sceneRoot->AppendChild(sphere);
		m_sphere = sphere;
	}
}

void CLevelViewContext::InitializeHudViewport()
{
	CVector2 screenSize = Athena::CGraphicDevice::GetInstance().GetScreenSize();

	m_forwardButtonBoundingBox = CBox2(CVector2(screenSize.x - (64 + 10), screenSize.y - (64 + 10)), CVector2(64, 64));
	m_backwardButtonBoundingBox = CBox2(CVector2(10, screenSize.y - (64 + 10)), CVector2(64, 64));
<commit_msg>Added some autos.<commit_after>#include <assert.h>
#include <math.h>
#include "LevelViewContext.h"
#include "PtrStream.h"
#include "QuakeEntityParser.h"
#include "QuakeViewerDefs.h"

CLevelViewContext::CLevelViewContext(CPakFile* pakFile, const char* levelPath)
: CContextBase(pakFile)
, m_mousePosition(0, 0)
, m_commandMode(COMMAND_MODE_IDLE)
, m_cameraPosition(0, 0, 0)
, m_cameraHAngle(0)
, m_cameraVAngle(0)
, m_dragHAngle(0)
, m_dragVAngle(0)
, m_dragPosition(0, 0)
, m_bspFile(nullptr)
, m_elapsed(0)
{
	m_viewerPackage = Athena::CPackage::Create("viewer");

	m_skyTexture = Athena::CGraphicDevice::GetInstance().CreateCubeTextureFromFile("./data/viewer/skybox.dds");

	{
		uint8* fileData = NULL;
		uint32 fileSize = 0;
		if(!m_pakFile->ReadFile(levelPath, &fileData, &fileSize))
		{
			throw std::runtime_error("Couldn't open file.");
		}
		Framework::CPtrStream inputStream(fileData, fileSize);
		m_bspFile = new CBspFile(inputStream);
		delete fileData;
	}

	{
		m_bspMapResourceProvider = new CBspMapResourceProvider();
		m_bspMapResourceProvider->LoadResources(*m_bspFile, *m_pakFile);
	}

	CVector3 originPosition(0, 0, 0);
	{
		QuakeEntityList entities = CQuakeEntityParser::Parse(m_bspFile->GetEntities());
		const QUAKE_ENTITY* info_player_entity = QuakeEntity::FindFirstEntityWithClassName(entities, "info_player_deathmatch");
		if(info_player_entity)
		{
			auto originValueIterator = info_player_entity->values.find("origin");
			if(originValueIterator != std::end(info_player_entity->values))
			{
				originPosition = QuakeEntity::ParseEntityVector(originValueIterator->second.c_str());
			}
		}
	}

	m_sphereBasePosition = originPosition;
	m_cameraPosition = originPosition + CVector3(0, 50, 0);

	InitializeReflectionMap();
	InitializeMapViewport();
	InitializeHudViewport();

	UpdateCamera();
}

CLevelViewContext::~CLevelViewContext()
{
	Athena::CGraphicDevice::GetInstance().RemoveViewport(m_mapViewport.get());
	Athena::CGraphicDevice::GetInstance().RemoveViewport(m_hudViewport.get());
	delete m_bspMapResourceProvider;
	delete m_bspFile;
}

void CLevelViewContext::InitializeMapViewport()
{
	m_bspMapMeshProvider = BspMapMeshProviderPtr(new CBspMapMeshProvider(m_bspFile, m_bspMapResourceProvider));

	m_mapViewport = Athena::CViewport::Create();

	m_mapCamera = Athena::CCamera::Create();
	CVector2 screenSize = Athena::CGraphicDevice::GetInstance().GetScreenSize();
	m_mapCamera->SetPerspectiveProjection(M_PI / 4, screenSize.x / screenSize.y, 1, 10000);
	m_mapViewport->SetCamera(m_mapCamera);

	Athena::CGraphicDevice::GetInstance().AddViewport(m_mapViewport.get());

	auto sceneRoot = m_mapViewport->GetSceneRoot();

	//Create skybox
	{
		auto skyBox = Athena::CCubeMesh::Create();
		skyBox->SetIsPeggedToOrigin(true);
		skyBox->SetScale(CVector3(50, 50, 50));
		skyBox->GetMaterial()->SetCullingMode(Athena::CULLING_CW);
		skyBox->GetMaterial()->SetTexture(0, m_skyTexture);
		skyBox->GetMaterial()->SetTextureCoordSource(0, Athena::TEXTURE_COORD_CUBE_POS);
		sceneRoot->AppendChild(skyBox);
	}

	sceneRoot->AppendChild(m_bspMapMeshProvider);

	//Create reflective sphere
	{
		auto sphere = Athena::CSphereMesh::Create();
		sphere->SetPosition(m_sphereBasePosition);
		sphere->SetScale(CVector3(25, 25, 25));
		sphere->GetMaterial()->SetTexture(0, m_reflectionRenderTarget);
		sphere->GetMaterial()->SetTextureCoordSource(0, Athena::TEXTURE_COORD_CUBE_REFLECT);
		sceneRoot->AppendChild(sphere);
		m_sphere = sphere;
	}
}

void CLevelViewContext::InitializeHudViewport()
{
	CVector2 screenSize = Athena::CGraphicDevice::GetInstance().GetScreenSize();

	m_forwardButtonBoundingBox = CBox2(CVector2(screenSize.x - (64 + 10), screenSize.y - (64 + 10)), CVector2(64, 64));
	m_backwardButtonBoundingBox = CBox2(CVector2(10, screenSize.y - (64 + 10)), CVector2(64, 64));

{'fraction_non_alphanumeric': 0.1389470927187009, 'fraction_numerical': 0.020953378732320588, 'mean_word_length': 7.619638826185102, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 59, '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': '7140567', 'n_tokens_mistral': 2962, 'n_tokens_neox': 2723, 'n_words': 358}