compressed fonts, lightmap histogram

Former-commit-id: 2fd36e0b2b7cd45ecdab628e0d2679efd17f01f3
Former-commit-id: 5c4109d7a2ce320584674c5415054a381ba4d6ec
This commit is contained in:
Song Minjae
2016-04-15 16:34:57 +09:00
parent d39715cbff
commit a903c629ec
42 changed files with 223 additions and 42 deletions

View File

@@ -7,7 +7,7 @@ import java.util.Random
*/
class Fudge3
/**
* Define new set of fudge dice with three dice.
* Define new set of Fudge dice with three dice (3dF).
* @param randfunc java.util.Random or its extension
*/
(randfunc: Random) : FudgeDice(randfunc, 3)

View File

@@ -7,20 +7,20 @@ import java.util.Random
*/
open class FudgeDice
/**
* Define new set of fudge dice with given counts.
* Define new set of Fudge dice with given counts.
* @param randfunc java.util.Random or its extension
* *
* @param counts amount of die
*/
(private val randfunc: Random, val diceCounts: Int) {
(private val randfunc: Random, val diceCount: Int) {
/**
* Roll dice and get result.
* @return Normal distributed integer [-N , N] for diceCount of N. 0 is the most frequent return.
* @return Normally distributed integer [-N , N] for diceCount of N. 0 is the most frequent return.
*/
fun roll(): Int {
var diceResult = 0
for (c in 0..diceCounts - 1) {
for (c in 0..diceCount - 1) {
diceResult += rollSingleDie()
}
@@ -29,14 +29,14 @@ open class FudgeDice
/**
* Roll dice and get result, for array index
* @return Normal distributed integer [0 , N] for N = 2 × DiceCounts + 1. 0 is the most frequent return.
* @return Normally distributed integer [0 , N] for N = 2 × DiceCounts + 1. 0 is the most frequent return.
*/
fun rollForArray(): Int {
return roll() + diceCounts
return roll() + diceCount
}
val sizeOfProbabilityRange: Int
get() = 2 * diceCounts + 1
get() = 2 * diceCount + 1
/**
* @return integer randomly picked from {-1, 0, 1}

View File

@@ -5,10 +5,7 @@ import net.torvald.JsonFetcher
import net.torvald.JsonWriter
import org.lwjgl.input.Controllers
import org.lwjgl.opengl.GL11
import org.newdawn.slick.AppGameContainer
import org.newdawn.slick.Font
import org.newdawn.slick.GameContainer
import org.newdawn.slick.SlickException
import org.newdawn.slick.*
import org.newdawn.slick.state.StateBasedGame
import java.io.File
import java.io.IOException
@@ -81,7 +78,7 @@ constructor(gamename: String) : StateBasedGame(gamename) {
lateinit var appgc: AppGameContainer
val WIDTH = 1060
val WIDTH = 1072
val HEIGHT = 742 // IMAX ratio
var VSYNC = true
val VSYNC_TRIGGER_THRESHOLD = 56
@@ -372,6 +369,11 @@ fun setBlendAlphaMap() {
GL11.glColorMask(false, false, false, true)
}
fun setBlendScreen() {
GL11.glEnable(GL11.GL_BLEND)
GL11.glColorMask(true, true, true, true)
GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_COLOR)}
fun setBlendDisable() {
GL11.glDisable(GL11.GL_BLEND)
}

View File

@@ -16,8 +16,8 @@ import java.util.*
*/
object LightmapRenderer {
val overscan_open: Int = (256f / (TilePropCodex.getProp(TileNameCode.AIR).opacity and 0xFF).toFloat()).ceil()
val overscan_opaque: Int = (256f / (TilePropCodex.getProp(TileNameCode.STONE).opacity and 0xFF).toFloat()).ceil()
val overscan_open: Int = Math.min(32, 256f.div(TilePropCodex.getProp(TileNameCode.AIR).opacity and 0xFF).toFloat().ceil())
val overscan_opaque: Int = Math.min(8, 256f.div(TilePropCodex.getProp(TileNameCode.STONE).opacity and 0xFF).toFloat().ceil())
private val LIGHTMAP_WIDTH = Terrarum.game.ZOOM_MIN.inv().times(Terrarum.WIDTH)
.div(MapDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
@@ -84,8 +84,73 @@ object LightmapRenderer {
* * true: overscanning is limited to 8 tiles in width (overscan_opaque)
* * false: overscanning will fully applied to 32 tiles in width (overscan_open)
*/
val noop_mask = BitSet(2 * (for_x_end - for_x_start + 1) +
2 * (for_y_end - for_y_start - 1))
/*val rect_width = for_x_end - for_x_start
val rect_height_rem_hbars = for_y_end - for_y_start - 2
val noop_mask = BitSet(2 * (rect_width) +
2 * (rect_height_rem_hbars))
val rect_size = noop_mask.size()
// get No-op mask
fun edgeToMaskNum(i: Int): Pair<Int, Int> {
if (i > rect_size) throw IllegalArgumentException()
if (i < rect_width) // top edge horizontal
return Pair(for_x_start + i, for_y_start)
else if (i >= rect_size - rect_width) // bottom edge horizontal
return Pair(
for_x_start + i.minus(rect_size - rect_width),
for_y_end
)
else { // vertical edges without horizontal edge pair
return Pair(
if ((rect_width.even() && i.even()) || (rect_width.odd() && i.odd()))
// if the index is on the left side of the box
for_x_start
else for_x_end ,
(i - rect_width).div(2) + for_y_start + 1
)
}
}
fun posToMaskNum(x: Int, y: Int): Int? {
if (x in for_x_start + 1..for_x_end - 1 && y in for_y_start + 1..for_y_end - 1) {
return null // inside of this imaginary box
}
else if (y <= for_y_start) { // upper edge
if (x < for_x_start) return 0
else if (x > for_x_end) return rect_width - 1
else return x - for_x_start
}
else if (y >= for_y_end) { // lower edge
if (x < for_x_start) return rect_size - rect_width
else if (x > for_x_end) return rect_size - 1
else return x - for_x_start + (rect_size - rect_width)
}
else { // between two edges
if (x < for_x_start) return (y - for_y_start - 1) * 2 + rect_width
else if (x > for_x_end) return (y - for_y_start - 1) * 2 + rect_width + 1
else return null
}
}
fun isNoop(x: Int, y: Int): Boolean =
if (posToMaskNum(x, y) == null)
false
else if (!(x in for_x_start - overscan_opaque..for_x_end + overscan_opaque &&
x in for_y_start - overscan_opaque..for_y_end + overscan_opaque))
// point is within the range of overscan_open but not overscan_opaque
noop_mask.get(posToMaskNum(x, y)!!)
else // point within the overscan_opaque must be rendered, so no no-op
false
// build noop map
for (i in 0..rect_size) {
val point = edgeToMaskNum(i)
val tile = Terrarum.game.map.getTileFromTerrain(point.first, point.second) ?: TileNameCode.NULL
val isSolid = TilePropCodex.getProp(tile).isSolid
noop_mask.set(i, isSolid)
}*/
/**
* Updating order:
@@ -527,4 +592,81 @@ object LightmapRenderer {
fun Float.floor() = FastMath.floor(this)
fun Float.round(): Int = Math.round(this)
fun Float.ceil() = FastMath.ceil(this)
fun Int.even(): Boolean = this and 1 == 0
fun Int.odd(): Boolean = this and 1 == 1
val histogram: Histogram
get() {
var reds = IntArray(MUL) // reds[intensity] ← counts
var greens = IntArray(MUL) // do.
var blues = IntArray(MUL) // do.
val render_width = for_x_end - for_x_start
val render_height = for_y_end - for_y_start
// excluiding overscans; only reckon visible lights
for (y in overscan_open..render_height + overscan_open + 1) {
for (x in overscan_open..render_width + overscan_open + 1) {
reds[lightmap[y][x].rawR()] += 1
greens[lightmap[y][x].rawG()] += 1
blues[lightmap[y][x].rawB()] += 1
}
}
return Histogram(reds, greens, blues)
}
class Histogram(val reds: IntArray, val greens: IntArray, val blues: IntArray) {
val RED = 0
val GREEN = 1
val BLUE = 2
val screen_tiles: Int
get() = (for_x_end - for_x_start + 2) * (for_y_end - for_y_start + 2)
val brightest: Int
get() {
for (i in CHANNEL_MAX downTo 1) {
if (reds[i] > 0 || greens[i] > 0 || blues[i] > 0)
return i
}
return 0
}
val brightest8Bit: Int
get() { val b = brightest
return if (brightest > 255) 255 else b
}
val dimmest: Int
get() {
for (i in 0..CHANNEL_MAX) {
if (reds[i] > 0 || greens[i] > 0 || blues[i] > 0)
return i
}
return CHANNEL_MAX
}
val histogramMax: Int
get() {
var max = 0
for (c in 0..2) {
for (i in 0..CHANNEL_MAX) {
val value = get(c)[i]
if (value > max) max = value
}
}
return max
}
val range: Int
get() = reds.size
fun get(index: Int): IntArray {
return when (index) {
RED -> reds
GREEN -> greens
BLUE -> blues
else -> throw IllegalArgumentException()
}
}
}
}

View File

@@ -41,7 +41,7 @@
"10"; "2";"TILE_PLATFORM_EBONY" ; "8396808"; "1"; "N/A"; "0"; "0"; "0"; "0"; "0"; "10"; "2"; "0";"16"
"10"; "3";"TILE_PLATFORM_BIRCH" ; "8396808"; "1"; "N/A"; "0"; "0"; "0"; "0"; "0"; "10"; "3"; "0";"16"
"10"; "4";"TILE_PLATFORM_BLOODROSE" ; "8396808"; "1"; "N/A"; "0"; "0"; "0"; "0"; "0"; "10"; "4"; "0";"16"
"11"; "0";"TILE_TORCH" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "0"; "244454464"; "11"; "0"; "0";"16"
"11"; "0";"TILE_TORCH" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "0"; "267518016"; "11"; "0"; "0";"16"
"11"; "1";"TILE_TORCH_FROST" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "0"; "81916159"; "11"; "1"; "0";"16"
"12"; "0";"TILE_TORCH" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "0"; "0"; "11"; "0"; "0";"16"
"12"; "1";"TILE_TORCH_FROST" ; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "0"; "0"; "11"; "1"; "0";"16"
@@ -84,22 +84,6 @@
"15"; "4";"TILE_SANDSTONE_BLACK" ; "33587232"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "15"; "4"; "0";"16"
"15"; "5";"TILE_SANDSTONE_BLACK" ; "33587232"; "25";"1900"; "0"; "0"; "1"; "1"; "0"; "15"; "5"; "0";"16"
"16"; "0";"TILE_LANTERN_IRON_REGULAR"; "8396808"; "0"; "N/A"; "0"; "0"; "0"; "0"; "267619480"; "16"; "0"; "0";"16"
"255"; "0";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "1";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "2";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "3";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "4";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "5";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "6";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "7";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "8";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "9";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "10";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "11";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "12";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "13";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "14";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "15";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"254"; "0";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "48"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0";"16"
"254"; "1";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "48"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0";"16"
"254"; "2";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "48"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0";"16"
@@ -116,6 +100,22 @@
"254"; "13";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "48"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0";"16"
"254"; "14";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "48"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0";"16"
"254"; "15";"TILE_LAVA" ;"260301048"; "100";"2600"; "1"; "48"; "0"; "0"; "205574144"; "N/A"; "N/A"; "0";"16"
"255"; "0";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "1";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "2";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "3";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "4";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "5";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "6";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "7";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "8";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "9";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "10";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "11";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "12";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "13";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "14";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"255"; "15";"TILE_WATER" ; "27282445"; "100";"1000"; "1"; "12"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
"256"; "0";"TILE_NULL" ; "0"; "-1";"2600"; "0"; "0"; "0"; "0"; "0"; "N/A"; "N/A"; "0";"16"
# Friction: 0: frictionless, <16: slippery, 16: regular, >16: sticky
# Opacity/Lumcolor: 40-step RGB
@@ -123,7 +123,7 @@
# movr: Movement resistance, (walkspeedmax) / (1 + (n/16)), 16 halves movement speed
# dsty: density. As we are putting water an 1000, it is identical to specific gravity. [g/l]
# Defalut torch : L 77 a 47 b 59; real candlelight colour taken from properly configured camera.
# Defalut torch : L 70 a 51 b 59; real candlelight colour taken from properly configured camera.
# 16 colour palette : Old Apple Macintosh 16-colour palette
Can't render this file because it contains an unexpected character in line 1 and column 18.

View File

@@ -1,11 +1,14 @@
package net.torvald.terrarum.ui
import com.jme3.math.FastMath
import net.torvald.terrarum.gamemap.PairedMapLayer
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.mapdrawer.LightmapRenderer
import net.torvald.terrarum.mapdrawer.MapCamera
import net.torvald.terrarum.mapdrawer.MapDrawer
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.setBlendNormal
import net.torvald.terrarum.setBlendScreen
import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
@@ -162,6 +165,8 @@ class BasicDebugInfoWindow : UICanvas {
g.drawString(
Lang["DEV_COLOUR_LEGEND_BLUE"] + " : nextHitbox", (Terrarum.WIDTH - 200).toFloat()
, line(3).toFloat())
drawHistogram(g, LightmapRenderer.histogram, Terrarum.WIDTH - 256 - 30, Terrarum.HEIGHT - 100 - 30)
}
private fun printLine(g: Graphics, l: Int, s: String) {
@@ -172,13 +177,45 @@ class BasicDebugInfoWindow : UICanvas {
g.drawString(s, (20 + column(col)).toFloat(), line(row).toFloat())
}
private fun line(i: Int): Int {
return i * 20
private fun drawHistogram(g: Graphics, histogram: LightmapRenderer.Histogram, x: Int, y: Int) {
val uiColour = Color(0x99000000.toInt())
val barR = Color(0xFF0000.toInt())
val barG = Color(0x00FF00.toInt())
val barB = Color(0x0000FF.toInt())
val barColour = arrayOf(barR, barG, barB)
val w = 256.toFloat()
val h = 100.toFloat()
val range = histogram.range
val histogramMax = histogram.screen_tiles
//val histogramMax = histogram.histogramMax
g.color = uiColour
g.fillRect(x.toFloat(), y.toFloat(), w.plus(1).toFloat(), h.toFloat())
setBlendScreen()
for (c in 0..2) {
for (i in 0..255) {
var histogram_value = if (i == 255) 0 else histogram.get(c)[i]
if (i == 255) {
for (k in 255..range - 1) {
histogram_value += histogram.get(c)[k]
}
}
val bar_x = x + (w / w.minus(1).toFloat()) * i.toFloat()
val bar_h = FastMath.ceil(h / histogramMax.toFloat()) * histogram_value.toFloat()
val bar_y = y + (h / histogramMax.toFloat()) - bar_h + h
val bar_w = 1f
g.color = barColour[c]
g.fillRect(bar_x, bar_y, bar_w, bar_h)
}
}
setBlendNormal()
}
private fun column(i: Int): Int {
return 250 * (i - 1)
}
private fun line(i: Int): Int = i * 20
private fun column(i: Int): Int = 250 * (i - 1)
override fun doOpening(gc: GameContainer, delta: Int) {