<commit_before>package flixel.system.frontEnds;

import flash.geom.Rectangle;
import flixel.FlxCamera;
import flixel.FlxG;
import flixel.util.FlxArrayUtil;
import flixel.util.FlxColor;

class CameraFrontEnd
{
	/**
	 * An array listing <code>FlxCamera</code> objects that are used to draw stuff.
	 * By default flixel creates one camera the size of the screen.
	 */
	public var list(default, null):Array<FlxCamera>;
	/**
	 * Allows you to possibly slightly optimize the rendering process IF
	 * you are not doing any pre-processing in your game state's <code>draw()</code> call.
	 * @default false
	 */
	public var useBufferLocking:Bool = false;
	/**
	 * Internal helper variable for clearing the cameras each frame.
	 */
	private var _cameraRect:Rectangle;
	
	public function new() 
	{
		_cameraRect = new Rectangle();
		list = new Array<FlxCamera>();
	}
	
	/**
	 * Called by the game object to lock all the camera buffers and clear them for the next draw pass.
	 */
	inline public function lock():Void
	{
		for (camera in list)
		{
			if (camera == null || !camera.exists || !camera.visible)
			{
				continue;
			}
			
			#if flash
			camera.checkResize();
			
			if (useBufferLocking)
			{
				camera.buffer.lock();
			}
			#end
			
		#if !flash
			camera.clearDrawStack();
			camera.canvas.graphics.clear();
			// Clearing camera's debug sprite
			#if !FLX_NO_DEBUG
			camera.debugLayer.graphics.clear();
			#end
		#end
			
			#if flash
			camera.fill(camera.bgColor, camera.useBgAlphaBlending);
			camera.screen.dirty = true;
			#else
			camera.fill((camera.bgColor & 0x00ffffff), camera.useBgAlphaBlending, ((camera.bgColor >> 24) & 255) / 255);
			#end
		}
	}
	
	#if !flash
	inline public function render():Void
	{
		for (camera in list)
		{
			if (camera != null && camera.exists && camera.visible)
			{
				camera.render();
			}
		}
	}
	#end
	
	/**
	 * Called by the game object to draw the special FX and unlock all the camera buffers.
	 */
	inline public function unlock():Void
	{
		for (camera in list)
		{
			if (camera == null || !camera.exists || !camera.visible)
			{
				continue;
			}
			
			camera.drawFX();
			
			#if flash
			if (useBufferLocking)
			{
				camera.buffer.unlock();
			}
			
			camera.screen.resetFrameBitmapDatas();
			#end
		}
	}
	
	/**
	 * Called by the game object to update the cameras and their tracking/special effects logic.
	 */
	inline public function update():Void
	{
		for (camera in list)
		{
			if (camera != null && camera.exists)
			{
				if (camera.active)
				{
					camera.update();
				}
				
				if (camera.target == null) 
				{
					camera.flashSprite.x = camera.x + camera.flashOffsetX;
					camera.flashSprite.y = camera.y + camera.flashOffsetY;
				}
				
				camera.flashSprite.visible = camera.visible;
			}
		}
	}
	
	/**
	 * Add a new camera object to the game.
	 * Handy for PiP, split-screen, etc.
	 * 
	 * @param	NewCamera	The camera you want to add.
	 * @return	This <code>FlxCamera</code> instance.
	 */
	inline public function add(NewCamera:FlxCamera):FlxCamera
	{
		FlxG.game.addChildAt(NewCamera.flashSprite, FlxG.game.getChildIndex(FlxG.game.inputContainer));
		FlxG.cameras.list.push(NewCamera);
		NewCamera.ID = FlxG.cameras.list.length - 1;
		return NewCamera;
	}
	
	/**<commit_msg>Added type param for CamerFrontEnd.add()<commit_after>package flixel.system.frontEnds;

import flash.geom.Rectangle;
import flixel.FlxCamera;
import flixel.FlxG;
import flixel.util.FlxArrayUtil;
import flixel.util.FlxColor;

class CameraFrontEnd
{
	/**
	 * An array listing <code>FlxCamera</code> objects that are used to draw stuff.
	 * By default flixel creates one camera the size of the screen.
	 */
	public var list(default, null):Array<FlxCamera>;
	/**
	 * Allows you to possibly slightly optimize the rendering process IF
	 * you are not doing any pre-processing in your game state's <code>draw()</code> call.
	 * @default false
	 */
	public var useBufferLocking:Bool = false;
	/**
	 * Internal helper variable for clearing the cameras each frame.
	 */
	private var _cameraRect:Rectangle;
	
	public function new() 
	{
		_cameraRect = new Rectangle();
		list = new Array<FlxCamera>();
	}
	
	/**
	 * Called by the game object to lock all the camera buffers and clear them for the next draw pass.
	 */
	inline public function lock():Void
	{
		for (camera in list)
		{
			if (camera == null || !camera.exists || !camera.visible)
			{
				continue;
			}
			
			#if flash
			camera.checkResize();
			
			if (useBufferLocking)
			{
				camera.buffer.lock();
			}
			#end
			
		#if !flash
			camera.clearDrawStack();
			camera.canvas.graphics.clear();
			// Clearing camera's debug sprite
			#if !FLX_NO_DEBUG
			camera.debugLayer.graphics.clear();
			#end
		#end
			
			#if flash
			camera.fill(camera.bgColor, camera.useBgAlphaBlending);
			camera.screen.dirty = true;
			#else
			camera.fill((camera.bgColor & 0x00ffffff), camera.useBgAlphaBlending, ((camera.bgColor >> 24) & 255) / 255);
			#end
		}
	}
	
	#if !flash
	inline public function render():Void
	{
		for (camera in list)
		{
			if (camera != null && camera.exists && camera.visible)
			{
				camera.render();
			}
		}
	}
	#end
	
	/**
	 * Called by the game object to draw the special FX and unlock all the camera buffers.
	 */
	inline public function unlock():Void
	{
		for (camera in list)
		{
			if (camera == null || !camera.exists || !camera.visible)
			{
				continue;
			}
			
			camera.drawFX();
			
			#if flash
			if (useBufferLocking)
			{
				camera.buffer.unlock();
			}
			
			camera.screen.resetFrameBitmapDatas();
			#end
		}
	}
	
	/**
	 * Called by the game object to update the cameras and their tracking/special effects logic.
	 */
	inline public function update():Void
	{
		for (camera in list)
		{
			if (camera != null && camera.exists)
			{
				if (camera.active)
				{
					camera.update();
				}
				
				if (camera.target == null) 
				{
					camera.flashSprite.x = camera.x + camera.flashOffsetX;
					camera.flashSprite.y = camera.y + camera.flashOffsetY;
				}
				
				camera.flashSprite.visible = camera.visible;
			}
		}
	}
	
	/**
	 * Add a new camera object to the game.
	 * Handy for PiP, split-screen, etc.
	 * 
	 * @param	NewCamera	The camera you want to add.
	 * @return	This <code>FlxCamera</code> instance.
	 */
	@:generic inline public function add<T:FlxCamera>(NewCamera:T):T
	{
		FlxG.game.addChildAt(NewCamera.flashSprite, FlxG.game.getChildIndex(FlxG.game.inputContainer));
		FlxG.cameras.list.push(NewCamera);
		NewCamera.ID = FlxG.cameras.list.length - 1;
		return NewCamera;
	}
	
	/**
{'fraction_non_alphanumeric': 0.12057387057387058, 'fraction_numerical': 0.003663003663003663, 'mean_word_length': 2.921603830041891, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 24, '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': '2354114', 'n_tokens_mistral': 2605, 'n_tokens_neox': 2143, 'n_words': 583}