idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
3,200
public static CollisionConfig imports ( Configurer configurer ) { Check . notNull ( configurer ) ; final Map < String , Collision > collisions = new HashMap < > ( 0 ) ; for ( final Xml node : configurer . getRoot ( ) . getChildren ( NODE_COLLISION ) ) { final String coll = node . readString ( ATT_NAME ) ; final Collision collision = createCollision ( node ) ; collisions . put ( coll , collision ) ; } return new CollisionConfig ( collisions ) ; }
Create the collision data from node .
3,201
public static Collision createCollision ( XmlReader node ) { Check . notNull ( node ) ; final String name = node . readString ( ATT_NAME ) ; final int offsetX = node . readInteger ( ATT_OFFSETX ) ; final int offsetY = node . readInteger ( ATT_OFFSETY ) ; final int width = node . readInteger ( ATT_WIDTH ) ; final int height = node . readInteger ( ATT_HEIGHT ) ; final boolean mirror = node . readBoolean ( ATT_MIRROR ) ; return new Collision ( name , offsetX , offsetY , width , height , mirror ) ; }
Create an collision from its node .
3,202
public static void exports ( Xml root , Collision collision ) { Check . notNull ( root ) ; Check . notNull ( collision ) ; final Xml node = root . createChild ( NODE_COLLISION ) ; node . writeString ( ATT_NAME , collision . getName ( ) ) ; node . writeInteger ( ATT_OFFSETX , collision . getOffsetX ( ) ) ; node . writeInteger ( ATT_OFFSETY , collision . getOffsetY ( ) ) ; node . writeInteger ( ATT_WIDTH , collision . getWidth ( ) ) ; node . writeInteger ( ATT_HEIGHT , collision . getHeight ( ) ) ; node . writeBoolean ( ATT_MIRROR , collision . hasMirror ( ) ) ; }
Create an XML node from a collision .
3,203
public Collision getCollision ( String name ) { if ( collisions . containsKey ( name ) ) { return collisions . get ( name ) ; } throw new LionEngineException ( ERROR_COLLISION_NOT_FOUND + name ) ; }
Get a collision data from its name .
3,204
private static Map < Circuit , Collection < TileRef > > getCircuits ( MapTile map ) { final MapTileGroup mapGroup = map . getFeature ( MapTileGroup . class ) ; final Map < Circuit , Collection < TileRef > > circuits = new HashMap < > ( ) ; final MapCircuitExtractor extractor = new MapCircuitExtractor ( map ) ; for ( int ty = 1 ; ty < map . getInTileHeight ( ) - 1 ; ty ++ ) { for ( int tx = 1 ; tx < map . getInTileWidth ( ) - 1 ; tx ++ ) { final Tile tile = map . getTile ( tx , ty ) ; if ( tile != null && TileGroupType . CIRCUIT == mapGroup . getType ( tile ) ) { checkCircuit ( circuits , extractor , map , tile ) ; } } } return circuits ; }
Get map tile circuits .
3,205
private static void checkCircuit ( Map < Circuit , Collection < TileRef > > circuits , MapCircuitExtractor extractor , MapTile map , Tile tile ) { final Circuit circuit = extractor . getCircuit ( tile ) ; if ( circuit != null ) { final TileRef ref = new TileRef ( tile ) ; getTiles ( circuits , circuit ) . add ( ref ) ; checkTransitionGroups ( circuits , circuit , map , ref ) ; } }
Check the tile circuit and add it to circuits collection if valid .
3,206
private static void checkTransitionGroups ( Map < Circuit , Collection < TileRef > > circuits , Circuit circuit , MapTile map , TileRef ref ) { final MapTileGroup mapGroup = map . getFeature ( MapTileGroup . class ) ; final MapTileTransition mapTransition = map . getFeature ( MapTileTransition . class ) ; final String group = mapGroup . getGroup ( ref ) ; for ( final String groupTransition : mapGroup . getGroups ( ) ) { if ( mapTransition . getTransitives ( group , groupTransition ) . size ( ) == 1 ) { final Circuit transitiveCircuit = new Circuit ( circuit . getType ( ) , group , groupTransition ) ; getTiles ( circuits , transitiveCircuit ) . add ( ref ) ; } } }
Check transitions groups and create compatible circuit on the fly .
3,207
private static Collection < TileRef > getTiles ( Map < Circuit , Collection < TileRef > > circuits , Circuit circuit ) { if ( ! circuits . containsKey ( circuit ) ) { circuits . put ( circuit , new HashSet < TileRef > ( ) ) ; } return circuits . get ( circuit ) ; }
Get the tiles for the circuit . Create empty list if new circuit .
3,208
private static Playback createPlayback ( Media media , Align alignment , int volume ) throws IOException { final AudioInputStream input = openStream ( media ) ; final SourceDataLine dataLine = getDataLine ( input ) ; dataLine . start ( ) ; updateAlignment ( dataLine , alignment ) ; updateVolume ( dataLine , volume ) ; return new Playback ( input , dataLine ) ; }
Play a sound .
3,209
private static AudioInputStream openStream ( Media media ) throws IOException { try { return AudioSystem . getAudioInputStream ( media . getInputStream ( ) ) ; } catch ( final UnsupportedAudioFileException exception ) { throw new IOException ( ERROR_PLAY_SOUND + media . getPath ( ) , exception ) ; } }
Open the audio stream and prepare it .
3,210
@ SuppressWarnings ( "resource" ) private static SourceDataLine getDataLine ( AudioInputStream input ) throws IOException { final AudioFormat format = input . getFormat ( ) ; try { final SourceDataLine dataLine ; if ( WavFormat . mixer != null ) { dataLine = AudioSystem . getSourceDataLine ( format , WavFormat . mixer ) ; } else { dataLine = AudioSystem . getSourceDataLine ( format ) ; } dataLine . open ( format ) ; return dataLine ; } catch ( final LineUnavailableException exception ) { throw new IOException ( exception ) ; } }
Get the audio data line .
3,211
private static void updateAlignment ( DataLine dataLine , Align alignment ) { if ( dataLine . isControlSupported ( Type . PAN ) ) { final FloatControl pan = ( FloatControl ) dataLine . getControl ( Type . PAN ) ; switch ( alignment ) { case CENTER : pan . setValue ( 0.0F ) ; break ; case RIGHT : pan . setValue ( 1.0F ) ; break ; case LEFT : pan . setValue ( - 1.0F ) ; break ; default : throw new LionEngineException ( alignment ) ; } } }
Update the sound alignment .
3,212
private static void updateVolume ( DataLine dataLine , int volume ) { if ( dataLine . isControlSupported ( Type . MASTER_GAIN ) ) { final FloatControl gainControl = ( FloatControl ) dataLine . getControl ( Type . MASTER_GAIN ) ; final double gain = UtilMath . clamp ( volume / 100.0 , 0.0 , 100.0 ) ; final double dB = Math . log ( gain ) / Math . log ( 10.0 ) * 20.0 ; gainControl . setValue ( ( float ) dB ) ; } }
Update the sound volume .
3,213
private static void readSound ( AudioInputStream input , SourceDataLine dataLine ) throws IOException { int read ; final byte [ ] buffer = new byte [ BUFFER ] ; while ( ( read = input . read ( buffer , 0 , buffer . length ) ) > 0 ) { dataLine . write ( buffer , 0 , read ) ; } }
Read the full sound and play it by buffer .
3,214
private static void close ( AudioInputStream input , DataLine dataLine ) throws IOException { dataLine . drain ( ) ; dataLine . flush ( ) ; dataLine . stop ( ) ; dataLine . close ( ) ; input . close ( ) ; }
Flush and close audio data and stream .
3,215
private void play ( Media media , Align alignment ) { try ( Playback playback = createPlayback ( media , alignment , volume ) ) { if ( opened . containsKey ( media ) ) { opened . get ( media ) . close ( ) ; } opened . put ( media , playback ) ; final AudioInputStream input = openStream ( media ) ; final SourceDataLine dataLine = playback . getDataLine ( ) ; dataLine . start ( ) ; readSound ( input , dataLine ) ; close ( input , dataLine ) ; } catch ( final IOException exception ) { if ( last == null || ! exception . getMessage ( ) . equals ( last . getMessage ( ) ) ) { Verbose . exception ( exception , media . toString ( ) ) ; last = exception ; } } }
Play sound .
3,216
public static ProducibleConfig imports ( Configurer configurer ) { Check . notNull ( configurer ) ; return imports ( configurer . getRoot ( ) ) ; }
Create the producible data from configurer .
3,217
public static ProducibleConfig imports ( Xml root ) { Check . notNull ( root ) ; final Xml node = root . getChild ( NODE_PRODUCIBLE ) ; final SizeConfig size = SizeConfig . imports ( root ) ; final int time = node . readInteger ( ATT_STEPS ) ; return new ProducibleConfig ( time , size . getWidth ( ) , size . getHeight ( ) ) ; }
Create the producible data from node .
3,218
public static Xml exports ( ProducibleConfig config ) { Check . notNull ( config ) ; final Xml node = new Xml ( NODE_PRODUCIBLE ) ; node . writeInteger ( ATT_STEPS , config . getSteps ( ) ) ; return node ; }
Export the producible node from config .
3,219
private void fired ( Direction initial ) { for ( final LauncherListener listener : listenersLauncher ) { listener . notifyFired ( ) ; } for ( final LaunchableConfig launchableConfig : launchables ) { final Media media = Medias . create ( launchableConfig . getMedia ( ) ) ; final Featurable featurable = factory . create ( media ) ; try { final Launchable launchable = featurable . getFeature ( Launchable . class ) ; if ( launchableConfig . getDelay ( ) > 0 ) { delayed . add ( new DelayedLaunch ( launchableConfig , initial , featurable , launchable ) ) ; } else { launch ( launchableConfig , initial , featurable , launchable ) ; } } catch ( final LionEngineException exception ) { featurable . getFeature ( Identifiable . class ) . destroy ( ) ; throw exception ; } } }
Called when fire is performed .
3,220
private void launch ( LaunchableConfig config , Direction initial , Featurable featurable , Launchable launchable ) { final double x = localizable . getX ( ) + config . getOffsetX ( ) + offsetX ; final double y = localizable . getY ( ) + config . getOffsetY ( ) + offsetY ; launchable . setLocation ( x , y ) ; final Force vector = new Force ( config . getVector ( ) ) ; vector . addDirection ( 1.0 , initial ) ; launchable . setVector ( computeVector ( vector ) ) ; launchable . launch ( ) ; for ( final LaunchableListener listener : listenersLaunchable ) { listener . notifyFired ( launchable ) ; } handler . add ( featurable ) ; }
Launch the launchable .
3,221
private Force computeVector ( Force vector ) { if ( target != null ) { return computeVector ( vector , target ) ; } vector . setDestination ( vector . getDirectionHorizontal ( ) , vector . getDirectionVertical ( ) ) ; return vector ; }
Compute the vector used for launch .
3,222
private Force computeVector ( Force vector , Localizable target ) { final double sx = localizable . getX ( ) ; final double sy = localizable . getY ( ) ; double dx = target . getX ( ) ; double dy = target . getY ( ) ; if ( target instanceof Transformable ) { final Transformable transformable = ( Transformable ) target ; final double ray = UtilMath . getDistance ( localizable . getX ( ) , localizable . getY ( ) , target . getX ( ) , target . getY ( ) ) ; dx += ( int ) ( ( target . getX ( ) - transformable . getOldX ( ) ) / vector . getDirectionHorizontal ( ) * ray ) ; dy += ( int ) ( ( target . getY ( ) - transformable . getOldY ( ) ) / vector . getDirectionVertical ( ) * ray ) ; } final double dist = Math . max ( Math . abs ( sx - dx ) , Math . abs ( sy - dy ) ) ; final double vecX = ( dx - sx ) / dist * vector . getDirectionHorizontal ( ) ; final double vecY = ( dy - sy ) / dist * vector . getDirectionVertical ( ) ; final Force force = new Force ( vector ) ; force . setDestination ( vecX , vecY ) ; return force ; }
Compute the force vector depending of the target .
3,223
private int countTiles ( int widthInTile , int step , int s ) { int count = 0 ; for ( int tx = 0 ; tx < widthInTile ; tx ++ ) { for ( int ty = 0 ; ty < map . getInTileHeight ( ) ; ty ++ ) { if ( map . getTile ( tx + s * step , ty ) != null ) { count ++ ; } } } return count ; }
Count the active tiles .
3,224
private void saveTiles ( FileWriting file , int widthInTile , int step , int s ) throws IOException { for ( int tx = 0 ; tx < widthInTile ; tx ++ ) { for ( int ty = 0 ; ty < map . getInTileHeight ( ) ; ty ++ ) { final Tile tile = map . getTile ( tx + s * step , ty ) ; if ( tile != null ) { saveTile ( file , tile ) ; } } } }
Save the active tiles .
3,225
private void appendMap ( MapTile other , int offsetX , int offsetY ) { for ( int v = 0 ; v < other . getInTileHeight ( ) ; v ++ ) { final int ty = offsetY + v ; for ( int h = 0 ; h < other . getInTileWidth ( ) ; h ++ ) { final int tx = offsetX + h ; final Tile tile = other . getTile ( h , v ) ; if ( tile != null ) { final double x = tx * ( double ) map . getTileWidth ( ) ; final double y = ty * ( double ) map . getTileHeight ( ) ; map . setTile ( map . createTile ( tile . getSheet ( ) , tile . getNumber ( ) , x , y ) ) ; } } } }
Append the map at specified offset .
3,226
public static boolean checkSha ( String value , String signature ) { Check . notNull ( signature ) ; return Arrays . equals ( getSha ( value ) . getBytes ( StandardCharsets . UTF_8 ) , signature . getBytes ( StandardCharsets . UTF_8 ) ) ; }
Compare a checksum with its supposed original value .
3,227
public static String getSha ( byte [ ] bytes ) { Check . notNull ( bytes ) ; final StringBuilder builder = new StringBuilder ( MAX_LENGTH ) ; for ( final byte b : SHA512 . digest ( bytes ) ) { builder . append ( 0xFF & b ) ; } return builder . toString ( ) ; }
Get the SHA - 256 signature of the input bytes .
3,228
public static String getSha ( String str ) { Check . notNull ( str ) ; return getSha ( str . getBytes ( StandardCharsets . UTF_8 ) ) ; }
Get the SHA - 256 signature of the input string .
3,229
private static MessageDigest create ( String algorithm ) { try { return MessageDigest . getInstance ( algorithm ) ; } catch ( final NoSuchAlgorithmException exception ) { throw new LionEngineException ( exception , ERROR_ALGORITHM + algorithm ) ; } }
Create digest .
3,230
public static Collection < CollisionCategory > imports ( Configurer configurer , MapTileCollision map ) { Check . notNull ( configurer ) ; Check . notNull ( map ) ; final Collection < Xml > children = configurer . getRoot ( ) . getChildren ( NODE_CATEGORY ) ; final Collection < CollisionCategory > categories = new ArrayList < > ( children . size ( ) ) ; for ( final Xml node : children ) { final CollisionCategory category = imports ( node , map ) ; categories . add ( category ) ; } return categories ; }
Create the categories data from nodes .
3,231
public static CollisionCategory imports ( Xml root , MapTileCollision map ) { Check . notNull ( root ) ; Check . notNull ( map ) ; final Collection < Xml > children = root . getChildren ( TileGroupsConfig . NODE_GROUP ) ; final Collection < CollisionGroup > groups = new ArrayList < > ( children . size ( ) ) ; for ( final Xml groupNode : children ) { final String groupName = groupNode . getText ( ) ; final CollisionGroup group = map . getCollisionGroup ( groupName ) ; groups . add ( group ) ; } final String axisName = root . readString ( ATT_AXIS ) ; final Axis axis ; try { axis = Axis . valueOf ( axisName ) ; } catch ( final IllegalArgumentException exception ) { throw new LionEngineException ( exception , ERROR_AXIS + axisName ) ; } final int x = root . readInteger ( ATT_X ) ; final int y = root . readInteger ( ATT_Y ) ; final boolean glue = root . readBoolean ( true , ATT_GLUE ) ; final String name = root . readString ( ATT_NAME ) ; return new CollisionCategory ( name , axis , x , y , glue , groups ) ; }
Create the category data from node .
3,232
public static void exports ( Xml root , CollisionCategory category ) { Check . notNull ( root ) ; Check . notNull ( category ) ; final Xml node = root . createChild ( NODE_CATEGORY ) ; node . writeString ( ATT_NAME , category . getName ( ) ) ; node . writeString ( ATT_AXIS , category . getAxis ( ) . name ( ) ) ; node . writeInteger ( ATT_X , category . getOffsetX ( ) ) ; node . writeInteger ( ATT_Y , category . getOffsetY ( ) ) ; node . writeBoolean ( ATT_GLUE , category . isGlue ( ) ) ; for ( final CollisionGroup group : category . getGroups ( ) ) { final Xml groupNode = node . createChild ( TileGroupsConfig . NODE_GROUP ) ; groupNode . setText ( group . getName ( ) ) ; } }
Export the collision category data as a node .
3,233
public void render ( Graphic g , Viewer viewer , Origin origin , Shape transformable , List < Collision > cacheColls , Map < Collision , Rectangle > cacheRect ) { if ( showCollision ) { final int size = cacheColls . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { final Collision collision = cacheColls . get ( i ) ; if ( Collision . AUTOMATIC == collision ) { final int x = ( int ) Math . round ( origin . getX ( viewer . getViewpointX ( transformable . getX ( ) ) , transformable . getWidth ( ) ) ) ; final int y = ( int ) Math . floor ( origin . getY ( viewer . getViewpointY ( transformable . getY ( ) ) , transformable . getHeight ( ) ) ) ; g . drawRect ( x , y , transformable . getWidth ( ) , transformable . getHeight ( ) , false ) ; } else { final Area area = cacheRect . get ( collision ) ; final int x = ( int ) Math . round ( viewer . getViewpointX ( area . getX ( ) ) ) ; final int y = ( int ) Math . floor ( viewer . getViewpointY ( area . getY ( ) ) ) - area . getHeight ( ) ; g . drawRect ( x , y , area . getWidth ( ) , area . getHeight ( ) , false ) ; } } } }
Render collisions .
3,234
public static RasterData load ( Xml root , String color ) { final Xml node = root . getChild ( color ) ; final double force = node . readDouble ( ATT_FORCE ) ; final int amplitude = node . readInteger ( ATT_AMPLITUDE ) ; final int offset = node . readInteger ( ATT_OFFSET ) ; final int type = node . readInteger ( ATT_TYPE ) ; return new RasterData ( force , amplitude , offset , type ) ; }
Load raster data from node .
3,235
private void initWindowed ( Resolution output ) { final Canvas canvas = new Canvas ( conf ) ; canvas . setBackground ( Color . BLACK ) ; canvas . setEnabled ( true ) ; canvas . setVisible ( true ) ; canvas . setIgnoreRepaint ( true ) ; frame . add ( canvas ) ; canvas . setPreferredSize ( new Dimension ( output . getWidth ( ) , output . getHeight ( ) ) ) ; frame . pack ( ) ; frame . setLocationRelativeTo ( null ) ; ToolsAwt . createBufferStrategy ( canvas , conf ) ; buf = canvas . getBufferStrategy ( ) ; componentForKeyboard = canvas ; componentForMouse = canvas ; componentForCursor = frame ; frame . validate ( ) ; }
Prepare windowed mode .
3,236
public final void setScreenSize ( int screenWidth , int screenHeight ) { this . screenWidth = screenWidth ; this . screenHeight = screenHeight ; final int w = ( int ) Math . ceil ( screenWidth / ( surface . getWidth ( ) * 0.6 * factH ) ) + 1 ; amplitude = ( int ) Math . ceil ( w / 2.0 ) + 1 ; }
Set the screen size . Used to know the parallax amplitude and the overall surface to render in order to fill the screen .
3,237
private void renderLine ( Graphic g , int numLine , int lineY ) { final int lineWidth = surface . getLineWidth ( numLine ) ; for ( int j = - amplitude ; j < amplitude ; j ++ ) { final int lx = ( int ) ( - offsetX + offsetX * j - x [ numLine ] - x2 [ numLine ] + numLine * ( 2.56 * factH ) * j ) ; if ( lx + lineWidth + decX >= 0 && lx <= screenWidth ) { surface . render ( g , numLine , lx + decX , lineY ) ; } } }
Render parallax line .
3,238
public void setMin ( int min ) { this . min = UtilMath . clamp ( min , 0 , Integer . MAX_VALUE ) ; max = UtilMath . clamp ( max , this . min , Integer . MAX_VALUE ) ; }
Set the minimum damage value . Max set to min value if over .
3,239
public void setDamages ( int min , int max ) { this . min = UtilMath . clamp ( min , 0 , Integer . MAX_VALUE ) ; this . max = UtilMath . clamp ( max , this . min , Integer . MAX_VALUE ) ; }
Set the maximum damage value . Max set to min value if over .
3,240
public static Document createDocument ( InputStream input ) throws IOException { Check . notNull ( input ) ; try { return getDocumentFactory ( ) . parse ( input ) ; } catch ( final SAXException exception ) { throw new IOException ( exception ) ; } }
Create a document from an input stream .
3,241
private static synchronized DocumentBuilder getDocumentFactory ( ) { if ( documentBuilder == null ) { final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory . newInstance ( ) ; documentBuilderFactory . setIgnoringElementContentWhitespace ( true ) ; try { documentBuilderFactory . setFeature ( javax . xml . XMLConstants . FEATURE_SECURE_PROCESSING , true ) ; } catch ( final ParserConfigurationException exception ) { Verbose . exception ( exception ) ; } try { documentBuilder = documentBuilderFactory . newDocumentBuilder ( ) ; documentBuilder . setErrorHandler ( null ) ; } catch ( final ParserConfigurationException exception ) { throw new LionEngineException ( exception ) ; } } return documentBuilder ; }
Get the document factory .
3,242
private static synchronized TransformerFactory getTransformerFactory ( ) { if ( transformerFactory == null ) { transformerFactory = TransformerFactory . newInstance ( ) ; transformerFactory . setAttribute ( javax . xml . XMLConstants . ACCESS_EXTERNAL_DTD , "" ) ; transformerFactory . setAttribute ( javax . xml . XMLConstants . ACCESS_EXTERNAL_STYLESHEET , "" ) ; } return transformerFactory ; }
Get the transformer factory .
3,243
public static byte [ ] intToByteArray ( int value ) { return new byte [ ] { ( byte ) ( value >>> Constant . BYTE_4 ) , ( byte ) ( value >>> Constant . BYTE_3 ) , ( byte ) ( value >>> Constant . BYTE_2 ) , ( byte ) value } ; }
Convert an integer to an array of byte .
3,244
public static boolean [ ] toBinary ( int number , int length ) { final boolean [ ] binary = new boolean [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { binary [ length - 1 - i ] = ( 1 << i & number ) != 0 ; } return binary ; }
Convert number to binary array representation .
3,245
public static int fromBinary ( boolean [ ] binary ) { Check . notNull ( binary ) ; int number = 0 ; for ( final boolean current : binary ) { number = number << 1 | boolToInt ( current ) ; } return number ; }
Convert binary array to number representation .
3,246
public static String toTitleCase ( String string ) { Check . notNull ( string ) ; final int length = string . length ( ) ; final StringBuilder result = new StringBuilder ( length ) ; for ( int i = 0 ; i < length ; i ++ ) { final String next = string . substring ( i , i + 1 ) ; if ( i == 0 ) { result . append ( next . toUpperCase ( Locale . ENGLISH ) ) ; } else { result . append ( next . toLowerCase ( Locale . ENGLISH ) ) ; } } return result . toString ( ) ; }
Convert a string to title case .
3,247
public static String toTitleCaseWord ( String string ) { Check . notNull ( string ) ; final String [ ] words = SPACE . split ( REPLACER . matcher ( string ) . replaceAll ( Constant . SPACE ) ) ; final StringBuilder title = new StringBuilder ( string . length ( ) ) ; for ( int i = 0 ; i < words . length ; i ++ ) { title . append ( toTitleCase ( words [ i ] ) ) ; if ( i < words . length - 1 ) { title . append ( Constant . SPACE ) ; } } return title . toString ( ) ; }
Convert a string to a pure title case for each word replacing special characters by space .
3,248
public static Text createText ( String fontName , int size , TextStyle style ) { return factoryGraphic . createText ( fontName , size , style ) ; }
Crate a text .
3,249
public static ImageBuffer createImageBuffer ( int width , int height , ColorRgba transparency ) { return factoryGraphic . createImageBuffer ( width , height , transparency ) ; }
Create an image buffer .
3,250
public static ImageBuffer applyMask ( ImageBuffer imageBuffer , ColorRgba maskColor ) { return factoryGraphic . applyMask ( imageBuffer , maskColor ) ; }
Apply color mask to the image .
3,251
private static int getStyle ( TextStyle style ) { final int value ; if ( TextStyle . NORMAL == style ) { value = Font . TRUETYPE_FONT ; } else if ( TextStyle . BOLD == style ) { value = Font . BOLD ; } else if ( TextStyle . ITALIC == style ) { value = Font . ITALIC ; } else { throw new LionEngineException ( style ) ; } return value ; }
Get the style equivalence .
3,252
public void set ( double x1 , double y1 , double x2 , double y2 ) { this . x1 = x1 ; this . y1 = y1 ; this . x2 = x2 ; this . y2 = y2 ; }
Set the line coordinates .
3,253
public static Force imports ( Configurer configurer ) { Check . notNull ( configurer ) ; return imports ( configurer . getRoot ( ) ) ; }
Create the force data from setup .
3,254
public static Force imports ( Xml root ) { Check . notNull ( root ) ; final Xml node = root . getChild ( NODE_FORCE ) ; final Force force = new Force ( node . readDouble ( ATT_VX ) , node . readDouble ( ATT_VY ) ) ; force . setVelocity ( node . readDouble ( 0.0 , ATT_VELOCITY ) ) ; force . setSensibility ( node . readDouble ( 0.0 , ATT_SENSIBILITY ) ) ; return force ; }
Create the force data from node .
3,255
public static Xml exports ( Force force ) { Check . notNull ( force ) ; final Xml node = new Xml ( NODE_FORCE ) ; node . writeDouble ( ATT_VX , force . getDirectionHorizontal ( ) ) ; node . writeDouble ( ATT_VY , force . getDirectionVertical ( ) ) ; node . writeDouble ( ATT_VELOCITY , force . getVelocity ( ) ) ; node . writeDouble ( ATT_SENSIBILITY , force . getSensibility ( ) ) ; return node ; }
Export the force node from data .
3,256
public static Collection < SpriteTiled > extract ( Collection < ImageBuffer > tiles , int horizontalTiles ) { final Surface surface = getSheetSize ( tiles , horizontalTiles ) ; final int horizontals = surface . getWidth ( ) ; final int verticals = surface . getHeight ( ) ; final int tilesPerSheet = Math . min ( tiles . size ( ) , horizontals * verticals ) ; final Collection < SpriteTiled > sheets = new ArrayList < > ( ) ; ImageBuffer sheet = null ; Graphic g = null ; int number = 0 ; int tw = 0 ; int th = 0 ; for ( final ImageBuffer tile : tiles ) { if ( g == null ) { tw = tile . getWidth ( ) ; th = tile . getHeight ( ) ; final int width = Math . max ( tw , horizontals * tw ) ; final int height = Math . max ( th , verticals * th ) ; sheet = Graphics . createImageBuffer ( width , height , tile . getTransparentColor ( ) ) ; g = sheet . createGraphic ( ) ; } final int x = number % horizontals ; final int y = ( int ) Math . floor ( number / ( double ) horizontals ) ; g . drawImage ( tile , x * tw , y * th ) ; number ++ ; if ( number >= tilesPerSheet ) { g . dispose ( ) ; sheets . add ( Drawable . loadSpriteTiled ( Graphics . getImageBuffer ( sheet ) , tw , th ) ) ; sheet = null ; g = null ; number = 0 ; } } return sheets ; }
Convert a set of tile to a set of tile sheets .
3,257
private static Surface getSheetSize ( Collection < ImageBuffer > tiles , int horizontalTiles ) { final int tilesNumber = tiles . size ( ) ; final int horizontals ; final int verticals ; if ( horizontalTiles > 0 ) { horizontals = horizontalTiles ; verticals = ( int ) Math . ceil ( tilesNumber / ( double ) horizontalTiles ) ; } else { horizontals = ( int ) Math . ceil ( Math . sqrt ( tilesNumber ) ) ; verticals = horizontals ; } return new Surface ( ) { public int getWidth ( ) { return Math . max ( 1 , horizontals ) ; } public int getHeight ( ) { return Math . max ( 1 , verticals ) ; } } ; }
Get the sheet size depending of the number of horizontal tiles and total number of tiles .
3,258
public boolean isVisible ( Tiled tiled ) { final int tx = tiled . getInTileX ( ) ; final int ty = tiled . getInTileY ( ) ; final int tw = tiled . getInTileWidth ( ) - 1 ; final int th = tiled . getInTileHeight ( ) - 1 ; for ( int ctx = tx ; ctx <= tx + tw ; ctx ++ ) { for ( int cty = ty ; cty <= ty + th ; cty ++ ) { if ( isFogged ( ctx , cty ) || ! isVisited ( ctx , cty ) ) { return false ; } } } return true ; }
Check if the tile is currently visible .
3,259
public boolean isVisited ( int tx , int ty ) { return mapHidden . getTile ( tx , ty ) . getNumber ( ) == MapTileFog . NO_FOG ; }
In case of active fog of war check if tile has been discovered .
3,260
public boolean isFogged ( int tx , int ty ) { return mapFogged . getTile ( tx , ty ) . getNumber ( ) < MapTileFog . FOG ; }
In case of active fog of war check if tile is hidden by fog .
3,261
public void resetInterval ( Localizable localizable ) { final int intervalHorizontalOld = intervalHorizontal ; final int intervalVerticalOld = intervalVertical ; final double oldX = getX ( ) ; final double oldY = getY ( ) ; setIntervals ( 0 , 0 ) ; offset . setLocation ( 0.0 , 0.0 ) ; setLocation ( localizable . getX ( ) , localizable . getY ( ) ) ; final double newX = getX ( ) ; final double newY = getY ( ) ; moveLocation ( 1.0 , oldX - newX , oldY - newY ) ; moveLocation ( 1.0 , newX - oldX , newY - oldY ) ; setIntervals ( intervalHorizontalOld , intervalVerticalOld ) ; offset . setLocation ( 0.0 , 0.0 ) ; }
Reset the camera interval to 0 by adapting its position . This will ensure camera centers its view to the localizable .
3,262
public void moveLocation ( double extrp , double vx , double vy ) { checkHorizontalLimit ( extrp , vx ) ; checkVerticalLimit ( extrp , vy ) ; }
Move camera by using specified vector .
3,263
public void setLocation ( double x , double y ) { final double dx = x - ( mover . getX ( ) + offset . getX ( ) ) ; final double dy = y - ( mover . getY ( ) + offset . getY ( ) ) ; moveLocation ( 1 , dx , dy ) ; }
Set the camera location .
3,264
public void drawFov ( Graphic g , int x , int y , int gridH , int gridV , Surface surface ) { final int h = x + ( int ) Math . floor ( ( getX ( ) + getViewX ( ) ) / gridH ) ; final int v = y + ( int ) - Math . floor ( ( getY ( ) + getHeight ( ) ) / gridV ) ; final int tileWidth = getWidth ( ) / gridH ; final int tileHeight = getHeight ( ) / gridV ; g . drawRect ( h , v + surface . getHeight ( ) , tileWidth , tileHeight , false ) ; }
Draw the camera field of view according to a grid .
3,265
private void setLimits ( Surface surface , int gridH , int gridV ) { Check . notNull ( surface ) ; if ( gridH == 0 ) { limitRight = 0 ; } else { limitRight = Math . max ( 0 , surface . getWidth ( ) - UtilMath . getRounded ( width , gridH ) ) ; } if ( gridV == 0 ) { limitTop = 0 ; } else { limitTop = Math . max ( 0 , surface . getHeight ( ) - UtilMath . getRounded ( height , gridV ) ) ; } limitLeft = 0 ; limitBottom = 0 ; moveLocation ( 1.0 , 0.0 , 0.0 ) ; }
Define the maximum view limit .
3,266
private void checkHorizontalLimit ( double extrp , double vx ) { if ( mover . getX ( ) >= limitLeft && mover . getX ( ) <= limitRight && limitLeft != Integer . MIN_VALUE && limitRight != Integer . MAX_VALUE ) { offset . moveLocation ( extrp , vx , 0 ) ; if ( offset . getX ( ) < - intervalHorizontal ) { offset . teleportX ( - intervalHorizontal ) ; } else if ( offset . getX ( ) > intervalHorizontal ) { offset . teleportX ( intervalHorizontal ) ; } } if ( ( int ) offset . getX ( ) == - intervalHorizontal || ( int ) offset . getX ( ) == intervalHorizontal ) { mover . moveLocationX ( extrp , vx ) ; } applyHorizontalLimit ( ) ; }
Check horizontal limit on move .
3,267
private void checkVerticalLimit ( double extrp , double vy ) { if ( mover . getY ( ) >= limitBottom && mover . getY ( ) <= limitTop && limitBottom != Integer . MIN_VALUE && limitTop != Integer . MAX_VALUE ) { offset . moveLocation ( extrp , 0 , vy ) ; if ( offset . getY ( ) < - intervalVertical ) { offset . teleportY ( - intervalVertical ) ; } else if ( offset . getY ( ) > intervalVertical ) { offset . teleportY ( intervalVertical ) ; } } if ( ( int ) offset . getY ( ) == - intervalVertical || ( int ) offset . getY ( ) == intervalVertical ) { mover . moveLocationY ( extrp , vy ) ; } applyVerticalLimit ( ) ; }
Check vertical limit on move .
3,268
private void applyHorizontalLimit ( ) { if ( mover . getX ( ) < limitLeft && limitLeft != Integer . MIN_VALUE ) { mover . teleportX ( limitLeft ) ; } else if ( mover . getX ( ) > limitRight && limitRight != Integer . MAX_VALUE ) { mover . teleportX ( limitRight ) ; } }
Fix location inside horizontal limit .
3,269
private void applyVerticalLimit ( ) { if ( mover . getY ( ) < limitBottom && limitBottom != Integer . MIN_VALUE ) { mover . teleportY ( limitBottom ) ; } else if ( mover . getY ( ) > limitTop && limitTop != Integer . MAX_VALUE ) { mover . teleportY ( limitTop ) ; } }
Fix location inside vertical limit .
3,270
public void add ( Orientation orientation , String group ) { final Collection < String > groups = constraints . get ( orientation ) ; groups . add ( group ) ; }
Add the group constraint at the specified orientation .
3,271
public static Collection < TileGroup > imports ( Media groupsConfig ) { Check . notNull ( groupsConfig ) ; final Xml nodeGroups = new Xml ( groupsConfig ) ; final Collection < Xml > children = nodeGroups . getChildren ( NODE_GROUP ) ; final Collection < TileGroup > groups = new ArrayList < > ( children . size ( ) ) ; for ( final Xml nodeGroup : children ) { final TileGroup group = importGroup ( nodeGroup ) ; groups . add ( group ) ; } return groups ; }
Import the group data from configuration .
3,272
public static void exports ( Media groupsConfig , Iterable < TileGroup > groups ) { Check . notNull ( groupsConfig ) ; Check . notNull ( groups ) ; final Xml nodeGroups = new Xml ( NODE_GROUPS ) ; nodeGroups . writeString ( Constant . XML_HEADER , Constant . ENGINE_WEBSITE ) ; for ( final TileGroup group : groups ) { exportGroup ( nodeGroups , group ) ; } nodeGroups . save ( groupsConfig ) ; }
Export groups to configuration file .
3,273
private static TileGroup importGroup ( Xml nodeGroup ) { final Collection < Xml > children = nodeGroup . getChildren ( TileConfig . NODE_TILE ) ; final Collection < TileRef > tiles = new ArrayList < > ( children . size ( ) ) ; for ( final Xml nodeTileRef : children ) { final TileRef tileRef = TileConfig . imports ( nodeTileRef ) ; tiles . add ( tileRef ) ; } final String groupName = nodeGroup . readString ( ATT_GROUP_NAME ) ; final TileGroupType groupType = TileGroupType . from ( nodeGroup . readString ( TileGroupType . NONE . name ( ) , ATT_GROUP_TYPE ) ) ; return new TileGroup ( groupName , groupType , tiles ) ; }
Import the group from its node .
3,274
private static void exportGroup ( Xml nodeGroups , TileGroup group ) { final Xml nodeGroup = nodeGroups . createChild ( NODE_GROUP ) ; nodeGroup . writeString ( ATT_GROUP_NAME , group . getName ( ) ) ; nodeGroup . writeString ( ATT_GROUP_TYPE , group . getType ( ) . name ( ) ) ; for ( final TileRef tileRef : group . getTiles ( ) ) { final Xml nodeTileRef = TileConfig . exports ( tileRef ) ; nodeGroup . add ( nodeTileRef ) ; } }
Export the group data as a node .
3,275
public final void setScreenWidth ( int screenWidth ) { final int wi = ( int ) Math . ceil ( screenWidth / ( double ) sprite . getWidth ( ) ) + 1 ; w = wi ; }
Set the screen width . Used to know how much clouds are needed in order to fill the screen .
3,276
private void kick ( ) { if ( ! connected ) { return ; } messagesIn . clear ( ) ; messagesOut . clear ( ) ; try { out . close ( ) ; } catch ( final IOException exception ) { Verbose . exception ( exception , "Error on closing output" ) ; } try { in . close ( ) ; } catch ( final IOException exception ) { Verbose . exception ( exception , "Error on closing input" ) ; } try { socket . close ( ) ; } catch ( final IOException exception ) { Verbose . exception ( exception , "Error on closing socket" ) ; } for ( final ConnectionListener listener : listeners ) { listener . notifyConnectionTerminated ( Byte . valueOf ( getId ( ) ) ) ; } listeners . clear ( ) ; connected = false ; Verbose . info ( "Disconnected from the server !" ) ; }
Terminate connection .
3,277
private String readString ( ) throws IOException { final int size = in . readByte ( ) ; if ( size > 0 ) { final byte [ ] name = new byte [ size ] ; if ( in . read ( name ) != - 1 ) { return new String ( name , NetworkMessage . CHARSET ) ; } } return null ; }
Get the name value read from the stream .
3,278
private void updateMessage ( byte messageSystemId ) throws IOException { switch ( messageSystemId ) { case NetworkMessageSystemId . CONNECTING : updateConnecting ( ) ; break ; case NetworkMessageSystemId . CONNECTED : updateConnected ( ) ; break ; case NetworkMessageSystemId . PING : ping = ( int ) pingTimer . elapsed ( ) ; break ; case NetworkMessageSystemId . KICKED : kick ( ) ; break ; case NetworkMessageSystemId . OTHER_CLIENT_CONNECTED : updateOtherClientConnected ( ) ; break ; case NetworkMessageSystemId . OTHER_CLIENT_DISCONNECTED : updateOtherClientDisconnected ( ) ; break ; case NetworkMessageSystemId . OTHER_CLIENT_RENAMED : updateOtherClientRenamed ( ) ; break ; case NetworkMessageSystemId . USER_MESSAGE : updateUserMessage ( ) ; break ; default : break ; } }
Update the message from its id .
3,279
private void updateConnecting ( ) throws IOException { if ( clientId == - 1 ) { clientId = in . readByte ( ) ; out . writeByte ( NetworkMessageSystemId . CONNECTING ) ; out . writeByte ( clientId ) ; final byte [ ] data = clientName . getBytes ( NetworkMessage . CHARSET ) ; out . writeByte ( data . length ) ; out . write ( data ) ; out . flush ( ) ; Verbose . info ( "Client: Performing connection to the server..." ) ; } }
Update the connecting case .
3,280
private void updateConnected ( ) throws IOException { byte cid = in . readByte ( ) ; if ( cid != clientId ) { return ; } for ( final ConnectionListener listener : listeners ) { listener . notifyConnectionEstablished ( Byte . valueOf ( clientId ) , clientName ) ; } final int clientsNumber = in . readByte ( ) ; for ( int i = 0 ; i < clientsNumber ; i ++ ) { cid = in . readByte ( ) ; final String cname = readString ( ) ; for ( final ConnectionListener listener : listeners ) { listener . notifyClientConnected ( Byte . valueOf ( cid ) , cname ) ; } } if ( in . available ( ) > 0 ) { final String motd = readString ( ) ; for ( final ConnectionListener listener : listeners ) { listener . notifyMessageOfTheDay ( motd ) ; } } out . write ( NetworkMessageSystemId . CONNECTED ) ; out . write ( clientId ) ; out . flush ( ) ; Verbose . info ( "Client: Connected to the server !" ) ; }
Update the connected case .
3,281
private void updateOtherClientConnected ( ) throws IOException { final byte cid = in . readByte ( ) ; final String cname = readString ( ) ; for ( final ConnectionListener listener : listeners ) { listener . notifyClientConnected ( Byte . valueOf ( cid ) , cname ) ; } }
Update the other client connected case .
3,282
private void updateOtherClientDisconnected ( ) throws IOException { final byte cid = in . readByte ( ) ; final String cname = readString ( ) ; for ( final ConnectionListener listener : listeners ) { listener . notifyClientDisconnected ( Byte . valueOf ( cid ) , cname ) ; } }
Update the other client disconnected case .
3,283
private void sendMessage ( NetworkMessage message ) { try ( ByteArrayOutputStream encode = message . encode ( ) ) { final byte [ ] encoded = encode . toByteArray ( ) ; out . writeByte ( NetworkMessageSystemId . USER_MESSAGE ) ; out . writeByte ( message . getClientId ( ) ) ; out . writeByte ( message . getClientDestId ( ) ) ; out . writeByte ( message . getType ( ) ) ; out . writeInt ( encoded . length ) ; out . write ( encoded ) ; out . flush ( ) ; final int headerSize = 8 ; bandwidth += headerSize + encoded . length ; } catch ( final IOException exception ) { Verbose . exception ( exception , "Unable to send the message for client: " , String . valueOf ( clientId ) ) ; } }
Send message over the network .
3,284
public static List < File > getDirectories ( File path ) { Check . notNull ( path ) ; return Optional . ofNullable ( path . listFiles ( ) ) . map ( files -> Arrays . asList ( files ) . stream ( ) . filter ( File :: isDirectory ) . collect ( Collectors . toList ( ) ) ) . orElseGet ( Collections :: emptyList ) ; }
Get all directories existing in the path .
3,285
public static String getPathSeparator ( String separator , String ... path ) { Check . notNull ( separator ) ; Check . notNull ( path ) ; final StringBuilder fullPath = new StringBuilder ( path . length ) ; for ( int i = 0 ; i < path . length ; i ++ ) { if ( i == path . length - 1 ) { fullPath . append ( path [ i ] ) ; } else if ( path [ i ] != null && path [ i ] . length ( ) > 0 ) { fullPath . append ( path [ i ] ) ; if ( ! fullPath . substring ( fullPath . length ( ) - 1 , fullPath . length ( ) ) . equals ( separator ) ) { fullPath . append ( separator ) ; } } } return fullPath . toString ( ) ; }
Construct a usable path using a list of string automatically separated by the portable separator .
3,286
public static CollisionConstraint imports ( Xml node ) { Check . notNull ( node ) ; final CollisionConstraint constraint = new CollisionConstraint ( ) ; if ( node . hasChild ( NODE_CONSTRAINT ) ) { for ( final Xml current : node . getChildren ( NODE_CONSTRAINT ) ) { final Orientation orientation = Orientation . valueOf ( current . readString ( ATT_ORIENTATION ) ) ; final String group = current . readString ( ATT_GROUP ) ; constraint . add ( orientation , group ) ; } } return constraint ; }
Create the collision constraint data from node .
3,287
public static void exports ( Xml root , CollisionConstraint constraint ) { Check . notNull ( root ) ; Check . notNull ( constraint ) ; for ( final Entry < Orientation , Collection < String > > entry : constraint . getConstraints ( ) . entrySet ( ) ) { final Orientation orientation = entry . getKey ( ) ; for ( final String group : entry . getValue ( ) ) { final Xml current = root . createChild ( NODE_CONSTRAINT ) ; current . writeString ( ATT_ORIENTATION , orientation . name ( ) ) ; current . writeString ( ATT_GROUP , group ) ; } } }
Export the collision constraint as a node .
3,288
private void remove ( Integer layer , Refreshable refreshable ) { final Collection < Refreshable > refreshables = getLayer ( layer ) ; refreshables . remove ( refreshable ) ; if ( refreshables . isEmpty ( ) ) { indexs . remove ( layer ) ; } }
Remove refreshable and its layer .
3,289
public static CollisionFormulaConfig imports ( Media config ) { final Xml root = new Xml ( config ) ; final Map < String , CollisionFormula > collisions = new HashMap < > ( 0 ) ; for ( final Xml node : root . getChildren ( NODE_FORMULA ) ) { final String name = node . readString ( ATT_NAME ) ; final CollisionFormula collision = createCollision ( node ) ; collisions . put ( name , collision ) ; } return new CollisionFormulaConfig ( collisions ) ; }
Create the formula data from node .
3,290
public static void exports ( Xml root , CollisionFormula formula ) { Check . notNull ( root ) ; Check . notNull ( formula ) ; final Xml node = root . createChild ( NODE_FORMULA ) ; node . writeString ( ATT_NAME , formula . getName ( ) ) ; CollisionRangeConfig . exports ( node , formula . getRange ( ) ) ; CollisionFunctionConfig . exports ( node , formula . getFunction ( ) ) ; CollisionConstraintConfig . exports ( node , formula . getConstraint ( ) ) ; }
Export the current formula data to the formula node .
3,291
public static CollisionFormula createCollision ( Xml node ) { Check . notNull ( node ) ; final String name = node . readString ( ATT_NAME ) ; final CollisionRange range = CollisionRangeConfig . imports ( node . getChild ( CollisionRangeConfig . NODE_RANGE ) ) ; final CollisionFunction function = CollisionFunctionConfig . imports ( node ) ; final CollisionConstraint constraint = CollisionConstraintConfig . imports ( node ) ; return new CollisionFormula ( name , range , function , constraint ) ; }
Create a collision formula from its node .
3,292
public static void remove ( Xml root , String formula ) { Check . notNull ( root ) ; Check . notNull ( formula ) ; for ( final Xml node : root . getChildren ( NODE_FORMULA ) ) { if ( node . readString ( ATT_NAME ) . equals ( formula ) ) { root . removeChild ( node ) ; } } }
Remove the formula node .
3,293
public static boolean has ( Xml root , String formula ) { Check . notNull ( root ) ; Check . notNull ( formula ) ; for ( final Xml node : root . getChildren ( NODE_FORMULA ) ) { if ( node . readString ( ATT_NAME ) . equals ( formula ) ) { return true ; } } return false ; }
Check if node has formula node .
3,294
public double getInputValue ( Axis input , double x , double y ) { final double v ; switch ( input ) { case X : v = Math . floor ( x - tile . getX ( ) ) ; break ; case Y : v = Math . floor ( y - tile . getY ( ) ) ; break ; default : throw new LionEngineException ( input ) ; } return v ; }
Get the input value relative to tile .
3,295
private Double getCollisionX ( CollisionRange range , CollisionFunction function , double x , double y , int offsetX ) { final double yOnTile = getInputValue ( Axis . Y , x , y ) ; if ( UtilMath . isBetween ( yOnTile , range . getMinY ( ) , range . getMaxY ( ) ) ) { final double xOnTile = getInputValue ( Axis . X , x , y ) ; final double result = Math . floor ( function . compute ( yOnTile ) ) ; if ( UtilMath . isBetween ( xOnTile , result + range . getMinX ( ) - 1 , result + range . getMaxX ( ) ) ) { final double coll = Math . floor ( tile . getX ( ) + result - offsetX ) ; return Double . valueOf ( coll ) ; } } return null ; }
Get the horizontal collision location between the tile and the current location .
3,296
int [ ] getScaledData ( int [ ] srcImage ) { final int [ ] dstImage = new int [ srcImage . length * SCALE * SCALE ] ; for ( int y = 0 ; y < height ; y ++ ) { for ( int x = 0 ; x < width ; x ++ ) { process ( srcImage , dstImage , x , y ) ; } } return dstImage ; }
Get the scaled data .
3,297
private void setDestPixel ( int [ ] dstImage , int x , int y , int p ) { dstImage [ x + y * width * SCALE ] = p ; }
Set destination pixel .
3,298
private int getSourcePixel ( int [ ] srcImage , int x , int y ) { int x1 = Math . max ( 0 , x ) ; x1 = Math . min ( width - 1 , x1 ) ; int y1 = Math . max ( 0 , y ) ; y1 = Math . min ( height - 1 , y1 ) ; return srcImage [ x1 + y1 * width ] ; }
Get pixel source .
3,299
private void process ( int [ ] srcImage , int [ ] dstImage , int x , int y ) { final int b = getSourcePixel ( srcImage , x , y - 1 ) ; final int d = getSourcePixel ( srcImage , x - 1 , y ) ; final int e = getSourcePixel ( srcImage , x , y ) ; final int f = getSourcePixel ( srcImage , x + 1 , y ) ; final int h = getSourcePixel ( srcImage , x , y + 1 ) ; int e0 = e ; int e1 = e ; int e2 = e ; int e3 = e ; if ( b != h && d != f ) { e0 = d == b ? d : e ; e1 = b == f ? f : e ; e2 = d == h ? d : e ; e3 = h == f ? f : e ; } setDestPixel ( dstImage , x * SCALE , y * SCALE , e0 ) ; setDestPixel ( dstImage , x * SCALE + 1 , y * SCALE , e1 ) ; setDestPixel ( dstImage , x * SCALE , y * SCALE + 1 , e2 ) ; setDestPixel ( dstImage , x * SCALE + 1 , y * SCALE + 1 , e3 ) ; }
Process filter .