v0.9.4: moved last bits of texture creation into TextureCache
This commit is contained in:
parent
630fbbb43f
commit
d03c80cb97
|
@ -79,8 +79,29 @@ public class TextureCache {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static void add( Object key, SmartTexture tx ) {
|
//texture defaults to black and given size, but no assurance is made about this is another already exists
|
||||||
all.put( key, tx );
|
public synchronized static SmartTexture create( Object key, int width, int height ) {
|
||||||
|
|
||||||
|
if (all.containsKey( key )) {
|
||||||
|
|
||||||
|
return all.get( key );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Pixmap pixmap = new Pixmap( width, height, Pixmap.Format.RGBA8888 );
|
||||||
|
|
||||||
|
pixmap.setColor(0x000000FF);
|
||||||
|
pixmap.fill();
|
||||||
|
|
||||||
|
SmartTexture tx = new SmartTexture( pixmap );
|
||||||
|
|
||||||
|
tx.filter( Texture.LINEAR, Texture.LINEAR );
|
||||||
|
tx.wrap( Texture.CLAMP, Texture.CLAMP );
|
||||||
|
|
||||||
|
all.put( key, tx );
|
||||||
|
|
||||||
|
return tx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static void remove( Object key ){
|
public synchronized static void remove( Object key ){
|
||||||
|
|
|
@ -24,6 +24,7 @@ package com.watabou.noosa;
|
||||||
import com.badlogic.gdx.graphics.Pixmap;
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
import com.watabou.gltextures.SmartTexture;
|
import com.watabou.gltextures.SmartTexture;
|
||||||
import com.watabou.gltextures.TextureCache;
|
import com.watabou.gltextures.TextureCache;
|
||||||
|
import com.watabou.glwrap.Texture;
|
||||||
|
|
||||||
public class Halo extends Image {
|
public class Halo extends Image {
|
||||||
|
|
||||||
|
@ -38,12 +39,13 @@ public class Halo extends Image {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
if (!TextureCache.contains( CACHE_KEY )) {
|
if (!TextureCache.contains( CACHE_KEY )) {
|
||||||
Pixmap pixmap = new Pixmap(2*RADIUS+1, 2*RADIUS+1, Pixmap.Format.RGBA8888);
|
|
||||||
|
Pixmap pixmap = TextureCache.create( CACHE_KEY, 2*RADIUS+1, 2*RADIUS+1 ).bitmap;
|
||||||
pixmap.setColor( 0xFFFFFF08 );
|
pixmap.setColor( 0xFFFFFF08 );
|
||||||
for (int i = 0; i < RADIUS; i+=2) {
|
for (int i = 0; i < RADIUS; i+=2) {
|
||||||
pixmap.fillCircle(RADIUS, RADIUS, (RADIUS - i));
|
pixmap.fillCircle(RADIUS, RADIUS, (RADIUS - i));
|
||||||
}
|
}
|
||||||
TextureCache.add( CACHE_KEY, new SmartTexture( pixmap ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
texture( CACHE_KEY );
|
texture( CACHE_KEY );
|
||||||
|
|
|
@ -24,9 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.tiles;
|
||||||
import com.badlogic.gdx.graphics.Pixmap;
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
|
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
|
||||||
import com.watabou.gltextures.SmartTexture;
|
|
||||||
import com.watabou.gltextures.TextureCache;
|
import com.watabou.gltextures.TextureCache;
|
||||||
import com.watabou.glwrap.Texture;
|
|
||||||
import com.watabou.noosa.Image;
|
import com.watabou.noosa.Image;
|
||||||
import com.watabou.noosa.NoosaScript;
|
import com.watabou.noosa.NoosaScript;
|
||||||
import com.watabou.noosa.NoosaScriptNoLighting;
|
import com.watabou.noosa.NoosaScriptNoLighting;
|
||||||
|
@ -112,14 +110,9 @@ public class FogOfWar extends Image {
|
||||||
width = width2 * size;
|
width = width2 * size;
|
||||||
height = height2 * size;
|
height = height2 * size;
|
||||||
|
|
||||||
//TODO might be nice to compartmentalize the pixmap access and modification into texture/texturecache
|
String key = "FogOfWar" + width2 + "x" + height2;
|
||||||
Pixmap px = new Pixmap(width2, height2, Pixmap.Format.RGBA8888);
|
texture(TextureCache.create(key, width2, height2));
|
||||||
px.setBlending(Pixmap.Blending.None);
|
texture.bind();
|
||||||
px.setColor(0x000000FF);
|
|
||||||
px.fill();
|
|
||||||
SmartTexture tx = new SmartTexture(px, Texture.LINEAR, Texture.CLAMP, false);
|
|
||||||
TextureCache.add(FogOfWar.class, tx);
|
|
||||||
texture( tx );
|
|
||||||
|
|
||||||
scale.set( size, size );
|
scale.set( size, size );
|
||||||
|
|
||||||
|
@ -188,6 +181,7 @@ public class FogOfWar extends Image {
|
||||||
}
|
}
|
||||||
|
|
||||||
Pixmap fog = texture.bitmap;
|
Pixmap fog = texture.bitmap;
|
||||||
|
fog.setBlending(Pixmap.Blending.None);
|
||||||
|
|
||||||
int cell;
|
int cell;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user