<commit_before>#include "util/funcs.h"
#include "util/bitmap.h"
#include "script/script.h"
#include "object/object.h"
#include "object/object_attack.h"
#include "object/character.h"
#include "util/font.h"
#include "util/file-system.h"
#include "util/gradient.h"
#include "factory/font_render.h"
#include "globals.h"
#include "object/effect.h"
#include "object/enemy.h"
#include "level/scene.h"
#include "level/random-scene.h"
#include "world.h"
#include "adventure_world.h"
#include "network/network.h"
#include "level/cacher.h"
#include "util/thread.h"
#include "util/events.h"

#include <iostream>
#include <string>
#include <vector>

using namespace std;

AdventureWorld::AdventureWorld():
World(),
draw_minimaps( true ),
mini_map( NULL ),
takeAScreenshot(false),
is_paused(false),
slowmotion(0),
descriptionTime(0),
descriptionGradient(0){
	scene = NULL;
	bang = NULL;
}

static const int DESCRIPTION_TIME = 700;

AdventureWorld::AdventureWorld( const vector< Object * > & players, const Filesystem::AbsolutePath & path, Level::Cacher * cacher, int _screen_size ):
World(),
path( path ),
draw_minimaps( true ),
mini_map( NULL ),
takeAScreenshot(false),
is_paused(false),
slowmotion(0),
cacher(cacher),
descriptionTime(DESCRIPTION_TIME),
descriptionGradient(new Effects::Gradient(100, Bitmap::makeColor(255, 255, 255), Bitmap::makeColor(128, 128, 128))){
	scene = NULL;
	bang = NULL;
	screen_size = _screen_size;

	for ( vector<Object *>::const_iterator it = players.begin(); it != players.end(); it++ ){
		PlayerTracker t;
		t.min_x = 0;
		t.player = *it;
		// this->players.push_back( (PlayerTracker) { .min_x = 0, .player = *it } );
		this->players.push_back( t );
	}

	threadedLoadLevel(path);

        /* 1.3333 is the aspect ratio of screen_width/screen_height when the res is any standard of
         * 640,480 800,600, 1024,768
         * but it should use the actual values instead of guessing since the screen size
         * could theoretically change
         */
	mini_map = new Bitmap(screen_size, (int)((double) screen_size / 1.3333));

        for ( vector<PlayerTracker>::iterator it = this->players.begin(); it != this->players.end(); it++ ){
            PlayerTracker & tracker = *it;
            void * handle = Script::Engine::getEngine()->createPlayer(tracker.player);
            tracker.player->setScriptObject(handle);
            tracker.script = handle;
        }

	/*
	if ( player != NULL ){
		objects.push_back( player );
	}
	*/
}

AdventureWorld::~AdventureWorld(){

	if ( bang ){
		delete bang;
	}

	if ( scene ){
		delete scene;
	}
	
	if ( mini_map ){
		delete mini_map;
	}

        delete cacher;

        delete descriptionGradient;

	deleteObjects( &objects );
            
        for (deque<Bitmap*>::iterator it = screenshots.begin(); it != screenshots.end(); it++){
            delete *it;
        }
	
        /* this prevents the object from being destroyed in the Object destructor */
        for ( vector<PlayerTracker>::iterator it = players.begin(); it != players.end(); it++ ){
            PlayerTracker & tracker = *it;
            void * handle = tracker.script;
            if (handle != NULL){
                Script::Engine::getEngine()->destroyObject(handle);
            }
            tracker.player->setScriptObject(NULL);
        }
}
        
Script::Engine * AdventureWorld::getEngine() const {
    return Script::getEngine();
    /*
    if (scene){
        return scene->getScript();
    }
    Global::debug(-1) << "Script is null somehow" << endl;
    exit(1);
    */
}

void AdventureWorld::reloadLevel(){
    for ( vector< PlayerTracker >::iterator it = players.begin(); it != players.end(); it++ ){
        it->min_x = 0;
    }
    loadLevel(path);
}
        
void AdventureWorld::changePause(){
    is_paused = ! is_paused;
}
        
bool AdventureWorld::isPaused(){
    return is_paused;
}

void AdventureWorld::pause(){
    is_paused = true;
}

void AdventureWorld::unpause(){
    is_paused = false;
}

struct LoadLevelInfo{
    LoadLevelInfo(AdventureWorld * who, const Filesystem::AbsolutePath & path):
        who(who), path(path){}

    AdventureWorld * who;
    const Filesystem::AbsolutePath & path;
};

void * AdventureWorld::do_load_level(void * arg){
    LoadLevelInfo * info = (LoadLevelInfo *) arg;
    AdventureWorld * world = info->who;
    world->loadLevel(info->path);
    delete info;
    return NULL;
}

void AdventureWorld::threadedLoadLevel(const Filesystem::AbsolutePath & path){
    /* this looks dangerous, passing a temporary to a thread but in theory
     * the temporary should live past the end of the thread life
     * so the memory will stick around.
     */
    LoadLevelInfo * info = new LoadLevelInfo(this, path);
    Util::Thread thread(do_load_level, info);
    Util::EventManager manager;
    manager.waitForThread(thread);
}

bool AdventureWorld::randomLevel() const {
    /* FIXME: let the user decide to make this true or not */
    return false;
}<commit_msg>rename Thread to WaitThread<commit_after>#include "util/funcs.h"
#include "util/bitmap.h"
#include "script/script.h"
#include "object/object.h"
#include "object/object_attack.h"
#include "object/character.h"
#include "util/font.h"
#include "util/file-system.h"
#include "util/gradient.h"
#include "factory/font_render.h"
#include "globals.h"
#include "object/effect.h"
#include "object/enemy.h"
#include "level/scene.h"
#include "level/random-scene.h"
#include "world.h"
#include "adventure_world.h"
#include "network/network.h"
#include "level/cacher.h"
#include "util/thread.h"
#include "util/events.h"

#include <iostream>
#include <string>
#include <vector>

using namespace std;

AdventureWorld::AdventureWorld():
World(),
draw_minimaps( true ),
mini_map( NULL ),
takeAScreenshot(false),
is_paused(false),
slowmotion(0),
descriptionTime(0),
descriptionGradient(0){
	scene = NULL;
	bang = NULL;
}

static const int DESCRIPTION_TIME = 700;

AdventureWorld::AdventureWorld( const vector< Object * > & players, const Filesystem::AbsolutePath & path, Level::Cacher * cacher, int _screen_size ):
World(),
path( path ),
draw_minimaps( true ),
mini_map( NULL ),
takeAScreenshot(false),
is_paused(false),
slowmotion(0),
cacher(cacher),
descriptionTime(DESCRIPTION_TIME),
descriptionGradient(new Effects::Gradient(100, Bitmap::makeColor(255, 255, 255), Bitmap::makeColor(128, 128, 128))){
	scene = NULL;
	bang = NULL;
	screen_size = _screen_size;

	for ( vector<Object *>::const_iterator it = players.begin(); it != players.end(); it++ ){
		PlayerTracker t;
		t.min_x = 0;
		t.player = *it;
		// this->players.push_back( (PlayerTracker) { .min_x = 0, .player = *it } );
		this->players.push_back( t );
	}

	threadedLoadLevel(path);

        /* 1.3333 is the aspect ratio of screen_width/screen_height when the res is any standard of
         * 640,480 800,600, 1024,768
         * but it should use the actual values instead of guessing since the screen size
         * could theoretically change
         */
	mini_map = new Bitmap(screen_size, (int)((double) screen_size / 1.3333));

        for ( vector<PlayerTracker>::iterator it = this->players.begin(); it != this->players.end(); it++ ){
            PlayerTracker & tracker = *it;
            void * handle = Script::Engine::getEngine()->createPlayer(tracker.player);
            tracker.player->setScriptObject(handle);
            tracker.script = handle;
        }

	/*
	if ( player != NULL ){
		objects.push_back( player );
	}
	*/
}

AdventureWorld::~AdventureWorld(){

	if ( bang ){
		delete bang;
	}

	if ( scene ){
		delete scene;
	}
	
	if ( mini_map ){
		delete mini_map;
	}

        delete cacher;

        delete descriptionGradient;

	deleteObjects( &objects );
            
        for (deque<Bitmap*>::iterator it = screenshots.begin(); it != screenshots.end(); it++){
            delete *it;
        }
	
        /* this prevents the object from being destroyed in the Object destructor */
        for ( vector<PlayerTracker>::iterator it = players.begin(); it != players.end(); it++ ){
            PlayerTracker & tracker = *it;
            void * handle = tracker.script;
            if (handle != NULL){
                Script::Engine::getEngine()->destroyObject(handle);
            }
            tracker.player->setScriptObject(NULL);
        }
}
        
Script::Engine * AdventureWorld::getEngine() const {
    return Script::getEngine();
    /*
    if (scene){
        return scene->getScript();
    }
    Global::debug(-1) << "Script is null somehow" << endl;
    exit(1);
    */
}

void AdventureWorld::reloadLevel(){
    for ( vector< PlayerTracker >::iterator it = players.begin(); it != players.end(); it++ ){
        it->min_x = 0;
    }
    loadLevel(path);
}
        
void AdventureWorld::changePause(){
    is_paused = ! is_paused;
}
        
bool AdventureWorld::isPaused(){
    return is_paused;
}

void AdventureWorld::pause(){
    is_paused = true;
}

void AdventureWorld::unpause(){
    is_paused = false;
}

struct LoadLevelInfo{
    LoadLevelInfo(AdventureWorld * who, const Filesystem::AbsolutePath & path):
        who(who), path(path){}

    AdventureWorld * who;
    const Filesystem::AbsolutePath & path;
};

void * AdventureWorld::do_load_level(void * arg){
    LoadLevelInfo * info = (LoadLevelInfo *) arg;
    AdventureWorld * world = info->who;
    world->loadLevel(info->path);
    delete info;
    return NULL;
}

void AdventureWorld::threadedLoadLevel(const Filesystem::AbsolutePath & path){
    /* this looks dangerous, passing a temporary to a thread but in theory
     * the temporary should live past the end of the thread life
     * so the memory will stick around.
     */
    LoadLevelInfo * info = new LoadLevelInfo(this, path);
    Util::WaitThread thread(do_load_level, info);
    Util::EventManager manager;
    manager.waitForThread(thread);
}

bool AdventureWorld::randomLevel() const {
    /* FIXME: let the user decide to make this true or not */
    return false;
}
{'fraction_non_alphanumeric': 0.13895033179167504, 'fraction_numerical': 0.012467323547154635, 'mean_word_length': 3.409131205673759, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 47, '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': '3600284', 'n_tokens_mistral': 3316, 'n_tokens_neox': 3089, 'n_words': 773}