idx
int64 0
41.2k
| question
stringlengths 73
5.81k
| target
stringlengths 5
918
|
|---|---|---|
3,300
|
public static Animation createAnimation ( XmlReader node ) { Check . notNull ( node ) ; final String name = node . readString ( ANIMATION_NAME ) ; final int start = node . readInteger ( ANIMATION_START ) ; final int end = node . readInteger ( ANIMATION_END ) ; final double speed = node . readDouble ( ANIMATION_SPEED ) ; final boolean reversed = node . readBoolean ( ANIMATION_REVERSED ) ; final boolean repeat = node . readBoolean ( ANIMATION_REPEAT ) ; return new Animation ( name , start , end , speed , reversed , repeat ) ; }
|
Create animation data from node .
|
3,301
|
public static void exports ( Xml root , Animation animation ) { Check . notNull ( root ) ; Check . notNull ( animation ) ; final Xml node = root . createChild ( ANIMATION ) ; node . writeString ( ANIMATION_NAME , animation . getName ( ) ) ; node . writeInteger ( ANIMATION_START , animation . getFirst ( ) ) ; node . writeInteger ( ANIMATION_END , animation . getLast ( ) ) ; node . writeDouble ( ANIMATION_SPEED , animation . getSpeed ( ) ) ; node . writeBoolean ( ANIMATION_REVERSED , animation . hasReverse ( ) ) ; node . writeBoolean ( ANIMATION_REPEAT , animation . hasRepeat ( ) ) ; }
|
Create an XML node from an animation .
|
3,302
|
public Animation getAnimation ( String name ) { final Animation animation = animations . get ( name ) ; if ( animation == null ) { throw new LionEngineException ( ERROR_NOT_FOUND + name ) ; } return animation ; }
|
Get an animation data from its name .
|
3,303
|
public void update ( Viewer viewer ) { x = ( int ) viewer . getX ( ) ; y = ( int ) viewer . getY ( ) - viewer . getViewY ( ) ; height = viewer . getHeight ( ) ; }
|
Update game text to store current location view .
|
3,304
|
public static final synchronized void terminate ( ) { if ( started ) { engine . close ( ) ; started = false ; Verbose . info ( ENGINE_TERMINATED ) ; engine . postClose ( ) ; engine = null ; } }
|
Terminate the engine . It is necessary to call this function only if the engine need to be started again during the same JVM execution . Does nothing if engine is not started .
|
3,305
|
private static void appendDate ( StringBuilder message ) { final String date = DATE_TIME_FORMAT . format ( Calendar . getInstance ( ) . getTime ( ) ) ; message . append ( date ) ; message . append ( Constant . SPACE ) ; }
|
Append date .
|
3,306
|
private static void appendLevel ( StringBuilder message , LogRecord event ) { final String logLevel = event . getLevel ( ) . getName ( ) ; for ( int i = logLevel . length ( ) ; i < LOG_LEVEL_LENGTH ; i ++ ) { message . append ( Constant . SPACE ) ; } message . append ( logLevel ) . append ( Constant . DOUBLE_DOT ) ; }
|
Append log level .
|
3,307
|
private static void appendFunction ( StringBuilder message , LogRecord event ) { final String clazz = event . getSourceClassName ( ) ; if ( clazz != null ) { message . append ( IN ) . append ( clazz ) ; } final String function = event . getSourceMethodName ( ) ; if ( function != null ) { message . append ( AT ) . append ( function ) . append ( Constant . DOUBLE_DOT ) ; } }
|
Append function location .
|
3,308
|
private static void appendThrown ( StringBuilder message , LogRecord event ) { final Throwable thrown = event . getThrown ( ) ; if ( thrown != null ) { final StringWriter sw = new StringWriter ( ) ; thrown . printStackTrace ( new PrintWriter ( sw ) ) ; message . append ( sw ) ; } }
|
Append thrown exception trace .
|
3,309
|
public static Optional < Coord > intersection ( Line l1 , Line l2 ) { Check . notNull ( l1 ) ; Check . notNull ( l2 ) ; final double x1 = l1 . getX1 ( ) ; final double x2 = l1 . getX2 ( ) ; final double y1 = l1 . getY1 ( ) ; final double y2 = l1 . getY2 ( ) ; final double x3 = l2 . getX1 ( ) ; final double x4 = l2 . getX2 ( ) ; final double y3 = l2 . getY1 ( ) ; final double y4 = l2 . getY2 ( ) ; final double d = ( x1 - x2 ) * ( y3 - y4 ) - ( y1 - y2 ) * ( x3 - x4 ) ; if ( Double . compare ( d , 0 ) == 0 ) { return Optional . empty ( ) ; } final double xi = ( ( x3 - x4 ) * ( x1 * y2 - y1 * x2 ) - ( x1 - x2 ) * ( x3 * y4 - y3 * x4 ) ) / d ; final double yi = ( ( y3 - y4 ) * ( x1 * y2 - y1 * x2 ) - ( y1 - y2 ) * ( x3 * y4 - y3 * x4 ) ) / d ; return Optional . of ( new Coord ( xi , yi ) ) ; }
|
Get the intersection point of two lines .
|
3,310
|
public static Area createArea ( double x , double y , double width , double height ) { return new AreaImpl ( x , y , width , height ) ; }
|
Create an area .
|
3,311
|
public static boolean same ( Localizable a , Localizable b ) { return Double . compare ( a . getX ( ) , b . getX ( ) ) == 0 && Double . compare ( a . getY ( ) , b . getY ( ) ) == 0 ; }
|
Check if two localizable are at the same location .
|
3,312
|
private static List < Field > getServiceFields ( Object object ) { final List < Field > toInject = new ArrayList < > ( ) ; Class < ? > clazz = object . getClass ( ) ; while ( clazz != null ) { final Field [ ] fields = clazz . getDeclaredFields ( ) ; final int length = fields . length ; for ( int i = 0 ; i < length ; i ++ ) { final Field field = fields [ i ] ; if ( field . isAnnotationPresent ( FeatureGet . class ) ) { toInject . add ( field ) ; } } clazz = clazz . getSuperclass ( ) ; } return toInject ; }
|
Get all with that require an injected service .
|
3,313
|
private void fillServices ( Object object ) { final List < Field > fields = getServiceFields ( object ) ; final int length = fields . size ( ) ; for ( int i = 0 ; i < length ; i ++ ) { final Field field = fields . get ( i ) ; UtilReflection . setAccessible ( field , true ) ; final Class < ? > type = field . getType ( ) ; setField ( field , object , type ) ; } }
|
Fill services fields with their right instance .
|
3,314
|
public static String normalizeExtension ( String file , String extension ) { Check . notNull ( file ) ; Check . notNull ( extension ) ; final int length = file . length ( ) + Constant . DOT . length ( ) + extension . length ( ) ; final StringBuilder builder = new StringBuilder ( length ) . append ( removeExtension ( file ) ) . append ( Constant . DOT ) ; if ( extension . startsWith ( Constant . DOT ) ) { builder . append ( getExtension ( extension ) ) ; } else { builder . append ( extension ) ; } return builder . toString ( ) ; }
|
Normalize the file extension by ensuring it has the required one .
|
3,315
|
public static String getExtension ( File file ) { Check . notNull ( file ) ; return getExtension ( file . getName ( ) ) ; }
|
Get a file extension .
|
3,316
|
public static List < File > getFiles ( File directory ) { Check . notNull ( directory ) ; if ( directory . isDirectory ( ) ) { final File [ ] files = directory . listFiles ( ) ; if ( files != null ) { return Arrays . asList ( files ) ; } } throw new LionEngineException ( ERROR_DIRECTORY + directory . getPath ( ) ) ; }
|
Get the files list from directory .
|
3,317
|
public static boolean isType ( File file , String extension ) { Check . notNull ( extension ) ; if ( file != null && file . isFile ( ) ) { final String current = getExtension ( file ) ; return current . equals ( extension . replace ( Constant . DOT , Constant . EMPTY_STRING ) ) ; } return false ; }
|
Check if the following type is the expected type .
|
3,318
|
private void renderTile ( Graphic g , int tx , int ty , double viewX , double viewY ) { final Tile tile = map . getTile ( tx , ty ) ; if ( tile != null ) { final int x = ( int ) Math . floor ( tile . getX ( ) - viewX ) ; final int y = ( int ) Math . floor ( - tile . getY ( ) + viewY - tile . getHeight ( ) ) ; for ( final MapTileRenderer renderer : renderers ) { renderer . renderTile ( g , map , tile , x , y ) ; } } }
|
Render the tile from location .
|
3,319
|
private void renderHorizontal ( Graphic g , int ty , double viewY ) { final int inTileWidth = ( int ) Math . ceil ( viewer . getWidth ( ) / ( double ) map . getTileWidth ( ) ) ; final int sx = ( int ) Math . floor ( ( viewer . getX ( ) + viewer . getViewX ( ) ) / map . getTileWidth ( ) ) ; final double viewX = viewer . getX ( ) ; for ( int h = 0 ; h <= inTileWidth ; h ++ ) { final int tx = h + sx ; if ( ! ( tx < 0 || tx >= map . getInTileWidth ( ) ) ) { renderTile ( g , tx , ty , viewX , viewY ) ; } } }
|
Render horizontal tiles .
|
3,320
|
public synchronized void start ( ) { if ( started . get ( ) ) { throw new LionEngineException ( ERROR_STARTED ) ; } started . set ( true ) ; thread . start ( ) ; }
|
Start to load resources in a separate thread .
|
3,321
|
public static Map < TileRef , ColorRgba > imports ( Media configMinimap ) { Check . notNull ( configMinimap ) ; final Map < TileRef , ColorRgba > colors = new HashMap < > ( ) ; final Xml nodeMinimap = new Xml ( configMinimap ) ; for ( final Xml nodeColor : nodeMinimap . getChildren ( NODE_COLOR ) ) { final ColorRgba color = new ColorRgba ( nodeColor . readInteger ( ATT_COLOR_RED ) , nodeColor . readInteger ( ATT_COLOR_GREEN ) , nodeColor . readInteger ( ATT_COLOR_BLUE ) ) ; for ( final Xml nodeTileRef : nodeColor . getChildren ( TileConfig . NODE_TILE ) ) { final TileRef tileRef = TileConfig . imports ( nodeTileRef ) ; colors . put ( tileRef , color ) ; } } return colors ; }
|
Create the minimap data from node .
|
3,322
|
public static void exports ( Media configMinimap , Map < TileRef , ColorRgba > tiles ) { Check . notNull ( configMinimap ) ; Check . notNull ( tiles ) ; final Map < ColorRgba , Collection < TileRef > > colors = convertToColorKey ( tiles ) ; final Xml nodeMinimap = new Xml ( NODE_MINIMAP ) ; for ( final Map . Entry < ColorRgba , Collection < TileRef > > entry : colors . entrySet ( ) ) { final ColorRgba color = entry . getKey ( ) ; final Xml nodeColor = nodeMinimap . createChild ( NODE_COLOR ) ; nodeColor . writeInteger ( ATT_COLOR_RED , color . getRed ( ) ) ; nodeColor . writeInteger ( ATT_COLOR_GREEN , color . getGreen ( ) ) ; nodeColor . writeInteger ( ATT_COLOR_BLUE , color . getBlue ( ) ) ; for ( final TileRef tileRef : entry . getValue ( ) ) { final Xml nodeTileRef = TileConfig . exports ( tileRef ) ; nodeColor . add ( nodeTileRef ) ; } } nodeMinimap . save ( configMinimap ) ; }
|
Export tiles colors data to configuration media .
|
3,323
|
private static Map < ColorRgba , Collection < TileRef > > convertToColorKey ( Map < TileRef , ColorRgba > tiles ) { final Map < ColorRgba , Collection < TileRef > > colors = new HashMap < > ( ) ; for ( final Map . Entry < TileRef , ColorRgba > entry : tiles . entrySet ( ) ) { final Collection < TileRef > tilesRef = getTiles ( colors , entry . getValue ( ) ) ; tilesRef . add ( entry . getKey ( ) ) ; } return colors ; }
|
Convert map associating color per tile to tiles per color .
|
3,324
|
private static Collection < TileRef > getTiles ( Map < ColorRgba , Collection < TileRef > > colors , ColorRgba color ) { if ( ! colors . containsKey ( color ) ) { colors . put ( color , new HashSet < TileRef > ( ) ) ; } return colors . get ( color ) ; }
|
Get the tiles corresponding to the color . Create empty list if new color .
|
3,325
|
private int getCharWidth ( String text , Align align ) { final int width ; if ( align == Align . RIGHT ) { width = getTextWidth ( text ) ; } else if ( align == Align . CENTER ) { width = getTextWidth ( text ) / 2 ; } else { width = 0 ; } return width ; }
|
Get character width depending of alignment .
|
3,326
|
public static FeaturableConfig imports ( Configurer configurer ) { Check . notNull ( configurer ) ; return imports ( configurer . getRoot ( ) ) ; }
|
Import the featurable data from configurer .
|
3,327
|
public static FeaturableConfig imports ( Xml root ) { Check . notNull ( root ) ; final String clazz ; if ( root . hasChild ( ATT_CLASS ) ) { clazz = root . getChild ( ATT_CLASS ) . getText ( ) ; } else { clazz = DEFAULT_CLASS_NAME ; } final String setup ; if ( root . hasChild ( ATT_SETUP ) ) { setup = root . getChild ( ATT_SETUP ) . getText ( ) ; } else { setup = Constant . EMPTY_STRING ; } return new FeaturableConfig ( clazz , setup ) ; }
|
Import the featurable data from node .
|
3,328
|
public static Xml exportClass ( String clazz ) { Check . notNull ( clazz ) ; final Xml node = new Xml ( ATT_CLASS ) ; node . setText ( clazz ) ; return node ; }
|
Export the featurable node from class data .
|
3,329
|
public static Xml exportSetup ( String setup ) { Check . notNull ( setup ) ; final Xml node = new Xml ( ATT_SETUP ) ; node . setText ( setup ) ; return node ; }
|
Export the featurable node from setup data .
|
3,330
|
@ SuppressWarnings ( "unchecked" ) private static < T > Class < T > getClass ( String className ) { if ( CLASS_CACHE . containsKey ( className ) ) { return ( Class < T > ) CLASS_CACHE . get ( className ) ; } try { final Class < ? > clazz = LOADER . loadClass ( className ) ; CLASS_CACHE . put ( className , clazz ) ; return ( Class < T > ) clazz ; } catch ( final ClassNotFoundException exception ) { throw new LionEngineException ( exception , ERROR_CLASS_PRESENCE + className ) ; } }
|
Get the class reference from its name using cache .
|
3,331
|
public boolean contains ( Integer sheet , int number ) { for ( final TileRef current : tiles ) { if ( current . getSheet ( ) . equals ( sheet ) && current . getNumber ( ) == number ) { return true ; } } return false ; }
|
Check if tile is contained by the group .
|
3,332
|
public static CollisionFunction imports ( Xml parent ) { Check . notNull ( parent ) ; final Xml node = parent . getChild ( FUNCTION ) ; final String name = node . readString ( TYPE ) ; try { final CollisionFunctionType type = CollisionFunctionType . valueOf ( name ) ; switch ( type ) { case LINEAR : return new CollisionFunctionLinear ( node . readDouble ( A ) , node . readDouble ( B ) ) ; default : throw new LionEngineException ( ERROR_TYPE + name ) ; } } catch ( final IllegalArgumentException | NullPointerException exception ) { throw new LionEngineException ( exception , ERROR_TYPE + name ) ; } }
|
Create the collision function from node .
|
3,333
|
public static void exports ( Xml root , CollisionFunction function ) { Check . notNull ( root ) ; Check . notNull ( function ) ; final Xml node = root . createChild ( FUNCTION ) ; if ( function instanceof CollisionFunctionLinear ) { final CollisionFunctionLinear linear = ( CollisionFunctionLinear ) function ; node . writeString ( TYPE , CollisionFunctionType . LINEAR . name ( ) ) ; node . writeDouble ( A , linear . getA ( ) ) ; node . writeDouble ( B , linear . getB ( ) ) ; } else { node . writeString ( TYPE , String . valueOf ( function . getType ( ) ) ) ; } }
|
Export the collision function data as a node .
|
3,334
|
public void update ( double screenX , double screenY ) { for ( final Image current : surfaces . values ( ) ) { current . setLocation ( screenX + offsetX , screenY + offsetY ) ; } if ( nextSurface != null ) { surface = nextSurface ; nextSurface = null ; } }
|
Update renderer location and surface ID .
|
3,335
|
final void resize ( int newWidth , int newHeight ) { final int oldWidth = widthInTile ; final int oldheight = heightInTile ; for ( int v = 0 ; v < newHeight - oldheight ; v ++ ) { tiles . add ( new ArrayList < Tile > ( newWidth ) ) ; } for ( int v = 0 ; v < newHeight ; v ++ ) { final int width ; if ( v < oldheight ) { width = newWidth - oldWidth ; } else { width = newWidth ; } for ( int h = 0 ; h < width ; h ++ ) { tiles . get ( v ) . add ( null ) ; } } widthInTile = newWidth ; heightInTile = newHeight ; radius = ( int ) Math . ceil ( StrictMath . sqrt ( newWidth * ( double ) newWidth + newHeight * ( double ) newHeight ) ) ; }
|
Resize map with new size .
|
3,336
|
public static PathFinder createPathFinder ( MapTile map , int maxSearchDistance , Heuristic heuristic ) { return new PathFinderImpl ( map , maxSearchDistance , heuristic ) ; }
|
Create a path finder .
|
3,337
|
private static void writeIdAndName ( ClientSocket client , int id , String name ) throws IOException { client . getOut ( ) . writeByte ( id ) ; final byte [ ] data = name . getBytes ( NetworkMessage . CHARSET ) ; client . getOut ( ) . writeByte ( data . length ) ; client . getOut ( ) . write ( data ) ; }
|
Send the id and the name to the client .
|
3,338
|
private static boolean checkValidity ( ClientSocket client , byte from , StateConnection expected ) { return from >= 0 && client . getState ( ) == expected ; }
|
Check if the client is in a valid state .
|
3,339
|
void notifyNewClientConnected ( Socket socket ) { try { int secure = 0 ; while ( clients . containsKey ( Byte . valueOf ( lastId ) ) ) { lastId ++ ; secure ++ ; final int max = 127 ; if ( secure > max ) { break ; } } final ClientSocket client = new ClientSocket ( lastId , socket ) ; client . setState ( StateConnection . CONNECTING ) ; client . getOut ( ) . writeByte ( NetworkMessageSystemId . CONNECTING ) ; client . getOut ( ) . writeByte ( client . getId ( ) ) ; client . getOut ( ) . flush ( ) ; clients . put ( Byte . valueOf ( client . getId ( ) ) , client ) ; clientsNumber ++ ; } catch ( final IOException exception ) { errorNewClientConnected ( exception ) ; } catch ( final LionEngineException exception ) { errorNewClientConnected ( exception ) ; } }
|
Add a client .
|
3,340
|
void removeClient ( ClientSocket client ) { if ( client != null ) { toRemove . add ( client ) ; client . terminate ( ) ; clientsNumber -- ; willRemove = true ; Verbose . info ( SERVER , client . getName ( ) , " disconnected" ) ; } }
|
Remove a client from the server .
|
3,341
|
private void errorNewClientConnected ( Exception exception ) { Verbose . warning ( Server . class , "addClient" , "Error on adding client: " , exception . getMessage ( ) ) ; if ( clients . remove ( Byte . valueOf ( lastId ) ) != null ) { clientsNumber -- ; } }
|
Error on new client connection .
|
3,342
|
private void receiveConnecting ( ClientSocket client , DataInputStream buffer , byte from , StateConnection expected ) throws IOException { if ( ServerImpl . checkValidity ( client , from , expected ) ) { final byte [ ] name = new byte [ buffer . readByte ( ) ] ; if ( buffer . read ( name ) == - 1 ) { throw new IOException ( "Unable to read client name !" ) ; } client . setName ( new String ( name , NetworkMessage . CHARSET ) ) ; client . setState ( StateConnection . CONNECTED ) ; client . getOut ( ) . writeByte ( NetworkMessageSystemId . CONNECTED ) ; client . getOut ( ) . writeByte ( client . getId ( ) ) ; client . getOut ( ) . writeByte ( clientsNumber - 1 ) ; for ( final ClientSocket other : clients . values ( ) ) { if ( other . getId ( ) != from ) { ServerImpl . writeIdAndName ( client , other . getId ( ) , other . getName ( ) ) ; } } if ( messageOfTheDay != null ) { final byte [ ] motd = messageOfTheDay . getBytes ( NetworkMessage . CHARSET ) ; client . getOut ( ) . writeByte ( motd . length ) ; client . getOut ( ) . write ( motd ) ; } client . getOut ( ) . flush ( ) ; } }
|
Update the receive connecting state .
|
3,343
|
private void receiveConnected ( ClientSocket client , byte from , StateConnection expected ) throws IOException { if ( ServerImpl . checkValidity ( client , from , expected ) ) { Verbose . info ( SERVER , client . getName ( ) , " connected" ) ; for ( final ClientListener listener : listeners ) { listener . notifyClientConnected ( Byte . valueOf ( client . getId ( ) ) , client . getName ( ) ) ; } for ( final ClientSocket other : clients . values ( ) ) { if ( other . getId ( ) == from ) { continue ; } other . getOut ( ) . writeByte ( NetworkMessageSystemId . OTHER_CLIENT_CONNECTED ) ; ServerImpl . writeIdAndName ( other , client . getId ( ) , client . getName ( ) ) ; other . getOut ( ) . flush ( ) ; } } }
|
Update the receive connected state .
|
3,344
|
private void receiveDisconnected ( ClientSocket client , byte from , StateConnection expected ) throws IOException { if ( ServerImpl . checkValidity ( client , from , expected ) ) { client . setState ( StateConnection . DISCONNECTED ) ; for ( final ClientListener listener : listeners ) { listener . notifyClientDisconnected ( Byte . valueOf ( client . getId ( ) ) , client . getName ( ) ) ; } for ( final ClientSocket other : clients . values ( ) ) { if ( other . getId ( ) == from || other . getState ( ) != StateConnection . CONNECTED ) { continue ; } other . getOut ( ) . writeByte ( NetworkMessageSystemId . OTHER_CLIENT_DISCONNECTED ) ; ServerImpl . writeIdAndName ( other , client . getId ( ) , client . getName ( ) ) ; other . getOut ( ) . flush ( ) ; } removeClient ( Byte . valueOf ( from ) ) ; } }
|
Update the receive disconnected state .
|
3,345
|
private void receiveRenamed ( ClientSocket client , DataInputStream buffer , byte from , StateConnection expected ) throws IOException { if ( ServerImpl . checkValidity ( client , from , expected ) ) { final byte [ ] name = new byte [ buffer . readByte ( ) ] ; if ( buffer . read ( name ) == - 1 ) { throw new IOException ( "Unable to read client name on rename !" ) ; } final String newName = new String ( name , NetworkMessage . CHARSET ) ; Verbose . info ( SERVER , client . getName ( ) , " rennamed to " , newName ) ; client . setName ( newName ) ; for ( final ClientListener listener : listeners ) { listener . notifyClientNameChanged ( Byte . valueOf ( client . getId ( ) ) , client . getName ( ) ) ; } for ( final ClientSocket other : clients . values ( ) ) { other . getOut ( ) . writeByte ( NetworkMessageSystemId . OTHER_CLIENT_RENAMED ) ; ServerImpl . writeIdAndName ( other , client . getId ( ) , client . getName ( ) ) ; other . getOut ( ) . flush ( ) ; } } }
|
Update the receive renamed state .
|
3,346
|
private void receiveMessage ( ClientSocket client , DataInputStream buffer , byte from , StateConnection expected ) throws IOException { if ( ServerImpl . checkValidity ( client , from , expected ) ) { final byte dest = buffer . readByte ( ) ; final byte type = buffer . readByte ( ) ; final int size = buffer . readInt ( ) ; if ( size > 0 ) { final byte [ ] clientData = new byte [ size ] ; if ( buffer . read ( clientData ) != - 1 ) { final DataInputStream clientBuffer = new DataInputStream ( new ByteArrayInputStream ( clientData ) ) ; decodeMessage ( type , from , dest , clientBuffer ) ; } } final int headerSize = 4 ; bandwidth += headerSize + size ; } }
|
Update the receive standard message state .
|
3,347
|
private void updateMessage ( ClientSocket client , DataInputStream buffer , byte messageSystemId , byte from ) throws IOException { switch ( messageSystemId ) { case NetworkMessageSystemId . CONNECTING : receiveConnecting ( client , buffer , from , StateConnection . CONNECTING ) ; break ; case NetworkMessageSystemId . CONNECTED : receiveConnected ( client , from , StateConnection . CONNECTED ) ; break ; case NetworkMessageSystemId . PING : client . getOut ( ) . writeByte ( NetworkMessageSystemId . PING ) ; client . getOut ( ) . flush ( ) ; bandwidth += 1 ; break ; case NetworkMessageSystemId . OTHER_CLIENT_DISCONNECTED : receiveDisconnected ( client , from , StateConnection . CONNECTED ) ; break ; case NetworkMessageSystemId . OTHER_CLIENT_RENAMED : receiveRenamed ( client , buffer , from , StateConnection . CONNECTED ) ; break ; case NetworkMessageSystemId . USER_MESSAGE : receiveMessage ( client , buffer , from , StateConnection . CONNECTED ) ; break ; default : break ; } }
|
Update the message depending of its ID .
|
3,348
|
private JFrame initMainFrame ( ) { final String title = getTitle ( ) ; final JFrame jframe = new JFrame ( title , conf ) ; jframe . setDefaultCloseOperation ( WindowConstants . DO_NOTHING_ON_CLOSE ) ; jframe . addWindowListener ( new WindowAdapter ( ) { public void windowClosing ( WindowEvent event ) { listeners . forEach ( ScreenListener :: notifyClosed ) ; } } ) ; jframe . setResizable ( false ) ; jframe . setUndecorated ( false ) ; jframe . setIgnoreRepaint ( true ) ; return jframe ; }
|
Initialize the main frame .
|
3,349
|
private static String getTitle ( ) { final StringBuilder builder = new StringBuilder ( Constant . BYTE_4 ) ; if ( Engine . isStarted ( ) ) { builder . append ( Engine . getProgramName ( ) ) . append ( Constant . SPACE ) . append ( Engine . getProgramVersion ( ) ) ; } else { builder . append ( Constant . ENGINE_NAME ) . append ( Constant . SPACE ) . append ( Constant . ENGINE_VERSION ) ; } return builder . toString ( ) ; }
|
Get screen title .
|
3,350
|
private static Collision collide ( Origin origin , FeatureProvider provider , Transformable transformable , Collidable other , Collision collision , Rectangle rectangle ) { final Mirror mirror = getMirror ( provider , collision ) ; final int offsetX = getOffsetX ( collision , mirror ) ; final int offsetY = getOffsetY ( collision , mirror ) ; final double sh = origin . getX ( transformable . getOldX ( ) + offsetX , rectangle . getWidthReal ( ) ) ; final double sv = origin . getY ( transformable . getOldY ( ) + offsetY , rectangle . getHeightReal ( ) ) ; final double dh = origin . getX ( transformable . getX ( ) + offsetX , rectangle . getWidthReal ( ) ) - sh ; final double dv = origin . getY ( transformable . getY ( ) + offsetY , rectangle . getHeightReal ( ) ) - sv ; final double norm = Math . sqrt ( dh * dh + dv * dv ) ; final double sx ; final double sy ; if ( Double . compare ( norm , 0.0 ) == 0 ) { sx = 0 ; sy = 0 ; } else { sx = dh / norm ; sy = dv / norm ; } final double oldX = rectangle . getX ( ) ; final double oldY = rectangle . getY ( ) ; for ( int count = 0 ; count <= norm ; count ++ ) { if ( checkCollide ( rectangle , other ) ) { return collision ; } rectangle . translate ( sx , sy ) ; } rectangle . set ( oldX , oldY , rectangle . getWidth ( ) , rectangle . getHeight ( ) ) ; return null ; }
|
Check if other collides with collision and its rectangle area .
|
3,351
|
private static boolean checkCollide ( Area area , Collidable other ) { final List < Rectangle > others = other . getCollisionBounds ( ) ; final int size = others . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { final Area current = others . get ( i ) ; if ( area . intersects ( current ) ) { return true ; } } return false ; }
|
Check if current area collides other collidable area .
|
3,352
|
private static Mirror getMirror ( FeatureProvider provider , Collision collision ) { if ( collision . hasMirror ( ) && provider . hasFeature ( Mirrorable . class ) ) { return provider . getFeature ( Mirrorable . class ) . getMirror ( ) ; } return Mirror . NONE ; }
|
Get the collision mirror .
|
3,353
|
private static int getOffsetX ( Collision collision , Mirror mirror ) { if ( mirror == Mirror . HORIZONTAL ) { return - collision . getOffsetX ( ) ; } return collision . getOffsetX ( ) ; }
|
Get the horizontal offset .
|
3,354
|
private static int getOffsetY ( Collision collision , Mirror mirror ) { if ( mirror == Mirror . VERTICAL ) { return - collision . getOffsetY ( ) ; } return collision . getOffsetY ( ) ; }
|
Get the vertical offset .
|
3,355
|
private void update ( Collision collision , double x , double y , int width , int height , Map < Collision , Rectangle > cacheRectRender ) { if ( boxs . containsKey ( collision ) ) { final Rectangle rectangle = boxs . get ( collision ) ; rectangle . set ( x , y , width , height ) ; cacheRectRender . get ( collision ) . set ( x , y , width , height ) ; } else { final Rectangle rectangle = new Rectangle ( x , y , width , height ) ; cacheColls . add ( collision ) ; cacheRect . add ( rectangle ) ; cacheRectRender . put ( collision , new Rectangle ( x , y , width , height ) ) ; boxs . put ( collision , rectangle ) ; } }
|
Update the collision box .
|
3,356
|
public List < Collision > collide ( Origin origin , FeatureProvider provider , Transformable transformable , Collidable other , Collection < Integer > accepted ) { final List < Collision > collisions = new ArrayList < > ( ) ; if ( enabled && other . isEnabled ( ) && accepted . contains ( other . getGroup ( ) ) ) { final int size = cacheColls . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { final Collision collision = collide ( origin , provider , transformable , other , cacheColls . get ( i ) , cacheRect . get ( i ) ) ; if ( collision != null ) { collisions . add ( collision ) ; } } } return collisions ; }
|
Check if the collidable entered in collision with another one .
|
3,357
|
public static LaunchableConfig imports ( Xml node ) { Check . notNull ( node ) ; final String media = node . readString ( ATT_MEDIA ) ; final int delay = node . readInteger ( ATT_DELAY ) ; final int ox = node . readInteger ( 0 , ATT_OFFSET_X ) ; final int oy = node . readInteger ( 0 , ATT_OFFSET_Y ) ; return new LaunchableConfig ( media , delay , ox , oy , ForceConfig . imports ( node ) ) ; }
|
Import the launchable data from node .
|
3,358
|
public static Xml exports ( LaunchableConfig config ) { Check . notNull ( config ) ; final Xml node = new Xml ( NODE_LAUNCHABLE ) ; node . writeString ( ATT_MEDIA , config . getMedia ( ) ) ; node . writeInteger ( ATT_DELAY , config . getDelay ( ) ) ; node . writeInteger ( ATT_OFFSET_X , config . getOffsetX ( ) ) ; node . writeInteger ( ATT_OFFSET_Y , config . getOffsetY ( ) ) ; node . add ( ForceConfig . exports ( config . getVector ( ) ) ) ; return node ; }
|
Export the launchable node from data .
|
3,359
|
public void mouseReleased ( MouseEvent event ) { lastClick = 0 ; final int button = event . getClick ( ) ; clicks [ button ] = false ; clicked [ button ] = false ; }
|
Called on mouse released .
|
3,360
|
public static Collection < ZipEntry > getEntriesByExtension ( File jar , String path , String extension ) { Check . notNull ( jar ) ; Check . notNull ( path ) ; Check . notNull ( extension ) ; try ( ZipFile zip = new ZipFile ( jar ) ) { return checkEntries ( zip , path , extension ) ; } catch ( final IOException exception ) { throw new LionEngineException ( exception , ERROR_OPEN_ZIP + jar . getAbsolutePath ( ) ) ; } }
|
Get all entries existing in the path considering the extension .
|
3,361
|
private static Collection < ZipEntry > checkEntries ( ZipFile zip , String path , String extension ) { final Collection < ZipEntry > entries = new ArrayList < > ( ) ; final Enumeration < ? extends ZipEntry > zipEntries = zip . entries ( ) ; while ( zipEntries . hasMoreElements ( ) ) { final ZipEntry entry = zipEntries . nextElement ( ) ; final String name = entry . getName ( ) ; if ( name . startsWith ( path ) && UtilFile . getExtension ( name ) . equals ( extension ) ) { entries . add ( entry ) ; } } return entries ; }
|
Check all entries existing in the ZIP considering the extension .
|
3,362
|
public static AudioFormat getFailsafe ( ) { try { return new Sc68Format ( ) ; } catch ( final LionEngineException exception ) { Verbose . exception ( exception , ERROR_LOAD_LIBRARY ) ; return new AudioVoidFormat ( FORMATS ) ; } }
|
Get the library or void format if not found .
|
3,363
|
private static Sc68Binding loadLibrary ( ) { try { Verbose . info ( "Load library: " , LIBRARY_NAME ) ; final Sc68Binding binding = Native . loadLibrary ( LIBRARY_NAME , Sc68Binding . class ) ; Verbose . info ( "Library " , LIBRARY_NAME , " loaded" ) ; return binding ; } catch ( final LinkageError exception ) { throw new LionEngineException ( exception , ERROR_LOAD_LIBRARY + LIBRARY_NAME ) ; } }
|
Load the library .
|
3,364
|
public void add ( Featurable featurable ) { featurables . put ( featurable . getFeature ( Identifiable . class ) . getId ( ) , featurable ) ; for ( final Class < ? > type : featurable . getClass ( ) . getInterfaces ( ) ) { addType ( type , featurable ) ; } for ( final Class < ? extends Feature > feature : featurable . getFeaturesType ( ) ) { final Feature object = featurable . getFeature ( feature ) ; addType ( feature , object ) ; for ( final Class < ? > other : UtilReflection . getInterfaces ( feature , Feature . class ) ) { addType ( other , object ) ; } } addType ( featurable . getClass ( ) , featurable ) ; addSuperClass ( featurable , featurable . getClass ( ) ) ; }
|
Add a featurable .
|
3,365
|
public void remove ( Featurable featurable , Integer id ) { for ( final Class < ? > type : featurable . getClass ( ) . getInterfaces ( ) ) { remove ( type , featurable ) ; } for ( final Class < ? extends Feature > feature : featurable . getFeaturesType ( ) ) { final Feature object = featurable . getFeature ( feature ) ; remove ( feature , object ) ; for ( final Class < ? > other : UtilReflection . getInterfaces ( feature , Feature . class ) ) { remove ( other , object ) ; } } remove ( featurable . getClass ( ) , featurable ) ; removeSuperClass ( featurable , featurable . getClass ( ) ) ; featurables . remove ( id ) ; }
|
Remove the featurable and all its references .
|
3,366
|
private void addType ( Class < ? > type , Object object ) { if ( ! items . containsKey ( type ) ) { items . put ( type , new HashSet < > ( ) ) ; } items . get ( type ) . add ( object ) ; }
|
Add a type from its interface .
|
3,367
|
private void addSuperClass ( Object object , Class < ? > type ) { for ( final Class < ? > types : type . getInterfaces ( ) ) { addType ( types , object ) ; } final Class < ? > parent = type . getSuperclass ( ) ; if ( parent != null ) { addSuperClass ( object , parent ) ; } }
|
Add object parent super type .
|
3,368
|
private void removeSuperClass ( Object object , Class < ? > type ) { for ( final Class < ? > types : type . getInterfaces ( ) ) { remove ( types , object ) ; } final Class < ? > parent = type . getSuperclass ( ) ; if ( parent != null ) { removeSuperClass ( object , parent ) ; } }
|
Remove object parent super type .
|
3,369
|
private void remove ( Class < ? > type , Object object ) { final Set < ? > set = items . get ( type ) ; if ( set != null ) { set . remove ( object ) ; } }
|
Remove the object from its type list .
|
3,370
|
public static Map < String , PathData > imports ( Configurer configurer ) { Check . notNull ( configurer ) ; final Xml root = configurer . getRoot ( ) ; if ( ! root . hasChild ( NODE_PATHFINDABLE ) ) { return Collections . emptyMap ( ) ; } final Map < String , PathData > categories = new HashMap < > ( 0 ) ; final Xml nodePathfindable = root . getChild ( NODE_PATHFINDABLE ) ; for ( final Xml nodePath : nodePathfindable . getChildren ( NODE_PATH ) ) { final PathData data = importPathData ( nodePath ) ; categories . put ( data . getName ( ) , data ) ; } return categories ; }
|
Import the pathfindable data from node .
|
3,371
|
public static Xml exports ( Map < String , PathData > pathData ) { Check . notNull ( pathData ) ; final Xml node = new Xml ( NODE_PATHFINDABLE ) ; for ( final PathData data : pathData . values ( ) ) { node . add ( exportPathData ( data ) ) ; } return node ; }
|
Export the pathfindable data to node .
|
3,372
|
private static Collection < MovementTile > importAllowedMovements ( Xml node ) { if ( ! node . hasChild ( NODE_MOVEMENT ) ) { return Collections . emptySet ( ) ; } final Collection < MovementTile > movements = EnumSet . noneOf ( MovementTile . class ) ; for ( final Xml movementNode : node . getChildren ( NODE_MOVEMENT ) ) { try { movements . add ( MovementTile . valueOf ( movementNode . getText ( ) ) ) ; } catch ( final IllegalArgumentException exception ) { throw new LionEngineException ( exception ) ; } } return movements ; }
|
Import the allowed movements .
|
3,373
|
private static void exportAllowedMovements ( Xml root , Collection < MovementTile > movements ) { for ( final MovementTile movement : movements ) { final Xml node = root . createChild ( NODE_MOVEMENT ) ; node . setText ( movement . name ( ) ) ; } }
|
Export the allowed movements .
|
3,374
|
private static TransitionType getTransition ( TransitionType a , TransitionType b , int ox , int oy ) { final TransitionType type = getTransitionHorizontalVertical ( a , b , ox , oy ) ; if ( type != null ) { return type ; } return getTransitionDiagonals ( a , b , ox , oy ) ; }
|
Get the new transition type from two transitions .
|
3,375
|
private static TransitionType getTransitionHorizontalVertical ( TransitionType a , TransitionType b , int ox , int oy ) { final TransitionType type ; if ( ox == - 1 && oy == 0 ) { type = TransitionType . from ( ! b . getDownRight ( ) , a . getDownLeft ( ) , ! b . getUpRight ( ) , a . getUpLeft ( ) ) ; } else if ( ox == 1 && oy == 0 ) { type = TransitionType . from ( a . getDownRight ( ) , ! b . getDownLeft ( ) , a . getUpRight ( ) , ! b . getUpLeft ( ) ) ; } else if ( ox == 0 && oy == 1 ) { type = TransitionType . from ( ! b . getDownRight ( ) , ! b . getDownLeft ( ) , a . getUpRight ( ) , a . getUpLeft ( ) ) ; } else if ( ox == 0 && oy == - 1 ) { type = TransitionType . from ( a . getDownRight ( ) , a . getDownLeft ( ) , ! b . getUpRight ( ) , ! b . getUpLeft ( ) ) ; } else { type = null ; } return type ; }
|
Get the new transition type from two transitions on horizontal and vertical axis .
|
3,376
|
private void resolve ( Collection < Tile > resolved , Collection < Tile > toResolve , Tile tile ) { updateTile ( resolved , toResolve , tile , - 1 , 0 ) ; updateTile ( resolved , toResolve , tile , 1 , 0 ) ; updateTile ( resolved , toResolve , tile , 0 , 1 ) ; updateTile ( resolved , toResolve , tile , 0 , - 1 ) ; updateTile ( resolved , toResolve , tile , - 1 , 1 ) ; updateTile ( resolved , toResolve , tile , 1 , 1 ) ; updateTile ( resolved , toResolve , tile , - 1 , - 1 ) ; updateTile ( resolved , toResolve , tile , 1 , - 1 ) ; }
|
Resolve current tile and add to resolve list extra tiles .
|
3,377
|
private void updateTransition ( Collection < Tile > resolved , Collection < Tile > toResolve , Tile tile , Tile neighbor , String neighborGroup , Transition newTransition ) { if ( ! neighborGroup . equals ( newTransition . getIn ( ) ) ) { updateTile ( resolved , toResolve , tile , neighbor , newTransition ) ; } }
|
Update transition .
|
3,378
|
private void checkTransitives ( Collection < Tile > resolved , Tile tile ) { boolean isTransitive = false ; for ( final Tile neighbor : map . getNeighbors ( tile ) ) { final String group = mapGroup . getGroup ( tile ) ; final String neighborGroup = mapGroup . getGroup ( neighbor ) ; final Collection < GroupTransition > transitives = getTransitives ( group , neighborGroup ) ; if ( transitives . size ( ) > 1 && ( getTransition ( neighbor , group ) == null || isCenter ( neighbor ) ) ) { final int iterations = transitives . size ( ) - 3 ; int i = 0 ; for ( final GroupTransition transitive : transitives ) { updateTransitive ( resolved , tile , neighbor , transitive ) ; isTransitive = true ; i ++ ; if ( i > iterations ) { break ; } } } } if ( isTransitive ) { map . setTile ( tile ) ; } }
|
Check tile transitive groups .
|
3,379
|
private void updateTransitive ( Collection < Tile > resolved , Tile tile , Tile neighbor , GroupTransition transitive ) { final String transitiveOut = transitive . getOut ( ) ; final Transition transition = new Transition ( TransitionType . CENTER , transitiveOut , transitiveOut ) ; final Collection < TileRef > refs = getTiles ( transition ) ; if ( ! refs . isEmpty ( ) ) { final TileRef ref = refs . iterator ( ) . next ( ) ; final Tile newTile = map . createTile ( ref . getSheet ( ) , ref . getNumber ( ) , tile . getX ( ) , tile . getY ( ) ) ; map . setTile ( newTile ) ; final Tile newTile2 = map . createTile ( ref . getSheet ( ) , ref . getNumber ( ) , neighbor . getX ( ) , neighbor . getY ( ) ) ; map . setTile ( newTile2 ) ; resolved . addAll ( resolve ( newTile2 ) ) ; } }
|
Update the transitive between tile and its neighbor .
|
3,380
|
private boolean isCenter ( Tile tile ) { for ( final Transition transition : tiles . get ( new TileRef ( tile ) ) ) { if ( TransitionType . CENTER == transition . getType ( ) ) { return true ; } } return false ; }
|
Check if tile is a center .
|
3,381
|
private static void compute ( Kernel kernel , int [ ] in , int [ ] out , int width , int height , boolean alpha , int edge ) { final float [ ] matrix = kernel . getMatrix ( ) ; final int cols = kernel . getWidth ( ) ; final int cols2 = cols / 2 ; for ( int y = 0 ; y < height ; y ++ ) { int index = y ; final int ioffset = y * width ; for ( int x = 0 ; x < width ; x ++ ) { compute ( matrix , in , out , x , index , ioffset , cols2 , width , alpha , edge ) ; index += height ; } } }
|
Compute blur .
|
3,382
|
private static void compute ( float [ ] matrix , int [ ] in , int [ ] out , int x , int index , int ioffset , int cols2 , int width , boolean alpha , int edge ) { float r = 0 ; float g = 0 ; float b = 0 ; float a = 0 ; final int moffset = cols2 ; for ( int col = - cols2 ; col <= cols2 ; col ++ ) { final float f = matrix [ moffset + col ] ; if ( Double . doubleToRawLongBits ( f ) != 0L ) { final int ix = checkEdge ( width , x , col , edge ) ; final int rgb = in [ ioffset + ix ] ; a += f * ( rgb >> Constant . BYTE_4 & 0xFF ) ; r += f * ( rgb >> Constant . BYTE_3 & 0xFF ) ; g += f * ( rgb >> Constant . BYTE_2 & 0xFF ) ; b += f * ( rgb & 0xFF ) ; } } final int ia ; if ( alpha ) { ia = clamp ( ( int ) ( a + Constant . HALF ) ) ; } else { ia = 0xFF ; } final int ir = clamp ( ( int ) ( r + 0.5 ) ) ; final int ig = clamp ( ( int ) ( g + 0.5 ) ) ; final int ib = clamp ( ( int ) ( b + 0.5 ) ) ; out [ index ] = ia << Constant . BYTE_4 | ir << Constant . BYTE_3 | ig << Constant . BYTE_2 | ib ; }
|
Compute blur point .
|
3,383
|
private static int checkEdge ( int width , int x , int col , int edge ) { int ix = x + col ; if ( ix < 0 ) { if ( edge == CLAMP_EDGES ) { ix = 0 ; } else { ix = ( x + width ) % width ; } } else if ( ix >= width ) { if ( edge == CLAMP_EDGES ) { ix = width - 1 ; } else { ix = ( x + width ) % width ; } } return ix ; }
|
Check the edge value .
|
3,384
|
private static Kernel createKernel ( float radius , int width , int height ) { final int r = ( int ) Math . ceil ( radius ) ; final int rows = r * 2 + 1 ; final float [ ] matrix = new float [ rows ] ; final float sigma = radius / 3 ; final float sigma22 = 2 * sigma * sigma ; final float sigmaPi2 = ( float ) ( 2 * Math . PI * sigma ) ; final float sqrtSigmaPi2 = ( float ) Math . sqrt ( sigmaPi2 ) ; final float radius2 = radius * radius ; float total = 0.0F ; int index = 0 ; for ( int row = - r ; row <= r ; row ++ ) { final float distance = row * ( float ) row ; if ( distance > radius2 ) { matrix [ index ] = 0 ; } else { matrix [ index ] = ( float ) Math . exp ( - distance / sigma22 ) / sqrtSigmaPi2 ; } total += matrix [ index ] ; index ++ ; } for ( int i = 0 ; i < rows ; i ++ ) { matrix [ i ] /= total ; } final float [ ] data = new float [ width * height ] ; System . arraycopy ( matrix , 0 , data , 0 , rows ) ; return new Kernel ( rows , data ) ; }
|
Create a blur kernel .
|
3,385
|
protected void setResolution ( Resolution output ) { Check . notNull ( output ) ; width = output . getWidth ( ) ; height = output . getHeight ( ) ; }
|
Set the screen config . Initialize the display .
|
3,386
|
public static Sequencable create ( Class < ? extends Sequencable > nextSequence , Context context , Object ... arguments ) { Check . notNull ( nextSequence ) ; Check . notNull ( context ) ; Check . notNull ( arguments ) ; try { final Class < ? > [ ] params = getParamTypes ( context , arguments ) ; return UtilReflection . create ( nextSequence , params , getParams ( context , arguments ) ) ; } catch ( final NoSuchMethodException exception ) { throw new LionEngineException ( exception ) ; } }
|
Create a sequence from its class .
|
3,387
|
public static void pause ( long delay ) { try { Thread . sleep ( delay ) ; } catch ( @ SuppressWarnings ( "unused" ) final InterruptedException exception ) { Thread . currentThread ( ) . interrupt ( ) ; } }
|
Pause time .
|
3,388
|
private static Object [ ] getParams ( Context context , Object ... arguments ) { final Collection < Object > params = new ArrayList < > ( 1 ) ; params . add ( context ) ; params . addAll ( Arrays . asList ( arguments ) ) ; return params . toArray ( ) ; }
|
Get the parameter as array .
|
3,389
|
private void assignObjectId ( int dtx , int dty ) { final int tw = transformable . getWidth ( ) / map . getTileWidth ( ) ; final int th = transformable . getHeight ( ) / map . getTileHeight ( ) ; for ( int tx = dtx ; tx < dtx + tw ; tx ++ ) { for ( int ty = dty ; ty < dty + th ; ty ++ ) { mapPath . addObjectId ( tx , ty , id ) ; } } }
|
Assign the map object id of the pathfindable .
|
3,390
|
private void removeObjectId ( int dtx , int dty ) { final int tw = transformable . getWidth ( ) / map . getTileWidth ( ) ; final int th = transformable . getHeight ( ) / map . getTileHeight ( ) ; for ( int tx = dtx ; tx < dtx + tw ; tx ++ ) { for ( int ty = dty ; ty < dty + th ; ty ++ ) { if ( mapPath . getObjectsId ( tx , ty ) . contains ( id ) ) { mapPath . removeObjectId ( tx , ty , id ) ; } } } }
|
Remove the map object id of the pathfindable .
|
3,391
|
private void updateObjectId ( int lastStep , int nextStep ) { final int max = getMaxStep ( ) ; if ( nextStep < max ) { if ( checkObjectId ( path . getX ( nextStep ) , path . getY ( nextStep ) ) ) { takeNextStep ( lastStep , nextStep ) ; } else { avoidObstacle ( nextStep , max ) ; } } }
|
Update reference by updating map object Id .
|
3,392
|
private void takeNextStep ( int lastStep , int nextStep ) { if ( ! pathStoppedRequested ) { removeObjectId ( path . getX ( lastStep ) , path . getY ( lastStep ) ) ; assignObjectId ( path . getX ( nextStep ) , path . getY ( nextStep ) ) ; } }
|
Update the next step has it is free .
|
3,393
|
private void avoidObstacle ( int nextStep , int max ) { if ( nextStep >= max - 1 ) { pathStoppedRequested = true ; } final Collection < Integer > cid = mapPath . getObjectsId ( path . getX ( nextStep ) , path . getY ( nextStep ) ) ; if ( sharedPathIds . containsAll ( cid ) ) { setDestination ( destX , destY ) ; } else { if ( ! ignoredIds . containsAll ( cid ) ) { setDestination ( destX , destY ) ; } } }
|
Update to avoid obstacle because next step is not free .
|
3,394
|
private void renderPath ( Graphic g ) { final int tw = map . getTileWidth ( ) ; final int th = map . getTileHeight ( ) ; for ( int i = 0 ; i < path . getLength ( ) ; i ++ ) { final int x = ( int ) viewer . getViewpointX ( path . getX ( i ) * ( double ) tw ) ; final int y = ( int ) viewer . getViewpointY ( path . getY ( i ) * ( double ) th ) ; g . drawRect ( x , y - th , tw , th , true ) ; if ( renderDebug ) { final Tile tile = map . getTile ( path . getX ( i ) , path . getY ( i ) ) ; if ( tile != null ) { final TilePath tilePath = tile . getFeature ( TilePath . class ) ; text . draw ( g , x + 2 , y - th + 2 , String . valueOf ( getCost ( tilePath . getCategory ( ) ) ) ) ; } } } }
|
Render the current path .
|
3,395
|
private void prepareDestination ( int dtx , int dty ) { pathStopped = false ; pathStoppedRequested = false ; destX = dtx ; destY = dty ; destinationReached = false ; }
|
Prepare the destination store its location and reset states .
|
3,396
|
private void moveTo ( double extrp , int dx , int dy ) { final Force force = getMovementForce ( transformable . getX ( ) , transformable . getY ( ) , dx , dy ) ; final double sx = force . getDirectionHorizontal ( ) ; final double sy = force . getDirectionVertical ( ) ; moveX = sx ; moveY = sy ; transformable . moveLocation ( extrp , force ) ; moving = true ; final boolean arrivedX = checkArrivedX ( extrp , sx , dx ) ; final boolean arrivedY = checkArrivedY ( extrp , sy , dy ) ; if ( arrivedX && arrivedY ) { setLocation ( path . getX ( currentStep ) , path . getY ( currentStep ) ) ; final int next = currentStep + 1 ; if ( currentStep < getMaxStep ( ) - 1 ) { updateObjectId ( currentStep , next ) ; } if ( ! pathStoppedRequested && ! skip ) { currentStep = next ; } if ( currentStep > 0 && ! skip ) { checkPathfinderChanges ( ) ; } } }
|
Move to destination .
|
3,397
|
private boolean checkArrivedX ( double extrp , double sx , double dx ) { final double x = transformable . getX ( ) ; if ( sx < 0 && x <= dx || sx >= 0 && x >= dx ) { transformable . moveLocation ( extrp , dx - x , 0 ) ; return true ; } return false ; }
|
Check if the pathfindable is horizontally arrived .
|
3,398
|
private boolean checkArrivedY ( double extrp , double sy , double dy ) { final double y = transformable . getY ( ) ; if ( sy < 0 && y <= dy || sy >= 0 && y >= dy ) { transformable . moveLocation ( extrp , 0 , dy - y ) ; return true ; } return false ; }
|
Check if the pathfindable is vertically arrived .
|
3,399
|
private void checkPathfinderChanges ( ) { if ( pathFoundChanged ) { if ( currentStep < getMaxStep ( ) ) { removeObjectId ( path . getX ( currentStep ) , path . getY ( currentStep ) ) ; } if ( path != null ) { path . clear ( ) ; } path = pathfinder . findPath ( this , destX , destY , false ) ; pathFoundChanged = false ; currentStep = 0 ; skip = false ; reCheckRef = false ; if ( path == null ) { pathStoppedRequested = true ; } } if ( pathStoppedRequested ) { pathStopped = true ; pathStoppedRequested = false ; onArrived ( ) ; } }
|
Check if pathfinder changed .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.