<commit_before>/////////////////////////////////////////
//
//         OpenLieroX
//
// based on sources for Carnage Marines
//
// code under LGPL, based on JasonBs work,
// enhanced by <NAME> and <NAME>
//
//
/////////////////////////////////////////


// Console source code
// Created 7/4/02
// <NAME>

#include "ThreadPool.h"
#include "LieroX.h"
#include "Debug.h"
#include "Clipboard.h"
#include "AuxLib.h"
#include "console.h"
#include "GfxPrimitives.h"
#include "InputEvents.h"
#include "StringUtils.h"
#include "Options.h"
#include "MathLib.h"
#include "ReadWriteLock.h"
#include "Timer.h"

console_t	*Console = NULL;

bool Con_IsInited() { return Console != NULL; }


// for Con_AddText
static SDL_mutex* con_mutex = NULL;

Timer *con_timer = NULL;

///////////////////
// Initialize the console
int Con_Initialize()
{
	con_mutex = SDL_CreateMutex();
	con_timer = new Timer("Console animation", null, NULL, 30);  // To make the animation smooth in the menu
	
	int n;
	Console = new console_t;;
	if(Console == NULL)
		return false;

	Console->fPosition = 1.0f;
	Console->iState = CON_HIDDEN;
	Console->iLastchar = 0;
	Console->icurHistory = -1;
	Console->iNumHistory = 0;
	Console->iCurpos = 0;
	Console->fBlinkTime = 0;
	Console->iBlinkState = 1;

	for(n=0;n<MAX_CONLINES;n++) {
		Console->Line[n].strText = "";
		Console->Line[n].Colour = CNC_NORMAL;
	}

	for(n=0;n<MAX_CONHISTORY;n++)
		Console->History[n].strText = "";

    Console->bmpConPic = LoadGameImage("data/gfx/console.png");
    if(!Console->bmpConPic.get())
        return false;
	
	return true;
}


///////////////////
// Toggle the console
void Con_Toggle()
{
	// Update the cursor blink state
	Console->fBlinkTime = 0;
	Console->iBlinkState = 1;

	con_timer->start();

	if(Console->iState == CON_HIDDEN || Console->iState == CON_HIDING) {
		Console->iState = CON_DROPPING;
        if(!tLXOptions->bFullscreen)
		    SDL_ShowCursor(SDL_ENABLE);
	}

	else if(Console->iState == CON_DROPPING || Console->iState == CON_DOWN) {
		Console->iState = CON_HIDING;
        if(!tLXOptions->bFullscreen)
		    SDL_ShowCursor(SDL_DISABLE);
	}
}


///////////////////
// Hide the console
void Con_Hide()
{
	Console->iCurpos = 0;
	Console->iState = CON_HIDDEN;
	Console->fPosition = 1;
	Console->fBlinkTime = 0;
	Console->iBlinkState = 1;
	con_timer->start();
}


///////////////////
// Process the console
void Con_Process(TimeDiff dt)<commit_msg>Fixed OLX taking too much CPU in menu after game (#2788962)<commit_after>/////////////////////////////////////////
//
//         OpenLieroX
//
// based on sources for Carnage Marines
//
// code under LGPL, based on JasonBs work,
// enhanced by <NAME> and <NAME>
//
//
/////////////////////////////////////////


// Console source code
// Created 7/4/02
// <NAME>

#include "ThreadPool.h"
#include "LieroX.h"
#include "Debug.h"
#include "Clipboard.h"
#include "AuxLib.h"
#include "console.h"
#include "GfxPrimitives.h"
#include "InputEvents.h"
#include "StringUtils.h"
#include "Options.h"
#include "MathLib.h"
#include "ReadWriteLock.h"
#include "Timer.h"

console_t	*Console = NULL;

bool Con_IsInited() { return Console != NULL; }


// for Con_AddText
static SDL_mutex* con_mutex = NULL;

Timer *con_timer = NULL;

///////////////////
// Initialize the console
int Con_Initialize()
{
	con_mutex = SDL_CreateMutex();
	con_timer = new Timer("Console animation", null, NULL, 30);  // To make the animation smooth in the menu
	
	int n;
	Console = new console_t;;
	if(Console == NULL)
		return false;

	Console->fPosition = 1.0f;
	Console->iState = CON_HIDDEN;
	Console->iLastchar = 0;
	Console->icurHistory = -1;
	Console->iNumHistory = 0;
	Console->iCurpos = 0;
	Console->fBlinkTime = 0;
	Console->iBlinkState = 1;

	for(n=0;n<MAX_CONLINES;n++) {
		Console->Line[n].strText = "";
		Console->Line[n].Colour = CNC_NORMAL;
	}

	for(n=0;n<MAX_CONHISTORY;n++)
		Console->History[n].strText = "";

    Console->bmpConPic = LoadGameImage("data/gfx/console.png");
    if(!Console->bmpConPic.get())
        return false;
	
	return true;
}


///////////////////
// Toggle the console
void Con_Toggle()
{
	// Update the cursor blink state
	Console->fBlinkTime = 0;
	Console->iBlinkState = 1;

	con_timer->start();

	if(Console->iState == CON_HIDDEN || Console->iState == CON_HIDING) {
		Console->iState = CON_DROPPING;
        if(!tLXOptions->bFullscreen)
		    SDL_ShowCursor(SDL_ENABLE);
	}

	else if(Console->iState == CON_DROPPING || Console->iState == CON_DOWN) {
		Console->iState = CON_HIDING;
        if(!tLXOptions->bFullscreen)
		    SDL_ShowCursor(SDL_DISABLE);
	}
}


///////////////////
// Hide the console
void Con_Hide()
{
	Console->iCurpos = 0;
	Console->iState = CON_HIDDEN;
	Console->fPosition = 1;
	Console->fBlinkTime = 0;
	Console->iBlinkState = 1;
}


///////////////////
// Process the console
void Con_Process(TimeDiff dt)
{'fraction_non_alphanumeric': 0.20648358455502788, 'fraction_numerical': 0.010530662812306421, 'mean_word_length': 2.8262243285939967, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 68, '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': '2322142', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1695, 'n_words': 374}