idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
38,100
void setMOD ( MODSound sound ) { if ( ! soundWorks ) { return ; } currentMusic = sources . get ( 0 ) ; stopSource ( 0 ) ; this . mod = sound ; if ( sound != null ) { this . stream = null ; } paused = false ; }
Set the mod thats being streamed if any
38,101
void setStream ( OpenALStreamPlayer stream ) { if ( ! soundWorks ) { return ; } currentMusic = sources . get ( 0 ) ; this . stream = stream ; if ( stream != null ) { this . mod = null ; } paused = false ; }
Set the stream being played
38,102
public void poll ( int delta ) { if ( ! soundWorks ) { return ; } if ( paused ) { return ; } if ( music ) { if ( mod != null ) { try { mod . poll ( ) ; } catch ( OpenALException e ) { Log . error ( "Error with OpenGL MOD Player on this this platform" ) ; Log . error ( e ) ; mod = null ; } } if ( stream != null ) { try { stream . update ( ) ; } catch ( OpenALException e ) { Log . error ( "Error with OpenGL Streaming Player on this this platform" ) ; Log . error ( e ) ; mod = null ; } } } }
Poll the streaming system
38,103
public boolean isMusicPlaying ( ) { if ( ! soundWorks ) { return false ; } int state = AL10 . alGetSourcei ( sources . get ( 0 ) , AL10 . AL_SOURCE_STATE ) ; return ( ( state == AL10 . AL_PLAYING ) || ( state == AL10 . AL_PAUSED ) ) ; }
Check if the music is currently playing
38,104
protected void addValue ( String name , ValuePanel valuePanel ) { named . put ( name , valuePanel ) ; valuePanel . setBounds ( 0 , 10 + yPos , 280 , 63 ) ; valuePanel . addListener ( this ) ; add ( valuePanel ) ; yPos += 63 ; }
Add a configurable value to the mapping table
38,105
protected void addMinMax ( String name , MinMaxPanel minMax ) { named . put ( name , minMax ) ; minMax . setBounds ( 0 , 10 + yPos , 280 , minMax . getOffset ( ) ) ; minMax . addListener ( this ) ; add ( minMax ) ; yPos += minMax . getOffset ( ) ; }
Add a configurable range panel to the mapping table
38,106
protected void link ( Range range , String name ) { link ( range , ( MinMaxPanel ) named . get ( name ) ) ; }
Link a emitter configurable range to a named component
38,107
protected void link ( Value value , String name ) { link ( value , ( ValuePanel ) named . get ( name ) ) ; }
Link a emitter configurable value to a named component
38,108
private void link ( Value value , ValuePanel panel ) { controlToData . put ( panel , value ) ; if ( value instanceof SimpleValue ) panel . setValue ( ( int ) ( ( SimpleValue ) value ) . getValue ( 0 ) ) ; else if ( value instanceof RandomValue ) panel . setValue ( ( int ) ( ( RandomValue ) value ) . getValue ( ) ) ; }
Link a emitter configurable value to a value panel
38,109
private void link ( Range range , MinMaxPanel panel ) { controlToData . put ( panel , range ) ; panel . setMax ( ( int ) range . getMax ( ) ) ; panel . setMin ( ( int ) range . getMin ( ) ) ; panel . setEnabledValue ( range . isEnabled ( ) ) ; }
Link a emitter configurable range to a value panel
38,110
public BufferedImage getScaledImage ( ) { RawScale3x scaler = new RawScale3x ( srcData , width , height ) ; BufferedImage image = new BufferedImage ( width * 3 , height * 3 , BufferedImage . TYPE_INT_ARGB ) ; image . setRGB ( 0 , 0 , width * 3 , height * 3 , scaler . getScaledData ( ) , 0 , width * 3 ) ; return image ; }
Retrieve the scaled image . Note this is the method that actually does the work so it may take some time to return
38,111
public static void main ( String argv [ ] ) { String srcFile = "randam_orig.png" ; try { System . out . println ( "Reading: " + srcFile ) ; BufferedImage src = ImageIO . read ( new File ( srcFile ) ) ; ImageScale3x scaler = new ImageScale3x ( src ) ; BufferedImage out = scaler . getScaledImage ( ) ; String outFile = srcFile . substring ( 0 , srcFile . length ( ) - 4 ) ; outFile += "3x" ; outFile += ".png" ; System . out . println ( "Writing: " + outFile ) ; ImageIO . write ( out , "PNG" , new File ( outFile ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } }
An entry point and a bit of test code
38,112
private static float findSignedDistance ( final int pointX , final int pointY , BufferedImage inImage , final int scanWidth , final int scanHeight ) { Color baseColour = new Color ( inImage . getRGB ( pointX , pointY ) ) ; final boolean baseIsSolid = baseColour . getRed ( ) > 0 ; float closestDistance = Float . MAX_VALUE ; boolean closestValid = false ; final int startX = pointX - ( scanWidth / 2 ) ; final int endX = startX + scanWidth ; final int startY = pointY - ( scanHeight / 2 ) ; final int endY = startY + scanHeight ; for ( int x = startX ; x < endX ; x ++ ) { if ( x < 0 || x >= inImage . getWidth ( ) ) continue ; for ( int y = startY ; y < endY ; y ++ ) { if ( y < 0 || y >= inImage . getWidth ( ) ) continue ; Color c = new Color ( inImage . getRGB ( x , y ) ) ; if ( baseIsSolid ) { if ( c . getRed ( ) == 0 ) { final float dist = separation ( pointX , pointY , x , y ) ; if ( dist < closestDistance ) { closestDistance = dist ; closestValid = true ; } } } else { if ( c . getRed ( ) > 0 ) { final float dist = separation ( pointX , pointY , x , y ) ; if ( dist < closestDistance ) { closestDistance = dist ; closestValid = true ; } } } } } if ( baseIsSolid ) { if ( closestValid ) return closestDistance ; else return Float . MAX_VALUE ; } else { if ( closestValid ) return - closestDistance ; else return Float . MIN_VALUE ; } }
Find the signed distance for a given point
38,113
public void save ( File file ) throws IOException { PrintStream out = new PrintStream ( new FileOutputStream ( file ) ) ; out . println ( "font.size=" + fontSize ) ; out . println ( "font.bold=" + bold ) ; out . println ( "font.italic=" + italic ) ; out . println ( ) ; out . println ( "pad.top=" + paddingTop ) ; out . println ( "pad.right=" + paddingRight ) ; out . println ( "pad.bottom=" + paddingBottom ) ; out . println ( "pad.left=" + paddingLeft ) ; out . println ( "pad.advance.x=" + paddingAdvanceX ) ; out . println ( "pad.advance.y=" + paddingAdvanceY ) ; out . println ( ) ; out . println ( "glyph.page.width=" + glyphPageWidth ) ; out . println ( "glyph.page.height=" + glyphPageHeight ) ; out . println ( ) ; for ( Iterator iter = effects . iterator ( ) ; iter . hasNext ( ) ; ) { ConfigurableEffect effect = ( ConfigurableEffect ) iter . next ( ) ; out . println ( "effect.class=" + effect . getClass ( ) . getName ( ) ) ; for ( Iterator iter2 = effect . getValues ( ) . iterator ( ) ; iter2 . hasNext ( ) ; ) { Value value = ( Value ) iter2 . next ( ) ; out . println ( "effect." + value . getName ( ) + "=" + value . getString ( ) ) ; } out . println ( ) ; } out . close ( ) ; }
Saves the settings to a file .
38,114
private void flushBuffer ( ) { if ( vertIndex == 0 ) { return ; } if ( currentType == NONE ) { return ; } if ( vertIndex < TOLERANCE ) { GL11 . glBegin ( currentType ) ; for ( int i = 0 ; i < vertIndex ; i ++ ) { GL11 . glColor4f ( cols [ ( i * 4 ) + 0 ] , cols [ ( i * 4 ) + 1 ] , cols [ ( i * 4 ) + 2 ] , cols [ ( i * 4 ) + 3 ] ) ; GL11 . glTexCoord2f ( texs [ ( i * 2 ) + 0 ] , texs [ ( i * 2 ) + 1 ] ) ; GL11 . glVertex3f ( verts [ ( i * 3 ) + 0 ] , verts [ ( i * 3 ) + 1 ] , verts [ ( i * 3 ) + 2 ] ) ; } GL11 . glEnd ( ) ; currentType = NONE ; return ; } vertices . clear ( ) ; colors . clear ( ) ; textures . clear ( ) ; vertices . put ( verts , 0 , vertIndex * 3 ) ; colors . put ( cols , 0 , vertIndex * 4 ) ; textures . put ( texs , 0 , vertIndex * 2 ) ; vertices . flip ( ) ; colors . flip ( ) ; textures . flip ( ) ; GL11 . glVertexPointer ( 3 , 0 , vertices ) ; GL11 . glColorPointer ( 4 , 0 , colors ) ; GL11 . glTexCoordPointer ( 2 , 0 , textures ) ; GL11 . glDrawArrays ( currentType , 0 , vertIndex ) ; currentType = NONE ; }
Flush the currently cached data down to the card
38,115
private void applyBuffer ( ) { if ( listMode > 0 ) { return ; } if ( vertIndex != 0 ) { flushBuffer ( ) ; startBuffer ( ) ; } super . glColor4f ( color [ 0 ] , color [ 1 ] , color [ 2 ] , color [ 3 ] ) ; }
Apply the current buffer and restart it
38,116
private boolean isSplittable ( int count , int type ) { switch ( type ) { case GL11 . GL_QUADS : return count % 4 == 0 ; case GL11 . GL_TRIANGLES : return count % 3 == 0 ; case GL11 . GL_LINE : return count % 2 == 0 ; } return false ; }
Check if the geometry being created can be split at the current index
38,117
private void checkTarget ( ) { if ( target == null ) { try { load ( ) ; LoadingList . get ( ) . remove ( this ) ; return ; } catch ( IOException e ) { throw new RuntimeException ( "Attempt to use deferred texture before loading and resource not found: " + resourceName ) ; } } }
Check if the target has been obtained already
38,118
public boolean contains ( float xp , float yp ) { checkPoints ( ) ; if ( xp <= getX ( ) ) { return false ; } if ( yp <= getY ( ) ) { return false ; } if ( xp >= maxX ) { return false ; } if ( yp >= maxY ) { return false ; } return true ; }
Check if this rectangle contains a point
38,119
public void setBounds ( Rectangle other ) { setBounds ( other . getX ( ) , other . getY ( ) , other . getWidth ( ) , other . getHeight ( ) ) ; }
Set the bounds of this rectangle based on the given rectangle
38,120
public void setBounds ( float x , float y , float width , float height ) { setX ( x ) ; setY ( y ) ; setSize ( width , height ) ; }
Set the bounds of this rectangle
38,121
public void grow ( float h , float v ) { setX ( getX ( ) - h ) ; setY ( getY ( ) - v ) ; setWidth ( getWidth ( ) + ( h * 2 ) ) ; setHeight ( getHeight ( ) + ( v * 2 ) ) ; }
Grow the rectangle at all edges by the given amounts . This will result in the rectangle getting larger around it s centre .
38,122
public void setWidth ( float width ) { if ( width != this . width ) { pointsDirty = true ; this . width = width ; maxX = x + width ; } }
Set the width of this box
38,123
public void setHeight ( float height ) { if ( height != this . height ) { pointsDirty = true ; this . height = height ; maxY = y + height ; } }
Set the heightof this box
38,124
public boolean intersects ( Shape shape ) { if ( shape instanceof Rectangle ) { Rectangle other = ( Rectangle ) shape ; if ( ( x > ( other . x + other . width ) ) || ( ( x + width ) < other . x ) ) { return false ; } if ( ( y > ( other . y + other . height ) ) || ( ( y + height ) < other . y ) ) { return false ; } return true ; } else if ( shape instanceof Circle ) { return intersects ( ( Circle ) shape ) ; } else { return super . intersects ( shape ) ; } }
Check if this box touches another
38,125
public void render ( ) { if ( ( engine . usePoints ( ) && ( usePoints == INHERIT_POINTS ) ) || ( usePoints == USE_POINTS ) ) { TextureImpl . bindNone ( ) ; GL . glEnable ( SGL . GL_POINT_SMOOTH ) ; GL . glPointSize ( size / 2 ) ; color . bind ( ) ; GL . glBegin ( SGL . GL_POINTS ) ; GL . glVertex2f ( x , y ) ; GL . glEnd ( ) ; } else if ( oriented || scaleY != 1.0f ) { GL . glPushMatrix ( ) ; GL . glTranslatef ( x , y , 0f ) ; if ( oriented ) { float angle = ( float ) ( Math . atan2 ( y , x ) * 180 / Math . PI ) ; GL . glRotatef ( angle , 0f , 0f , 1.0f ) ; } GL . glScalef ( 1.0f , scaleY , 1.0f ) ; image . draw ( ( int ) ( - ( size / 2 ) ) , ( int ) ( - ( size / 2 ) ) , ( int ) size , ( int ) size , color ) ; GL . glPopMatrix ( ) ; } else { color . bind ( ) ; image . drawEmbedded ( ( int ) ( x - ( size / 2 ) ) , ( int ) ( y - ( size / 2 ) ) , ( int ) size , ( int ) size ) ; } }
Render this particle
38,126
public void update ( int delta ) { emitter . updateParticle ( this , delta ) ; life -= delta ; if ( life > 0 ) { x += delta * velx ; y += delta * vely ; } else { engine . release ( this ) ; } }
Update the state of this particle
38,127
public void init ( ParticleEmitter emitter , float life ) { x = 0 ; this . emitter = emitter ; y = 0 ; velx = 0 ; vely = 0 ; size = 10 ; type = 0 ; this . originalLife = this . life = life ; oriented = false ; scaleY = 1.0f ; }
Initialise the state of the particle as it s reused
38,128
public void setColor ( float r , float g , float b , float a ) { if ( color == Color . white ) { color = new Color ( r , g , b , a ) ; } else { color . r = r ; color . g = g ; color . b = b ; color . a = a ; } }
Set the color of the particle
38,129
public void setVelocity ( float dirx , float diry , float speed ) { this . velx = dirx * speed ; this . vely = diry * speed ; }
Set the velocity of the particle
38,130
public void setSpeed ( float speed ) { float currentSpeed = ( float ) Math . sqrt ( ( velx * velx ) + ( vely * vely ) ) ; velx *= speed ; vely *= speed ; velx /= currentSpeed ; vely /= currentSpeed ; }
Set the current speed of this particle
38,131
public static void enableSharedContext ( ) throws SlickException { try { SHARED_DRAWABLE = new Pbuffer ( 64 , 64 , new PixelFormat ( 8 , 0 , 0 ) , null ) ; } catch ( LWJGLException e ) { throw new SlickException ( "Unable to create the pbuffer used for shard context, buffers not supported" , e ) ; } }
Enable shared OpenGL context . After calling this all containers created will shared a single parent context
38,132
public static int getBuildVersion ( ) { try { Properties props = new Properties ( ) ; props . load ( ResourceLoader . getResourceAsStream ( "version" ) ) ; int build = Integer . parseInt ( props . getProperty ( "build" ) ) ; Log . info ( "Slick Build #" + build ) ; return build ; } catch ( Exception e ) { Log . error ( "Unable to determine Slick build number" ) ; return - 1 ; } }
Get the build number of slick
38,133
public void sleep ( int milliseconds ) { long target = getTime ( ) + milliseconds ; while ( getTime ( ) < target ) { try { Thread . sleep ( 1 ) ; } catch ( Exception e ) { } } }
Sleep for a given period
38,134
protected void updateAndRender ( int delta ) throws SlickException { if ( smoothDeltas ) { if ( getFPS ( ) != 0 ) { delta = 1000 / getFPS ( ) ; } } input . poll ( width , height ) ; Music . poll ( delta ) ; if ( ! paused ) { storedDelta += delta ; if ( storedDelta >= minimumLogicInterval ) { try { if ( maximumLogicInterval != 0 ) { long cycles = storedDelta / maximumLogicInterval ; for ( int i = 0 ; i < cycles ; i ++ ) { game . update ( this , ( int ) maximumLogicInterval ) ; } int remainder = ( int ) ( storedDelta % maximumLogicInterval ) ; if ( remainder > minimumLogicInterval ) { game . update ( this , ( int ) ( remainder % maximumLogicInterval ) ) ; storedDelta = 0 ; } else { storedDelta = remainder ; } } else { game . update ( this , ( int ) storedDelta ) ; storedDelta = 0 ; } } catch ( Throwable e ) { Log . error ( e ) ; throw new SlickException ( "Game.update() failure - check the game code." ) ; } } } else { game . update ( this , 0 ) ; } if ( hasFocus ( ) || getAlwaysRender ( ) ) { if ( clearEachFrame ) { GL . glClear ( SGL . GL_COLOR_BUFFER_BIT | SGL . GL_DEPTH_BUFFER_BIT ) ; } GL . glLoadIdentity ( ) ; graphics . resetTransform ( ) ; graphics . resetFont ( ) ; graphics . resetLineWidth ( ) ; graphics . setAntiAlias ( false ) ; try { game . render ( this , graphics ) ; } catch ( Throwable e ) { Log . error ( e ) ; throw new SlickException ( "Game.render() failure - check the game code." ) ; } graphics . resetTransform ( ) ; if ( showFPS ) { defaultFont . drawString ( 10 , 10 , "FPS: " + recordedFPS ) ; } GL . flush ( ) ; } if ( targetFPS != - 1 ) { Display . sync ( targetFPS ) ; } }
Update and render the game
38,135
protected void initSystem ( ) throws SlickException { initGL ( ) ; setMusicVolume ( 1.0f ) ; setSoundVolume ( 1.0f ) ; graphics = new Graphics ( width , height ) ; defaultFont = graphics . getFont ( ) ; }
Initialise the system components OpenGL and OpenAL .
38,136
public void setLocation ( float x , float y ) { if ( area != null ) { area . setX ( x ) ; area . setY ( y ) ; } }
Moves the component .
38,137
private void updateImage ( ) { if ( ! over ) { currentImage = normalImage ; currentColor = normalColor ; state = NORMAL ; mouseUp = false ; } else { if ( mouseDown ) { if ( ( state != MOUSE_DOWN ) && ( mouseUp ) ) { if ( mouseDownSound != null ) { mouseDownSound . play ( ) ; } currentImage = mouseDownImage ; currentColor = mouseDownColor ; state = MOUSE_DOWN ; notifyListeners ( ) ; mouseUp = false ; } return ; } else { mouseUp = true ; if ( state != MOUSE_OVER ) { if ( mouseOverSound != null ) { mouseOverSound . play ( ) ; } currentImage = mouseOverImage ; currentColor = mouseOverColor ; state = MOUSE_OVER ; } } } mouseDown = false ; state = NORMAL ; }
Update the current normalImage based on the mouse state
38,138
public void render ( Graphics g ) { if ( list == - 1 ) { list = GL . glGenLists ( 1 ) ; GL . glNewList ( list , SGL . GL_COMPILE ) ; render ( g , diagram ) ; GL . glEndList ( ) ; } GL . glCallList ( list ) ; TextureImpl . bindNone ( ) ; }
Render the diagram to the given graphics context
38,139
public static void render ( Graphics g , Diagram diagram ) { for ( int i = 0 ; i < diagram . getFigureCount ( ) ; i ++ ) { Figure figure = diagram . getFigure ( i ) ; if ( figure . getData ( ) . isFilled ( ) ) { if ( figure . getData ( ) . isColor ( NonGeometricData . FILL ) ) { g . setColor ( figure . getData ( ) . getAsColor ( NonGeometricData . FILL ) ) ; g . fill ( diagram . getFigure ( i ) . getShape ( ) ) ; g . setAntiAlias ( true ) ; g . draw ( diagram . getFigure ( i ) . getShape ( ) ) ; g . setAntiAlias ( false ) ; } String fill = figure . getData ( ) . getAsReference ( NonGeometricData . FILL ) ; if ( diagram . getPatternDef ( fill ) != null ) { System . out . println ( "PATTERN" ) ; } if ( diagram . getGradient ( fill ) != null ) { Gradient gradient = diagram . getGradient ( fill ) ; Shape shape = diagram . getFigure ( i ) . getShape ( ) ; TexCoordGenerator fg = null ; if ( gradient . isRadial ( ) ) { fg = new RadialGradientFill ( shape , diagram . getFigure ( i ) . getTransform ( ) , gradient ) ; } else { fg = new LinearGradientFill ( shape , diagram . getFigure ( i ) . getTransform ( ) , gradient ) ; } Color . white . bind ( ) ; ShapeRenderer . texture ( shape , gradient . getImage ( ) , fg ) ; } } if ( figure . getData ( ) . isStroked ( ) ) { if ( figure . getData ( ) . isColor ( NonGeometricData . STROKE ) ) { g . setColor ( figure . getData ( ) . getAsColor ( NonGeometricData . STROKE ) ) ; g . setLineWidth ( figure . getData ( ) . getAsFloat ( NonGeometricData . STROKE_WIDTH ) ) ; g . setAntiAlias ( true ) ; g . draw ( diagram . getFigure ( i ) . getShape ( ) ) ; g . setAntiAlias ( false ) ; g . resetLineWidth ( ) ; } } } }
Utility method to render a diagram in immediate mode
38,140
public void setTheta ( double theta ) { if ( ( theta < - 360 ) || ( theta > 360 ) ) { theta = theta % 360 ; } if ( theta < 0 ) { theta = 360 + theta ; } double oldTheta = getTheta ( ) ; if ( ( theta < - 360 ) || ( theta > 360 ) ) { oldTheta = oldTheta % 360 ; } if ( theta < 0 ) { oldTheta = 360 + oldTheta ; } float len = length ( ) ; x = len * ( float ) FastTrig . cos ( StrictMath . toRadians ( theta ) ) ; y = len * ( float ) FastTrig . sin ( StrictMath . toRadians ( theta ) ) ; }
Calculate the components of the vectors based on a angle
38,141
public double getTheta ( ) { double theta = StrictMath . toDegrees ( StrictMath . atan2 ( y , x ) ) ; if ( ( theta < - 360 ) || ( theta > 360 ) ) { theta = theta % 360 ; } if ( theta < 0 ) { theta = 360 + theta ; } return theta ; }
Get the angle this vector is at
38,142
public Vector2f add ( Vector2f v ) { x += v . getX ( ) ; y += v . getY ( ) ; return this ; }
Add a vector to this vector
38,143
public Vector2f sub ( Vector2f v ) { x -= v . getX ( ) ; y -= v . getY ( ) ; return this ; }
Subtract a vector from this vector
38,144
public void projectOntoUnit ( Vector2f b , Vector2f result ) { float dp = b . dot ( this ) ; result . x = dp * b . getX ( ) ; result . y = dp * b . getY ( ) ; }
Project this vector onto another
38,145
public float distanceSquared ( Vector2f other ) { float dx = other . getX ( ) - getX ( ) ; float dy = other . getY ( ) - getY ( ) ; return ( float ) ( dx * dx ) + ( dy * dy ) ; }
Get the distance from this point to another squared . This can sometimes be used in place of distance and avoids the additional sqrt .
38,146
public void setLinkedEmitter ( ConfigurableEmitter emitter ) { Window w = SwingUtilities . windowForComponent ( this ) ; if ( w instanceof Frame ) ( ( Frame ) w ) . setTitle ( "Whiskas Gradient Editor (" + emitter . name + ")" ) ; properties . removeAllItems ( ) ; values . clear ( ) ; panel . setInterpolator ( null ) ; enableControls ( ) ; }
Set the emitter that is being controlled
38,147
private void fireUpdated ( Object control ) { if ( control . equals ( minSpinner ) ) { int minY = ( ( Integer ) minSpinner . getValue ( ) ) . intValue ( ) ; if ( minY < panel . getWorldMaxY ( ) ) { panel . setWorldMinY ( minY ) ; panel . makeSureCurveFits ( ) ; panel . repaint ( ) ; } else { minSpinner . setValue ( new Integer ( ( int ) panel . getWorldMinY ( ) ) ) ; } } else if ( control . equals ( maxSpinner ) ) { int maxY = ( ( Integer ) maxSpinner . getValue ( ) ) . intValue ( ) ; if ( maxY > panel . getWorldMinY ( ) ) { panel . setWorldMaxY ( maxY ) ; panel . makeSureCurveFits ( ) ; panel . repaint ( ) ; } else { maxSpinner . setValue ( new Integer ( ( int ) panel . getWorldMaxY ( ) ) ) ; } } }
Fire a notification that the panel has been changed
38,148
public void registerValue ( LinearInterpolator value , String name ) { properties . addItem ( name ) ; values . put ( name , value ) ; panel . setInterpolator ( value ) ; enableControls ( ) ; }
Register a configurable value with the graph panel
38,149
public void removeValue ( String name ) { properties . removeItem ( name ) ; values . remove ( name ) ; if ( properties . getItemCount ( ) >= 1 ) { properties . setSelectedIndex ( 0 ) ; } else { panel . setInterpolator ( null ) ; } enableControls ( ) ; }
Remove a configurable value from the graph
38,150
public void setFirstProperty ( ) { if ( properties . getItemCount ( ) > 0 ) { properties . setSelectedIndex ( 0 ) ; LinearInterpolator currentValue = ( LinearInterpolator ) values . get ( properties . getSelectedItem ( ) ) ; panel . setInterpolator ( currentValue ) ; } }
Indicate that the first property should be displayed
38,151
public void recalculateScale ( ) throws SlickException { targetWidth = container . getWidth ( ) ; targetHeight = container . getHeight ( ) ; if ( maintainAspect ) { boolean normalIsWide = ( normalWidth / normalHeight > 1.6 ? true : false ) ; boolean containerIsWide = ( ( float ) targetWidth / ( float ) targetHeight > 1.6 ? true : false ) ; float wScale = targetWidth / normalWidth ; float hScale = targetHeight / normalHeight ; if ( normalIsWide & containerIsWide ) { float scale = ( wScale < hScale ? wScale : hScale ) ; targetWidth = ( int ) ( normalWidth * scale ) ; targetHeight = ( int ) ( normalHeight * scale ) ; } else if ( normalIsWide & ! containerIsWide ) { targetWidth = ( int ) ( normalWidth * wScale ) ; targetHeight = ( int ) ( normalHeight * wScale ) ; } else if ( ! normalIsWide & containerIsWide ) { targetWidth = ( int ) ( normalWidth * hScale ) ; targetHeight = ( int ) ( normalHeight * hScale ) ; } else { float scale = ( wScale < hScale ? wScale : hScale ) ; targetWidth = ( int ) ( normalWidth * scale ) ; targetHeight = ( int ) ( normalHeight * scale ) ; } } if ( held instanceof InputListener ) { container . getInput ( ) . addListener ( ( InputListener ) held ) ; } container . getInput ( ) . setScale ( normalWidth / targetWidth , normalHeight / targetHeight ) ; int yoffset = 0 ; int xoffset = 0 ; if ( targetHeight < container . getHeight ( ) ) { yoffset = ( container . getHeight ( ) - targetHeight ) / 2 ; } if ( targetWidth < container . getWidth ( ) ) { xoffset = ( container . getWidth ( ) - targetWidth ) / 2 ; } container . getInput ( ) . setOffset ( - xoffset / ( targetWidth / normalWidth ) , - yoffset / ( targetHeight / normalHeight ) ) ; }
Recalculate the scale of the game
38,152
public void addState ( GameState state ) { states . put ( new Integer ( state . getID ( ) ) , state ) ; if ( currentState . getID ( ) == - 1 ) { currentState = state ; } }
Add a state to the game . The state will be updated and maintained by the game
38,153
public void enterState ( int id , Transition leave , Transition enter ) { if ( leave == null ) { leave = new EmptyTransition ( ) ; } if ( enter == null ) { enter = new EmptyTransition ( ) ; } leaveTransition = leave ; enterTransition = enter ; nextState = getState ( id ) ; if ( nextState == null ) { throw new RuntimeException ( "No game state registered with the ID: " + id ) ; } leaveTransition . init ( currentState , nextState ) ; }
Enter a particular game state with the transitions provided
38,154
public void setRGBA ( int x , int y , int r , int g , int b , int a ) { if ( ( x < 0 ) || ( x >= width ) || ( y < 0 ) || ( y >= height ) ) { throw new RuntimeException ( "Specified location: " + x + "," + y + " outside of image" ) ; } int ofs = ( ( x + ( y * texWidth ) ) * 4 ) ; if ( ByteOrder . nativeOrder ( ) == ByteOrder . BIG_ENDIAN ) { rawData [ ofs ] = ( byte ) b ; rawData [ ofs + 1 ] = ( byte ) g ; rawData [ ofs + 2 ] = ( byte ) r ; rawData [ ofs + 3 ] = ( byte ) a ; } else { rawData [ ofs ] = ( byte ) r ; rawData [ ofs + 1 ] = ( byte ) g ; rawData [ ofs + 2 ] = ( byte ) b ; rawData [ ofs + 3 ] = ( byte ) a ; } }
Set a pixel in the image buffer
38,155
private void fireUpdate ( ) { ActionEvent event = new ActionEvent ( this , 0 , "" ) ; for ( int i = 0 ; i < listeners . size ( ) ; i ++ ) { ( ( ActionListener ) listeners . get ( i ) ) . actionPerformed ( event ) ; } }
Fire an update to all listeners
38,156
private boolean checkPoint ( int mx , int my , ControlPoint pt ) { int dx = ( int ) Math . abs ( ( 10 + ( width * pt . pos ) ) - mx ) ; int dy = Math . abs ( ( y + barHeight + 7 ) - my ) ; if ( ( dx < 5 ) && ( dy < 7 ) ) { return true ; } return false ; }
Check if there is a control point at the specified mouse location
38,157
private void addPoint ( ) { ControlPoint point = new ControlPoint ( Color . white , 0.5f ) ; for ( int i = 0 ; i < list . size ( ) - 1 ; i ++ ) { ControlPoint now = ( ControlPoint ) list . get ( i ) ; ControlPoint next = ( ControlPoint ) list . get ( i + 1 ) ; if ( ( now . pos <= 0.5f ) && ( next . pos >= 0.5f ) ) { list . add ( i + 1 , point ) ; break ; } } selected = point ; sortPoints ( ) ; repaint ( 0 ) ; fireUpdate ( ) ; }
Add a new control point
38,158
private void sortPoints ( ) { final ControlPoint firstPt = ( ControlPoint ) list . get ( 0 ) ; final ControlPoint lastPt = ( ControlPoint ) list . get ( list . size ( ) - 1 ) ; Comparator compare = new Comparator ( ) { public int compare ( Object first , Object second ) { if ( first == firstPt ) { return - 1 ; } if ( second == lastPt ) { return - 1 ; } float a = ( ( ControlPoint ) first ) . pos ; float b = ( ( ControlPoint ) second ) . pos ; return ( int ) ( ( a - b ) * 10000 ) ; } } ; Collections . sort ( list , compare ) ; }
Sort the control points based on their position
38,159
private void editPoint ( ) { if ( selected == null ) { return ; } Color col = JColorChooser . showDialog ( this , "Select Color" , selected . col ) ; if ( col != null ) { selected . col = col ; repaint ( 0 ) ; fireUpdate ( ) ; } }
Edit the currently selected control point
38,160
private void selectPoint ( int mx , int my ) { if ( ! isEnabled ( ) ) { return ; } for ( int i = 1 ; i < list . size ( ) - 1 ; i ++ ) { if ( checkPoint ( mx , my , ( ControlPoint ) list . get ( i ) ) ) { selected = ( ControlPoint ) list . get ( i ) ; return ; } } if ( checkPoint ( mx , my , ( ControlPoint ) list . get ( 0 ) ) ) { selected = ( ControlPoint ) list . get ( 0 ) ; return ; } if ( checkPoint ( mx , my , ( ControlPoint ) list . get ( list . size ( ) - 1 ) ) ) { selected = ( ControlPoint ) list . get ( list . size ( ) - 1 ) ; return ; } selected = null ; }
Select the control point at the specified mouse coordinate
38,161
private void delPoint ( ) { if ( ! isEnabled ( ) ) { return ; } if ( selected == null ) { return ; } if ( list . indexOf ( selected ) == 0 ) { return ; } if ( list . indexOf ( selected ) == list . size ( ) - 1 ) { return ; } list . remove ( selected ) ; sortPoints ( ) ; repaint ( 0 ) ; fireUpdate ( ) ; }
Delete the currently selected point
38,162
private void movePoint ( int mx , int my ) { if ( ! isEnabled ( ) ) { return ; } if ( selected == null ) { return ; } if ( list . indexOf ( selected ) == 0 ) { return ; } if ( list . indexOf ( selected ) == list . size ( ) - 1 ) { return ; } float newPos = ( mx - 10 ) / ( float ) width ; newPos = Math . min ( 1 , newPos ) ; newPos = Math . max ( 0 , newPos ) ; selected . pos = newPos ; sortPoints ( ) ; fireUpdate ( ) ; }
Move the current point to the specified mouse location
38,163
public void addPoint ( float pos , Color col ) { ControlPoint point = new ControlPoint ( col , pos ) ; for ( int i = 0 ; i < list . size ( ) - 1 ; i ++ ) { ControlPoint now = ( ControlPoint ) list . get ( i ) ; ControlPoint next = ( ControlPoint ) list . get ( i + 1 ) ; if ( ( now . pos <= 0.5f ) && ( next . pos >= 0.5f ) ) { list . add ( i + 1 , point ) ; break ; } } repaint ( 0 ) ; }
Add a control point to the gradient
38,164
public void setEnd ( Color col ) { ( ( ControlPoint ) list . get ( list . size ( ) - 1 ) ) . col = col ; repaint ( 0 ) ; }
Set the ending colour
38,165
public void remove ( DeferredResource resource ) { Log . info ( "Early loading of deferred resource due to req: " + resource . getDescription ( ) ) ; total -- ; deferred . remove ( resource ) ; }
Remove a resource from the list that has been loaded for other reasons .
38,166
public static void checkVerboseLogSetting ( ) { try { AccessController . doPrivileged ( new PrivilegedAction ( ) { public Object run ( ) { String val = System . getProperty ( Log . forceVerboseProperty ) ; if ( ( val != null ) && ( val . equalsIgnoreCase ( Log . forceVerbosePropertyOnValue ) ) ) { Log . setForcedVerboseOn ( ) ; } return null ; } } ) ; } catch ( Throwable e ) { } }
Check if the system property org . newdawn . slick . verboseLog is set to true . If this is the case we activate the verbose logging mode
38,167
public void addShape ( Shape shape ) { if ( shape . points . length != points . length ) { throw new RuntimeException ( "Attempt to morph between two shapes with different vertex counts" ) ; } Shape prev = ( Shape ) shapes . get ( shapes . size ( ) - 1 ) ; if ( equalShapes ( prev , shape ) ) { shapes . add ( prev ) ; } else { shapes . add ( shape ) ; } if ( shapes . size ( ) == 2 ) { next = ( Shape ) shapes . get ( 1 ) ; } }
Add a subsequent shape that we should morph too in order
38,168
private boolean equalShapes ( Shape a , Shape b ) { a . checkPoints ( ) ; b . checkPoints ( ) ; for ( int i = 0 ; i < a . points . length ; i ++ ) { if ( a . points [ i ] != b . points [ i ] ) { return false ; } } return true ; }
Check if the shape s points are all equal
38,169
public void setMorphTime ( float time ) { int p = ( int ) time ; int n = p + 1 ; float offset = time - p ; p = rational ( p ) ; n = rational ( n ) ; setFrame ( p , n , offset ) ; }
Set the time index for this morph . This is given in terms of shapes so 0 . 5f would give you the position half way between the first and second shapes .
38,170
public void updateMorphTime ( float delta ) { offset += delta ; if ( offset < 0 ) { int index = shapes . indexOf ( current ) ; if ( index < 0 ) { index = shapes . size ( ) - 1 ; } int nframe = rational ( index + 1 ) ; setFrame ( index , nframe , offset ) ; offset += 1 ; } else if ( offset > 1 ) { int index = shapes . indexOf ( next ) ; if ( index < 1 ) { index = 0 ; } int nframe = rational ( index + 1 ) ; setFrame ( index , nframe , offset ) ; offset -= 1 ; } else { pointsDirty = true ; } }
Update the morph time and hence the curent frame
38,171
public void setExternalFrame ( Shape current ) { this . current = current ; next = ( Shape ) shapes . get ( 0 ) ; offset = 0 ; }
Set the current frame
38,172
private int rational ( int n ) { while ( n >= shapes . size ( ) ) { n -= shapes . size ( ) ; } while ( n < 0 ) { n += shapes . size ( ) ; } return n ; }
Get an index that is rational i . e . fits inside this set of shapes
38,173
private void setFrame ( int a , int b , float offset ) { current = ( Shape ) shapes . get ( a ) ; next = ( Shape ) shapes . get ( b ) ; this . offset = offset ; pointsDirty = true ; }
Set the frame to be represented
38,174
private void loadElement ( Element element , Transform t ) throws ParsingException { for ( int i = 0 ; i < processors . size ( ) ; i ++ ) { ElementProcessor processor = ( ElementProcessor ) processors . get ( i ) ; if ( processor . handles ( element ) ) { processor . process ( this , element , diagram , t ) ; } } }
Load a single element into the diagram
38,175
public Stroke getStroke ( ) { if ( stroke == null ) { return new BasicStroke ( width , BasicStroke . CAP_SQUARE , join ) ; } return stroke ; }
Get the stroke being used to draw the outline
38,176
public Sprite getSpriteAt ( int x , int y ) { for ( int i = 0 ; i < sprites . size ( ) ; i ++ ) { if ( ( ( Sprite ) sprites . get ( i ) ) . contains ( x , y ) ) { return ( ( Sprite ) sprites . get ( i ) ) ; } } return null ; }
Get the sprite a given location on the current sheet
38,177
public void select ( ArrayList selection ) { list . clearSelection ( ) ; int [ ] selected = new int [ selection . size ( ) ] ; for ( int i = 0 ; i < selection . size ( ) ; i ++ ) { selected [ i ] = sprites . indexOf ( selection . get ( i ) ) ; } list . setSelectedIndices ( selected ) ; sheetPanel . setSelection ( selection ) ; }
Select a series of sprites
38,178
private void save ( ) { int resp = saveChooser . showSaveDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File out = saveChooser . getSelectedFile ( ) ; ArrayList list = new ArrayList ( ) ; for ( int i = 0 ; i < sprites . size ( ) ; i ++ ) { list . add ( sprites . elementAt ( i ) ) ; } try { int b = ( ( Integer ) border . getValue ( ) ) . intValue ( ) ; pack . packImages ( list , twidth , theight , b , out ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; JOptionPane . showMessageDialog ( this , "Failed to write output" ) ; } } }
Save the sprite sheet
38,179
private void regenerate ( ) { try { ArrayList list = new ArrayList ( ) ; for ( int i = 0 ; i < sprites . size ( ) ; i ++ ) { list . add ( sprites . elementAt ( i ) ) ; } int b = ( ( Integer ) border . getValue ( ) ) . intValue ( ) ; Sheet sheet = pack . packImages ( list , twidth , theight , b , null ) ; sheetPanel . setImage ( sheet ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } }
Regenerate the sprite sheet that is being displayed
38,180
public void addPoint ( float x , float y ) { if ( hasVertex ( x , y ) && ( ! allowDups ) ) { return ; } ArrayList tempPoints = new ArrayList ( ) ; for ( int i = 0 ; i < points . length ; i ++ ) { tempPoints . add ( new Float ( points [ i ] ) ) ; } tempPoints . add ( new Float ( x ) ) ; tempPoints . add ( new Float ( y ) ) ; int length = tempPoints . size ( ) ; points = new float [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { points [ i ] = ( ( Float ) tempPoints . get ( i ) ) . floatValue ( ) ; } if ( x > maxX ) { maxX = x ; } if ( y > maxY ) { maxY = y ; } if ( x < minX ) { minX = x ; } if ( y < minY ) { minY = y ; } findCenter ( ) ; calculateRadius ( ) ; pointsDirty = true ; }
Add a point to the polygon
38,181
public Polygon copy ( ) { float [ ] copyPoints = new float [ points . length ] ; System . arraycopy ( points , 0 , copyPoints , 0 , copyPoints . length ) ; return new Polygon ( copyPoints ) ; }
Provide a copy of this polygon
38,182
private Class getClassForElementName ( String name ) { Class clazz = ( Class ) nameToClass . get ( name ) ; if ( clazz != null ) { return clazz ; } if ( defaultPackage != null ) { try { return Class . forName ( defaultPackage + "." + name ) ; } catch ( ClassNotFoundException e ) { } } return null ; }
Deterine the name of the class that should be used for a given XML element name .
38,183
private Object typeValue ( String value , Class clazz ) throws SlickXMLException { if ( clazz == String . class ) { return value ; } try { clazz = mapPrimitive ( clazz ) ; return clazz . getConstructor ( new Class [ ] { String . class } ) . newInstance ( new Object [ ] { value } ) ; } catch ( Exception e ) { throw new SlickXMLException ( "Failed to convert: " + value + " to the expected primitive type: " + clazz , e ) ; } }
Convert a given value to a given type
38,184
private Class mapPrimitive ( Class clazz ) { if ( clazz == Integer . TYPE ) { return Integer . class ; } if ( clazz == Double . TYPE ) { return Double . class ; } if ( clazz == Float . TYPE ) { return Float . class ; } if ( clazz == Boolean . TYPE ) { return Boolean . class ; } if ( clazz == Long . TYPE ) { return Long . class ; } throw new RuntimeException ( "Unsupported primitive: " + clazz ) ; }
Map a primitive class type to it s real object wrapper
38,185
private Field findField ( Class clazz , String name ) { Field [ ] fields = clazz . getDeclaredFields ( ) ; for ( int i = 0 ; i < fields . length ; i ++ ) { if ( fields [ i ] . getName ( ) . equalsIgnoreCase ( name ) ) { if ( fields [ i ] . getType ( ) . isPrimitive ( ) ) { return fields [ i ] ; } if ( fields [ i ] . getType ( ) == String . class ) { return fields [ i ] ; } } } return null ; }
Find a field in a class by it s name . Note that this method is only needed because the general reflection method is case sensitive
38,186
private Method findMethod ( Class clazz , String name ) { Method [ ] methods = clazz . getDeclaredMethods ( ) ; for ( int i = 0 ; i < methods . length ; i ++ ) { if ( methods [ i ] . getName ( ) . equalsIgnoreCase ( name ) ) { Method method = methods [ i ] ; Class [ ] params = method . getParameterTypes ( ) ; if ( params . length == 1 ) { return method ; } } } return null ; }
Find a method in a class by it s name . Note that this method is only needed because the general reflection method is case sensitive
38,187
private void setField ( Field field , Object instance , Object value ) throws SlickXMLException { try { field . setAccessible ( true ) ; field . set ( instance , value ) ; } catch ( IllegalArgumentException e ) { throw new SlickXMLException ( "Failed to set: " + field + " for an XML attribute, is it valid?" , e ) ; } catch ( IllegalAccessException e ) { throw new SlickXMLException ( "Failed to set: " + field + " for an XML attribute, is it valid?" , e ) ; } finally { field . setAccessible ( false ) ; } }
Set a field value on a object instance
38,188
private void invoke ( Method method , Object instance , Object [ ] params ) throws SlickXMLException { try { method . setAccessible ( true ) ; method . invoke ( instance , params ) ; } catch ( IllegalArgumentException e ) { throw new SlickXMLException ( "Failed to invoke: " + method + " for an XML attribute, is it valid?" , e ) ; } catch ( IllegalAccessException e ) { throw new SlickXMLException ( "Failed to invoke: " + method + " for an XML attribute, is it valid?" , e ) ; } catch ( InvocationTargetException e ) { throw new SlickXMLException ( "Failed to invoke: " + method + " for an XML attribute, is it valid?" , e ) ; } finally { method . setAccessible ( false ) ; } }
Call a method on a object
38,189
public void play ( float pitch , float volume ) { sound . playAsSoundEffect ( pitch , volume * SoundStore . get ( ) . getSoundVolume ( ) , false ) ; }
Play this sound effect at a given volume and pitch
38,190
public void playAt ( float pitch , float volume , float x , float y , float z ) { sound . playAsSoundEffect ( pitch , volume * SoundStore . get ( ) . getSoundVolume ( ) , false , x , y , z ) ; }
Play a sound effect from a particular location
38,191
public void loop ( float pitch , float volume ) { sound . playAsSoundEffect ( pitch , volume * SoundStore . get ( ) . getSoundVolume ( ) , true ) ; }
Loop this sound effect at a given volume and pitch
38,192
public static AiffData create ( URL path ) { try { return create ( AudioSystem . getAudioInputStream ( new BufferedInputStream ( path . openStream ( ) ) ) ) ; } catch ( Exception e ) { org . lwjgl . LWJGLUtil . log ( "Unable to create from: " + path ) ; e . printStackTrace ( ) ; return null ; } }
Creates a AiffData container from the specified url
38,193
public static AiffData create ( InputStream is ) { try { return create ( AudioSystem . getAudioInputStream ( is ) ) ; } catch ( Exception e ) { org . lwjgl . LWJGLUtil . log ( "Unable to create from inputstream" ) ; e . printStackTrace ( ) ; return null ; } }
Creates a AiffData container from the specified inputstream
38,194
public static AiffData create ( byte [ ] buffer ) { try { return create ( AudioSystem . getAudioInputStream ( new BufferedInputStream ( new ByteArrayInputStream ( buffer ) ) ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return null ; } }
Creates a AiffData container from the specified bytes
38,195
public void link ( Space other ) { if ( inTolerance ( x , other . x + other . width ) || inTolerance ( x + width , other . x ) ) { float linkx = x ; if ( x + width == other . x ) { linkx = x + width ; } float top = Math . max ( y , other . y ) ; float bottom = Math . min ( y + height , other . y + other . height ) ; float linky = top + ( ( bottom - top ) / 2 ) ; Link link = new Link ( linkx , linky , other ) ; links . put ( other , link ) ; linksList . add ( link ) ; } if ( inTolerance ( y , other . y + other . height ) || inTolerance ( y + height , other . y ) ) { float linky = y ; if ( y + height == other . y ) { linky = y + height ; } float left = Math . max ( x , other . x ) ; float right = Math . min ( x + width , other . x + other . width ) ; float linkx = left + ( ( right - left ) / 2 ) ; Link link = new Link ( linkx , linky , other ) ; links . put ( other , link ) ; linksList . add ( link ) ; } }
Link this space to another by creating a link and finding the point at which the spaces link up
38,196
public boolean hasJoinedEdge ( Space other ) { if ( inTolerance ( x , other . x + other . width ) || inTolerance ( x + width , other . x ) ) { if ( ( y >= other . y ) && ( y <= other . y + other . height ) ) { return true ; } if ( ( y + height >= other . y ) && ( y + height <= other . y + other . height ) ) { return true ; } if ( ( other . y >= y ) && ( other . y <= y + height ) ) { return true ; } if ( ( other . y + other . height >= y ) && ( other . y + other . height <= y + height ) ) { return true ; } } if ( inTolerance ( y , other . y + other . height ) || inTolerance ( y + height , other . y ) ) { if ( ( x >= other . x ) && ( x <= other . x + other . width ) ) { return true ; } if ( ( x + width >= other . x ) && ( x + width <= other . x + other . width ) ) { return true ; } if ( ( other . x >= x ) && ( other . x <= x + width ) ) { return true ; } if ( ( other . x + other . width >= x ) && ( other . x + other . width <= x + width ) ) { return true ; } } return false ; }
Check if this space has an edge that is joined with another
38,197
public Space merge ( Space other ) { float minx = Math . min ( x , other . x ) ; float miny = Math . min ( y , other . y ) ; float newwidth = width + other . width ; float newheight = height + other . height ; if ( x == other . x ) { newwidth = width ; } else { newheight = height ; } return new Space ( minx , miny , newwidth , newheight ) ; }
Merge this space with another
38,198
public boolean canMerge ( Space other ) { if ( ! hasJoinedEdge ( other ) ) { return false ; } if ( ( x == other . x ) && ( width == other . width ) ) { return true ; } if ( ( y == other . y ) && ( height == other . height ) ) { return true ; } return false ; }
Check if the given space can be merged with this one . It must have an adjacent edge and have the same height or width as this space .
38,199
public boolean contains ( float xp , float yp ) { return ( xp >= x ) && ( xp < x + width ) && ( yp >= y ) && ( yp < y + height ) ; }
Check if this space contains a given point