v0.8.1: refactored fog of war to use LibGDX pixmaps
This commit is contained in:
parent
72a97fd83b
commit
4a6b0130c0
|
@ -1,91 +0,0 @@
|
||||||
/*
|
|
||||||
* Pixel Dungeon
|
|
||||||
* Copyright (C) 2012-2015 Oleg Dolya
|
|
||||||
*
|
|
||||||
* Shattered Pixel Dungeon
|
|
||||||
* Copyright (C) 2014-2019 Evan Debenham
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.watabou.gltextures;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
|
||||||
import com.watabou.glwrap.Texture;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
import java.nio.IntBuffer;
|
|
||||||
|
|
||||||
//provides a native intbuffer implementation because pixmap is too slow
|
|
||||||
//TODO: should evaluate this again, seeing as I've moved to LibGDX
|
|
||||||
public class BufferTexture extends SmartTexture {
|
|
||||||
|
|
||||||
public IntBuffer pixels;
|
|
||||||
|
|
||||||
public BufferTexture(int w, int h) {
|
|
||||||
super();
|
|
||||||
width = w;
|
|
||||||
height = h;
|
|
||||||
pixels = ByteBuffer.
|
|
||||||
allocateDirect( w * h * 4 ).
|
|
||||||
order( ByteOrder.nativeOrder() ).
|
|
||||||
asIntBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void generate() {
|
|
||||||
id = Gdx.gl.glGenTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reload() {
|
|
||||||
super.reload();
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update(){
|
|
||||||
bind();
|
|
||||||
filter( Texture.LINEAR, Texture.LINEAR );
|
|
||||||
wrap( Texture.CLAMP, Texture.CLAMP);
|
|
||||||
pixels.position(0);
|
|
||||||
Gdx.gl.glTexImage2D(
|
|
||||||
Gdx.gl.GL_TEXTURE_2D,
|
|
||||||
0,
|
|
||||||
Gdx.gl.GL_RGBA,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
0,
|
|
||||||
Gdx.gl.GL_RGBA,
|
|
||||||
Gdx.gl.GL_UNSIGNED_BYTE,
|
|
||||||
pixels );
|
|
||||||
}
|
|
||||||
|
|
||||||
//allows partially updating the texture
|
|
||||||
public void update(int top, int bottom){
|
|
||||||
bind();
|
|
||||||
filter( Texture.LINEAR, Texture.LINEAR );
|
|
||||||
wrap( Texture.CLAMP, Texture.CLAMP);
|
|
||||||
pixels.position(top*width);
|
|
||||||
Gdx.gl.glTexSubImage2D(Gdx.gl.GL_TEXTURE_2D,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
top,
|
|
||||||
width,
|
|
||||||
bottom - top,
|
|
||||||
Gdx.gl.GL_RGBA,
|
|
||||||
Gdx.gl.GL_UNSIGNED_BYTE,
|
|
||||||
pixels);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -40,13 +40,6 @@ public class SmartTexture extends Texture {
|
||||||
|
|
||||||
public Atlas atlas;
|
public Atlas atlas;
|
||||||
|
|
||||||
protected SmartTexture( ) {
|
|
||||||
//useful for subclasses which want to manage their own texture data
|
|
||||||
// in cases where pixmaps isn't fast enough.
|
|
||||||
|
|
||||||
//subclasses which use this MUST also override some mix of reload/generate/bind
|
|
||||||
}
|
|
||||||
|
|
||||||
public SmartTexture( Pixmap bitmap ) {
|
public SmartTexture( Pixmap bitmap ) {
|
||||||
this( bitmap, NEAREST, CLAMP, false );
|
this( bitmap, NEAREST, CLAMP, false );
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,6 @@ public class Game implements ApplicationListener {
|
||||||
draw();
|
draw();
|
||||||
|
|
||||||
Gdx.gl.glDisable( Gdx.gl.GL_SCISSOR_TEST );
|
Gdx.gl.glDisable( Gdx.gl.GL_SCISSOR_TEST );
|
||||||
Gdx.gl.glFlush();
|
|
||||||
|
|
||||||
step();
|
step();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,12 @@
|
||||||
|
|
||||||
package com.shatteredpixel.shatteredpixeldungeon.tiles;
|
package com.shatteredpixel.shatteredpixeldungeon.tiles;
|
||||||
|
|
||||||
|
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.BufferTexture;
|
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;
|
||||||
|
@ -110,7 +112,11 @@ public class FogOfWar extends Image {
|
||||||
width = width2 * size;
|
width = width2 * size;
|
||||||
height = height2 * size;
|
height = height2 * size;
|
||||||
|
|
||||||
BufferTexture tx = new BufferTexture(width2, height2);
|
//TODO might be nice to compartmentalize the pixmap access and modification into texture/texturecache
|
||||||
|
Pixmap px = new Pixmap(width2, height2, Pixmap.Format.RGBA8888);
|
||||||
|
px.setBlending(Pixmap.Blending.None);
|
||||||
|
px.fill();
|
||||||
|
SmartTexture tx = new SmartTexture(px, Texture.LINEAR, Texture.CLAMP, false);
|
||||||
TextureCache.add(FogOfWar.class, tx);
|
TextureCache.add(FogOfWar.class, tx);
|
||||||
texture( tx );
|
texture( tx );
|
||||||
|
|
||||||
|
@ -182,7 +188,7 @@ public class FogOfWar extends Image {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferTexture fog = (BufferTexture) texture;
|
Pixmap fog = texture.bitmap;
|
||||||
|
|
||||||
int cell;
|
int cell;
|
||||||
|
|
||||||
|
@ -273,11 +279,7 @@ public class FogOfWar extends Image {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updating.size() == 1 && !fullUpdate){
|
texture.bitmap(fog);
|
||||||
fog.update(updating.get(0).top * PIX_PER_TILE, updating.get(0).bottom * PIX_PER_TILE);
|
|
||||||
} else {
|
|
||||||
fog.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,31 +300,19 @@ public class FogOfWar extends Image {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillLeft( BufferTexture fog, int x, int y, int color){
|
private void fillLeft( Pixmap fog, int x, int y, int color){
|
||||||
for (int i = 0; i < PIX_PER_TILE; i++){
|
fog.setColor((color << 8) | (color >>> 24));
|
||||||
fog.pixels.position(((y * PIX_PER_TILE)+i)*width2 + x * PIX_PER_TILE);
|
fog.fillRectangle(x * PIX_PER_TILE, y*PIX_PER_TILE, PIX_PER_TILE/2, PIX_PER_TILE);
|
||||||
for (int j = 0; j < PIX_PER_TILE/2; j++) {
|
|
||||||
fog.pixels.put(color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillRight( BufferTexture fog, int x, int y, int color){
|
private void fillRight( Pixmap fog, int x, int y, int color){
|
||||||
for (int i = 0; i < PIX_PER_TILE; i++){
|
fog.setColor((color << 8) | (color >>> 24));
|
||||||
fog.pixels.position(((y * PIX_PER_TILE)+i)*width2 + x * PIX_PER_TILE + PIX_PER_TILE/2);
|
fog.fillRectangle(x * PIX_PER_TILE + PIX_PER_TILE/2, y*PIX_PER_TILE, PIX_PER_TILE/2, PIX_PER_TILE);
|
||||||
for (int j = PIX_PER_TILE/2; j < PIX_PER_TILE; j++) {
|
|
||||||
fog.pixels.put(color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillCell( BufferTexture fog, int x, int y, int color){
|
private void fillCell( Pixmap fog, int x, int y, int color){
|
||||||
for (int i = 0; i < PIX_PER_TILE; i++){
|
fog.setColor((color << 8) | (color >>> 24));
|
||||||
fog.pixels.position(((y * PIX_PER_TILE)+i)*width2 + x * PIX_PER_TILE);
|
fog.fillRectangle(x * PIX_PER_TILE, y*PIX_PER_TILE, PIX_PER_TILE, PIX_PER_TILE);
|
||||||
for (int j = 0; j < PIX_PER_TILE; j++) {
|
|
||||||
fog.pixels.put(color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue
Block a user