<commit_before>package org.glob3.mobile.generated; 
//
//  TileImagesTileTexturizer.cpp
//  G3MiOSSDK
//
//  Created by <NAME> on 12/07/12.
//  Copyright (c) 2012 IGO Software SL. All rights reserved.
//

//
//  TileImagesTileTexturizer.hpp
//  G3MiOSSDK
//
//  Created by <NAME> on 12/07/12.
//  Copyright (c) 2012 IGO Software SL. All rights reserved.
//








//C++ TO JAVA CONVERTER NOTE: Java has no need of forward class declarations:
//class TilePetitions;
//C++ TO JAVA CONVERTER NOTE: Java has no need of forward class declarations:
//class WMSLayer;

public class TileImagesTileTexturizer extends TileTexturizer
{

  //STATE
  private IFactory _factory; // FINAL WORD REMOVE BY CONVERSOR RULE
  private TexturesHandler _texHandler;
  private Downloader _downloader;
  private RenderContext _renderContext;

  private java.util.ArrayList<TilePetitions> _tilePetitions = new java.util.ArrayList<TilePetitions>();
  private java.util.ArrayList<TilePetitions> _tilePetitionsTopTile = new java.util.ArrayList<TilePetitions>();

  private final TileParameters _parameters;

  private WMSLayer _layer;
  private LayerSet _layerSet;

  private java.util.ArrayList<MutableVector2D> _texCoordsCache;

  private TilePetitions createTilePetitions(Tile tile)
  {
	java.util.ArrayList<Petition> pet = _layerSet.createTilePetitions(_renderContext, _factory, tile, _parameters._tileTextureWidth, _parameters._tileTextureHeight);
  
	return new TilePetitions(tile.getLevel(), tile.getRow(), tile.getColumn(), tile.getSector(), pet);
  }

//C++ TO JAVA CONVERTER WARNING: 'const' methods are not available in Java:
//ORIGINAL LINE: java.util.ArrayList<MutableVector2D> getTextureCoordinates(const TileTessellator* tessellator) const
  private java.util.ArrayList<MutableVector2D> getTextureCoordinates(TileTessellator tessellator)
  {
	if (_texCoordsCache == null)
	{
	  _texCoordsCache = tessellator.createUnitTextCoords();
	}
  
	return _texCoordsCache;
  }

//C++ TO JAVA CONVERTER WARNING: 'const' methods are not available in Java:
//ORIGINAL LINE: void translateAndScaleFallBackTex(Tile* tile, Tile* fallbackTile, TextureMapping* tmap) const
  private void translateAndScaleFallBackTex(Tile tile, Tile fallbackTile, TextureMapping tmap)
  {
	final Sector tileSector = tile.getSector();
	final Sector fallbackTileSector = fallbackTile.getSector();
  
	tmap.setTranslationAndScale(tileSector.getTranslationFactor(fallbackTileSector), tileSector.getScaleFactor(fallbackTileSector));
  }

  private void registerNewRequest(Tile tile)
  {
	if (getRegisteredTilePetitions(tile) == null) //NOT YET REQUESTED
	{
	  int priority = tile.getLevel(); //DOWNLOAD PRIORITY SET TO TILE LEVEL
	  TilePetitions tp = createTilePetitions(tile);
	  _tilePetitions.add(tp); //STORED
	  tp.requestToNet(_downloader, priority);
	}
  }

//C++ TO JAVA CONVERTER WARNING: 'const' methods are not available in Java:
//ORIGINAL LINE: TilePetitions* getRegisteredTilePetitions(Tile* tile) const
  private TilePetitions getRegisteredTilePetitions(Tile tile)
  {
  //  for(std::list<TilePetitions*>::iterator it = _tilePetitions.begin();
  //      it != _tilePetitions.end();
  //      it++) {
  //    TilePetitions* tp = *it;
  //
  //    if (tile->getLevel()  == tp->getLevel() &&
  //        tile->getRow()    == tp->getRow()   &&
  //        tile->getColumn() == tp->getColumn()) {
  //      return tp;
  //    }
  //  }
  
	for (int i = 0; i < _tilePetitions.size(); i++)
	{
	  TilePetitions tp = _tilePetitions.get(i);
	  if (tile.getLevel() == tp.getLevel() && tile.getRow() == tp.getRow() && tile.getColumn() == tp.getColumn())
	  {
		return tp;
	  }
	}
  
	return null;
  }
  private void removeRegisteredTilePetitions(Tile tile)
  {
  //  for(std::list<TilePetitions*>::iterator it = _tilePetitions.begin();
  //      it != _tilePetitions.end();
  //      it++) {
  //    TilePetitions* tp = *it;
  //    if (tile->getLevel()  == tp->getLevel() &&
  //        tile->getRow()    == tp->getRow()   &&
  //        tile->getColumn() == tp->getColumn()) {
  //      _tilePetitions.erase(it);
  //      delete tp;
  //      break;
  //    }
  //  }
  
	TilePetitions tp = null;
	for (int i = 0; i < _tilePetitions.size(); i++)
	{
	  tp = _tilePetitions.get(i);
	  if (tile.getLevel() == tp.getLevel() && tile.getRow() == tp.getRow() && tile.getColumn() == tp.getColumn())
	  {
  
  	  _tilePetitions.remove(i);
		if (tp != null)
			tp.dispose();
		break;
	  }
	}
  }

  private Mesh getFallBackTexturedMesh(Tile tile, TileTessellator tessellator, Mesh tessellatorMesh, Mesh previousMesh)
  {
	TextureMapping fbTMap = NULL;
	int texID = -1;
	Tile fbTile = tile.getParent();
	while (fbTile != null && texID < 0)
	{
  
	  if (fbTile.isTextureSolved())
	  {
		TexturedMesh texMesh = (TexturedMesh) fbTile.getTexturizerMesh();
		if (texMesh != null)
		{
		  fbTMap = texMesh.getTextureMapping();
  
		  texID = _texHandler.getTextureIdIfAvailable(fbTMap.getStringTexID(), fbTMap.getWidth(), fbTMap.getHeight());
  
		  break;
		}
	  }
	  fbTile = fbTile.getParent(); //TRYING TO CREATE FALLBACK TEXTURE FROM ANTECESOR
	}
  
	//CREATING MESH
	if (texID > -1)
	{
	  TextureMapping tMap = new TextureMapping(texID, getTextureCoordinates(tessellator), _texHandler, fbTMap.getStringTexID(), fbTMap.getWidth(), fbTMap.getHeight());
	  translateAndScaleFallBackTex(tile, fbTile, tMap);
	  TexturedMesh texMesh = new TexturedMesh(tessellatorMesh, false, tMap, true);
	  if (previousMesh != null)
		  previousMesh.dispose(); //If a new mesh has been produced we delete the previous one
	  return texMesh;<commit_msg>Generated<commit_after>package org.glob3.mobile.generated; 
//
//  TileImagesTileTexturizer.cpp
//  G3MiOSSDK
//
//  Created by <NAME> on 12/07/12.
//  Copyright (c) 2012 IGO Software SL. All rights reserved.
//

//
//  TileImagesTileTexturizer.hpp
//  G3MiOSSDK
//
//  Created by <NAME> on 12/07/12.
//  Copyright (c) 2012 IGO Software SL. All rights reserved.
//








//C++ TO JAVA CONVERTER NOTE: Java has no need of forward class declarations:
//class TilePetitions;
//C++ TO JAVA CONVERTER NOTE: Java has no need of forward class declarations:
//class WMSLayer;

public class TileImagesTileTexturizer extends TileTexturizer
{

  //STATE
  private IFactory _factory; // FINAL WORD REMOVE BY CONVERSOR RULE
  private TexturesHandler _texHandler;
  private Downloader _downloader;
  private RenderContext _renderContext;

  private java.util.ArrayList<TilePetitions> _tilePetitions = new java.util.ArrayList<TilePetitions>();
  private java.util.ArrayList<TilePetitions> _tilePetitionsTopTile = new java.util.ArrayList<TilePetitions>();

  private final TileParameters _parameters;

  private WMSLayer _layer;
  private LayerSet _layerSet;

  private java.util.ArrayList<MutableVector2D> _texCoordsCache;

  private TilePetitions createTilePetitions(Tile tile)
  {
	java.util.ArrayList<Petition> pet = _layerSet.createTilePetitions(_renderContext, _factory, tile, _parameters._tileTextureWidth, _parameters._tileTextureHeight);
  
	return new TilePetitions(tile.getLevel(), tile.getRow(), tile.getColumn(), tile.getSector(), pet);
  }

//C++ TO JAVA CONVERTER WARNING: 'const' methods are not available in Java:
//ORIGINAL LINE: java.util.ArrayList<MutableVector2D> getTextureCoordinates(const TileTessellator* tessellator) const
  private java.util.ArrayList<MutableVector2D> getTextureCoordinates(TileTessellator tessellator)
  {
	if (_texCoordsCache == null)
	{
	  _texCoordsCache = tessellator.createUnitTextCoords();
	}
  
	return _texCoordsCache;
  }

//C++ TO JAVA CONVERTER WARNING: 'const' methods are not available in Java:
//ORIGINAL LINE: void translateAndScaleFallBackTex(Tile* tile, Tile* fallbackTile, TextureMapping* tmap) const
  private void translateAndScaleFallBackTex(Tile tile, Tile fallbackTile, TextureMapping tmap)
  {
	final Sector tileSector = tile.getSector();
	final Sector fallbackTileSector = fallbackTile.getSector();
  
	tmap.setTranslationAndScale(tileSector.getTranslationFactor(fallbackTileSector), tileSector.getScaleFactor(fallbackTileSector));
  }

  private void registerNewRequest(Tile tile)
  {
	if (getRegisteredTilePetitions(tile) == null) //NOT YET REQUESTED
	{
	  int priority = tile.getLevel(); //DOWNLOAD PRIORITY SET TO TILE LEVEL
	  TilePetitions tp = createTilePetitions(tile);
	  _tilePetitions.add(tp); //STORED
	  tp.requestToNet(_downloader, priority);
	}
  }

//C++ TO JAVA CONVERTER WARNING: 'const' methods are not available in Java:
//ORIGINAL LINE: TilePetitions* getRegisteredTilePetitions(Tile* tile) const
  private TilePetitions getRegisteredTilePetitions(Tile tile)
  {
  //  for(std::list<TilePetitions*>::iterator it = _tilePetitions.begin();
  //      it != _tilePetitions.end();
  //      it++) {
  //    TilePetitions* tp = *it;
  //
  //    if (tile->getLevel()  == tp->getLevel() &&
  //        tile->getRow()    == tp->getRow()   &&
  //        tile->getColumn() == tp->getColumn()) {
  //      return tp;
  //    }
  //  }
  
	for (int i = 0; i < _tilePetitions.size(); i++)
	{
	  TilePetitions tp = _tilePetitions.get(i);
	  if (tile.getLevel() == tp.getLevel() && tile.getRow() == tp.getRow() && tile.getColumn() == tp.getColumn())
	  {
		return tp;
	  }
	}
  
	return null;
  }
  private void removeRegisteredTilePetitions(Tile tile)
  {
  //  for(std::list<TilePetitions*>::iterator it = _tilePetitions.begin();
  //      it != _tilePetitions.end();
  //      it++) {
  //    TilePetitions* tp = *it;
  //    if (tile->getLevel()  == tp->getLevel() &&
  //        tile->getRow()    == tp->getRow()   &&
  //        tile->getColumn() == tp->getColumn()) {
  //      _tilePetitions.erase(it);
  //      delete tp;
  //      break;
  //    }
  //  }
  
	TilePetitions tp = null;
	for (int i = 0; i < _tilePetitions.size(); i++)
	{
	  tp = _tilePetitions.get(i);
	  if (tile.getLevel() == tp.getLevel() && tile.getRow() == tp.getRow() && tile.getColumn() == tp.getColumn())
	  {
  
  	  _tilePetitions.remove(i);
		if (tp != null)
			tp.dispose();
		break;
	  }
	}
  }

  private Mesh getFallBackTexturedMesh(Tile tile, TileTessellator tessellator, Mesh tessellatorMesh, Mesh previousMesh)
  {
	TextureMapping fbTMap = null;
	int texID = -1;
	Tile fbTile = tile.getParent();
	while (fbTile != null && texID < 0)
	{
  
	  if (fbTile.isTextureSolved())
	  {
		TexturedMesh texMesh = (TexturedMesh) fbTile.getTexturizerMesh();
		if (texMesh != null)
		{
		  fbTMap = texMesh.getTextureMapping();
  
		  texID = _texHandler.getTextureIdIfAvailable(fbTMap.getStringTexID(), fbTMap.getWidth(), fbTMap.getHeight());
  
		  break;
		}
	  }
	  fbTile = fbTile.getParent(); //TRYING TO CREATE FALLBACK TEXTURE FROM ANTECESOR
	}
  
	//CREATING MESH
	if (texID > -1)
	{
	  TextureMapping tMap = new TextureMapping(texID, getTextureCoordinates(tessellator), _texHandler, fbTMap.getStringTexID(), fbTMap.getWidth(), fbTMap.getHeight());
	  translateAndScaleFallBackTex(tile, fbTile, tMap);
	  TexturedMesh texMesh = new TexturedMesh(tessellatorMesh, false, tMap, true);
	  if (previousMesh != null)
		  previousMesh.dispose(); //If a new mesh has been produced we delete the previous one
	  return texMesh;
{'fraction_non_alphanumeric': 0.12919432980441414, 'fraction_numerical': 0.00556253364435672, 'mean_word_length': 3.7373565660858477, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6038123', 'n_tokens_mistral': 3991, 'n_tokens_neox': 3791, 'n_words': 851}