<commit_before>#ifdef WINDOWS
#define BITMAP dummyBITMAP
#include <windows.h>
#undef BITMAP
#endif

#include "main.h"
#include "init.h"
#include <sstream>
#include <iostream>
#include <stdlib.h>
#include <time.h>

#include "factory/collector.h"
#include "factory/object_factory.h"
#include "factory/heart_factory.h"
#include "factory/font_render.h"
#include "fonts.h"
#include "globals.h"
#include "configuration.h"
#include "level/scene.h"
#include "return_exception.h"
#include "loading.h"
#include "music.h"
#include "object/buddy_player.h"
#include "object/character.h"
#include "object/network_character.h"
#include "object/effect.h"
#include "object/enemy.h"
#include "object/object.h"
#include "object/object_attack.h"
#include "object/player.h"
#include "object/versus_player.h"
#include "object/versus_enemy.h"
#include "util/bitmap.h"
#include "util/funcs.h"
#include "util/load_exception.h"
#include "util/token.h"
#include "util/token_exception.h"
#include "util/font.h"
#include "util/tokenreader.h"
#include "util/timedifference.h"
#include "select_player.h"
#include "network_world.h"
#include "network_world_client.h"
#include "world.h"
#include "versus_world.h"

#include <pthread.h>

#include "network.h"

/*
#include "sockets/SocketHandler.h"
#include "sockets/ListenSocket.h"
#include "sockets/TcpSocket.h"
*/

/* Global effect for copying */
// static Object * bang = NULL;

/*
#ifndef debug
#define debug cout<<"File: "<<__FILE__<<" Line: "<<__LINE__<<endl;
// #define debug
#endif
*/
	
static bool show_loading_screen = true;

static double startingGameSpeed = 1.0;
static int LAZY_KEY_DELAY = 300;
static int gfx = Global::WINDOWED;

static const char * DEFAULT_FONT = "/fonts/arial.ttf";

static int startingLives = 4;

static void stopLoading( pthread_t thread ){
	if ( show_loading_screen ){
		pthread_mutex_lock( &Global::loading_screen_mutex );
		Global::done_loading = true;
		pthread_mutex_unlock( &Global::loading_screen_mutex );

		pthread_join( thread, NULL );
	}
}

static void startLoading( pthread_t * thread ){
	if ( show_loading_screen ){
		pthread_create( thread, NULL, loadingScreen, NULL );
	}
}

/* fade the screen and tell the player they lost */
void fadeOut( const string & message ){
	Bitmap dark( GFX_X, GFX_Y );
	dark.fill( Bitmap::makeColor( 0, 0, 0 ) );
	Global::speed_counter = 0;
	Bitmap::transBlender( 0, 0, 0, 10 );
	int fade = 0;
	const Font & f = Font::getFont( Util::getDataPath() + DEFAULT_FONT, 50, 50 );
	f.printf( 200, 200, Bitmap::makeColor( 255, 0, 0 ), dark, message, 0 );
	while ( fade < 100 ){
		fade++;
	
		Bitmap::transBlender( 0, 0, 0, fade / 2 );

		bool draw = false;
		if ( Global::speed_counter > 0 ){
			draw = true;
			Global::speed_counter = 0;
		}

		if ( draw ){
			dark.drawTrans( 0, 0, *Bitmap::Screen );
		}
		
		while ( Global::speed_counter == 0 ){
			Util::rest( 1 );
		}
	}

	Util::rest( 1000 );
}

/* if given blah.txt and that file exists return blah1.txt
 * returns <file>#.<ext> where # is incremented until the entire
 * filename is unique
 */
static string findNextFile( const char * name ){
	char buf[ 128 ];
	char * extension = strchr( name, '.' );
	char first[ 128 ];
	strncpy( first, name, extension - name );
	first[ extension - name ] = '\0';
	int num = 0;
	sprintf( buf, "%s%d%s", first, num, extension );
	do{
		num += 1;
		sprintf( buf, "%s%d%s", first, num, extension );
	} while ( Util::exists( buf ) );
	return string( buf );
}<commit_msg>make fadeout screen look a little better<commit_after>#ifdef WINDOWS
#define BITMAP dummyBITMAP
#include <windows.h>
#undef BITMAP
#endif

#include "main.h"
#include "init.h"
#include <sstream>
#include <iostream>
#include <stdlib.h>
#include <time.h>

#include "factory/collector.h"
#include "factory/object_factory.h"
#include "factory/heart_factory.h"
#include "factory/font_render.h"
#include "fonts.h"
#include "globals.h"
#include "configuration.h"
#include "level/scene.h"
#include "return_exception.h"
#include "loading.h"
#include "music.h"
#include "object/buddy_player.h"
#include "object/character.h"
#include "object/network_character.h"
#include "object/effect.h"
#include "object/enemy.h"
#include "object/object.h"
#include "object/object_attack.h"
#include "object/player.h"
#include "object/versus_player.h"
#include "object/versus_enemy.h"
#include "util/bitmap.h"
#include "util/funcs.h"
#include "util/load_exception.h"
#include "util/token.h"
#include "util/token_exception.h"
#include "util/font.h"
#include "util/tokenreader.h"
#include "util/timedifference.h"
#include "select_player.h"
#include "network_world.h"
#include "network_world_client.h"
#include "world.h"
#include "versus_world.h"

#include <pthread.h>

#include "network.h"

/*
#include "sockets/SocketHandler.h"
#include "sockets/ListenSocket.h"
#include "sockets/TcpSocket.h"
*/

/* Global effect for copying */
// static Object * bang = NULL;

/*
#ifndef debug
#define debug cout<<"File: "<<__FILE__<<" Line: "<<__LINE__<<endl;
// #define debug
#endif
*/
	
static bool show_loading_screen = true;

static double startingGameSpeed = 1.0;
static int LAZY_KEY_DELAY = 300;
static int gfx = Global::WINDOWED;

static const char * DEFAULT_FONT = "/fonts/arial.ttf";

static int startingLives = 4;

static void stopLoading( pthread_t thread ){
	if ( show_loading_screen ){
		pthread_mutex_lock( &Global::loading_screen_mutex );
		Global::done_loading = true;
		pthread_mutex_unlock( &Global::loading_screen_mutex );

		pthread_join( thread, NULL );
	}
}

static void startLoading( pthread_t * thread ){
	if ( show_loading_screen ){
		pthread_create( thread, NULL, loadingScreen, NULL );
	}
}

/* fade the screen and tell the player they lost */
void fadeOut( const string & message ){
	Bitmap dark( GFX_X, GFX_Y );
	Bitmap copy( *Bitmap::Screen );
	Bitmap work( GFX_X, GFX_Y );
	// dark.fill( Bitmap::makeColor( 32, 32, 32 ) );
	Global::speed_counter = 0;
	int fade = 0;
	int colors[ 100 ];
	Util::blend_palette( colors, 100, Bitmap::makeColor( 26, 24, 24 ), Bitmap::makeColor( 97, 90, 91 ) );
	for ( int y = 0; y < GFX_Y; y++ ){
			  int color = colors[ (GFX_Y - y) / 5 ];
			  // dark.line( 0, y, GFX_X, y, Bitmap::makeColor( (GFX_Y - y) / 6, (GFX_Y - y) / 4, (GFX_Y - y) / 5 ) );
			  dark.line( 0, y, GFX_X, y, color );
	}
	const Font & f = Font::getFont( Util::getDataPath() + DEFAULT_FONT, 50, 50 );
	f.printf( 200, 200, Bitmap::makeColor( 255, 0, 0 ), dark, message, 0 );
	/*
	for ( int y = 0; y < GFX_Y; y += 6 ){

			  if ( Global::speed_counter >= 1 ){
						 dark.Blit( 0, y, GFX_X, 6, 0, y, *Bitmap::Screen );
						 Global::speed_counter = 0;
			  }

			  while ( Global::speed_counter < 1 ){
						 Util::rest( 1 );
			  }
	}
	*/
	while ( fade < 64 ){

		bool draw = false;
		if ( Global::speed_counter > 0 ){
			fade += Global::speed_counter;
			draw = true;
			Global::speed_counter = 0;
		}

		if ( draw ){
			// Bitmap::transBlender( 0, 0, 0, 255 - fade );
			// copy.drawTrans( 0, 0, work );
			dark.Blit( work );
			Bitmap::transBlender( 0, 0, 0, 255 - fade * fade / 8 );
			copy.drawTrans( 0, 0, work );
			work.BlitToScreen();
			// work.clear();
			// dark.drawTrans( 0, 0, *Bitmap::Screen );
			// dark.drawTrans( 0, 0, copy );
			// copy.BlitToScreen();
		}
		
		while ( Global::speed_counter == 0 ){
			Util::rest( 1 );
		}
	}
	dark.Blit( *Bitmap::Screen );

	Util::rest( 1000 );
}

/* if given blah.txt and that file exists return blah1.txt
 * returns <file>#.<ext> where # is incremented until the entire
 * filename is unique
 */
static string findNextFile( const char * name ){
	char buf[ 128 ];
	char * extension = strchr( name, '.' );
	char first[ 128 ];
	strncpy( first, name, extension - name );
	first[ extension - name ] = '\0';
	int num = 0;
	sprintf( buf, "%s%d%s", first, num, extension );
	do{
		num += 1;
		sprintf( buf, "%s%d%s", first, num, extension );
	} while ( Util::exists( buf ) );
	return string( buf );
}
{'fraction_non_alphanumeric': 0.16161359888367371, 'fraction_numerical': 0.020804262336673856, 'mean_word_length': 4.11284046692607, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 22, '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': '707936', 'n_tokens_mistral': 3176, 'n_tokens_neox': 2860, 'n_words': 760}