ThreadPool renamed to PhreadParallel, tweaks on font

Former-commit-id: 52c6d53764449cecd9ab1aa96b23810e5e406cc2
Former-commit-id: cf8ff86f3c62851c8be2370774b426e09410ad6f
This commit is contained in:
Song Minjae
2017-01-01 15:06:19 +09:00
parent f5f0fcb077
commit 0c2cb48135
11 changed files with 147 additions and 69 deletions

View File

@@ -4,6 +4,81 @@
<facet type="Lua" name="Lua"> <facet type="Lua" name="Lua">
<configuration SdkName="Kahlua" /> <configuration SdkName="Kahlua" />
</facet> </facet>
<facet type="kotlin-language" name="Kotlin">
<configuration version="1">
<option name="compilerInfo">
<KotlinCompilerInfo>
<option name="compilerSettings">
<CompilerSettings>
<option name="additionalArguments" value="-version" />
<option name="copyJsLibraryFiles" value="true" />
<option name="outputDirectoryForJsLibraryFiles" value="lib" />
</CompilerSettings>
</option>
<option name="k2jsCompilerArguments">
<K2JSCompilerArguments>
<option name="outputFile" />
<option name="noStdlib" value="false" />
<option name="libraryFiles" />
<option name="sourceMap" value="false" />
<option name="metaInfo" value="false" />
<option name="kjsm" value="false" />
<option name="target" />
<option name="moduleKind" />
<option name="main" />
<option name="outputPrefix" />
<option name="outputPostfix" />
<option name="languageVersion" />
<option name="apiVersion" />
<option name="suppressWarnings" value="false" />
<option name="verbose" value="false" />
<option name="version" value="false" />
<option name="help" value="false" />
<option name="extraHelp" value="false" />
<option name="noInline" value="false" />
<option name="repeat" />
<option name="pluginClasspaths" />
<option name="pluginOptions" />
<option name="freeArgs">
<list />
</option>
<option name="unknownExtraFlags">
<list />
</option>
</K2JSCompilerArguments>
</option>
<option name="_commonCompilerArguments">
<DummyImpl>
<option name="languageVersion" />
<option name="apiVersion" />
<option name="suppressWarnings" value="false" />
<option name="verbose" value="false" />
<option name="version" value="false" />
<option name="help" value="false" />
<option name="extraHelp" value="false" />
<option name="noInline" value="false" />
<option name="repeat" />
<option name="pluginClasspaths" />
<option name="pluginOptions" />
<option name="freeArgs">
<list />
</option>
<option name="unknownExtraFlags">
<list />
</option>
</DummyImpl>
</option>
</KotlinCompilerInfo>
</option>
<option name="versionInfo">
<KotlinVersionInfo>
<option name="apiLevel" value="1.0" />
<option name="languageLevel" value="1.0" />
<option name="targetPlatformName" value="JVM 1.6" />
</KotlinVersionInfo>
</option>
</configuration>
</facet>
</component> </component>
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -1,18 +1,16 @@
package net.torvald.imagefont package net.torvald.imagefont
import net.torvald.terrarum.Terrarum
import org.newdawn.slick.* import org.newdawn.slick.*
/** /**
* Created by minjaesong on 16-01-20. * Created by minjaesong on 16-01-20.
*/ */
class GameFontWhite @Throws(SlickException::class) class GameFontWhite : GameFontBase() {
constructor() : GameFontBase() {
init { init {
GameFontBase.hangulSheet = SpriteSheet( GameFontBase.hangulSheet = SpriteSheet(
"./assets/graphics/fonts/han_johab.png", GameFontBase.W_HANGUL, GameFontBase.H_HANGUL) "./assets/graphics/fonts/hangul_johab.png", GameFontBase.W_HANGUL, GameFontBase.H_HANGUL)
GameFontBase.asciiSheet = SpriteSheet( GameFontBase.asciiSheet = SpriteSheet(
"./assets/graphics/fonts/ascii_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H) "./assets/graphics/fonts/ascii_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
GameFontBase.asciiSheetEF = SpriteSheet( GameFontBase.asciiSheetEF = SpriteSheet(
@@ -68,19 +66,19 @@ constructor() : GameFontBase() {
GameFontBase.extASheetEF, GameFontBase.extASheetEF,
GameFontBase.kanaSheet, GameFontBase.kanaSheet,
GameFontBase.cjkPunct, GameFontBase.cjkPunct,
null, // Filler null, // Full unihan, filler because we're using WenQuanYi
GameFontBase.cyrilic, GameFontBase.cyrilic,
GameFontBase.cyrilicEF, GameFontBase.cyrilicEF,
GameFontBase.fullwidthForms, GameFontBase.fullwidthForms,
GameFontBase.uniPunct, GameFontBase.uniPunct,
GameFontBase.wenQuanYi_1, GameFontBase.wenQuanYi_1,
GameFontBase.wenQuanYi_2, // uniHan GameFontBase.wenQuanYi_2,
GameFontBase.greekSheet, GameFontBase.greekSheet,
GameFontBase.greekSheetEF, GameFontBase.greekSheetEF,
GameFontBase.romanianSheet, GameFontBase.romanianSheet,
GameFontBase.romanianSheetEF, GameFontBase.romanianSheetEF,
GameFontBase.thaiSheet, GameFontBase.thaiSheet,
null, // Filler null, // Thai EF, filler because not being used right now
GameFontBase.keycapSheet GameFontBase.keycapSheet
) )
GameFontBase.sheetKey = shk GameFontBase.sheetKey = shk

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum
import net.torvald.imagefont.GameFontBase import net.torvald.imagefont.GameFontBase
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
import net.torvald.terrarum.audio.AudioResourceLibrary import net.torvald.terrarum.audio.AudioResourceLibrary
import net.torvald.terrarum.concurrent.ThreadPool import net.torvald.terrarum.concurrent.ThreadParallel
import net.torvald.terrarum.console.* import net.torvald.terrarum.console.*
import net.torvald.terrarum.gameactors.ActorHumanoid import net.torvald.terrarum.gameactors.ActorHumanoid
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
@@ -54,7 +54,7 @@ constructor() : BasicGameState() {
val ACTORCONTAINER_INITIAL_SIZE = 128 val ACTORCONTAINER_INITIAL_SIZE = 128
val actorContainer = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE) val actorContainer = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
val actorContainerInactive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE) val actorContainerInactive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
val uiContainer = LinkedList<UIHandler>() val uiContainer = ArrayList<UIHandler>()
lateinit var consoleHandler: UIHandler lateinit var consoleHandler: UIHandler
lateinit var debugWindow: UIHandler lateinit var debugWindow: UIHandler
@@ -527,8 +527,8 @@ constructor() : BasicGameState() {
if (false) { // don't multithread this for now, it's SLOWER //if (Terrarum.MULTITHREAD) { if (false) { // don't multithread this for now, it's SLOWER //if (Terrarum.MULTITHREAD) {
val actors = actorContainer.size.toFloat() val actors = actorContainer.size.toFloat()
// set up indices // set up indices
for (i in 0..ThreadPool.POOL_SIZE - 1) { for (i in 0..ThreadParallel.POOL_SIZE - 1) {
ThreadPool.map( ThreadParallel.map(
i, i,
ThreadActorUpdate( ThreadActorUpdate(
actors.div(Terrarum.THREADS).times(i).roundInt(), actors.div(Terrarum.THREADS).times(i).roundInt(),
@@ -539,7 +539,7 @@ constructor() : BasicGameState() {
) )
} }
ThreadPool.startAll() ThreadParallel.startAll()
} }
else { else {
actorContainer.forEach { it.update(gc, delta) } actorContainer.forEach { it.update(gc, delta) }

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum
import com.sudoplay.joise.Joise import com.sudoplay.joise.Joise
import com.sudoplay.joise.module.* import com.sudoplay.joise.module.*
import net.torvald.terrarum.Terrarum.Companion.STATE_ID_TOOL_NOISEGEN import net.torvald.terrarum.Terrarum.Companion.STATE_ID_TOOL_NOISEGEN
import net.torvald.terrarum.concurrent.ThreadPool import net.torvald.terrarum.concurrent.ThreadParallel
import net.torvald.terrarum.gameactors.roundInt import net.torvald.terrarum.gameactors.roundInt
import org.newdawn.slick.Color import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer import org.newdawn.slick.GameContainer
@@ -128,7 +128,7 @@ class StateNoiseTexGen : BasicGameState() {
} }
for (i in 0..Terrarum.THREADS - 1) { for (i in 0..Terrarum.THREADS - 1) {
ThreadPool.map( ThreadParallel.map(
i, i,
ThreadRunNoiseSampling( ThreadRunNoiseSampling(
imagesize.toFloat().div(Terrarum.THREADS).times(i).roundInt(), imagesize.toFloat().div(Terrarum.THREADS).times(i).roundInt(),
@@ -139,7 +139,7 @@ class StateNoiseTexGen : BasicGameState() {
) )
} }
ThreadPool.startAll() ThreadParallel.startAll()
} }
override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) { override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) {

View File

@@ -152,7 +152,7 @@ constructor(gamename: String) : StateBasedGame(gamename) {
lateinit var appgc: AppGameContainer lateinit var appgc: AppGameContainer
var WIDTH = 1072 var WIDTH = 1072
var HEIGHT = 742 // IMAX ratiso var HEIGHT = 742 // IMAX ratio
var VSYNC = true var VSYNC = true
val VSYNC_TRIGGER_THRESHOLD = 56 val VSYNC_TRIGGER_THRESHOLD = 56

View File

@@ -6,7 +6,7 @@ import java.util.*
/** /**
* Created by minjaesong on 16-05-25. * Created by minjaesong on 16-05-25.
*/ */
object ThreadPool { object ThreadParallel {
val POOL_SIZE = Terrarum.THREADS + 1 val POOL_SIZE = Terrarum.THREADS + 1
private val pool: Array<Thread?> = Array(POOL_SIZE, { null }) private val pool: Array<Thread?> = Array(POOL_SIZE, { null })

View File

@@ -6,13 +6,17 @@ import net.torvald.terrarum.tileproperties.TileCodex
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.colourutil.RGB import net.torvald.colourutil.RGB
import net.torvald.colourutil.CIELuvUtil.additiveLuv import net.torvald.colourutil.CIELuvUtil.additiveLuv
import net.torvald.terrarum.concurrent.ThreadParallel
import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.abs
import net.torvald.terrarum.gameactors.roundInt
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.tileproperties.Tile import net.torvald.terrarum.tileproperties.Tile
import net.torvald.terrarum.tileproperties.TilePropUtil import net.torvald.terrarum.tileproperties.TilePropUtil
import org.newdawn.slick.Color import org.newdawn.slick.Color
import org.newdawn.slick.Graphics import org.newdawn.slick.Graphics
import java.util.* import java.util.*
import java.util.concurrent.locks.ReentrantLock
/** /**
* Created by minjaesong on 16-01-25. * Created by minjaesong on 16-01-25.
@@ -56,6 +60,7 @@ object LightmapRenderer {
internal var for_x_end: Int = 0 internal var for_x_end: Int = 0
internal var for_y_end: Int = 0 internal var for_y_end: Int = 0
fun getLightRawPos(x: Int, y: Int) = lightmap[y][x] fun getLightRawPos(x: Int, y: Int) = lightmap[y][x]
fun getLight(x: Int, y: Int): Int? { fun getLight(x: Int, y: Int): Int? {
@@ -114,7 +119,7 @@ object LightmapRenderer {
if ((rect_width.even() && i.even()) || (rect_width.odd() && i.odd())) if ((rect_width.even() && i.even()) || (rect_width.odd() && i.odd()))
// if the index is on the left side of the box // if the index is on the left side of the box
for_x_start for_x_start
else for_x_end , else for_x_end,
(i - rect_width).div(2) + for_y_start + 1 (i - rect_width).div(2) + for_y_start + 1
) )
} }
@@ -174,34 +179,10 @@ object LightmapRenderer {
*/ */
purgeLightmap() purgeLightmap()
buildLanternmap()
// scan for luminous actors and store their lighting info to the lanterns
lanternMap.clear()
Terrarum.ingame.actorContainer.forEach { it ->
if (it is Luminous && it is ActorWithBody) {
// put lanterns to the area the luminantBox is occupying
for (lightBox in it.lightBoxList) {
val lightBoxX = it.hitbox.posX + lightBox.posX
val lightBoxY = it.hitbox.posY + lightBox.posY
val lightBoxW = lightBox.width
val lightBoxH = lightBox.height
for (y in lightBoxY.div(TILE_SIZE).floorInt()
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorInt()) {
for (x in lightBoxX.div(TILE_SIZE).floorInt()
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorInt()) {
lanternMap.add(Lantern(x, y, it.luminosity))
// Q&D fix for Roundworld anomaly
lanternMap.add(Lantern(x + world.width, y, it.luminosity))
lanternMap.add(Lantern(x - world.width, y, it.luminosity))
}
}
}
}
}
// O(36n) == O(n) where n is a size of the map. // O(36n) == O(n) where n is a size of the map.
// Because of inevitable overlaps on the area, it only works with ADDITIVE blend (aka maxblend) // Because of inevitable overlaps on the area, it only works with ADDITIVE blend (aka maxblend)
try {
// Round 1 // Round 1
for (y in for_y_start - overscan_open..for_y_end) { for (y in for_y_start - overscan_open..for_y_end) {
for (x in for_x_start - overscan_open..for_x_end) { for (x in for_x_start - overscan_open..for_x_end) {
@@ -229,12 +210,31 @@ object LightmapRenderer {
setLight(x, y, calculate(x, y)) setLight(x, y, calculate(x, y))
} }
} }
TilePropUtil.dynamicLumFuncTickClock()
}
catch (e: ArrayIndexOutOfBoundsException) {
} }
private fun buildLanternmap() {
lanternMap.clear()
Terrarum.ingame.actorContainer.forEach { it ->
if (it is Luminous && it is ActorWithBody) {
// put lanterns to the area the luminantBox is occupying
for (lightBox in it.lightBoxList) {
val lightBoxX = it.hitbox.posX + lightBox.posX
val lightBoxY = it.hitbox.posY + lightBox.posY
val lightBoxW = lightBox.width
val lightBoxH = lightBox.height
for (y in lightBoxY.div(TILE_SIZE).floorInt()
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorInt()) {
for (x in lightBoxX.div(TILE_SIZE).floorInt()
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorInt()) {
lanternMap.add(Lantern(x, y, it.luminosity))
// Q&D fix for Roundworld anomaly
lanternMap.add(Lantern(x + world.width, y, it.luminosity))
lanternMap.add(Lantern(x - world.width, y, it.luminosity))
}
}
}
}
}
} }
private fun calculate(x: Int, y: Int): Int = calculate(x, y, false) private fun calculate(x: Int, y: Int): Int = calculate(x, y, false)
@@ -266,9 +266,14 @@ object LightmapRenderer {
// END MIX TILE // END MIX TILE
// mix luminous actor // mix luminous actor
for ((posX, posY, luminosity) in lanternMap) { /*for ((posX, posY, luminosity) in lanternMap) {
if (posX == x && posY == y) if (posX == x && posY == y)
lightLevelThis = lightLevelThis maxBlend luminosity // maximise to not exceed 1.0 with normal (<= 1.0) light lightLevelThis = lightLevelThis maxBlend luminosity // maximise to not exceed 1.0 with normal (<= 1.0) light
}*/
for (i in 0..lanternMap.size - 1) {
val lmap = lanternMap[i]
if (lmap.posX == x && lmap.posY == y)
lightLevelThis = lightLevelThis maxBlend lmap.luminosity // maximise to not exceed 1.0 with normal (<= 1.0) light
} }

View File

@@ -6,7 +6,7 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.tileproperties.Tile import net.torvald.terrarum.tileproperties.Tile
import net.torvald.terrarum.tileproperties.TileCodex import net.torvald.terrarum.tileproperties.TileCodex
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.terrarum.concurrent.ThreadPool import net.torvald.terrarum.concurrent.ThreadParallel
import net.torvald.terrarum.blendMul import net.torvald.terrarum.blendMul
import net.torvald.terrarum.blendNormal import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.mapdrawer.FeaturesDrawer.TILE_SIZE import net.torvald.terrarum.mapdrawer.FeaturesDrawer.TILE_SIZE

View File

@@ -7,7 +7,7 @@ import com.jme3.math.FastMath
import com.sudoplay.joise.Joise import com.sudoplay.joise.Joise
import com.sudoplay.joise.module.* import com.sudoplay.joise.module.*
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.concurrent.ThreadPool import net.torvald.terrarum.concurrent.ThreadParallel
import net.torvald.terrarum.gameactors.ThreadActorUpdate import net.torvald.terrarum.gameactors.ThreadActorUpdate
import net.torvald.terrarum.gameactors.roundInt import net.torvald.terrarum.gameactors.roundInt
import java.util.* import java.util.*
@@ -689,7 +689,7 @@ object WorldGenerator {
if (Terrarum.MULTITHREAD) { if (Terrarum.MULTITHREAD) {
// set up indices // set up indices
for (i in 0..Terrarum.THREADS - 1) { for (i in 0..Terrarum.THREADS - 1) {
ThreadPool.map( ThreadParallel.map(
i, i,
ThreadProcessNoiseLayers( ThreadProcessNoiseLayers(
HEIGHT.toFloat().div(Terrarum.THREADS).times(i).roundInt(), HEIGHT.toFloat().div(Terrarum.THREADS).times(i).roundInt(),
@@ -700,7 +700,7 @@ object WorldGenerator {
) )
} }
ThreadPool.startAll() ThreadParallel.startAll()
// FIXME game starts prematurely // FIXME game starts prematurely
/* Console: /* Console:
[mapgenerator] Seed: 85336530 [mapgenerator] Seed: 85336530