<commit_before>#include "Game.h"
#include <iostream>

Game::Game() {
	m_pWindow = 0;
	m_pRenderer = 0;
}

Game::~Game() {
	TextureManager::free();
}

bool Game::_initSDL(
	const char* title,
	const int x,
	const int y,
	const int w,
	const int h,
	const bool fullScreen
) {
	bool l_bReturn = true;
	int flags = 0;

	if (fullScreen) {
		flags |= SDL_WINDOW_FULLSCREEN;
	}

	// initialize SDL
	if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
		std::cout << "SDL Init failed\n";
		l_bReturn = false;
	}
	else {
		// if succeeded create our window
		m_pWindow = SDL_CreateWindow(title, x, y, w, h, flags);
		// if the window creation succeeded create our renderer
		if (m_pWindow == 0) {
			std::cout << "Window creation failed\n";
			l_bReturn = false;
		}
		else {
			m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);
			if (m_pRenderer == 0) {
				std::cout << "Renderer creation failed\n";
				l_bReturn = false;
			}
		}
	}

	return l_bReturn;
}

bool Game::_loadResources() {
	m_textureManager->load("resources/char9.bmp", "animate", m_pRenderer);
	return true;
}

bool Game::init(
	const char* title,
	const int x,
	const int y,
	const int w,
	const int h,
	const bool fullScreen
) {
	bool l_bReturn = true;
	m_textureManager = TextureManager::Instance();

	l_bReturn &= _initSDL(title, x, y, w, h, fullScreen);
	l_bReturn &= _loadResources();
	m_bRunning = l_bReturn;
	return l_bReturn;
}

void Game::handleEvents() {
	SDL_Event event;
	if (SDL_PollEvent(&event)) {
		switch (event.type) {<commit_msg>error message displayed when loading a resource<commit_after>#include "Game.h"
#include <iostream>
#include <errno.h>

Game::Game() {
	m_pWindow = 0;
	m_pRenderer = 0;
}

Game::~Game() {
	TextureManager::free();
}

bool Game::_initSDL(
	const char* title,
	const int x,
	const int y,
	const int w,
	const int h,
	const bool fullScreen
) {
	bool l_bReturn = true;
	int flags = 0;

	if (fullScreen) {
		flags |= SDL_WINDOW_FULLSCREEN;
	}

	// initialize SDL
	if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
		std::cout << "SDL Init failed\n";
		l_bReturn = false;
	}
	else {
		// if succeeded create our window
		m_pWindow = SDL_CreateWindow(title, x, y, w, h, flags);
		// if the window creation succeeded create our renderer
		if (m_pWindow == 0) {
			std::cout << "Window creation failed\n";
			l_bReturn = false;
		}
		else {
			m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);
			if (m_pRenderer == 0) {
				std::cout << "Renderer creation failed\n";
				l_bReturn = false;
			}
		}
	}

	return l_bReturn;
}

bool Game::_loadResources() {
	const char* fileName = "resources/char9.bmp";
	const char* errorPattern = "An error occured while loading the file %s\n%s\n";
	char errorMessage[strlen(fileName) + strlen(errorPattern) - 2];
	bool textureLoaded = m_textureManager->load(
		fileName,
		"animate",
		m_pRenderer
	);

	if (!textureLoaded) {
		sprintf(errorMessage, errorPattern, fileName, strerror(errno));
		std::cout << errorMessage;
		return false;
	}

	return true;
}

bool Game::init(
	const char* title,
	const int x,
	const int y,
	const int w,
	const int h,
	const bool fullScreen
) {
	bool l_bReturn = true;
	m_textureManager = TextureManager::Instance();

	l_bReturn &= _initSDL(title, x, y, w, h, fullScreen);
	l_bReturn &= _loadResources();
	m_bRunning = l_bReturn;
	return l_bReturn;
}

void Game::handleEvents() {
	SDL_Event event;
	if (SDL_PollEvent(&event)) {
		switch (event.type) {
{'fraction_non_alphanumeric': 0.13378418112319906, 'fraction_numerical': 0.00558659217877095, 'mean_word_length': 3.9591836734693877, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 8, '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': '1297533', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1287, 'n_words': 342}