<commit_before>#include "libRocketBackendSystem.h"

#include "GraphicsBackendSystem.h"
#include "InputBackendSystem.h"
#include "LibRocketRenderInterface.h"
#include "LibRocketSystemInterface.h"
#include <AntTweakBarWrapper.h>
#include <Control.h>
#include <Cursor.h>
#include <Globals.h>
#include <GraphicsWrapper.h>
#include <DebugUtil.h>
#include <Rocket/Controls.h>
#include <EventInstancer.h>
#include "LibRocketInputHelper.h"
#include "ClientConnectToServerSystem.h"
#include "LibRocketEventManagerSystem.h"

LibRocketBackendSystem::LibRocketBackendSystem( GraphicsBackendSystem* p_graphicsBackend
											   , InputBackendSystem* p_inputBackend )
	: EntitySystem( SystemType::LibRocketBackendSystem )
{
	m_graphicsBackend = p_graphicsBackend;
	m_inputBackend = p_inputBackend;

}


LibRocketBackendSystem::~LibRocketBackendSystem()
{
	// The connect handler is also an EntitySystem, and thus owned by the SystemManager.
	// Therefor, it is unregistered manually.
	//m_eventManager->UnregisterEventHandler("join");

	//m_eventManager->Shutdown();
	//delete m_eventManager;

	for( unsigned int i=0; i<m_documents.size(); i++ )
	{
		m_rocketContext->UnloadDocument(m_documents[i]);
		m_documents[i]->RemoveReference();
	}

	m_rocketContext->RemoveReference(); //release context

	delete m_renderInterface;
	delete m_systemInterface;
}

void LibRocketBackendSystem::initialize()
{
	LibRocketInputHelper::initialize();

	m_renderInterface = new LibRocketRenderInterface( m_graphicsBackend->getGfxWrapper() );
	m_systemInterface = new LibRocketSystemInterface( m_world );

	Rocket::Core::SetSystemInterface(m_systemInterface);
	Rocket::Core::SetRenderInterface(m_renderInterface);
	Rocket::Core::Initialise();
	Rocket::Controls::Initialise();

	m_wndWidth = m_graphicsBackend->getGfxWrapper()->getWindowWidth();
	m_wndHeight = m_graphicsBackend->getGfxWrapper()->getWindowHeight();

	m_rocketContextName = "default_name"; // Change the name if using multiple contexts!

	m_rocketContext = Rocket::Core::CreateContext(
		Rocket::Core::String( m_rocketContextName.c_str() ),
		Rocket::Core::Vector2i( m_wndWidth, m_wndHeight) );

	Rocket::Debugger::Initialise( m_rocketContext );
	Rocket::Debugger::SetVisible( true );
	
	m_cursor = m_inputBackend->getCursor();

	// Load fonts and documents
	// TODO: Should be done by assemblage

	vector<string> fonts;
	fonts.push_back( "Delicious-Roman.otf" );
	fonts.push_back( "Delicious-Bold.otf" );
	fonts.push_back( "Delicious-Italic.otf" );
	fonts.push_back( "Delicious-Roman.otf" );
	fonts.push_back( "Armorhide.ttf" );
	for( unsigned int i=0; i<fonts.size(); i++ )
	{
		string tmp = GUI_FONT_PATH + fonts[i]; 
		loadFontFace( tmp.c_str() );
	}

	//m_eventManager = static_cast<LibRocketEventManager*>(
	//	m_world->getSystem(SystemType::LibRocketEventManager));
	// Initialise event instancer and handlers.
	//EventInstancer* eventInstancer = new EventInstancer(m_eventManager);
	//Rocket::Core::Factory::RegisterEventListenerInstancer(eventInstancer);
	//eventInstancer->RemoveReference();

	//m_eventManager->Initialize(m_rocketContext);

	/*
	string tmp;
	tmp = GUI_HUD_PATH + "hud.rml";<commit_msg>Temporarily removed librocket debug gui<commit_after>#include "libRocketBackendSystem.h"

#include "GraphicsBackendSystem.h"
#include "InputBackendSystem.h"
#include "LibRocketRenderInterface.h"
#include "LibRocketSystemInterface.h"
#include <AntTweakBarWrapper.h>
#include <Control.h>
#include <Cursor.h>
#include <Globals.h>
#include <GraphicsWrapper.h>
#include <DebugUtil.h>
#include <Rocket/Controls.h>
#include <EventInstancer.h>
#include "LibRocketInputHelper.h"
#include "ClientConnectToServerSystem.h"
#include "LibRocketEventManagerSystem.h"

LibRocketBackendSystem::LibRocketBackendSystem( GraphicsBackendSystem* p_graphicsBackend
											   , InputBackendSystem* p_inputBackend )
	: EntitySystem( SystemType::LibRocketBackendSystem )
{
	m_graphicsBackend = p_graphicsBackend;
	m_inputBackend = p_inputBackend;

}


LibRocketBackendSystem::~LibRocketBackendSystem()
{
	// The connect handler is also an EntitySystem, and thus owned by the SystemManager.
	// Therefor, it is unregistered manually.
	//m_eventManager->UnregisterEventHandler("join");

	//m_eventManager->Shutdown();
	//delete m_eventManager;

	for( unsigned int i=0; i<m_documents.size(); i++ )
	{
		m_rocketContext->UnloadDocument(m_documents[i]);
		m_documents[i]->RemoveReference();
	}

	m_rocketContext->RemoveReference(); //release context

	delete m_renderInterface;
	delete m_systemInterface;
}

void LibRocketBackendSystem::initialize()
{
	LibRocketInputHelper::initialize();

	m_renderInterface = new LibRocketRenderInterface( m_graphicsBackend->getGfxWrapper() );
	m_systemInterface = new LibRocketSystemInterface( m_world );

	Rocket::Core::SetSystemInterface(m_systemInterface);
	Rocket::Core::SetRenderInterface(m_renderInterface);
	Rocket::Core::Initialise();
	Rocket::Controls::Initialise();

	m_wndWidth = m_graphicsBackend->getGfxWrapper()->getWindowWidth();
	m_wndHeight = m_graphicsBackend->getGfxWrapper()->getWindowHeight();

	m_rocketContextName = "default_name"; // Change the name if using multiple contexts!

	m_rocketContext = Rocket::Core::CreateContext(
		Rocket::Core::String( m_rocketContextName.c_str() ),
		Rocket::Core::Vector2i( m_wndWidth, m_wndHeight) );

	//Rocket::Debugger::Initialise( m_rocketContext );
	//Rocket::Debugger::SetVisible( true );
	
	m_cursor = m_inputBackend->getCursor();

	// Load fonts and documents
	// TODO: Should be done by assemblage

	vector<string> fonts;
	fonts.push_back( "Delicious-Roman.otf" );
	fonts.push_back( "Delicious-Bold.otf" );
	fonts.push_back( "Delicious-Italic.otf" );
	fonts.push_back( "Delicious-Roman.otf" );
	fonts.push_back( "Armorhide.ttf" );
	for( unsigned int i=0; i<fonts.size(); i++ )
	{
		string tmp = GUI_FONT_PATH + fonts[i]; 
		loadFontFace( tmp.c_str() );
	}

	//m_eventManager = static_cast<LibRocketEventManager*>(
	//	m_world->getSystem(SystemType::LibRocketEventManager));
	// Initialise event instancer and handlers.
	//EventInstancer* eventInstancer = new EventInstancer(m_eventManager);
	//Rocket::Core::Factory::RegisterEventListenerInstancer(eventInstancer);
	//eventInstancer->RemoveReference();

	//m_eventManager->Initialize(m_rocketContext);

	/*
	string tmp;
	tmp = GUI_HUD_PATH + "hud.rml";
{'fraction_non_alphanumeric': 0.1302149178255373, 'fraction_numerical': 0.0009481668773704172, 'mean_word_length': 6.634499396863691, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 51, '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': '1554709', 'n_tokens_mistral': 2180, 'n_tokens_neox': 2119, 'n_words': 355}