Compare commits
8 Commits
f9b339c0e4
...
826419b545
Author | SHA1 | Date | |
---|---|---|---|
826419b545 | |||
f60ad2a712 | |||
297fb46bde | |||
79381845b0 | |||
8d8143c914 | |||
889c481d0d | |||
0c169e58ec | |||
b223d6ea6c |
@ -7,8 +7,7 @@ import jnr.ffi.Runtime;
|
|||||||
import jnr.ffi.annotations.IgnoreError;
|
import jnr.ffi.annotations.IgnoreError;
|
||||||
import jnr.ffi.annotations.LongLong;
|
import jnr.ffi.annotations.LongLong;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
@SuppressWarnings({"UnnecessaryModifier", "SpellCheckingInspection", "unused"})
|
@SuppressWarnings({"UnnecessaryModifier", "SpellCheckingInspection", "unused"})
|
||||||
public interface LuaJNR {
|
public interface LuaJNR {
|
||||||
@ -34,7 +33,7 @@ public interface LuaJNR {
|
|||||||
@IgnoreError
|
@IgnoreError
|
||||||
public long lua_atpanic(@NotNull Pointer luaState, @LongLong long fn);
|
public long lua_atpanic(@NotNull Pointer luaState, @LongLong long fn);
|
||||||
@IgnoreError
|
@IgnoreError
|
||||||
public long luaL_traceback(@NotNull Pointer luaState, @NotNull Pointer forState, @NotNull String message, int level);
|
public long luaL_traceback(@NotNull Pointer luaState, @NotNull Pointer forState, @Nullable String message, int level);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new thread, pushes it on the stack, and returns a pointer to a lua_State that represents this new thread. The new thread returned by this function shares with the original thread its global environment, but has an independent execution stack.
|
* Creates a new thread, pushes it on the stack, and returns a pointer to a lua_State that represents this new thread. The new thread returned by this function shares with the original thread its global environment, but has an independent execution stack.
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package ru.dbotthepony.kstarbound.io
|
package ru.dbotthepony.kstarbound.io
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectFunction
|
import it.unimi.dsi.fastutil.objects.Object2ObjectFunction
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap
|
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMap
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps
|
||||||
import ru.dbotthepony.kommons.gson.get
|
import ru.dbotthepony.kommons.gson.get
|
||||||
import ru.dbotthepony.kommons.io.readBinaryString
|
import ru.dbotthepony.kommons.io.readBinaryString
|
||||||
import ru.dbotthepony.kommons.io.readVarInt
|
import ru.dbotthepony.kommons.io.readVarInt
|
||||||
@ -48,10 +51,16 @@ class StarboundPak(val path: File, callback: (finished: Boolean, status: String)
|
|||||||
get() = false
|
get() = false
|
||||||
|
|
||||||
private var frozen = false
|
private var frozen = false
|
||||||
private val innerChildren = Object2ObjectLinkedOpenHashMap<String, IStarboundFile>()
|
private var innerChildren: Object2ObjectMap<String, IStarboundFile> = Object2ObjectArrayMap(2)
|
||||||
|
|
||||||
fun put(value: IStarboundFile) {
|
fun put(value: IStarboundFile) {
|
||||||
check(!frozen) { "Can't put, already frozen!" }
|
check(!frozen) { "Can't put, already frozen!" }
|
||||||
|
|
||||||
|
if (innerChildren is Object2ObjectArrayMap && innerChildren.size >= 8) {
|
||||||
|
innerChildren = Object2ObjectLinkedOpenHashMap(innerChildren)
|
||||||
|
children = Object2ObjectMaps.unmodifiable(innerChildren)
|
||||||
|
}
|
||||||
|
|
||||||
innerChildren[value.name] = value
|
innerChildren[value.name] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +70,8 @@ class StarboundPak(val path: File, callback: (finished: Boolean, status: String)
|
|||||||
return innerChildren.computeIfAbsent(name, Object2ObjectFunction { SBDirectory(it as String, this) }) as? SBDirectory ?: throw IllegalStateException("$name already exists (in ${computeFullPath()})")
|
return innerChildren.computeIfAbsent(name, Object2ObjectFunction { SBDirectory(it as String, this) }) as? SBDirectory ?: throw IllegalStateException("$name already exists (in ${computeFullPath()})")
|
||||||
}
|
}
|
||||||
|
|
||||||
override val children: Map<String, IStarboundFile> = Collections.unmodifiableMap(innerChildren)
|
override var children: Map<String, IStarboundFile> = Object2ObjectMaps.unmodifiable(innerChildren)
|
||||||
|
private set
|
||||||
|
|
||||||
fun freeze() {
|
fun freeze() {
|
||||||
check(!frozen) { "Already frozen" }
|
check(!frozen) { "Already frozen" }
|
||||||
|
@ -71,15 +71,13 @@ class LuaSharedState(val handlesThread: LuaThread, private val cleanable: Cleana
|
|||||||
val peek = it.peek()
|
val peek = it.peek()
|
||||||
|
|
||||||
if (peek == LuaType.STRING) {
|
if (peek == LuaType.STRING) {
|
||||||
it.lua.traceback(it.lua.getString()!!, 1)
|
val err = LuaRuntimeException(it.lua.traceback(it.lua.getString(), 1))
|
||||||
val err = LuaRuntimeException(it.lua.getString())
|
|
||||||
it.lua.push(err)
|
it.lua.push(err)
|
||||||
} else if (peek == LuaType.USERDATA) {
|
} else if (peek == LuaType.USERDATA) {
|
||||||
val obj = it.nextObject<Any>()
|
val obj = it.nextObject<Any>()
|
||||||
|
|
||||||
if (obj is Throwable && obj !is LuaRuntimeException) {
|
if (obj is Throwable && obj !is LuaRuntimeException) {
|
||||||
it.lua.traceback(obj.toString(), 1)
|
val err = LuaRuntimeException(it.lua.traceback(obj.toString(), 1), cause = obj, writeStackTrace = false)
|
||||||
val err = LuaRuntimeException(it.lua.getString(), cause = obj, writeStackTrace = false)
|
|
||||||
it.lua.push(err)
|
it.lua.push(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -340,8 +340,9 @@ class LuaThread private constructor(
|
|||||||
return callConditional(numResults, { block(this); true })!!
|
return callConditional(numResults, { block(this); true })!!
|
||||||
}
|
}
|
||||||
|
|
||||||
fun traceback(message: String, level: Int = 0) {
|
fun traceback(message: String? = null, level: Int = 0): String {
|
||||||
LuaJNR.INSTANCE.luaL_traceback(pointer, pointer, message, level)
|
LuaJNR.INSTANCE.luaL_traceback(pointer, pointer, message, level)
|
||||||
|
return popString()!!
|
||||||
}
|
}
|
||||||
|
|
||||||
fun invokeGlobal(name: String): Boolean {
|
fun invokeGlobal(name: String): Boolean {
|
||||||
@ -1212,10 +1213,13 @@ class LuaThread private constructor(
|
|||||||
|
|
||||||
fun nextBoolean(position: Int = this.position++): Boolean {
|
fun nextBoolean(position: Int = this.position++): Boolean {
|
||||||
if (position !in 1 ..this.top)
|
if (position !in 1 ..this.top)
|
||||||
throw IllegalArgumentException("bad argument #$position: boolean expected, got nil")
|
return false
|
||||||
|
|
||||||
return this@LuaThread.getBoolean(position)
|
return when (typeAt(position)) {
|
||||||
?: throw IllegalArgumentException("bad argument #$position: boolean expected, got ${this@LuaThread.typeAt(position)}")
|
LuaType.NONE, LuaType.NIL -> false
|
||||||
|
LuaType.BOOLEAN -> this@LuaThread.getBooleanRaw(position)
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1665,8 +1669,18 @@ class LuaThread private constructor(
|
|||||||
val num = value.asNumber
|
val num = value.asNumber
|
||||||
|
|
||||||
when (num) {
|
when (num) {
|
||||||
is Int, is Long -> this.push(num.toLong())
|
is Int, is Long -> push(num.toLong())
|
||||||
else -> this.push(num.toDouble())
|
is Float, is Double -> push(num.toDouble())
|
||||||
|
else -> {
|
||||||
|
// lazy parsed number
|
||||||
|
val str = value.asString
|
||||||
|
|
||||||
|
if (str.none { it == '.' } || str.endsWith(".0")) {
|
||||||
|
push(num.toLong())
|
||||||
|
} else {
|
||||||
|
push(num.toDouble())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (value.isString) {
|
} else if (value.isString) {
|
||||||
this.push(value.asString)
|
this.push(value.asString)
|
||||||
@ -1711,7 +1725,8 @@ class LuaThread private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "LuaThread at ${pointer.address()}"
|
val p = pointer.address().toString(16)
|
||||||
|
return "LuaThread at 0x${if (p.length < 12) "0".repeat(12 - p.length) else ""}${p}"
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -271,8 +271,8 @@ fun provideAnimatorBindings(self: Animator, lua: LuaThread) {
|
|||||||
lua.pushBinding(self, "rotateGroup", ::rotateGroup)
|
lua.pushBinding(self, "rotateGroup", ::rotateGroup)
|
||||||
lua.pushBinding(self, "currentRotationAngle", ::currentRotationAngle)
|
lua.pushBinding(self, "currentRotationAngle", ::currentRotationAngle)
|
||||||
lua.pushBinding(self, "targetRotationAngle", ::targetRotationAngle)
|
lua.pushBinding(self, "targetRotationAngle", ::targetRotationAngle)
|
||||||
lua.pushBinding(self, "translateTransformGroup", ::translateTransformGroup)
|
lua.pushBinding(self, "translateTransformationGroup", ::translateTransformGroup)
|
||||||
lua.pushBinding(self, "rotateTransformGroup", ::rotateTransformGroup)
|
lua.pushBinding(self, "rotateTransformationGroup", ::rotateTransformGroup)
|
||||||
lua.pushBinding(self, "scaleTransformationGroup", ::scaleTransformationGroup)
|
lua.pushBinding(self, "scaleTransformationGroup", ::scaleTransformationGroup)
|
||||||
lua.pushBinding(self, "transformTransformationGroup", ::transformTransformationGroup)
|
lua.pushBinding(self, "transformTransformationGroup", ::transformTransformationGroup)
|
||||||
lua.pushBinding(self, "resetTransformationGroup", ::resetTransformationGroup)
|
lua.pushBinding(self, "resetTransformationGroup", ::resetTransformationGroup)
|
||||||
|
@ -286,6 +286,7 @@ private fun createBehaviorTree(args: LuaThread.ArgStack): Int {
|
|||||||
|
|
||||||
push(blackboard)
|
push(blackboard)
|
||||||
push(root)
|
push(root)
|
||||||
|
push(mergedParams.name)
|
||||||
}[0]
|
}[0]
|
||||||
|
|
||||||
args.lua.call {
|
args.lua.call {
|
||||||
|
@ -613,7 +613,7 @@ class ActorMovementController() : MovementController() {
|
|||||||
if (isGroundMovement) {
|
if (isGroundMovement) {
|
||||||
this.isRunning = isRunning && controlMove != null
|
this.isRunning = isRunning && controlMove != null
|
||||||
this.isWalking = !isRunning && controlMove != null
|
this.isWalking = !isRunning && controlMove != null
|
||||||
this.isCrouching = controlCrouch && controlMove != null
|
this.isCrouching = controlCrouch && controlMove == null
|
||||||
}
|
}
|
||||||
|
|
||||||
isFlying = controlFly != null
|
isFlying = controlFly != null
|
||||||
|
@ -327,6 +327,10 @@ class MonsterEntity(val variant: MonsterVariant, level: Double? = null) : ActorE
|
|||||||
|
|
||||||
private val deathDamageKinds = ObjectArraySet<String>()
|
private val deathDamageKinds = ObjectArraySet<String>()
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "MonsterEntity[${variant.type}@${variant.seed} / ${if (isInWorld) world.toString() else "not in world"} / $position]"
|
||||||
|
}
|
||||||
|
|
||||||
override fun experienceDamage(damage: DamageRequestPacket): List<DamageNotification> {
|
override fun experienceDamage(damage: DamageRequestPacket): List<DamageNotification> {
|
||||||
val notifications = statusController.experienceDamage(damage.request)
|
val notifications = statusController.experienceDamage(damage.request)
|
||||||
val totalDamage = notifications.sumOf { it.healthLost }
|
val totalDamage = notifications.sumOf { it.healthLost }
|
||||||
|
@ -71,7 +71,13 @@ local function blackboardSet(self, t, key, value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function blackboardPrototype:set(t, key, value)
|
function blackboardPrototype:set(t, key, value)
|
||||||
blackboardSet(self, mappedParameterTypes[t], key, value)
|
local lookup = mappedParameterTypes[t]
|
||||||
|
|
||||||
|
if not lookup then
|
||||||
|
error('unknown blackboard value type ' .. tostring(t))
|
||||||
|
end
|
||||||
|
|
||||||
|
blackboardSet(self, lookup, key, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
function blackboardPrototype:setRaw(t, key, value)
|
function blackboardPrototype:setRaw(t, key, value)
|
||||||
@ -263,21 +269,18 @@ do
|
|||||||
return FAILURE
|
return FAILURE
|
||||||
end
|
end
|
||||||
|
|
||||||
if nodeStatus == nil then
|
|
||||||
--table.remove(stack)
|
|
||||||
return RUNNING
|
|
||||||
end
|
|
||||||
|
|
||||||
if nodeExtra ~= nil then
|
if nodeExtra ~= nil then
|
||||||
blackboard:setOutput(self, nodeExtra)
|
blackboard:setOutput(self, nodeExtra)
|
||||||
end
|
end
|
||||||
|
|
||||||
--table.remove(stack)
|
--table.remove(stack)
|
||||||
|
|
||||||
if nodeStatus then
|
if nodeStatus == nil then
|
||||||
return SUCCESS
|
return RUNNING
|
||||||
else
|
elseif nodeStatus == false then
|
||||||
return FAILURE
|
return FAILURE
|
||||||
|
else
|
||||||
|
return SUCCESS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -342,23 +345,13 @@ do
|
|||||||
return FAILURE
|
return FAILURE
|
||||||
end
|
end
|
||||||
|
|
||||||
if nodeStatus == nil then
|
if nodeStatus == true then
|
||||||
local s = coroutine_status(coroutine)
|
|
||||||
|
|
||||||
if s == 'dead' then
|
|
||||||
-- quite unexpected, but whatever
|
|
||||||
--table.remove(stack)
|
|
||||||
return SUCCESS
|
return SUCCESS
|
||||||
|
elseif nodeStatus == false then
|
||||||
|
return FAILURE
|
||||||
else
|
else
|
||||||
self.coroutine = coroutine
|
self.coroutine = coroutine
|
||||||
end
|
end
|
||||||
elseif nodeStatus then
|
|
||||||
--table.remove(stack)
|
|
||||||
return SUCCESS
|
|
||||||
else
|
|
||||||
--table.remove(stack)
|
|
||||||
return FAILURE
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
@ -377,30 +370,13 @@ do
|
|||||||
return FAILURE
|
return FAILURE
|
||||||
end
|
end
|
||||||
|
|
||||||
if nodeStatus == nil then
|
if nodeStatus == true then
|
||||||
-- another yield OR unexpected return?
|
|
||||||
|
|
||||||
local s = coroutine_status(self.coroutine)
|
|
||||||
|
|
||||||
if s == 'dead' then
|
|
||||||
self.coroutine = nil
|
|
||||||
--table.remove(stack)
|
|
||||||
return SUCCESS
|
return SUCCESS
|
||||||
end
|
elseif nodeStatus == false then
|
||||||
else
|
|
||||||
-- yield or return with status
|
|
||||||
self.coroutine = nil
|
|
||||||
|
|
||||||
if nodeStatus then
|
|
||||||
--table.remove(stack)
|
|
||||||
return SUCCESS
|
|
||||||
else
|
|
||||||
--table.remove(stack)
|
|
||||||
return FAILURE
|
return FAILURE
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function decoratorNode:reset()
|
function decoratorNode:reset()
|
||||||
@ -461,6 +437,9 @@ function seqNode:run(delta, blackboard, stack)
|
|||||||
|
|
||||||
self.index = self.index + 1
|
self.index = self.index + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if isSelector then return FAILURE end
|
||||||
|
return SUCCESS
|
||||||
end
|
end
|
||||||
|
|
||||||
function seqNode:reset()
|
function seqNode:reset()
|
||||||
@ -594,13 +573,19 @@ function dynNode:run(delta, blackboard, stack)
|
|||||||
self.calls = self.calls + 1
|
self.calls = self.calls + 1
|
||||||
--table.insert(stack, 'DynamicNode')
|
--table.insert(stack, 'DynamicNode')
|
||||||
|
|
||||||
for i, node in ipairs(self.children) do
|
local i = 1
|
||||||
local status = runAndReset(node, delta, blackboard, stack)
|
local children = self.children
|
||||||
|
|
||||||
if stauts == FAILURE and self.index == i then
|
while i <= self.index do
|
||||||
|
local child = children[i]
|
||||||
|
local status = runAndReset(child, delta, blackboard, stack)
|
||||||
|
|
||||||
|
if status == FAILURE and i == self.index then
|
||||||
self.index = self.index + 1
|
self.index = self.index + 1
|
||||||
elseif status ~= RUNNING and i < self.index then
|
end
|
||||||
node:reset()
|
|
||||||
|
if i < self.index and (status == SUCCESS or status == RUNNING) then
|
||||||
|
child:reset()
|
||||||
self.index = i
|
self.index = i
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -608,6 +593,8 @@ function dynNode:run(delta, blackboard, stack)
|
|||||||
--table.remove(stack)
|
--table.remove(stack)
|
||||||
return status
|
return status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
--table.remove(stack)
|
--table.remove(stack)
|
||||||
@ -692,9 +679,10 @@ end
|
|||||||
local statePrototype = {}
|
local statePrototype = {}
|
||||||
statePrototype.__index = statePrototype
|
statePrototype.__index = statePrototype
|
||||||
|
|
||||||
function statePrototype:ctor(blackboard, root)
|
function statePrototype:ctor(blackboard, root, name)
|
||||||
self.root = root
|
self.root = root
|
||||||
self._blackboard = blackboard
|
self._blackboard = blackboard
|
||||||
|
self.name = name or 'unnamed'
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
@ -90,6 +90,8 @@ local entityTypes = {
|
|||||||
|
|
||||||
local function entityTypeNamesToIntegers(input, fullName)
|
local function entityTypeNamesToIntegers(input, fullName)
|
||||||
if input then
|
if input then
|
||||||
|
local output = {}
|
||||||
|
|
||||||
for i, v in ipairs(input) do
|
for i, v in ipairs(input) do
|
||||||
-- could have used string.lower, but original engine does case-sensitive comparison here
|
-- could have used string.lower, but original engine does case-sensitive comparison here
|
||||||
-- so we can save quite a lot cpu cycles for ourselves by not doing string.lower
|
-- so we can save quite a lot cpu cycles for ourselves by not doing string.lower
|
||||||
@ -99,10 +101,10 @@ local function entityTypeNamesToIntegers(input, fullName)
|
|||||||
error('invalid entity type ' .. tostring(v) .. ' for ' .. fullName .. ' in types table at index ' .. i, 3)
|
error('invalid entity type ' .. tostring(v) .. ' for ' .. fullName .. ' in types table at index ' .. i, 3)
|
||||||
end
|
end
|
||||||
|
|
||||||
input[i] = lookup
|
output[i] = lookup
|
||||||
end
|
end
|
||||||
|
|
||||||
return input
|
return output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user