<commit_before>#include "sgherm.h"	// emu_state,
#include "print.h"	// debug
#include "signals.h"	// do_exit
#include "frontend.h"	// frontend

// SDL 2 whines. *sigh*
#ifdef HAVE_STDINT_H
#	undef HAVE_STDINT_H
#endif
#ifdef HAVE_CLOCK_GETTIME
#	undef HAVE_CLOCK_GETTIME
#endif
#ifdef HAVE_NANOSLEEP
#	undef HAVE_NANOSLEEP
#endif

#include <SDL.h>	// SDL
#include <stdbool.h>	// bool
#include <stdlib.h>	// calloc


#define LEN 144
#define WID 160
#define BPP 32
#define PITCH sizeof(uint32_t) * WID

#define RED	0x000000ff
#define GREEN	0x0000ff00
#define BLUE	0x00ff0000
#define ALPHA	0xff000000


typedef struct sdl2_video_data_t
{
	SDL_Window *window;
	SDL_Renderer *render;
	SDL_Texture *texture;
} sdl2_video_data;


bool sdl2_init_video(emu_state *state)
{
	sdl2_video_data *video;

	info(state, "Initalising the SDL video frontend!");

	if(SDL_InitSubSystem(SDL_INIT_VIDEO) != 0)
	{
		error(state, "Failed to initalise video frontend during video init: %s", SDL_GetError());
		return false;
	}

	video = calloc(1, sizeof(sdl2_video_data));
	state->front.video.data = video;

	video->window = SDL_CreateWindow("SuperGameHerm",
			SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
			WID*2, LEN*2, SDL_WINDOW_RESIZABLE|SDL_WINDOW_SHOWN);
	if(!(video->window))
	{
		error(state, "Failed to initalise video frontend during window creation: %s", SDL_GetError());
		free(video);
		return false;
	}

	video->render = SDL_CreateRenderer(video->window, -1, 0);
	if(!(video->render))
	{
		error(state, "Failed to initalise video frontend during render creation: %s", SDL_GetError());
		SDL_DestroyWindow(video->window);
		free(video);
		return false;
	}

	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
	SDL_RenderSetLogicalSize(video->render, WID, LEN);

	video->texture = SDL_CreateTexture(video->render,
			SDL_PIXELFORMAT_ARGB8888,
			SDL_TEXTUREACCESS_STREAMING,
			WID, LEN);
	if(!(video->texture))
	{
		error(state, "Failed to initalise video frontend during texture creation: %s", SDL_GetError());
		SDL_DestroyRenderer(video->render);
		SDL_DestroyWindow(video->window);
		free(video);
		return false;<commit_msg>Use OpenGL with SDL2 for speed improvement<commit_after>#include "sgherm.h"	// emu_state,
#include "print.h"	// debug
#include "signals.h"	// do_exit
#include "frontend.h"	// frontend

// SDL 2 whines. *sigh*
#ifdef HAVE_STDINT_H
#	undef HAVE_STDINT_H
#endif
#ifdef HAVE_CLOCK_GETTIME
#	undef HAVE_CLOCK_GETTIME
#endif
#ifdef HAVE_NANOSLEEP
#	undef HAVE_NANOSLEEP
#endif

#include <SDL.h>	// SDL
#include <stdbool.h>	// bool
#include <stdlib.h>	// calloc


#define LEN 144
#define WID 160
#define BPP 32
#define PITCH sizeof(uint32_t) * WID

#define RED	0x000000ff
#define GREEN	0x0000ff00
#define BLUE	0x00ff0000
#define ALPHA	0xff000000


typedef struct sdl2_video_data_t
{
	SDL_Window *window;
	SDL_Renderer *render;
	SDL_Texture *texture;
} sdl2_video_data;


bool sdl2_init_video(emu_state *state)
{
	sdl2_video_data *video;

	info(state, "Initalising the SDL video frontend!");

	if(SDL_InitSubSystem(SDL_INIT_VIDEO) != 0)
	{
		error(state, "Failed to initalise video frontend during video init: %s", SDL_GetError());
		return false;
	}

	video = calloc(1, sizeof(sdl2_video_data));
	state->front.video.data = video;

	video->window = SDL_CreateWindow("SuperGameHerm",
			SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
			WID*2, LEN*2, SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
	if(!(video->window))
	{
		error(state, "Failed to initalise video frontend during window creation: %s", SDL_GetError());
		free(video);
		return false;
	}

	video->render = SDL_CreateRenderer(video->window, -1, 0);
	if(!(video->render))
	{
		error(state, "Failed to initalise video frontend during render creation: %s", SDL_GetError());
		SDL_DestroyWindow(video->window);
		free(video);
		return false;
	}

	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
	SDL_RenderSetLogicalSize(video->render, WID, LEN);

	video->texture = SDL_CreateTexture(video->render,
			SDL_PIXELFORMAT_ARGB8888,
			SDL_TEXTUREACCESS_STREAMING,
			WID, LEN);
	if(!(video->texture))
	{
		error(state, "Failed to initalise video frontend during texture creation: %s", SDL_GetError());
		SDL_DestroyRenderer(video->render);
		SDL_DestroyWindow(video->window);
		free(video);
		return false;
{'fraction_non_alphanumeric': 0.12316647264260769, 'fraction_numerical': 0.025844004656577414, 'mean_word_length': 5.499243570347958, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, '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': '487505', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1621, 'n_words': 359}