From 087c4616b6418a8ed0df770da392c6226aa762d8 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Fri, 29 Sep 2023 22:45:59 +0700 Subject: [PATCH] Add base movement parameters --- .../dbotthepony/kstarbound/GlobalDefaults.kt | 9 +- .../kstarbound/defs/BaseMovementParameters.kt | 97 +++++++++++++++++++ .../kstarbound/defs/MovementParameters.kt | 28 ++++++ .../defs/player/PlayerMovementParameters.kt | 52 ++-------- 4 files changed, 140 insertions(+), 46 deletions(-) create mode 100644 src/main/kotlin/ru/dbotthepony/kstarbound/defs/BaseMovementParameters.kt create mode 100644 src/main/kotlin/ru/dbotthepony/kstarbound/defs/MovementParameters.kt diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/GlobalDefaults.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/GlobalDefaults.kt index 63fa650b..b8717210 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/GlobalDefaults.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/GlobalDefaults.kt @@ -1,6 +1,7 @@ package ru.dbotthepony.kstarbound import org.apache.logging.log4j.LogManager +import ru.dbotthepony.kstarbound.defs.MovementParameters import ru.dbotthepony.kstarbound.defs.player.PlayerMovementParameters import java.util.concurrent.ForkJoinPool import java.util.concurrent.ForkJoinTask @@ -9,7 +10,10 @@ import kotlin.reflect.KMutableProperty0 object GlobalDefaults { private val LOGGER = LogManager.getLogger() - var defaultMovementParameters = PlayerMovementParameters() + var playerMovementParameters = PlayerMovementParameters() + private set + + var movementParameters = MovementParameters() private set private object EmptyTask : ForkJoinTask() { @@ -44,7 +48,8 @@ object GlobalDefaults { fun load(log: ILoadingLog, executor: ForkJoinPool): List> { val tasks = ArrayList>() - tasks.add(load("/default_actor_movement.config", ::defaultMovementParameters, executor)) + tasks.add(load("/default_actor_movement.config", ::playerMovementParameters, executor)) + tasks.add(load("/default_movement.config", ::movementParameters, executor)) return listOf(executor.submit { val line = log.line("Loading global defaults...") diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/BaseMovementParameters.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/BaseMovementParameters.kt new file mode 100644 index 00000000..93b0cb23 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/BaseMovementParameters.kt @@ -0,0 +1,97 @@ +package ru.dbotthepony.kstarbound.defs + +import com.google.common.collect.ImmutableSet +import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory +import ru.dbotthepony.kstarbound.io.json.builder.JsonImplementation +import ru.dbotthepony.kstarbound.util.KOptional + +@JsonImplementation(BaseMovementParameters.Impl::class) +interface BaseMovementParameters { + val mass: KOptional + val gravityMultiplier: KOptional + val liquidBuoyancy: KOptional + val airBuoyancy: KOptional + val bounceFactor: KOptional + + // If set to true, during an update that has more than one internal movement + // step, the movement will stop on the first bounce. + val stopOnFirstBounce: KOptional + + // Cheat when sliding on the ground, by trying to correct upwards before + // other directions (within a set limit). Allows smooth sliding along + // horizontal ground without losing horizontal speed. + val enableSurfaceSlopeCorrection: KOptional + val slopeSlidingFactor: KOptional + val maxMovementPerStep: KOptional + val maximumCorrection: KOptional + val speedLimit: KOptional + + val stickyCollision: KOptional + val stickyForce: KOptional + + val airFriction: KOptional + val liquidFriction: KOptional + val groundFriction: KOptional + + val collisionEnabled: KOptional + val frictionEnabled: KOptional + val gravityEnabled: KOptional + + val maximumPlatformCorrection: KOptional + val maximumPlatformCorrectionVelocityFactor: KOptional + + val physicsEffectCategories: KOptional> + + @JsonFactory + data class Impl( + override val mass: KOptional = KOptional.empty(), + override val gravityMultiplier: KOptional = KOptional.empty(), + override val liquidBuoyancy: KOptional = KOptional.empty(), + override val airBuoyancy: KOptional = KOptional.empty(), + override val bounceFactor: KOptional = KOptional.empty(), + override val stopOnFirstBounce: KOptional = KOptional.empty(), + override val enableSurfaceSlopeCorrection: KOptional = KOptional.empty(), + override val slopeSlidingFactor: KOptional = KOptional.empty(), + override val maxMovementPerStep: KOptional = KOptional.empty(), + override val maximumCorrection: KOptional = KOptional.empty(), + override val speedLimit: KOptional = KOptional.empty(), + override val stickyCollision: KOptional = KOptional.empty(), + override val stickyForce: KOptional = KOptional.empty(), + override val airFriction: KOptional = KOptional.empty(), + override val liquidFriction: KOptional = KOptional.empty(), + override val groundFriction: KOptional = KOptional.empty(), + override val collisionEnabled: KOptional = KOptional.empty(), + override val frictionEnabled: KOptional = KOptional.empty(), + override val gravityEnabled: KOptional = KOptional.empty(), + override val maximumPlatformCorrection: KOptional = KOptional.empty(), + override val maximumPlatformCorrectionVelocityFactor: KOptional = KOptional.empty(), + override val physicsEffectCategories: KOptional> = KOptional.empty(), + ) : BaseMovementParameters { + fun merge(other: Impl): Impl { + return Impl( + mass = mass.or(other.mass), + gravityMultiplier = gravityMultiplier.or(other.gravityMultiplier), + liquidBuoyancy = liquidBuoyancy.or(other.liquidBuoyancy), + airBuoyancy = airBuoyancy.or(other.airBuoyancy), + bounceFactor = bounceFactor.or(other.bounceFactor), + stopOnFirstBounce = stopOnFirstBounce.or(other.stopOnFirstBounce), + enableSurfaceSlopeCorrection = enableSurfaceSlopeCorrection.or(other.enableSurfaceSlopeCorrection), + slopeSlidingFactor = slopeSlidingFactor.or(other.slopeSlidingFactor), + maxMovementPerStep = maxMovementPerStep.or(other.maxMovementPerStep), + maximumCorrection = maximumCorrection.or(other.maximumCorrection), + speedLimit = speedLimit.or(other.speedLimit), + stickyCollision = stickyCollision.or(other.stickyCollision), + stickyForce = stickyForce.or(other.stickyForce), + airFriction = airFriction.or(other.airFriction), + liquidFriction = liquidFriction.or(other.liquidFriction), + groundFriction = groundFriction.or(other.groundFriction), + collisionEnabled = collisionEnabled.or(other.collisionEnabled), + frictionEnabled = frictionEnabled.or(other.frictionEnabled), + gravityEnabled = gravityEnabled.or(other.gravityEnabled), + maximumPlatformCorrection = maximumPlatformCorrection.or(other.maximumPlatformCorrection), + maximumPlatformCorrectionVelocityFactor = maximumPlatformCorrectionVelocityFactor.or(other.maximumPlatformCorrectionVelocityFactor), + physicsEffectCategories = physicsEffectCategories.or(other.physicsEffectCategories), + ) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/MovementParameters.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/MovementParameters.kt new file mode 100644 index 00000000..07b60aa3 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/MovementParameters.kt @@ -0,0 +1,28 @@ +package ru.dbotthepony.kstarbound.defs + +import com.google.common.collect.ImmutableList +import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory +import ru.dbotthepony.kstarbound.io.json.builder.JsonFlat +import ru.dbotthepony.kstarbound.util.KOptional +import ru.dbotthepony.kvector.vector.Vector2d + +@JsonFactory +data class MovementParameters( + @JsonFlat + val base: BaseMovementParameters.Impl = BaseMovementParameters.Impl(), + + val discontinuityThreshold: KOptional = KOptional.empty(), + val collisionPoly: KOptional> = KOptional.empty(), + val ignorePlatformCollision: KOptional = KOptional.empty(), + val restDuration: KOptional = KOptional.empty(), +) : BaseMovementParameters by base { + fun merge(other: MovementParameters): MovementParameters { + return MovementParameters( + base = base.merge(other.base), + discontinuityThreshold = discontinuityThreshold.or(other.discontinuityThreshold), + collisionPoly = collisionPoly.or(other.collisionPoly), + ignorePlatformCollision = ignorePlatformCollision.or(other.ignorePlatformCollision), + restDuration = restDuration.or(other.restDuration), + ) + } +} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/PlayerMovementParameters.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/PlayerMovementParameters.kt index b8eea93d..81763402 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/PlayerMovementParameters.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/PlayerMovementParameters.kt @@ -2,38 +2,28 @@ package ru.dbotthepony.kstarbound.defs.player import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableSet +import ru.dbotthepony.kstarbound.defs.BaseMovementParameters import ru.dbotthepony.kstarbound.defs.JumpProfile import ru.dbotthepony.kstarbound.io.json.builder.JsonAlias import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory +import ru.dbotthepony.kstarbound.io.json.builder.JsonFlat import ru.dbotthepony.kstarbound.util.KOptional import ru.dbotthepony.kvector.vector.Vector2d @JsonFactory data class PlayerMovementParameters( - val mass: KOptional = KOptional.empty(), - val gravityMultiplier: KOptional = KOptional.empty(), - val liquidBuoyancy: KOptional = KOptional.empty(), - val airBuoyancy: KOptional = KOptional.empty(), - val bounceFactor: KOptional = KOptional.empty(), - val stopOnFirstBounce: KOptional = KOptional.empty(), - val enableSurfaceSlopeCorrection: KOptional = KOptional.empty(), - val slopeSlidingFactor: KOptional = KOptional.empty(), - val maxMovementPerStep: KOptional = KOptional.empty(), - val maximumCorrection: KOptional = KOptional.empty(), - val speedLimit: KOptional = KOptional.empty(), + @JsonFlat + val base: BaseMovementParameters.Impl = BaseMovementParameters.Impl(), @JsonAlias("collisionPoly") val standingPoly: KOptional> = KOptional.empty(), @JsonAlias("collisionPoly") val crouchingPoly: KOptional> = KOptional.empty(), - val stickyCollision: KOptional = KOptional.empty(), - val stickyForce: KOptional = KOptional.empty(), val walkSpeed: KOptional = KOptional.empty(), val runSpeed: KOptional = KOptional.empty(), val flySpeed: KOptional = KOptional.empty(), - val airFriction: KOptional = KOptional.empty(), - val liquidFriction: KOptional = KOptional.empty(), + val minimumLiquidPercentage: KOptional = KOptional.empty(), val liquidImpedance: KOptional = KOptional.empty(), val normalGroundFriction: KOptional = KOptional.empty(), @@ -47,41 +37,21 @@ data class PlayerMovementParameters( val fallStatusSpeedMin: KOptional = KOptional.empty(), val fallThroughSustainFrames: KOptional = KOptional.empty(), - val maximumPlatformCorrection: KOptional = KOptional.empty(), - val maximumPlatformCorrectionVelocityFactor: KOptional = KOptional.empty(), - val physicsEffectCategories: KOptional> = KOptional.empty(), + val groundMovementMinimumSustain: KOptional = KOptional.empty(), val groundMovementMaximumSustain: KOptional = KOptional.empty(), val groundMovementCheckDistance: KOptional = KOptional.empty(), - val collisionEnabled: KOptional = KOptional.empty(), - val frictionEnabled: KOptional = KOptional.empty(), - val gravityEnabled: KOptional = KOptional.empty(), - val pathExploreRate: KOptional = KOptional.empty(), -) { +) : BaseMovementParameters by base { fun merge(other: PlayerMovementParameters): PlayerMovementParameters { return PlayerMovementParameters( - mass = mass.or(other.mass), - gravityMultiplier = gravityMultiplier.or(other.gravityMultiplier), - liquidBuoyancy = liquidBuoyancy.or(other.liquidBuoyancy), - airBuoyancy = airBuoyancy.or(other.airBuoyancy), - bounceFactor = bounceFactor.or(other.bounceFactor), - stopOnFirstBounce = stopOnFirstBounce.or(other.stopOnFirstBounce), - enableSurfaceSlopeCorrection = enableSurfaceSlopeCorrection.or(other.enableSurfaceSlopeCorrection), - slopeSlidingFactor = slopeSlidingFactor.or(other.slopeSlidingFactor), - maxMovementPerStep = maxMovementPerStep.or(other.maxMovementPerStep), - maximumCorrection = maximumCorrection.or(other.maximumCorrection), - speedLimit = speedLimit.or(other.speedLimit), + base = base.merge(other.base), standingPoly = standingPoly.or(other.standingPoly), crouchingPoly = crouchingPoly.or(other.crouchingPoly), - stickyCollision = stickyCollision.or(other.stickyCollision), - stickyForce = stickyForce.or(other.stickyForce), walkSpeed = walkSpeed.or(other.walkSpeed), runSpeed = runSpeed.or(other.runSpeed), flySpeed = flySpeed.or(other.flySpeed), - airFriction = airFriction.or(other.airFriction), - liquidFriction = liquidFriction.or(other.liquidFriction), minimumLiquidPercentage = minimumLiquidPercentage.or(other.minimumLiquidPercentage), liquidImpedance = liquidImpedance.or(other.liquidImpedance), normalGroundFriction = normalGroundFriction.or(other.normalGroundFriction), @@ -93,15 +63,9 @@ data class PlayerMovementParameters( liquidJumpProfile = liquidJumpProfile.merge(other.liquidJumpProfile), fallStatusSpeedMin = fallStatusSpeedMin.or(other.fallStatusSpeedMin), fallThroughSustainFrames = fallThroughSustainFrames.or(other.fallThroughSustainFrames), - maximumPlatformCorrection = maximumPlatformCorrection.or(other.maximumPlatformCorrection), - maximumPlatformCorrectionVelocityFactor = maximumPlatformCorrectionVelocityFactor.or(other.maximumPlatformCorrectionVelocityFactor), - physicsEffectCategories = physicsEffectCategories.or(other.physicsEffectCategories), groundMovementMinimumSustain = groundMovementMinimumSustain.or(other.groundMovementMinimumSustain), groundMovementMaximumSustain = groundMovementMaximumSustain.or(other.groundMovementMaximumSustain), groundMovementCheckDistance = groundMovementCheckDistance.or(other.groundMovementCheckDistance), - collisionEnabled = collisionEnabled.or(other.collisionEnabled), - frictionEnabled = frictionEnabled.or(other.frictionEnabled), - gravityEnabled = gravityEnabled.or(other.gravityEnabled), ) } }