vc ppu: some updates for Lua

Former-commit-id: 3d99a6788d05eaf3e90bffe8d412f0ab92e7f9bb
Former-commit-id: 306ed39d09f2b0b5461cb71d0cef96d7d5793769
This commit is contained in:
Song Minjae
2017-02-26 03:08:58 +09:00
parent 679a65a12e
commit 71091cce98
4 changed files with 121 additions and 40 deletions

View File

@@ -53,14 +53,15 @@ class StateBlurTest : BasicGameState() {
kotlin.repeat(3) { fastBoxBlur(bluredImage, 3) }
g.background = Color(0x404040)
val image = bluredImage.image
val image = bluredImage.image // ImageBuffer.getImage() always HARDCOPIES texture data by
// allocating new ByteBuffer. We need variable so that we can destroy() it manually
g.drawImage(image,
Terrarum.WIDTH.minus(testImage.width).div(2f).floor() + FastMath.cos(theta) * 120,
Terrarum.HEIGHT.minus(testImage.height).div(2f).floor() + FastMath.sin(theta) * 40
)
g.flush()
image.destroy()
image.destroy() // You are done and you will be terminated, for the perkeleen memory's sake
}
private val isLE: Boolean

View File

@@ -28,17 +28,50 @@ class StateGraphicComputerTest : BasicGameState() {
}
override fun init(container: GameContainer?, game: StateBasedGame?) {
val sprite = (computer.getPeripheral("ppu") as PeripheralVideoCard).vram.sprites[0]
val vcard = (computer.getPeripheral("ppu") as PeripheralVideoCard).vram
sprite.setLine(0, intArrayOf(1,1,0,0,0,0,3,3))
sprite.setLine(1, intArrayOf(1,1,0,0,0,0,3,3))
sprite.setLine(2, intArrayOf(1,1,0,0,0,0,1,1))
sprite.setLine(3, intArrayOf(1,1,1,1,1,1,1,1))
sprite.setLine(4, intArrayOf(1,1,1,1,1,1,1,1))
sprite.setLine(5, intArrayOf(0,0,0,0,0,0,1,1))
sprite.setLine(6, intArrayOf(2,2,0,0,0,0,1,1))
sprite.setLine(7, intArrayOf(2,2,0,0,0,0,1,1))
(0..3).forEach { vcard.sprites[it].setPaletteSet(64,33,12,62) }
vcard.sprites[0].setAll(intArrayOf(
0,0,0,0,0,1,1,1,
0,0,0,0,1,1,1,1,
0,0,0,0,2,2,2,3,
0,0,0,2,3,2,3,3,
0,0,0,2,3,2,2,3,
0,0,0,2,2,3,3,3,
0,0,0,0,0,3,3,3,
0,0,0,0,2,2,1,2
))
vcard.sprites[1].setAll(intArrayOf(
1,1,0,0,0,0,0,0,
1,1,1,1,1,0,0,0,
3,2,3,0,0,0,0,0,
3,2,3,3,3,0,0,0,
3,3,2,3,3,3,0,0,
3,2,2,2,2,0,0,0,
3,3,3,3,0,0,0,0,
2,2,0,0,0,0,0,0
))
vcard.sprites[2].setAll(intArrayOf(
0,0,0,2,2,2,1,2,
0,0,2,2,2,2,1,1,
0,0,3,3,2,1,3,1,
0,0,3,3,3,1,1,1,
0,0,3,3,1,1,1,1,
0,0,0,0,1,1,1,0,
0,0,0,2,2,2,0,0,
0,0,2,2,2,2,0,0
))
vcard.sprites[3].setAll(intArrayOf(
2,1,2,2,2,0,0,0,
1,1,2,2,2,2,0,0,
1,3,1,2,3,3,0,0,
1,1,1,3,3,3,0,0,
1,1,1,1,3,3,0,0,
0,1,1,1,0,0,0,0,
0,0,2,2,2,0,0,0,
0,0,2,2,2,2,0,0
))
}
var angle = 0.0
@@ -50,24 +83,33 @@ class StateGraphicComputerTest : BasicGameState() {
computer.update(container, delta)
val vcard = (computer.getPeripheral("ppu") as PeripheralVideoCard)
val sprite = vcard.vram.sprites[0]
val sprites = vcard.vram.sprites
angle += delta / 500.0
angle += delta / 1000.0
sprite.posX = (Math.cos(angle) * 80 + 100).roundInt()
sprite.posY = (Math.sin(angle) * 80 + 100).roundInt()
(0..3).forEach { vcard.vram.sprites[it].setPaletteSet(64,26,12,62) }
sprites[0].posX = (Math.cos(angle) * 80 + 100).roundInt() - 8
sprites[0].posY = (Math.sin(angle) * 0 + 100).roundInt() - 8
sprites[1].posX = (Math.cos(angle) * 80 + 100).roundInt()
sprites[1].posY = (Math.sin(angle) * 0 + 100).roundInt() - 8
sprites[2].posX = (Math.cos(angle) * 80 + 100).roundInt() - 8
sprites[2].posY = (Math.sin(angle) * 0 + 100).roundInt()
sprites[3].posX = (Math.cos(angle) * 80 + 100).roundInt()
sprites[3].posY = (Math.sin(angle) * 0 + 100).roundInt()
//sprite.pal0 = (sprite.pal0 + 1) % 65
//sprite.pal1 = (sprite.pal1 + 1) % 65
//sprite.pal2 = (sprite.pal2 + 1) % 65
//sprite.pal3 = (sprite.pal3 + 1) % 65
sprite.rotation = (angle * 2 / Math.PI).roundInt() % 4
//vcard.vram.setBackgroundPixel(Random().nextInt(320), Random().nextInt(200), Random().nextInt(64))
//kotlin.repeat(64) {
// vcard.vram.setBackgroundPixel(Random().nextInt(320), Random().nextInt(200), 0)
//kotlin.repeat(256) {
//vcard.vram.setBackgroundPixel(Random().nextInt(320), Random().nextInt(200), Random().nextInt(64))
//vcard.vram.setBackgroundPixel(Random().nextInt(320), Random().nextInt(200), 15)
//}
}

View File

@@ -141,7 +141,7 @@ constructor(gamename: String) : StateBasedGame(gamename) {
//addState(StateMonitorCheck())
//addState(StateFontTester())
//addState(StateNoiseTexGen())
addState(StateBlurTest())
//addState(StateBlurTest())
//addState(StateShaderTest())
//addState(StateNoiseTester())

View File

@@ -44,7 +44,9 @@ class PeripheralVideoCard(val termW: Int = 40, val termH: Int = 25) :
val width = termW * blockW
val height = termH * blockH
val vram = VRAM(width, height, 64)
val spritesCount = 64
val vram = VRAM(width, height, spritesCount)
val frameBuffer = ImageBuffer(width, height)
val frameBufferImage = frameBuffer.image
@@ -61,6 +63,28 @@ class PeripheralVideoCard(val termW: Int = 40, val termH: Int = 25) :
val CLUT = VRAM.CLUT
val coloursCount = CLUT.size
val luaSpriteTable = LuaTable()
init {
fun composeSpriteObject(spriteIndex: Int) : LuaValue {
val sprite = vram.sprites[spriteIndex]
val t = LuaTable()
t["getColFromPal"] = SpriteGetColFromPal(sprite)
t["setPixel"] = SpriteSetPixel(sprite)
t["setPalSet"] = SpriteSetPaletteSet(sprite)
t["setLine"] = SpriteSetLine(sprite)
t["setAll"] = SpriteSetAll(sprite)
t["setRotation"] = SpriteSetRotation(sprite)
t["setFlipH"] = SpriteSetFlipH(sprite)
t["setFlipV"] = SpriteSetFlipV(sprite)
return t
}
(0..spritesCount - 1).forEach { luaSpriteTable[it + 1] = composeSpriteObject(it) }
}
fun buildFontRom(ref: String) {
// load font rom out of TGA
val imageRef = Image(ref)
@@ -93,6 +117,8 @@ class PeripheralVideoCard(val termW: Int = 40, val termH: Int = 25) :
globals["ppu"]["clearAll"] = ClearAll(this)
globals["ppu"]["clearBack"] = ClearBackground(this)
globals["ppu"]["clearFore"] = ClearForeground(this)
globals["ppu"]["getSpritesCount"] = GetSpritesCount(this)
}
private val spriteBuffer = ImageBuffer(VSprite.width, VSprite.height)
@@ -219,7 +245,7 @@ class PeripheralVideoCard(val termW: Int = 40, val termH: Int = 25) :
* 00011000
* 01111111
* 00000000
* 00111110
* 00111111
* 01100011
* 01100000
* 00111111
@@ -290,24 +316,21 @@ class PeripheralVideoCard(val termW: Int = 40, val termH: Int = 25) :
return LuaValue.NONE
}
}
class GetSpritesCount(val videoCard: PeripheralVideoCard) : ZeroArgFunction() {
override fun call(): LuaValue {
return videoCard.spritesCount.toLua()
}
}
class GetSprite(val videoCard: PeripheralVideoCard) : OneArgFunction() {
override fun call(arg: LuaValue): LuaValue {
return videoCard.luaSpriteTable[arg.checkint() - 1]
}
}
/////////////
// Sprites //
/////////////
fun composeSpriteObject(spriteIndex: Int) : LuaValue {
val sprite = vram.sprites[spriteIndex]
val t = LuaTable()
t["getColFromPal"] = SpriteGetColFromPal(sprite)
t["setPixel"] = SpriteSetPixel(sprite)
t["setPalSet"] = SpriteSetPaletteSet(sprite)
t["setLine"] = SpriteSetLine(sprite)
t["setAll"] = SpriteSetAll(sprite)
return t
}
private class SpriteGetColFromPal(val sprite: VSprite) : OneArgFunction() {
override fun call(arg: LuaValue): LuaValue {
return when (arg.checkint()) {
@@ -319,34 +342,48 @@ class PeripheralVideoCard(val termW: Int = 40, val termH: Int = 25) :
}
}
}
private class SpriteSetPixel(val sprite: VSprite) : ThreeArgFunction() {
override fun call(arg1: LuaValue, arg2: LuaValue, arg3: LuaValue): LuaValue {
sprite.setPixel(arg1.checkint(), arg2.checkint(), arg3.checkint())
return LuaValue.NONE
}
}
private class SpriteSetPaletteSet(val sprite: VSprite) : OneArgFunction() {
override fun call(arg: LuaValue): LuaValue {
sprite.setPaletteSet(arg(1).checkint(), arg(2).checkint(), arg(3).checkint(), arg(4).checkint())
return LuaValue.NONE
}
}
private class SpriteSetLine(val sprite: VSprite) : TwoArgFunction() {
override fun call(arg1: LuaValue, arg2: LuaValue): LuaValue {
sprite.setLine(arg1.checkint(), arg2.checktable().toIntArray())
return LuaValue.NONE
}
}
private class SpriteSetAll(val sprite: VSprite) : OneArgFunction() {
override fun call(arg: LuaValue): LuaValue {
sprite.setAll(arg.checktable().toIntArray())
return LuaValue.NONE
}
}
private class SpriteSetRotation(val sprite: VSprite) : OneArgFunction() {
override fun call(arg: LuaValue): LuaValue {
sprite.rotation = arg.checkint()
return LuaValue.NONE
}
}
private class SpriteSetFlipH(val sprite: VSprite) : OneArgFunction() {
override fun call(arg: LuaValue): LuaValue {
sprite.hFlip = arg.checkboolean()
return LuaValue.NONE
}
}
private class SpriteSetFlipV(val sprite: VSprite) : OneArgFunction() {
override fun call(arg: LuaValue): LuaValue {
sprite.vFlip = arg.checkboolean()
return LuaValue.NONE
}
}
}
class VRAM(pxlWidth: Int, pxlHeight: Int, nSprites: Int) {
@@ -391,6 +428,7 @@ class VSprite {
var hFlip = false
var vFlip = false
var rotation = 0
set(value) { field = value % 4 }
var isBackground = false
var isVisible = false