open/cave mix control via tile survey

This commit is contained in:
minjaesong
2023-11-29 00:48:55 +09:00
parent 544024c282
commit bbfd3cf881
7 changed files with 65 additions and 34 deletions

View File

@@ -230,14 +230,14 @@ object AudioMixer: Disposable {
it.pan = (it.pan - 0.001f).coerceIn(-1f, 1f)
}
}*/
if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
/*if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
convolveBusOpen.volume = (convolveBusOpen.volume + 0.001).coerceIn(0.0, 1.0)
convolveBusCave.volume = 1.0 - convolveBusOpen.volume
}
else if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
convolveBusOpen.volume = (convolveBusOpen.volume - 0.001).coerceIn(0.0, 1.0)
convolveBusCave.volume = 1.0 - convolveBusOpen.volume
}
}*/

View File

@@ -20,11 +20,11 @@ object TileSurvey {
val height: Int,
val spatialGranularity: Int, // 1: survey every (w*h) tile, 2: survey every other (w*h/4) tile ...
val temporalGranularity: Int, // 1: survey every frame, 2: every other frame ...
val predicate: (GameWorld, Int, Int) -> Boolean
val predicate: (GameWorld, Int, Int) -> Float
)
private val proposals = HashMap<String, SurveyProposal>()
private val results = HashMap<String, Pair<Double, Int>>() // (matching tiles/actually surveyed tiles)
private val results = HashMap<String, Pair<Double, Float>>() // (ratio of accumulated data to total tile count / raw accumulated data)
fun submitProposal(proposal: SurveyProposal) {
proposals[proposal.surveyIdentifier] = proposal
@@ -54,11 +54,11 @@ object TileSurvey {
val for_x_end = ceil(player.intTilewiseHitbox.centeredX + proposal.width / 2.0).toInt()
val for_y_end = ceil(player.intTilewiseHitbox.centeredY + proposal.height / 2.0).toInt()
var akku = 0
var akku = 0f
for (y in for_y_start until for_y_end step proposal.spatialGranularity) {
for (x in for_x_start until for_x_end step proposal.spatialGranularity) {
if (proposal.predicate(world, x, y)) akku += 1
akku += proposal.predicate(world, x, y)
}
}

View File

@@ -31,6 +31,8 @@ class Material {
var rcs: Int = 10
var sondrefl: Float = 0f
/**
* Mainly intended to be used by third-party modules
*/
@@ -73,6 +75,7 @@ class MaterialCodex {
prop.identifier = it.get("idst").toUpperCase()
prop.toolReach = it.intVal("reach")
prop.rcs = it.intVal("rcs")
prop.sondrefl = it.floatVal("sondrefl")
materialProps[prop.identifier] = prop

View File

@@ -278,6 +278,10 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
CREATE_NEW, LOAD_FROM
}
private val soundReflectiveMaterials = hashSetOf(
""
)
override fun show() {
//initViewPort(AppLoader.terrarumAppConfig.screenW, AppLoader.terrarumAppConfig.screenH)
@@ -295,6 +299,17 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
super.show() // this function sets gameInitialised = true
TileSurvey.submitProposal(
TileSurvey.SurveyProposal(
"basegame.Ingame.audioReflection", 72, 48, 2, 4
) { world, x, y ->
val tileProp = BlockCodex[world.getTileFromTerrain(x, y)]
val wallProp = BlockCodex[world.getTileFromWall(x, y)]
val prop = if (tileProp.isSolid && !tileProp.isActorBlock) tileProp else wallProp
MaterialCodex[prop.material].sondrefl
}
)
}
data class NewGameParams(
@@ -869,9 +884,17 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
oldCamX = WorldCamera.x
oldPlayerX = actorNowPlaying?.hitbox?.canonicalX ?: 0.0
// update audio mixer
val ratio = (TileSurvey.getRatio("basegame.Ingame.audioReflection") ?: 0.0).coerceIn(0.0, 1.0)
AudioMixer.convolveBusCave.volume = ratio
AudioMixer.convolveBusOpen.volume = 1.0 - ratio
WORLD_UPDATE_TIMER += 1
// run benchmark if F2 is on
if (KeyToggler.isOn(Input.Keys.F2)) {
deltaTeeBenchmarks.appendHead(1f / Gdx.graphics.deltaTime)

View File

@@ -33,12 +33,12 @@ object FeaturesDrawer {
TileSurvey.submitProposal(
TileSurvey.SurveyProposal(
"basegame.FeaturesDrawer.coldTiles", 72, 48, 2, 2
) { world, x, y -> BlockCodex[world.getTileFromTerrain(x, y)].hasTag("COLD") }
) { world, x, y -> BlockCodex[world.getTileFromTerrain(x, y)].hasTag("COLD").toInt().toFloat() }
)
TileSurvey.submitProposal(
TileSurvey.SurveyProposal(
"basegame.FeaturesDrawer.warmTiles", 72, 48, 2, 2
) { world, x, y -> BlockCodex[world.getTileFromTerrain(x, y)].hasTag("WARM") }
) { world, x, y -> BlockCodex[world.getTileFromTerrain(x, y)].hasTag("WARM").toInt().toFloat() }
)
}