<commit_before>package net.mgsx.game.core;

import com.badlogic.ashley.core.Component;
import com.badlogic.ashley.core.Engine;
import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.utils.Json.Serializer;

import net.mgsx.game.core.storage.Storage;
import net.mgsx.game.plugins.camera.components.CameraComponent;
import net.mgsx.game.plugins.camera.components.CullingComponent;
import net.mgsx.game.plugins.camera.components.RenderingComponent;
import net.mgsx.game.plugins.camera.systems.CameraSystem;

/**
 * Base screen for managed game scene.
 * Has its own Entity Engine.
 * 
 * @author mgsx
 *
 */
public class GameScreen extends ScreenAdapter
{
	final public AssetManager assets;
	
	final public Engine entityEngine;
	public GameRegistry registry;
	private Entity camera;
	
	private CameraSystem cameraSystem;
	
	public GameScreen(AssetManager assets, Engine engine) {
		super();
		this.assets = assets;
		this.entityEngine = engine;
		init();
	}
	
	
	protected <T extends Component> T addComponent(Entity entity, Class<T> type){
		T component = entityEngine.createComponent(type);
		entity.add(component);
		return component;
	}
	
	private void init()
	{
		createCamera();
	}
	
	@Override
	public void show() {
		super.show();
		cameraSystem = entityEngine.getSystem(CameraSystem.class);
	}
	
	public Camera getRenderCamera()
	{
		Entity cameraEntity = cameraSystem.getRenderCamera();
		CameraComponent camera = CameraComponent.components.get(cameraEntity);
		return camera.camera;
	}
	
	void createCamera() 
	{
		Camera gameCamera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		gameCamera.position.set(0, 0, 10);
		gameCamera.up.set(0,1,0);
		gameCamera.lookAt(0,0,0);
		gameCamera.near = 1f;
		gameCamera.far = 3000f;
		gameCamera.update(true);
		
		camera = entityEngine.createEntity();
		addComponent(camera, CameraComponent.class).camera = gameCamera;
		addComponent(camera, RenderingComponent.class);
		addComponent(camera, CullingComponent.class);
		entityEngine.addEntity(camera);
	}


	public Camera getCullingCamera()
	{
		Entity cameraEntity = cameraSystem.getCullingCamera();
		CameraComponent camera = CameraComponent.components.get(cameraEntity);
		return camera.camera;
	}
	
	
	// TODO remove ?
	@Override
	public void render(float delta) {
		
		// TODO in systems
		Gdx.gl.glClearColor(.7f, .9f, 1f, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

		// run the engine
		entityEngine.update(Gdx.graphics.getDeltaTime());
	}
	
	@Override
	public void resize(int width, int height) <commit_msg>change default clear color<commit_after>package net.mgsx.game.core;

import com.badlogic.ashley.core.Component;
import com.badlogic.ashley.core.Engine;
import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.utils.Json.Serializer;

import net.mgsx.game.core.storage.Storage;
import net.mgsx.game.plugins.camera.components.CameraComponent;
import net.mgsx.game.plugins.camera.components.CullingComponent;
import net.mgsx.game.plugins.camera.components.RenderingComponent;
import net.mgsx.game.plugins.camera.systems.CameraSystem;

/**
 * Base screen for managed game scene.
 * Has its own Entity Engine.
 * 
 * @author mgsx
 *
 */
public class GameScreen extends ScreenAdapter
{
	final public AssetManager assets;
	
	final public Engine entityEngine;
	public GameRegistry registry;
	private Entity camera;
	
	private CameraSystem cameraSystem;
	
	public GameScreen(AssetManager assets, Engine engine) {
		super();
		this.assets = assets;
		this.entityEngine = engine;
		init();
	}
	
	
	protected <T extends Component> T addComponent(Entity entity, Class<T> type){
		T component = entityEngine.createComponent(type);
		entity.add(component);
		return component;
	}
	
	private void init()
	{
		createCamera();
	}
	
	@Override
	public void show() {
		super.show();
		cameraSystem = entityEngine.getSystem(CameraSystem.class);
	}
	
	public Camera getRenderCamera()
	{
		Entity cameraEntity = cameraSystem.getRenderCamera();
		CameraComponent camera = CameraComponent.components.get(cameraEntity);
		return camera.camera;
	}
	
	void createCamera() 
	{
		Camera gameCamera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		gameCamera.position.set(0, 0, 10);
		gameCamera.up.set(0,1,0);
		gameCamera.lookAt(0,0,0);
		gameCamera.near = 1f;
		gameCamera.far = 3000f;
		gameCamera.update(true);
		
		camera = entityEngine.createEntity();
		addComponent(camera, CameraComponent.class).camera = gameCamera;
		addComponent(camera, RenderingComponent.class);
		addComponent(camera, CullingComponent.class);
		entityEngine.addEntity(camera);
	}


	public Camera getCullingCamera()
	{
		Entity cameraEntity = cameraSystem.getCullingCamera();
		CameraComponent camera = CameraComponent.components.get(cameraEntity);
		return camera.camera;
	}
	
	
	// TODO remove ?
	@Override
	public void render(float delta) {
		
		// TODO in systems
		Gdx.gl.glClearColor(.2f, .2f, .2f, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

		// run the engine
		entityEngine.update(Gdx.graphics.getDeltaTime());
	}
	
	@Override
	public void resize(int width, int height) 
{'fraction_non_alphanumeric': 0.11194029850746269, 'fraction_numerical': 0.009371745921555015, 'mean_word_length': 4.815338042381433, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2224152', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1817, 'n_words': 369}