idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
37,800 | public double set ( double amount , String world , String currencyName ) { return set ( amount , world , currencyName , Cause . UNKNOWN , null ) ; } | set a certain amount of money in the account |
37,801 | public boolean hasEnough ( double amount , String worldName , String currencyName ) { boolean result = false ; amount = format ( amount ) ; if ( ! Common . getInstance ( ) . getWorldGroupManager ( ) . worldGroupExist ( worldName ) ) { worldName = Common . getInstance ( ) . getWorldGroupManager ( ) . getWorldGroupName ( worldName ) ; } Currency currency = Common . getInstance ( ) . getCurrencyManager ( ) . getCurrency ( currencyName ) ; if ( currency != null && ( getBalance ( worldName , currencyName ) >= amount || hasInfiniteMoney ( ) ) ) { result = true ; } return result ; } | Checks if we have enough money in a certain balance |
37,802 | private static String getWorldPlayerCurrentlyIn ( String playerName ) { return Common . getInstance ( ) . getServerCaller ( ) . getPlayerCaller ( ) . getPlayerWorld ( playerName ) ; } | Returns the world that the player is currently in |
37,803 | public static String getWorldGroupOfPlayerCurrentlyIn ( String playerName ) { return Common . getInstance ( ) . getWorldGroupManager ( ) . getWorldGroupName ( getWorldPlayerCurrentlyIn ( playerName ) ) ; } | Retrieve the world group of the player |
37,804 | public void setInfiniteMoney ( boolean infinite ) { Common . getInstance ( ) . getStorageHandler ( ) . getStorageEngine ( ) . setInfiniteMoney ( this , infinite ) ; infiniteMoney = infinite ; } | Sets the account to have infinite money . |
37,805 | public void setIgnoreACL ( boolean ignore ) { Common . getInstance ( ) . getStorageHandler ( ) . getStorageEngine ( ) . setIgnoreACL ( this , ignore ) ; ignoreACL = ignore ; } | Sets if a account should ignore his ACL . Only works on Bank accounts . |
37,806 | public void setName ( String name ) { String oldname = this . name ; this . name = name ; save ( oldname ) ; } | Set the currency name |
37,807 | public double getExchangeRate ( Currency otherCurrency ) throws NoExchangeRate { return Common . getInstance ( ) . getStorageHandler ( ) . getStorageEngine ( ) . getExchangeRate ( this , otherCurrency ) ; } | Returns the exchange rate between 2 currency . |
37,808 | public void setExchangeRate ( Currency otherCurrency , double amount ) { Common . getInstance ( ) . getStorageHandler ( ) . getStorageEngine ( ) . setExchangeRate ( this , otherCurrency , amount ) ; } | Set the exchange rate between 2 currency |
37,809 | private void save ( String oldName ) { Common . getInstance ( ) . getStorageHandler ( ) . getStorageEngine ( ) . saveCurrency ( oldName , this ) ; Common . getInstance ( ) . getCurrencyManager ( ) . updateEntry ( oldName , this ) ; } | Save the currency information . Used while changing the main currency name . |
37,810 | public boolean setDbType ( String dbType ) { boolean result = false ; if ( dbTypes . contains ( dbType ) ) { setSelectedDbType ( dbType ) ; result = true ; } return result ; } | Sets the selected database type . |
37,811 | public boolean setDbInfo ( String field , String value ) { boolean result = false ; if ( dbInfo . contains ( field ) ) { dbConnectInfo . put ( field , value ) ; result = true ; } return result ; } | Sets a field information for the selected database type |
37,812 | protected void addAccountToString ( String sender , List < User > userList2 ) { Common . getInstance ( ) . getServerCaller ( ) . getPlayerCaller ( ) . sendMessage ( sender , "{{DARK_RED}}Converting accounts. This may take a while." ) ; Common . getInstance ( ) . getStorageHandler ( ) . getStorageEngine ( ) . saveImporterUsers ( userList2 ) ; Common . getInstance ( ) . getServerCaller ( ) . getPlayerCaller ( ) . sendMessage ( sender , userList2 . size ( ) + " {{DARK_GREEN}}accounts converted! Enjoy!" ) ; } | Add the given accounts to the system |
37,813 | public void addWorld ( String name ) { if ( name != null && Common . getInstance ( ) . getServerCaller ( ) . worldExist ( name ) && ! worldExist ( name ) ) { worldList . add ( name ) ; save ( ) ; } } | Add a world to this worldGroup . It needs to exist so it can be added! |
37,814 | public void removeWorld ( String world ) { if ( worldList . contains ( world ) ) { worldList . remove ( world ) ; save ( ) ; } } | Remove a world from the group if it exists . |
37,815 | public void sendData ( TreeSet < Data > data ) { if ( data == null ) { throw new IllegalArgumentException ( "Data must be not null" ) ; } if ( data . isEmpty ( ) ) { return ; } addData ( data ) ; if ( distributed ) { partitionManager . notifyData ( new ArrayList < > ( data ) ) ; } } | use synchronized blocks to protect pendingData . |
37,816 | public void sendEvents ( TreeSet < Event > events ) { if ( events == null ) { throw new IllegalArgumentException ( "Events must be not null" ) ; } if ( events . isEmpty ( ) ) { return ; } addEvents ( events ) ; if ( distributed ) { partitionManager . notifyEvents ( new ArrayList < > ( events ) ) ; } } | use synchronized blocks to protect pendingEvents . |
37,817 | private void addFullTrigger ( String tenantId , FullTrigger fullTrigger ) throws Exception { if ( null == fullTrigger ) { throw new IllegalArgumentException ( "FullTrigger must be not null" ) ; } if ( fullTrigger . getTrigger ( ) != null ) { Trigger trigger = fullTrigger . getTrigger ( ) ; trigger . setTenantId ( tenantId ) ; addTrigger ( trigger ) ; if ( ! isEmpty ( fullTrigger . getDampenings ( ) ) ) { for ( Dampening d : fullTrigger . getDampenings ( ) ) { d . setTenantId ( tenantId ) ; d . setTriggerId ( trigger . getId ( ) ) ; addDampening ( d ) ; } } if ( ! isEmpty ( fullTrigger . getConditions ( ) ) ) { setAllConditions ( tenantId , trigger . getId ( ) , fullTrigger . getConditions ( ) ) ; } } } | caller should be deferring notifications |
37,818 | public Map < PartitionEntry , Integer > calculatePartition ( List < PartitionEntry > entries , Map < Integer , Integer > buckets ) { if ( entries == null ) { throw new IllegalArgumentException ( "entries must be not null" ) ; } if ( isEmpty ( buckets ) ) { throw new IllegalArgumentException ( "entries must be not null" ) ; } HashFunction md5 = Hashing . md5 ( ) ; int numBuckets = buckets . size ( ) ; Map < PartitionEntry , Integer > newPartition = new HashMap < > ( ) ; for ( PartitionEntry entry : entries ) { newPartition . put ( entry , buckets . get ( Hashing . consistentHash ( md5 . hashInt ( entry . hashCode ( ) ) , numBuckets ) ) ) ; } return newPartition ; } | Distribute triggers on nodes using a consistent hashing strategy . This strategy allows to scale and minimize changes and re - distribution when cluster changes . |
37,819 | public Integer calculateNewEntry ( PartitionEntry newEntry , Map < Integer , Integer > buckets ) { if ( newEntry == null ) { throw new IllegalArgumentException ( "newEntry must be not null" ) ; } if ( isEmpty ( buckets ) ) { throw new IllegalArgumentException ( "buckets must be not null" ) ; } HashFunction md5 = Hashing . md5 ( ) ; int numBuckets = buckets . size ( ) ; return buckets . get ( Hashing . consistentHash ( md5 . hashInt ( newEntry . hashCode ( ) ) , numBuckets ) ) ; } | Distribute a new entry across buckets using a consistent hashing strategy . |
37,820 | public static boolean validate ( TriggerAction triggerAction , Event event ) { if ( triggerAction == null || event == null ) { return true ; } if ( ( isEmpty ( triggerAction . getStates ( ) ) ) && triggerAction . getCalendar ( ) == null ) { return true ; } if ( event instanceof Alert && triggerAction . getStates ( ) != null && ! triggerAction . getStates ( ) . isEmpty ( ) && ! triggerAction . getStates ( ) . contains ( ( ( Alert ) event ) . getStatus ( ) . name ( ) ) ) { return false ; } if ( triggerAction . getCalendar ( ) != null ) { try { return triggerAction . getCalendar ( ) . isSatisfiedBy ( event . getCtime ( ) ) ; } catch ( Exception e ) { log . debug ( e . getMessage ( ) , e ) ; log . errorCannotValidateAction ( e . getMessage ( ) ) ; } } return true ; } | Validate if an Event should generate an Action based on the constraints defined on a TriggerAction . |
37,821 | public Map < String , String > processTemplate ( ActionMessage msg ) throws Exception { Map < String , String > emailProcessed = new HashMap < > ( ) ; PluginMessageDescription pmDesc = new PluginMessageDescription ( msg ) ; emailProcessed . put ( "emailSubject" , pmDesc . getEmailSubject ( ) ) ; String plain ; String html ; String templateLocale = pmDesc . getProps ( ) != null ? pmDesc . getProps ( ) . get ( EmailPlugin . PROP_TEMPLATE_LOCALE ) : null ; if ( templateLocale != null ) { plain = pmDesc . getProps ( ) . get ( EmailPlugin . PROP_TEMPLATE_PLAIN + "." + templateLocale ) ; html = pmDesc . getProps ( ) . get ( EmailPlugin . PROP_TEMPLATE_HTML + "." + templateLocale ) ; } else { plain = pmDesc . getProps ( ) != null ? pmDesc . getProps ( ) . get ( EmailPlugin . PROP_TEMPLATE_PLAIN ) : null ; html = pmDesc . getProps ( ) != null ? pmDesc . getProps ( ) . get ( EmailPlugin . PROP_TEMPLATE_HTML ) : null ; } StringWriter writerPlain = new StringWriter ( ) ; StringWriter writerHtml = new StringWriter ( ) ; if ( ! isEmpty ( plain ) ) { StringReader plainReader = new StringReader ( plain ) ; ftlTemplate = new Template ( "plainTemplate" , plainReader , ftlCfg ) ; ftlTemplate . process ( pmDesc , writerPlain ) ; } else { ftlTemplatePlain . process ( pmDesc , writerPlain ) ; } if ( ! isEmpty ( html ) ) { StringReader htmlReader = new StringReader ( html ) ; ftlTemplate = new Template ( "htmlTemplate" , htmlReader , ftlCfg ) ; ftlTemplate . process ( pmDesc , writerHtml ) ; } else { ftlTemplateHtml . process ( pmDesc , writerHtml ) ; } writerPlain . flush ( ) ; writerPlain . close ( ) ; emailProcessed . put ( "emailBodyPlain" , writerPlain . toString ( ) ) ; writerHtml . flush ( ) ; writerHtml . close ( ) ; emailProcessed . put ( "emailBodyHtml" , writerHtml . toString ( ) ) ; return emailProcessed ; } | Process a PluginMessage and creates email content based on templates . |
37,822 | private boolean rule1 ( double sample ) { if ( ! hasMean ( ) ) { return false ; } return Math . abs ( sample - mean . getResult ( ) ) > threeDeviations ; } | one point is more than 3 standard deviations from the mean |
37,823 | private boolean rule5 ( double sample ) { if ( ! hasMean ( ) ) { return false ; } if ( rule5LastThree . size ( ) == 3 ) { switch ( rule5LastThree . removeLast ( ) ) { case ">" : -- rule5Above ; break ; case "<" : -- rule5Below ; break ; } } if ( Math . abs ( sample - mean . getResult ( ) ) > twoDeviations ) { if ( sample > mean . getResult ( ) ) { ++ rule5Above ; rule5LastThree . push ( ">" ) ; } else { ++ rule5Below ; rule5LastThree . push ( "<" ) ; } } else { rule5LastThree . push ( "" ) ; } return rule5Above >= 2 || rule5Below >= 2 ; } | At least 2 of 3 points in a row are > 2 standard deviations from the mean in the same direction |
37,824 | private boolean rule6 ( double sample ) { if ( ! hasMean ( ) ) { return false ; } if ( rule6LastFive . size ( ) == 5 ) { switch ( rule6LastFive . removeLast ( ) ) { case ">" : -- rule6Above ; break ; case "<" : -- rule6Below ; break ; } } if ( Math . abs ( sample - mean . getResult ( ) ) > oneDeviation ) { if ( sample > mean . getResult ( ) ) { ++ rule6Above ; rule6LastFive . push ( ">" ) ; } else { ++ rule6Below ; rule6LastFive . push ( "<" ) ; } } else { rule6LastFive . push ( "" ) ; } return rule6Above >= 4 || rule6Below >= 4 ; } | At least 4 of 5 points in a row are > 1 standard deviation from the mean in the same direction |
37,825 | private boolean rule7 ( double sample ) { if ( ! hasMean ( ) ) { return false ; } if ( sample == mean . getResult ( ) ) { rule7Count = 0 ; return false ; } if ( Math . abs ( sample - mean . getResult ( ) ) <= oneDeviation ) { ++ rule7Count ; } else { rule7Count = 0 ; } return rule7Count >= 15 ; } | a very steady metric . Minimally I have taken away the flat - line case where all samples are the mean . |
37,826 | private boolean rule8 ( Double sample ) { if ( ! hasMean ( ) ) { return false ; } if ( Math . abs ( sample - mean . getResult ( ) ) > oneDeviation ) { ++ rule8Count ; } else { rule8Count = 0 ; } return rule8Count >= 8 ; } | and the points are in both directions from the mean |
37,827 | public boolean isDataIdActive ( String tenantId , String dataId ) { return tenantId != null && dataId != null && activeDataIds . contains ( new DataId ( tenantId , dataId ) ) ; } | Check if a specific dataId is active on this node |
37,828 | public void remove ( String tenantId , String triggerId ) { if ( tenantId == null ) { throw new IllegalArgumentException ( "tenantId must be not null" ) ; } if ( triggerId == null ) { throw new IllegalArgumentException ( "triggerId must be not null" ) ; } Set < DataEntry > dataEntriesToRemove = new HashSet < > ( ) ; activeDataEntries . stream ( ) . forEach ( e -> { if ( e . getTenantId ( ) . equals ( tenantId ) && e . getTriggerId ( ) . equals ( triggerId ) ) { dataEntriesToRemove . add ( e ) ; } } ) ; activeDataEntries . removeAll ( dataEntriesToRemove ) ; Set < DataId > dataIdToCheck = new HashSet < > ( ) ; dataEntriesToRemove . stream ( ) . forEach ( e -> { dataIdToCheck . add ( new DataId ( e . getTenantId ( ) , e . getDataId ( ) ) ) ; } ) ; Set < DataId > dataIdToRemove = new HashSet < > ( ) ; dataIdToCheck . stream ( ) . forEach ( dataId -> { boolean found = false ; for ( DataEntry entry : activeDataEntries ) { DataId currentDataId = new DataId ( entry . getTenantId ( ) , entry . getDataId ( ) ) ; if ( currentDataId . equals ( dataId ) ) { found = true ; break ; } } if ( ! found ) { dataIdToRemove . add ( dataId ) ; } } ) ; activeDataIds . removeAll ( dataIdToRemove ) ; } | Remove all DataEntry for a specified trigger . |
37,829 | private void requestCacheUpdate ( ) { log . debug ( "Cache update requested" ) ; if ( updateRequested ) { log . debug ( "Cache update, redundant request ignored." ) ; return ; } updateRequested = true ; if ( ! updating ) { updateCache ( ) ; } } | Just run updateCache one time if multiple requests come in while an update is already in progress ... |
37,830 | public String external ( ExternalCondition condition ) { String description = "AlerterId: " + condition . getAlerterId ( ) ; description += " DataId: " + condition . getDataId ( ) ; description += " Expression: " + condition . getExpression ( ) ; return description ; } | Create a description for an ExternalCondition object . |
37,831 | public String events ( EventCondition condition ) { String description = "event on: " + condition . getDataId ( ) ; if ( condition . getExpression ( ) != null ) { description += " [" + condition . getExpression ( ) + "]" ; } return description ; } | Create a description for an EventCondition object . |
37,832 | public String missing ( MissingCondition condition ) { String description ; if ( condition . getContext ( ) != null && condition . getContext ( ) . get ( CONTEXT_PROPERTY_DESCRIPTION ) != null ) { description = condition . getContext ( ) . get ( CONTEXT_PROPERTY_DESCRIPTION ) ; } else { description = condition . getDataId ( ) ; } description += " not reported for " + condition . getInterval ( ) + "ms" ; return description ; } | Create a description for a MissingCondition object . |
37,833 | public String nelson ( NelsonCondition condition ) { String description ; if ( condition . getContext ( ) != null && condition . getContext ( ) . get ( CONTEXT_PROPERTY_DESCRIPTION ) != null ) { description = condition . getContext ( ) . get ( CONTEXT_PROPERTY_DESCRIPTION ) ; } else { description = condition . getDataId ( ) ; } description += " violates one or the following Nelson rules: " + condition . getActiveRules ( ) ; return description ; } | Create a description for a NelsonCondition object . |
37,834 | public String rate ( RateCondition condition ) { String description ; if ( condition . getContext ( ) != null && condition . getContext ( ) . get ( CONTEXT_PROPERTY_DESCRIPTION ) != null ) { description = condition . getContext ( ) . get ( CONTEXT_PROPERTY_DESCRIPTION ) ; } else { description = condition . getDataId ( ) ; } switch ( condition . getDirection ( ) ) { case DECREASING : description += " decreasing " ; break ; case INCREASING : description += " increasing " ; break ; case NA : break ; default : throw new IllegalArgumentException ( condition . getDirection ( ) . name ( ) ) ; } switch ( condition . getOperator ( ) ) { case GT : description += " greater than " ; break ; case GTE : description += " greater or equal than " ; break ; case LT : description += " less than " ; break ; case LTE : description += " less or equal than " ; break ; default : throw new IllegalArgumentException ( condition . getOperator ( ) . name ( ) ) ; } description += decimalFormat . format ( condition . getThreshold ( ) ) ; if ( condition . getContext ( ) != null && condition . getContext ( ) . get ( CONTEXT_PROPERTY_UNIT ) != null ) { description += " " + condition . getContext ( ) . get ( CONTEXT_PROPERTY_UNIT ) ; } switch ( condition . getPeriod ( ) ) { case DAY : description = " per day " ; break ; case HOUR : description = " per hour " ; break ; case MINUTE : description = " per minute " ; break ; case SECOND : description = " per second " ; break ; case WEEK : description = " per week " ; break ; default : throw new IllegalArgumentException ( condition . getOperator ( ) . name ( ) ) ; } return description ; } | Create a description for a RateCondition object . |
37,835 | private String inClause ( String field , Set < String > values ) { String separator = "" ; StringBuffer sb = new StringBuffer ( " and (" ) ; for ( String v : values ) { sb . append ( separator ) ; sb . append ( String . format ( "%s = '%s'" , field , v ) ) ; separator = " or " ; } sb . append ( ")" ) ; return sb . toString ( ) ; } | An exploded in clause because the actual one seems not to work |
37,836 | public String rfc5988String ( ) { StringBuilder builder = new StringBuilder ( ) ; builder . append ( "<" ) . append ( href ) . append ( ">; rel=\"" ) . append ( rel ) . append ( "\"" ) ; return builder . toString ( ) ; } | Return the link in the format of RFC 5988 Web Linking . |
37,837 | public String cleanWithOutputEncoding ( String input , String outputEncoding ) throws ConversionException { return clean ( input , null , outputEncoding ) ; } | Clean - up HTML code with specified output encoding asumes UTF - 8 as input encoding . |
37,838 | public String cleanWithInputEncoding ( String htmlFile , String inputEncoding ) throws ConversionException { return clean ( htmlFile , inputEncoding , null ) ; } | Clean - up HTML code with specified input encoding asumes UTF - 8 as output encoding . |
37,839 | public String clean ( String input , String inputEncoding , String outputEncoding ) throws ConversionException { InputStream stringAsStream ; try { stringAsStream = new ByteArrayInputStream ( input . getBytes ( inputEncoding != null ? inputEncoding : "UTF-8" ) ) ; } catch ( UnsupportedEncodingException e ) { throw ConversionException . HTML_TO_PDF_EXCEPTION ; } ByteArrayOutputStream outputAsStream = new ByteArrayOutputStream ( ) ; Tidy htmlCleaner = new Tidy ( ) ; htmlCleaner . setInputEncoding ( inputEncoding != null ? inputEncoding : "UTF-8" ) ; htmlCleaner . setOutputEncoding ( outputEncoding != null ? outputEncoding : "UTF-8" ) ; htmlCleaner . setXHTML ( true ) ; htmlCleaner . parse ( stringAsStream , outputAsStream ) ; try { String result = outputAsStream . toString ( outputEncoding != null ? outputEncoding : "UTF-8" ) ; return result . trim ( ) ; } catch ( UnsupportedEncodingException e ) { throw ConversionException . HTML_TO_PDF_EXCEPTION ; } } | Clean - up HTML code with specified input and output encodings . |
37,840 | public static void setCurrent ( Graphics current ) { if ( currentGraphics != current ) { if ( currentGraphics != null ) { currentGraphics . disable ( ) ; } currentGraphics = current ; currentGraphics . enable ( ) ; } } | Set the current graphics context in use |
37,841 | public void setDrawMode ( int mode ) { predraw ( ) ; currentDrawingMode = mode ; if ( currentDrawingMode == MODE_NORMAL ) { GL . glEnable ( SGL . GL_BLEND ) ; GL . glColorMask ( true , true , true , true ) ; GL . glBlendFunc ( SGL . GL_SRC_ALPHA , SGL . GL_ONE_MINUS_SRC_ALPHA ) ; } if ( currentDrawingMode == MODE_ALPHA_MAP ) { GL . glDisable ( SGL . GL_BLEND ) ; GL . glColorMask ( false , false , false , true ) ; } if ( currentDrawingMode == MODE_ALPHA_BLEND ) { GL . glEnable ( SGL . GL_BLEND ) ; GL . glColorMask ( true , true , true , false ) ; GL . glBlendFunc ( SGL . GL_DST_ALPHA , SGL . GL_ONE_MINUS_DST_ALPHA ) ; } if ( currentDrawingMode == MODE_COLOR_MULTIPLY ) { GL . glEnable ( SGL . GL_BLEND ) ; GL . glColorMask ( true , true , true , true ) ; GL . glBlendFunc ( SGL . GL_ONE_MINUS_SRC_COLOR , SGL . GL_SRC_COLOR ) ; } if ( currentDrawingMode == MODE_ADD ) { GL . glEnable ( SGL . GL_BLEND ) ; GL . glColorMask ( true , true , true , true ) ; GL . glBlendFunc ( SGL . GL_ONE , SGL . GL_ONE ) ; } if ( currentDrawingMode == MODE_SCREEN ) { GL . glEnable ( SGL . GL_BLEND ) ; GL . glColorMask ( true , true , true , true ) ; GL . glBlendFunc ( SGL . GL_ONE , SGL . GL_ONE_MINUS_SRC_COLOR ) ; } postdraw ( ) ; } | Set the drawing mode to use . This mode defines how pixels are drawn to the graphics context . It can be used to draw into the alpha map . |
37,842 | public void setBackground ( Color color ) { predraw ( ) ; GL . glClearColor ( color . r , color . g , color . b , color . a ) ; postdraw ( ) ; } | Set the background colour of the graphics context . This colour is used when clearing the context . Note that calling this method alone does not cause the context to be cleared . |
37,843 | public Color getBackground ( ) { predraw ( ) ; FloatBuffer buffer = BufferUtils . createFloatBuffer ( 16 ) ; GL . glGetFloat ( SGL . GL_COLOR_CLEAR_VALUE , buffer ) ; postdraw ( ) ; return new Color ( buffer ) ; } | Get the current graphics context background color |
37,844 | public void resetTransform ( ) { sx = 1 ; sy = 1 ; if ( pushed ) { predraw ( ) ; GL . glPopMatrix ( ) ; pushed = false ; postdraw ( ) ; } } | Reset the transformation on this graphics context |
37,845 | public void scale ( float sx , float sy ) { this . sx = this . sx * sx ; this . sy = this . sy * sy ; checkPush ( ) ; predraw ( ) ; GL . glScalef ( sx , sy , 1 ) ; postdraw ( ) ; } | Apply a scaling factor to everything drawn on the graphics context |
37,846 | public void rotate ( float rx , float ry , float ang ) { checkPush ( ) ; predraw ( ) ; translate ( rx , ry ) ; GL . glRotatef ( ang , 0 , 0 , 1 ) ; translate ( - rx , - ry ) ; postdraw ( ) ; } | Apply a rotation to everything draw on the graphics context |
37,847 | public void translate ( float x , float y ) { checkPush ( ) ; predraw ( ) ; GL . glTranslatef ( x , y , 0 ) ; postdraw ( ) ; } | Apply a translation to everything drawn to the context |
37,848 | public void setColor ( Color color ) { if ( color == null ) { return ; } currentColor = new Color ( color ) ; predraw ( ) ; currentColor . bind ( ) ; postdraw ( ) ; } | Set the color to use when rendering to this context |
37,849 | public void drawLine ( float x1 , float y1 , float x2 , float y2 ) { float lineWidth = this . lineWidth - 1 ; if ( LSR . applyGLLineFixes ( ) ) { if ( x1 == x2 ) { if ( y1 > y2 ) { float temp = y2 ; y2 = y1 ; y1 = temp ; } float step = 1 / sy ; lineWidth = lineWidth / sy ; fillRect ( x1 - ( lineWidth / 2.0f ) , y1 - ( lineWidth / 2.0f ) , lineWidth + step , ( y2 - y1 ) + lineWidth + step ) ; return ; } else if ( y1 == y2 ) { if ( x1 > x2 ) { float temp = x2 ; x2 = x1 ; x1 = temp ; } float step = 1 / sx ; lineWidth = lineWidth / sx ; fillRect ( x1 - ( lineWidth / 2.0f ) , y1 - ( lineWidth / 2.0f ) , ( x2 - x1 ) + lineWidth + step , lineWidth + step ) ; return ; } } predraw ( ) ; currentColor . bind ( ) ; TextureImpl . bindNone ( ) ; LSR . start ( ) ; LSR . vertex ( x1 , y1 ) ; LSR . vertex ( x2 , y2 ) ; LSR . end ( ) ; postdraw ( ) ; } | Draw a line on the canvas in the current colour |
37,850 | public void draw ( Shape shape , ShapeFill fill ) { predraw ( ) ; TextureImpl . bindNone ( ) ; ShapeRenderer . draw ( shape , fill ) ; currentColor . bind ( ) ; postdraw ( ) ; } | Draw the outline of the given shape . |
37,851 | public void drawRect ( float x1 , float y1 , float width , float height ) { float lineWidth = getLineWidth ( ) ; drawLine ( x1 , y1 , x1 + width , y1 ) ; drawLine ( x1 + width , y1 , x1 + width , y1 + height ) ; drawLine ( x1 + width , y1 + height , x1 , y1 + height ) ; drawLine ( x1 , y1 + height , x1 , y1 ) ; } | Draw a rectangle to the canvas in the current colour |
37,852 | public void setWorldClip ( float x , float y , float width , float height ) { predraw ( ) ; worldClipRecord = new Rectangle ( x , y , width , height ) ; GL . glEnable ( SGL . GL_CLIP_PLANE0 ) ; worldClip . put ( 1 ) . put ( 0 ) . put ( 0 ) . put ( - x ) . flip ( ) ; GL . glClipPlane ( SGL . GL_CLIP_PLANE0 , worldClip ) ; GL . glEnable ( SGL . GL_CLIP_PLANE1 ) ; worldClip . put ( - 1 ) . put ( 0 ) . put ( 0 ) . put ( x + width ) . flip ( ) ; GL . glClipPlane ( SGL . GL_CLIP_PLANE1 , worldClip ) ; GL . glEnable ( SGL . GL_CLIP_PLANE2 ) ; worldClip . put ( 0 ) . put ( 1 ) . put ( 0 ) . put ( - y ) . flip ( ) ; GL . glClipPlane ( SGL . GL_CLIP_PLANE2 , worldClip ) ; GL . glEnable ( SGL . GL_CLIP_PLANE3 ) ; worldClip . put ( 0 ) . put ( - 1 ) . put ( 0 ) . put ( y + height ) . flip ( ) ; GL . glClipPlane ( SGL . GL_CLIP_PLANE3 , worldClip ) ; postdraw ( ) ; } | Set clipping that controls which areas of the world will be drawn to . Note that world clip is different from standard screen clip in that it s defined in the space of the current world coordinate - i . e . it s affected by translate rotate scale etc . |
37,853 | public void clearWorldClip ( ) { predraw ( ) ; worldClipRecord = null ; GL . glDisable ( SGL . GL_CLIP_PLANE0 ) ; GL . glDisable ( SGL . GL_CLIP_PLANE1 ) ; GL . glDisable ( SGL . GL_CLIP_PLANE2 ) ; GL . glDisable ( SGL . GL_CLIP_PLANE3 ) ; postdraw ( ) ; } | Clear world clipping setup . This does not effect screen clipping |
37,854 | public void setWorldClip ( Rectangle clip ) { if ( clip == null ) { clearWorldClip ( ) ; } else { setWorldClip ( clip . getX ( ) , clip . getY ( ) , clip . getWidth ( ) , clip . getHeight ( ) ) ; } } | Set the world clip to be applied |
37,855 | public void fillRect ( float x , float y , float width , float height , Image pattern , float offX , float offY ) { int cols = ( ( int ) Math . ceil ( width / pattern . getWidth ( ) ) ) + 2 ; int rows = ( ( int ) Math . ceil ( height / pattern . getHeight ( ) ) ) + 2 ; Rectangle preClip = getWorldClip ( ) ; setWorldClip ( x , y , width , height ) ; predraw ( ) ; for ( int c = 0 ; c < cols ; c ++ ) { for ( int r = 0 ; r < rows ; r ++ ) { pattern . draw ( c * pattern . getWidth ( ) + x - offX , r * pattern . getHeight ( ) + y - offY ) ; } } postdraw ( ) ; setWorldClip ( preClip ) ; } | Tile a rectangle with a pattern specifing the offset from the top corner that one tile should match |
37,856 | public void fillRect ( float x1 , float y1 , float width , float height ) { predraw ( ) ; TextureImpl . bindNone ( ) ; currentColor . bind ( ) ; GL . glBegin ( SGL . GL_QUADS ) ; GL . glVertex2f ( x1 , y1 ) ; GL . glVertex2f ( x1 + width , y1 ) ; GL . glVertex2f ( x1 + width , y1 + height ) ; GL . glVertex2f ( x1 , y1 + height ) ; GL . glEnd ( ) ; postdraw ( ) ; } | Fill a rectangle on the canvas in the current color |
37,857 | public void setLineWidth ( float width ) { predraw ( ) ; this . lineWidth = width ; LSR . setWidth ( width ) ; GL . glPointSize ( width ) ; postdraw ( ) ; } | Set the with of the line to be used when drawing line based primitives |
37,858 | public void resetLineWidth ( ) { predraw ( ) ; Renderer . getLineStripRenderer ( ) . setWidth ( 1.0f ) ; GL . glLineWidth ( 1.0f ) ; GL . glPointSize ( 1.0f ) ; postdraw ( ) ; } | Reset the line width in use to the default for this graphics context |
37,859 | public void setAntiAlias ( boolean anti ) { predraw ( ) ; antialias = anti ; LSR . setAntiAlias ( anti ) ; if ( anti ) { GL . glEnable ( SGL . GL_POLYGON_SMOOTH ) ; } else { GL . glDisable ( SGL . GL_POLYGON_SMOOTH ) ; } postdraw ( ) ; } | Indicate if we should antialias as we draw primitives |
37,860 | public void drawString ( String str , float x , float y ) { predraw ( ) ; font . drawString ( x , y , str , currentColor ) ; postdraw ( ) ; } | Draw a string to the screen using the current font |
37,861 | public void copyArea ( Image target , int x , int y ) { int format = target . getTexture ( ) . hasAlpha ( ) ? SGL . GL_RGBA : SGL . GL_RGB ; target . bind ( ) ; GL . glCopyTexImage2D ( SGL . GL_TEXTURE_2D , 0 , format , x , screenHeight - ( y + target . getHeight ( ) ) , target . getTexture ( ) . getTextureWidth ( ) , target . getTexture ( ) . getTextureHeight ( ) , 0 ) ; target . ensureInverted ( ) ; } | Copy an area of the rendered screen into an image . The width and height of the area are assumed to match that of the image |
37,862 | public Color getPixel ( int x , int y ) { predraw ( ) ; GL . glReadPixels ( x , screenHeight - y , 1 , 1 , SGL . GL_RGBA , SGL . GL_UNSIGNED_BYTE , readBuffer ) ; postdraw ( ) ; return new Color ( translate ( readBuffer . get ( 0 ) ) , translate ( readBuffer . get ( 1 ) ) , translate ( readBuffer . get ( 2 ) ) , translate ( readBuffer . get ( 3 ) ) ) ; } | Get the colour of a single pixel in this graphics context |
37,863 | public void getArea ( int x , int y , int width , int height , ByteBuffer target ) { if ( target . capacity ( ) < width * height * 4 ) { throw new IllegalArgumentException ( "Byte buffer provided to get area is not big enough" ) ; } predraw ( ) ; GL . glReadPixels ( x , screenHeight - y - height , width , height , SGL . GL_RGBA , SGL . GL_UNSIGNED_BYTE , target ) ; postdraw ( ) ; } | Get an ara of pixels as RGBA values into a buffer |
37,864 | public void popTransform ( ) { if ( stackIndex == 0 ) { throw new RuntimeException ( "Attempt to pop a transform that hasn't be pushed" ) ; } predraw ( ) ; stackIndex -- ; FloatBuffer oldBuffer = ( FloatBuffer ) stack . get ( stackIndex ) ; GL . glLoadMatrix ( oldBuffer ) ; sx = oldBuffer . get ( 16 ) ; sy = oldBuffer . get ( 17 ) ; postdraw ( ) ; } | Pop a previously pushed transform from the stack to the current . This should only be called if a transform has been previously pushed . |
37,865 | public int getLayerIndex ( String name ) { int idx = 0 ; for ( int i = 0 ; i < layers . size ( ) ; i ++ ) { Layer layer = ( Layer ) layers . get ( i ) ; if ( layer . name . equals ( name ) ) { return i ; } } return - 1 ; } | Get the index of the layer with given name |
37,866 | public Image getTileImage ( int x , int y , int layerIndex ) { Layer layer = ( Layer ) layers . get ( layerIndex ) ; int tileSetIndex = layer . data [ x ] [ y ] [ 0 ] ; if ( ( tileSetIndex >= 0 ) && ( tileSetIndex < tileSets . size ( ) ) ) { TileSet tileSet = ( TileSet ) tileSets . get ( tileSetIndex ) ; int sheetX = tileSet . getTileX ( layer . data [ x ] [ y ] [ 1 ] ) ; int sheetY = tileSet . getTileY ( layer . data [ x ] [ y ] [ 1 ] ) ; return tileSet . tiles . getSprite ( sheetX , sheetY ) ; } return null ; } | Gets the Image used to draw the tile at the given x and y coordinates . |
37,867 | public int getTileId ( int x , int y , int layerIndex ) { Layer layer = ( Layer ) layers . get ( layerIndex ) ; return layer . getTileID ( x , y ) ; } | Get the global ID of a tile at specified location in the map |
37,868 | public void setTileId ( int x , int y , int layerIndex , int tileid ) { Layer layer = ( Layer ) layers . get ( layerIndex ) ; layer . setTileID ( x , y , tileid ) ; } | Set the global ID of a tile at specified location in the map |
37,869 | public String getMapProperty ( String propertyName , String def ) { if ( props == null ) return def ; return props . getProperty ( propertyName , def ) ; } | Get a property given to the map . Note that this method will not perform well and should not be used as part of the default code path in the game loop . |
37,870 | public String getLayerProperty ( int layerIndex , String propertyName , String def ) { Layer layer = ( Layer ) layers . get ( layerIndex ) ; if ( layer == null || layer . props == null ) return def ; return layer . props . getProperty ( propertyName , def ) ; } | Get a property given to a particular layer . Note that this method will not perform well and should not be used as part of the default code path in the game loop . |
37,871 | public String getTileProperty ( int tileID , String propertyName , String def ) { if ( tileID == 0 ) { return def ; } TileSet set = findTileSet ( tileID ) ; Properties props = set . getProperties ( tileID ) ; if ( props == null ) { return def ; } return props . getProperty ( propertyName , def ) ; } | Get a propety given to a particular tile . Note that this method will not perform well and should not be used as part of the default code path in the game loop . |
37,872 | public void render ( int x , int y , int layer ) { render ( x , y , 0 , 0 , getWidth ( ) , getHeight ( ) , layer , false ) ; } | Render a single layer from the map |
37,873 | protected void renderIsometricMap ( int x , int y , int sx , int sy , int width , int height , Layer layer , boolean lineByLine ) { ArrayList drawLayers = layers ; if ( layer != null ) { drawLayers = new ArrayList ( ) ; drawLayers . add ( layer ) ; } int maxCount = width * height ; int allCount = 0 ; boolean allProcessed = false ; int initialLineX = x ; int initialLineY = y ; int startLineTileX = 0 ; int startLineTileY = 0 ; while ( ! allProcessed ) { int currentTileX = startLineTileX ; int currentTileY = startLineTileY ; int currentLineX = initialLineX ; int min = 0 ; if ( height > width ) min = ( startLineTileY < width - 1 ) ? startLineTileY : ( width - currentTileX < height ) ? width - currentTileX - 1 : width - 1 ; else min = ( startLineTileY < height - 1 ) ? startLineTileY : ( width - currentTileX < height ) ? width - currentTileX - 1 : height - 1 ; for ( int burner = 0 ; burner <= min ; currentTileX ++ , currentTileY -- , burner ++ ) { for ( int layerIdx = 0 ; layerIdx < drawLayers . size ( ) ; layerIdx ++ ) { Layer currentLayer = ( Layer ) drawLayers . get ( layerIdx ) ; currentLayer . render ( currentLineX , initialLineY , currentTileX , currentTileY , 1 , 0 , lineByLine , tileWidth , tileHeight ) ; } currentLineX += tileWidth ; allCount ++ ; } if ( startLineTileY < ( height - 1 ) ) { startLineTileY += 1 ; initialLineX -= tileWidth / 2 ; initialLineY += tileHeight / 2 ; } else { startLineTileX += 1 ; initialLineX += tileWidth / 2 ; initialLineY += tileHeight / 2 ; } if ( allCount >= maxCount ) allProcessed = true ; } } | Render of isometric map renders . |
37,874 | public TileSet getTileSetByGID ( int gid ) { for ( int i = 0 ; i < tileSets . size ( ) ; i ++ ) { TileSet set = ( TileSet ) tileSets . get ( i ) ; if ( set . contains ( gid ) ) { return set ; } } return null ; } | Get a tileset by a given global ID |
37,875 | public int getObjectCount ( int groupID ) { if ( groupID >= 0 && groupID < objectGroups . size ( ) ) { ObjectGroup grp = ( ObjectGroup ) objectGroups . get ( groupID ) ; return grp . objects . size ( ) ; } return - 1 ; } | Returns the number of objects of a specific object - group . |
37,876 | public String getObjectName ( int groupID , int objectID ) { if ( groupID >= 0 && groupID < objectGroups . size ( ) ) { ObjectGroup grp = ( ObjectGroup ) objectGroups . get ( groupID ) ; if ( objectID >= 0 && objectID < grp . objects . size ( ) ) { GroupObject object = ( GroupObject ) grp . objects . get ( objectID ) ; return object . name ; } } return null ; } | Return the name of a specific object from a specific group . |
37,877 | public String getObjectType ( int groupID , int objectID ) { if ( groupID >= 0 && groupID < objectGroups . size ( ) ) { ObjectGroup grp = ( ObjectGroup ) objectGroups . get ( groupID ) ; if ( objectID >= 0 && objectID < grp . objects . size ( ) ) { GroupObject object = ( GroupObject ) grp . objects . get ( objectID ) ; return object . type ; } } return null ; } | Return the type of an specific object from a specific group . |
37,878 | public int getObjectX ( int groupID , int objectID ) { if ( groupID >= 0 && groupID < objectGroups . size ( ) ) { ObjectGroup grp = ( ObjectGroup ) objectGroups . get ( groupID ) ; if ( objectID >= 0 && objectID < grp . objects . size ( ) ) { GroupObject object = ( GroupObject ) grp . objects . get ( objectID ) ; return object . x ; } } return - 1 ; } | Returns the x - coordinate of a specific object from a specific group . |
37,879 | public int getObjectY ( int groupID , int objectID ) { if ( groupID >= 0 && groupID < objectGroups . size ( ) ) { ObjectGroup grp = ( ObjectGroup ) objectGroups . get ( groupID ) ; if ( objectID >= 0 && objectID < grp . objects . size ( ) ) { GroupObject object = ( GroupObject ) grp . objects . get ( objectID ) ; return object . y ; } } return - 1 ; } | Returns the y - coordinate of a specific object from a specific group . |
37,880 | public int getObjectWidth ( int groupID , int objectID ) { if ( groupID >= 0 && groupID < objectGroups . size ( ) ) { ObjectGroup grp = ( ObjectGroup ) objectGroups . get ( groupID ) ; if ( objectID >= 0 && objectID < grp . objects . size ( ) ) { GroupObject object = ( GroupObject ) grp . objects . get ( objectID ) ; return object . width ; } } return - 1 ; } | Returns the width of a specific object from a specific group . |
37,881 | public int getObjectHeight ( int groupID , int objectID ) { if ( groupID >= 0 && groupID < objectGroups . size ( ) ) { ObjectGroup grp = ( ObjectGroup ) objectGroups . get ( groupID ) ; if ( objectID >= 0 && objectID < grp . objects . size ( ) ) { GroupObject object = ( GroupObject ) grp . objects . get ( objectID ) ; return object . height ; } } return - 1 ; } | Returns the height of a specific object from a specific group . |
37,882 | public String getObjectImage ( int groupID , int objectID ) { if ( groupID >= 0 && groupID < objectGroups . size ( ) ) { ObjectGroup grp = ( ObjectGroup ) objectGroups . get ( groupID ) ; if ( objectID >= 0 && objectID < grp . objects . size ( ) ) { GroupObject object = ( GroupObject ) grp . objects . get ( objectID ) ; if ( object == null ) { return null ; } return object . image ; } } return null ; } | Retrieve the image source property for a given object |
37,883 | public String getObjectProperty ( int groupID , int objectID , String propertyName , String def ) { if ( groupID >= 0 && groupID < objectGroups . size ( ) ) { ObjectGroup grp = ( ObjectGroup ) objectGroups . get ( groupID ) ; if ( objectID >= 0 && objectID < grp . objects . size ( ) ) { GroupObject object = ( GroupObject ) grp . objects . get ( objectID ) ; if ( object == null ) { return def ; } if ( object . props == null ) { return def ; } return object . props . getProperty ( propertyName , def ) ; } } return def ; } | Looks for a property with the given name and returns it s value . If no property is found def is returned . |
37,884 | private static Element getFirstNamedElement ( Element element , String name ) { NodeList list = element . getElementsByTagName ( name ) ; if ( list . getLength ( ) == 0 ) { return null ; } return ( Element ) list . item ( 0 ) ; } | Get the first child named as specified from the passed XML element |
37,885 | private static Element createRangeElement ( Document document , String name , ConfigurableEmitter . Range range ) { Element element = document . createElement ( name ) ; element . setAttribute ( "min" , "" + range . getMin ( ) ) ; element . setAttribute ( "max" , "" + range . getMax ( ) ) ; element . setAttribute ( "enabled" , "" + range . isEnabled ( ) ) ; return element ; } | Create an XML element based on a configured range |
37,886 | private static Element createValueElement ( Document document , String name , ConfigurableEmitter . Value value ) { Element element = document . createElement ( name ) ; if ( value instanceof SimpleValue ) { element . setAttribute ( "type" , "simple" ) ; element . setAttribute ( "value" , "" + value . getValue ( 0 ) ) ; } else if ( value instanceof RandomValue ) { element . setAttribute ( "type" , "random" ) ; element . setAttribute ( "value" , "" + ( ( RandomValue ) value ) . getValue ( ) ) ; } else if ( value instanceof LinearInterpolator ) { element . setAttribute ( "type" , "linear" ) ; element . setAttribute ( "min" , "" + ( ( LinearInterpolator ) value ) . getMin ( ) ) ; element . setAttribute ( "max" , "" + ( ( LinearInterpolator ) value ) . getMax ( ) ) ; element . setAttribute ( "active" , "" + ( ( LinearInterpolator ) value ) . isActive ( ) ) ; ArrayList curve = ( ( LinearInterpolator ) value ) . getCurve ( ) ; for ( int i = 0 ; i < curve . size ( ) ; i ++ ) { Vector2f point = ( Vector2f ) curve . get ( i ) ; Element pointElement = document . createElement ( "point" ) ; pointElement . setAttribute ( "x" , "" + point . x ) ; pointElement . setAttribute ( "y" , "" + point . y ) ; element . appendChild ( pointElement ) ; } } else { Log . warn ( "unkown value type ignored: " + value . getClass ( ) ) ; } return element ; } | Create an XML element based on a configured value |
37,887 | private static void parseRangeElement ( Element element , ConfigurableEmitter . Range range ) { if ( element == null ) { return ; } range . setMin ( Float . parseFloat ( element . getAttribute ( "min" ) ) ) ; range . setMax ( Float . parseFloat ( element . getAttribute ( "max" ) ) ) ; range . setEnabled ( "true" . equals ( element . getAttribute ( "enabled" ) ) ) ; } | Parse an XML element into a configured range |
37,888 | private static void parseValueElement ( Element element , ConfigurableEmitter . Value value ) { if ( element == null ) { return ; } String type = element . getAttribute ( "type" ) ; String v = element . getAttribute ( "value" ) ; if ( type == null || type . length ( ) == 0 ) { if ( value instanceof SimpleValue ) { ( ( SimpleValue ) value ) . setValue ( Float . parseFloat ( v ) ) ; } else if ( value instanceof RandomValue ) { ( ( RandomValue ) value ) . setValue ( Float . parseFloat ( v ) ) ; } else { Log . warn ( "problems reading element, skipping: " + element ) ; } } else { if ( type . equals ( "simple" ) ) { ( ( SimpleValue ) value ) . setValue ( Float . parseFloat ( v ) ) ; } else if ( type . equals ( "random" ) ) { ( ( RandomValue ) value ) . setValue ( Float . parseFloat ( v ) ) ; } else if ( type . equals ( "linear" ) ) { String min = element . getAttribute ( "min" ) ; String max = element . getAttribute ( "max" ) ; String active = element . getAttribute ( "active" ) ; NodeList points = element . getElementsByTagName ( "point" ) ; ArrayList curve = new ArrayList ( ) ; for ( int i = 0 ; i < points . getLength ( ) ; i ++ ) { Element point = ( Element ) points . item ( i ) ; float x = Float . parseFloat ( point . getAttribute ( "x" ) ) ; float y = Float . parseFloat ( point . getAttribute ( "y" ) ) ; curve . add ( new Vector2f ( x , y ) ) ; } ( ( LinearInterpolator ) value ) . setCurve ( curve ) ; ( ( LinearInterpolator ) value ) . setMin ( Integer . parseInt ( min ) ) ; ( ( LinearInterpolator ) value ) . setMax ( Integer . parseInt ( max ) ) ; ( ( LinearInterpolator ) value ) . setActive ( "true" . equals ( active ) ) ; } else { Log . warn ( "unkown type detected: " + type ) ; } } } | Parse an XML element into a configured value |
37,889 | public NavMesh build ( TileBasedMap map , boolean tileBased ) { this . tileBased = tileBased ; ArrayList spaces = new ArrayList ( ) ; if ( tileBased ) { for ( int x = 0 ; x < map . getWidthInTiles ( ) ; x ++ ) { for ( int y = 0 ; y < map . getHeightInTiles ( ) ; y ++ ) { if ( ! map . blocked ( this , x , y ) ) { spaces . add ( new Space ( x , y , 1 , 1 ) ) ; } } } } else { Space space = new Space ( 0 , 0 , map . getWidthInTiles ( ) , map . getHeightInTiles ( ) ) ; subsection ( map , space , spaces ) ; } while ( mergeSpaces ( spaces ) ) { } linkSpaces ( spaces ) ; return new NavMesh ( spaces ) ; } | Build a navigation mesh based on a tile map |
37,890 | private boolean mergeSpaces ( ArrayList spaces ) { for ( int source = 0 ; source < spaces . size ( ) ; source ++ ) { Space a = ( Space ) spaces . get ( source ) ; for ( int target = source + 1 ; target < spaces . size ( ) ; target ++ ) { Space b = ( Space ) spaces . get ( target ) ; if ( a . canMerge ( b ) ) { spaces . remove ( a ) ; spaces . remove ( b ) ; spaces . add ( a . merge ( b ) ) ; return true ; } } } return false ; } | Merge the spaces that have been created to optimize out anywhere we can . |
37,891 | private void linkSpaces ( ArrayList spaces ) { for ( int source = 0 ; source < spaces . size ( ) ; source ++ ) { Space a = ( Space ) spaces . get ( source ) ; for ( int target = source + 1 ; target < spaces . size ( ) ; target ++ ) { Space b = ( Space ) spaces . get ( target ) ; if ( a . hasJoinedEdge ( b ) ) { a . link ( b ) ; b . link ( a ) ; } } } } | Determine the links between spaces |
37,892 | public boolean clear ( TileBasedMap map , Space space ) { if ( tileBased ) { return true ; } float x = 0 ; boolean donex = false ; while ( x < space . getWidth ( ) ) { float y = 0 ; boolean doney = false ; while ( y < space . getHeight ( ) ) { sx = ( int ) ( space . getX ( ) + x ) ; sy = ( int ) ( space . getY ( ) + y ) ; if ( map . blocked ( this , sx , sy ) ) { return false ; } y += 0.1f ; if ( ( y > space . getHeight ( ) ) && ( ! doney ) ) { y = space . getHeight ( ) ; doney = true ; } } x += 0.1f ; if ( ( x > space . getWidth ( ) ) && ( ! donex ) ) { x = space . getWidth ( ) ; donex = true ; } } return true ; } | Check if a particular space is clear of blockages |
37,893 | private void subsection ( TileBasedMap map , Space space , ArrayList spaces ) { if ( ! clear ( map , space ) ) { float width2 = space . getWidth ( ) / 2 ; float height2 = space . getHeight ( ) / 2 ; if ( ( width2 < smallestSpace ) && ( height2 < smallestSpace ) ) { return ; } subsection ( map , new Space ( space . getX ( ) , space . getY ( ) , width2 , height2 ) , spaces ) ; subsection ( map , new Space ( space . getX ( ) , space . getY ( ) + height2 , width2 , height2 ) , spaces ) ; subsection ( map , new Space ( space . getX ( ) + width2 , space . getY ( ) , width2 , height2 ) , spaces ) ; subsection ( map , new Space ( space . getX ( ) + width2 , space . getY ( ) + height2 , width2 , height2 ) , spaces ) ; } else { spaces . add ( space ) ; } } | Subsection a space into smaller spaces if required to find a non - blocked area . |
37,894 | public void setPosition ( int x , int y ) { int cx = ( xoffset . getMin ( ) + xoffset . getMax ( ) ) / 2 ; int cy = ( yoffset . getMin ( ) + yoffset . getMax ( ) ) / 2 ; int dx = x - cx ; int dy = y - cy ; xoffset . setMin ( xoffset . getMin ( ) + dx ) ; xoffset . setMax ( xoffset . getMax ( ) + dx ) ; yoffset . setMin ( yoffset . getMin ( ) + dy ) ; yoffset . setMax ( yoffset . getMax ( ) + dy ) ; xoffset . fireUpdated ( null ) ; yoffset . fireUpdated ( null ) ; } | Set the position of the emitter |
37,895 | public void start ( ) throws SlickException { SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { try { Input . disableControllers ( ) ; try { Display . setParent ( CanvasGameContainer . this ) ; } catch ( LWJGLException e ) { throw new SlickException ( "Failed to setParent of canvas" , e ) ; } container . setup ( ) ; scheduleUpdate ( ) ; } catch ( SlickException e ) { e . printStackTrace ( ) ; System . exit ( 0 ) ; } } } ) ; } | Start the game container rendering |
37,896 | private void scheduleUpdate ( ) { if ( ! isVisible ( ) ) { return ; } SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { try { container . gameLoop ( ) ; } catch ( SlickException e ) { e . printStackTrace ( ) ; } container . checkDimensions ( ) ; scheduleUpdate ( ) ; } } ) ; } | Schedule an update on the EDT |
37,897 | public float distance2 ( float tx , float ty ) { float dx = tx - px ; float dy = ty - py ; return ( ( dx * dx ) + ( dy * dy ) ) ; } | Get the distance squared from this link to the given position |
37,898 | public void renderLines ( float [ ] points , int count ) { if ( antialias ) { GL . glEnable ( SGL . GL_POLYGON_SMOOTH ) ; renderLinesImpl ( points , count , width + 1f ) ; } GL . glDisable ( SGL . GL_POLYGON_SMOOTH ) ; renderLinesImpl ( points , count , width ) ; if ( antialias ) { GL . glEnable ( SGL . GL_POLYGON_SMOOTH ) ; } } | Render the lines applying antialiasing if required |
37,899 | private void bindColor ( int index ) { if ( index < cpt ) { if ( renderHalf ) { GL . glColor4f ( colours [ ( index * 4 ) ] * 0.5f , colours [ ( index * 4 ) + 1 ] * 0.5f , colours [ ( index * 4 ) + 2 ] * 0.5f , colours [ ( index * 4 ) + 3 ] * 0.5f ) ; } else { GL . glColor4f ( colours [ ( index * 4 ) ] , colours [ ( index * 4 ) + 1 ] , colours [ ( index * 4 ) + 2 ] , colours [ ( index * 4 ) + 3 ] ) ; } } } | Bind the colour at a given index in the array |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.