<commit_before>#include "util/bitmap.h"
#include "mugen/background.h"
#include <math.h>
#include <ostream>
#include <cstring>
#include <string>
#include <list>
#include <algorithm>
#include "globals.h"
#include "mugen_sprite.h"
#include "util/regex.h"
#include "util/file-system.h"
#include "util/timedifference.h"
#include "ast/all.h"
#include "parser/all.h"

using namespace std;
namespace PaintownUtil = ::Util;
using namespace Mugen;

// Default to center of screen
const unsigned int MAP_X = 120;
const unsigned int MAP_Y = 0;

struct Tile {
    int start;
    int total;
};

static Tile getTileData( int location, int length, int spacing, int total ){
    Tile tile;
    if (total == 0){
	tile.start = location;
	tile.total = 1;
	return tile;
    } else if (total > 1){
	tile.start = location;
	tile.total = total;
	return tile;
    } else if (total == 1){
	// Infinite tiling.. just tile on the board
	if (location < 0){
	    // Less than the board itself lets get location up to that point
	    while (location < 0){
		location+=spacing;
	    }
	    // Now backup 1 so we get the wrap effect 
	    location-=spacing;
	} else{
	    // Either Larger than the board or inside seek back to beginning
	    while (location > 0){
		location-=spacing;
	    }
	}
	// Now figure out how many we need to do
	int temp = location;
	// Reuse total
	total = 0;
	while (temp < length){
	    total++;
	    temp+=spacing;
	}
	// Blammo
	tile.start = location;
	tile.total = total;
	return tile;
    }
    tile.start = 0;
    tile.total = 0;
    return tile;
}

static double interpolate(double f1, double f2, double p){
    return (f1 * (1.0 - p)) + (f2 * p);
}
static int ff = 0;
static void doParallax2(const Bitmap &bmp, const Bitmap &work, int leftx, int lefty, int xoffset, double top, double bot, int yscalestart, double yscaledelta, double yoffset, bool mask){
    const int height = bmp.getHeight();
    const int width = bmp.getWidth();
    //double z = 1.0 / z1;
    //const double z_add = ((1.0 / z2) - z) / (y2 - y1);


    Global::debug(3) << "background leftx " << leftx << endl;
    xoffset = 0;

    leftx -= 320;

    // leftx = 0;
    // leftx = ff;
    // xoffset = 50;
    // xoffset = ff - 300;
    ff = (ff + 1) % 600;

    for (int localy = 0; localy < height; ++localy ){
        int movex = 0;
	//int width = bmp.getWidth()*z;
        const double range = (double)localy / (double)height;
	const double scale = interpolate(top, bot, range);
	//const double newHeight = height*((yscalestart+(yoffset*yscaledelta))/100);
	//const double yscale = (newHeight/height);
	// movex = (int)(leftx + (leftx - xoffset) * (scale - top));
	movex = (int)(xoffset + (xoffset - leftx) * (scale - top));
	bmp.Stretch(work, 0, localy, width, 1, movex, lefty+localy, width, 1);
        // bmp.BlitMasked(0, localy, width, 1, movex, lefty + localy, work);
        // bmp.Blit(0, localy, width, 1, movex, lefty + localy, work);
	//z +=  z_add;
	//Global::debug(1) << "Height: " << height << " | yscalestart: " << yscalestart << " | yscaledelta: " << yscaledelta << " | yoffset: " << yoffset << " | New Height: " << newHeight << " | yscale: " << yscale << endl;	
    }
}


BackgroundElement::BackgroundElement():
deltaX(1),
deltaY(1),
windowDeltaX(0),
windowDeltaY(0),
positionLink(false),
velocityX(0),
velocityY(0),
linkedElement(0){
}
BackgroundElement::~BackgroundElement(){
}

void BackgroundElement::setLink(BackgroundElement *element){
    element->linkedElement = this;
    if (positionLink){
	if (linkedElement){
	    linkedElement->setLink(element);
	    return;
	}
    }
    Mugen::Point newStart = element->getStart();
    newStart.x += start.x;
    newStart.y += start.y;<commit_msg>Clarify setLink in comments<commit_after>#include "util/bitmap.h"
#include "mugen/background.h"
#include <math.h>
#include <ostream>
#include <cstring>
#include <string>
#include <list>
#include <algorithm>
#include "globals.h"
#include "mugen_sprite.h"
#include "util/regex.h"
#include "util/file-system.h"
#include "util/timedifference.h"
#include "ast/all.h"
#include "parser/all.h"

using namespace std;
namespace PaintownUtil = ::Util;
using namespace Mugen;

// Default to center of screen
const unsigned int MAP_X = 120;
const unsigned int MAP_Y = 0;

struct Tile {
    int start;
    int total;
};

static Tile getTileData( int location, int length, int spacing, int total ){
    Tile tile;
    if (total == 0){
	tile.start = location;
	tile.total = 1;
	return tile;
    } else if (total > 1){
	tile.start = location;
	tile.total = total;
	return tile;
    } else if (total == 1){
	// Infinite tiling.. just tile on the board
	if (location < 0){
	    // Less than the board itself lets get location up to that point
	    while (location < 0){
		location+=spacing;
	    }
	    // Now backup 1 so we get the wrap effect 
	    location-=spacing;
	} else{
	    // Either Larger than the board or inside seek back to beginning
	    while (location > 0){
		location-=spacing;
	    }
	}
	// Now figure out how many we need to do
	int temp = location;
	// Reuse total
	total = 0;
	while (temp < length){
	    total++;
	    temp+=spacing;
	}
	// Blammo
	tile.start = location;
	tile.total = total;
	return tile;
    }
    tile.start = 0;
    tile.total = 0;
    return tile;
}

static double interpolate(double f1, double f2, double p){
    return (f1 * (1.0 - p)) + (f2 * p);
}
static int ff = 0;
static void doParallax2(const Bitmap &bmp, const Bitmap &work, int leftx, int lefty, int xoffset, double top, double bot, int yscalestart, double yscaledelta, double yoffset, bool mask){
    const int height = bmp.getHeight();
    const int width = bmp.getWidth();
    //double z = 1.0 / z1;
    //const double z_add = ((1.0 / z2) - z) / (y2 - y1);


    Global::debug(3) << "background leftx " << leftx << endl;
    xoffset = 0;

    leftx -= 320;

    // leftx = 0;
    // leftx = ff;
    // xoffset = 50;
    // xoffset = ff - 300;
    ff = (ff + 1) % 600;

    for (int localy = 0; localy < height; ++localy ){
        int movex = 0;
	//int width = bmp.getWidth()*z;
        const double range = (double)localy / (double)height;
	const double scale = interpolate(top, bot, range);
	//const double newHeight = height*((yscalestart+(yoffset*yscaledelta))/100);
	//const double yscale = (newHeight/height);
	// movex = (int)(leftx + (leftx - xoffset) * (scale - top));
	movex = (int)(xoffset + (xoffset - leftx) * (scale - top));
	bmp.Stretch(work, 0, localy, width, 1, movex, lefty+localy, width, 1);
        // bmp.BlitMasked(0, localy, width, 1, movex, lefty + localy, work);
        // bmp.Blit(0, localy, width, 1, movex, lefty + localy, work);
	//z +=  z_add;
	//Global::debug(1) << "Height: " << height << " | yscalestart: " << yscalestart << " | yscaledelta: " << yscaledelta << " | yoffset: " << yoffset << " | New Height: " << newHeight << " | yscale: " << yscale << endl;	
    }
}


BackgroundElement::BackgroundElement():
deltaX(1),
deltaY(1),
windowDeltaX(0),
windowDeltaY(0),
positionLink(false),
velocityX(0),
velocityY(0),
linkedElement(0){
}
BackgroundElement::~BackgroundElement(){
}

/* Copy the contents of this into element
 * If this element is linked then we will call it recursively until we've come to the end of the chain
 * and then copy the contents of the last link of the chain into our passed element
 */
void BackgroundElement::setLink(BackgroundElement *element){
    element->linkedElement = this;
    if (positionLink){
	if (linkedElement){
	    linkedElement->setLink(element);
	    return;
	}
    }
    Mugen::Point newStart = element->getStart();
    newStart.x += start.x;
    newStart.y += start.y;
{'fraction_non_alphanumeric': 0.14885245901639343, 'fraction_numerical': 0.017311475409836064, 'mean_word_length': 3.1490750816104462, 'pattern_counts': {'":': 0, '<': 87, '<?xml version=': 0, '>': 25, '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': '3186572', 'n_tokens_mistral': 2803, 'n_tokens_neox': 2626, 'n_words': 809}